From 1d67fe4dbee99ec1113abbc5ebb19d4e8c67e414 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Feb 2001 12:04:49 +0000 Subject: better handling of '.' better verbose print (This used to be commit 1f8b8a7189fb8c142801d679cf53c586aee74740) --- source3/utils/masktest.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/masktest.c b/source3/utils/masktest.c index 7e0757e32a..4dd8f3ef06 100644 --- a/source3/utils/masktest.c +++ b/source3/utils/masktest.c @@ -40,12 +40,19 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) char *p = pattern, *n = string; char c; - if (strcmp(p,"?")==0 && strcmp(n,".")==0) return 0; + if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match; while ((c = *p++)) { switch (c) { + case '.': + if (!strchr(p,'.') && !*n && ms_fnmatch_lanman_core(p, n)==0) + goto match; + if (*n != '.') goto nomatch; + n++; + break; + case '?': - if (*n == '.' || ! *n) return ms_fnmatch_lanman_core(p, n); + if ((*n == '.' && n[1] != '.') || ! *n) goto next; n++; break; @@ -55,7 +62,7 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) if (ms_fnmatch_lanman_core(p, n) == 0) goto match; goto nomatch; } - if (! *n) return ms_fnmatch_lanman_core(p, n); + if (! *n) goto next; n++; break; @@ -90,11 +97,14 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) if (! *n) goto match; - nomatch: if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); return -1; +next: + if (ms_fnmatch_lanman_core(p, n) == 0) goto match; + goto nomatch; + match: if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); return 0; @@ -102,19 +112,11 @@ int ms_fnmatch_lanman_core(char *pattern, char *string) int ms_fnmatch_lanman(char *pattern, char *string) { - int ret; - pattern = strdup(pattern); - - /* it appears that '.' at the end of a pattern is stripped if the - pattern contains any wildcard characters. Bizarre */ - if (strpbrk(pattern, "?*<>\"")) { - int len = strlen(pattern); - if (len > 0 && pattern[len-1] == '.') pattern[len-1] = 0; + if (!strpbrk(pattern, "?*<>\"")) { + return strcmp(pattern, string); } - ret = ms_fnmatch_lanman_core(pattern, string); - free(pattern); - return ret; + return ms_fnmatch_lanman_core(pattern, string); } static BOOL reg_match_one(char *pattern, char *file) -- cgit