Greetings.  In accordance with my earlier conversation with hop, and my
offer to write the patch to fix the previously mentioned behavior, here's
the patch.

Things worth noting:  All (correct) original behavior is, for all intents and
purposes, preserved.  //ignore and $uhc() get the added benefit of working
slightly 'faster' because they have no need to split an fqdn into
host/domain parts.  I have done my best to insure that this patch doesn't
cause the client to burst into flames, but I have not rigorously tested it.

Additionally, I feel there may be a memory leak in 'figure_out_address',
where there is an malloc_strcpy call with no accompanying (new_)free().
This problem might be best solved with a static buffer.

What I have done is to separate the former figure_out_address into two
segments.  figure_out_address does exactly what it advertises to do, which
is to take some arbitrary user input and turn it into an address.  I've
added 'figure_out_domain' which takes an fqdn and splits it into a
host/domain pairing.  Right now $mask() is the only thing which uses it,
but I decided not to incorporate it into $mask() becuase someone else may
find it useful later.

[patch attached]

-wd
-- 
chip norkus; c programmer of the apocalypse     [EMAIL PROTECTED]
"question = (to) ? be : !be;" --Shakespeare     http://telekinesis.org
diff -rubN epic4/include/ircaux.h epic4.patch/include/ircaux.h
--- epic4/include/ircaux.h      Wed Jan 30 15:48:31 2002
+++ epic4.patch/include/ircaux.h        Wed Jan 30 23:31:28 2002
@@ -145,7 +145,8 @@
 char * decode                  (const char *);
 char * chomp                   (char *);
 int    opento                  (const char *, int, off_t);
-int    figure_out_address      (char *, char **, char **, char **, char **, int *);
+int    figure_out_address      (char *, char **, char **, char **, int *);
+int    figure_out_domain       (char *, char **, char **);
 int    count_char              (const unsigned char *, const unsigned char);
 char * strnrchr                (char *, char, int);
 void   mask_digits             (char **);
Binary files epic4/source/.ircaux.c.swp and epic4.patch/source/.ircaux.c.swp differ
diff -rubN epic4/source/functions.c epic4.patch/source/functions.c
--- epic4/source/functions.c    Wed Jan 30 15:48:34 2002
+++ epic4.patch/source/functions.c      Wed Jan 30 23:45:54 2002
@@ -3928,22 +3928,19 @@
        RETURN_INT(-1);
 }
 
-#define DOT (*host ? dot : empty_string)
 
 BUILT_IN_FUNCTION(function_uhc, input)
 {
-       char    *nick, *user, *host, *domain;
+       char    *nick, *user, *host;
        int     ip;
 
        if (!input || !*input)
                RETURN_EMPTY;
 
-       if (figure_out_address(input, &nick, &user, &host, &domain, &ip))
+       if (figure_out_address(input, &nick, &user, &host, &ip))
                RETURN_STR(input);
-       else if (ip == 0)
-               return m_sprintf("%s!%s@%s%s%s", nick, user, host, DOT, domain);
        else
-               return m_sprintf("%s!%s@%s%s%s", nick, user, domain, DOT, host);
+               return m_sprintf("%s!%s@%s", nick, user, host);
 }
 
 /*
@@ -4864,6 +4861,7 @@
        char *  nuh;
        char *  nick = NULL;
        char *  user = NULL;
+       char *  fqdn = NULL;
        char *  host = NULL;
        char *  domain = NULL;
        int     which;
@@ -4884,7 +4882,13 @@
                GET_INT_ARG(which, args);
        }
 
-       if (figure_out_address(nuh, &nick, &user, &host, &domain, &ip))
+       if (figure_out_address(nuh, &nick, &user, &fqdn, &ip))
+               RETURN_EMPTY;
+       if (strchr(fqdn, '.') == NULL) {
+               domain = NULL;
+               host = fqdn;
+       }
+       else if (figure_out_domain(fqdn, &host, &domain))
                RETURN_EMPTY;
 
        /*
@@ -4901,7 +4905,12 @@
                user[8] = 0;
        }
 
+       /* okay, here's how the DOMN/DOT work, DOMN gives you the 'domain' bit
+        * unless it's empty (see above).  DOT gives you a "." if the host and
+        * domain are both non-empty */
 #define USER (user == star ? empty_string : user)
