simple.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import sys,getpass
  2. import ldap
  3. #l = ldap.open("localhost", 31001)
  4. l = ldap.open("marta.it.uq.edu.au")
  5. login_dn = "cn=root,ou=CSEE,o=UQ,c=AU"
  6. login_pw = getpass.getpass("Password for %s: " % login_dn)
  7. l.simple_bind_s(login_dn, login_pw)
  8. #
  9. # create a new sub organisation
  10. #
  11. try:
  12. dn = "ou=CSEE,o=UQ,c=AU"
  13. print "Adding", repr(dn)
  14. l.add_s(dn,
  15. [
  16. ("objectclass",["organizationalUnit"]),
  17. ("ou", ["CSEE"]),
  18. ("description", [
  19. "Department of Computer Science and Electrical Engineering"]),
  20. ]
  21. )
  22. except _ldap.LDAPError:
  23. pass
  24. #
  25. # create an entry for me
  26. #
  27. dn = "cn=David Leonard,ou=CSEE,o=UQ,c=AU"
  28. print "Updating", repr(dn)
  29. try:
  30. l.delete_s(dn)
  31. except:
  32. pass
  33. l.add_s(dn,
  34. [
  35. ("objectclass", ["organizationalPerson"]),
  36. ("sn", ["Leonard"]),
  37. ("cn", ["David Leonard"]),
  38. ("description", ["Ph.D. student"]),
  39. ("display-name", ["David Leonard"]),
  40. #("commonname", ["David Leonard"]),
  41. ("mail", ["david.leonard@csee.uq.edu.au"]),
  42. ("othermailbox", ["d@openbsd.org"]),
  43. ("givenname", ["David"]),
  44. ("surname", ["Leonard"]),
  45. ("seeAlso", ["http://www.csee.uq.edu.au/~leonard/"]),
  46. ("url", ["http://www.csee.uq.edu.au/~leonard/"]),
  47. #("homephone", []),
  48. #("fax", []),
  49. #("otherfacsimiletelephonenumber",[]),
  50. #("officefax", []),
  51. #("mobile", []),
  52. #("otherpager", []),
  53. #("officepager", []),
  54. #("pager", []),
  55. ("info", ["info"]),
  56. ("title", ["Mr"]),
  57. #("telephonenumber", []),
  58. ("l", ["Brisbane"]),
  59. ("st", ["Queensland"]),
  60. ("c", ["AU"]),
  61. ("co", ["co"]),
  62. ("o", ["UQ"]),
  63. ("ou", ["CSEE"]),
  64. #("homepostaladdress", []),
  65. #("postaladdress", []),
  66. #("streetaddress", []),
  67. #("street", []),
  68. ("department", ["CSEE"]),
  69. ("comment", ["comment"]),
  70. #("postalcode", []),
  71. ("physicaldeliveryofficename", ["Bldg 78, UQ, St Lucia"]),
  72. ("preferredDeliveryMethod", ["email"]),
  73. ("initials", ["DRL"]),
  74. ("conferenceinformation", ["MS-conferenceinformation"]),
  75. #("usercertificate", []),
  76. ("labeleduri", ["labeleduri"]),
  77. ("manager", ["cn=Jaga Indulska"]),
  78. ("reports", ["reports"]),
  79. ("jpegPhoto", [open("/www/leonard/leonard.jpg","r").read()]),
  80. ("uid", ["leonard"]),
  81. ("userPassword", [""])
  82. ])
  83. #
  84. # search beneath the CSEE/UQ/AU tree
  85. #
  86. res = l.search_s(
  87. "ou=CSEE, o=UQ, c=AU",
  88. _ldap.SCOPE_SUBTREE,
  89. "objectclass=*",
  90. )
  91. print res
  92. l.unbind()