View | Details | Raw Unified | Return to bug 49638
Collapse All | Expand All

(-)a/base/univention-python/modules/uldap.py (-6 / +19 lines)
 Lines 417-423   class access: Link Here 
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.
 Lines 445-452   class access: Link Here 
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
 Lines 454-460   class access: Link Here 
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'})
 Lines 462-468   class access: Link Here 
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.
 Lines 482-488   class access: Link Here 
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]]
(-)a/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py (-2 / +2 lines)
 Lines 1691-1697   class simpleLdap(object): Link Here 
1691
		return containers
1691
		return containers
1692
1692
1693
	@classmethod
1693
	@classmethod
1694
	def lookup(cls, co, lo, filter_s, base='', superordinate=None, scope='sub', unique=False, required=False, timeout=-1, sizelimit=0):  # type: (univention.admin.uldap.config, univention.admin.uldap.access, str, str, Optional[str], str, bool, bool, int, int) -> list[simpleLdap]
1694
	def lookup(cls, co, lo, filter_s, base='', superordinate=None, scope='sub', unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None, response=None):  # type: (univention.admin.uldap.config, univention.admin.uldap.access, str, str, Optional[str], str, bool, bool, int, int) -> list[simpleLdap]
1695
		"""
1695
		"""
1696
		Perform a LDAP search and return a list of instances.
1696
		Perform a LDAP search and return a list of instances.
1697
1697
 Lines 1714-1720   class simpleLdap(object): Link Here 
1714
		filter_str = unicode(filter_s or '')
1714
		filter_str = unicode(filter_s or '')
1715
		attr = cls._ldap_attributes()
1715
		attr = cls._ldap_attributes()
1716
		result = []
1716
		result = []
1717
		for dn, attrs in lo.search(filter_str, base, scope, attr, unique, required, timeout, sizelimit):
1717
		for dn, attrs in lo.search(filter_str, base, scope, attr, unique, required, timeout, sizelimit, serverctrls=serverctrls, response=response):
1718
			try:
1718
			try:
1719
				result.append(cls(co, lo, None, dn=dn, superordinate=superordinate, attributes=attrs))
1719
				result.append(cls(co, lo, None, dn=dn, superordinate=superordinate, attributes=attrs))
1720
			except univention.admin.uexceptions.base as exc:
1720
			except univention.admin.uexceptions.base as exc:
(-)a/management/univention-directory-manager-modules/modules/univention/admin/uldap.py (-4 / +4 lines)
 Lines 722-728   class access: Link Here 
722
		"""
722
		"""
723
		return self.lo.getAttr(dn, attr, required)
723
		return self.lo.getAttr(dn, attr, required)
724
724
725
	def search(self, filter='(objectClass=*)', base='', scope='sub', attr=[], unique=False, required=False, timeout=-1, sizelimit=0):
725
	def search(self, filter='(objectClass=*)', base='', scope='sub', attr=[], unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None, response=None):
726
		# type: (str, str, str, List[str], bool, bool, int, int) -> List[Tuple[str, Dict[str, List[str]]]]
726
		# type: (str, str, str, List[str], bool, bool, int, int) -> List[Tuple[str, Dict[str, List[str]]]]
727
		"""
727
		"""
728
		Perform LDAP search and return values.
728
		Perform LDAP search and return values.
 Lines 747-753   class access: Link Here 
747
		:raises univention.admin.uexceptions.ldapError: on any other LDAP error.
747
		:raises univention.admin.uexceptions.ldapError: on any other LDAP error.
748
		"""
748
		"""
749
		try:
749
		try:
750
			return self.lo.search(filter, base, scope, attr, unique, required, timeout, sizelimit)
750
			return self.lo.search(filter, base, scope, attr, unique, required, timeout, sizelimit, serverctrls=serverctrls, response=response)
751
		except ldap.NO_SUCH_OBJECT as msg:
751
		except ldap.NO_SUCH_OBJECT as msg:
752
			raise univention.admin.uexceptions.noObject(_err2str(msg))
752
			raise univention.admin.uexceptions.noObject(_err2str(msg))
753
		except ldap.INAPPROPRIATE_MATCHING as msg:
753
		except ldap.INAPPROPRIATE_MATCHING as msg:
 Lines 763-769   class access: Link Here 
763
		except ldap.LDAPError as msg:
763
		except ldap.LDAPError as msg:
764
			raise univention.admin.uexceptions.ldapError(_err2str(msg), original_exception=msg)
764
			raise univention.admin.uexceptions.ldapError(_err2str(msg), original_exception=msg)
765
765
766
	def searchDn(self, filter='(objectClass=*)', base='', scope='sub', unique=False, required=False, timeout=-1, sizelimit=0):
766
	def searchDn(self, filter='(objectClass=*)', base='', scope='sub', unique=False, required=False, timeout=-1, sizelimit=0, serverctrls=None, response=None):
767
		# type: (str, str, str, bool, bool, int, int) -> List[str]
767
		# type: (str, str, str, bool, bool, int, int) -> List[str]
768
		"""
768
		"""
769
		Perform LDAP search and return distinguished names only.
769
		Perform LDAP search and return distinguished names only.
 Lines 788-794   class access: Link Here 
788
		:raises univention.admin.uexceptions.ldapError: on any other LDAP error.
788
		:raises univention.admin.uexceptions.ldapError: on any other LDAP error.
789
		"""
789
		"""
790
		try:
790
		try:
791
			return self.lo.searchDn(filter, base, scope, unique, required, timeout, sizelimit)
791
			return self.lo.searchDn(filter, base, scope, unique, required, timeout, sizelimit, serverctrls=serverctrls, response=response)
792
		except ldap.NO_SUCH_OBJECT as msg:
792
		except ldap.NO_SUCH_OBJECT as msg:
793
			raise univention.admin.uexceptions.noObject(_err2str(msg))
793
			raise univention.admin.uexceptions.noObject(_err2str(msg))
794
		except ldap.INAPPROPRIATE_MATCHING as msg:
794
		except ldap.INAPPROPRIATE_MATCHING as msg:

Return to bug 49638