Really strange error

2008-08-01 Thread Jonathan Hansen
Ok I am only mediocre at python so maybe this is a stupid mistake on  
my part, but I have exhausted my options from Google searches.

When I run the script below it binds successfully, but then when I try  
and run the search says it cannot contact the server. I have verified  
the service is running, ports are open, it binds without error so I am  
quite confused.

If someone could point at what I am doing wrong I would greatly  
appreciate it.

This may seem overly complicated but I am trying to build a framework  
with which I can run queries against the active directory domain.

Thanks in advance,

-Jonathan

Here is the output:

In [18]: run ldap-ad.py
ldap://my.company.example.com:389
Bind result: (97, []) <-- obviously a successful connection
Running search: (objectClass=user)(mail=*)
Can't contact LDAP server <-- now it can't connect

And here is the script:

#!/usr/bin/env python

import ldap, ldapurl, sys
# AD Hack
ldap.set_option(ldap.OPT_REFERRALS, 0)
ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3)

def handle_ldap_exception(e):
if type(e.message) == dict and e.message.has_key('info'):
if e.message['info'] != '':
print e.message['info']
if type(e.message) == dict and e.message.has_key('desc'):
if e.message['desc'] != '':
print e.message['desc']
else:
print e

def get_ldap_url(dns_name, proto = 'ldap', port=0):
if proto == 'ldap' and port == 0:
port = 389
elif proto =='ldaps' and port == 0:
port = 636
server = ldapurl.LDAPUrl(urlscheme=proto,
hostport="%s:%s" % (dns_name, 
str(port))).initializeUrl()
return server

base_dn = "cn=Users,dc=my,dc=company,dc=example,dc=com"
dn = '[EMAIL PROTECTED]'
pw = "itsasecret"

ad_conn = ldap.initialize(get_ldap_url("ad-dc.my.company.example.com",  
proto = 'ldap'))
try:
ad_conn.protocol_version = ldap.VERSION3
bind = ad_conn.simple_bind_s(dn, pw)
print "Bind result: " + str(bind)
except ldap.LDAPError, e:
handle_ldap_exception(e)
ad_conn.unbind_s()
sys.exit()  

search_email='(objectClass=user)(mail=*)'

res_attrs = ['*']

print "Running search: %s" % search_email

try:
res = ad_conn.search_s(base_dn, ldap.SCOPE_SUBTREE, search_email,  
res_attrs)
result_set = []
while True:
result_type, result_data = ad_conn.result(res, 0)
if (result_data == []):
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
print result_set
except ldap.LDAPError, e:
handle_ldap_exception(e)
ad_conn.unbind_s()
sys.exit()  

ad_conn.unbind_s()

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Python-LDAP-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev


Change password

2008-09-15 Thread Jonathan Hansen
Does anyone have a working password change script for active directory  
server that will run on Linux? We try and run as little as possible on  
windows.

I have found several but none actually run. I know I am committing  
list pho pa by asking this but I am an IT guy not a programmer so  
although am working on it do not yet have the skill to sort out stuff  
like this.

My attempt at a script authenticated fine but then when I tried to do  
a search or anything else claimed it was not able to talk to the  
server it had just authenticated against *sighs* I hate microsoft.

Thanks,

Jonathan

PS: my error in case anyone wants to help with that instead:

=> result: (97, [], 1, [])
Bind result: (97, [])
Running search: (objectClass=user)(mail=*)
*** ldap://my.ldap.server:389 - SimpleLDAPObject.search_ext  
(('cn=Users,my.dc', 2, '(objectClass=user)(mail=*)', ['*'], 0, None,  
None, -1, 0),{})
=> result: 2
*** ldap://my.ldap.server:389 - SimpleLDAPObject.result3 ((2, 1, -1),{})
=> LDAPError - SERVER_DOWN: {'info': '', 'desc': "Can't contact LDAP  
server"}
Can't contact LDAP server


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Python-LDAP-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev