-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathldapattrdelete
More file actions
executable file
·25 lines (19 loc) · 965 Bytes
/
ldapattrdelete
File metadata and controls
executable file
·25 lines (19 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
if [ $UID -ne 0 ]; then
echo "Hey! You have to be root to do this. (Try 'sudo !!')"
exit 1
fi
echo "Okay, we'll delete an attribute from a user."
echo -n " (Username) uid: "; read LDAPUID #You can't use $UID in a bash script.
echo -n " Attribute name: "; read ATTRIBUTE
echo -n "Current value for that attribute: "; read VALUE
ADMINPASS=$(grep 'olcRootPW' /etc/ldap/slapd.d/cn\=config/olcDatabase\=\{0\}config.ldif | cut -d ' ' -f 2)
echo -n "Okay, we will remove $ATTRIBUTE: $VALUE from the user $LDAPUID. If that's right, hit return. Hit Ctrl+C to bail."; read BLAH
echo ""
echo -n "Provisioning LDAP attribute. "
echo "dn: uid=$LDAPUID,ou=people,dc=makerslocal,dc=org
changetype: modify
delete: $ATTRIBUTE
$ATTRIBUTE: $VALUE" | ldapadd -D "cn=admin,dc=makerslocal,dc=org" -w $ADMINPASS -xH ldap://newldap
if [ $? -ne 0 ]; then echo "Well, that didn't work."; exit; fi
echo "aaaaaand done. We did the thing!"