def search(self, base, filter, scope, attributes): '''Perform a paged search but return all of the results in one hit''' logger.debug( 'SmartLDAPSearcher.search called with base={}, filter={}, scope={} and attributes={}' .format(str(base), str(filter), str(scope), str(attributes))) connection = self.get_connection() connection.search(search_base=base, search_filter=filter, search_scope=scope, attributes=attributes, paged_size=self.page_size, paged_cookie=None) logger.debug('Connection.search.response is: {}'.format( connection.response)) results = connection.response if len(connection.response) > self.page_size: cookie = connection.result['controls']['1.2.840.113556.1.4.319'][ 'value']['cookie'] while cookie: connection.search( search_base=base, search_filter=filter, search_scope=ldap3.SEARCH_SCOPE_WHOLE_SUBTREE, attributes=attributes, paged_size=self.page_size, paged_cookie=cookie) results += connection.response cookie = connection.result['controls'][ '1.2.840.113556.1.4.319']['value']['cookie'] return results
def get(self, dn, attributes=[]): '''Return the object referenced by the given dn or return None''' # break the dn down and get a base from it search_base = ','.join(dn.split(',')[1:]) connection = self.get_connection() connection.search(search_base=search_base, search_filter='(distinguishedName={})'.format(dn), search_scope=ldap3.SEARCH_SCOPE_SINGLE_LEVEL, attributes=attributes) results = connection.response if len(results) > 1: raise MultipleLDAPResultsReturned() elif len(results) == 0: return None else: return results[0]
def search(self, base, filter, scope, attributes): '''Perform a paged search but return all of the results in one hit''' logger.debug('SmartLDAPSearcher.search called with base={}, filter={}, scope={} and attributes={}'.format(str(base), str(filter), str(scope), str(attributes))) connection = self.get_connection() connection.search(search_base=base, search_filter=filter, search_scope=scope, attributes=attributes, paged_size=self.page_size, paged_cookie=None) logger.debug('Connection.search.response is: {}'.format(connection.response)) results = connection.response if len(connection.response) > self.page_size: cookie = connection.result['controls']['1.2.840.113556.1.4.319']['value']['cookie'] while cookie: connection.search(search_base=base, search_filter=filter, search_scope=ldap3.SEARCH_SCOPE_WHOLE_SUBTREE, attributes=attributes, paged_size=self.page_size, paged_cookie=cookie) results += connection.response cookie = connection.result['controls']['1.2.840.113556.1.4.319']['value']['cookie'] return results