Эх сурвалжийг харах

Get the next posix uid/gid number via a function in person2posix

Théo Ertzscheid 2 жил өмнө
parent
commit
cf351cff4f
2 өөрчлөгдсөн 6 нэмэгдсэн , 2 устгасан
  1. 4 0
      funcs
  2. 2 2
      person2posix

+ 4 - 0
funcs

@@ -16,3 +16,7 @@ is_posix() {
 	res=$(ldapsearch -x -LLL -b $PEOPLEDN -D $BINDDN -w $BINDPW "(&(uid=$1)(objectClass=posixAccount))" | grep uid: | cut -f2 -d' ')
 	[ -n "$res" ]
 }
+
+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))
+}

+ 2 - 2
person2posix

@@ -41,14 +41,14 @@ gidNumber: %NUMBER%
 memberUid: %UID%"
 
 # get the list of currently used uid numbers and add 1 to get the next one
-uidnumber=$(( $(/usr/sbin/slapcat | grep 'gidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
+uidnumber=get_posix_number
 
 # add the necessary attribbute for a posixAccount
 echo "$user" | sed \
 	-e "s/%NUMBER%/$uidnumber/" \
 	-e "s/%UID%/$uid/" | ldapmodify $LDAPOPTS
 
-# create a posic group with the same name and uid as the user
+# create a posix group with the same name and uid as the user
 # and add them to it
 echo "$group" | sed \
 	-e "s/%NUMBER%/$uidnumber/" \