win_acls.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:rdiff-backup 作者: sol1 项目源码 文件源码
def clear_rp(self, rp):
        # not sure how to interpret this
        # I'll just clear all acl-s from rp.path
        try:
            sd = rp.conn.win32security. \
                    GetNamedSecurityInfo(rp.path, SE_FILE_OBJECT, ACL.flags)
        except (OSError, IOError, pywintypes.error), exc:
            log.Log("Warning: unable to read ACL from %s for clearing: %s"
                    % (repr(rp.path), exc), 4)
            return

        acl = sd.GetSecurityDescriptorDacl()
        if acl:
            n = acl.GetAceCount()
            # traverse the ACL in reverse, so the indices stay correct
            while n:
                n -= 1
                acl.DeleteAce(n)
            sd.SetSecurityDescriptorDacl(0, acl, 0)

        if ACL.flags & SACL_SECURITY_INFORMATION:
            acl = sd.GetSecurityDescriptorSacl()
            if acl:
                n = acl.GetAceCount()
                # traverse the ACL in reverse, so the indices stay correct
                while n:
                    n -= 1
                    acl.DeleteAce(n)
                sd.SetSecurityDescriptorSacl(0, acl, 0)

        try:
            rp.conn.win32security. \
                SetNamedSecurityInfo(rp.path, SE_FILE_OBJECT, ACL.flags,
                sd.GetSecurityDescriptorOwner(),sd.GetSecurityDescriptorGroup(),
                sd.GetSecurityDescriptorDacl(),
                (ACL.flags & SACL_SECURITY_INFORMATION) and 
                    sd.GetSecurityDescriptorSacl() or None)
        except (OSError, IOError, pywintypes.error), exc:
            log.Log("Warning: unable to set ACL on %s after clearing: %s"
                    % (repr(rp.path), exc), 4)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号