various bugfixes and IPv6 preparation work
[srvx.git] / src / tools.c
index 219d0afdc91ede210005662e444a5bbf42bb8a65..973bc53bb823455cc1fce85313c2e690a641336a 100644 (file)
@@ -334,20 +334,22 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int include_nick
     if (!match_ircglob(user->ident, glob))
         return 0;
     glob = marker + 1;
-    /* Now check the host part */
-    if (isdigit(*glob) && !glob[strspn(glob, "0123456789./*?")]) {
-        /* Looks like an IP-based mask */
-        return match_ircglob(inet_ntoa(user->ip), glob);
-    } else {
-        /* The host part of the mask isn't IP-based */
-        if (hidden_host_suffix && user->handle_info) {
-            char hidden_host[HOSTLEN+1];
-            snprintf(hidden_host, sizeof(hidden_host), "%s.%s", user->handle_info->handle, hidden_host_suffix);
-            if (match_ircglob(hidden_host, glob))
-                return 1;
-        }
-        return match_ircglob(user->hostname, glob);
-    }
+    /* If it might be an IP glob, test that. */
+    if (!glob[strspn(glob, "0123456789./*?")]
+        && match_ircglob(inet_ntoa(user->ip), glob))
+        return 1;
+    /* Check for a fakehost match. */
+    if (IsFakeHost(user) && match_ircglob(user->fakehost, glob))
+            return 1;
+    /* Check for an account match. */
+    if (hidden_host_suffix && user->handle_info) {
+        char hidden_host[HOSTLEN+1];
+        snprintf(hidden_host, sizeof(hidden_host), "%s.%s", user->handle_info->handle, hidden_host_suffix);
+        if (match_ircglob(hidden_host, glob))
+            return 1;
+    }
+    /* None of the above; could only be a hostname match. */
+    return match_ircglob(user->hostname, glob);
 }
 
 int
@@ -376,7 +378,7 @@ is_gline(const char *text)
         return 0;
     if (!*text)
         return 0;
-    while (*text && (isalnum((char)*text) || strchr(".-?*", *text)))
+    while (*text && (isalnum((char)*text) || strchr(".-?*:", *text)))
         text++;
     return !*text;
 }
@@ -403,9 +405,9 @@ split_ircmask(char *text, char **nick, char **ident, char **host)
     *text = 0;
     if (ident)
         *ident = start;
-    
+
     start = ++text;
-    while (*text && (isalnum((char)*text) || strchr(".-?*", *text)))
+    while (*text && (isalnum((char)*text) || strchr(".-?*:", *text)))
         text++;
     if (host)
         *host = start;
@@ -744,7 +746,7 @@ string_buffer_append_vprintf(struct string_buffer *buf, const char *fmt, va_list
         /* pre-C99 behavior; double buffer size until it is big enough */
         va_end(working);
         VA_COPY(working, args);
-        while ((ret = vsnprintf(buf->list + buf->used, buf->size, fmt, working)) == -1) {
+        while ((ret = vsnprintf(buf->list + buf->used, buf->size - buf->used, fmt, working)) <= 0) {
             buf->size += len;
             buf->list = realloc(buf->list, buf->size);
             va_end(working);