<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16850" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=305484018-23062009>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I have a query that was written in
python (2.5) utilizing the python-ldap package (newest stable version for both
Windows and Linux) to query an Active Directory server for a user’s group
membership.<SPAN style="mso-spacerun: yes"> </SPAN>The code works fine on
my test machine (2-3 seconds for result) which is Windows based but when I move
the code over and run it on our production Linux (Ubuntu 8.10) server the query
hangs for exactly 5 minutes and then displays the results.<SPAN
style="mso-spacerun: yes"> </SPAN>Does anyone have any ideas where this
delay might be coming from and how I can resolve the issue? <?xml:namespace
prefix = o ns = "urn:schemas-microsoft-com:office:office"
/><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The code is (please note I replaced
some real data i.e. login, password, etc with “????” but in my code real names
are there):<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=FR
style="mso-ansi-language: FR"><FONT size=3><FONT
face="Times New Roman">#!/usr/bin/envpython<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=FR
style="mso-ansi-language: FR"><FONT size=3><FONT face="Times New Roman">import
ldap<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=FR
style="mso-ansi-language: FR"><FONT size=3><FONT face="Times New Roman">import
ldap.sasl<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=FR
style="mso-ansi-language: FR"><FONT size=3><FONT face="Times New Roman">import
sys<o:p></o:p></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN lang=FR
style="mso-ansi-language: FR"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">server =
'ldap://10.200.1.10'<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">user_id = ????<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">pw = ????<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">def main():<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN style="mso-spacerun: yes">
</SPAN>try:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes"> </SPAN>con
= ldap.initialize(server)<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>con.simple_bind_s(user_id, pw)<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print 'Connection Made'<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN style="mso-spacerun: yes">
</SPAN>except ldap.INVALID_CREDENTIALS:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print "Your username or password is
incorrect."<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>sys.exit()<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN style="mso-spacerun: yes">
</SPAN>except ldap.LDAPError, e:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes"> </SPAN>if
type(e.message) == dict and
e.message.has_key('desc'):<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print 'Error - ' + e.message['desc']<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>else:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print 'Error - ' + str(e)<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>sys.exit()<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN style="mso-spacerun: yes">
</SPAN>finally:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print 'Connected'<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>try:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>#con.timeout = 10<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>#con.network_timeout = 10<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>base_dn = 'dc=mariner,dc=local'<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>filter =
"(memberOf=CN=????,CN=Users,DC=????,DC=local)"<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>attrs =
['sn','mail','cn','sAMAccountName','displayName','memberOf']<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>timeout = 3<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>results = con.search_s(base_dn, ldap.SCOPE_SUBTREE, filter,
attrs)<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>for dn,entry in results:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>if dn != None:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print 'Processing',repr(dn)<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print entry['sAMAccountName']<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print entry['displayName']<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print entry['memberOf']<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>con.unbind()<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print ""<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print "Connection Closed"<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>except ldap.LDAPError, e:<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>print 'Error - ' + str(e)<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>sys.exit()<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman"
size=3> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"># End Of Code<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">##<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">###<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">####<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman">if __name__=="__main__":<o:p></o:p></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT
face="Times New Roman"><SPAN style="mso-spacerun: yes">
</SPAN>main()</FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"
size=3></FONT> </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
class=305484018-23062009><FONT face="Times New Roman" size=3>Thank
You</FONT></SPAN></P></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV align=left>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt" align=left><STRONG><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Todd J.
Hanson</SPAN></STRONG></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><A
title=blocked::mailto:thanson@qisadvisors.com
href="mailto:todd.hanson@mariner-qs.com">todd.hanson@mariner-qs.com</A></SPAN></P></DIV>
<DIV> </DIV></BODY></HTML>