not contain a '.', otherwise it points at the last dot in 'n'.
*/
static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
- struct max_n *max_n, const smb_ucs2_t *ldot)
+ struct max_n *max_n, const smb_ucs2_t *ldot,
+ BOOL is_case_sensitive)
{
smb_ucs2_t c;
int i;
return null_match(p);
}
for (i=0; n[i]; i++) {
- if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) {
+ if (ms_fnmatch_core(p, n+i, max_n+1, ldot, is_case_sensitive) == 0) {
return 0;
}
}
return -1;
}
for (i=0; n[i]; i++) {
- if (ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0;
+ if (ms_fnmatch_core(p, n+i, max_n+1, ldot, is_case_sensitive) == 0) return 0;
if (n+i == ldot) {
- if (ms_fnmatch_core(p, n+i+1, max_n+1, ldot) == 0) return 0;
+ if (ms_fnmatch_core(p, n+i+1, max_n+1, ldot, is_case_sensitive) == 0) return 0;
if (!max_n->postdot || max_n->postdot > n) max_n->postdot = n;
return -1;
}
break;
default:
- if (c != *n && toupper_w(c) != toupper_w(*n)) {
- return -1;
+ if (c != *n) {
+ if (is_case_sensitive) {
+ return -1;
+ }
+ if (toupper_w(c) != toupper_w(*n)) {
+ return -1;
+ }
}
n++;
break;
return -1;
}
-int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol)
+int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol,
+ BOOL is_case_sensitive)
{
wpstring p, s;
int ret, count, i;
if (strpbrk(pattern, "<>*?\"") == NULL) {
/* this is not just an optmisation - it is essential
for LANMAN1 correctness */
- return StrCaseCmp(pattern, string);
+ if (is_case_sensitive) {
+ return strcmp(pattern, string);
+ } else {
+ return StrCaseCmp(pattern, string);
+ }
}
pstrcpy_wa(p, pattern);
}
}
- ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')));
+ ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive);
if (max_n) {
free(max_n);
/* a generic fnmatch function - uses for non-CIFS pattern matching */
int gen_fnmatch(const char *pattern, const char *string)
{
- return ms_fnmatch(pattern, string, PROTOCOL_NT1);
+ return ms_fnmatch(pattern, string, PROTOCOL_NT1, False);
}