Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / gline.c
index 03cfae6684bb001433f8e98267fd3eb5b0ab0032..bc18f39ce2c49eb9671364535e1122bab176f4f7 100644 (file)
@@ -28,6 +28,7 @@
 #include "match.h"
 #include "numeric.h"
 #include "s_bsd.h"
+#include "s_debug.h"
 #include "s_misc.h"
 #include "send.h"
 #include "struct.h"
@@ -39,6 +40,8 @@
 
 #include <assert.h>
 #include <string.h>
+#include <stdio.h>
+#include <arpa/inet.h> /* for inet_ntoa */
 
 struct Gline* GlobalGlineList  = 0;
 struct Gline* BadChanGlineList = 0;
@@ -62,9 +65,32 @@ static struct Gline *
 make_gline(char *userhost, char *reason, time_t expire, time_t lastmod,
           unsigned int flags)
 {
-  struct Gline *gline;
+  struct Gline *gline, *sgline, *after = 0;
   char *user, *host;
 
+  if (!(flags & GLINE_BADCHAN)) { /* search for overlapping glines first */
+    canon_userhost(userhost, &user, &host, "*"); /* find user and host */
+
+    for (gline = GlobalGlineList; gline; gline = sgline) {
+      sgline = gline->gl_next;
+
+      if (gline->gl_expire <= CurrentTime)
+       gline_free(gline);
+      else if ((gline->gl_flags & GLINE_LOCAL) != (flags & GLINE_LOCAL))
+       continue;
+      else if (!mmatch(gline->gl_user, user) && /* gline contains new mask */
+              !mmatch(gline->gl_host, host)) {
+       if (expire <= gline->gl_expire) /* will expire before wider gline */
+         return 0;
+       else
+         after = gline; /* stick new gline after this one */
+      } else if (!mmatch(user, gline->gl_user) && /* new mask contains gline */
+                !mmatch(host, gline->gl_host) &&
+                gline->gl_expire <= expire) /* gline expires before new one */
+       gline_free(gline); /* save some memory */
+    }
+  }
+
   gline = (struct Gline *)MyMalloc(sizeof(struct Gline)); /* alloc memory */
   assert(0 != gline);
 
@@ -83,19 +109,42 @@ make_gline(char *userhost, char *reason, time_t expire, time_t lastmod,
       BadChanGlineList->gl_prev_p = &gline->gl_next;
     BadChanGlineList = gline;
   } else {
-    canon_userhost(userhost, &user, &host, "*"); /* find user and host */
-
     DupString(gline->gl_user, user); /* remember them... */
     DupString(gline->gl_host, host);
 
-    if (check_if_ipmask(host)) /* mark if it's an IP mask */
+    if (check_if_ipmask(host)) { /* mark if it's an IP mask */
+      int class;
+      char ipname[16];
+      int ad[4] = { 0 };
+      int bits2 = 0;
+       
+      class = sscanf(host,"%d.%d.%d.%d/%d",
+                     &ad[0],&ad[1],&ad[2],&ad[3], &bits2);
+      if (class!=5) {
+        gline->bits=class*8;
+      }
+      else {
+        gline->bits=bits2;
+      }
+      sprintf_irc(ipname,"%d.%d.%d.%d",ad[0],ad[1],ad[2],ad[3]);
+      gline->ipnum.s_addr = inet_addr(ipname);
+      Debug((DEBUG_DEBUG,"IP gline: %08x/%i",gline->ipnum.s_addr,gline->bits));
       gline->gl_flags |= GLINE_IPMASK;
+    }
 
-    gline->gl_next = GlobalGlineList; /* then link it into list */
-    gline->gl_prev_p = &GlobalGlineList;
-    if (GlobalGlineList)
-      GlobalGlineList->gl_prev_p = &gline->gl_next;
-    GlobalGlineList = gline;
+    if (after) {
+      gline->gl_next = after->gl_next;
+      gline->gl_prev_p = &after->gl_next;
+      if (after->gl_next)
+       after->gl_next->gl_prev_p = &gline->gl_next;
+      after->gl_next = gline;
+    } else {
+      gline->gl_next = GlobalGlineList; /* then link it into list */
+      gline->gl_prev_p = &GlobalGlineList;
+      if (GlobalGlineList)
+       GlobalGlineList->gl_prev_p = &gline->gl_next;
+      GlobalGlineList = gline;
+    }
   }
 
   return gline;
@@ -117,27 +166,35 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
     if ((acptr = LocalClientArray[fd])) {
       if (!acptr->user)
        continue;
-
-      if ((GlineIsIpMask(gline) ? match(gline->gl_host, acptr->sock_ip) :
-          match(gline->gl_host, acptr->sockhost)) == 0 &&
-         (!acptr->user->username ||
-          match(gline->gl_user, acptr->user->username) == 0)) {
-       /* ok, here's one that got G-lined */
-       sendto_one(acptr, ":%s %d %s :*** %s.", me.name, ERR_YOUREBANNEDCREEP,
-                  acptr->name, gline->gl_reason);
-
-       /* let the ops know about it */
-       sendto_op_mask(SNO_GLINE, "G-line active for %s",
-                      get_client_name(acptr, FALSE));
-
-       /* and get rid of him */
-       if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)",
-                                   gline->gl_reason)))
-         retval = tval; /* retain killed status */
+       
+      if (acptr->user->username && 
+          match(gline->gl_user, acptr->user->username) == 0)
+          continue;
+          
+      if (GlineIsIpMask(gline)) {
+        Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",cptr->ip.s_addr,gline->ipnum.s_addr,gline->bits));
+        if ((cptr->ip.s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+          continue;
+      }
+      else {
+        if (match(gline->gl_host, acptr->sock_ip) != 0)
+          continue;
       }
+
+      /* ok, here's one that got G-lined */
+      send_reply(acptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s",
+          gline->gl_reason);
+
+      /* let the ops know about it */
+      sendto_opmask_butone(0, SNO_GLINE, "G-line active for %s",
+                    get_client_name(acptr, FALSE));
+
+      /* and get rid of him */
+      if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)",
+          gline->gl_reason)))
+        retval = tval; /* retain killed status */
     }
   }
