def resolve_sid(self, sid): """ Two cases: * the SID is a WELL KNOWN SID and a local SID, the name of the corresponding account is returned; * else, the SID is search through the LDAP and the corresponding record is returned. @sid: the sid to search for. @throw ActiveDirectoryInvalidSID if the SID is not a valid SID. @return the record corresponding to the SID queried. """ if sid in WELL_KNOWN_SIDs: return WELL_KNOWN_SIDs[sid] elif validate_sid(sid): results = self.query(f"(&(ObjectSid={sid}))") if results: return results raise self.ActiveDirectoryInvalidSID(f"SID: {sid}")
def resolve_sid(self, sid): """ Two cases: * the SID is a WELL KNOWN SID and a local SID, the name of the corresponding account is returned; * else, the SID is search through the cache and the corresponding record is returned. @sid: the sid to search for. @throw ActiveDirectoryInvalidSID if the SID is not a valid SID. @return the record corresponding to the SID queried. """ if sid in WELL_KNOWN_SIDs: return WELL_KNOWN_SIDs[sid] elif validate_sid(sid): results = self.query({ "fmt": "json", "files": ["users_all", "groups", "machines"], "filter": lambda x: x["objectSid"] == sid }) if results: return results raise self.ActiveDirectoryInvalidSID(f"SID: {sid}")