diff --git a/src/main/java/dev/dokan/dokan_java/AbstractDokanFileSystem.java b/src/main/java/dev/dokan/dokan_java/AbstractDokanFileSystem.java index f0cf8cc..8d80544 100644 --- a/src/main/java/dev/dokan/dokan_java/AbstractDokanFileSystem.java +++ b/src/main/java/dev/dokan/dokan_java/AbstractDokanFileSystem.java @@ -54,7 +54,7 @@ private void init(DokanOperations dokanOperations) { if (usesKernelFlagsAndCodes) { if (isImplemented("zwCreateFile")) { - dokanOperations.setZwCreateFile(this::zwCreateFile); + dokanOperations.setZwCreateFile((rawPath, securityContext, rawDesiredAccess, rawFileAttributes, rawShareAccess, rawCreateDisposition, rawCreateOptions, dokanFileInfo) -> zwCreateFile(rawPath, securityContext, rawDesiredAccess, rawFileAttributes, rawShareAccess, rawCreateDisposition, rawCreateOptions, dokanFileInfo)); } if (isImplemented("cleanup")) { dokanOperations.setCleanup(this::cleanup); diff --git a/src/main/java/dev/dokan/dokan_java/DokanFileSystem.java b/src/main/java/dev/dokan/dokan_java/DokanFileSystem.java index c51bcf1..e403267 100644 --- a/src/main/java/dev/dokan/dokan_java/DokanFileSystem.java +++ b/src/main/java/dev/dokan/dokan_java/DokanFileSystem.java @@ -6,6 +6,7 @@ import dev.dokan.dokan_java.constants.microsoft.NtStatuses; import dev.dokan.dokan_java.structure.ByHandleFileInformation; import dev.dokan.dokan_java.structure.DokanFileInfo; +import dev.dokan.dokan_java.structure.DokanIOSecurityContext; import dev.dokan.dokan_java.structure.DokanOptions; import com.sun.jna.Pointer; import com.sun.jna.WString; @@ -51,7 +52,7 @@ public interface DokanFileSystem extends Mountable { */ int zwCreateFile( WString rawPath, - WinBase.SECURITY_ATTRIBUTES securityContext, + DokanIOSecurityContext securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, diff --git a/src/main/java/dev/dokan/dokan_java/DokanFileSystemStub.java b/src/main/java/dev/dokan/dokan_java/DokanFileSystemStub.java index 7f5094e..74510ec 100644 --- a/src/main/java/dev/dokan/dokan_java/DokanFileSystemStub.java +++ b/src/main/java/dev/dokan/dokan_java/DokanFileSystemStub.java @@ -7,6 +7,8 @@ import com.sun.jna.platform.win32.WinBase; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; +import dev.dokan.dokan_java.structure.DokanIOSecurityContext; + public class DokanFileSystemStub extends AbstractDokanFileSystem { @@ -29,7 +31,7 @@ public DokanFileSystemStub(FileSystemInformation fileSystemInformation, boolean */ @Override @NotImplemented - public int zwCreateFile(WString rawPath, WinBase.SECURITY_ATTRIBUTES securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanFileInfo dokanFileInfo) { + public int zwCreateFile(WString rawPath, DokanIOSecurityContext securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanFileInfo dokanFileInfo) { return 0; } diff --git a/src/main/java/dev/dokan/dokan_java/DokanOperations.java b/src/main/java/dev/dokan/dokan_java/DokanOperations.java index 636b815..b6f24b6 100644 --- a/src/main/java/dev/dokan/dokan_java/DokanOperations.java +++ b/src/main/java/dev/dokan/dokan_java/DokanOperations.java @@ -8,12 +8,12 @@ import dev.dokan.dokan_java.constants.microsoft.FileSystemFlag; import dev.dokan.dokan_java.structure.ByHandleFileInformation; import dev.dokan.dokan_java.structure.DokanFileInfo; +import dev.dokan.dokan_java.structure.DokanIOSecurityContext; import dev.dokan.dokan_java.structure.DokanOptions; import com.sun.jna.Callback; import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.WString; -import com.sun.jna.platform.win32.WinBase; import com.sun.jna.platform.win32.WinBase.FILETIME; import com.sun.jna.platform.win32.WinBase.WIN32_FIND_DATA; import com.sun.jna.ptr.IntByReference; @@ -119,7 +119,7 @@ interface ZwCreateFile extends Callback { */ long callback( WString rawPath, - WinBase.SECURITY_ATTRIBUTES securityContext, + DokanIOSecurityContext securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, diff --git a/src/main/java/dev/dokan/dokan_java/examples/DirListingFileSystem.java b/src/main/java/dev/dokan/dokan_java/examples/DirListingFileSystem.java index 633e743..e725a63 100644 --- a/src/main/java/dev/dokan/dokan_java/examples/DirListingFileSystem.java +++ b/src/main/java/dev/dokan/dokan_java/examples/DirListingFileSystem.java @@ -17,6 +17,7 @@ import dev.dokan.dokan_java.constants.microsoft.Win32ErrorCodes; import dev.dokan.dokan_java.structure.ByHandleFileInformation; import dev.dokan.dokan_java.structure.DokanFileInfo; +import dev.dokan.dokan_java.structure.DokanIOSecurityContext; import dev.dokan.dokan_java.structure.EnumIntegerSet; import java.io.IOException; @@ -51,7 +52,7 @@ public DirListingFileSystem(Path root, FileSystemInformation fileSystemInformati } @Override - public int zwCreateFile(WString rawPath, WinBase.SECURITY_ATTRIBUTES securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanFileInfo dokanFileInfo) { + public int zwCreateFile(WString rawPath, DokanIOSecurityContext securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanFileInfo dokanFileInfo) { Path p = getrootedPath(rawPath); //the files must exist and we are read only here diff --git a/src/main/java/dev/dokan/dokan_java/structure/DokanAccessState.java b/src/main/java/dev/dokan/dokan_java/structure/DokanAccessState.java new file mode 100644 index 0000000..0ea580e --- /dev/null +++ b/src/main/java/dev/dokan/dokan_java/structure/DokanAccessState.java @@ -0,0 +1,100 @@ +package dev.dokan.dokan_java.structure; + + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; + +import java.util.Arrays; +import java.util.List; + + +/** + * This is a Dokan specific implementation of the ACCESS_STATE structure of the windows kernel. + * + * @see Microsoft Documentation + * @see Check for Traverse Privilege on IRP_MJ_CREATE. + * A driver can also check for the TOKEN_IS_RESTRICTED flag. + * These flags are defined in Ntifs.h. + */ + public int Flags; + + /** + * An ACCESS_MASK type that describes the access rights that have not yet been granted to the caller. + * A driver uses this member to determine if the Windows security system can grant access. + * If access can be granted, the driver updates the PreviouslyGrantedAccess and RemainingDesiredAccess members accordingly. + */ + public int RemainingDesiredAccess; + + /** + * An ACCESS_MASK type that specifies the information about access that has already been granted to the caller of one of the Security Reference Monitor Routines + * The Windows security system grants certain rights based on the privileges of the caller, such as traverse right (the ability to traverse through a directory as part of opening a subdirectory or file). + */ + public int PreviouslyGrantedAccess; + + /** + * An ACCESS_MASK type that contains the original access rights that were requested by the caller. + */ + public int OriginalDesiredAccess; + + /** + * A pointer to a SECURITY_DESCRIPTOR structure that contains security information for the object that this access relates to. + */ + public Pointer SecurityDescriptor; + //public WinNT.SECURITY_DESCRIPTOR_RELATIVE.ByReference SecurityDescriptor; //Does not work + + /** + * A UNICODE_STRING structure that contains the object name string for the access. This member is used for auditing. + */ + public UnicodeString ObjectName; + + /** + * A UNICODE_STRING structure that contains the object type name string for the access. This member is used for auditing. + */ + public UnicodeString ObjectType; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"SecurityEvaluated", + "GenerateAudit", + "GenerateOnClose", + "AuditPrivileges", + "Flags", + "RemainingDesiredAccess", + "PreviouslyGrantedAccess", + "OriginalDesiredAccess", + "SecurityDescriptor", + "ObjectName", + "ObjectType"}); + } +} diff --git a/src/main/java/dev/dokan/dokan_java/structure/DokanIOSecurityContext.java b/src/main/java/dev/dokan/dokan_java/structure/DokanIOSecurityContext.java new file mode 100644 index 0000000..a4a17a3 --- /dev/null +++ b/src/main/java/dev/dokan/dokan_java/structure/DokanIOSecurityContext.java @@ -0,0 +1,28 @@ +package dev.dokan.dokan_java.structure; + + +import com.sun.jna.Structure; +import com.sun.jna.WString; + + +/** + * The DokanIOSecurityContext contains the Dokan specific security context of the Windows kernel create request. + * It is a parameter in the {@link dev.dokan.dokan_java.DokanFileSystem#zwCreateFile(WString, DokanIOSecurityContext, int, int, int, int, int, DokanFileInfo)} function. + * + * @see Microsoft documentation of the original structure + * @see + * This class is needed to fully implement {@link DokanAccessState}. + * It is defined in fileinfo.h in the dokan module of the Dokany project. + */ +@Structure.FieldOrder({"Length", "MaximumLength", "Buffer"}) +public class UnicodeString extends Structure { + + /** + * The length, in bytes, of the string stored in {@link UnicodeString#Buffer}. + */ + public short Length; + + /** + * The length, in bytes, of {@link UnicodeString#Buffer}. + */ + public short MaximumLength; + + /** + * Pointer to a buffer used to contain a string of wide characters. + */ + public Pointer Buffer; + +}