mirror of
https://github.com/samba-team/samba.git
synced 2025-08-30 17:49:30 +03:00
Generic wildcard matching fix from weidel@multichart.de.
Jeremy.
(This used to be commit 8b790cf3e2
)
This commit is contained in:
@ -1143,14 +1143,46 @@ BOOL unix_do_match(char *str, char *regexp, BOOL case_sig)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '*':
|
case '*':
|
||||||
/* Look for a character matching
|
/*
|
||||||
the one after the '*' */
|
* Look for a character matching
|
||||||
|
* the one after the '*'.
|
||||||
|
*/
|
||||||
p++;
|
p++;
|
||||||
if(!*p)
|
if(!*p)
|
||||||
return True; /* Automatic match */
|
return True; /* Automatic match */
|
||||||
while(*str) {
|
while(*str) {
|
||||||
while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*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++;
|
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))
|
if(unix_do_match(str,p,case_sig))
|
||||||
return True;
|
return True;
|
||||||
if(!*str)
|
if(!*str)
|
||||||
@ -1172,6 +1204,7 @@ BOOL unix_do_match(char *str, char *regexp, BOOL case_sig)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!*p && !*str)
|
if(!*p && !*str)
|
||||||
return True;
|
return True;
|
||||||
|
|
||||||
@ -1283,10 +1316,38 @@ static BOOL do_match(char *str, char *regexp, int case_sig, BOOL win9x_semantics
|
|||||||
while(*str) {
|
while(*str) {
|
||||||
while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str))))
|
while(*str && (case_sig ? (*p != *str) : (toupper(*p)!=toupper(*str))))
|
||||||
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))))
|
* 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++;
|
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 '*' */
|
str--; /* We've eaten the match char after the '*' */
|
||||||
if(do_match(str,p,case_sig,win9x_semantics)) {
|
if(do_match(str,p,case_sig,win9x_semantics)) {
|
||||||
return True;
|
return True;
|
||||||
|
Reference in New Issue
Block a user