# rom ..config.ldap import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS
from ..config.ldap import DEFAULT_TIMEOUT
-__version__ = '0.11.1'
+__version__ = '0.11.2'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
continue
filtered_instances.append(inst.lower())
+ if self.verbose > 2:
+ LOG.debug(_("Filtered instances:") + ' ' + pp(filtered_instances))
+
self._validate_given_instances(filtered_instances)
if self.verbose > 1:
LOG.debug(_("Disconnecting from LDAP server {!r} ...").format(connect_info.url))
del self.ldap_server[inst]
+ # -------------------------------------------------------------------------
+ def get_all_entries(self, inst, base_dn=None, ldap_filter=None, attributes=None):
+ """Get all LDAP entries bellow the given BaseDN and the given LDAP filter.
+ If no attributes are given, all attributes are given back.
+ The result is a hash with the DNs if the resulting entries as keys, and a hash
+ with the resulting attributes as values.
+ """
+ connect_info = self.cfg.ldap_connection[inst]
+ ldap = self.ldap_connection[inst]
+
+ result = {}
+
+ if not base_dn:
+ base_dn = connect_info.base_dn
+ if attributes is None:
+ attributes = [ALL_ATTRIBUTES]
+ if ldap_filter is None:
+ ldap_filter = '(objectClass=*)'
+
+ if self.verbose > 2:
+ msg = _(
+ "Searching in {uri}/{bdn} for all entries with filter {fltr!r}, "
+ "giving attributes:").format(uri=connect_info.url, bdn=base_dn, fltr=ldap_filter)
+ msg += ' ' + format_list(attributes, do_repr=True)
+ LOG.debug(msg)
+
+ req_status, req_result, req_response, req_whatever = ldap.search(
+ search_base=base_dn, search_scope=SUBTREE, attributes=attributes,
+ search_filter=ldap_filter, time_limit=self.cfg.ldap_timeout)
+
+ if req_status:
+ if self.verbose > 4:
+ LOG.debug(_("Result of searching:") + '\n' + pp(req_result))
+
+ for entry in req_response:
+ dn = entry['dn']
+ if self.verbose > 3:
+ LOG.debug(_("Found entry {!r}.").format(dn))
+ result[dn] = self.normalized_attributes(entry)
+
+ if self.verbose > 2:
+ msg = ngettext(
+ "Found one entry with filter {fltr!r} in {uri}/{bdn}.",
+ "Found {nr} enries with filter {fltr!r} in {uri}/{bdn}.",
+ len(result)).format(nr=len(result), uri=connect_info.url,
+ bdn=base_dn, fltr=ldap_filter)
+ LOG.debug(msg)
+ if self.verbose > 4:
+ LOG.debug(_("Got response entries:") + '\n' + pp(result))
+
+ else:
+ if self.verbose > 3:
+ msg = _("No entry found with filter {fltr!r} in {uri}/{bdn}.").format(
+ uri=connect_info.url, bdn=base_dn, fltr=ldap_filter)
+ LOG.debug(msg)
+
+ return result
+
# -------------------------------------------------------------------------
def get_all_entry_dns(self, inst, ldap_filter=None):
"""Get DNs of all entries in the given LDAP instance and sort them."""
ldap = self.ldap_connection[inst]
result = []
+
attributes = ['dn']
if not ldap_filter:
ldap_filter = '(objectClass=*)'