当前位置: 首页>>代码示例>>Python>>正文


Python win32security.LookupAccountName方法代码示例

本文整理汇总了Python中win32security.LookupAccountName方法的典型用法代码示例。如果您正苦于以下问题:Python win32security.LookupAccountName方法的具体用法?Python win32security.LookupAccountName怎么用?Python win32security.LookupAccountName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32security的用法示例。


在下文中一共展示了win32security.LookupAccountName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_home_dir

# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [as 别名]
def get_home_dir(self, username):
            """Return the user's profile directory, the closest thing
            to a user home directory we have on Windows.
            """
            try:
                sid = win32security.ConvertSidToStringSid(
                    win32security.LookupAccountName(None, username)[0])
            except pywintypes.error as err:
                raise AuthorizerError(err)
            path = r"SOFTWARE\Microsoft\Windows NT" \
                   r"\CurrentVersion\ProfileList" + "\\" + sid
            try:
                key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
            except WindowsError:
                raise AuthorizerError(
                    "No profile directory defined for user %s" % username)
            value = winreg.QueryValueEx(key, "ProfileImagePath")[0]
            home = win32api.ExpandEnvironmentStrings(value)
            if not PY3 and not isinstance(home, unicode):
                home = home.decode('utf8')
            return home 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:23,代码来源:authorizers.py

示例2: set_file_owner

# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [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

示例3: change_acl_for_delete

# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [as 别名]
def change_acl_for_delete(path):
    """Zaps the SECURITY_DESCRIPTOR's DACL on a directory entry that is tedious
    to delete.

    This function is a heavy hammer. It discards the SECURITY_DESCRIPTOR and
    creates a new one with only one DACL set to user:FILE_ALL_ACCESS.

    Used as last resort.
    """
    STANDARD_RIGHTS_REQUIRED = 0xf0000
    SYNCHRONIZE = 0x100000
    FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3ff

    import win32security
    user, _domain, _type = win32security.LookupAccountName(
        '', getpass.getuser())
    sd = win32security.SECURITY_DESCRIPTOR()
    sd.Initialize()
    sd.SetSecurityDescriptorOwner(user, False)
    dacl = win32security.ACL()
    dacl.Initialize()
    dacl.AddAccessAllowedAce(
        win32security.ACL_REVISION_DS, FILE_ALL_ACCESS, user)
    sd.SetSecurityDescriptorDacl(1, dacl, 0)
    # Note that this assumes the object is either owned by the current user or
    # its group or that the current ACL permits this. Otherwise it will silently
    # fail.
    win32security.SetFileSecurity(
        fs.extend(path), win32security.DACL_SECURITY_INFORMATION, sd)
    # It's important to also look for the read only bit after, as it's possible
    # the set_read_only() call to remove the read only bit had silently failed
    # because there was no DACL for the user.
    if not (os.stat(path).st_mode & stat.S_IWUSR):
      os.chmod(path, 0o777) 
开发者ID:luci,项目名称:luci-py,代码行数:36,代码来源:file_path.py

示例4: setUp

# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [as 别名]
def setUp(self):
        self.pwr_sid=win32security.LookupAccountName('','Power Users')[0]
        self.admin_sid=win32security.LookupAccountName('','Administrator')[0] 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_security.py

示例5: testEqual

# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [as 别名]
def testEqual(self):
        self.failUnlessEqual(win32security.LookupAccountName('','Administrator')[0],
                             win32security.LookupAccountName('','Administrator')[0]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_security.py

示例6: testBuffer

# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [as 别名]
def testBuffer(self):
        self.failUnlessEqual(ob2memory(win32security.LookupAccountName('','Administrator')[0]),
                             ob2memory(win32security.LookupAccountName('','Administrator')[0])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_security.py


注:本文中的win32security.LookupAccountName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。