funcs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. . .env
  3. user_exists() {
  4. res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ')
  5. [ -n "$res" ]
  6. }
  7. group_exists() {
  8. res=$(ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(cn=$1)" | grep cn: | cut -f2 -d' ')
  9. [ -n "$res" ]
  10. }
  11. user_is_posix() {
  12. res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ')
  13. [ -n "$res" ]
  14. }
  15. group_is_posix() {
  16. res=$(ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(&(cn=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ')
  17. [ -n "$res" ]
  18. }
  19. get_posixGroups () {
  20. ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(&(memberUid=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' '
  21. }
  22. # get the list of currently used uid numbers and add 1 to get the next one
  23. # uids between 2000 and 2999 are used for users. If the need to manage
  24. # more than 1000 users arise, consider using something else than a few bash scripts
  25. # to manage your directory.
  26. get_posix_number() {
  27. echo $(( $(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
  28. }