diff options
author | Darren Tucker <dtucker@dtucker.net> | 2019-03-12 09:19:19 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@dtucker.net> | 2019-03-12 09:19:19 +1100 |
commit | daa7505aadca68ba1a2c70cbdfce423208eb91ee (patch) | |
tree | 5a928d2516bac7be6f0fde98dfdb7eb7b266dec9 | |
parent | fd10cf027b56f9aaa80c9e3844626a05066589a4 (diff) |
Use Cygwin-specific matching only for users+groups.
Patch from vinschen at redhat.com, updated a little by me.
-rw-r--r-- | match.c | 12 | ||||
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.c | 18 | ||||
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.h | 1 |
3 files changed, 13 insertions, 18 deletions
@@ -111,8 +111,6 @@ match_pattern(const char *s, const char *pattern) | |||
111 | /* NOTREACHED */ | 111 | /* NOTREACHED */ |
112 | } | 112 | } |
113 | 113 | ||
114 | #ifndef HAVE_CYGWIN /* Cygwin version in openbsd-compat/bsd-cygwin_util.c */ | ||
115 | |||
116 | /* | 114 | /* |
117 | * Tries to match the string against the | 115 | * Tries to match the string against the |
118 | * comma-separated sequence of subpatterns (each possibly preceded by ! to | 116 | * comma-separated sequence of subpatterns (each possibly preceded by ! to |
@@ -172,18 +170,16 @@ match_pattern_list(const char *string, const char *pattern, int dolower) | |||
172 | return got_positive; | 170 | return got_positive; |
173 | } | 171 | } |
174 | 172 | ||
175 | #endif | ||
176 | |||
177 | /* Match a list representing users or groups. */ | 173 | /* Match a list representing users or groups. */ |
178 | int | 174 | int |
179 | match_usergroup_pattern_list(const char *string, const char *pattern) | 175 | match_usergroup_pattern_list(const char *string, const char *pattern) |
180 | { | 176 | { |
181 | #ifndef HAVE_CYGWIN | 177 | #ifdef HAVE_CYGWIN |
182 | /* Case sensitive match */ | 178 | /* Windows usernames may be Unicode and are not case sensitive */ |
183 | return match_pattern_list(string, pattern, 0); | 179 | return cygwin_ug_match_pattern_list(string, pattern); |
184 | #else | 180 | #else |
185 | /* Case insensitive match */ | 181 | /* Case insensitive match */ |
186 | return match_pattern_list(string, pattern, 1); | 182 | return match_pattern_list(string, pattern, 0); |
187 | #endif | 183 | #endif |
188 | } | 184 | } |
189 | 185 | ||
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c index f721fca9d..1e4cdc928 100644 --- a/openbsd-compat/bsd-cygwin_util.c +++ b/openbsd-compat/bsd-cygwin_util.c | |||
@@ -128,7 +128,7 @@ free_windows_environment(char **p) | |||
128 | */ | 128 | */ |
129 | 129 | ||
130 | static int | 130 | static int |
131 | __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive) | 131 | __match_pattern (const wchar_t *s, const wchar_t *pattern) |
132 | { | 132 | { |
133 | for (;;) { | 133 | for (;;) { |
134 | /* If at end of pattern, accept if also at end of string. */ | 134 | /* If at end of pattern, accept if also at end of string. */ |
@@ -152,8 +152,7 @@ __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive) | |||
152 | */ | 152 | */ |
153 | for (; *s; s++) | 153 | for (; *s; s++) |
154 | if (*s == *pattern && | 154 | if (*s == *pattern && |
155 | __match_pattern(s + 1, pattern + 1, | 155 | __match_pattern(s + 1, pattern + 1)) |
156 | caseinsensitive)) | ||
157 | return 1; | 156 | return 1; |
158 | /* Failed. */ | 157 | /* Failed. */ |
159 | return 0; | 158 | return 0; |
@@ -163,7 +162,7 @@ __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive) | |||
163 | * match at each position. | 162 | * match at each position. |
164 | */ | 163 | */ |
165 | for (; *s; s++) | 164 | for (; *s; s++) |
166 | if (__match_pattern(s, pattern, caseinsensitive)) | 165 | if (__match_pattern(s, pattern)) |
167 | return 1; | 166 | return 1; |
168 | /* Failed. */ | 167 | /* Failed. */ |
169 | return 0; | 168 | return 0; |
@@ -176,8 +175,7 @@ __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive) | |||
176 | return 0; | 175 | return 0; |
177 | 176 | ||
178 | /* Check if the next character of the string is acceptable. */ | 177 | /* Check if the next character of the string is acceptable. */ |
179 | if (*pattern != '?' && (*pattern != *s && | 178 | if (*pattern != '?' && towlower(*pattern) != towlower(*s)) |
180 | (!caseinsensitive || towlower(*pattern) != towlower(*s)))) | ||
181 | return 0; | 179 | return 0; |
182 | 180 | ||
183 | /* Move to the next character, both in string and in pattern. */ | 181 | /* Move to the next character, both in string and in pattern. */ |
@@ -188,7 +186,7 @@ __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive) | |||
188 | } | 186 | } |
189 | 187 | ||
190 | static int | 188 | static int |
191 | _match_pattern(const char *s, const char *pattern, int caseinsensitive) | 189 | _match_pattern(const char *s, const char *pattern) |
192 | { | 190 | { |
193 | wchar_t *ws; | 191 | wchar_t *ws; |
194 | wchar_t *wpattern; | 192 | wchar_t *wpattern; |
@@ -202,7 +200,7 @@ _match_pattern(const char *s, const char *pattern, int caseinsensitive) | |||
202 | return 0; | 200 | return 0; |
203 | wpattern = (wchar_t *) alloca((len + 1) * sizeof (wchar_t)); | 201 | wpattern = (wchar_t *) alloca((len + 1) * sizeof (wchar_t)); |
204 | mbstowcs(wpattern, pattern, len + 1); | 202 | mbstowcs(wpattern, pattern, len + 1); |
205 | return __match_pattern (ws, wpattern, caseinsensitive); | 203 | return __match_pattern (ws, wpattern); |
206 | } | 204 | } |
207 | 205 | ||
208 | /* | 206 | /* |
@@ -212,7 +210,7 @@ _match_pattern(const char *s, const char *pattern, int caseinsensitive) | |||
212 | * a positive match, 0 if there is no match at all. | 210 | * a positive match, 0 if there is no match at all. |
213 | */ | 211 | */ |
214 | int | 212 | int |
215 | match_pattern_list(const char *string, const char *pattern, int caseinsensitive) | 213 | cygwin_ug_match_pattern_list(const char *string, const char *pattern) |
216 | { | 214 | { |
217 | char sub[1024]; | 215 | char sub[1024]; |
218 | int negated; | 216 | int negated; |
@@ -248,7 +246,7 @@ match_pattern_list(const char *string, const char *pattern, int caseinsensitive) | |||
248 | sub[subi] = '\0'; | 246 | sub[subi] = '\0'; |
249 | 247 | ||
250 | /* Try to match the subpattern against the string. */ | 248 | /* Try to match the subpattern against the string. */ |
251 | if (_match_pattern(string, sub, caseinsensitive)) { | 249 | if (_match_pattern(string, sub)) { |
252 | if (negated) | 250 | if (negated) |
253 | return -1; /* Negative */ | 251 | return -1; /* Negative */ |
254 | else | 252 | else |
diff --git a/openbsd-compat/bsd-cygwin_util.h b/openbsd-compat/bsd-cygwin_util.h index 202c055db..55c5a5b81 100644 --- a/openbsd-compat/bsd-cygwin_util.h +++ b/openbsd-compat/bsd-cygwin_util.h | |||
@@ -55,6 +55,7 @@ int binary_open(const char *, int , ...); | |||
55 | int check_ntsec(const char *); | 55 | int check_ntsec(const char *); |
56 | char **fetch_windows_environment(void); | 56 | char **fetch_windows_environment(void); |
57 | void free_windows_environment(char **); | 57 | void free_windows_environment(char **); |
58 | int cygwin_ug_match_pattern_list(const char *, const char *); | ||
58 | 59 | ||
59 | #ifndef NO_BINARY_OPEN | 60 | #ifndef NO_BINARY_OPEN |
60 | #define open binary_open | 61 | #define open binary_open |