Skip to content

Instantly share code, notes, and snippets.

@truekonrads
Created July 5, 2012 13:23
Show Gist options
  • Select an option

  • Save truekonrads/3053616 to your computer and use it in GitHub Desktop.

Select an option

Save truekonrads/3053616 to your computer and use it in GitHub Desktop.
Get objectSID from AD/LDAP and convert it to traditional string SID
searchFilter="(&(objectClass=group)(distinguishedName=%s))" % (groupName)
res=self.search(searchFilter,["objectSid"])
rawsid=res[0]['objectSid']
objectSid=win32security.ConvertSidToStringSid(pywintypes.SID(rawsid))
primaryGroupID=objectSid.split("-")[-1]
logging.log(logging.DEBUG,"objectSid: %s, RID: %s" % (objectSid,primaryGroupID))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment