Created
September 3, 2014 14:53
-
-
Save gcavalcante8808/bf36ef2aa32d110ddd18 to your computer and use it in GitHub Desktop.
A simple recipe to read objectGUID field from an active directory object on django-ldapdb.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ldapdb.models.fields import CharField | |
from uuid import UUID | |
def guid2string(val): | |
""" convert an active directory binary objectGUID value as returned by | |
python-ldap into a string that can be used as an LDAP query value """ | |
s = UUID(bytes_le=val) | |
return s | |
class GUIDField(CharField): | |
""" | |
Field with support for Binary objectGUID support on ActiveDirectory. | |
""" | |
def from_ldap(self, value, connection): | |
if len(value) == 0: | |
return '' | |
else: | |
return guid2string(value[0]) | |
class LdapComputer(ldapdb.models.Model): | |
base_dn = "dc=X,dc=X" | |
object_classes = ['computer'] | |
id = GUIDField(db_column='objectGUID', unique=True, primary_key=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment