2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2021
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "lib/util_matching.h"
24 bool run_str_match_mswild(int dummy
)
26 const char *namelist
= "/abc*.txt/xyz*.dat/a0123456789Z/";
27 struct name_compare_entry
*name_entries
= NULL
;
28 struct samba_path_matching
*pmcs
= NULL
;
29 struct samba_path_matching
*pmci
= NULL
;
30 const struct str_match_mswild_name
{
32 ssize_t case_sensitive_idx
;
33 ssize_t case_insensitive_idx
;
35 .name
= "/dir/abc123.txt",
36 .case_sensitive_idx
= 0,
37 .case_insensitive_idx
= 0,
39 .name
= "/dir/AbC123.TxT",
40 .case_sensitive_idx
= -1,
41 .case_insensitive_idx
= 0,
43 .name
= "/dir/xyz123.dat",
44 .case_sensitive_idx
= 1,
45 .case_insensitive_idx
= 1,
47 .name
= "/dir/XyZ123.DaT",
48 .case_sensitive_idx
= -1,
49 .case_insensitive_idx
= 1,
51 .name
= "/dir/aaa123.jpg",
52 .case_sensitive_idx
= -1,
53 .case_insensitive_idx
= -1,
55 .name
= "/dir/a0123456789Z",
56 .case_sensitive_idx
= 2,
57 .case_insensitive_idx
= 2,
59 .name
= "/dir/A0123456789z",
60 .case_sensitive_idx
= -1,
61 .case_insensitive_idx
= 2,
67 d_fprintf(stderr
, "namelist: %s\n", namelist
);
69 ret
= set_namearray(talloc_tos(), namelist
, &name_entries
);
70 SMB_ASSERT(ret
&& name_entries
!= NULL
);
72 status
= samba_path_matching_mswild_create(talloc_tos(),
73 true, /* case_sensitive */
76 SMB_ASSERT(NT_STATUS_IS_OK(status
));
77 status
= samba_path_matching_mswild_create(talloc_tos(),
78 false, /* case_sensitive */
81 SMB_ASSERT(NT_STATUS_IS_OK(status
));
84 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
85 const struct str_match_mswild_name
*n
= &names
[i
];
86 bool case_sensitive_match
;
87 bool case_insensitive_match
;
88 ssize_t cs_match_idx
= -1;
89 ssize_t ci_match_idx
= -1;
90 ssize_t replace_start
= -1;
91 ssize_t replace_end
= -1;
94 case_sensitive_match
= is_in_path(n
->name
,
97 if (n
->case_sensitive_idx
!= -1) {
98 ok
&= case_sensitive_match
;
100 ok
&= !case_sensitive_match
;
102 status
= samba_path_matching_check_last_component(pmcs
,
107 SMB_ASSERT(NT_STATUS_IS_OK(status
));
108 SMB_ASSERT(replace_start
== -1);
109 SMB_ASSERT(replace_end
== -1);
110 if (n
->case_sensitive_idx
!= cs_match_idx
) {
113 case_insensitive_match
= is_in_path(n
->name
,
116 if (n
->case_insensitive_idx
!= -1) {
117 ok
&= case_insensitive_match
;
119 ok
&= !case_insensitive_match
;
121 status
= samba_path_matching_check_last_component(pmci
,
126 SMB_ASSERT(NT_STATUS_IS_OK(status
));
127 SMB_ASSERT(replace_start
== -1);
128 SMB_ASSERT(replace_end
== -1);
129 if (n
->case_insensitive_idx
!= ci_match_idx
) {
133 d_fprintf(stderr
, "name[%s] "
134 "case_sensitive[TIDX=%zd;MATCH=%u;MIDX=%zd] "
135 "case_insensitive[TIDX=%zd;MATCH=%u;MIDX=%zd] "
138 n
->case_sensitive_idx
,
139 case_sensitive_match
,
141 n
->case_insensitive_idx
,
142 case_insensitive_match
,
152 bool run_str_match_regex_sub1(int dummy
)
154 const char *invalidlist1
= "/Re7599Ex[0-9].*\\.txt/";
155 const char *invalidlist2
= "/Re7599Ex\\([0-9]\\).*\\.\\(txt\\)/";
156 const char *invalidlist3
= "/Re7599Ex\\([0-9]).*\\.txt/";
157 const char *invalidlist4
= "/Re7599Ex[0-9.*\\.txt/";
158 const char *namelist
= "/Re7599Ex\\([0-9]\\).*\\.txt/test\\(.*\\).txt/^test\\([0-9]*\\).dat/";
159 struct samba_path_matching
*pm
= NULL
;
160 const struct str_match_regex_sub1
{
166 .name
= "/dir/Re7599Ex567.txt",
171 .name
= "/dir/rE7599eX567.txt",
176 .name
= "/dir/Re7599Ex.txt",
181 .name
= "/dir/testabc123.txt",
186 .name
= "/dir/testabc123.tXt",
191 .name
= "/dir/test123.dat",
196 .name
= "/dir/tEst123.dat",
205 d_fprintf(stderr
, "invalidlist1: %s\n", invalidlist1
);
206 status
= samba_path_matching_regex_sub1_create(talloc_tos(),
209 SMB_ASSERT(NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
));
210 d_fprintf(stderr
, "invalidlist2: %s\n", invalidlist2
);
211 status
= samba_path_matching_regex_sub1_create(talloc_tos(),
214 SMB_ASSERT(NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
));
215 d_fprintf(stderr
, "invalidlist3: %s\n", invalidlist3
);
216 status
= samba_path_matching_regex_sub1_create(talloc_tos(),
219 SMB_ASSERT(NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
));
220 d_fprintf(stderr
, "invalidlist4: %s\n", invalidlist4
);
221 status
= samba_path_matching_regex_sub1_create(talloc_tos(),
224 SMB_ASSERT(NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
));
226 d_fprintf(stderr
, "namelist: %s\n", namelist
);
227 status
= samba_path_matching_regex_sub1_create(talloc_tos(),
230 SMB_ASSERT(NT_STATUS_IS_OK(status
));
232 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
233 const struct str_match_regex_sub1
*n
= &names
[i
];
234 ssize_t match_idx
= -1;
235 ssize_t replace_start
= -1;
236 ssize_t replace_end
= -1;
239 status
= samba_path_matching_check_last_component(pm
,
244 SMB_ASSERT(NT_STATUS_IS_OK(status
));
245 if (match_idx
== -1) {
246 SMB_ASSERT(replace_start
== -1);
247 SMB_ASSERT(replace_end
== -1);
249 if (n
->match_idx
!= match_idx
) {
252 if (n
->sub_start
!= replace_start
) {
255 if (n
->sub_end
!= replace_end
) {
259 d_fprintf(stderr
, "name[%s] "
260 "T[IDX=%zd;START=%zd;END=%zd] "
261 "M[[IDX=%zd;START=%zd;END=%zd] "