+#define DOMN (domain == NULL ? empty_string : domain)
+#define DOT  (domain != NULL && *host ? dot : empty_string)
 #define MASK1(x, y) snprintf(stuff, BIG_BUFFER_SIZE, x, y); break;
 #define MASK2(x, y, z) snprintf(stuff, BIG_BUFFER_SIZE, x, y, z); break;
 #define MASK3(x, y, z, a) snprintf(stuff, BIG_BUFFER_SIZE, x, y, z, a); break;
@@ -4911,26 +4920,26 @@
        if (ip == 0) 
        switch (which)
        {
-               case 0:  MASK4("*!%s@%s%s%s",         user, host, DOT, domain)
-               case 1:  MASK4("*!*%s@%s%s%s",        USER, host, DOT, domain)
-               case 2:  MASK3("*!*@%s%s%s",                host, DOT, domain)
-               case 3:  MASK3("*!*%s@*%s%s",         USER,       DOT, domain)
-               case 4:  MASK2("*!*@*%s%s",                       DOT, domain)
-               case 5:  MASK5("%s!%s@%s%s%s",  nick, user, host, DOT, domain)
-               case 6:  MASK5("%s!*%s@%s%s%s", nick, USER, host, DOT, domain)
-               case 7:  MASK4("%s!*@%s%s%s",   nick,       host, DOT, domain)
-               case 8:  MASK4("%s!*%s@*%s%s",  nick, USER,       DOT, domain)
-               case 9:  MASK3("%s!*@*%s%s",    nick,             DOT, domain)
+               case 0:  MASK4("*!%s@%s%s%s",         user, host, DOT, DOMN)
+               case 1:  MASK4("*!*%s@%s%s%s",        USER, host, DOT, DOMN)
+               case 2:  MASK3("*!*@%s%s%s",                host, DOT, DOMN)
+               case 3:  MASK3("*!*%s@*%s%s",         USER,       DOT, DOMN)
+               case 4:  MASK2("*!*@*%s%s",                       DOT, DOMN)
+               case 5:  MASK5("%s!%s@%s%s%s",  nick, user, host, DOT, DOMN)
+               case 6:  MASK5("%s!*%s@%s%s%s", nick, USER, host, DOT, DOMN)
+               case 7:  MASK4("%s!*@%s%s%s",   nick,       host, DOT, DOMN)
+               case 8:  MASK4("%s!*%s@*%s%s",  nick, USER,       DOT, DOMN)
+               case 9:  MASK3("%s!*@*%s%s",    nick,             DOT, DOMN)
                case 10: mask_digits(&host);
-                        MASK3("*!*@%s%s%s",                host, DOT, domain)
+                        MASK3("*!*@%s%s%s",                host, DOT, DOMN)
                case 11: mask_digits(&host);
-                        MASK4("*!*%s@%s%s%s",        USER, host, DOT, domain)
+                        MASK4("*!*%s@%s%s%s",        USER, host, DOT, DOMN)
                case 12: mask_digits(&host);
-                        MASK4("%s!*@%s%s%s",   nick,       host, DOT, domain)
+                        MASK4("%s!*@%s%s%s",   nick,       host, DOT, DOMN)
                case 13: mask_digits(&host);
-                        MASK5("%s!*%s@%s%s%s", nick, USER, host, DOT, domain)
+                        MASK5("%s!*%s@%s%s%s", nick, USER, host, DOT, DOMN)
        }
