summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 09f8f14..8f9ec8b 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -37,6 +37,18 @@ int validate_arguments (void);
37void print_help (void); 37void print_help (void);
38void print_usage (void); 38void print_usage (void);
39 39
40#ifdef HAVE_REGEX_H
41#include <regex.h>
42char regex_expect[MAX_INPUT_BUFFER] = "";
43regex_t preg;
44regmatch_t pmatch[10];
45char timestamp[10] = "";
46char errbuf[MAX_INPUT_BUFFER];
47int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
48int eflags = 0;
49int errcode, excode;
50#endif
51
40int server_port = SMTP_PORT; 52int server_port = SMTP_PORT;
41char *server_address = NULL; 53char *server_address = NULL;
42char *server_expect = NULL; 54char *server_expect = NULL;
@@ -160,9 +172,36 @@ main (int argc, char **argv)
160 if (verbose) 172 if (verbose)
161 printf("%s", buffer); 173 printf("%s", buffer);
162 strip (buffer); 174 strip (buffer);
163 if (n < nresponses && strstr(buffer, responses[n])!=buffer) { 175 if (n < nresponses) {
164 result = STATE_WARNING; 176#ifdef HAVE_REGEX_H
165 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]); 177 cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
178 //strncpy (regex_expect, responses[n], sizeof (regex_expect) - 1);
179 //regex_expect[sizeof (regex_expect) - 1] = '\0';
180 errcode = regcomp (&preg, responses[n], cflags);
181 if (errcode != 0) {
182 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
183 printf (_("Could Not Compile Regular Expression"));
184 return ERROR;
185 }
186 excode = regexec (&preg, buffer, 10, pmatch, eflags);
187 if (excode == 0) {
188 result = STATE_OK;
189 }
190 else if (excode == REG_NOMATCH) {
191 result = STATE_WARNING;
192 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
193 }
194 else {
195 regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
196 printf (_("Execute Error: %s\n"), errbuf);
197 result = STATE_UNKNOWN;
198 }
199#else
200 if (strstr(buffer, responses[n])!=buffer) {
201 result = STATE_WARNING;
202 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
203 }
204#endif
166 } 205 }
167 n++; 206 n++;
168 } 207 }