Browse Source

Added a check to see if the account is already posix in person2posix

theo 2 years ago
parent
commit
7974becd2e
2 changed files with 9 additions and 1 deletions
  1. 4 0
      funcs
  2. 5 1
      person2posix

+ 4 - 0
funcs

@@ -22,6 +22,10 @@ group_is_posix() {
 	[ -n "$res" ]
 }
 
+# get the list of currently used uid numbers and add 1 to get the next one
+# uids between 2000 and 2999 are used for users. If the need to manage
+# more than 1000 users arise, 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))
 }

+ 5 - 1
person2posix

@@ -10,6 +10,11 @@ else
     exit 1
 fi
 
+if user_is_posix $uid; then
+    echo "User $uid is already a posixAccount" 
+    exit 1
+fi
+
 user="dn: uid=%UID%,$PEOPLEDN
 changeType: modify
 add: objectClass
@@ -40,7 +45,6 @@ cn: %UID%
 gidNumber: %NUMBER%
 memberUid: %UID%"
 
-# get the list of currently used uid numbers and add 1 to get the next one
 uidnumber=get_posix_number
 
 # add the necessary attribbute for a posixAccount