funcs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. if [ -e /etc/ldap-utils.conf ]; then
  3. . /etc/ldap-utils.conf
  4. else
  5. exit 1
  6. fi
  7. user_exists() {
  8. res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ')
  9. [ -n "$res" ]
  10. }
  11. group_exists() {
  12. res=$($GROUPSEARCHCMD "(cn=$1)" | grep cn: | cut -f2 -d' ')
  13. [ -n "$res" ]
  14. }
  15. mail_exists() {
  16. res=$($PEOPLESEARCHCMD "(|(mail=$1)(mailAlias=$1))")
  17. [ -n "$res" ]
  18. }
  19. user_is_posix() {
  20. res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ')
  21. [ -n "$res" ]
  22. }
  23. user_is_postfix() {
  24. res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=PostfixBookMailAccount))" | grep uid: | cut -f2 -d' ')
  25. [ -n "$res" ]
  26. }
  27. group_is_posix() {
  28. res=$($GROUPSEARCHCMD "(&(cn=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ')
  29. [ -n "$res" ]
  30. }
  31. get_posixGroups() {
  32. $GROUPSEARCHCMD "(&(memberUid=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' '
  33. }
  34. # get the list of currently used uid numbers and add 1 to get the next one
  35. # uids between 2000 and 2999 are used for users. If the need to manage
  36. # more than 1000 users arises, consider using something else than a few bash scripts
  37. # to manage your directory.
  38. get_posix_number() {
  39. echo $(( $($PEOPLESEARCHCMD "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
  40. }
  41. vf() {
  42. ldapvi --discover -Z -w $BINDPW -h localhost -D $BINDDN "($1)"
  43. }
  44. vu() {
  45. vf "uid=$1"
  46. }
  47. vg() {
  48. vf "cn=$1"
  49. }