+ test_dn = config['base dn']
+ else:
+ # default set in the config object
+ test_dn = 'dc=example,dc=com'
+
+ # Test the LDAP connection anonymously
+ try:
+ lh = ldap_connect(config['server url'], config['tls'])
+ lh.simple_bind_s('', '')
+ lh.search_s(test_dn, ldap.SCOPE_BASE,
+ attrlist=['objectclasses'])
+ except ldap.INSUFFICIENT_ACCESS:
+ logging.warn('Anonymous access not allowed, continuing')
+ except ldap.UNWILLING_TO_PERFORM: # probably minSSF issue
+ logging.warn('LDAP server unwilling to perform, expect issues')
+ except ldap.SERVER_DOWN:
+ logging.warn('LDAP server is down')
+ except ldap.NO_SUCH_OBJECT:
+ logging.error('Base DN not found')
+ return False
+ except ldap.LDAPError as e:
+ logging.error(e)
+ return False
+