theo 1 anno fa
parent
commit
969dab983a
2 ha cambiato i file con 11 aggiunte e 9 eliminazioni
  1. 3 1
      .env.example
  2. 8 8
      funcs

+ 3 - 1
.env.example

@@ -4,4 +4,6 @@ PEOPLEDN="ou=People,dc=example,dc=com"
 GROUPSDN="ou=Groups,dc=example,dc=com"
 HOST="localhost"
 DOMAIN="example.com"
-LDAPOPTS="-x -D $BINDDN -w $BINDPW"
+LDAPOPTS="-Z -x -D $BINDDN -w $BINDPW"
+PEOPLESEARCHCMD="ldapsearch -Z -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW"
+GROUPSEARCHCMD="ldapsearch -Z -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW"

+ 8 - 8
funcs

@@ -3,37 +3,37 @@
 . .env
 
 user_exists() {
-	res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ')
+	res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=inetOrgPerson))" | grep uid: | cut -f2 -d' ')
 	[ -n "$res" ]
 }
 
 group_exists() {
-	res=$(ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(cn=$1)" | grep cn: | cut -f2 -d' ')
+	res=$($GROUPSEARCHCMD "(cn=$1)" | grep cn: | cut -f2 -d' ')
 	[ -n "$res" ]
 }
 
 mail_exists() {
-	res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(|(mail=$1)(mailAlias=$1))")
+	res=$($PEOPLESEARCHCMD "(|(mail=$1)(mailAlias=$1))")
 	[ -n "$res" ]
 }
 
 user_is_posix() {
-	res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ')
+	res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ')
 	[ -n "$res" ]
 }
 
 user_is_postfix() {
-	res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=PostfixBookMailAccount))" | grep uid: | cut -f2 -d' ')
+	res=$($PEOPLESEARCHCMD "(&(uid=$1)(objectClass=PostfixBookMailAccount))" | grep uid: | cut -f2 -d' ')
 	[ -n "$res" ]
 }
 
 group_is_posix() {
-	res=$(ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(&(cn=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ')
+	res=$($GROUPSEARCHCMD "(&(cn=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' ')
 	[ -n "$res" ]
 }
 
 get_posixGroups () {
-	ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(&(memberUid=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' '
+	$GROUPSEARCHCMD "(&(memberUid=$1)(objectClass=posixGroup))" | grep cn: | cut -f2 -d' '
 }
 
 # get the list of currently used uid numbers and add 1 to get the next one
@@ -41,5 +41,5 @@ get_posixGroups () {
 # more than 1000 users arises, consider using something else than a few bash scripts 
 # to manage your directory.
 get_posix_number() {
-	echo $(( $(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
+	echo $(( $($PEOPLESEARCHCMD "(objectClass=posixAccount)" | grep 'uidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
 }