]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/tools.c
Fix for bug in X3.unban handling
[irc/evilnet/x3.git] / src / tools.c
index 3a25dd45664ebf7770c22307cad51e56f066ba4c..afaed60c9b43421edc1aaec402a1c7244148eac9 100644 (file)
@@ -367,6 +367,10 @@ irc_strtolower(char *str) {
 
 int
 irccasecmp(const char *stra, const char *strb) {
+    if (!stra)
+      return -1;
+    if (!strb)
+      return 1;
     while (*stra && (tolower(*stra) == tolower(*strb)))
         stra++, strb++;
     return tolower(*stra) - tolower(*strb);
@@ -604,7 +608,7 @@ int is_overmask(char *mask)
 int
 user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int shared)
 {
-    char *tmpglob, *glob, *marker, *echannel, *emodes;
+    char *tmpglob, *glob, *marker;
     char exttype = 0;
     int extreverse = 0, is_extended = 0, match = 0, banned = 0;
     unsigned int count, n;
@@ -657,38 +661,25 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int s
                 return match_ircglob(user->hostname, glob);
             case 'c':
                 if (!strstr(glob, "#"))
-                    return 0;
-
-                tmpglob = strdup(glob);
-                if (*glob != '#') {
-                    echannel = strstr(glob, "#");
-                    emodes = strtok(tmpglob, "#");
-                } else {
-                    echannel = strdup(glob);
-                    emodes = "";
-                }
+                    return -1;
 
                 if (extreverse) {
                     for (n=count=0; n<user->channels.used; n++) {
                         mn = user->channels.list[n];
                         match = 0;
 
-                        if (0 == strcasecmp(echannel, mn->channel->name)) {
-                            if (strlen(emodes) > 0) {
-                                if (mn->modes & MODE_CHANOP) {
-                                    if (strstr(emodes, "@"))
-                                        match = 1;
-                                }
-                                if (mn->modes & MODE_HALFOP) {
-                                    if (strstr(emodes, "%"))
-                                        match = 1;
-                                }
-                                if (mn->modes & MODE_VOICE) {
-                                    if (strstr(emodes, "+"))
-                                        match = 1;
-                                }
-                            } else
+                        if (*glob == '#') {
+                            if (0 == strcasecmp(glob, mn->channel->name))
                                 match = 1;
+                        } else {
+                            if (0 == strcasecmp(glob+1, mn->channel->name)) {
+                                if ((*glob == '@') && (mn->modes & MODE_CHANOP))
+                                    match = 1;
+                                else if ((*glob == '%') && (mn->modes & MODE_HALFOP))
+                                    match = 1;
+                                else if ((*glob == '+') && (mn->modes & MODE_VOICE))
+                                    match = 1;
+                             }
                         }
 
                         if (match == 0)
@@ -703,23 +694,20 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int s
                         mn = user->channels.list[n];
                         match = 0;
 
-                        if (0 == strcasecmp(echannel, mn->channel->name)) {
-                            if (strlen(emodes) > 0) {
-                                if (mn->modes & MODE_CHANOP) {
-                                    if (strstr(emodes, "@"))
-                                        match = 1;
-                                }
-                                if (mn->modes & MODE_HALFOP) {
-                                    if (strstr(emodes, "%"))
-                                        match = 1;
-                                }
-                                if (mn->modes & MODE_VOICE) {
-                                    if (strstr(emodes, "+"))
-                                        match = 1;
-                                }
-                            } else
+                        if (*glob == '#') {
+                            if (0 == strcasecmp(glob, mn->channel->name))
                                 match = 1;
+                        } else {
+                            if (0 == strcasecmp(glob+1, mn->channel->name)) {
+                                if ((*glob == '@') && (mn->modes & MODE_CHANOP))
+                                    match = 1;
+                                else if ((*glob == '%') && (mn->modes & MODE_HALFOP))
+                                    match = 1;
+                                else if ((*glob == '+') && (mn->modes & MODE_VOICE))
+                                    match = 1;
+                             }
                         }
+
                         if (match == 1)
                             banned = 1;
                     }
@@ -731,6 +719,8 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int s
                     return match_ircglob(user->hostname, glob);
             case 'j':
                  if (shared == 0) {
+                     if (*glob != '#')
+                         return -1;
                      if ((channel = GetChannel(glob))) {
                          for (n = 0; n < channel->banlist.used; n++) {
                              ban = channel->banlist.list[n];
@@ -746,8 +736,10 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int s
                 return match_ircglob(user->hostname, glob);
             case 't': /* this is handled ircd side */
                 return match_ircglob(user->hostname, glob);
+            case 'R': /* this is handled ircd side */
+                return match_ircglob(user->hostname, glob);
             default:
-                return 0;
+                return -1;
         }
     }
 
@@ -796,7 +788,8 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int s
 
     /* If only matching the visible hostnames, bail early. */
     if ((flags & MATCH_VISIBLE) && IsHiddenHost(user)
-        && (IsFakeHost(user) || (hidden_host_suffix && user->handle_info)))
+        && (IsFakeHost(user) || (hidden_host_suffix && user->handle_info) ||
+            user->crypthost || user->cryptip))
         return 0;
     /* If it might be an IP glob, test that. */
     if (!glob[strspn(glob, "0123456789./*?")]