[python-ldap] simple_bind_s, no exception on empty password

Chris Gray fathed at gmail.com
Fri Dec 7 23:51:34 CET 2012


Hey everyone, I have a question with simple_bind_s.

The code below, if passing in the wrong password, will return 1 as the exit
code. It will return 0 if the bind is successful. That's pretty much all I
need it to do.

My problem is, if I just hit enter on the getpass() prompt, my exit code
ends up being 0 anyway.

Changing the bind line to ldap_conn.simple_bind_s(ldap_user, "") has the
same effect, no exception thrown. That seems to do not even try to do the
bind, but the lack of exception doesn't seem to be the right behavior
either.

Variable data is changed to protect... or some reason.

Any suggestions?
Thanks!
Chris


import sys
import ldap
import getpass


ldap_user = sys.argv[1]
ldap_pass = getpass.getpass()
#if ldap_pass == "":
# ldap_pass = "badpassword"

ldap_conn = ldap.initialize('ldap://domaincontroller.fqdn')
ldap_conn.protocol_version = 3
ldap_conn.set_option(ldap.OPT_REFERRALS, 0)

ldap_domains = ['domain1',
                'domain2',
                'domain3',
                'domain4',
                'domain5',
                'domain6',
                'domain7']

for domain in ldap_domains:
try:
ldap_user += '@' + domain
ldap_conn.simple_bind_s(ldap_user, ldap_pass)
sys.exit(0)
except Exception:
pass

sys.exit(1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20121207/c7961b7b/attachment.html>


More information about the python-ldap mailing list