Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ldap connection test using python Django

I am using below code to test ldap connection but its getting failed with 'info': 'Invalid DN syntax', 'desc': 'Invalid DN syntax'}.

import ldap
AD_LDAP_URL = 'ldap://test.example.com'
username = 'User'
password = 'PassWord'
try:
  ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
  l = ldap.initialize(AD_LDAP_URL)
  l.simple_bind_s(username, password)
except ldap.NO_SUCH_OBJECT, e:
  print "Auth error: No user "
except ldap.INVALID_CREDENTIALS, e:
  print 'error'
except ldap.LDAPError, e:
  print e
like image 653
tempuser Avatar asked Apr 09 '26 08:04

tempuser


1 Answers

This happens because you should send DN of the user to bind method (or simple_bind_s), not just the username. A example of valid DN - cn=user,dc=example,dc=com

P.S. You can use some tools for easier navigation in your LDAP (for example jXplorer allows to copy DN of an object).

like image 109
Akisame Avatar answered Apr 11 '26 23:04

Akisame



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!