5 コミット 1f61d9a53c ... 93da9bfbfb

作者 SHA1 メッセージ 日付
  theo 93da9bfbfb Changes to createperson 2 年 前
  theo 755aa483c5 Delete user from posixGroups when deleting the user 2 年 前
  theo 0c49211a13 Fixed removefromgroups not removing users from posix groups 2 年 前
  theo d4d0c6f77c Fixed addtogroups not adding users to posix groups 2 年 前
  theo 21b40d860f Fixed typo 2 年 前
6 ファイル変更41 行追加26 行削除
  1. 1 1
      addtogroups
  2. 30 22
      createperson
  3. 4 0
      funcs
  4. 1 1
      person2posix
  5. 1 1
      removefromgroups
  6. 4 1
      removeperson

+ 1 - 1
addtogroups

@@ -30,7 +30,7 @@ shift
 for g in $@; do
     if group_exists $g ; then
 	if group_is_posix $g; then
-		user_is_posix $uid || echo "User $uid is not a posixAccount, skipping posixGroup $g..." && continue
+		user_is_posix $uid || { echo "User $uid is not a posixAccount, skipping posixGroup $g..." && continue; }
 		group="$group_posix"
 	else
 		group="$group_ofnames"

+ 30 - 22
createperson

@@ -1,11 +1,34 @@
-#!/bin/bash
+#!/bin/bash -e
 . .env
 . funcs
 
-read -p "UID: " uid
-read -p "GivenName: " gn
-read -p "Name: " sn
-pw=$(/usr/bin/slappasswd -s salut$uid)
+usage() {
+	echo "Usage : $(basename $0) -u <uid> -n <First name> -s <Last Name> [-p] [-g group1,group2,...]"
+}
+
+trap usage ERR
+
+while getopts 'u:n:s:p?g:?' opt; do
+  case "$opt" in
+    u)
+      uid="$OPTARG"
+      ;;
+    n)
+      gn="$OPTARG"
+      ;;
+    s)
+      sn="$OPTARG"
+      ;;
+    p)
+      posix="true"
+      ;;
+    g)
+      grouplist=$( echo $OPTARG | tr ',' ' ')
+      ;;
+  esac
+done
+
+pw=$(/usr/sbin/slappasswd -s "salut$uid")
 
 if user_exists $uid; then
     echo "User $uid already exist." 
@@ -23,21 +46,6 @@ userPassword: $pw"
 
 echo "$user" | ldapadd $LDAPOPTS
 
-read -p "User added. Do you want to make it a posixAccount? [y/N] " a
+[ -n "$posix" ] && echo posix &&  ./person2posix $uid
 
-case $a in
-    y*|o* )
-	./person2posix $uid;;
-    * )
-        true;;
-esac
-
-read -p "User added. Do you want to add them to groups ? [y/N] " a
-
-case $a in
-    y*|o* )
-        read -p "Enter list of groups separated by spaces: " grouplist
-	./addtogroups $uid $grouplist;;
-    * )
-        true;;
-esac
+[ -n "$grouplist" ] && echo groups && ./addtogroups $uid $grouplist

+ 4 - 0
funcs

@@ -22,6 +22,10 @@ group_is_posix() {
 	[ -n "$res" ]
 }
 
+get_posixGroups () {
+	ldapsearch -x -LLL -b $GROUPSDN -D $BINDDN -w $BINDPW "(&(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
 # 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 

+ 1 - 1
person2posix

@@ -45,7 +45,7 @@ cn: %UID%
 gidNumber: %NUMBER%
 memberUid: %UID%"
 
-uidnumber=get_posix_number
+uidnumber=$(get_posix_number)
 
 # add the necessary attribbute for a posixAccount
 echo "$user" | sed \

+ 1 - 1
removefromgroups

@@ -29,7 +29,7 @@ shift
 for g in $@; do
     if group_exists $g ; then
 	if group_is_posix $g; then
-		user_is_posix $uid || echo "User $uid is not a posixAccount, skipping posixGroup $g..." && continue
+		user_is_posix $uid || { echo "User $uid is not a posixAccount, skipping posixGroup $g..." && continue; }
 		group="$group_posix"
 	else
 		group="$group_ofnames"

+ 4 - 1
removeperson

@@ -14,7 +14,10 @@ read -p "Are you sure you want to delete user $uid [y/N] " a
 
 case $a in
     y*|o* )
-	user_is_posix $uid && ldapdelete $LDAPOPTS cn=$uid,$GROUPSDN
+	if user_is_posix $uid; then 
+		ldapdelete $LDAPOPTS cn=$uid,$GROUPSDN
+		./removefromgroups $uid $(get_posixGroups $uid)
+	fi
 	ldapdelete $LDAPOPTS uid=$uid,$PEOPLEDN ;;
     * )
         exit;;