Closed fiurthorn closed 5 years ago
the following does not work:
var netUser = Netapi32Util.getUserInfo("xxx");
log.info(netUser.name, netUser.sidString);
// var sec = new com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR(securityContext.lpSecurityDescriptor);
// var user = Advapi32Util.getAccountByName("xxx");
// log.info(user.name, user.sidString);
SecurityIdentifier owner = SecurityIdentifier.fromString(netUser.sidString);
SecurityIdentifier group = null;
AccessControlEntry entry = new AccessAllowedACE(
new EnumIntegerSet(AccessControlEntryFlag.NO_PROPAGATE_INHERIT_ACE), owner, new EnumIntegerSet(AccessMask.GENERIC_READ)
);
AccessControlList dacl = AccessControlList.createDaclRevision2(List.of(entry));
SelfRelativeSecurityDescriptor srsd = SelfRelativeSecurityDescriptor.createSD(
new EnumIntegerSet(SecurityDescriptorControlFlag.DP),
owner, group, null, dacl
);
securityContext.bInheritHandle = false;
securityContext.lpSecurityDescriptor = new Memory(srsd.sizeOfByteArray());
securityContext.lpSecurityDescriptor.write(0, srsd.toByteArray(), 0, srsd.sizeOfByteArray());
securityContext.dwLength = new WinDef.DWORD(srsd.sizeOfByteArray());
First of all you don't create a security descriptor in a zwCreateFile() call. The security descriptor either already exists or is set to null.
In fact dokan-java does not provide a way to set the security attributes of a file or anything since you implement your own filesystem. What it does provide is a tool to create a self-relative security descriptor to answer a GetFileSecurity() call. For your purpose i would suggest to take a look at the WinNT.SECURITY_DESCIRPTOR class of the jna project.
Enabling the following features never gives me a SecurityDescriptior that can be deserialized. The error of uninitialized memory always comes.
The tab Securitiy can be seen in the file properties, but empty.
PERSISTENT_ACLS(WinNT.FILE_PERSISTENT_ACLS)
SUPPORTS_EXTENDED_ATTRIBUTES(WinNT.FILE_SUPPORTS_EXTENDED_ATTRIBUTES)
I simply want to know who access the file, or set who can access the file.
dokan-java is the wrong library for this purpose. It does not give you access to native windows functions and/or features. It only provides a way to implement your own filesystem in Java for Windows and provide a mount/access point for it. The filesystem could be anything, not only some additional layer between you and the files on disk.
For your purpose you should use the JNA library.
I'm closing this issue since it is not about dokan-java and rather about accessing/setting a native windows structure.
I've found that I need to use SelfRelativeSecurityDescriptor. But how?