1 See https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=17847
2 (Though the original code needs to be patched to be case-insensitive.)
6 @@ -89,6 +89,10 @@ An expression of the form `n.n.n.n/m.m.m
7 bitwise AND of the address and the `mask\'. For example, the net/mask
8 pattern `131.155.72.0/255.255.254.0\' matches every address in the
9 range `131.155.72.0\' through `131.155.73.255\'.
11 +Wildcards `*\' and `?\' can be used to match hostnames or IP addresses. This
12 +method of matching cannot be used in conjunction with `net/mask\' matching,
13 +hostname matching beginning with `.\' or IP address matching ending with `.\'.
15 The access control language supports explicit wildcards:
19 @@ -82,6 +82,7 @@ static int client_match();
20 static int host_match();
21 static int string_match();
22 static int masked_match();
23 +static int match_pattern_ylo();
25 /* Size of logical line buffer. */
27 @@ -289,6 +290,11 @@ char *string;
31 +#ifndef DISABLE_WILDCARD_MATCHING
32 + if (strchr(tok, '*') || strchr(tok,'?')) { /* contains '*' or '?' */
33 + return (match_pattern_ylo(string,tok));
36 if (tok[0] == '.') { /* suffix */
37 n = strlen(string) - strlen(tok);
38 return (n > 0 && STR_EQ(tok, string + n));
39 @@ -329,3 +335,78 @@ char *string;
41 return ((addr & mask) == net);
44 +#ifndef DISABLE_WILDCARD_MATCHING
45 +/* Note: this feature has been adapted in a pretty straightforward way
46 + from Tatu Ylonen's last SSH version under free license by
47 + Pekka Savola <pekkas@netcore.fi>.
49 + Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
52 +/* Returns true if the given string matches the pattern (which may contain
53 + ? and * as wildcards), and zero if it does not match. */
55 +static int match_pattern_ylo(const char *s, const char *pattern)
61 + /* If at end of pattern, accept if also at end of string. */
66 + if (*pattern == '*')
68 + /* Skip the asterisk. */
71 + /* If at end of pattern, accept immediately. */
75 + /* If next character in pattern is known, optimize. */
76 + if (*pattern != '?' && *pattern != '*')
78 + /* Look instances of the next character in pattern, and try
79 + to match starting from those. */
83 + if (toupper(src) == toupper(pat) &&
84 + match_pattern_ylo(s + 1, pattern + 1))
91 + /* Move ahead one character at a time and try to match at each
94 + if (match_pattern_ylo(s, pattern))
100 + /* There must be at least one more character in the string. If we are
101 + at the end, fail. */
105 + /* Check if the next character of the string is acceptable. */
108 + if (*pattern != '?' && toupper(pat) != toupper(src))
111 + /* Move to the next character, both in string and in pattern. */
117 +#endif /* DISABLE_WILDCARD_MATCHING */