diff options
author | Jeremy Allison <jra@samba.org> | 2000-01-06 21:09:11 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2000-01-06 21:09:11 +0000 |
commit | 8b790cf3e21dd415e1daba24f5eba219e824cdc4 (patch) | |
tree | 76375e651af7f0c8de5ee0cf4233e702d212ba67 /source | |
parent | f4898a1f16a2dbc25d062b0088d6c589a34c93a0 (diff) | |
download | samba-8b790cf3e21dd415e1daba24f5eba219e824cdc4.tar.gz samba-8b790cf3e21dd415e1daba24f5eba219e824cdc4.tar.xz samba-8b790cf3e21dd415e1daba24f5eba219e824cdc4.zip |
Generic wildcard matching fix from weidel@multichart.de.
Jeremy.
Diffstat (limited to 'source')
-rw-r--r-- | source/lib/util.c | 99 |
1 files changed, 80 insertions, 19 deletions
diff --git a/source/lib/util.c b/source/lib/util.c index 1a893c52ce5..a7c322c0a0f 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -1143,35 +1143,68 @@ BOOL unix_do_match(char *str, char *regexp, BOOL case_sig) break; case '*': - /* Look for a character matching - the one after the '*' */ + /* + * Look for a character matching + * the one after the '*'. + */ p++; if(!*p) - return True; /* Automatic match */ + return True; /* Automatic match */ while(*str) { - while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str)))) - str++; - if(unix_do_match(str,p,case_sig)) - return True; - if(!*str) - return False; - else - str++; + /* + * Patch from weidel@multichart.de. In the case of the regexp + * '*XX*' we want to ensure there are at least 2 'X' characters + * in the filename after the '*' for a match to be made. + */ + + { + int matchcount=0; + + /* + * Eat all the characters that match, but count how many there were. + */ + + while(*str && (case_sig ? (*p == *str) : (toupper(*p)==toupper(*str)))) { + str++; + matchcount++; + } + + /* + * Now check that if the regexp had n identical characters that + * matchcount had at least that many matches. + */ + + while (( *(p+1) && (case_sig ? (*(p+1) == *p) : (toupper(*(p+1))==toupper(*p))))) { + p++; + matchcount--; + } + if ( matchcount <= 0 ) { + return False; + } + } + str--; /* We've eaten the match char after the '*' */ + if(unix_do_match(str,p,case_sig)) + return True; + if(!*str) + return False; + else + str++; } return False; default: if(case_sig) { - if(*str != *p) - return False; + if(*str != *p) + return False; } else { - if(toupper(*str) != toupper(*p)) - return False; + if(toupper(*str) != toupper(*p)) + return False; } str++, p++; break; } } + if(!*p && !*str) return True; @@ -1283,10 +1316,38 @@ static BOOL do_match(char *str, char *regexp, int case_sig, BOOL win9x_semantics while(*str) { while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str)))) str++; - /* Now eat all characters that match, as - we want the *last* character to match. */ - while(*str && (case_sig ? (*p == *str) : (toupper(*p)==toupper(*str)))) - str++; + + /* + * Patch from weidel@multichart.de. In the case of the regexp + * '*XX*' we want to ensure there are at least 2 'X' characters + * in the filename after the '*' for a match to be made. + */ + + { + int matchcount=0; + + /* + * Eat all the characters that match, but count how many there were. + */ + + while(*str && (case_sig ? (*p == *str) : (toupper(*p)==toupper(*str)))) { + str++; + matchcount++; + } + + /* + * Now check that if the regexp had n identical characters that + * matchcount had at least that many matches. + */ + + while (( *(p+1) && (case_sig ? (*(p+1) == *p) : (toupper(*(p+1))==toupper(*p))))) { + p++; + matchcount--; + } + if ( matchcount <= 0 ) { + return False; + } + } str--; /* We've eaten the match char after the '*' */ if(do_match(str,p,case_sig,win9x_semantics)) { return True; |