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

Chris Gray fathed at gmail.com
Sat Dec 8 03:04:16 CET 2012


Yeah, I was checking that, but since the empty password was working, I
switched it to catch all exceptions. None were triggered. I might just end
up using the com objects, as I'm in windows land anyway. Looking at the
ldap library code, this might be an OpenLDAP issue more so than an issue
with the python-ldap library.


On Fri, Dec 7, 2012 at 5:39 PM, Tom Tucker <tktucker at gmail.com> wrote:

>
> If you figure this out, please let me know. ;-)
> I check for credentials issues with 'except ldap.INVALID_CREDENTIALS'
> after attempting an add, delete, etc activity.
>
>
> On Fri, Dec 7, 2012 at 5:51 PM, Chris Gray <fathed at gmail.com> wrote:
>
>> 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)
>>
>> _______________________________________________
>> python-ldap mailing list
>> python-ldap at python.org
>> http://mail.python.org/mailman/listinfo/python-ldap
>>
>>
>


-- 
Intelligence is a matter of opinion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20121207/cb6fa024/attachment.html>


More information about the python-ldap mailing list