Blame SOURCES/tcp_wrappers-7.6-bug17847.patch

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