我想给任何人完全访问特定文件夹(+子文件夹+其中的文件)。 我试过那段代码:
f = "c:\test" #... which is the folder
#vars
sidWorld = win32security.CreateWellKnownSid(win32security.WinWorldSid, None)
worldRights = win32file.FILE_ALL_ACCESS
#get DACL
fileSecDesc = win32security.GetNamedSecurityInfo( \
f, win32security.SE_FILE_OBJECT, win32security.DACL_SECURITY_INFORMATION)
fileDacl = fileSecDesc.GetSecurityDescriptorDacl()
#add rights
fileDacl.AddAccessAllowedAce( win32security.ACL_REVISION, worldRights, sidWorld )
win32security.SetNamedSecurityInfo( \
f, win32security.SE_FILE_OBJECT, win32security.DACL_SECURITY_INFORMATION, \
None, None, fileDacl, None )
问题是,它没有显示为完全访问权限,我认为是因为缺少继承(我还需要继承)。我无法弄清楚如何解决这个问题。
知道我错过了什么吗? 谢谢,最好的问候, Florian Lagg。
答案 0 :(得分:3)
休息后得到它:它很容易:
#vars
sidWorld = win32security.CreateWellKnownSid(win32security.WinWorldSid, None)
worldRights = win32file.FILE_ALL_ACCESS
flags = win32security.OBJECT_INHERIT_ACE| \
win32security.CONTAINER_INHERIT_ACE
#get DACL
fileSecDesc = win32security.GetNamedSecurityInfo( \
f, win32security.SE_FILE_OBJECT, win32security.DACL_SECURITY_INFORMATION)
fileDacl = fileSecDesc.GetSecurityDescriptorDacl()
#add rights
fileDacl.AddAccessAllowedAceEx( \
win32security.ACL_REVISION_DS, \
flags, \
worldRights, \
sidWorld)
win32security.SetNamedSecurityInfo( \
f, win32security.SE_FILE_OBJECT, win32security.DACL_SECURITY_INFORMATION, \
None, None, fileDacl, None )
因此:解决了! 不管怎样,谢谢!