change_passwd 641 B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. username=$1
  3. password=$2
  4. current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  5. ini="$current_dir/scripts.ini"
  6. ldap_password=$(awk '/ldap_password/ {print $2}' $ini)
  7. dc=$(awk '/dc/ {print $2}' $ini)
  8. cn="$(awk '/cn/ {print $2}' $ini),$dc"
  9. users_ou="$(awk '/users_ou/ {print $2}' $ini),$dc"
  10. uid="uid=$username,$users_ou"
  11. if [ -z $username ]
  12. then
  13. echo "No username was set. Usage: change_passwd 'username' 'password'."
  14. exit 0
  15. fi
  16. if [ -z $password ]
  17. then
  18. echo "No password was set. change_passwd 'username' 'password'."
  19. exit 0
  20. fi
  21. ldappasswd -x -D $cn -w $ldap_password -s $password "$uid"