-       else
+       else /* in the case of IPs, we always have domain/host */
        switch (which)
        {
                case 0:  MASK3("*!%s@%s.%s",          user, domain, host)
diff -rubN epic4/source/ignore.c epic4.patch/source/ignore.c
--- epic4/source/ignore.c       Thu Nov 15 18:50:27 2001
+++ epic4.patch/source/ignore.c Wed Jan 30 23:47:40 2002
@@ -61,7 +61,6 @@
        char *  mnick;
        char *  user;
        char *  host;
-       char *  dom;
 
        for (nick = LOCAL_COPY(nicklist); nick; nick = ptr)
        {
@@ -71,14 +70,11 @@
                if (!*nick)
                        continue;
 
-               if (figure_out_address(nick, &mnick, &user, &host, &dom, &ip))
+               if (figure_out_address(nick, &mnick, &user, &host, &ip))
                        strlcpy(new_nick, nick, IRCD_BUFFER_SIZE);
-               else if (ip == 0)
-                       snprintf(new_nick, IRCD_BUFFER_SIZE, "%s!%s@%s%s%s", 
-                               mnick, user, host, DOT, dom);
                else
-                       snprintf(new_nick, IRCD_BUFFER_SIZE, "%s!%s@%s%s%s",
-                               mnick, user, dom, DOT, host);
+                       snprintf(new_nick, IRCD_BUFFER_SIZE, "%s!%s@%s",
+                               mnick, user, host);
 
                if (!(new_i = (Ignore *) list_lookup((List **)&ignored_nicks, 
                                                        new_nick, 
@@ -201,17 +197,14 @@
        Ignore  *tmp;
        char    new_nick[IRCD_BUFFER_SIZE + 1];
        int     count = 0;
-       char    *mnick, *user, *host, *domain;
+       char    *mnick, *user, *host;
        int     ip;
 
-       if (figure_out_address(nick, &mnick, &user, &host, &domain, &ip))
+       if (figure_out_address(nick, &mnick, &user, &host, &ip))
                strlcpy(new_nick, nick, IRCD_BUFFER_SIZE);
-       else if (ip == 0)
-               snprintf(new_nick, IRCD_BUFFER_SIZE, "%s!%s@%s%s%s",
-                       mnick, user, host, DOT, domain);
        else
-               snprintf(new_nick, IRCD_BUFFER_SIZE, "%s!%s@%s%s%s",
-                       mnick, user, domain, DOT, host);
+               snprintf(new_nick, IRCD_BUFFER_SIZE, "%s!%s@%s",
+                       mnick, user, host);
 
        /*
         * Look for an exact match first.
diff -rubN epic4/source/ircaux.c epic4.patch/source/ircaux.c
--- epic4/source/ircaux.c       Wed Jan 30 15:48:34 2002
+++ epic4.patch/source/ircaux.c Wed Jan 30 23:55:52 2002
@@ -2783,19 +2783,12 @@
 /*
  * figure_out_address -- lets try this one more time.
  */
-int    figure_out_address (char *nuh, char **nick, char **user, char **host, char 
**domain, int *ip)
+int    figure_out_address (char *nuh, char **nick, char **user, char **host, int *ip)
 {
 static         char    *mystuff = NULL;
-       char    *firstback, 
-               *secondback, 
-               *thirdback, 
-               *fourthback;
        char    *bang, 
                *at, 
-               *dot = NULL,
-               *myhost = star, 
-               *endstring;
-       int     number;
+               *dot = NULL;
 
        /* Dont bother with channels, theyre ok. */
        if (*nuh == '#' || *nuh == '&')
@@ -2803,7 +2796,7 @@
 
        malloc_strcpy(&mystuff, nuh);
 
-       *host = *domain = star;
+       *host = star;
        *ip = 0;
 
 
@@ -2845,6 +2838,9 @@
 
 /*
  * STAGE ONE -- EXTRACT THE NICK, USER, AND HOST PORTIONS.
+ *
+ * stage two is now in 'figure_out_domain', so functions which want it
+ * that way can have it that way.
  */
 
        /*
@@ -2857,7 +2853,7 @@
                        /* nick!user@host */
                        *nick = mystuff;
                        *user = bang + 1;
-                       myhost = at + 1;
+                       *host = at + 1;
                }
                else
                {
@@ -2865,13 +2861,13 @@
                        {
                                *nick = mystuff;
                                *user = star;
-                               myhost = at + 1;
+                               *host = at + 1;
                        }
                        else                    /* nick!user */
                        {
                                *nick = mystuff;
                                *user = star;
-                               myhost = star;
+                               *host = star;
                        }
                }
        }
@@ -2882,7 +2878,7 @@
                        /* [EMAIL PROTECTED] */
                        *nick = star;
                        *user = mystuff;
-                       myhost = at + 1;
+                       *host = at + 1;
                }
                else
                {
@@ -2890,36 +2886,53 @@
                        {
                                *nick = star;
                                *user = star;
-                               myhost = mystuff;
+                               *host = mystuff;
                        }
                        else                    /* nick */
                        {
                                *nick = mystuff;
                                *user = star;
-                               myhost = star;
+                               *host = star;
+                       }
                        }
                }
+
+       /* determine if we have an IP, use dot to hold this */
+       if (dot = strrchr(*host, '.')) {
+           if (my_atol(dot + 1))
+               *ip = 1;
        }
 
+       return 0;
+}
+
+
+int    figure_out_domain (char *fqdn, char **host, char **domain) {
+       char    *firstback, 
+               *secondback, 
+               *thirdback, 
+               *fourthback;
+       char    *endstring;
+       int     number;
 
 /*
- * STAGE TWO -- EXTRACT THE HOST AND DOMAIN FROM MYHOST
+ * STAGE TWO -- EXTRACT THE HOST AND DOMAIN FROM FQDN
  */
 
        /*
-        * At this point, 'myhost' points what what we think the hostname
+        * At this point, 'fqdn' points what what we think the hostname
         * is.  We chop it up into discrete parts and see what we end up with.
         */
-       endstring = myhost + strlen(myhost);
-       firstback = strnrchr(myhost, '.', 1);
-       secondback = strnrchr(myhost, '.', 2);
-       thirdback = strnrchr(myhost, '.', 3);
-       fourthback = strnrchr(myhost, '.', 4);
+       endstring = fqdn + strlen(fqdn);
+       firstback = strnrchr(fqdn, '.', 1);
+       secondback = strnrchr(fqdn, '.', 2);
+       thirdback = strnrchr(fqdn, '.', 3);
+       fourthback = strnrchr(fqdn, '.', 4);
 
        /* Track foo@bar or some such thing. */
        if (!firstback)
        {
-               *host = myhost;
+               *host = fqdn;
                return 0;
        }
 
@@ -2928,10 +2941,9 @@
         */
        if (my_atol(firstback + 1))
        {
-               *ip = 1;
-               *domain = myhost;
+               *domain = fqdn;
 
-               number = my_atol(myhost);
+               number = my_atol(fqdn);
                if (number < 128)
                        *host = thirdback;
                else if (number < 192)
@@ -2951,7 +2963,7 @@
         */
        else if (secondback && (endstring - firstback == 4))
        {
-               *host = myhost;
+               *host = fqdn;
                *domain = secondback;
                **domain = 0;
                (*domain)++;
@@ -2965,7 +2977,7 @@
                        !strncmp(thirdback, ".k12.", 5) &&
                        !strncmp(firstback, ".us", 3))
        {
-               *host = myhost;
+               *host = fqdn;
                *domain = fourthback;
                **domain = 0;
                (*domain)++;
@@ -2980,7 +2992,7 @@
                        !strncmp(firstback, ".us", 3))
        {
                *host = empty_string;
-               *domain = myhost;
+               *domain = fqdn;
        }
        /*
         *      (*).(*.???.??)
@@ -2990,7 +3002,7 @@
                        (endstring - firstback == 3) &&
                        (firstback - secondback == 4))
        {
-               *host = myhost;
+               *host = fqdn;
                *domain = thirdback;
                **domain = 0;
                (*domain)++;
@@ -3004,7 +3016,7 @@
                        (firstback - secondback == 4))
        {
                *host = empty_string;
-               *domain = myhost;
+               *domain = fqdn;
        }
        /*
         *      (*).(*.??.??)
@@ -3014,7 +3026,7 @@
                        (endstring - firstback == 3) &&
                        (firstback - secondback == 3))
        {
-               *host = myhost;
+               *host = fqdn;
                *domain = thirdback;
                **domain = 0;
                (*domain)++;
@@ -3028,7 +3040,7 @@
                        (firstback - secondback == 3))
        {
                *host = empty_string;
-               *domain = myhost;
+               *domain = fqdn;
        }
        /*
         *      (*).(*.??)
@@ -3036,7 +3048,7 @@
         */
        else if (secondback && (endstring - firstback == 3))
        {
-               *host = myhost;
+               *host = fqdn;
                *domain = secondback;
                **domain = 0;
                (*domain)++;
@@ -3047,7 +3059,7 @@
        else
        {
                *host = empty_string;
-               *domain = myhost;
+               *domain = fqdn;
        }
 
        return 0;

Reply via email to