diff options
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r-- | plugins/check_smtp.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 09f8f143..8f9ec8bb 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -37,6 +37,18 @@ int validate_arguments (void); | |||
37 | void print_help (void); | 37 | void print_help (void); |
38 | void print_usage (void); | 38 | void print_usage (void); |
39 | 39 | ||
40 | #ifdef HAVE_REGEX_H | ||
41 | #include <regex.h> | ||
42 | char regex_expect[MAX_INPUT_BUFFER] = ""; | ||
43 | regex_t preg; | ||
44 | regmatch_t pmatch[10]; | ||
45 | char timestamp[10] = ""; | ||
46 | char errbuf[MAX_INPUT_BUFFER]; | ||
47 | int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; | ||
48 | int eflags = 0; | ||
49 | int errcode, excode; | ||
50 | #endif | ||
51 | |||
40 | int server_port = SMTP_PORT; | 52 | int server_port = SMTP_PORT; |
41 | char *server_address = NULL; | 53 | char *server_address = NULL; |
42 | char *server_expect = NULL; | 54 | char *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 | } |