deluser.sh 848 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash -e
  2. USER="$1"
  3. if [ "$USER" = "" ]; then
  4. echo "syntax: $0 login" >&2
  5. exit 1
  6. fi
  7. USER="${USER//[\/]/}"
  8. TMPDIR="$(mktemp -d)"
  9. if [ "$TMPDIR" = "" ]; then
  10. echo "error: cannot create temporary directory" >&2
  11. exit 2
  12. fi
  13. LDAP_LOGINPASS=($(awk -F '"' '{if ($1 == "masterDN=") {LOGIN=$2} if ($1 == "masterPw=") {PASS=$2}} END {print LOGIN"\t"PASS}' < /etc/smbldap-tools/smbldap_bind.conf))
  14. LDAP_LOGIN="${LDAP_LOGINPASS[0]}"
  15. LDAP_PASS="${LDAP_LOGINPASS[1]}"
  16. if [ "$LDAP_LOGIN" = "" -o "$LDAP_PASS" = "" ]; then
  17. echo "error: cannot parse ldap login/pass from /etc/smbldap-tools/smbldap_bind.conf" >&2
  18. exit 3
  19. fi
  20. echo "uid=$USER,ou=users,dc=mephi,dc=ru" > "$TMPDIR"/todelete.dnlist
  21. ldapdelete -x -D "$LDAP_LOGIN" -w "$LDAP_PASS" -f "$TMPDIR"/todelete.dnlist -h ldap.ut.mephi.ru
  22. rm -f "$TMPDIR"/{,.}* 2>/dev/null
  23. rmdir "$TMPDIR"
  24. exit 0