funcs 1.1 KB

12345678910111213141516171819202122232425262728293031
  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 the list of currently used uid numbers and add 1 to get the next one
  20. # uids between 2000 and 2999 are used for users. If the need to manage
  21. # more than 1000 users arise, consider using something else than a few bash scripts
  22. # to manage your directory.
  23. get_posix_number() {
  24. echo $(( $(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
  25. }