-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ldap.initialize() instead of deprecated ldap.open() in all demos.
- Loading branch information
stroeder
committed
Feb 1, 2002
1 parent
690068e
commit 202bbed
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import ldap | ||
| from getpass import getpass | ||
|
|
||
| # Create LDAPObject instance | ||
| l = ldap.initialize('ldap://localhost:1389',trace_level=1) | ||
|
|
||
| print 'Password:' | ||
| cred = getpass() | ||
|
|
||
| try: | ||
|
|
||
| # Set LDAP protocol version used | ||
| l.set_option(ldap.OPT_PROTOCOL_VERSION,3) | ||
|
|
||
| # Try a bind to provoke failure if protocol version is not supported | ||
| l.bind_s('cn=root,dc=stroeder,dc=com',cred,ldap.AUTH_SIMPLE) | ||
|
|
||
| print 'Using rename_s():' | ||
|
|
||
| l.rename_s( | ||
| 'uid=fred,ou=Unstructured testing tree,dc=stroeder,dc=com', | ||
| 'cn=Fred Feuerstein', | ||
| 'dc=stroeder,dc=com', | ||
| 0 | ||
| ) | ||
|
|
||
| l.rename_s( | ||
| 'cn=Fred Feuerstein,dc=stroeder,dc=com', | ||
| 'uid=fred', | ||
| 'ou=Unstructured testing tree,dc=stroeder,dc=com', | ||
| 0 | ||
| ) | ||
|
|
||
| m = l.rename( | ||
| 'uid=fred,ou=Unstructured testing tree,dc=stroeder,dc=com', | ||
| 'cn=Fred Feuerstein', | ||
| 'dc=stroeder,dc=com', | ||
| 0 | ||
| ) | ||
| r = l.result(m,1) | ||
|
|
||
| m = l.rename( | ||
| 'cn=Fred Feuerstein,dc=stroeder,dc=com', | ||
| 'uid=fred', | ||
| 'ou=Unstructured testing tree,dc=stroeder,dc=com', | ||
| 0 | ||
| ) | ||
| r = l.result(m,1) | ||
|
|
||
| finally: | ||
|
|
||
| l.unbind_s() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import sys,getpass | ||
| import ldap | ||
|
|
||
| #l = ldap.open("localhost", 31001) | ||
| l = ldap.open("marta.it.uq.edu.au") | ||
|
|
||
| login_dn = "cn=root,ou=CSEE,o=UQ,c=AU" | ||
| login_pw = getpass.getpass("Password for %s: " % login_dn) | ||
| l.simple_bind_s(login_dn, login_pw) | ||
|
|
||
| # | ||
| # create a new sub organisation | ||
| # | ||
|
|
||
| try: | ||
| dn = "ou=CSEE,o=UQ,c=AU" | ||
| print "Adding", repr(dn) | ||
| l.add_s(dn, | ||
| [ | ||
| ("objectclass",["organizationalUnit"]), | ||
| ("ou", ["CSEE"]), | ||
| ("description", [ | ||
| "Department of Computer Science and Electrical Engineering"]), | ||
| ] | ||
| ) | ||
|
|
||
| except _ldap.LDAPError: | ||
| pass | ||
|
|
||
| # | ||
| # create an entry for me | ||
| # | ||
|
|
||
| dn = "cn=David Leonard,ou=CSEE,o=UQ,c=AU" | ||
| print "Updating", repr(dn) | ||
|
|
||
| try: | ||
| l.delete_s(dn) | ||
| except: | ||
| pass | ||
|
|
||
| l.add_s(dn, | ||
| [ | ||
| ("objectclass", ["organizationalPerson"]), | ||
| ("sn", ["Leonard"]), | ||
| ("cn", ["David Leonard"]), | ||
| ("description", ["Ph.D. student"]), | ||
| ("display-name", ["David Leonard"]), | ||
| #("commonname", ["David Leonard"]), | ||
| ("mail", ["david.leonard@csee.uq.edu.au"]), | ||
| ("othermailbox", ["d@openbsd.org"]), | ||
| ("givenname", ["David"]), | ||
| ("surname", ["Leonard"]), | ||
| ("seeAlso", ["http://www.csee.uq.edu.au/~leonard/"]), | ||
| ("url", ["http://www.csee.uq.edu.au/~leonard/"]), | ||
| #("homephone", []), | ||
| #("fax", []), | ||
| #("otherfacsimiletelephonenumber",[]), | ||
| #("officefax", []), | ||
| #("mobile", []), | ||
| #("otherpager", []), | ||
| #("officepager", []), | ||
| #("pager", []), | ||
| ("info", ["info"]), | ||
| ("title", ["Mr"]), | ||
| #("telephonenumber", []), | ||
| ("l", ["Brisbane"]), | ||
| ("st", ["Queensland"]), | ||
| ("c", ["AU"]), | ||
| ("co", ["co"]), | ||
| ("o", ["UQ"]), | ||
| ("ou", ["CSEE"]), | ||
| #("homepostaladdress", []), | ||
| #("postaladdress", []), | ||
| #("streetaddress", []), | ||
| #("street", []), | ||
| ("department", ["CSEE"]), | ||
| ("comment", ["comment"]), | ||
| #("postalcode", []), | ||
| ("physicaldeliveryofficename", ["Bldg 78, UQ, St Lucia"]), | ||
| ("preferredDeliveryMethod", ["email"]), | ||
| ("initials", ["DRL"]), | ||
| ("conferenceinformation", ["MS-conferenceinformation"]), | ||
| #("usercertificate", []), | ||
| ("labeleduri", ["labeleduri"]), | ||
| ("manager", ["cn=Jaga Indulska"]), | ||
| ("reports", ["reports"]), | ||
| ("jpegPhoto", [open("/www/leonard/leonard.jpg","r").read()]), | ||
| ("uid", ["leonard"]), | ||
| ("userPassword", [""]) | ||
|
|
||
| ]) | ||
|
|
||
| # | ||
| # search beneath the CSEE/UQ/AU tree | ||
| # | ||
|
|
||
| res = l.search_s( | ||
| "ou=CSEE, o=UQ, c=AU", | ||
| _ldap.SCOPE_SUBTREE, | ||
| "objectclass=*", | ||
| ) | ||
| print res | ||
|
|
||
| l.unbind() | ||
|
|