from ..errors import DpxWriteLdapItemError
from ..xlate import XLATOR, format_list
-__version__ = '1.3.0'
+__version__ = '1.3.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
if self.verbose > 1:
LOG.debug(_('Using LDAP filter: {!r}').format(ldap_filter))
- if inst not in self.ldap_connection:
- self.connect_instance(inst)
- ldap = self.ldap_connection[inst]
-
- try:
- req_status, req_result, req_response, req_whatever = ldap.search(
- search_base=base_dn, search_scope=SUBTREE, search_filter=ldap_filter,
- get_operational_attributes=False, attributes=attributes,
- time_limit=self.cfg.ldap_timeout)
- finally:
- if not self.single_session:
- self.disconnect_instance(inst)
+ (search_status, search_result, search_response) = self.search(
+ inst, search_base=base_dn, ldap_filter=ldap_filter, attributes=attributes,
+ scope=scope)
- if req_status:
+ if search_status:
if self.verbose > 2:
msg = ngettext(
'Found one entry with filter {fltr!r} in {uri}/{bdn}.',
'Found {nr} entries with filter {fltr!r} in {uri}/{bdn}.',
- len(req_response)).format(
- nr=len(req_response), uri=connect_info.url, bdn=base_dn, fltr=ldap_filter)
+ len(search_response)).format(
+ nr=len(search_response), uri=connect_info.url, bdn=base_dn, fltr=ldap_filter)
LOG.debug(msg)
if self.verbose > 5:
msg = _('Result of searching for DNs of all entries:')
- LOG.debug(msg + '\n' + pp(req_result))
- for entry in req_response:
+ LOG.debug(msg + '\n' + pp(search_result))
+ for entry in search_response:
if self.verbose > 4:
LOG.debug(_('Got a response entry:') + ' ' + pp(entry))
result.append(entry['dn'])
return result
# -------------------------------------------------------------------------
- def get_all_entry_dns_hash(self, inst, ldap_filter=None):
+ def get_all_entry_dns_hash(self, inst, ldap_filter=None, base_dn=None):
"""Get Object classes and DNs of all entries in the given LDAP instance."""
connect_info = self.cfg.ldap_connection[inst]
- base_dn = connect_info.base_dn
+ if not base_dn:
+ base_dn = connect_info.base_dn
result = CIDict()
attributes = ['objectClass']
if self.verbose > 1:
LOG.debug(_('Using LDAP filter: {!r}').format(ldap_filter))
- if inst not in self.ldap_connection:
- self.connect_instance(inst)
- ldap = self.ldap_connection[inst]
-
- try:
- req_status, req_result, req_response, req_whatever = ldap.search(
- search_base=base_dn, search_scope=SUBTREE, search_filter=ldap_filter,
- get_operational_attributes=False, attributes=attributes,
- time_limit=self.cfg.ldap_timeout)
- finally:
- if not self.single_session:
- self.disconnect_instance(inst)
+ (search_status, search_result, search_response) = self.search(
+ inst, search_base=base_dn, ldap_filter=ldap_filter, attributes=attributes)
- if req_status:
+ if search_status:
if self.verbose > 5:
msg = _('Result of searching for DNs of all entries:')
- LOG.debug(msg + '\n' + pp(req_result))
- for entry in req_response:
+ LOG.debug(msg + '\n' + pp(search_result))
+ for entry in search_response:
if self.verbose > 4:
LOG.debug(_('Got a response entry:') + ' ' + pp(entry))
}
else:
- LOG.warn('Got no entry DNs.')
+ LOG.warn(_('Got no entry DNs.'))
return result