diff options
Diffstat (limited to 'web/attachments/154473-nagios_plugins-nagios_shell.patch')
-rw-r--r-- | web/attachments/154473-nagios_plugins-nagios_shell.patch | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/web/attachments/154473-nagios_plugins-nagios_shell.patch b/web/attachments/154473-nagios_plugins-nagios_shell.patch new file mode 100644 index 0000000..64e7d5f --- /dev/null +++ b/web/attachments/154473-nagios_plugins-nagios_shell.patch | |||
@@ -0,0 +1,168 @@ | |||
1 | --- ../../original_sources/nagios-plugins-1.4.2/contrib/nagios_shell 2005-10-11 20:27:28.411568216 -0400 | ||
2 | +++ nagios-plugins-1.4.2/contrib/nagios_shell 2005-10-11 20:28:54.933414896 -0400 | ||
3 | @@ -0,0 +1,165 @@ | ||
4 | +#! /usr/bin/perl -T | ||
5 | + | ||
6 | +# changable variables | ||
7 | +# set $NAGIOS_PLUGIN_DIR to the directory that contains the nagios plugins. | ||
8 | +# Don't include a trailing '/'. | ||
9 | +my($NAGIOS_PLUGIN_DIR)="PLUGIN_DIR_HERE"; | ||
10 | + | ||
11 | +# Other commands that can be run via this shell. It is strongly | ||
12 | +# recommended that all of these are specified with a full path name. | ||
13 | +my(@other_commands) = ( | ||
14 | +); | ||
15 | + | ||
16 | +# set the PATH needed for the commands run under this shell. | ||
17 | +$ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin"; | ||
18 | + | ||
19 | +#Name: nagiosshell | ||
20 | +#Use: used as forced command under ssh as receiver for check_by_ssh plugin | ||
21 | +#Function: Check provided command and runs it from predefined directory | ||
22 | +# or fully specified path. | ||
23 | +# Example: in ~nagios/.ssh/authorized_keys on system to be monitoed using | ||
24 | +# check_by_ssh: | ||
25 | +# | ||
26 | +# command="/path/to/nagiosshell" from="nagios.example.org" ssh-rsa AAAAB3N... | ||
27 | +# | ||
28 | +# This has not been tested with the multiple passive mode of check_by_ssh. | ||
29 | + | ||
30 | +use warnings; | ||
31 | +use strict; | ||
32 | + | ||
33 | +my($command, $exec_command, @args, @exec_args, $i); | ||
34 | + | ||
35 | +die("$0: Not running as forced command, \$SSH_ORIGINAL_COMMAND not found.\n") | ||
36 | + if (not exists($ENV{"SSH_ORIGINAL_COMMAND"})); | ||
37 | + | ||
38 | +($command, @args) = split(' ', $ENV{"SSH_ORIGINAL_COMMAND"}); | ||
39 | +if ($command !~ m#/#) { | ||
40 | + # then its a command name and not a full path | ||
41 | + if (! -x "$NAGIOS_PLUGIN_DIR/$command") { | ||
42 | + print "$0: Unable to find command $NAGIOS_PLUGIN_DIR/$command.\n"; | ||
43 | + exit 3; | ||
44 | + } else { | ||
45 | + # create the fully qualified name | ||
46 | + ($exec_command) = ($command =~ m/^([A-z0-9_.-]+)$/); | ||
47 | + $exec_command = "$NAGIOS_PLUGIN_DIR/$exec_command"; | ||
48 | + } | ||
49 | +} else { | ||
50 | + # we have a qualified command path, verify it | ||
51 | + foreach $i (@other_commands) { | ||
52 | + $exec_command = $i if ($i eq $command); | ||
53 | + } | ||
54 | +} | ||
55 | + | ||
56 | +if (! $exec_command) { | ||
57 | + print "$0: Unable to validate $command\n"; | ||
58 | + exit 3; | ||
59 | +} | ||
60 | + | ||
61 | +# set up a clean environment | ||
62 | +# PATH is explicitly set at top of script in modifyable variables. | ||
63 | +delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PERLLIB'}; | ||
64 | + | ||
65 | +# clean the args | ||
66 | +foreach (@args) { | ||
67 | + if ( m/^([^`;()]*)$/ ) { | ||
68 | + push(@exec_args, $1); | ||
69 | + } else { | ||
70 | + die ("$0: Unsafe argument $_ found. Exiting.\n"); | ||
71 | + } | ||
72 | +} | ||
73 | + | ||
74 | +# run the requested command without executing a shell. | ||
75 | +if (@exec_args) { | ||
76 | + eval {no warnings 'all'; exec $exec_command $exec_command, @exec_args}; | ||
77 | +} else { | ||
78 | + eval {no warnings 'all'; exec $exec_command $exec_command}; | ||
79 | +} | ||
80 | + | ||
81 | +use warnings; | ||
82 | + | ||
83 | +die("$0: Unable to exec ($!) $exec_command with args: \"" . join('", "', @exec_args) . "\".\n"); | ||
84 | + | ||
85 | +#TESTPREP: | ||
86 | +# mkdir $NAGIOS_PLUGIN_DIR | ||
87 | +# echo '#! /usr/bin/foo' > $NAGIOS_PLUGIN_BIN/check_foo | ||
88 | +# echo '#! /bin/sh' > $NAGIOS_PLUGIN_BIN/check_bar | ||
89 | +# echo 'ls "$@"' >> $NAGIOS_PLUGIN_BIN/check_bar | ||
90 | +# chmod +x $NAGIOS_PLUGIN_BIN/check_bar $NAGIOS_PLUGIN_BIN/check_foo | ||
91 | + | ||
92 | +#TEST: | ||
93 | +#- plugin unable to exec good args | ||
94 | +# SSH_ORIGINAL_COMMAND='check_foo -w 3:5 -c 2,4,3 -d 12-34' ./nagios_shell | ||
95 | +##Unable to exec (No such file or directory) /tmp/nagiosplug/check_foo | ||
96 | +## with args: "-w", "3:5", "-c", "2,4,3", "-d", "12-34". | ||
97 | + | ||
98 | +#- plugin unable to exec bad args | ||
99 | +# SSH_ORIGINAL_COMMAND='check_foo -w 3`5 -c 2,4,3 -d 12-34' ./nagios_shell | ||
100 | +##./nagios_shell: Unsafe argument 3`5 found. Exiting. | ||
101 | + | ||
102 | +#- plugin unable to exec no args | ||
103 | +# SSH_ORIGINAL_COMMAND='check_foo' ./nagios_shell | ||
104 | +##./nagios_shell: Unable to exec (No such file or directory) | ||
105 | +## /tmp/nagiosplug/check_foo with args: "". | ||
106 | + | ||
107 | +#- plugin able to exec good args | ||
108 | +# SSH_ORIGINAL_COMMAND='check_bar -w 3:5 -c 2,4,3 -d 12-34' ./nagios_shell | ||
109 | +##ls: 2,4,3: No such file or directory | ||
110 | +##ls: 12-34: No such file or directory | ||
111 | + | ||
112 | +#- plugin able to exec bad args | ||
113 | +# SSH_ORIGINAL_COMMAND='check_bar -w 35 -c 2,4,3 -d (12-34)' ./nagios_shell | ||
114 | +##./nagios_shell: Unsafe argument (12-34) found. Exiting. | ||
115 | + | ||
116 | +#- plugin able to exec no args | ||
117 | +# SSH_ORIGINAL_COMMAND='check_bar' ./nagios_shell | ||
118 | +## list of files in directory | ||
119 | + | ||
120 | +#- non existant plugin no args | ||
121 | +# SSH_ORIGINAL_COMMAND='check_zap' ./nagios_shell | ||
122 | +##./nagios_shell: Unable to find command /tmp/nagiosplug/check_zap. | ||
123 | + | ||
124 | +#- non existant plugin bad args | ||
125 | +# SSH_ORIGINAL_COMMAND='check_zap (foo' ./nagios_shell | ||
126 | +##./nagios_shell: Unable to find command /tmp/nagiosplug/check_zap. | ||
127 | + | ||
128 | +#- non existant plugin good args | ||
129 | +# SSH_ORIGINAL_COMMAND='check_zap foo' ./nagios_shell | ||
130 | +##./nagios_shell: Unable to find command /tmp/nagiosplug/check_zap. | ||
131 | + | ||
132 | +#- explicit command unable to exec (non-existent) good args | ||
133 | +# SSH_ORIGINAL_COMMAND='/usr/bin/nc1 -l /tmp' ./nagios_shell | ||
134 | +##Unable to exec (No such file or directory) /usr/bin/nc1 with args: | ||
135 | +## "-l", "/tmp". | ||
136 | + | ||
137 | +#- explicit command unable to exec (non-existent) bad args | ||
138 | +# SSH_ORIGINAL_COMMAND='/usr/bin/nc1 -l (/tmp)' ./nagios_shell | ||
139 | +##Unsafe argument (/tmp) found. Exiting. | ||
140 | + | ||
141 | +#- explicit command unable to exec (non-existent) no args | ||
142 | +# SSH_ORIGINAL_COMMAND='/usr/bin/nc1' ./nagios_shell | ||
143 | +##./nagios_shell: Unable to exec (No such file or directory) | ||
144 | +## /usr/bin/nc1 with args: "". | ||
145 | + | ||
146 | +#- explicit command able to exec good args | ||
147 | +# SSH_ORIGINAL_COMMAND='/usr/bin/ls -l /dev/null' ./nagios_shell | ||
148 | +##crw-rw-rw- 1 rouilj None 1, 3 Sep 24 23:19 /dev/null | ||
149 | + | ||
150 | +#- explicit command able to exec bad args | ||
151 | +# SSH_ORIGINAL_COMMAND='/usr/bin/ls -l `/dev/null`' ./nagios_shell | ||
152 | +##./nagios_shell: Unsafe argument `/dev/null` found. Exiting. | ||
153 | + | ||
154 | +#- explicit command able to exec no args | ||
155 | +# SSH_ORIGINAL_COMMAND='/usr/bin/ls ' ./nagios_shell | ||
156 | +##list of files in directory | ||
157 | + | ||
158 | +#- explicit command not found in list | ||
159 | +# SSH_ORIGINAL_COMMAND='/usr/bin/nc3' ./nagios_shell | ||
160 | +##./nagios_shell: Unable to validate /usr/bin/nc3 | ||
161 | + | ||
162 | +#- explicit command not found in list bad args | ||
163 | +# SSH_ORIGINAL_COMMAND='/usr/bin/nc3 (foo' ./nagios_shell | ||
164 | +##./nagios_shell: Unable to validate /usr/bin/nc3 | ||
165 | + | ||
166 | +#- explicit command not found in list good args | ||
167 | +# SSH_ORIGINAL_COMMAND='/usr/bin/nc3 foo' ./nagios_shell | ||
168 | +##./nagios_shell: Unable to validate /usr/bin/nc3 | ||