rename.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import ldap
  2. from getpass import getpass
  3. # Create LDAPObject instance
  4. l = ldap.initialize('ldap://localhost:1389',trace_level=1)
  5. print 'Password:'
  6. cred = getpass()
  7. try:
  8. # Set LDAP protocol version used
  9. l.set_option(ldap.OPT_PROTOCOL_VERSION,3)
  10. # Try a bind to provoke failure if protocol version is not supported
  11. l.bind_s('cn=root,dc=stroeder,dc=com',cred,ldap.AUTH_SIMPLE)
  12. print 'Using rename_s():'
  13. l.rename_s(
  14. 'uid=fred,ou=Unstructured testing tree,dc=stroeder,dc=com',
  15. 'cn=Fred Feuerstein',
  16. 'dc=stroeder,dc=com',
  17. 0
  18. )
  19. l.rename_s(
  20. 'cn=Fred Feuerstein,dc=stroeder,dc=com',
  21. 'uid=fred',
  22. 'ou=Unstructured testing tree,dc=stroeder,dc=com',
  23. 0
  24. )
  25. m = l.rename(
  26. 'uid=fred,ou=Unstructured testing tree,dc=stroeder,dc=com',
  27. 'cn=Fred Feuerstein',
  28. 'dc=stroeder,dc=com',
  29. 0
  30. )
  31. r = l.result(m,1)
  32. m = l.rename(
  33. 'cn=Fred Feuerstein,dc=stroeder,dc=com',
  34. 'uid=fred',
  35. 'ou=Unstructured testing tree,dc=stroeder,dc=com',
  36. 0
  37. )
  38. r = l.result(m,1)
  39. finally:
  40. l.unbind_s()