r2824: restored the is_case_sensitive option to ms_fnmatch() in Samba3. It is
authorAndrew Tridgell <tridge@samba.org>
Tue, 5 Oct 2004 03:26:02 +0000 (03:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:54 +0000 (10:52 -0500)
very rarely used, but we sohuldn't be removing a feature in a minor
release of this kind.
(This used to be commit 4ce0505bc369243aa77013519ce4e4f6e50f5a48)

source3/lib/ms_fnmatch.c
source3/lib/util.c
source3/torture/masktest.c

index bdfb26d0ca575192fe1ef3df52915a0ad0286fa8..3040dc7f9d350f5dbfaccf787bcb8b4e5507448b 100644 (file)
@@ -55,7 +55,8 @@ struct max_n {
   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;
@@ -68,7 +69,7 @@ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
                                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;
                                }
                        }
@@ -86,9 +87,9 @@ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
                                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;
                                }
@@ -125,8 +126,13 @@ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
                        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;
@@ -140,7 +146,8 @@ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
        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;
@@ -153,7 +160,11 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot
        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);
@@ -190,7 +201,7 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot
                }
        }
 
-       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);
@@ -203,5 +214,5 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot
 /* 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);
 }
index 53ce8ab17bedc2bfb707f551235607cf3b88845e..5e88bd896ffef1031132afb1d43ee3df6dd64d27 100644 (file)
@@ -2325,7 +2325,7 @@ BOOL mask_match(const char *string, char *pattern, BOOL is_case_sensitive)
        if (strcmp(pattern,".") == 0)
                return False;
        
-       return ms_fnmatch(pattern, string, Protocol) == 0;
+       return ms_fnmatch(pattern, string, Protocol, is_case_sensitive) == 0;
 }
 
 /*******************************************************************
index fa901e3d63d4067ea54f410cbf89f9f0dd8c9a8f..67515463d15e7e07c942743491a971b8fb9e877a 100644 (file)
@@ -140,7 +140,7 @@ static BOOL reg_match_one(struct cli_state *cli, const char *pattern, const char
 
        if (strcmp(file,"..") == 0) file = ".";
 
-       return ms_fnmatch(pattern, file, cli->protocol)==0;
+       return ms_fnmatch(pattern, file, cli->protocol, False) == 0;
 }
 
 static char *reg_test(struct cli_state *cli, char *pattern, char *long_name, char *short_name)