forked from outroll/vesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv-change-user-password
executable file
·57 lines (41 loc) · 1.53 KB
/
v-change-user-password
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# info: change user password
# options: USER PASSWORD
#
# The function changes user's password and updates RKEY value.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
password=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Hiding password
A2="******"
EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER PASSWORD'
validate_format 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_password_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Changing user password
echo "$user:$password" | /usr/sbin/chpasswd
md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Changing RKEY value
update_user_value "$user" '$RKEY' "$(gen_password)"
update_user_value "$user" '$MD5' "$md5"
# Logging
log_history "changed password"
log_event "$OK" "$EVENT"
exit