diff options
Diffstat (limited to 'source/lib/ms_fnmatch.c')
-rw-r--r-- | source/lib/ms_fnmatch.c | 119 |
1 files changed, 45 insertions, 74 deletions
diff --git a/source/lib/ms_fnmatch.c b/source/lib/ms_fnmatch.c index 106efa5bbcf..87e40049e05 100644 --- a/source/lib/ms_fnmatch.c +++ b/source/lib/ms_fnmatch.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 3.0 filename matching routine Copyright (C) Andrew Tridgell 1992-1998 @@ -23,44 +24,37 @@ */ -#if FNMATCH_TEST -#include <stdio.h> -#include <stdlib.h> -#else #include "includes.h" -#endif /* bugger. we need a separate wildcard routine for older versions 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) + better thaan what we had */ +static int ms_fnmatch_lanman_core(const char *pattern, const char *string) { - const smb_ucs2_t *p = pattern, *n = string; - smb_ucs2_t c; + const char *p = pattern, *n = string; + char c; - if (strcmp_wa(p, "?")==0 && strcmp_wa(n, ".")) goto match; + if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match; while ((c = *p++)) { switch (c) { - case UCS2_CHAR('.'): + case '.': if (! *n) goto next; - if (*n != UCS2_CHAR('.')) goto nomatch; + /* if (! *n && ! *p) goto match; */ + if (*n != '.') goto nomatch; n++; break; - case UCS2_CHAR('?'): + case '?': if (! *n) goto next; - if ((*n == UCS2_CHAR('.') && - n[1] != UCS2_CHAR('.')) || ! *n) - goto next; + if ((*n == '.' && n[1] != '.') || ! *n) goto next; n++; break; - case UCS2_CHAR('>'): + case '>': if (! *n) goto next; - if (n[0] == UCS2_CHAR('.')) { + if (n[0] == '.') { if (! n[1] && ms_fnmatch_lanman_core(p, n+1) == 0) goto match; if (ms_fnmatch_lanman_core(p, n) == 0) goto match; goto nomatch; @@ -68,7 +62,7 @@ static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern, n++; break; - case UCS2_CHAR('*'): + case '*': if (! *n) goto next; if (! *p) goto match; for (; *n; n++) { @@ -76,20 +70,19 @@ static int ms_fnmatch_lanman_core(const smb_ucs2_t *pattern, } break; - case UCS2_CHAR('<'): + case '<': for (; *n; n++) { if (ms_fnmatch_lanman_core(p, n) == 0) goto match; - if (*n == UCS2_CHAR('.') && - !strchr_w(n+1,UCS2_CHAR('.'))) { + if (*n == '.' && !strchr(n+1,'.')) { n++; break; } } break; - case UCS2_CHAR('"'): + case '"': if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match; - if (*n != UCS2_CHAR('.')) goto nomatch; + if (*n != '.') goto nomatch; n++; break; @@ -118,19 +111,16 @@ next: return 0; } -static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, const smb_ucs2_t *string) +static int ms_fnmatch_lanman1(const char *pattern, const char *string) { - if (!strpbrk_wa(pattern, "?*<>\"")) { - smb_ucs2_t s[] = {UCS2_CHAR('.'), 0}; - if (strcmp_wa(string,"..") == 0) string = s; - return strcasecmp_w(pattern, string); + if (!strpbrk(pattern, "?*<>\"")) { + if (strcmp(string,"..") == 0) string = "."; + return strcasecmp(pattern, string); } - 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); + if (strcmp(string,"..") == 0 || strcmp(string,".") == 0) { + return ms_fnmatch_lanman_core(pattern, "..") && + ms_fnmatch_lanman_core(pattern, "."); } return ms_fnmatch_lanman_core(pattern, string); @@ -145,51 +135,52 @@ static int ms_fnmatch_lanman1(const smb_ucs2_t *pattern, const smb_ucs2_t *strin Returns 0 on match, -1 on fail. */ -static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int protocol) +int ms_fnmatch(const char *pattern, const char *string) { - const smb_ucs2_t *p = pattern, *n = string; - smb_ucs2_t c; + const char *p = pattern, *n = string; + char c; + extern int Protocol; - if (protocol <= PROTOCOL_LANMAN2) { + if (Protocol <= PROTOCOL_LANMAN2) { return ms_fnmatch_lanman1(pattern, string); } while ((c = *p++)) { switch (c) { - case UCS2_CHAR('?'): + case '?': if (! *n) return -1; n++; break; - 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; + case '>': + if (n[0] == '.') { + if (! n[1] && ms_fnmatch(p, n+1) == 0) return 0; + if (ms_fnmatch(p, n) == 0) return 0; return -1; } - if (! *n) return ms_fnmatch_w(p, n, protocol); + if (! *n) return ms_fnmatch(p, n); n++; break; - case UCS2_CHAR('*'): + case '*': for (; *n; n++) { - if (ms_fnmatch_w(p, n, protocol) == 0) return 0; + if (ms_fnmatch(p, n) == 0) return 0; } break; - case UCS2_CHAR('<'): + case '<': for (; *n; n++) { - if (ms_fnmatch_w(p, n, protocol) == 0) return 0; - if (*n == UCS2_CHAR('.') && !strchr_wa(n+1,'.')) { + if (ms_fnmatch(p, n) == 0) return 0; + if (*n == '.' && !strchr(n+1,'.')) { n++; break; } } break; - case UCS2_CHAR('"'): - if (*n == 0 && ms_fnmatch_w(p, n, protocol) == 0) return 0; - if (*n != UCS2_CHAR('.')) return -1; + case '"': + if (*n == 0 && ms_fnmatch(p, n) == 0) return 0; + if (*n != '.') return -1; n++; break; @@ -203,23 +194,3 @@ static int ms_fnmatch_w(const smb_ucs2_t *pattern, const smb_ucs2_t *string, int return -1; } - - -int ms_fnmatch(const char *pattern, const char *string, int protocol) -{ - wpstring p, s; - int ret; - - pstrcpy_wa(p, pattern); - pstrcpy_wa(s, string); - - ret = ms_fnmatch_w(p, s, protocol); -/* DEBUG(0,("ms_fnmatch(%s,%s) -> %d\n", pattern, string, ret)); */ - 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); -} |