Search in sources :

Example 6 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Advapi32Test method testMakeAbsoluteSD.

public void testMakeAbsoluteSD() throws Exception {
    SECURITY_DESCRIPTOR absolute = new SECURITY_DESCRIPTOR(64 * 1024);
    // Get a SD in self relative form
    int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
    PointerByReference relativeByReference = new PointerByReference();
    File file = createTempFile();
    try {
        try {
            assertEquals("GetNamedSecurityInfo(" + file + ")", Advapi32.INSTANCE.GetNamedSecurityInfo(file.getAbsolutePath(), AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, null, null, null, null, relativeByReference), 0);
            SECURITY_DESCRIPTOR_RELATIVE relative = new SECURITY_DESCRIPTOR_RELATIVE(relativeByReference.getValue());
            PSID pOwner = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
            PSID pGroup = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
            ACL pDacl = new ACL(ACL.MAX_ACL_SIZE);
            ACL pSacl = new ACL(ACL.MAX_ACL_SIZE);
            IntByReference lpdwBufferLength = new IntByReference(absolute.size());
            IntByReference lpdwDaclSize = new IntByReference(ACL.MAX_ACL_SIZE);
            IntByReference lpdwSaclSize = new IntByReference(ACL.MAX_ACL_SIZE);
            IntByReference lpdwOwnerSize = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
            IntByReference lpdwPrimaryGroupSize = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
            assertTrue(Advapi32.INSTANCE.MakeAbsoluteSD(relative, absolute, lpdwBufferLength, pDacl, lpdwDaclSize, pSacl, lpdwSaclSize, pOwner, lpdwOwnerSize, pGroup, lpdwPrimaryGroupSize));
        } finally {
            file.delete();
        }
    } finally {
        Kernel32Util.freeLocalMemory(relativeByReference.getValue());
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) SECURITY_DESCRIPTOR_RELATIVE(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR_RELATIVE) SECURITY_DESCRIPTOR(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR) ACL(com.sun.jna.platform.win32.WinNT.ACL) PSID(com.sun.jna.platform.win32.WinNT.PSID) File(java.io.File)

Example 7 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Advapi32Test method testGetSecurityDescriptorLength.

public void testGetSecurityDescriptorLength() throws Exception {
    int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
    PointerByReference ppSecurityDescriptor = new PointerByReference();
    File file = createTempFile();
    try {
        try {
            assertEquals("GetNamedSecurityInfo(" + file + ")", 0, Advapi32.INSTANCE.GetNamedSecurityInfo(file.getAbsolutePath(), AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, null, null, null, null, ppSecurityDescriptor));
            assertTrue("GetSecurityDescriptorLength(" + file + ")", Advapi32.INSTANCE.GetSecurityDescriptorLength(ppSecurityDescriptor.getValue()) > 0);
        } finally {
            file.delete();
        }
    } finally {
        Kernel32Util.freeLocalMemory(ppSecurityDescriptor.getValue());
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) File(java.io.File)

Example 8 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Advapi32Test method testSetNamedSecurityInfoForFileNoSACL.

public void testSetNamedSecurityInfoForFileNoSACL() throws Exception {
    int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
    PointerByReference ppsidOwner = new PointerByReference();
    PointerByReference ppsidGroup = new PointerByReference();
    PointerByReference ppDacl = new PointerByReference();
    PointerByReference ppSecurityDescriptor = new PointerByReference();
    // create a temp file
    File file = createTempFile();
    String filePath = file.getAbsolutePath();
    try {
        try {
            assertEquals("GetNamedSecurityInfo(" + filePath + ")", 0, Advapi32.INSTANCE.GetNamedSecurityInfo(filePath, AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, ppsidOwner, ppsidGroup, ppDacl, null, ppSecurityDescriptor));
            assertEquals("SetNamedSecurityInfo(" + filePath + ")", 0, Advapi32.INSTANCE.SetNamedSecurityInfo(filePath, AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, ppsidOwner.getValue(), ppsidGroup.getValue(), ppDacl.getValue(), null));
        } finally {
            file.delete();
        }
    } finally {
        Kernel32Util.freeLocalMemory(ppSecurityDescriptor.getValue());
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) File(java.io.File)

Example 9 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Advapi32Test method testLookupAccountName.

public void testLookupAccountName() {
    IntByReference pSid = new IntByReference(0);
    IntByReference pDomain = new IntByReference(0);
    PointerByReference peUse = new PointerByReference();
    String accountName = "Administrator";
    assertFalse(Advapi32.INSTANCE.LookupAccountName(null, accountName, null, pSid, null, pDomain, peUse));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
    assertTrue(pSid.getValue() > 0);
    Memory sidMemory = new Memory(pSid.getValue());
    PSID pSidMemory = new PSID(sidMemory);
    char[] referencedDomainName = new char[pDomain.getValue() + 1];
    assertTrue(Advapi32.INSTANCE.LookupAccountName(null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
    assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
    assertTrue(Native.toString(referencedDomainName).length() > 0);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) PointerByReference(com.sun.jna.ptr.PointerByReference) PSID(com.sun.jna.platform.win32.WinNT.PSID)

Example 10 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class ITypeLibTest method testGetTypeComp.

public void testGetTypeComp() {
    ITypeLib shellTypeLib = loadShellTypeLib();
    PointerByReference pbr = new PointerByReference();
    HRESULT hr = shellTypeLib.GetTypeComp(pbr);
    // Only check that call works
    assertTrue(COMUtils.SUCCEEDED(hr));
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)128 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)54 IntByReference (com.sun.jna.ptr.IntByReference)35 Pointer (com.sun.jna.Pointer)20 Test (org.junit.Test)19 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)18 REFIID (com.sun.jna.platform.win32.Guid.REFIID)13 File (java.io.File)13 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)10 PSID (com.sun.jna.platform.win32.WinNT.PSID)10 Memory (com.sun.jna.Memory)8 WString (com.sun.jna.WString)8 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 WinNT (com.sun.jna.platform.win32.WinNT)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IID (com.sun.jna.platform.win32.Guid.IID)6 ArrayList (java.util.ArrayList)6 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 UINT (com.sun.jna.platform.win32.WinDef.UINT)5