-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-allowed.sh
More file actions
executable file
·51 lines (43 loc) · 1.04 KB
/
Copy pathrun-allowed.sh
File metadata and controls
executable file
·51 lines (43 loc) · 1.04 KB
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
#!/usr/bin/env sh
usage() {
echo "Usage: $0 <allowed-cmds>... -- <run-cmd> <run-args>"
echo
echo " <allowed-cmds> One or more comma-separated allowed commands"
echo " run-cmd Command to be tested against allowed list and ran"
echo " run-args Optional arguments to pass to the run command"
exit 2
}
error_not_allowed() {
echo "error: command not allowed"
exit 3
}
[ $# -ge 2 ] || usage
allowed_cmds=''
while [ $# -gt 1 ]; do
case $1 in
--)
shift
break
;;
*)
cmd=$(which "$1" 2>/dev/null)
if [ -n "$cmd" ]; then
allowed_cmds="${allowed_cmds}${allowed_cmds:+:}${cmd}"
fi
shift
esac
done
run_cmd=$(which "$1" 2>/dev/null)
shift
if [ -n "$run_cmd" ]; then
IFS=:
for cmd in $allowed_cmds; do
if [ "$cmd" = "$run_cmd" ]; then
echo "run: $run_cmd"
echo "args:" "$@"
$run_cmd "$@"
exit 0
fi
done
fi
error_not_allowed