diff options
Diffstat (limited to 'web/attachments/125109-tcp_bin.patch')
-rw-r--r-- | web/attachments/125109-tcp_bin.patch | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/web/attachments/125109-tcp_bin.patch b/web/attachments/125109-tcp_bin.patch new file mode 100644 index 0000000..1ac15e4 --- /dev/null +++ b/web/attachments/125109-tcp_bin.patch | |||
@@ -0,0 +1,214 @@ | |||
1 | diff -rNu nagios_orig/plugins/check_tcp.c nagios-plugins-1.4/plugins/check_tcp.c | ||
2 | --- nagios_orig/plugins/check_tcp.c 2004-12-30 01:41:40.000000000 +0100 | ||
3 | +++ nagios-plugins-1.4/plugins/check_tcp.c 2005-03-09 15:46:03.000000000 +0100 | ||
4 | @@ -80,6 +80,8 @@ | ||
5 | char *server_address = NULL; | ||
6 | char *server_send = NULL; | ||
7 | char *server_quit = NULL; | ||
8 | +char *input_file_name = NULL; | ||
9 | +char *output_file_name = NULL; | ||
10 | char **server_expect = NULL; | ||
11 | size_t server_expect_count = 0; | ||
12 | int maxbytes = 0; | ||
13 | @@ -132,6 +134,15 @@ | ||
14 | PROTOCOL = TCP_PROTOCOL; | ||
15 | PORT = 0; | ||
16 | } | ||
17 | + else if (strstr (argv[0], "check_tcp_bin")) { | ||
18 | + progname = strdup ("check_tcp_bin"); | ||
19 | + SERVICE = strdup ("TCP"); | ||
20 | + SEND = NULL; | ||
21 | + EXPECT = NULL; | ||
22 | + QUIT = NULL; | ||
23 | + PROTOCOL = TCP_PROTOCOL; | ||
24 | + PORT = 0; | ||
25 | + } | ||
26 | else if (strstr (argv[0], "check_ftp")) { | ||
27 | progname = strdup ("check_ftp"); | ||
28 | SERVICE = strdup ("FTP"); | ||
29 | @@ -299,6 +310,42 @@ | ||
30 | send (sd, server_send, strlen(server_send), 0); | ||
31 | } | ||
32 | |||
33 | + /* send content of input file ? */ | ||
34 | + if (input_file_name != NULL) { | ||
35 | + struct stat istat; | ||
36 | + if (stat(input_file_name, &istat) != 0) { | ||
37 | + printf("UNKNOWN - File not found %s\n", input_file_name); | ||
38 | + return STATE_UNKNOWN; | ||
39 | + } | ||
40 | + size_t in_len = istat.st_size; | ||
41 | + | ||
42 | + FILE * in = fopen(input_file_name, "rb"); | ||
43 | + if (in == NULL) { | ||
44 | + printf("UNKNOWN - Can not open file: %s\n", input_file_name); | ||
45 | + return STATE_UNKNOWN; | ||
46 | + } | ||
47 | + char * indata = malloc(in_len); | ||
48 | + if (indata == NULL) { | ||
49 | + printf(_("UNKNOWN - Not enough memory\n")); | ||
50 | + return STATE_UNKNOWN; | ||
51 | + } | ||
52 | + size_t bytes = fread(indata, 1, in_len, in); | ||
53 | + if (bytes != in_len) { | ||
54 | + printf("UNKNOWN - Error reading file: \n", input_file_name); | ||
55 | + free(indata); | ||
56 | + fclose(in); | ||
57 | + return STATE_UNKNOWN; | ||
58 | + } | ||
59 | + fclose(in); | ||
60 | +#ifdef HAVE_SSL | ||
61 | + if (use_ssl) | ||
62 | + SSL_write(ssl, indata, in_len); | ||
63 | + else | ||
64 | +#endif | ||
65 | + send (sd, indata, in_len, 0); | ||
66 | + free(indata); | ||
67 | + } | ||
68 | + | ||
69 | if (delay > 0) { | ||
70 | tv.tv_sec += delay; | ||
71 | sleep (delay); | ||
72 | @@ -345,6 +392,57 @@ | ||
73 | } | ||
74 | } | ||
75 | |||
76 | + /* Verify server response */ | ||
77 | + if (output_file_name != NULL) { | ||
78 | + struct stat ostat; | ||
79 | + if (stat(output_file_name, &ostat) != 0) { | ||
80 | + printf("UNKNOWN - File not found %s\n", output_file_name); | ||
81 | + return STATE_UNKNOWN; | ||
82 | + } | ||
83 | + size_t out_len = ostat.st_size; | ||
84 | + | ||
85 | + FILE * out = fopen(output_file_name, "rb"); | ||
86 | + if (out == NULL) { | ||
87 | + printf("UNKNOWN - Can not open file: %s\n", output_file_name); | ||
88 | + return STATE_UNKNOWN; | ||
89 | + } | ||
90 | + char * outdata = malloc(out_len); | ||
91 | + if (outdata == NULL) { | ||
92 | + printf(_("UNKNOWN - Not enough memory\n")); | ||
93 | + return STATE_UNKNOWN; | ||
94 | + } | ||
95 | + size_t bytes = fread(outdata, 1, out_len, out); | ||
96 | + if (bytes != out_len) { | ||
97 | + printf("UNKNOWN - Error reading file: \n", output_file_name); | ||
98 | + free(outdata); | ||
99 | + fclose(out); | ||
100 | + return STATE_UNKNOWN; | ||
101 | + } | ||
102 | + fclose(out); | ||
103 | + | ||
104 | + char * rcvbuf = malloc(out_len); | ||
105 | + if (rcvbuf != NULL) { | ||
106 | + char *p = rcvbuf; | ||
107 | + size_t count = 0; | ||
108 | + | ||
109 | + do { | ||
110 | + count += my_bin_recv(p, out_len-count); | ||
111 | + p += count; | ||
112 | + } while (count < out_len); | ||
113 | + | ||
114 | + if (memcmp(outdata, rcvbuf, out_len) == 0) { | ||
115 | + result = STATE_OK; | ||
116 | + } else { | ||
117 | + printf(_("WARNING response does not match\n")); | ||
118 | + result = expect_mismatch_state; | ||
119 | + } | ||
120 | + free(rcvbuf); | ||
121 | + } else { | ||
122 | + result = STATE_UNKNOWN; | ||
123 | + } | ||
124 | + | ||
125 | + } | ||
126 | + | ||
127 | if (server_quit != NULL) { | ||
128 | #ifdef HAVE_SSL | ||
129 | if (use_ssl) { | ||
130 | @@ -417,6 +515,8 @@ | ||
131 | {"expect", required_argument, 0, 'e'}, | ||
132 | {"maxbytes", required_argument, 0, 'm'}, | ||
133 | {"quit", required_argument, 0, 'q'}, | ||
134 | + {"inputfile", required_argument, 0, 'i'}, | ||
135 | + {"outputfile", required_argument, 0, 'o'}, | ||
136 | {"jail", required_argument, 0, 'j'}, | ||
137 | {"delay", required_argument, 0, 'd'}, | ||
138 | {"refuse", required_argument, 0, 'r'}, | ||
139 | @@ -454,8 +554,8 @@ | ||
140 | } | ||
141 | |||
142 | while (1) { | ||
143 | - c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", | ||
144 | - longopts, &option); | ||
145 | + c = getopt_long (argc, argv, | ||
146 | + "+hVv46H:s:e:q:m:c:i:o:w:t:p:C:W:d:Sr:jD:M:", longopts, &option); | ||
147 | |||
148 | if (c == -1 || c == EOF || c == 1) | ||
149 | break; | ||
150 | @@ -527,6 +627,12 @@ | ||
151 | case 's': | ||
152 | server_send = optarg; | ||
153 | break; | ||
154 | + case 'i': | ||
155 | + input_file_name = optarg; | ||
156 | + break; | ||
157 | + case 'o': | ||
158 | + output_file_name = optarg; | ||
159 | + break; | ||
160 | case 'e': /* expect string (may be repeated) */ | ||
161 | EXPECT = NULL; | ||
162 | exact_matching = FALSE; | ||
163 | @@ -748,7 +854,18 @@ | ||
164 | return i; | ||
165 | } | ||
166 | |||
167 | - | ||
168 | +int my_bin_recv(char * buf, size_t len) { | ||
169 | + int i; | ||
170 | +#ifdef HAVE_SSL | ||
171 | + if (use_ssl) { | ||
172 | + i = SSL_read (ssl, buf, len); | ||
173 | + } else { | ||
174 | +#endif | ||
175 | + i = read (sd, buf, len); | ||
176 | +#ifdef HAVE_SSL | ||
177 | + } | ||
178 | +#endif | ||
179 | +} | ||
180 | |||
181 | void | ||
182 | print_help (void) | ||
183 | @@ -786,6 +903,10 @@ | ||
184 | Hide output from TCP socket\n\ | ||
185 | -m, --maxbytes=INTEGER\n\ | ||
186 | Close connection once more than this number of bytes are received\n\ | ||
187 | + -i, --inputfile=file_name\n\ | ||
188 | + Input file to send to server\n\ | ||
189 | + -o, --outputfile=file_name\n\ | ||
190 | + Output file to binary compare with server response\n\ | ||
191 | -d, --delay=INTEGER\n\ | ||
192 | Seconds to wait between sending string and polling for response\n")); | ||
193 | |||
194 | @@ -816,5 +937,6 @@ | ||
195 | [-s <send string>] [-e <expect string>] [-q <quit string>]\n\ | ||
196 | [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\ | ||
197 | [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\ | ||
198 | + [-i <input file>] [-o <output file>]\n\ | ||
199 | [-D <days to cert expiry>] [-S <use SSL>]\n", progname); | ||
200 | } | ||
201 | diff -rNu nagios_orig/plugins/Makefile.am nagios-plugins-1.4/plugins/Makefile.am | ||
202 | --- nagios_orig/plugins/Makefile.am 2005-02-01 13:30:38.000000000 +0100 | ||
203 | +++ nagios-plugins-1.4/plugins/Makefile.am 2005-03-09 17:25:07.000000000 +0100 | ||
204 | @@ -16,8 +16,8 @@ | ||
205 | check_udp check_ups check_users negate urlize check_icmp\ | ||
206 | @EXTRAS@ | ||
207 | |||
208 | -check_tcp_programs = check_ftp check_imap check_nntp check_pop check_udp2 \ | ||
209 | - @check_tcp_ssl@ | ||
210 | +check_tcp_programs = check_ftp check_imap check_nntp check_pop check_tcp_bin \ | ||
211 | + check_udp2 @check_tcp_ssl@ | ||
212 | |||
213 | EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | ||
214 | check_swap check_fping check_ldap check_game check_dig \ | ||