

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
1 message in net.java.dev.jna.users[jna-users] byte[] cast to Structure| From | Sent On | Attachments |
|---|---|---|
| Hannes | Jun 19, 2008 12:22 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [jna-users] byte[] cast to Structure | Actions... |
|---|---|---|
| From: | Hannes (hb...@sbox.tugraz.at) | |
| Date: | Jun 19, 2008 12:22:11 am | |
| List: | net.java.dev.jna.users | |
hi,
i am trying to read acls in windows out of an java program.
Here is my Jna mapping:
/* The security descriptor structure */ // typedef struct { // BYTE Revision; // BYTE Sbz1; // SECURITY_DESCRIPTOR_CONTROL Control; // PSID Owner; // PSID Group; // PACL Sacl; // PACL Dacl; // } SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;
class SECURITY_DESCRIPTOR extends Structure { public static class PSECURITY_DESCRIPTOR extends SECURITY_DESCRIPTOR implements Structure.ByReference{} byte Revision, Sbz1; SECURITY_DESCRIPTOR_CONTROL Control; public PSID Owner; public PSID Group; public PACL Sacl; }
// BOOL WINAPI GetSecurityDescriptorDacl( // __in PSECURITY_DESCRIPTOR pSecurityDescriptor, // __out LPBOOL lpbDaclPresent, // __out PACL* pDacl, // __out LPBOOL lpbDaclDefaulted // ); boolean GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor,IntByReference lpbDaclPresent, PointerByReference pDacl, IntByReference lpbDaclDefaulted);
// BOOL WINAPI GetFileSecurity( // __in LPCTSTR lpFileName, // __in SECURITY_INFORMATION RequestedInformation, // __out_opt PSECURITY_DESCRIPTOR pSecurityDescriptor, IMPLEMENTED AS BYTE[]!!!! // __in DWORD nLength, // __out LPDWORD lpnLengthNeeded // );
boolean GetFileSecurityA(String lpFileName, SECURITY_INFORMATION RequestedInformation, byte[] pSecurityDescriptor, int nLength, IntByReference lpnLengthNeeded);
// typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; class SECURITY_INFORMATION extends Structure{ public int SECURITY_INFORMATION =4; }
// typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL; class SECURITY_DESCRIPTOR_CONTROL extends Structure{ public short SECURITY_DESCRIPTOR_CONTROL; } // typedef struct { // BYTE Value[6]; // } SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY,*LPSID_IDENTIFIER_AUTHORITY;
class SID_IDENTIFIER_AUTHORITY extends Structure{ public byte[] Value = new byte[6]; }
Here is my java implementation
public class advapi32test {
public static void main(String[] args) {
advapi32.SECURITY_INFORMATION DACL_SECURITY_INFORMATION= new advapi32.SECURITY_INFORMATION();
IntByReference lpnLengthNeeded= new IntByReference(); advapi32.SECURITY_DESCRIPTOR.PSECURITY_DESCRIPTOR pSecDescriptorBuf= new advapi32.SECURITY_DESCRIPTOR.PSECURITY_DESCRIPTOR();
byte[] pSecDescriptorBuf1 = new byte[lpnLengthNeeded.getValue()];
//System.out.println("pSecDescriptorBuf size: " +pSecDescriptorBuf.size()); boolean result3=advapi32.INSTANCE.GetFileSecurityA("E:/test.txt", DACL_SECURITY_INFORMATION, pSecDescriptorBuf1, lpnLengthNeeded.getValue(), lpnLengthNeeded);
IntByReference lpbDaclPresent = new IntByReference(); PointerByReference pDacl = new PointerByReference(); IntByReference lpbDaclDefaulted = new IntByReference(); boolean result4 = GetSecurityDescriptorDacl((PSECURITY_DESCRIPTOR) pSecDescriptorBuf1, lpbDaclPresent, pDacl, lpbDaclDefaulted);
Now i'm having the problem that GetFileSecurityA returns a byte[] instead of an pointer to an SECURITY_DESCRIPTOR. Has anyone a solution out there? Should i defiine the Jna Interface as byte[]?
thanks for help







