Search in sources :

Example 36 with Advapi32

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));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) PSIDByReference(com.sun.jna.platform.win32.WinNT.PSIDByReference) SECURITY_DESCRIPTOR(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR) PSID(com.sun.jna.platform.win32.WinNT.PSID)

Example 37 with Advapi32

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());
}
Also used : PROCESS_INFORMATION(com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION) STARTUPINFO(com.sun.jna.platform.win32.WinBase.STARTUPINFO) File(java.io.File)

Example 38 with Advapi32

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));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 39 with Advapi32

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();
}
Also used : SECURITY_DESCRIPTOR_RELATIVE(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR_RELATIVE) File(java.io.File)

Example 40 with Advapi32

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();
}
Also used : SECURITY_DESCRIPTOR_RELATIVE(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR_RELATIVE) File(java.io.File)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)51 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)39 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)31 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)31 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)23 PSID (com.sun.jna.platform.win32.WinNT.PSID)20 PointerByReference (com.sun.jna.ptr.PointerByReference)20 Advapi32 (com.sun.jna.platform.win32.Advapi32)15 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)15 File (java.io.File)15 Memory (com.sun.jna.Memory)13 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)13 PSIDByReference (com.sun.jna.platform.win32.WinNT.PSIDByReference)10 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)9 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)7 Pointer (com.sun.jna.Pointer)6 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 GENERIC_MAPPING (com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING)6 BOOLByReference (com.sun.jna.platform.win32.WinDef.BOOLByReference)5