X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fos_regex%2Fos_match_execute.c;fp=src%2Fos_regex%2Fos_match_execute.c;h=77b5ed6a4da4e6be98c680a7ea1626cd7c7c7f98;hp=0bc8377f5dd04eb6f2f3fee3241953fbaf913cfb;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/os_regex/os_match_execute.c b/src/os_regex/os_match_execute.c old mode 100755 new mode 100644 index 0bc8377..77b5ed6 --- a/src/os_regex/os_match_execute.c +++ b/src/os_regex/os_match_execute.c @@ -1,5 +1,3 @@ -/* $OSSEC, os_match_execute.c, v0.1, 2006/04/18, Daniel B. Cid$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -9,138 +7,80 @@ * Foundation */ - #include #include #include #include "os_regex.h" -#include "os_regex_internal.h" - -/** Internal matching **/ -int _OS_Match(const char *pattern, const char *str, size_t str_len, size_t size) +/* Compare an already compiled pattern with a not NULL string. + * Returns 1 on success or 0 on error. + * The error code is set on reg->error. + */ +int OSMatch_Execute(const char *str, size_t str_len, OSMatch *reg) { - size_t i = 0,j; - const char *pt = pattern; - - if(str_len < size) - return(FALSE); - - size = str_len - size; - - /* Look to match the first pattern */ - do - { - /* Match */ - if(charmap[(uchar)str[i]] == *pt) - { - pt++; - j = i+1; - - while(*pt != '\0') - { - if(str[j] == '\0') - return(FALSE); - - else if(*pt != charmap[(uchar)str[j]]) - { - pt = pattern; - goto nnext; - } - j++;pt++; - } - return(TRUE); - nnext: - continue; - } - }while(++i <= size); - - return(FALSE); + return reg->exec_function(str, str_len, reg); } +int OSMatch_Execute_true(const char *subject, size_t len, OSMatch *match) +{ + (void)subject; + (void)len; + (void)match; + return (1); +} -/** Internal matching **/ -int _os_strncmp(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, size_t size) +int OSMatch_Execute_pcre2_match(const char *str, size_t str_len, OSMatch * reg) { - if(strncasecmp(pattern, str, size) == 0) - return(TRUE); + int rc = 0; + +#ifdef USE_PCRE2_JIT + rc = pcre2_jit_match(reg->regex, (PCRE2_SPTR)str, str_len, 0, 0, reg->match_data, NULL); +#else + rc = pcre2_match(reg->regex, (PCRE2_SPTR)str, str_len, 0, 0, reg->match_data, NULL); +#endif - return(FALSE); + return (rc >= 0); } -/** Internal matching **/ -int _os_strcmp(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size) +int OSMatch_Execute_strcmp(const char *subject, size_t len, OSMatch *match) { - if(strcasecmp(pattern, str) == 0) - return(TRUE); - - return(FALSE); + //^literal$ + (void)len; + return !strcmp(match->pattern, subject); } -int _os_strmatch(__attribute__((unused)) const char *pattern, __attribute__((unused)) const char *str, - __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size) +int OSMatch_Execute_strncmp(const char *subject, size_t len, OSMatch *match) { - return(TRUE); + //^literal + (void)len; + return !strncmp(match->pattern, subject, match->pattern_len); } -int _os_strstr(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size) +int OSMatch_Execute_strrcmp(const char *subject, size_t len, OSMatch *match) { - if(strstr(str, pattern) != NULL) - { - return(TRUE); + // literal$ + if (len >= match->pattern_len) { + return !strcmp(match->pattern, &subject[len - match->pattern_len]); } - return(FALSE); + return (0); } - -/** Internal matching **/ -int _os_strcmp_last(const char *pattern, const char *str, size_t str_len, size_t size) +int OSMatch_Execute_strcasecmp(const char *subject, size_t len, OSMatch *match) { - /* Size of the string must be bigger */ - if(str_len < size) - return(FALSE); - - if(strcasecmp(pattern, str + (str_len - size)) == 0) - return(TRUE); - - return(FALSE); + return (len == match->pattern_len && !strcasecmp(match->pattern, subject)); } - -/** int OSMatch_Execute(char *str, int str_len, OSMatch *reg) v0.1 - * Compare an already compiled pattern with - * a not NULL string. - * Returns 1 on success or 0 on error. - * The error code is set on reg->error. - */ -int OSMatch_Execute(const char *str, size_t str_len, OSMatch *reg) +int OSMatch_Execute_strncasecmp(const char *subject, size_t len, OSMatch *match) { - short int i = 0; - - /* The string can't be NULL */ - if(str == NULL) - { - reg->error = OS_REGEX_STR_NULL; - return(0); - } - + (void)len; + return !strncasecmp(match->pattern, subject, match->pattern_len); +} - /* Looping on all sub patterns */ - while(reg->patterns[i]) - { - if(reg->match_fp[i](reg->patterns[i], - str, - str_len, - reg->size[i]) == TRUE) - { - return(1); - } - i++; +int OSMatch_Execute_strrcasecmp(const char *subject, size_t len, OSMatch *match) { + if (len >= match->pattern_len) { + return !strcasecmp(match->pattern, &subject[len - match->pattern_len]); } - - return(0); + return (0); } - -/* EOF */