use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testSetGetSecurityDescriptorGroup.
public void testSetGetSecurityDescriptorGroup() {
SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
PSID pSidPut = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
IntByReference cbSid = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
assertTrue("Failed to create well-known SID", Advapi32.INSTANCE.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinBuiltinAdministratorsSid, null, pSidPut, cbSid));
assertTrue(Advapi32.INSTANCE.SetSecurityDescriptorGroup(sd, pSidPut, true));
BOOLByReference lpbOwnerDefaulted = new BOOLByReference();
PSIDByReference prSd = new PSIDByReference();
assertTrue(Advapi32.INSTANCE.GetSecurityDescriptorGroup(sd, prSd, lpbOwnerDefaulted));
PSID pSidGet = prSd.getValue();
assertTrue(Advapi32.INSTANCE.EqualSid(pSidPut, pSidGet));
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testCreateProcessWithLogonW.
public void testCreateProcessWithLogonW() {
String winDir = Kernel32Util.getEnvironmentVariable("WINDIR");
assertNotNull("No WINDIR value returned", winDir);
assertTrue("Specified WINDIR does not exist: " + winDir, new File(winDir).exists());
STARTUPINFO si = new STARTUPINFO();
si.lpDesktop = null;
PROCESS_INFORMATION results = new PROCESS_INFORMATION();
// i have the same combination on my luggage
boolean result = Advapi32.INSTANCE.CreateProcessWithLogonW("A" + System.currentTimeMillis(), "localhost", "12345", Advapi32.LOGON_WITH_PROFILE, new File(winDir, "notepad.exe").getAbsolutePath(), "", 0, null, "", si, results);
// we tried to run notepad as a bogus user, so it should fail.
assertFalse("CreateProcessWithLogonW should have returned false because the username was bogus.", result);
// should fail with "the user name or password is incorrect" (error 1326)
assertEquals("GetLastError() should have returned ERROR_LOGON_FAILURE because the username was bogus.", W32Errors.ERROR_LOGON_FAILURE, Native.getLastError());
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testReadEventLog.
public void testReadEventLog() {
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
IntByReference pnBytesRead = new IntByReference();
IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
Memory buffer = new Memory(1);
assertFalse(Advapi32.INSTANCE.ReadEventLog(h, WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_BACKWARDS_READ, 0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded));
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
assertTrue(pnMinNumberOfBytesNeeded.getValue() > 0);
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32UtilTest method testGetFileSecurityDescriptor.
public void testGetFileSecurityDescriptor() throws Exception {
File file = createTempFile();
SECURITY_DESCRIPTOR_RELATIVE sdr = Advapi32Util.getFileSecurityDescriptor(file, false);
assertTrue(Advapi32.INSTANCE.IsValidSecurityDescriptor(sdr.getPointer()));
file.delete();
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32UtilTest method testSetFileSecurityDescriptor.
public void testSetFileSecurityDescriptor() throws Exception {
File file = createTempFile();
SECURITY_DESCRIPTOR_RELATIVE sdr = Advapi32Util.getFileSecurityDescriptor(file, false);
Advapi32Util.setFileSecurityDescriptor(file, sdr, false, true, true, false, true, false);
sdr = Advapi32Util.getFileSecurityDescriptor(file, false);
assertTrue(Advapi32.INSTANCE.IsValidSecurityDescriptor(sdr.getPointer()));
file.delete();
}
Aggregations