def __init__(self, distinguished_name=None, adsi_ldap_com_object=None, options={}): if adsi_ldap_com_object: self._ldap_adsi_obj = adsi_ldap_com_object elif distinguished_name: self._set_defaults(options) self.__ads_path = pyadutils.generate_ads_path( distinguished_name, self.default_ldap_protocol, self.default_ldap_server, self.default_ldap_port) self.__set_adsi_obj() else: raise Exception( "Either a distinguished name or a COM object must be provided to create an ADObject" ) # by pulling the DN from object instead of what is passed in, # we guarantee correct capitalization self.__distinguished_name = self.get_attribute('distinguishedName', False) self.__object_guid = self.get_attribute('objectGUID', False) if self.__object_guid is not None: self.__object_guid = pyadutils.convert_guid(self.__object_guid) # Set pyAD Object Type occn = self.get_attribute('objectCategory', False) if occn: # pull out CN from DN object_category_cn = occn.split('=', 1)[1].split(",", 1)[0] # some object categories are not very human readable # so we provide the option to override if object_category_cn in PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS: self._type = PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS[ object_category_cn] else: self._type = object_category_cn.lower() else: # Sometimes you don't have access to objectCategory attribute, # try, with objectClass attribute objClass = self.get_attribute('objectClass', True) if 'domain' in objClass: self._type = 'domain' elif 'user' in objClass: self._type = 'user' elif 'organizationalUnit' in objClass: self._type = 'organizationalUnit' else: self._type = 'unknown'
def __init__(self, distinguished_name=None, adsi_ldap_com_object=None, options={}): if adsi_ldap_com_object: self._ldap_adsi_obj = adsi_ldap_com_object elif distinguished_name: self._set_defaults(options) self.__ads_path = pyadutils.generate_ads_path(distinguished_name, self.default_ldap_protocol, self.default_ldap_server, self.default_ldap_port ) self.__set_adsi_obj() else: raise Exception("Either a distinguished name or a COM object must be provided to create an ADObject") # by pulling the DN from object instead of what is passed in, # we guarantee correct capitalization self.__distinguished_name = self.get_attribute('distinguishedName', False) self.__object_guid = self.get_attribute('objectGUID', False) if self.__object_guid is not None: self.__object_guid = pyadutils.convert_guid(self.__object_guid) # Set pyAD Object Type occn = self.get_attribute('objectCategory',False) if occn: # pull out CN from DN object_category_cn = occn.split('=',1)[1].split(",",1)[0] # some object categories are not very human readable # so we provide the option to override if object_category_cn in PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS: self._type = PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS[object_category_cn] else: self._type = object_category_cn.lower() else: # Sometimes you don't have access to objectCategory attribute, # try, with objectClass attribute objClass = self.get_attribute('objectClass',True) if 'domain' in objClass: self._type = 'domain' elif 'user' in objClass: self._type = 'user' elif 'organizationalUnit' in objClass: self._type = 'organizationalUnit' else: self._type = 'unknown'
except pywintypes.com_error, excpt: additional_info = { 'distinguished_name': distinguished_name, 'server': self.default_ldap_server, 'port': self.default_ldap_port } pyadutils.pass_up_com_exception(excpt, additional_info) else: raise Exception( "Either a distinguished name or a COM object must be provided to create an ADObject" ) # by pulling the DN from object instead of what is passed in, we gaurantee correct capitalization self.__distinguished_name = self.get_attribute('distinguishedName', False) self.__object_guid = pyadutils.convert_guid( self.get_attribute('objectGUID', False)) # Set pyAD Object Type occn = self.get_attribute('objectCategory', False) if occn: # pull out CN from DN object_category_cn = occn.split('=', 1)[1].split(",", 1)[0] # some object categories are not very human readable so we provide the option to override if object_category_cn in PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS: self._type = PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS[ object_category_cn] else: self._type = object_category_cn.lower() else: self._type = 'unknown' @classmethod
self.__ads_path = pyadutils.generate_ads_path(distinguished_name, 'LDAP', self.default_ldap_server, self.default_ldap_port) try: self._ldap_adsi_obj = self.adsi_provider.getObject('',self.__ads_path) except pywintypes.com_error, excpt: additional_info = { 'distinguished_name':distinguished_name, 'server':self.default_ldap_server, 'port':self.default_ldap_port } pyadutils.pass_up_com_exception(excpt, additional_info) else: raise Exception("Either a distinguished name or a COM object must be provided to create an ADObject") # by pulling the DN from object instead of what is passed in, we gaurantee correct capitalization self.__distinguished_name = self.get_attribute('distinguishedName', False) self.__object_guid = pyadutils.convert_guid(self.get_attribute('objectGUID', False)) # Set pyAD Object Type occn = self.get_attribute('objectCategory',False) if occn: # pull out CN from DN object_category_cn = occn.split('=',1)[1].split(",",1)[0] # some object categories are not very human readable so we provide the option to override if object_category_cn in PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS: self._type = PYAD_CATEGORY_TYPE_OVERRIDE_MAPPPINGS[object_category_cn] else: self._type = object_category_cn.lower() else: self._type = 'unknown' @classmethod def from_guid(cls, guid, options={}):