Browse Source

Delete user from posixGroups when deleting the user

theo 2 years ago
parent
commit
755aa483c5
2 changed files with 8 additions and 1 deletions
  1. 4 0
      funcs
  2. 4 1
      removeperson

+ 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 

+ 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;;