Selaa lähdekoodia

Various fixes:

- Call slapcat by its full path to prevent the command
not being found when run as non root
- Removed $CMD variable and added $LDAPOPTS instead
- Added a way to make a user a posixAccount at creation time
Théo Ertzscheid 2 vuotta sitten
vanhempi
sitoutus
b532fe3ef2
3 muutettua tiedostoa jossa 15 lisäystä ja 6 poistoa
  1. 1 1
      addtogroups
  2. 11 2
      createperson
  3. 3 3
      person2posix

+ 1 - 1
addtogroups

@@ -27,7 +27,7 @@ for g in $@; do
     if group_exists $g ; then
         echo "$group" | sed \
             -e "s/%GROUP%/$g/" \
-            -e "s/%UID%/$uid/" | $MODIFY_CMD
+            -e "s/%UID%/$uid/" | ldapmodify $LDAPOPTS
     else
         echo "Group $g does not exist, skipping..."
     fi

+ 11 - 2
createperson

@@ -21,7 +21,16 @@ cn: $gn $sn
 mail: $uid@$DOMAIN
 userPassword: $pw"
 
-echo "$user" | $ADD_CMD
+echo "$user" | ldapadd $LDAPOPTS
+
+read -p "User added. Do you want to make it a posixAccount? [o/N] " a
+
+case $a in
+    y*|o* )
+	./person2posix $uid;;
+    * )
+        true;;
+esac
 
 read -p "User added. Do you want to add them to groups ? [o/N] " a
 
@@ -30,5 +39,5 @@ case $a in
         read -p "Enter list of groups separated by spaces: " grouplist
 	./addtogroups $uid $grouplist;;
     * )
-        exit;;
+        true;;
 esac

+ 3 - 3
person2posix

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