]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Use Cygwin-specific matching only for users+groups.
authorDarren Tucker <dtucker@dtucker.net>
Mon, 11 Mar 2019 22:19:19 +0000 (09:19 +1100)
committerDarren Tucker <dtucker@dtucker.net>
Mon, 11 Mar 2019 22:19:19 +0000 (09:19 +1100)
Patch from vinschen at redhat.com, updated a little by me.

match.c
openbsd-compat/bsd-cygwin_util.c
openbsd-compat/bsd-cygwin_util.h

diff --git a/match.c b/match.c
index ff0815ef91f769b3e7df225eb24992713acd7390..fcf69596d56ec88c28c332e819708385217a28e2 100644 (file)
--- a/match.c
+++ b/match.c
@@ -111,8 +111,6 @@ match_pattern(const char *s, const char *pattern)
        /* NOTREACHED */
 }
 
-#ifndef HAVE_CYGWIN /* Cygwin version in openbsd-compat/bsd-cygwin_util.c */
-
 /*
  * Tries to match the string against the
  * 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)
        return got_positive;
 }
 
-#endif
-
 /* Match a list representing users or groups. */
 int
 match_usergroup_pattern_list(const char *string, const char *pattern)
 {
-#ifndef HAVE_CYGWIN
-       /* Case sensitive match */
-       return match_pattern_list(string, pattern, 0);
+#ifdef HAVE_CYGWIN
+       /* Windows usernames may be Unicode and are not case sensitive */
+       return cygwin_ug_match_pattern_list(string, pattern);
 #else
        /* Case insensitive match */
-       return match_pattern_list(string, pattern, 1);
+       return match_pattern_list(string, pattern, 0);
 #endif
 }
 
index f721fca9d9987a16e98579324d6fdb6c4228ac54..1e4cdc9280d4ecb9bf08a7e3b11bb739c7696f32 100644 (file)
@@ -128,7 +128,7 @@ free_windows_environment(char **p)
  */
 
 static int
-__match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive)
+__match_pattern (const wchar_t *s, const wchar_t *pattern)
 {
        for (;;) {
                /* 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)
                                 */
                                for (; *s; s++)
                                        if (*s == *pattern &&
-                                           __match_pattern(s + 1, pattern + 1,
-                                                           caseinsensitive))
+                                           __match_pattern(s + 1, pattern + 1))
                                                return 1;
                                /* Failed. */
                                return 0;
@@ -163,7 +162,7 @@ __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive)
                         * match at each position.
                         */
                        for (; *s; s++)
-                               if (__match_pattern(s, pattern, caseinsensitive))
+                               if (__match_pattern(s, pattern))
                                        return 1;
                        /* Failed. */
                        return 0;
@@ -176,8 +175,7 @@ __match_pattern (const wchar_t *s, const wchar_t *pattern, int caseinsensitive)
                        return 0;
 
                /* Check if the next character of the string is acceptable. */
-               if (*pattern != '?' && (*pattern != *s &&
-                    (!caseinsensitive || towlower(*pattern) != towlower(*s))))
+               if (*pattern != '?' && towlower(*pattern) != towlower(*s))
                        return 0;
 
                /* 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)
 }
 
 static int
-_match_pattern(const char *s, const char *pattern, int caseinsensitive)
+_match_pattern(const char *s, const char *pattern)
 {
        wchar_t *ws;
        wchar_t *wpattern;
@@ -202,7 +200,7 @@ _match_pattern(const char *s, const char *pattern, int caseinsensitive)
                return 0;
        wpattern = (wchar_t *) alloca((len + 1) * sizeof (wchar_t));
        mbstowcs(wpattern, pattern, len + 1);
-       return __match_pattern (ws, wpattern, caseinsensitive);
+       return __match_pattern (ws, wpattern);
 }
 
 /*
@@ -212,7 +210,7 @@ _match_pattern(const char *s, const char *pattern, int caseinsensitive)
  * a positive match, 0 if there is no match at all.
  */
 int
-match_pattern_list(const char *string, const char *pattern, int caseinsensitive)
+cygwin_ug_match_pattern_list(const char *string, const char *pattern)
 {
        char sub[1024];
        int negated;
@@ -248,7 +246,7 @@ match_pattern_list(const char *string, const char *pattern, int caseinsensitive)
                sub[subi] = '\0';
 
                /* Try to match the subpattern against the string. */
-               if (_match_pattern(string, sub, caseinsensitive)) {
+               if (_match_pattern(string, sub)) {
                        if (negated)
                                return -1;              /* Negative */
                        else
index 202c055dbae747933fbc7da03bc28639424bedc0..55c5a5b81b4418255127eeeff88528e076701967 100644 (file)
@@ -55,6 +55,7 @@ int binary_open(const char *, int , ...);
 int check_ntsec(const char *);
 char **fetch_windows_environment(void);
 void free_windows_environment(char **);
+int cygwin_ug_match_pattern_list(const char *, const char *);
 
 #ifndef NO_BINARY_OPEN
 #define open binary_open