Fix an error in backtracking (apparently exacerbated by escapes).
[ircu2.10.12-pk.git] / ircd / match.c
index 530201871d96d9e3f0c3e1750d70ab93e81f6b81..b585053c795348900039553fae8c29f037fea525 100644 (file)
@@ -201,12 +201,14 @@ int match(const char *mask, const char *name)
       return 1;
     m = m_tmp;
     n = ++n_tmp;
+    if (*n == '\0')
+      return 1;
     break;
   case '\\':
     m++;
     /* allow escaping to force capitalization */
     if (*m++ != *n++)
-      return 1;
+      goto backtrack;
     break;
   case '*': case '?':
     for (star_p = 0; ; m++) {
@@ -839,102 +841,6 @@ int mmexec(const char *wcm, int wminlen, const char *rcm, int rminlen)
   return 1;                     /* Auch... something left out ? Fail */
 }
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-/** Parse an input string as an IPv4 address.
- * @param[in] in Text form of address.
- * @param[out] out IPv4 address in network representation.
- * @return Number of address bits specified by \a in.
- */
-static int ipmask_parse_ipv4(const char *in, struct in_addr *out)
-{
-  int class;
-  int ad[4] = { 0 };
-  int bits = 0;
-
-  class = sscanf(in, "%d.%d.%d.%d/%d", &ad[0], &ad[1], &ad[2], &ad[3], &bits);
-  if (class != 5)
-    bits = class * 8;
-  out->s_addr = ntohl((ad[0] << 24) | (ad[1] << 16) | (ad[2] << 8) | ad[3]);
-  return bits;
-}
-
-/** Test whether a string looks like it matches only IPv4 addresses.
- * @param[in] mask Hostname matching mask.
- * @return Non-zero if \a mask can only match IPv4 addresses, zero otherwise.
- */
-int check_if_ipmask(const char *mask)
-{
-  int has_digit = 0;
-  const char *p;
-
-  /* Given the bug that inspired this test, this may seem like a hasty
-   * kludge.  It isn't: Wildcard characters should be matched from the
-   * start, as when the username is the "interesting" part of the ban.
-   * Likewise, we cannot simply reject masks interpreted as x/0 for
-   * all x.
-   */
-  if (mask[0] == '.' || mask[0] == '/')
-    return 0;
-  for (p = mask; *p; ++p)
-    if (*p != '*' && *p != '?' && *p != '.' && *p != '/')
-    {
-      if (!IsDigit(*p))
-        return 0;
-      has_digit = -1;
-    }
-
-  return has_digit;
-}
-
-/** Try to parse an IPv4 or IPv6 address mask.
- * @param[in] in Address matching mask.
- * @param[out] mask Fixed bits of address mask.
- * @param[out] bits_ptr If non-NULL, receives number of bits specified in address mask.
- * @return Non-zero on successful parse; zero on error.
- */
-int ipmask_parse(const char *in, struct irc_in_addr *mask, unsigned char *bits_ptr)
-{
-  struct in_addr ipv4;
-  char *p;
-  int bits = 0;
-
-  if (check_if_ipmask(in)) {
-    bits = ipmask_parse_ipv4(in, &ipv4);
-    mask->in6_16[0] = mask->in6_16[1] = mask->in6_16[2] = 0;
-    mask->in6_16[3] = mask->in6_16[4] = 0;
-    mask->in6_16[5] = 0xffff;
-    memcpy(&mask->in6_16[6], &ipv4.s_addr, sizeof(ipv4.s_addr));
-    bits += 96;
-  } else if (in[0] == '*' && in[1] == '\0') {
-    /* accept as a 0-bit mask */
-    memset(&mask->in6_16, 0, sizeof(mask->in6_16));
-    bits = 0;
-  } else {
-    if (!(p = strchr(in, '/')))
-      bits = 128;
-    else
-      *p = 0;
-    if (!ircd_aton(mask, in)) {
-      if (p)
-        *p = '/';
-      return 0;
-    }
-    if (p) {
-      bits = atoi(p + 1);
-      *p = '/';
-    }
-  }
-
-  if (bits_ptr)
-    *bits_ptr = bits;
-  return 1;
-}
-
 /** Test whether an address matches the most significant bits of a mask.
  * @param[in] addr Address to test.
  * @param[in] mask Address to test against.