moddn_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package ldap_test
  2. import (
  3. "log"
  4. "notabug.org/makenotabuggreatagain/ldap"
  5. )
  6. // ExampleConn_ModifyDN_renameNoMove shows how to rename an entry without moving it
  7. func ExampleConn_ModifyDN_renameNoMove() {
  8. conn, err := ldap.Dial("tcp", "ldap.example.org:389")
  9. if err != nil {
  10. log.Fatalf("Failed to connect: %s\n", err)
  11. }
  12. defer conn.Close()
  13. _, err = conn.SimpleBind(&ldap.SimpleBindRequest{
  14. Username: "uid=someone,ou=people,dc=example,dc=org",
  15. Password: "MySecretPass",
  16. })
  17. if err != nil {
  18. log.Fatalf("Failed to bind: %s\n", err)
  19. }
  20. // just rename to uid=new,ou=people,dc=example,dc=org:
  21. req := ldap.NewModifyDNRequest("uid=user,ou=people,dc=example,dc=org", "uid=new", true, "")
  22. if err = conn.ModifyDN(req); err != nil {
  23. log.Fatalf("Failed to call ModifyDN(): %s\n", err)
  24. }
  25. }
  26. // ExampleConn_ModifyDN_renameAndMove shows how to rename an entry and moving it to a new base
  27. func ExampleConn_ModifyDN_renameAndMove() {
  28. conn, err := ldap.Dial("tcp", "ldap.example.org:389")
  29. if err != nil {
  30. log.Fatalf("Failed to connect: %s\n", err)
  31. }
  32. defer conn.Close()
  33. _, err = conn.SimpleBind(&ldap.SimpleBindRequest{
  34. Username: "uid=someone,ou=people,dc=example,dc=org",
  35. Password: "MySecretPass",
  36. })
  37. if err != nil {
  38. log.Fatalf("Failed to bind: %s\n", err)
  39. }
  40. // rename to uid=new,ou=people,dc=example,dc=org and move to ou=users,dc=example,dc=org ->
  41. // uid=new,ou=users,dc=example,dc=org
  42. req := ldap.NewModifyDNRequest("uid=user,ou=people,dc=example,dc=org", "uid=new", true, "ou=users,dc=example,dc=org")
  43. if err = conn.ModifyDN(req); err != nil {
  44. log.Fatalf("Failed to call ModifyDN(): %s\n", err)
  45. }
  46. }
  47. // ExampleConn_ModifyDN_moveOnly shows how to move an entry to a new base without renaming the RDN
  48. func ExampleConn_ModifyDN_moveOnly() {
  49. conn, err := ldap.Dial("tcp", "ldap.example.org:389")
  50. if err != nil {
  51. log.Fatalf("Failed to connect: %s\n", err)
  52. }
  53. defer conn.Close()
  54. _, err = conn.SimpleBind(&ldap.SimpleBindRequest{
  55. Username: "uid=someone,ou=people,dc=example,dc=org",
  56. Password: "MySecretPass",
  57. })
  58. if err != nil {
  59. log.Fatalf("Failed to bind: %s\n", err)
  60. }
  61. // move to ou=users,dc=example,dc=org -> uid=user,ou=users,dc=example,dc=org
  62. req := ldap.NewModifyDNRequest("uid=user,ou=people,dc=example,dc=org", "uid=user", true, "ou=users,dc=example,dc=org")
  63. if err = conn.ModifyDN(req); err != nil {
  64. log.Fatalf("Failed to call ModifyDN(): %s\n", err)
  65. }
  66. }