pythonwinapisid

LookupAccountSid, No mapping between account names and security ID's


Trying to do a scan over a selected source while getting information of each individual file, (size, time, owner) The owner of the file is where the code is working on some harddrives but not other harddrives.

The df_path is higher in the code but holds a list of all the paths being tested

df_values = []
for path in df_path:
    values = []
    #owner = pwd.getpwuid(os.stat(path).st_uid)
    size = os.stat(path).st_size
    access = os.stat(path).st_atime
    modification = os.stat(path).st_mtime
    created = os.stat(path).st_ctime
    sd = win32security.GetFileSecurity(path, win32security.OWNER_SECURITY_INFORMATION)
    owner_sid = sd.GetSecurityDescriptorOwner()
    name, domain, type = win32security.LookupAccountSid(None, owner_sid)
    owner = name
    values = [path, owner, size, access, modification, created]
    df_values.append(values)
print(df_values)
print(df_values[0])

on one root folder it will work perfectly and output will look like

['E:/Sams Phone\\DCIM\\Camera\\20180920_224234.jpg', 'Brandon', 3385818, 1576223423.6219194, 1537504954.0, 1576223423.5281403]

Process finished with exit code 0

but then on others I get back

Traceback (most recent call last):
  File "C:/Users/Python/Projects/filescanner/treeScanner.py", line 53, in <module>
    name, domain, type = win32security.LookupAccountSid(None, owner_sid)
pywintypes.error: (1332, 'LookupAccountSid', 'No mapping between account names and security IDs was done.')

Their is no unknown user in the reg or anywhere else that I have been able to find

Any and all help is greatly appreciated


Solution

  • (1332, 'LookupAccountSid', 'No mapping between account names and security IDs was done.')
    

    If the function LookupAccountSid cannot find an account name for the SID, GetLastError returns ERROR_NONE_MAPPED.

    This error can occur at the following situations: