v_change_user_password 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_CONF/vesta.conf
  15. source $V_FUNC/shared.func
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. # Checking arg number
  20. check_args '2' "$#" 'user password'
  21. # Checking argument format
  22. format_validation 'user' 'password'
  23. # Checking user
  24. is_user_valid
  25. # Checking user is active
  26. is_user_suspended
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Changing user password
  31. echo "$password" | /usr/bin/passwd "$user" --stdin >/dev/null 2>&1
  32. #----------------------------------------------------------#
  33. # Vesta #
  34. #----------------------------------------------------------#
  35. # Changing RKEY value
  36. update_user_value "$user" '$RKEY' "$(gen_password)"
  37. # Hiding password
  38. V_EVENT="$V_DATE $V_SCRIPT $user *****"
  39. # Logging
  40. log_event 'system' "$V_EVENT"
  41. exit