lib: Add "is_case_sensitive" to ms_fnmatch_protocol
authorVolker Lendecke <vl@samba.org>
Tue, 25 Oct 2016 09:53:53 +0000 (11:53 +0200)
committerRalph Boehme <slow@samba.org>
Sun, 22 Jan 2017 17:30:12 +0000 (18:30 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/util/ms_fnmatch.c
lib/util/samba_util.h
source4/client/client.c
source4/ntvfs/cifs_posix_cli/svfs_util.c
source4/ntvfs/posix/pvfs_dirlist.c
source4/ntvfs/simple/svfs_util.c
source4/torture/masktest.c

index ede9eff78f821ead827abc4bf471c863b9fad1ba..7f1cce06bb1eb7a93fd79dda28d8629fa280a286 100644 (file)
@@ -59,7 +59,8 @@ struct max_n {
   not contain a '.', otherwise it points at the last dot in 'n'.
 */
 static int ms_fnmatch_core(const char *p, const char *n, 
-                          struct max_n *max_n, const char *ldot)
+                          struct max_n *max_n, const char *ldot,
+                          bool is_case_sensitive)
 {
        codepoint_t c, c2;
        int i;
@@ -76,7 +77,7 @@ static int ms_fnmatch_core(const char *p, const char *n,
                        }
                        for (i=0; n[i]; i += size_n) {
                                next_codepoint(n+i, &size_n);
-                               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;
                                }
                        }
@@ -95,9 +96,9 @@ static int ms_fnmatch_core(const char *p, const char *n,
                        }
                        for (i=0; n[i]; i += size_n) {
                                next_codepoint(n+i, &size_n);
-                               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+size_n, max_n+1, ldot) == 0) return 0;
+                                       if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot, is_case_sensitive) == 0) return 0;
                                        if (!max_n->postdot || max_n->postdot > n) max_n->postdot = n;
                                        return -1;
                                }
@@ -140,8 +141,13 @@ static int ms_fnmatch_core(const char *p, const char *n,
 
                default:
                        c2 = next_codepoint(n, &size_n);
-                       if (c != c2 && codepoint_cmpi(c, c2) != 0) {
-                               return -1;
+                       if (c != c2) {
+                               if (is_case_sensitive) {
+                                       return -1;
+                               }
+                               if (codepoint_cmpi(c, c2) != 0) {
+                                       return -1;
+                               }
                        }
                        n += size_n;
                        break;
@@ -155,7 +161,8 @@ static int ms_fnmatch_core(const char *p, const char *n,
        return -1;
 }
 
-int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol)
+int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
+                       bool is_case_sensitive)
 {
        int ret, count, i;
        struct max_n *max_n = NULL;
@@ -193,7 +200,8 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol)
                                p[i] = '<';
                        }
                }
-               ret = ms_fnmatch_protocol(p, string, PROTOCOL_NT1);
+               ret = ms_fnmatch_protocol(p, string, PROTOCOL_NT1,
+                                         is_case_sensitive);
                talloc_free(p);
                return ret;
        }
@@ -207,7 +215,8 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol)
                return -1;
        }
 
-       ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.'));
+       ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.'),
+                             is_case_sensitive);
 
        talloc_free(max_n);
 
@@ -218,5 +227,5 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol)
 /** a generic fnmatch function - uses for non-CIFS pattern matching */
 int gen_fnmatch(const char *pattern, const char *string)
 {
-       return ms_fnmatch_protocol(pattern, string, PROTOCOL_NT1);
+       return ms_fnmatch_protocol(pattern, string, PROTOCOL_NT1, false);
 }
index 5dcaf947b38e773bb7de0a7111997cdca3d6714b..aad44dc4c268c9add8351b083f9f08f693857df3 100644 (file)
@@ -526,7 +526,8 @@ _PUBLIC_ int sys_fsusage(const char *path, uint64_t *dfree, uint64_t *dsize);
  * @brief MS-style Filename matching
  */
 
-int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol);
+int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
+                       bool is_case_sensitive);
 
 /** a generic fnmatch function - uses for non-CIFS pattern matching */
 int gen_fnmatch(const char *pattern, const char *string);
