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 | cebc23762d39cdd5373276f97cf68e2bc56d899a (patch) | |
tree | 804fd28389127c6b77b2f6d121e518a8a3b9ed16 | |
parent | 8bd94c178ff108bbc6e686e33b99588876ab8a5a (diff) | |
download | samba-cebc23762d39cdd5373276f97cf68e2bc56d899a.tar.gz samba-cebc23762d39cdd5373276f97cf68e2bc56d899a.tar.bz2 samba-cebc23762d39cdd5373276f97cf68e2bc56d899a.zip |
Generic wildcard matching fix from weidel@multichart.de.
Jeremy.
(This used to be commit 8b790cf3e21dd415e1daba24f5eba219e824cdc4)
-rw-r--r-- | source3/lib/util.c | 99 |
1 files changed, 80 insertions, 19 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index 1a893c52ce..a7c322c0a0 100644 --- a/source3/lib/util.c +++ b/source3/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; |