diff options
Diffstat (limited to 'web/attachments/57482-check_smtp.patch')
-rw-r--r-- | web/attachments/57482-check_smtp.patch | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/web/attachments/57482-check_smtp.patch b/web/attachments/57482-check_smtp.patch new file mode 100644 index 0000000..2c81f99 --- /dev/null +++ b/web/attachments/57482-check_smtp.patch | |||
@@ -0,0 +1,272 @@ | |||
1 | --- check_smtp-cvs.c 2003-07-31 19:02:23.000000000 -0500 | ||
2 | +++ check_smtp.c 2003-07-31 19:02:07.000000000 -0500 | ||
3 | @@ -33,6 +33,7 @@ | ||
4 | |||
5 | const char *option_summary = "\ | ||
6 | -H host [-p port] [-e expect] [-C command] [-f from addr]\n\ | ||
7 | + [-A authtype -U authuser -P authpass]\n\ | ||
8 | [-w warn] [-c crit] [-t timeout] [-n] [-v] [-4|-6]"; | ||
9 | |||
10 | const char *options = "\ | ||
11 | @@ -53,6 +54,12 @@ | ||
12 | -f, --from=STRING\n\ | ||
13 | FROM-address to include in MAIL command, required by Exchange 2000\n\ | ||
14 | (default: '%s')\n\ | ||
15 | + -A, --authtype=STRING\n\ | ||
16 | + SMTP AUTH type to check (default none, only LOGIN supported)\n\ | ||
17 | + -U, --authuser=STRING\n\ | ||
18 | + SMTP AUTH username\n\ | ||
19 | + -P, --authpass=STRING\n\ | ||
20 | + SMTP AUTH password\n\ | ||
21 | -w, --warning=INTEGER\n\ | ||
22 | Seconds necessary to result in a warning status\n\ | ||
23 | -c, --critical=INTEGER\n\ | ||
24 | @@ -89,12 +96,80 @@ | ||
25 | int smtp_use_dummycmd = 1; | ||
26 | char *mail_command = "MAIL "; | ||
27 | char *from_arg = " "; | ||
28 | +char *authtype = NULL; | ||
29 | +char *authuser = NULL; | ||
30 | +char *authpass = NULL; | ||
31 | int warning_time = 0; | ||
32 | int check_warning_time = FALSE; | ||
33 | int critical_time = 0; | ||
34 | int check_critical_time = FALSE; | ||
35 | int verbose = 0; | ||
36 | |||
37 | +/* encode64 routine from http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20245582.html */ | ||
38 | + | ||
39 | +/* #define OK (0) */ | ||
40 | +/* #define FAIL (-1) */ | ||
41 | +#define BUFOVER (-2) | ||
42 | +#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)]) | ||
43 | +static char basis_64[] = | ||
44 | +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????"; | ||
45 | +static char index_64[128] = { | ||
46 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
47 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||
48 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, | ||
49 | + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, | ||
50 | + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | ||
51 | + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, | ||
52 | + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | ||
53 | + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 | ||
54 | +}; | ||
55 | + | ||
56 | +static int | ||
57 | +encode64(const char *_in, unsigned inlen, char *_out, unsigned outmax, unsigned *outlen) | ||
58 | +{ | ||
59 | + | ||
60 | + const unsigned char *in = (const unsigned char *) _in; | ||
61 | + unsigned char *out = (unsigned char *) _out; | ||
62 | + unsigned char oval; | ||
63 | + char *blah; | ||
64 | + unsigned olen; | ||
65 | + | ||
66 | + olen = (inlen + 2) / 3 * 4; | ||
67 | + if (outlen) | ||
68 | + *outlen = olen; | ||
69 | + if (outmax < olen) | ||
70 | + return BUFOVER; | ||
71 | + | ||
72 | + blah = (char *) out; | ||
73 | + while (inlen >= 3) | ||
74 | + { | ||
75 | +/* user provided max buffer size; make sure we don't go over it */ | ||
76 | + *out++ = basis_64[in[0] >> 2]; | ||
77 | + *out++ = basis_64[((in[0] << 4) & 0x30) | (in[1] >> 4)]; | ||
78 | + *out++ = basis_64[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; | ||
79 | + *out++ = basis_64[in[2] & 0x3f]; | ||
80 | + in += 3; | ||
81 | + inlen -= 3; | ||
82 | + } | ||
83 | + if (inlen > 0) | ||
84 | + { | ||
85 | +/* user provided max buffer size; make sure we don't go over it */ | ||
86 | + *out++ = basis_64[in[0] >> 2]; | ||
87 | + oval = (in[0] << 4) & 0x30; | ||
88 | + if (inlen > 1) | ||
89 | + oval |= in[1] >> 4; | ||
90 | + *out++ = basis_64[oval]; | ||
91 | + *out++ = (inlen < 2) ? '=' : basis_64[(in[1] << 2) & 0x3c]; | ||
92 | + *out++ = '='; | ||
93 | + } | ||
94 | + | ||
95 | + if (olen < outmax) | ||
96 | + *out = '\0'; | ||
97 | + | ||
98 | + return OK; | ||
99 | + | ||
100 | +} | ||
101 | + | ||
102 | int | ||
103 | main (int argc, char **argv) | ||
104 | { | ||
105 | @@ -104,6 +179,7 @@ | ||
106 | char buffer[MAX_INPUT_BUFFER] = ""; | ||
107 | char *from_str = NULL; | ||
108 | char *helocmd = NULL; | ||
109 | + char *error_msg = NULL; | ||
110 | struct timeval tv; | ||
111 | |||
112 | if (process_arguments (argc, argv) != OK) | ||
113 | @@ -163,7 +239,97 @@ | ||
114 | |||
115 | /* allow for response to helo command to reach us */ | ||
116 | recv(sd, buffer, MAX_INPUT_BUFFER-1, 0); | ||
117 | - | ||
118 | + | ||
119 | + if (authtype != NULL) { | ||
120 | + if (strcmp (authtype, "LOGIN") == 0) { | ||
121 | + char abuf[MAX_INPUT_BUFFER]; | ||
122 | + unsigned alen; | ||
123 | + int ret; | ||
124 | + do { | ||
125 | + if (authuser == NULL) { | ||
126 | + result = STATE_CRITICAL; | ||
127 | + error_msg = "no authuser specified"; | ||
128 | + break; | ||
129 | + } | ||
130 | + if (authpass == NULL) { | ||
131 | + result = STATE_CRITICAL; | ||
132 | + error_msg = "no authpass specified"; | ||
133 | + break; | ||
134 | + } | ||
135 | + send(sd, "AUTH LOGIN\r\n", strlen("AUTH LOGIN\r\n"), 0); | ||
136 | + if (verbose == TRUE) { | ||
137 | + printf ("sent AUTH LOGIN\n"); | ||
138 | + } | ||
139 | + if ((ret = recv(sd, buffer, MAX_INPUT_BUFFER-1, 0)) == -1) { | ||
140 | + result = STATE_CRITICAL; | ||
141 | + error_msg = "recv() failed after AUTH LOGIN"; | ||
142 | + break; | ||
143 | + } | ||
144 | + buffer[ret] = 0; | ||
145 | + if (verbose == TRUE) { | ||
146 | + printf ("received %s\n", buffer); | ||
147 | + } | ||
148 | + if (strncmp (buffer, "334", 3) != 0) { | ||
149 | + result = STATE_CRITICAL; | ||
150 | + error_msg = "invalid response received after AUTH LOGIN"; | ||
151 | + break; | ||
152 | + } | ||
153 | + if (encode64 (authuser, strlen(authuser), abuf, MAX_INPUT_BUFFER, &alen) != OK) { | ||
154 | + result = STATE_CRITICAL; | ||
155 | + error_msg = "failed to base64-encode authuser"; | ||
156 | + break; | ||
157 | + } | ||
158 | + strcat (abuf, "\r\n"); | ||
159 | + send(sd, abuf, strlen(abuf), 0); | ||
160 | + if (verbose == TRUE) { | ||
161 | + printf ("sent %s\n", abuf); | ||
162 | + } | ||
163 | + if ((ret = recv(sd, buffer, MAX_INPUT_BUFFER-1, 0)) == -1) { | ||
164 | + result = STATE_CRITICAL; | ||
165 | + error_msg = "recv() failed after sending authuser"; | ||
166 | + break; | ||
167 | + } | ||
168 | + buffer[ret] = 0; | ||
169 | + if (verbose == TRUE) { | ||
170 | + printf ("received %s\n", buffer); | ||
171 | + } | ||
172 | + if (strncmp (buffer, "334", 3) != 0) { | ||
173 | + result = STATE_CRITICAL; | ||
174 | + error_msg = "invalid response received after authuser"; | ||
175 | + break; | ||
176 | + } | ||
177 | + if (encode64 (authpass, strlen(authpass), abuf, MAX_INPUT_BUFFER, &alen) != OK) { | ||
178 | + result = STATE_CRITICAL; | ||
179 | + error_msg = "failed to base64-encode authpass"; | ||
180 | + break; | ||
181 | + } | ||
182 | + strcat (abuf, "\r\n"); | ||
183 | + send(sd, abuf, strlen(abuf), 0); | ||
184 | + if (verbose == TRUE) { | ||
185 | + printf ("sent %s\n", abuf); | ||
186 | + } | ||
187 | + if ((ret = recv(sd, buffer, MAX_INPUT_BUFFER-1, 0)) == -1) { | ||
188 | + result = STATE_CRITICAL; | ||
189 | + error_msg = "recv() failed after sending authpass"; | ||
190 | + break; | ||
191 | + } | ||
192 | + buffer[ret] = 0; | ||
193 | + if (verbose == TRUE) { | ||
194 | + printf ("received %s\n", buffer); | ||
195 | + } | ||
196 | + if (strncmp (buffer, "235", 3) != 0) { | ||
197 | + result = STATE_CRITICAL; | ||
198 | + error_msg = "invalid response received after authpass"; | ||
199 | + break; | ||
200 | + } | ||
201 | + break; | ||
202 | + } while (0); | ||
203 | + } else { | ||
204 | + result = STATE_CRITICAL; | ||
205 | + error_msg = "only authtype LOGIN is supported"; | ||
206 | + } | ||
207 | + } | ||
208 | + | ||
209 | /* sendmail will syslog a "NOQUEUE" error if session does not attempt | ||
210 | * to do something useful. This can be prevented by giving a command | ||
211 | * even if syntax is illegal (MAIL requires a FROM:<...> argument) | ||
212 | @@ -204,11 +370,21 @@ | ||
213 | result = STATE_WARNING; | ||
214 | |||
215 | if (verbose) | ||
216 | - printf ("SMTP %s - %.3f sec. response time, %s|time=%.3f\n", | ||
217 | - state_text (result), elapsed_time, buffer, elapsed_time); | ||
218 | + if (error_msg == NULL) { | ||
219 | + printf ("SMTP %s - %.3f sec. response time, %s|time=%.3f\n", | ||
220 | + state_text (result), elapsed_time, buffer, elapsed_time); | ||
221 | + } else { | ||
222 | + printf ("SMTP %s - %s, %.3f sec. response time, %s|time=%.3f\n", | ||
223 | + state_text (result), error_msg, elapsed_time, buffer, elapsed_time); | ||
224 | + } | ||
225 | else | ||
226 | - printf ("SMTP %s - %.3f second response time|time=%.3f\n", | ||
227 | - state_text (result), elapsed_time, elapsed_time); | ||
228 | + if (error_msg == NULL) { | ||
229 | + printf ("SMTP %s - %.3f second response time|time=%.3f\n", | ||
230 | + state_text (result), elapsed_time, elapsed_time); | ||
231 | + } else { | ||
232 | + printf ("SMTP %s - %s, %.3f second response time|time=%.3f\n", | ||
233 | + state_text (result), error_msg, elapsed_time, elapsed_time); | ||
234 | + } | ||
235 | |||
236 | return result; | ||
237 | } | ||
238 | @@ -233,6 +409,9 @@ | ||
239 | {"timeout", required_argument, 0, 't'}, | ||
240 | {"port", required_argument, 0, 'p'}, | ||
241 | {"from", required_argument, 0, 'f'}, | ||
242 | + {"authtype", required_argument, 0, 'A'}, | ||
243 | + {"authuser", required_argument, 0, 'U'}, | ||
244 | + {"authpass", required_argument, 0, 'P'}, | ||
245 | {"command", required_argument, 0, 'C'}, | ||
246 | {"nocommand", required_argument, 0, 'n'}, | ||
247 | {"verbose", no_argument, 0, 'v'}, | ||
248 | @@ -256,7 +435,7 @@ | ||
249 | } | ||
250 | |||
251 | while (1) { | ||
252 | - c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:", | ||
253 | + c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:A:U:P:", | ||
254 | long_options, &option_index); | ||
255 | |||
256 | if (c == -1 || c == EOF) | ||
257 | @@ -282,6 +461,15 @@ | ||
258 | case 'f': /* from argument */ | ||
259 | from_arg = optarg; | ||
260 | break; | ||
261 | + case 'A': | ||
262 | + authtype = optarg; | ||
263 | + break; | ||
264 | + case 'U': | ||
265 | + authuser = optarg; | ||
266 | + break; | ||
267 | + case 'P': | ||
268 | + authpass = optarg; | ||
269 | + break; | ||
270 | case 'e': /* server expect string on 220 */ | ||
271 | server_expect = optarg; | ||
272 | break; | ||