|
417 |
raise ldap.NO_SUCH_OBJECT({'desc': 'no object'}) |
417 |
raise ldap.NO_SUCH_OBJECT({'desc': 'no object'}) |
418 |
return [] |
418 |
return [] |
419 |
|
419 |
|
420 |
def search(self, filter='(objectClass=*)', base='', scope='sub', attr=[], unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None): |
420 |
def search(self, filter='(objectClass=*)', base='', scope='sub', attr=[], unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None, response=None): |
421 |
# type: (str, str, str, List[str], bool, bool, int, int, Optional[List[ldap.controls.LDAPControl]]) -> List[Tuple[str, Dict[str, List[str]]]] |
421 |
# type: (str, str, str, List[str], bool, bool, int, int, Optional[List[ldap.controls.LDAPControl]]) -> List[Tuple[str, Dict[str, List[str]]]] |
422 |
""" |
422 |
""" |
423 |
Perform LDAP search and return values. |
423 |
Perform LDAP search and return values. |
|
445 |
base = self.base |
445 |
base = self.base |
446 |
|
446 |
|
447 |
if scope == 'base+one': |
447 |
if scope == 'base+one': |
448 |
res = self.lo.search_ext_s(base, ldap.SCOPE_BASE, filter, attr, serverctrls=serverctrls, clientctrls=None, timeout=timeout, sizelimit=sizelimit) + \ |
448 |
res = self.__search(response, base, ldap.SCOPE_BASE, filter, attr, serverctrls=serverctrls, clientctrls=None, timeout=timeout, sizelimit=sizelimit) + \ |
449 |
self.lo.search_ext_s(base, ldap.SCOPE_ONELEVEL, filter, attr, serverctrls=serverctrls, clientctrls=None, timeout=timeout, sizelimit=sizelimit) |
449 |
self.__search(response, base, ldap.SCOPE_ONELEVEL, filter, attr, serverctrls=serverctrls, clientctrls=None, timeout=timeout, sizelimit=sizelimit) |
450 |
else: |
450 |
else: |
451 |
if scope == 'sub' or scope == 'domain': |
451 |
if scope == 'sub' or scope == 'domain': |
452 |
ldap_scope = ldap.SCOPE_SUBTREE |
452 |
ldap_scope = ldap.SCOPE_SUBTREE |
|
454 |
ldap_scope = ldap.SCOPE_ONELEVEL |
454 |
ldap_scope = ldap.SCOPE_ONELEVEL |
455 |
else: |
455 |
else: |
456 |
ldap_scope = ldap.SCOPE_BASE |
456 |
ldap_scope = ldap.SCOPE_BASE |
457 |
res = self.lo.search_ext_s(base, ldap_scope, filter, attr, serverctrls=serverctrls, clientctrls=None, timeout=timeout, sizelimit=sizelimit) |
457 |
res = self.__search(response, base, ldap_scope, filter, attr, serverctrls=serverctrls, clientctrls=None, timeout=timeout, sizelimit=sizelimit) |
458 |
|
458 |
|
459 |
if unique and len(res) > 1: |
459 |
if unique and len(res) > 1: |
460 |
raise ldap.INAPPROPRIATE_MATCHING({'desc': 'more than one object'}) |
460 |
raise ldap.INAPPROPRIATE_MATCHING({'desc': 'more than one object'}) |
|
462 |
raise ldap.NO_SUCH_OBJECT({'desc': 'no object'}) |
462 |
raise ldap.NO_SUCH_OBJECT({'desc': 'no object'}) |
463 |
return res |
463 |
return res |
464 |
|
464 |
|
465 |
def searchDn(self, filter='(objectClass=*)', base='', scope='sub', unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None): |
465 |
def __search(self, response, *args, **kwargs): |
|
|
466 |
try: |
467 |
rtype, rdata, rmsgid, resp_ctrls = self.lo.result3(self.lo.search_ext(*args, **kwargs)) |
468 |
except ldap.REFERRAL as exc: |
469 |
if not self.follow_referral: |
470 |
raise |
471 |
lo_ref = self._handle_referral(exc) |
472 |
rtype, rdata, rmsgid, resp_ctrls = lo_ref.result3(lo_ref.search_ext(*args, **kwargs)) |
473 |
|
474 |
if kwargs.get('serverctrls') and isinstance(response, dict): |
475 |
response['ctrls'] = resp_ctrls |
476 |
return rdata |
477 |
|
478 |
def searchDn(self, filter='(objectClass=*)', base='', scope='sub', unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None, response=None): |
466 |
# type: (str, str, str, bool, bool, int, int, Optional[List[ldap.controls.LDAPControl]]) -> List[str] |
479 |
# type: (str, str, str, bool, bool, int, int, Optional[List[ldap.controls.LDAPControl]]) -> List[str] |
467 |
""" |
480 |
""" |
468 |
Perform LDAP search and return distinguished names only. |
481 |
Perform LDAP search and return distinguished names only. |
|
482 |
:raises ldap.INAPPROPRIATE_MATCHING: Indicates that the matching rule specified in the search filter does not match a rule defined for the attribute's syntax. |
495 |
:raises ldap.INAPPROPRIATE_MATCHING: Indicates that the matching rule specified in the search filter does not match a rule defined for the attribute's syntax. |
483 |
""" |
496 |
""" |
484 |
_d = univention.debug.function('uldap.searchDn filter=%s base=%s scope=%s unique=%d required=%d' % (filter, base, scope, unique, required)) # noqa F841 |
497 |
_d = univention.debug.function('uldap.searchDn filter=%s base=%s scope=%s unique=%d required=%d' % (filter, base, scope, unique, required)) # noqa F841 |
485 |
return [x[0] for x in self.search(filter, base, scope, ['dn'], unique, required, timeout, sizelimit, serverctrls)] |
498 |
return [x[0] for x in self.search(filter, base, scope, ['dn'], unique, required, timeout, sizelimit, serverctrls, response)] |
486 |
|
499 |
|
487 |
def getPolicies(self, dn, policies=None, attrs=None, result=None, fixedattrs=None): |
500 |
def getPolicies(self, dn, policies=None, attrs=None, result=None, fixedattrs=None): |
488 |
# type: (str, List[str], Dict[str, List[Any]], Any, Any) -> Dict[str, Dict[str, Any]] |
501 |
# type: (str, List[str], Dict[str, List[Any]], Any, Any) -> Dict[str, Dict[str, Any]] |