Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto set WinBase.SECURITY_ATTRIBUTES #20

Closed
fiurthorn opened this issue Jul 9, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@fiurthorn
Copy link

commented Jul 9, 2019

@Override public int zwCreateFile(WString rawPath, WinBase.SECURITY_ATTRIBUTES securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanFileInfo dokanFileInfo);

I've found that I need to use SelfRelativeSecurityDescriptor.
But how?

@fiurthorn

This comment has been minimized.

Copy link
Author

commented Jul 9, 2019

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());
@infeo

This comment has been minimized.

Copy link
Contributor

commented Jul 9, 2019

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.

@fiurthorn

This comment has been minimized.

Copy link
Author

commented Jul 10, 2019

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)
@fiurthorn

This comment has been minimized.

Copy link
Author

commented Jul 10, 2019

I simply want to know who access the file, or set who can access the file.

@infeo

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2019

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.

@infeo infeo closed this Jul 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.