diff --git a/CHANGES.rst b/CHANGES.rst index 34f9dad..9c70372 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,15 +6,13 @@ Changelog **Improvements** +- Added type() method to determine type of Directory (e.g. eDirectory, Active Directory): will be used later for type specific subclasses - Added verify_password(dn, password) method - -**Bugfixes** - - Added escape_filter_chars() to filter (sanitize) the filter - Override of cidicts __getitem__ so that user.attrs['nonexistent'] won't raise an exception, but instead returns an empty list -0.1.3 and 0.1.4 -+++++++++++++++ +0.1.3 and 0.1.4 (2014-09-16) +++++++++++++++++++++++++++++ - Wrestling with pypi (needs a new version number even if you've made a mistake by uploading rubbish) diff --git a/ldappr/connection.py b/ldappr/connection.py index 49a4b94..abb8a4f 100644 --- a/ldappr/connection.py +++ b/ldappr/connection.py @@ -9,7 +9,7 @@ class Connection(object): self.search_base = search_base if port == '': port = 389 if protocol == 'ldap' else 636 - self.ldap_url = '%s://%s:%s' % (protocol, server, str(port)) + self.ldap_url = '{}://{}:{}'.format(protocol, server, str(port)) try: ldap.set_option(ldap.OPT_REFERRALS, 0) if not verify: @@ -19,6 +19,21 @@ class Connection(object): except: raise + def type(self): + result = self.conn.search_s('', ldap.SCOPE_BASE, + attrlist=['objectClass', 'vendorName', + 'supportedCapabilities']) + rootDSE = LdapprObject(result[0], self.conn) + if rootDSE.attrs['vendorName'] == ['Novell, Inc.']: + return 'eDirectory' + if '1.2.840.113556.1.4.800' in rootDSE.attrs['supportedCapabilities']: + return 'Active Directory' + if rootDSE.attrs['vendorName'] == ['Apache Software Foundation']: + return 'Apache DS' + if 'OpenLDAProotDSE' in rootDSE.attrs['objectClass']: + return 'OpenLDAP' + return 'Unknown' + def search(self, search_filter): """Get list of objects that match the search_filter @@ -89,9 +104,9 @@ class Connection(object): test_conn = ldap.initialize(self.ldap_url) test_conn.simple_bind_s(dn, password) test_conn.unbind_s() - return True except ldap.LDAPError: return False + return True def close(self): self.conn.unbind_s() diff --git a/ldappr/test/test_ldappr.py b/ldappr/test/test_ldappr.py index 49a7336..23a00ee 100644 --- a/ldappr/test/test_ldappr.py +++ b/ldappr/test/test_ldappr.py @@ -1,5 +1,4 @@ import unittest -import ldap from ldappr import connect_to