funcs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. . .env
  3. user_exists() {
  4. res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ')
  5. [ -n "$res" ]
  6. }
  7. group_exists() {
  8. res=$($GROUPSEARCHCMD "(cn=$1)" | grep cn: | cut -f2 -d' ')
  9. [ -n "$res" ]
  10. }
  11. mail_exists() {
  12. res=$($PEOPLESEARCHCMD "(|(mail=$1)(mailAlias=$1))")
  13. [ -n "$res" ]
  14. }
  15. user_is_posix() {
  16. res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ')
  17. [ -n "$res" ]
  18. }
  19. user_is_postfix() {
  20. res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=PostfixBookMailAccount))" | grep uid: | cut -f2 -d' ')
  21. [ -n "$res" ]
  22. }
  23. group_is_posix() {
  24. res=$($GROUPSEARCHCMD "(&(cn=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ')
  25. [ -n "$res" ]
  26. }
  27. get_posixGroups () {
  28. $GROUPSEARCHCMD "(&(memberUid=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' '
  29. }
  30. # get the list of currently used uid numbers and add 1 to get the next one
  31. # uids between 2000 and 2999 are used for users. If the need to manage
  32. # more than 1000 users arises, consider using something else than a few bash scripts
  33. # to manage your directory.
  34. get_posix_number() {
  35. echo $(( $($PEOPLESEARCHCMD "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
  36. }