當前位置: 首頁>>代碼示例>>Python>>正文


Python win32security.GetFileSecurity方法代碼示例

本文整理匯總了Python中win32security.GetFileSecurity方法的典型用法代碼示例。如果您正苦於以下問題:Python win32security.GetFileSecurity方法的具體用法?Python win32security.GetFileSecurity怎麽用?Python win32security.GetFileSecurity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32security的用法示例。


在下文中一共展示了win32security.GetFileSecurity方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_owner

# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import GetFileSecurity [as 別名]
def get_owner(self):
        r""" Return the name of the owner of this file or directory.

        This follows symbolic links.

        On Windows, this returns a name of the form ur'DOMAIN\User Name'.
        On Windows, a group can own a file or directory.
        """
        if os.name == 'nt':
            if win32security is None:
                raise Exception("path.owner requires win32all to be installed")
            desc = win32security.GetFileSecurity(
                self, win32security.OWNER_SECURITY_INFORMATION)
            sid = desc.GetSecurityDescriptorOwner()
            account, domain, typecode = win32security.LookupAccountSid(None, sid)
            return domain + u'\\' + account
        else:
            if pwd is None:
                raise NotImplementedError("path.owner is not implemented on this platform.")
            st = self.stat()
            return pwd.getpwuid(st.st_uid).pw_name 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:_path.py

示例2: get_file_owner

# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import GetFileSecurity [as 別名]
def get_file_owner(self, file_path):
        """Returns the user name of the owner of the specified file.

        @param file_path: The path of the file.
        @type file_path: str

        @return: The user name of the owner.
        @rtype: str
        """
        sd = win32security.GetFileSecurity(
            file_path, win32security.OWNER_SECURITY_INFORMATION
        )
        owner_sid = sd.GetSecurityDescriptorOwner()
        name, domain, account_type = win32security.LookupAccountSid(None, owner_sid)
        if name == "Administrators":
            return self.__local_administrators
        else:
            return "%s\\%s" % (domain, name) 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:20,代碼來源:platform_windows.py

示例3: set_file_owner

# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import GetFileSecurity [as 別名]
def set_file_owner(self, file_path, owner):
        """Sets the owner of the specified file.

        @param file_path: The path of the file.
        @param owner: The new owner of the file.  This should be a string returned by either `get_file_ower` or
            `get_current_user`.
        @type file_path: str
        @type owner: str
        """
        # Lookup the user info by their name.  We need their sid, which will be in the 0th element of user_info.
        domain_user = owner.split("\\")
        user_info = win32security.LookupAccountName(domain_user[0], domain_user[1])

        # Get the current acl so we can just replace the owner information.
        owner_acl = win32security.GetFileSecurity(
            file_path, win32security.OWNER_SECURITY_INFORMATION
        )

        owner_acl.SetSecurityDescriptorOwner(user_info[0], True)
        win32security.SetFileSecurity(
            file_path, win32security.OWNER_SECURITY_INFORMATION, owner_acl
        ) 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:24,代碼來源:platform_windows.py

示例4: __get_owner_windows

# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import GetFileSecurity [as 別名]
def __get_owner_windows(self):
        """
        Return the name of the owner of this file or directory. Follow
        symbolic links.

        Return a name of the form ``r'DOMAIN\\User Name'``; may be a group.

        .. seealso:: :attr:`owner`
        """
        desc = win32security.GetFileSecurity(
            self, win32security.OWNER_SECURITY_INFORMATION)
        sid = desc.GetSecurityDescriptorOwner()
        account, domain, typecode = win32security.LookupAccountSid(None, sid)
        return domain + '\\' + account 
開發者ID:click-contrib,項目名稱:click-configfile,代碼行數:16,代碼來源:path.py

示例5: check_permissions

# 需要導入模塊: import win32security [as 別名]
# 或者: from win32security import GetFileSecurity [as 別名]
def check_permissions(path, logger):
    logger.info("I am", win32api.GetUserNameEx(win32con.NameSamCompatible))
    logger.info(path)
    sd = win32security.GetFileSecurity(path, win32security.OWNER_SECURITY_INFORMATION)
    owner_sid = sd.GetSecurityDescriptorOwner()
    name, domain, _ = win32security.LookupAccountSid(None, owner_sid)
    logger.info("File owned by %s\\%s" % (domain, name)) 
開發者ID:SekoiaLab,項目名稱:Fastir_Collector,代碼行數:9,代碼來源:utils.py


注:本文中的win32security.GetFileSecurity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。