The Samba-Bugzilla – Attachment 54 Details for
Bug 205
wildcard matching with different length of upper/lower case
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Don't strlower for fnmatch
fnmatch.patch (text/plain), 10.47 KB, created by
Andrew Bartlett
on 2003-07-22 06:24:54 UTC
(
hide
)
Description:
Don't strlower for fnmatch
Filename:
MIME Type:
Creator:
Andrew Bartlett
Created:
2003-07-22 06:24:54 UTC
Size:
10.47 KB
patch
obsolete
>? config.abartlet >? passdb.xml >? auth/auth_util.idmap-conflict.c >? bin/stNDYv74 >? include/smb_ldap.h >? modules/developer.c >? modules/vfs_fake_perms-old.c >? passdb/pdb_ldap.c2 >Index: Makefile.in >=================================================================== >RCS file: /home/cvs/samba/source/Makefile.in,v >retrieving revision 1.468.2.146 >diff -u -r1.468.2.146 Makefile.in >--- Makefile.in 22 Jul 2003 00:20:53 -0000 1.468.2.146 >+++ Makefile.in 22 Jul 2003 13:21:57 -0000 >@@ -460,7 +460,7 @@ > > LIBBIGBALLOFMUD_OBJ = $(PARAM_OBJ) $(LIB_OBJ) $(UBIQX_OBJ) $(SECRETS_OBJ) \ > $(LIBSMB_OBJ) $(LIBMSRPC_OBJ) $(RPC_PARSE_OBJ) $(PASSDB_OBJ) \ >- $(GROUPDB_OBJ) $(KRBCLIENT_OBJ) $(SMBLDAP_OBJ) >+ $(GROUPDB_OBJ) $(KRBCLIENT_OBJ) $(SMBLDAP_OBJ) lib/dummyroot.o > > LIBBIGBALLOFMUD_PICOBJS = $(LIBBIGBALLOFMUD_OBJ:.o=.po) > >Index: lib/charcnv.c >=================================================================== >RCS file: /home/cvs/samba/source/lib/charcnv.c,v >retrieving revision 1.55.2.28 >diff -u -r1.55.2.28 charcnv.c >--- lib/charcnv.c 3 Jul 2003 19:11:28 -0000 1.55.2.28 >+++ lib/charcnv.c 22 Jul 2003 13:21:58 -0000 >@@ -319,8 +319,7 @@ > size_t size; > smb_ucs2_t *buffer; > >- size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, >- (void **) &buffer); >+ size = push_ucs2_allocate(&buffer, src); > if (size == -1) { > smb_panic("failed to create UCS2 buffer"); > } >@@ -480,18 +479,11 @@ > { > size_t len=0; > size_t src_len = strlen(src); >- pstring tmpbuf; > > /* treat a pstring as "unlimited" length */ > if (dest_len == (size_t)-1) > dest_len = sizeof(pstring); > >- if (flags & STR_UPPER) { >- pstrcpy(tmpbuf, src); >- strupper_m(tmpbuf); >- src = tmpbuf; >- } >- > if (flags & STR_TERMINATE) > src_len++; > >@@ -506,6 +498,18 @@ > dest_len &= ~1; > > len += convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len); >+ >+ if (flags & STR_UPPER) { >+ smb_ucs2_t *dest_ucs2 = dest; >+ size_t i; >+ for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) { >+ smb_ucs2_t v = toupper_w(dest_ucs2[i]); >+ if (v != dest_ucs2[i]) { >+ dest_ucs2[i] = v; >+ } >+ } >+ } >+ > return len; > } > >Index: lib/ms_fnmatch.c >=================================================================== >RCS file: /home/cvs/samba/source/lib/ms_fnmatch.c,v >retrieving revision 1.9 >diff -u -r1.9 ms_fnmatch.c >--- lib/ms_fnmatch.c 30 Jan 2002 06:08:16 -0000 1.9 >+++ lib/ms_fnmatch.c 22 Jul 2003 13:21:58 -0000 >@@ -35,7 +35,8 @@ > of the protocol. This is not yet perfect, but its a lot > better than what we had */ > static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern, >- const smb_ucs2_t *string) >+ const smb_ucs2_t *string, >+ BOOL case_sensitive) > { > const smb_ucs2_t *p = pattern, *n = string; > smb_ucs2_t c; >@@ -61,8 +62,8 @@ > case UCS2_CHAR('>'): > if (! *n) goto next; > if (n[0] == UCS2_CHAR('.')) { >- if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match; >- if (ms_fnmatch_lanman_core(p, n) == 0) goto match; >+ if (! n[1] && ms_fnmatch_lanman_core(p, n+1, case_sensitive) == 0) goto match; >+ if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match; > goto nomatch; > } > n++; >@@ -72,13 +73,13 @@ > if (! *n) goto next; > if (! *p) goto match; > for (; *n; n++) { >- if (ms_fnmatch_lanman_core(p, n) == 0) goto match; >+ if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match; > } > break; > > case UCS2_CHAR('<'): > for (; *n; n++) { >- if (ms_fnmatch_lanman_core(p, n) == 0) goto match; >+ if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match; > if (*n == UCS2_CHAR('.') && > !strchr_w(n+1,UCS2_CHAR('.'))) { > n++; >@@ -88,13 +89,17 @@ > break; > > case UCS2_CHAR('"'): >- if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match; >+ if (*n == 0 && ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match; > if (*n != UCS2_CHAR('.')) goto nomatch; > n++; > break; > > default: >- if (c != *n) goto nomatch; >+ if (case_sensitive) { >+ if (c != *n) goto nomatch; >+ } else { >+ if (tolower_w(c) != tolower_w(*n)) goto nomatch; >+ } > n++; > } > } >@@ -108,7 +113,7 @@ > return -1; > > next: >- if (ms_fnmatch_lanman_core(p, n) == 0) goto match; >+ if (ms_fnmatch_lanman_core(p, n, case_sensitive) == 0) goto match; > goto nomatch; > > match: >@@ -118,7 +123,8 @@ > return 0; > } > >-static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, const smb_ucs2_t *string) >+static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, >+ const smb_ucs2_t *string, BOOL case_sensitive) > { > if (!strpbrk_wa(pattern, "?*<>\"")) { > smb_ucs2_t s[] = {UCS2_CHAR('.'), 0}; >@@ -129,11 +135,11 @@ > if (strcmp_wa(string,"..") == 0 || strcmp_wa(string,".") == 0) { > smb_ucs2_t dot[] = {UCS2_CHAR('.'), 0}; > smb_ucs2_t dotdot[] = {UCS2_CHAR('.'), UCS2_CHAR('.'), 0}; >- return ms_fnmatch_lanman_core(pattern, dotdot) && >- ms_fnmatch_lanman_core(pattern, dot); >+ return ms_fnmatch_lanman_core(pattern, dotdot, case_sensitive) && >+ ms_fnmatch_lanman_core(pattern, dot, case_sensitive); > } > >- return ms_fnmatch_lanman_core(pattern, string); >+ return ms_fnmatch_lanman_core(pattern, string, case_sensitive); > } > > >@@ -145,13 +151,14 @@ > > Returns 0 on match, -1 on fail. > */ >-static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int protocol) >+static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, >+ int protocol, BOOL case_sensitive) > { > const smb_ucs2_t *p = pattern, *n = string; > smb_ucs2_t c; > > if (protocol <= PROTOCOL_LANMAN2) { >- return ms_fnmatch_lanman1(pattern, string); >+ return ms_fnmatch_lanman1(pattern, string, case_sensitive); > } > > while ((c = *p++)) { >@@ -163,23 +170,23 @@ > > case UCS2_CHAR('>'): > if (n[0] == UCS2_CHAR('.')) { >- if (! n[1] && ms_fnmatch_w(p, n+1, protocol) == 0) return 0; >- if (ms_fnmatch_w(p, n, protocol) == 0) return 0; >+ if (! n[1] && ms_fnmatch_w(p, n+1, protocol, case_sensitive) == 0) return 0; >+ if (ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0; > return -1; > } >- if (! *n) return ms_fnmatch_w(p, n, protocol); >+ if (! *n) return ms_fnmatch_w(p, n, protocol, case_sensitive); > n++; > break; > > case UCS2_CHAR('*'): > for (; *n; n++) { >- if (ms_fnmatch_w(p, n, protocol) == 0) return 0; >+ if (ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0; > } > break; > > case UCS2_CHAR('<'): > for (; *n; n++) { >- if (ms_fnmatch_w(p, n, protocol) == 0) return 0; >+ if (ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0; > if (*n == UCS2_CHAR('.') && !strchr_wa(n+1,'.')) { > n++; > break; >@@ -188,13 +195,17 @@ > break; > > case UCS2_CHAR('"'): >- if (*n == 0 && ms_fnmatch_w(p, n, protocol) == 0) return 0; >+ if (*n == 0 && ms_fnmatch_w(p, n, protocol, case_sensitive) == 0) return 0; > if (*n != UCS2_CHAR('.')) return -1; > n++; > break; > > default: >- if (c != *n) return -1; >+ if (case_sensitive) { >+ if (c != *n) return -1; >+ } else { >+ if (tolower_w(c) != tolower_w(*n)) return -1; >+ } > n++; > } > } >@@ -205,21 +216,40 @@ > } > > >-int ms_fnmatch(const char *pattern, const char *string, int protocol) >+int ms_fnmatch(const char *pattern, const char *string, int protocol, >+ BOOL case_senstive) > { >- wpstring p, s; >+ smb_ucs2_t *buffer_pattern, *buffer_string; > int ret; >+ size_t size; > >- pstrcpy_wa(p, pattern); >- pstrcpy_wa(s, string); >+ size = convert_string_allocate(CH_UNIX, CH_UCS2, pattern, strlen(pattern)+1, >+ (void **) &buffer_pattern); >+ if (size == (size_t)-1) { >+ return -1; >+ /* Not quite the right answer, but finding the right one >+ under this failure case is expensive, and it's pretty close */ >+ } >+ >+ size = convert_string_allocate(CH_UNIX, CH_UCS2, string, strlen(string)+1, >+ (void **) &buffer_string); >+ if (size == (size_t)-1) { >+ SAFE_FREE(buffer_pattern); >+ return -1; >+ /* Not quite the right answer, but finding the right one >+ under this failure case is expensive, and it's pretty close */ >+ } > >- ret = ms_fnmatch_w(p, s, protocol); >+ ret = ms_fnmatch_w(buffer_pattern, buffer_string, protocol, case_senstive); > /* DEBUG(0,("ms_fnmatch(%s,%s) -> %d\n", pattern, string, ret)); */ >+ >+ SAFE_FREE(buffer_pattern); >+ SAFE_FREE(buffer_string); > return ret; > } > > /* 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, True); > } >Index: lib/util.c >=================================================================== >RCS file: /home/cvs/samba/source/lib/util.c,v >retrieving revision 1.358.2.31 >diff -u -r1.358.2.31 util.c >--- lib/util.c 14 Jul 2003 08:46:31 -0000 1.358.2.31 >+++ lib/util.c 22 Jul 2003 13:22:00 -0000 >@@ -2335,21 +2335,12 @@ > > BOOL mask_match(const char *string, char *pattern, BOOL is_case_sensitive) > { >- fstring p2, s2; >- > if (strcmp(string,"..") == 0) > string = "."; > if (strcmp(pattern,".") == 0) > return False; > >- if (is_case_sensitive) >- return ms_fnmatch(pattern, string, Protocol) == 0; >- >- fstrcpy(p2, pattern); >- fstrcpy(s2, string); >- strlower_m(p2); >- strlower_m(s2); >- return ms_fnmatch(p2, s2, Protocol) == 0; >+ return ms_fnmatch(pattern, string, Protocol, is_case_sensitive) == 0; > } > > /********************************************************* >Index: lib/util_str.c >=================================================================== >RCS file: /home/cvs/samba/source/lib/util_str.c,v >retrieving revision 1.47.2.29 >diff -u -r1.47.2.29 util_str.c >--- lib/util_str.c 19 Jul 2003 00:36:43 -0000 1.47.2.29 >+++ lib/util_str.c 22 Jul 2003 13:22:01 -0000 >@@ -208,17 +208,15 @@ > return +1; > } > >- size = convert_string_allocate(CH_UNIX, CH_UCS2, s, strlen(s), >- (void **) &buffer_s); >- if (size == -1) { >+ size = push_ucs2_allocate(&buffer_s, s); >+ if (size == (size_t)-1) { > return strcmp(s, t); > /* Not quite the right answer, but finding the right one > under this failure case is expensive, and it's pretty close */ > } > >- size = convert_string_allocate(CH_UNIX, CH_UCS2, t, strlen(t), >- (void **) &buffer_t); >- if (size == -1) { >+ size = push_ucs2_allocate(&buffer_t, t); >+ if (size == (size_t)-1) { > SAFE_FREE(buffer_s); > return strcmp(s, t); > /* Not quite the right answer, but finding the right one >@@ -364,7 +362,7 @@ > NOTE: oldc and newc must be 7 bit characters > **/ > >-void string_replace(char *s,char oldc,char newc) >+void string_replace(pstring s,char oldc,char newc) > { > push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE); > string_replace_w(tmpbuf, UCS2_CHAR(oldc), UCS2_CHAR(newc));
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 205
: 54