2 Unix SMB/Netbios implementation.
4 filename matching routine
5 Copyright (C) Andrew Tridgell 1992-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 This module was originally based on fnmatch.c copyright by the Free
23 Software Foundation. It bears little resemblence to that code now
30 bugger. we need a separate wildcard routine for older versions
31 of the protocol. This is not yet perfect, but its a lot
32 better thaan what we had */
33 static int ms_fnmatch_lanman_core(const char *pattern
, const char *string
)
35 const char *p
= pattern
, *n
= string
;
38 if (strcmp(p
,"?")==0 && strcmp(n
,".")==0) goto match
;
44 /* if (! *n && ! *p) goto match; */
45 if (*n
!= '.') goto nomatch
;
51 if ((*n
== '.' && n
[1] != '.') || ! *n
) goto next
;
58 if (! n
[1] && ms_fnmatch_lanman_core(p
, n
+1) == 0) goto match
;
59 if (ms_fnmatch_lanman_core(p
, n
) == 0) goto match
;
69 if (ms_fnmatch_lanman_core(p
, n
) == 0) goto match
;
75 if (ms_fnmatch_lanman_core(p
, n
) == 0) goto match
;
76 if (*n
== '.' && !strchr(n
+1,'.')) {
84 if (*n
== 0 && ms_fnmatch_lanman_core(p
, n
) == 0) goto match
;
85 if (*n
!= '.') goto nomatch
;
90 if (c
!= *n
) goto nomatch
;
99 if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string);
104 if (ms_fnmatch_lanman_core(p
, n
) == 0) goto match
;
109 if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string);
114 static int ms_fnmatch_lanman1(const char *pattern
, const char *string
)
116 if (!strpbrk(pattern
, "?*<>\"")) {
117 if (strcmp(string
,"..") == 0) string
= ".";
118 return strcasecmp(pattern
, string
);
121 if (strcmp(string
,"..") == 0 || strcmp(string
,".") == 0) {
122 return ms_fnmatch_lanman_core(pattern
, "..") &&
123 ms_fnmatch_lanman_core(pattern
, ".");
126 return ms_fnmatch_lanman_core(pattern
, string
);
130 /* the following function was derived using the masktest utility -
131 after years of effort we finally have a perfect MS wildcard
134 NOTE: this matches only filenames with no directory component
136 Returns 0 on match, -1 on fail.
138 int ms_fnmatch(const char *pattern
, const char *string
)
140 const char *p
= pattern
, *n
= string
;
144 if (Protocol
<= PROTOCOL_LANMAN2
) {
145 return ms_fnmatch_lanman1(pattern
, string
);
157 if (! n
[1] && ms_fnmatch(p
, n
+1) == 0) return 0;
158 if (ms_fnmatch(p
, n
) == 0) return 0;
161 if (! *n
) return ms_fnmatch(p
, n
);
167 if (ms_fnmatch(p
, n
) == 0) return 0;
173 if (ms_fnmatch(p
, n
) == 0) return 0;
174 if (*n
== '.' && !strchr(n
+1,'.')) {
182 if (*n
== 0 && ms_fnmatch(p
, n
) == 0) return 0;
183 if (*n
!= '.') return -1;
188 if (c
!= *n
) return -1;