make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / pam / pam_shelltest
blob35b5e38cbf34f73c4234f6f059a76e68cbf741ed
1 #!/bin/bash
3 PAM_SUCCESS=0
4 PAM_SYSTEM_ERR=4
5 PAM_PERM_DENIED=6
6 PAM_AUTH_ERR=7
7 PAM_IGNORE=25
8 declare -a myargv
9 declare -a testargv
12 IFS=: read username password uid pri_gid gecos home shell <<<"$(getent passwd "$PAM_USER")"
13 shell_basename=`basename "$shell"`
15 for arg in "$@"
17 arg=${arg//%PAM_RHOST%/$PAM_RHOST}
18 arg=${arg//%PAM_RUSER%/$PAM_RUSER}
19 arg=${arg//%PAM_SERVICE%/$PAM_SERVICE}
20 arg=${arg//%PAM_TTY%/$PAM_TTY}
21 arg=${arg//%PAM_USER%/$PAM_USER}
22 arg=${arg//%PAM_TYPE%/$PAM_TYPE}
24 arg=${arg//%UID%/$uid}
25 arg=${arg//%PRI_GID%/$pri_gid}
26 arg=${arg//%HOME%/$home}
27 arg=${arg//%SHELL%/$shell}
28 arg=${arg//%SHELL_BASENAME%/$shell_basename}
30 myargv+=("$arg")
31 done
34 set -- "${myargv[@]}"
35 while [ -n "$1" ]
37 case "$1" in
38 -[bcdefghLkpsSuzn])
39 testargv+=("$1" "$2")
40 shift
42 '!'|-[ao]|=|'!'=)
43 testargv+=("$1")
45 --on|--off)
46 [ ".$1" = .--on ] && patt="on|yes|true|1" || patt="off|no|false|0"
47 head -n 1 "$2" | grep -Eiqx '\s*'"$patt"'\s*'
48 if [ ${PIPESTATUS[1]} = 0 ]
49 then
50 testargv+=('1')
51 else
52 testargv+=('')
54 shift
56 -*)
57 echo "pam_shelltest: Invalid parameter: $1" >&2
58 exit $PAM_SYSTEM_ERR
61 testargv+=("$1")
63 esac
64 shift
65 done
67 if [ ${#testargv[@]} -gt 0 ]
68 then
69 test "${testargv[@]}"
70 case $? in
71 0) exit $PAM_SUCCESS
73 1) exit $PAM_PERM_DENIED
75 *) exit $PAM_SYSTEM_ERR
77 esac
78 else
79 exit $PAM_IGNORE