Added type() method to determine type of Directory (e.g. eDirectory)

master
nanu2 2014-09-25 10:26:09 +02:00
parent 0f398f4458
commit f19ca67500
3 changed files with 20 additions and 8 deletions

View File

@ -6,15 +6,13 @@ Changelog
**Improvements** **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 - Added verify_password(dn, password) method
**Bugfixes**
- Added escape_filter_chars() to filter (sanitize) the filter - 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 - 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) - Wrestling with pypi (needs a new version number even if you've made a mistake by uploading rubbish)

View File

@ -9,7 +9,7 @@ class Connection(object):
self.search_base = search_base self.search_base = search_base
if port == '': if port == '':
port = 389 if protocol == 'ldap' else 636 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: try:
ldap.set_option(ldap.OPT_REFERRALS, 0) ldap.set_option(ldap.OPT_REFERRALS, 0)
if not verify: if not verify:
@ -19,6 +19,21 @@ class Connection(object):
except: except:
raise 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): def search(self, search_filter):
"""Get list of objects that match the 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 = ldap.initialize(self.ldap_url)
test_conn.simple_bind_s(dn, password) test_conn.simple_bind_s(dn, password)
test_conn.unbind_s() test_conn.unbind_s()
return True
except ldap.LDAPError: except ldap.LDAPError:
return False return False
return True
def close(self): def close(self):
self.conn.unbind_s() self.conn.unbind_s()

View File

@ -1,5 +1,4 @@
import unittest import unittest
import ldap
from ldappr import connect_to from ldappr import connect_to