-
   return retval;
 }
 
@@ -148,15 +205,15 @@ propagate_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
     return;
 
   if (gline->gl_lastmod)
-    sendcmdto_serv_butone(cptr, CMD_GLINE, sptr, "* %c%s%s%s %Tu %Tu :%s",
-                         GlineIsActive(gline) ? '+' : '-', gline->gl_user,
+    sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu :%s",
+                         GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
                          GlineIsBadChan(gline) ? "" : "@",
                          GlineIsBadChan(gline) ? "" : gline->gl_host,
                          gline->gl_expire - CurrentTime, gline->gl_lastmod,
                          gline->gl_reason);
   else
-    sendcmdto_serv_butone(cptr, CMD_GLINE, sptr, "* %c%s%s%s %Tu :%s",
-                         GlineIsActive(gline) ? '+' : '-', gline->gl_user,
+    sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s %Tu :%s",
+                         GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
                          GlineIsBadChan(gline) ? "" : "@",
                          GlineIsBadChan(gline) ? "" : gline->gl_host,
                          gline->gl_expire - CurrentTime, gline->gl_reason);
@@ -177,14 +234,13 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
    */
   if (!(flags & GLINE_FORCE) && (expire <= 0 || expire > GLINE_MAX_EXPIRE)) {
     if (!IsServer(sptr) && MyConnect(sptr))
-      send_error_to_client(sptr, ERR_BADEXPIRE, expire);
+      send_reply(sptr, ERR_BADEXPIRE, expire);
     return 0;
   }
 
   expire += CurrentTime; /* convert from lifetime to timestamp */
 
   /* NO_OLD_GLINE allows *@#channel to work correctly */
-#ifdef BADCHAN
   if (*userhost == '#' || *userhost == '&' || *userhost == '+'
 # ifndef NO_OLD_GLINE
       || userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+'
@@ -196,36 +252,29 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
 # endif
     flags |= GLINE_BADCHAN;
   }
-#endif /* BADCHAN */
 
   /* Inform ops... */
-  sendto_op_mask(SNO_GLINE, "%s adding %s %s for %s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                flags & GLINE_LOCAL ? "local" : "global",
-                flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
-                expire + TSoffset, reason);
+  sendto_opmask_butone(0, SNO_GLINE, "%s adding %s %s for %s, expiring at "
+                      "%Tu: %s",
+                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      flags & GLINE_LOCAL ? "local" : "global",
+                      flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
+                      expire + TSoffset, reason);
 
 #ifdef GPATH
   /* and log it */
-  if (IsServer(sptr))
-    write_log(GPATH, "# " TIME_T_FMT " %s adding %s %s for %s, expiring at "
-             TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             flags & GLINE_LOCAL ? "local" : "global",
-             flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
-             expire + TSoffset, reason);
-  else
-    write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s adding %s %s for %s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             flags & GLINE_LOCAL ? "local" : "global",
-             flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
-             expire + TSoffset, reason);
+  write_log(GPATH, "# %Tu %C adding %s %s for %s, expiring at %Tu: %s\n",
+           TStime(), sptr, flags & GLINE_LOCAL ? "local" : "global",
+           flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
+           expire + TSoffset, reason);
 #endif /* GPATH */
 
   /* make the gline */
   agline = make_gline(userhost, reason, expire, lastmod, flags);
 
