Python win32security.GetFileSecurity() Examples
The following are 5
code examples of win32security.GetFileSecurity().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32security
, or try the search function
.
Example #1
Source File: _path.py From Computable with MIT License | 6 votes |
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
Example #2
Source File: platform_windows.py From scalyr-agent-2 with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: platform_windows.py From scalyr-agent-2 with Apache License 2.0 | 6 votes |
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 )
Example #4
Source File: path.py From click-configfile with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #5
Source File: utils.py From Fastir_Collector with GNU General Public License v3.0 | 5 votes |
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))