Blame SOURCES/tcp_wrappers-7.6-bug17847.patch

c863fc
--- tcp_wrappers_7.6/hosts_access.5.patch6	2013-01-23 11:10:00.545081410 +0100
c863fc
+++ tcp_wrappers_7.6/hosts_access.5	2013-01-23 11:10:00.549081436 +0100
c863fc
@@ -96,6 +96,10 @@ or address pattern listed in the named f
c863fc
 zero or more lines with zero or more host name or address patterns
c863fc
 separated by whitespace.  A file name pattern can be used anywhere
c863fc
 a host name or address pattern can be used.
c863fc
+.IP \(bu
c863fc
+Wildcards `*\' and `?\' can be used to match hostnames or IP addresses.  This
c863fc
+method of matching cannot be used in conjunction with `net/mask\' matching,
c863fc
+hostname matching beginning with `.\' or IP address matching ending with `.\'.
c863fc
 .SH WILDCARDS
c863fc
 The access control language supports explicit wildcards:
c863fc
 .IP ALL
c863fc
--- tcp_wrappers_7.6/hosts_access.c.patch6	2013-01-23 11:10:00.546081416 +0100
c863fc
+++ tcp_wrappers_7.6/hosts_access.c	2013-01-23 11:12:28.519925230 +0100
c863fc
@@ -376,6 +376,11 @@ char   *string;
c863fc
 {
c863fc
     int     n;
c863fc
 
c863fc
+#ifndef DISABLE_WILDCARD_MATCHING
c863fc
+    if (strchr(tok, '*') || strchr(tok,'?')) {  /* contains '*' or '?' */
c863fc
+        return (match_pattern_ylo(string,tok)); 	       
c863fc
+    } else 
c863fc
+#endif    
c863fc
     if (tok[0] == '.') {			/* suffix */
c863fc
 	n = strlen(string) - strlen(tok);
c863fc
 	return (n > 0 && STR_EQ(tok, string + n));
c863fc
@@ -417,6 +422,74 @@ char   *string;
c863fc
     return ((addr & mask) == net);
c863fc
 }
c863fc
 
c863fc
+#ifndef DISABLE_WILDCARD_MATCHING
c863fc
+/* Note: this feature has been adapted in a pretty straightforward way
c863fc
+   from Tatu Ylonen's last SSH version under free license by 
c863fc
+   Pekka Savola <pekkas@netcore.fi>.
c863fc
+
c863fc
+   Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
c863fc
+*/
c863fc
+
c863fc
+/* Returns true if the given string matches the pattern (which may contain
c863fc
+   ? and * as wildcards), and zero if it does not match. */
c863fc
+	  
c863fc
+int match_pattern_ylo(const char *s, const char *pattern)
c863fc
+{
c863fc
+  while (1)
c863fc
+    {
c863fc
+      /* If at end of pattern, accept if also at end of string. */
c863fc
+      if (!*pattern)
c863fc
+        return !*s;
c863fc
+
c863fc
+      /* Process '*'. */
c863fc
+      if (*pattern == '*')
c863fc
+        {
c863fc
+	  /* Skip the asterisk. */
c863fc
+	  pattern++;
c863fc
+
c863fc
+	  /* If at end of pattern, accept immediately. */
c863fc
+          if (!*pattern)
c863fc
+            return 1;
c863fc
+
c863fc
+	  /* If next character in pattern is known, optimize. */
c863fc
+          if (*pattern != '?' && *pattern != '*')
c863fc
+            {
c863fc
+	      /* Look instances of the next character in pattern, and try
c863fc
+		 to match starting from those. */
c863fc
+              for (; *s; s++)
c863fc
+                if (*s == *pattern &&
c863fc
+                    match_pattern_ylo(s + 1, pattern + 1))
c863fc
+                  return 1;
c863fc
+	      /* Failed. */
c863fc
+              return 0;
c863fc
+            }
c863fc
+
c863fc
+	  /* Move ahead one character at a time and try to match at each
c863fc
+	     position. */
c863fc
+          for (; *s; s++)
c863fc
+            if (match_pattern_ylo(s, pattern))
c863fc
+              return 1;
c863fc
+	  /* Failed. */
c863fc
+          return 0;
c863fc
+        }
c863fc
+
c863fc
+      /* There must be at least one more character in the string.  If we are
c863fc
+	 at the end, fail. */
c863fc
+      if (!*s)
c863fc
+        return 0;
c863fc
+
c863fc
+      /* Check if the next character of the string is acceptable. */
c863fc
+      if (*pattern != '?' && *pattern != *s)
c863fc
+	return 0;
c863fc
+      
c863fc
+      /* Move to the next character, both in string and in pattern. */
c863fc
+      s++;
c863fc
+      pattern++;
c863fc
+    }
c863fc
+  /*NOTREACHED*/
c863fc
+}
c863fc
+#endif /* DISABLE_WILDCARD_MATCHING */
c863fc
+
c863fc
 #ifdef HAVE_IPV6
c863fc
 /*
c863fc
  * Function that zeros all but the first "maskbits" bits of the IPV6 address