+  if (!agline) /* if it overlapped, silently return */
+    return 0;
+
   propagate_gline(cptr, sptr, agline);
 
   if (GlineIsBadChan(agline))
@@ -242,99 +291,105 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
 
 int
 gline_activate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
-              time_t lastmod)
+              time_t lastmod, unsigned int flags)
 {
+  unsigned int saveflags = 0;
+
   assert(0 != gline);
-  assert(!GlineIsLocal(gline));
 
-  gline->gl_flags |= GLINE_ACTIVE;
+  saveflags = gline->gl_flags;
 
-  if (gline->gl_lastmod >= lastmod) /* force lastmod to increase */
-    gline->gl_lastmod++;
-  else
-    gline->gl_lastmod = lastmod;
+  if (flags & GLINE_LOCAL)
+    gline->gl_flags &= ~GLINE_LDEACT;
+  else {
+    gline->gl_flags |= GLINE_ACTIVE;
+
+    if (gline->gl_lastmod >= lastmod) /* force lastmod to increase */
+      gline->gl_lastmod++;
+    else
+      gline->gl_lastmod = lastmod;
+  }
+
+  if ((saveflags & GLINE_ACTMASK) == GLINE_ACTIVE)
+    return 0; /* was active to begin with */
 
   /* Inform ops and log it */
-  sendto_op_mask(SNO_GLINE, "%s activating global %s for %s%s%s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-                gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-                GlineIsBadChan(gline) ? "" : gline->gl_host,
-                gline->gl_expire + TSoffset, gline->gl_reason);
+  sendto_opmask_butone(0, SNO_GLINE, "%s activating global %s for %s%s%s, "
+                      "expiring at %Tu: %s",
+                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+                      gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+                      GlineIsBadChan(gline) ? "" : gline->gl_host,
+                      gline->gl_expire + TSoffset, gline->gl_reason);
 
 #ifdef GPATH
-  if (IsServer(sptr))
-    write_log(GPATH, "# " TIME_T_FMT " %s activating global %s for %s%s%s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
-  else
-    write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s activating %s for "
-             "%s%s%s, expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
+  write_log(GPATH, "# %Tu %C activating global %s for %s%s%s, expiring at "
+           "%Tu: %s\n", TStime(), sptr,
+           GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+           gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+           GlineIsBadChan(gline) ? "" : gline->gl_host,
+           gline->gl_expire + TSoffset, gline->gl_reason);
 #endif /* GPATH */
 
-  propagate_gline(cptr, sptr, gline);
+  if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
+    propagate_gline(cptr, sptr, gline);
 
   return GlineIsBadChan(gline) ? 0 : do_gline(cptr, sptr, gline);
 }
 
 int
 gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
-                time_t lastmod)
+                time_t lastmod, unsigned int flags)
 {
+  unsigned int saveflags = 0;
+  char *msg;
+
   assert(0 != gline);
 
-  if (!GlineIsLocal(gline)) {
-    gline->gl_flags &= ~GLINE_ACTIVE;
+  saveflags = gline->gl_flags;
 
-    if (gline->gl_lastmod >= lastmod)
-      gline->gl_lastmod++;
-    else
-      gline->gl_lastmod = lastmod;
+  if (GlineIsLocal(gline))
+    msg = "removing local";
+  else if (!gline->gl_lastmod && !(flags & GLINE_LOCAL))
+    msg = "removing global";
+  else {
+    msg = "deactivating global";
+
+    if (flags & GLINE_LOCAL)
+      gline->gl_flags |= GLINE_LDEACT;
+    else {
+      gline->gl_flags &= ~GLINE_ACTIVE;
+
+      if (gline->gl_lastmod >= lastmod)
+       gline->gl_lastmod++;
+      else
+       gline->gl_lastmod = lastmod;
+    }
+
+    if ((saveflags & GLINE_ACTMASK) != GLINE_ACTIVE)
+      return 0; /* was inactive to begin with */
   }
 
   /* Inform ops and log it */
-  sendto_op_mask(SNO_GLINE, "%s %s %s for %s%s%s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                GlineIsLocal(gline) ? "removing local" :
-                "deactivating global",
-                GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-                gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-                GlineIsBadChan(gline) ? "" : gline->gl_host,
-                gline->gl_expire + TSoffset, gline->gl_reason);
+  sendto_opmask_butone(0, SNO_GLINE, "%s %s %s for %s%s%s, expiring at %Tu: "
+                      "%s",
+                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+                      gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+                      GlineIsBadChan(gline) ? "" : gline->gl_host,
+                      gline->gl_expire + TSoffset, gline->gl_reason);
 
 #ifdef GPATH
-  if (IsServer(sptr))
-    write_log(GPATH, "# " TIME_T_FMT " %s %s %s for %s%s%s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             GlineIsLocal(gline) ? "removing local" : "deactivating global",
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
-  else
-    write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s %s %s for "
-             "%s%s%s, expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             GlineIsLocal(gline) ? "removing local" : "deactivating global",
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
+  write_log(GPATH, "# %Tu %C %s %s for %s%s%s, expiring at %Tu: %s\n",
+           TStime(), sptr, msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+           gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+           GlineIsBadChan(gline) ? "" : gline->gl_host,
+           gline->gl_expire + TSoffset, gline->gl_reason);
 #endif /* GPATH */
 
-  if (GlineIsLocal(gline))
+  if (GlineIsLocal(gline) || (!gline->gl_lastmod && !(flags & GLINE_LOCAL)))
     gline_free(gline);
-  else
+  else if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
     propagate_gline(cptr, sptr, gline);
 
   return 0;
@@ -351,8 +406,11 @@ gline_find(char *userhost, unsigned int flags)
     for (gline = BadChanGlineList; gline; gline = sgline) {
       sgline = gline->gl_next;
 
-      if (gline->gl_expire <= TStime())
+      if (gline->gl_expire <= CurrentTime)
        gline_free(gline);
+      else if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+              (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+       continue;
       else if ((flags & GLINE_EXACT ? ircd_strcmp(gline->gl_user, userhost) :
                match(gline->gl_user, userhost)) == 0)
        return gline;
@@ -373,8 +431,11 @@ gline_find(char *userhost, unsigned int flags)
   for (gline = GlobalGlineList; gline; gline = sgline) {
     sgline = gline->gl_next;
 
-    if (gline->gl_expire <= TStime())
+    if (gline->gl_expire <= CurrentTime)
       gline_free(gline);
+    else if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+            (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+      continue;
     else if (flags & GLINE_EXACT) {
       if (ircd_strcmp(gline->gl_host, host) == 0 &&
          ((!user && ircd_strcmp(gline->gl_user, "*") == 0) ||
@@ -394,7 +455,7 @@ gline_find(char *userhost, unsigned int flags)
 }
 
 struct Gline *
-gline_lookup(struct Client *cptr)
+gline_lookup(struct Client *cptr, unsigned int flags)
 {
   struct Gline *gline;
   struct Gline *sgline;
@@ -402,15 +463,32 @@ gline_lookup(struct Client *cptr)
   for (gline = GlobalGlineList; gline; gline = sgline) {
     sgline = gline->gl_next;
 
-    if (gline->gl_expire <= TStime())
+    if (gline->gl_expire <= CurrentTime) {
       gline_free(gline);
-    else if ((GlineIsIpMask(gline) ?
-             match(gline->gl_host, ircd_ntoa((const char *)&cptr->ip)) :
-             match(gline->gl_host, cptr->user->host)) == 0 &&
-            match(gline->gl_user, cptr->user->username) == 0)
-      return gline;
+      continue;
+    }
+    
+    if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+            (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+      continue;
+     
+    if (match(gline->gl_user, cptr->user->username) != 0)
+      continue;
+        
+    if (GlineIsIpMask(gline)) {
+      Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",cptr->ip.s_addr,gline->ipnum.s_addr,gline->bits));
+      if ((cptr->ip.s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+        continue;
+    }
+    else {
+      if (match(gline->gl_host, cptr->user->host) != 0) 
+        continue;
+    }
+    return gline;
   }
-
+  /*
+   * No Glines matched
+   */
   return 0;
 }
 
@@ -439,11 +517,11 @@ gline_burst(struct Client *cptr)
   for (gline = GlobalGlineList; gline; gline = sgline) { /* all glines */
     sgline = gline->gl_next;
 
-    if (gline->gl_expire <= TStime()) /* expire any that need expiring */
+    if (gline->gl_expire <= CurrentTime) /* expire any that need expiring */
       gline_free(gline);
     else if (!GlineIsLocal(gline) && gline->gl_lastmod)
-      sendcmdto_one(cptr, CMD_GLINE, &me, "* %c%s@%s %Tu %Tu :%s",
-                   GlineIsActive(gline) ? '+' : '-', gline->gl_user,
+      sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s@%s %Tu %Tu :%s",
+                   GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
                    gline->gl_host, gline->gl_expire - CurrentTime,
                    gline->gl_lastmod, gline->gl_reason);
   }
@@ -451,11 +529,11 @@ gline_burst(struct Client *cptr)
   for (gline = BadChanGlineList; gline; gline = sgline) { /* all glines */
     sgline = gline->gl_next;
 
-    if (gline->gl_expire <= TStime()) /* expire any that need expiring */
+    if (gline->gl_expire <= CurrentTime) /* expire any that need expiring */
       gline_free(gline);
     else if (!GlineIsLocal(gline) && gline->gl_lastmod)
-      sendcmdto_one(cptr, CMD_GLINE, &me, "* %c%s %Tu %Tu :%s",
-                   GlineIsActive(gline) ? '+' : '-', gline->gl_user,
+      sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s %Tu %Tu :%s",
+                   GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
                    gline->gl_expire - CurrentTime, gline->gl_lastmod,
                    gline->gl_reason);
   }
@@ -467,8 +545,8 @@ gline_resend(struct Client *cptr, struct Gline *gline)
   if (GlineIsLocal(gline) || !gline->gl_lastmod)
     return 0;
 
-  sendcmdto_one(cptr, CMD_GLINE, &me, "* %c%s%s%s %Tu %Tu :%s",
-               GlineIsActive(gline) ? '+' : '-', gline->gl_user,
+  sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu :%s",
+               GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
                GlineIsBadChan(gline) ? "" : "@",
                GlineIsBadChan(gline) ? "" : gline->gl_host,
                gline->gl_expire - CurrentTime, gline->gl_lastmod,
@@ -485,23 +563,24 @@ gline_list(struct Client *sptr, char *userhost)
 
   if (userhost) {
     if (!(gline = gline_find(userhost, GLINE_ANY))) /* no such gline */
-      return send_error_to_client(sptr, ERR_NOSUCHGLINE, userhost);
+      return send_reply(sptr, ERR_NOSUCHGLINE, userhost);
 
     /* send gline information along */
-    sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name, gline->gl_user,
+    send_reply(sptr, RPL_GLIST, gline->gl_user,
               GlineIsBadChan(gline) ? "" : "@",
-              GlineIsBadChan(gline) ? "" : gline->gl_host, gline->gl_expire + TSoffset,
+              GlineIsBadChan(gline) ? "" : gline->gl_host,
+              gline->gl_expire + TSoffset,
               GlineIsLocal(gline) ? me.name : "*",
               GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
   } else {
     for (gline = GlobalGlineList; gline; gline = sgline) {
       sgline = gline->gl_next;
 
-      if (gline->gl_expire <= TStime())
+      if (gline->gl_expire <= CurrentTime)
        gline_free(gline);
       else
-       sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name,
-                  gline->gl_user, "@", gline->gl_host, gline->gl_expire + TSoffset,
+       send_reply(sptr, RPL_GLIST, gline->gl_user, "@", gline->gl_host,
+                  gline->gl_expire + TSoffset,
                   GlineIsLocal(gline) ? me.name : "*",
                   GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
     }
@@ -509,19 +588,18 @@ gline_list(struct Client *sptr, char *userhost)
     for (gline = BadChanGlineList; gline; gline = sgline) {
       sgline = gline->gl_next;
 
-      if (gline->gl_expire <= TStime())
+      if (gline->gl_expire <= CurrentTime)
        gline_free(gline);
       else
-       sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name,
-                  gline->gl_user, "", "", gline->gl_expire + TSoffset,
+       send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
+                  gline->gl_expire + TSoffset,
                   GlineIsLocal(gline) ? me.name : "*",
                   GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
     }
   }
 
   /* end of gline information */
-  sendto_one(sptr, rpl_str(RPL_ENDOFGLIST), me.name, sptr->name);
-  return 0;
+  return send_reply(sptr, RPL_ENDOFGLIST);
 }
 
 void
@@ -533,11 +611,10 @@ gline_stats(struct Client *sptr)
   for (gline = GlobalGlineList; gline; gline = sgline) {
     sgline = gline->gl_next;
 
-    if (gline->gl_expire <= TStime())
+    if (gline->gl_expire <= CurrentTime)
       gline_free(gline);
     else
-      sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, sptr->name, 'G',
-                gline->gl_user, gline->gl_host, gline->gl_expire + TSoffset,
-                gline->gl_reason);
+      send_reply(sptr, RPL_STATSGLINE, 'G', gline->gl_user, gline->gl_host,
+                gline->gl_expire + TSoffset, gline->gl_reason);
   }
 }