简体   繁体   English

使用Python重置NTFS文件夹的继承权限

[英]Reset inherited permissions on NTFS folders with Python

I have quite a few folders on an NTFS partition (on Windows 2008) which are not inheriting their permissions from their parents. 我在NTFS分区(在Windows 2008上)上有很多文件夹,这些文件夹不会从父项继承权限。

I'd like to reset that so they do include those parent permissions (equivalent to checking the "Include inheritable permissions from this object's parent" checkbox under the Advanced Security Settings area). 我想重置它,以便它们包括那些父权限(相当于检查“高级安全设置”区域下的“包括此对象的父级的可继承权限”复选框)。

Since we use Python for some other system management tasks here, I'd like to do it in Python if possible (I know how I can do it in VBScript, but this isn't going to be a one off script, but run regularly, so should integrate with the rest of our codebase). 由于我们在这里使用Python进行其他一些系统管理任务,如果可能的话我想用Python做(我知道如何在VBScript中做到这一点,但这不是一次性的脚本,而是定期运行,所以应该与我们的代码库的其余部分集成)。

I've been using the excellent pywin32 extensions and examples from http://timgolden.me.uk/python/win32_how_do_i.html and Google to get started, but I don't see any way to simply say "inherit permissions from parent." 我一直在使用来自http://timgolden.me.uk/python/win32_how_do_i.html和Google的优秀pywin32扩展和示例来开始,但我没有看到任何方式简单地说“从父级继承权限”。 “

Using AddAccessAllowedAceEx, I can even fake inheritance of something by adding the INHERITED_ACE flag in something like, whether it really is coming from the parent or not: 使用AddAccessAllowedAceEx,我甚至可以通过添加INHERITED_ACE标志来伪造某些东西的继承,无论它是否真的来自父级:

dacl.AddAccessAllowedAceEx( \
  win32security.ACL_REVISION_DS \
, win32security.OBJECT_INHERIT_ACE | win32security.CONTAINER_INHERIT_ACE | win32security.INHERITED_ACE \
, ntsecuritycon.FILE_GENERIC_READ | ntsecuritycon.FILE_GENERIC_EXECUTE \
, some_sid_here \
)

But how in the world do I know which things to inherit unless I walk the entire path from the root folder and build the inheritance all the way down? 但是,除非我从根文件夹走完整个路径并一直构建继承,否则我怎么知道要继承哪些东西呢?

OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE need to be set on the root folder's ACEs. 需要在根文件夹的ACE上设置OBJECT_INHERIT_ACE和CONTAINER_INHERIT_ACE。 You'll probably also want to clear any permissions set directly on each subfolder and file. 您可能还希望清除直接在每个子文件夹和文件上设置的任何权限。 (Those would be the ones that don't include INHERITED_ACE in their ACE flags). (那些将在ACE标志中不包含INHERITED_ACE的那些)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM