Kapisi/roles/Password/package/ldap-recreateuser

23 lines
593 B
Plaintext
Raw Permalink Normal View History

2024-09-02 23:54:57 -05:00
#!/bin/bash
uid="$1"
userfile="/etc/openldap/users.d/$uid.ldif"
if [ -z "$uid" ]; then
echo "Need a user ID (uid)!"
exit 1
fi
if [ ! -f "$userfile" ]; then
ldapsearch -x "uid=${uid}" > "$userfile"
echo "$userfile" had to be created -- please validate before re-running this script.
exit 2
fi
read -sp 'cn=root,dc=aninix,dc=net Password: ' rootdnpw
ldapdelete -D 'cn=root,dc=aninix,dc=net' -w "$rootdnpw" -H ldap://127.0.0.1 "uid=$uid,ou=People,dc=aninix,dc=net" && \
ldapadd -D 'cn=root,dc=aninix,dc=net' -w "$rootdnpw" -H ldap://127.0.0.1 -f "$userfile"
exit $?