summaryrefslogtreecommitdiff
path: root/source3/lib/ms_fnmatch.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-04-17 05:41:07 +0000
committerJeremy Allison <jra@samba.org>2001-04-17 05:41:07 +0000
commit8a1c2e02984edd17e6ab0d5088a80c4dd5f9b933 (patch)
tree3bdf52421af74f40263ee9f141316c0665712fd2 /source3/lib/ms_fnmatch.c
parent4355098a757885462dd44b94b616014c30eea2bf (diff)
downloadsamba-8a1c2e02984edd17e6ab0d5088a80c4dd5f9b933.tar.gz
samba-8a1c2e02984edd17e6ab0d5088a80c4dd5f9b933.tar.bz2
samba-8a1c2e02984edd17e6ab0d5088a80c4dd5f9b933.zip
AIX ACLs donated by IBM.
Merge Andrew's fnmatch fix for WfW. Jeremy. (This used to be commit 1d4438f07745df3d02ed8ab3ef048e20016816b6)
Diffstat (limited to 'source3/lib/ms_fnmatch.c')
-rw-r--r--source3/lib/ms_fnmatch.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c
index 364fd6f347..c4ebaf6aa2 100644
--- a/source3/lib/ms_fnmatch.c
+++ b/source3/lib/ms_fnmatch.c
@@ -31,6 +31,106 @@
#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 thaan what we had */
+static int ms_fnmatch_lanman_core(char *pattern, char *string)
+{
+ char *p = pattern, *n = string;
+ char c;
+
+ if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match;
+
+ while ((c = *p++)) {
+ switch (c) {
+ case '.':
+ /* if (! *n && ! *p) goto match; */
+ if (*n != '.') goto nomatch;
+ n++;
+ break;
+
+ case '?':
+ if ((*n == '.' && n[1] != '.') || ! *n) goto next;
+ n++;
+ break;
+
+ case '>':
+ 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;
+ }
+ if (! *n) goto next;
+ n++;
+ break;
+
+ case '*':
+ if (! *p) goto match;
+ for (; *n; n++) {
+ if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
+ }
+ break;
+
+ case '<':
+ for (; *n; n++) {
+ if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
+ if (*n == '.' && !strchr(n+1,'.')) {
+ n++;
+ break;
+ }
+ }
+ break;
+
+ case '"':
+ if (*n == 0 && ms_fnmatch_lanman_core(p, n) == 0) goto match;
+ if (*n != '.') goto nomatch;
+ n++;
+ break;
+
+ default:
+ if (c != *n) goto nomatch;
+ n++;
+ }
+ }
+
+ 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;
+}
+
+static int ms_fnmatch_lanman1(char *pattern, char *string)
+{
+ if (!strpbrk(pattern, "?*<>\"")) {
+ if (strcmp(string,"..") == 0) string = ".";
+ return strcmp(pattern, string);
+ }
+
+ 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);
+}
+
+
/* the following function was derived using the masktest utility -
after years of effort we finally have a perfect MS wildcard
matching routine!
@@ -43,6 +143,11 @@ int ms_fnmatch(char *pattern, char *string)
{
char *p = pattern, *n = string;
char c;
+ extern int Protocol;
+
+ if (Protocol <= PROTOCOL_LANMAN2) {
+ return ms_fnmatch_lanman1(pattern, string);
+ }
while ((c = *p++)) {
switch (c) {