|
25 | 25 | #define PCRE2_CODE_UNIT_WIDTH 8 |
26 | 26 | #include <pcre2.h> |
27 | 27 | #endif |
| 28 | +#include <regex.h> |
28 | 29 | #include <ctype.h> |
29 | 30 | #include "probe.h" |
30 | 31 | #include "log.h" |
@@ -362,17 +363,38 @@ static int is_socks5_protocol(const char *p_in, ssize_t len, struct sslhcfg_prot |
362 | 363 | return PROBE_MATCH; |
363 | 364 | } |
364 | 365 |
|
| 366 | +/* ****************** |
| 367 | + * is_syslog_protocol |
| 368 | + * */ |
| 369 | +static regex_t syslog_preg; |
| 370 | +static int configured_syslog_regex = 0; |
| 371 | + |
| 372 | +static void config_syslog_regex(void) |
| 373 | +{ |
| 374 | + /* two patterns for syslog messages: |
| 375 | + * <12> My message |
| 376 | + * 15 <12> My message |
| 377 | + * 12 is 'priority', 1 to 3 digits (RFC4234) |
| 378 | + * 15 is 'message length', a TCP-only option (RFC6587) |
| 379 | + */ |
| 380 | + int res = regcomp(&syslog_preg, "^([0-9]{1,3} )?<[0-9]{1,3}>", REG_EXTENDED); |
| 381 | + if (res) { |
| 382 | + print_message(msg_system_error, "regcomp"); |
| 383 | + exit(1); |
| 384 | + } |
| 385 | + configured_syslog_regex = 1; |
| 386 | +} |
| 387 | + |
365 | 388 | static int is_syslog_protocol(const char *p, ssize_t len, struct sslhcfg_protocols_item* proto) |
366 | 389 | { |
367 | | - int res, i, j; |
| 390 | + char buf[len+1]; |
368 | 391 |
|
369 | | - res = sscanf(p, "<%d>", &i); |
370 | | - if (res == 1) return PROBE_MATCH; |
| 392 | + if (!configured_syslog_regex) config_syslog_regex(); |
371 | 393 |
|
372 | | - res = sscanf(p, "%d <%d>", &i, &j); |
373 | | - if (res == 2) return PROBE_MATCH; |
| 394 | + strncpy(buf, p, len); |
| 395 | + buf[len] = 0; |
374 | 396 |
|
375 | | - return PROBE_NEXT; |
| 397 | + return (regexec(&syslog_preg, buf, (size_t)0, NULL, 0) == 0); |
376 | 398 | } |
377 | 399 |
|
378 | 400 | static int is_teamspeak_protocol(const char *p, ssize_t len, struct sslhcfg_protocols_item* proto) |
|
0 commit comments