zut.context.getsid

zut.context.getsid() str

Retrieve the current user’s global SID (Security Identifier) on Windows, on on Linux if the host is part of an Active Directory domain. Raises an exception if the SID cannot be determined.

Returns:

The current user’s SID as a string, for example: S-1-5-21-1234567890-123456789-123456789-12345.

Structure of the SID: - “S”: Indicates that this is a SID. - “-1-”: The revision level of the SID structure (almost always 1). - “-5-”: The security authority identifier (5 = SECURITY_NT_AUTHORITY). - Then the RID (relative identifier) components follow, which are unique to the domain or local computer and the user account. In the example above:

  • “-21-”: The “non-unique RID” (relative identifier) indicating a domain or local computer (“non-unique” meaning that the RID value (here 21) is not sufficient to identify the security principal).

  • “-1234567890-123456789-123456789-”: The unique identifier for the domain or local computer.

  • “-12345”: The final RID for the user account within the domain. Known values: 500 = Administrator (of the machine ), 501 = Guest, 1000+ = first non-system user.

Well-known RIDs for S-1-5-: - 18 : Local System (S-1-5-18) - 19 : Local Service (S-1-5-19) - 20 : Network Service (S-1-5-20) - 32 : Builtin domain (ex: S-1-5-32-544 pour Administrators) - 80 : NT Service (S-1-5-80-…) - 11 : Authenticated Users (S-1-5-11) - 7 : Anonymous Logon (S-1-5-7)

See also: - https://learn.microsoft.com/en-us/windows/win32/secauthz/security-identifiers - https://learn.microsoft.com/en-us/windows/win32/secauthz/well-known-sids