-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange.sh
executable file
·72 lines (54 loc) · 1.13 KB
/
change.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
command=""
find_user ()
{
local user_str=`grep -E "^${USER}\s*:" $1 2> /dev/null`
if [ "$user_str" != "" ]; then
# some magic and we're done!!
command=`echo $user_str | cut -d':' -f2-`
fi
}
gethome ()
{
local _USER=$1
_HOME=""
if [ -z "${_USER}" ]; then
return 1
fi
# FIXME: I guess this won't work for a nis like system
# it has to be done to avoid expansion
local F='$6'
_HOME=`cat /etc/passwd | awk -F ':' "/${_USER}/ { printf $F; }"`
return 0
}
USER=$1
if [ "$USER" == "" ]; then
exit
fi
conf="global"
file="/etc/preexec/preexec.conf"
if [ -r $file ]; then
find_user $file
fi
if [ "$command" == "" ]; then
gethome $USER
file="${_HOME}/.preexec"
if [ -r $file ]; then
find_user $file
fi
conf="local"
fi
if [ "$command" == "" ]; then
exit
fi
# global options get euid == root, TODO: add a configurable switch for this?
if [ "$conf" == "global" ]; then
NEWPASS=`$command`
else
# of course this is needed, otherwise the user whould have root privileges
NEWPASS=`su -c "$command" $USER`
fi
if [ "$NEWPASS" == "" ]; then
exit
fi
/etc/preexec/feeder.sh $NEWPASS | /usr/bin/passwd $USER 2>/dev/null