Add new LDAP users to admin group.

This commit is contained in:
James Valleroy 2015-06-30 16:29:03 -04:00 committed by Sunil Mohan Adapa
parent 82cf4df0bc
commit f4835b4515

View File

@ -34,3 +34,24 @@ if [ $? -ne 0 ]; then
echo "Failed to create user"
exit 1
fi
# check if admin group exists
results=$(ldapsearch -Y EXTERNAL -H ldapi:/// -b 'ou=groups,dc=thisbox' -LLL "(cn=admin)" cn)
if [ -z "$results" ]; then
# create admin group, with new user as a member
cat <<EOF |ldapadd -Y EXTERNAL -H ldapi:///
dn: cn=admin,ou=groups,dc=thisbox
objectClass: groupOfUniqueNames
cn: admin
uniqueMember: uid=$username,ou=users,dc=thisbox
EOF
else
# add new user to existing admin group
cat <<EOF |ldapmodify -Y EXTERNAL -H ldapi:///
dn: cn=admin,ou=groups,dc=thisbox
changetype: modify
add: uniqueMember
uniqueMember: uid=$username,ou=users,dc=thisbox
EOF
fi