summaryrefslogtreecommitdiffstats
path: root/web/attachments/55482-check_smtp.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/55482-check_smtp.patch')
-rw-r--r--web/attachments/55482-check_smtp.patch287
1 files changed, 287 insertions, 0 deletions
diff --git a/web/attachments/55482-check_smtp.patch b/web/attachments/55482-check_smtp.patch
new file mode 100644
index 0000000..4ce0629
--- /dev/null
+++ b/web/attachments/55482-check_smtp.patch
@@ -0,0 +1,287 @@
1Index: check_smtp.c
2===================================================================
3RCS file: /usr/local/cvs/root/nagios-plugins/plugins/check_smtp.c,v
4retrieving revision 1.1.1.1
5retrieving revision 1.2
6diff -u -r1.1.1.1 -r1.2
7--- check_smtp.c 3 Jul 2003 23:27:44 -0000 1.1.1.1
8+++ check_smtp.c 3 Jul 2003 23:35:52 -0000 1.2
9@@ -69,12 +69,80 @@
10 char *server_address = NULL;
11 char *server_expect = NULL;
12 char *from_arg = " ";
13+char *authtype = NULL;
14+char *authuser = NULL;
15+char *authpass = NULL;
16 int warning_time = 0;
17 int check_warning_time = FALSE;
18 int critical_time = 0;
19 int check_critical_time = FALSE;
20 int verbose = FALSE;
21
22+/* encode64 routine from http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20245582.html */
23+
24+/* #define OK (0) */
25+/* #define FAIL (-1) */
26+#define BUFOVER (-2)
27+#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])
28+static char basis_64[] =
29+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????";
30+static char index_64[128] = {
31+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
34+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
35+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
36+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
37+ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
38+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
39+};
40+
41+static int
42+encode64(const char *_in, unsigned inlen, char *_out, unsigned outmax, unsigned *outlen)
43+{
44+
45+ const unsigned char *in = (const unsigned char *) _in;
46+ unsigned char *out = (unsigned char *) _out;
47+ unsigned char oval;
48+ char *blah;
49+ unsigned olen;
50+
51+ olen = (inlen + 2) / 3 * 4;
52+ if (outlen)
53+ *outlen = olen;
54+ if (outmax < olen)
55+ return BUFOVER;
56+
57+ blah = (char *) out;
58+ while (inlen >= 3)
59+ {
60+/* user provided max buffer size; make sure we don't go over it */
61+ *out++ = basis_64[in[0] >> 2];
62+ *out++ = basis_64[((in[0] << 4) & 0x30) | (in[1] >> 4)];
63+ *out++ = basis_64[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
64+ *out++ = basis_64[in[2] & 0x3f];
65+ in += 3;
66+ inlen -= 3;
67+ }
68+ if (inlen > 0)
69+ {
70+/* user provided max buffer size; make sure we don't go over it */
71+ *out++ = basis_64[in[0] >> 2];
72+ oval = (in[0] << 4) & 0x30;
73+ if (inlen > 1)
74+ oval |= in[1] >> 4;
75+ *out++ = basis_64[oval];
76+ *out++ = (inlen < 2) ? '=' : basis_64[(in[1] << 2) & 0x3c];
77+ *out++ = '=';
78+ }
79+
80+ if (olen < outmax)
81+ *out = '\0';
82+
83+ return OK;
84+
85+}
86+
87 int
88 main (int argc, char **argv)
89 {
90@@ -151,14 +219,19 @@
91 && (end_time - start_time) > warning_time) result =
92 STATE_WARNING;
93
94- if (verbose == TRUE)
95- printf ("SMTP %s - %d sec. response time, %s\n",
96+ if (authtype == NULL) {
97+ if (verbose == TRUE)
98+ printf ("SMTP %s - %d sec. response time, %s\n",
99 state_text (result), (int) (end_time - start_time), buffer);
100- else
101- printf ("SMTP %s - %d second response time\n", state_text (result),
102+ else
103+ printf ("SMTP %s - %d second response time\n", state_text (result),
104 (int) (end_time - start_time));
105+ }
106 }
107 }
108+ }
109+
110+ if (result == STATE_OK) {
111
112 /* close the connection */
113
114@@ -168,6 +241,112 @@
115 /* allow for response to helo command to reach us */
116 recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
117
118+ if (authtype != NULL) {
119+ if (strcmp (authtype, "LOGIN") == 0) {
120+ if (authuser == NULL) {
121+ result = STATE_CRITICAL;
122+ printf ("SMTP %s - no authuser specified\n", state_text (result));
123+ } else if (authpass == NULL) {
124+ result = STATE_CRITICAL;
125+ printf ("SMTP %s - no authpass specified\n", state_text (result));
126+ } else {
127+ char abuf[MAX_INPUT_BUFFER];
128+ unsigned alen;
129+ int ret;
130+ do {
131+ send(sd, "AUTH LOGIN\r\n", strlen("AUTH LOGIN\r\n"), 0);
132+ if (verbose == TRUE) {
133+ printf ("sent AUTH LOGIN\n");
134+ }
135+ if ((ret = recv(sd, buffer, MAX_INPUT_BUFFER-1, 0)) == -1) {
136+ result = STATE_WARNING;
137+ printf ("SMTP %s - recv() failed after AUTH LOGIN\n",
138+ state_text (result));
139+ break;
140+ }
141+ buffer[ret] = 0;
142+ if (verbose == TRUE) {
143+ printf ("received %s\n", buffer);
144+ }
145+ if (strncmp (buffer, "334", 3) != 0) {
146+ result = STATE_CRITICAL;
147+ printf ("SMTP %s - Invalid response received from host after AUTH LOGIN\n",
148+ state_text (result));
149+ break;
150+ }
151+ if (encode64 (authuser, strlen(authuser), abuf, MAX_INPUT_BUFFER, &alen) != OK) {
152+ result = STATE_WARNING;
153+ printf ("SMTP %s - Failed to base64-encode authuser\n",
154+ state_text (result));
155+ break;
156+ }
157+ strcat (abuf, "\r\n");
158+ send(sd, abuf, strlen(abuf), 0);
159+ if (verbose == TRUE) {
160+ printf ("sent %s\n", abuf);
161+ }
162+ if ((ret = recv(sd, buffer, MAX_INPUT_BUFFER-1, 0)) == -1) {
163+ result = STATE_WARNING;
164+ printf ("SMTP %s - recv() failed after sending authuser\n",
165+ state_text (result));
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+ printf ("SMTP %s - Invalid response received from host after authuser\n",
175+ state_text (result));
176+ break;
177+ }
178+ if (encode64 (authpass, strlen(authpass), abuf, MAX_INPUT_BUFFER, &alen) != OK) {
179+ result = STATE_WARNING;
180+ printf ("SMTP %s - Failed to base64-encode authpass\n",
181+ state_text (result));
182+ break;
183+ }
184+ strcat (abuf, "\r\n");
185+ send(sd, abuf, strlen(abuf), 0);
186+ if (verbose == TRUE) {
187+ printf ("sent %s\n", abuf);
188+ }
189+ if ((ret = recv(sd, buffer, MAX_INPUT_BUFFER-1, 0)) == -1) {
190+ result = STATE_WARNING;
191+ printf ("SMTP %s - recv() failed after sending authpass\n",
192+ state_text (result));
193+ break;
194+ }
195+ buffer[ret] = 0;
196+ if (verbose == TRUE) {
197+ printf ("received %s\n", buffer);
198+ }
199+ if (strncmp (buffer, "235", 3) != 0) {
200+ result = STATE_CRITICAL;
201+ printf ("SMTP %s - Invalid response received from host after authpass\n",
202+ state_text (result));
203+ break;
204+ }
205+ break;
206+ } while (0);
207+ if (result == STATE_OK) {
208+ if (verbose == TRUE)
209+ printf ("SMTP %s - %d sec. response time, %s\n",
210+ state_text (result), (int) (end_time - start_time), buffer);
211+ else
212+ printf ("SMTP %s - %d second response time\n", state_text (result),
213+ (int) (end_time - start_time));
214+ }
215+ }
216+ } else {
217+ result = STATE_CRITICAL;
218+ printf ("SMTP %s - authtype %s is not supported\n", state_text (result), authtype);
219+ }
220+ }
221+ }
222+
223+ if (result == STATE_OK) {
224 #ifdef SMTP_USE_DUMMYCMD
225 send(sd, from_str, strlen(from_str), 0);
226
227@@ -211,6 +390,9 @@
228 {"warning", required_argument, 0, 'w'},
229 {"port", required_argument, 0, 'p'},
230 {"from", required_argument, 0, 'f'},
231+ {"authtype", required_argument, 0, 'A'},
232+ {"authuser", required_argument, 0, 'U'},
233+ {"authpass", required_argument, 0, 'P'},
234 {"verbose", no_argument, 0, 'v'},
235 {"version", no_argument, 0, 'V'},
236 {"help", no_argument, 0, 'h'},
237@@ -233,10 +415,10 @@
238 while (1) {
239 #ifdef HAVE_GETOPT_H
240 c =
241- getopt_long (argc, argv, "+hVvt:p:f:e:c:w:H:", long_options,
242+ getopt_long (argc, argv, "+hVvt:p:f:e:c:w:H:A:U:P:", long_options,
243 &option_index);
244 #else
245- c = getopt (argc, argv, "+?hVvt:p:f:e:c:w:H:");
246+ c = getopt (argc, argv, "+?hVvt:p:f:e:c:w:H:A:U:P:");
247 #endif
248 if (c == -1 || c == EOF)
249 break;
250@@ -261,6 +443,15 @@
251 case 'f': /* from argument */
252 from_arg = optarg;
253 break;
254+ case 'A':
255+ authtype = optarg;
256+ break;
257+ case 'U':
258+ authuser = optarg;
259+ break;
260+ case 'P':
261+ authpass = optarg;
262+ break;
263 case 'e': /* server expect string on 220 */
264 server_expect = optarg;
265 break;
266@@ -355,6 +546,12 @@
267 " String to expect in first line of server response (default: %s)\n"
268 " -f, --from=STRING\n"
269 " from address to include in MAIL command (default NULL, Exchange2000 requires one)\n"
270+ " -A, --authtype=STRING\n"
271+ " SMTP AUTH type to check (default NULL, only LOGIN supported)\n"
272+ " -U, --authuser=STRING\n"
273+ " SMTP AUTH username\n"
274+ " -P, --authpass=STRING\n"
275+ " SMTP AUTH password\n"
276 " -w, --warning=INTEGER\n"
277 " Seconds necessary to result in a warning status\n"
278 " -c, --critical=INTEGER\n"
279@@ -379,7 +576,7 @@
280 print_usage (void)
281 {
282 printf
283- ("Usage: %s -H host [-e expect] [-p port] [-f from addr] [-w warn] [-c crit] [-t timeout] [-v]\n"
284+ ("Usage: %s -H host [-e expect] [-p port] [-A authtype -U authuser -P authpass] [-f from addr] [-w warn] [-c crit] [-t timeout] [-v]\n"
285 " %s --help\n"
286 " %s --version\n", progname, progname, progname);
287 }