本文整理汇总了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
示例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
)
示例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)
示例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]
示例5: testEqual
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LookupAccountName [as 别名]
def testEqual(self):
self.failUnlessEqual(win32security.LookupAccountName('','Administrator')[0],
win32security.LookupAccountName('','Administrator')[0])
示例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]))