index 9866444b006be6ff137a70b668191afa0a2e1643..10d027b5e0bfe8c40f3ec28fedf80de1544266b8 100644 (file)
@@ -311,12 +311,14 @@ static bool mask_match(struct smbcli_state *c, const char *string,
                return false;
        
        if (is_case_sensitive)
-               return ms_fnmatch_protocol(pattern, string, 
-                                 c->transport->negotiate.protocol) == 0;
+               return ms_fnmatch_protocol(
+                       pattern, string, c->transport->negotiate.protocol,
+                       true) == 0;
 
        p2 = strlower_talloc(NULL, pattern);
        s2 = strlower_talloc(NULL, string);
-       ret = ms_fnmatch_protocol(p2, s2, c->transport->negotiate.protocol) == 0;
+       ret = ms_fnmatch_protocol(p2, s2, c->transport->negotiate.protocol,
+                                 true) == 0;
        talloc_free(p2);
        talloc_free(s2);
 
index cf881a1c9ae215a5a2c95e954f8fa152de08dc0c..ec2e933080602ad900a4a63523fe87267ded7fc2 100644 (file)
@@ -105,7 +105,8 @@ struct cifspsx_dir *cifspsx_list_unix(TALLOC_CTX *mem_ctx, struct ntvfs_request
                if (!low_name) { continue; }
 
                /* check it matches the wildcard pattern */
-               if (ms_fnmatch_protocol(low_mask, low_name, PROTOCOL_NT1) != 0) {
+               if (ms_fnmatch_protocol(low_mask, low_name, PROTOCOL_NT1,
+                                       true) != 0) {
                        continue;
                }
                
index 1bc91c1c788fa5f7e6081c9d3eb4e287780b41f2..d86fce4e85252b02b8323b7463a65e40f5b810cb 100644 (file)
@@ -199,7 +199,8 @@ const char *pvfs_list_next(struct pvfs_dir *dir, off_t *ofs)
        if (*ofs == DIR_OFFSET_DOT) {
                (*ofs) = DIR_OFFSET_DOTDOT;
                dir->offset = *ofs;
-               if (ms_fnmatch_protocol(dir->pattern, ".", protocol) == 0) {
+               if (ms_fnmatch_protocol(dir->pattern, ".", protocol,
+                                       true) == 0) {
                        dcache_add(dir, ".");
                        return ".";
                }
@@ -208,7 +209,8 @@ const char *pvfs_list_next(struct pvfs_dir *dir, off_t *ofs)
        if (*ofs == DIR_OFFSET_DOTDOT) {
                (*ofs) = DIR_OFFSET_BASE;
                dir->offset = *ofs;
-               if (ms_fnmatch_protocol(dir->pattern, "..", protocol) == 0) {
+               if (ms_fnmatch_protocol(dir->pattern, "..", protocol,
+                                       true) == 0) {
                        dcache_add(dir, "..");
                        return "..";
                }
@@ -228,10 +230,12 @@ const char *pvfs_list_next(struct pvfs_dir *dir, off_t *ofs)
                        continue;
                }
 
-               if (ms_fnmatch_protocol(dir->pattern, dname, protocol) != 0) {
+               if (ms_fnmatch_protocol(dir->pattern, dname, protocol,
+                                       true) != 0) {
                        char *short_name = pvfs_short_name_component(dir->pvfs, dname);
                        if (short_name == NULL ||
-                           ms_fnmatch_protocol(dir->pattern, short_name, protocol) != 0) {
+                           ms_fnmatch_protocol(dir->pattern, short_name,
+                                               protocol, true) != 0) {
                                talloc_free(short_name);
                                continue;
                        }
index 171813bea21a9ce7e3dfe533b2a3323b75c783c7..21f20c58ac8a1d930e267e5aec424c30303a7257 100644 (file)
@@ -101,7 +101,8 @@ struct svfs_dir *svfs_list_unix(TALLOC_CTX *mem_ctx, struct ntvfs_request *req,
                if (!low_name) { continue; }
 
                /* check it matches the wildcard pattern */
-               if (ms_fnmatch_protocol(low_mask, low_name, PROTOCOL_NT1) != 0) {
+               if (ms_fnmatch_protocol(low_mask, low_name, PROTOCOL_NT1,
+                                       true) != 0) {
                        continue;
                }
                
index b96c6dabbe5bc66ae47d03b584562f2baeb4544e..e6e7f4e4245d50759567d1d94ced0e008c460c4c 100644 (file)
@@ -49,7 +49,8 @@ static bool reg_match_one(struct smbcli_state *cli, const char *pattern, const c
 
        if (ISDOTDOT(file)) file = ".";
 
-       return ms_fnmatch_protocol(pattern, file, cli->transport->negotiate.protocol)==0;
+       return ms_fnmatch_protocol(
+               pattern, file, cli->transport->negotiate.protocol, true)==0;
 }
 
 static char *reg_test(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char *pattern, const char *long_name, const char *short_name)