v-change-user-password 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # info: change user password
  3. # options: USER PASSWORD
  4. #
  5. # The function changes user's password and updates RKEY value.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. password=$2
  12. # Includes
  13. source $VESTA/func/main.sh
  14. source $VESTA/conf/vesta.conf
  15. # Hiding password
  16. A2="******"
  17. EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '2' "$#" 'USER PASSWORD'
  22. validate_format 'user' 'password'
  23. is_object_valid 'user' 'USER' "$user"
  24. is_object_unsuspended 'user' 'USER' "$user"
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Changing user password
  29. echo "$user:$password" | /usr/sbin/chpasswd
  30. md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)
  31. #----------------------------------------------------------#
  32. # Vesta #
  33. #----------------------------------------------------------#
  34. # Changing RKEY value
  35. update_user_value "$user" '$RKEY' "$(gen_password)"
  36. update_user_value "$user" '$MD5' "$md5"
  37. # Logging
  38. log_history "changed password"
  39. log_event "$OK" "$EVENT"
  40. exit