Created
October 19, 2016 20:15
-
-
Save happy-monk/ad7c210279fb25409d54e1b39038ef8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from fs.osfs import OSFS | |
from fs.expose import dokan | |
from fs.expose.dokan.libdokan import LPDWORD | |
import ctypes | |
from ctypes.wintypes import BOOL, LPWSTR, DWORD | |
advapi32 = ctypes.windll.advapi32 | |
class SECURITY_DESCRIPTOR(ctypes.Structure): pass | |
PSECURITY_DESCRIPTOR = ctypes.POINTER(SECURITY_DESCRIPTOR) | |
PPSECURITY_DESCRIPTOR = ctypes.POINTER(PSECURITY_DESCRIPTOR) | |
SECURITY_INFORMATION = DWORD | |
PSECURITY_INFORMATION = ctypes.POINTER(SECURITY_INFORMATION) | |
GetFileSecurity = ctypes.windll.advapi32.GetFileSecurityW | |
GetFileSecurity.restype = BOOL | |
GetFileSecurity.argtypes = ( | |
LPWSTR, # _In_ LPCTSTR lpFileName, | |
SECURITY_INFORMATION, # _In_ SECURITY_INFORMATION RequestedInformation, | |
PSECURITY_DESCRIPTOR, # _Out_opt_ PSECURITY_DESCRIPTOR pSecurityDescriptor, | |
DWORD, # _In_ DWORD nLength, | |
LPDWORD, # _Out_ LPDWORD lpnLengthNeeded | |
) | |
STATUS_BUFFER_OVERFLOW = 0x80000005 | |
class MyOperations(dokan.FSOperations): | |
@dokan.handle_fs_errors | |
def GetFileSecurity(self, path, securityinformation, securitydescriptor, securitydescriptorlength, neededlength, | |
info): | |
securitydescriptor = ctypes.cast(securitydescriptor, PSECURITY_DESCRIPTOR) | |
path = self._dokanpath2pyfs(path) | |
if self.fs.isdir(path): | |
res = GetFileSecurity( | |
os.path.expanduser('~'), | |
ctypes.cast(securityinformation, PSECURITY_INFORMATION)[0], | |
securitydescriptor, | |
securitydescriptorlength, | |
neededlength, | |
) | |
return dokan.STATUS_SUCCESS if res else STATUS_BUFFER_OVERFLOW | |
return dokan.STATUS_NOT_IMPLEMENTED | |
fs = OSFS(r'D:\Test', create = True) | |
mount_point = 'p:\\' | |
try: | |
dokan.unmount(mount_point) | |
except OSError: | |
pass | |
dokan.mount( | |
fs, mount_point, | |
foreground = True, | |
numthreads = 16, | |
FSOperationsClass = MyOperations, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment