Add group management to user editing form.

This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2015-07-13 19:50:58 +05:30
1 parent 197c95a7bf
commit 0eb3d35b5b
8 files changed
+104 -52

No files matched your search

+12 -11
View File
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# This file is part of Plinth.
#
@@ -29,18 +29,19 @@ else
exit 1
fi
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
dn: cn=admin,ou=groups,dc=thisbox
# update groups
results=$(ldapsearch 2>/dev/null -Y EXTERNAL -H ldapi:/// -b 'ou=groups,dc=thisbox' -LLL "(uniqueMember=uid=$username,ou=users,dc=thisbox)" dn | grep -v '^$')
while read -r line; do
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
$line
changetype: modify
delete: uniqueMember
uniqueMember: uid=$username,ou=users,dc=thisbox
EOF
if [ $? -eq 0 ]; then
echo "Removed user from admin group"
elif [ $? -eq 16 ]; then
echo "User was not in admin group"
elif [ $? -eq 65 ]; then
echo "Cannot remove last LDAP admin user"
exit 2
fi
if [ $? -eq 65 ]; then
# Cannot have empty group, so just delete the group.
ldapdelete -Y EXTERNAL -H ldapi:/// "$line"
fi
done <<< "$results"
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Must be run as root.
username="$1"
ldapsearch 2>/dev/null -Y EXTERNAL -H ldapi:/// -b 'ou=groups,dc=thisbox' -LLL "(uniqueMember=uid=$username,ou=users,dc=thisbox)" cn | awk '/cn:/ { print $2 }'
+8 -10
View File
@@ -35,23 +35,21 @@ else
exit 1
fi
# check if user is admin
results=$(ldapsearch -Y EXTERNAL -H ldapi:/// -b 'cn=admin,ou=groups,dc=thisbox' -LLL "(uniqueMember=uid=$old_username,ou=users,dc=thisbox)" uniqueMember)
# update groups
results=$(ldapsearch 2>/dev/null -Y EXTERNAL -H ldapi:/// -b 'ou=groups,dc=thisbox' -LLL "(uniqueMember=uid=$old_username,ou=users,dc=thisbox)" dn | grep -v '^$')
if [ -z "$results" ]; then
exit 0
fi
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
dn: cn=admin,ou=groups,dc=thisbox
while read -r line; do
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
$line
changetype: modify
add: uniqueMember
uniqueMember: uid=$new_username,ou=users,dc=thisbox
EOF
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
dn: cn=admin,ou=groups,dc=thisbox
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
$line
changetype: modify
delete: uniqueMember
uniqueMember: uid=$old_username,ou=users,dc=thisbox
EOF
done <<< "$results"