Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_gline.c
index c2980c187ea536d6ecc0dda8a7b4ba665505f3ae..e1aa27dc0f4bf6f91c8fb1490092b4f705bf3a20 100644 (file)
@@ -79,6 +79,8 @@
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
+#include "config.h"
+
 #if 0
 /*
  * No need to include handlers.h here the signatures must match
@@ -91,6 +93,7 @@
 #include "gline.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_features.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "match.h"
@@ -133,13 +136,13 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   time_t expire_off, lastmod = 0;
   char *mask = parv[2], *target = parv[1], *reason;
 
-  if (parc == 4) {
-    if (!find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD))
+  if ((parc == 3 && *mask == '-') || parc == 5) {
+    if (!find_conf_byhost(cli_confs(cptr), cli_name(sptr), CONF_UWORLD))
       return need_more_params(sptr, "GLINE");
 
     reason = parv[4];
     flags |= GLINE_FORCE;
-  } else if (parc >= 5) {
+  } else if (parc > 5) {
     lastmod = atoi(parv[4]);
     reason = parv[5];
   } else
@@ -150,16 +153,13 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       return 0; /* no such server */
 
     if (!IsMe(acptr)) { /* manually propagate */
-      if (IsServer(sptr)) {
-       if (!lastmod)
-         sendto_one(acptr, "%s " TOK_GLINE " %s %s %s :%s", NumServ(sptr),
-                    target, mask, parv[3], reason);
-       else
-         sendto_one(acptr, "%s " TOK_GLINE " %s %s %s %s :%s", NumServ(sptr),
-                    target, mask, parv[3], parv[4], reason);
-      } else
-       sendto_one(acptr, "%s%s " TOK_GLINE " %s %s %s %s :%s", NumNick(sptr),
-                  target, mask, parv[3], parv[4], reason);
+      if (!lastmod)
+       sendcmdto_one(sptr, CMD_GLINE, acptr,
+                     (parc == 3) ? "%C %s" : "%C %s %s :%s", acptr, mask,
+                     parv[3], reason);
+      else
+       sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s %s %s :%s", acptr, mask,
+                     parv[3], parv[4], reason);
 
       return 0;
     }
@@ -167,31 +167,41 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     flags |= GLINE_LOCAL;
   }
 
-  if (*server == '-')
-    server++;
-  else if (*server == '+') {
+  if (*mask == '-')
+    mask++;
+  else if (*mask == '+') {
     flags |= GLINE_ACTIVE;
-    server++;
+    mask++;
   } else
     flags |= GLINE_ACTIVE;
 
-  expire_off = atoi(parv[3]);
+  expire_off = parc < 5 ? 0 : atoi(parv[3]);
 
-  agline = gline_find(mask, GLINE_ANY);
+  agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
 
   if (agline) {
     if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */
       gline_free(agline);
+    else if (!lastmod && ((flags & GLINE_ACTIVE) == GlineIsRemActive(agline)))
+      return gline_propagate(cptr, sptr, agline);
     else if (!lastmod || GlineLastMod(agline) < lastmod) { /* new mod */
       if (flags & GLINE_ACTIVE)
-       return gline_activate(cptr, sptr, agline, lastmod);
+       return gline_activate(cptr, sptr, agline, lastmod, flags);
       else
-       return gline_deactivate(cptr, sptr, agline, lastmod);
-    } else if (GlineLastMod(agline) == lastmod)
+       return gline_deactivate(cptr, sptr, agline, lastmod, flags);
+    } else if (GlineLastMod(agline) == lastmod || IsBurstOrBurstAck(cptr))
       return 0;
     else
       return gline_resend(cptr, agline); /* other server desynched WRT gline */
-  }
+  } else if (parc == 3 && !(flags & GLINE_ACTIVE)) {
+    /* U-lined server removing a G-line we don't have; propagate the removal
+     * anyway.
+     */
+    if (!(flags & GLINE_LOCAL))
+      sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* -%s", mask);
+    return 0;
+  } else if (parc < 5)
+    return need_more_params(sptr, "GLINE");
 
   return gline_add(cptr, sptr, mask, reason, expire_off, lastmod, flags);
 }
@@ -202,12 +212,12 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
  * parv[0] = Sender prefix
  * parv[1] = [[+|-]<G-line mask>]
  *
- * Old style:
+ * Local (to me) style:
  *
  * parv[2] = [Expiration offset]
  * parv[3] = [Comment]
  *
- * New style:
+ * Global (or remote local) style:
  *
  * parv[2] = [target]
  * parv[3] = [Expiration offset]
@@ -229,23 +239,17 @@ mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   if (*mask == '+') {
     flags |= GLINE_ACTIVE;
     mask++;
+
   } else if (*mask == '-')
     mask++;
   else
     return gline_list(sptr, mask);
 
-#ifndef LOCOP_LGLINE
-  if (!IsOper(sptr)) {
-    send_error_to_client(sptr, ERR_NOPRIVILEGES);
-    return 0;
-  }
-#endif
-
-  if (parc == 3) {
+  if (parc == 4) {
     expire_off = atoi(parv[2]);
     reason = parv[3];
     flags |= GLINE_LOCAL;
-  } else if (parc >= 4) {
+  } else if (parc > 4) {
     target = parv[2];
     expire_off = atoi(parv[3]);
     reason = parv[4];
@@ -254,41 +258,46 @@ mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
   if (target) {
     if (!(target[0] == '*' && target[1] == '\0')) {
-      if (!(acptr = find_match_server(target))) {
-       send_error_to_client(sptr, ERR_NOSUCHSERVER, target);
-       return 0;
-      }
+      if (!(acptr = find_match_server(target)))
+       return send_reply(sptr, ERR_NOSUCHSERVER, target);
 
       if (!IsMe(acptr)) { /* manually propagate, since we don't set it */
-       if (!IsOper(sptr)) {
-         send_error_to_client(sptr, ERR_NOPRIVILEGES);
-         return 0;
-       }
+       if (!feature_bool(FEAT_CONFIG_OPERCMDS))
+         return send_reply(sptr, ERR_DISABLED, "GLINE");
 
-       sendto_one(acptr, "%s%s " TOK_GLINE " %s %c%s %s " TIME_T_FMT " :%s",
-                  NumNick(sptr), NumServ(acptr),
-                  flags & GLINE_ACTIVE ? '?' : '-', mask, parv[3], TStime(),
-                  reason);
+       if (!HasPriv(sptr, PRIV_GLINE))
+         return send_reply(sptr, ERR_NOPRIVILEGES);
+
+       sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %c%s %s %Tu :%s", acptr,
+                     flags & GLINE_ACTIVE ? '+' : '-', mask, parv[3],
+                     TStime(), reason);
        return 0;
-      }
+      } else if (!HasPriv(sptr, PRIV_LOCAL_GLINE))
+       return send_reply(sptr, ERR_NOPRIVILEGES);
 
       flags |= GLINE_LOCAL;
-    } else if (!IsOper(sptr)) {
-      send_error_to_client(sptr, ERR_NOPRIVILEGES);
-      return 0;
-    }
+    } else if (!HasPriv(sptr, PRIV_GLINE))
+      return send_reply(sptr, ERR_NOPRIVILEGES);
   }
 
-  agline = gline_find(mask, GLINE_ANY);
+  if (!(flags & GLINE_LOCAL) && !feature_bool(FEAT_CONFIG_OPERCMDS))
+    return send_reply(sptr, ERR_DISABLED, "GLINE");
+
+  agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
 
   if (agline) {
     if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */
       gline_free(agline);
     else {
+      if (!GlineLastMod(agline)) /* force mods to Uworld-set G-lines local */
+       flags |= GLINE_LOCAL;
+
       if (flags & GLINE_ACTIVE)
-       return gline_activate(cptr, sptr, agline, TStime());
+       return gline_activate(cptr, sptr, agline,
+                             GlineLastMod(agline) ? TStime() : 0, flags);
       else
-       return gline_deactivate(cptr, sptr, agline, TStime());
+       return gline_deactivate(cptr, sptr, agline,
+                               GlineLastMod(agline) ? TStime() : 0, flags);
     }
   }
 
@@ -306,1034 +315,7 @@ int
 m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 {
   if (parc < 2)
-    return gline_list(sptr, 0);
+    return send_reply(sptr, ERR_NOSUCHGLINE, "");
 
   return gline_list(sptr, parv[1]);
 }
-
-#if 0
-/*
- * ms_gline - server message handler
- *
- * parv[0] = Send prefix
- *
- * From server:
- *
- * parv[1] = Target: server numeric
- * parv[2] = [+|-]<G-line mask>
- * parv[3] = Expiration offset
- * parv[4] = Comment
- *
- * From client:
- *
- * parv[1] = [+|-]<G-line mask>
- * parv[2] = Expiration offset
- * parv[3] = Comment
- *
- */
-int ms_gline(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
-{
-  struct Client* acptr = 0;  /* Init. to avoid compiler warning. */
-  struct Gline*  gline;
-  struct Gline*  prev;
-  char*          user;
-  char*          host;
-  int            active;
-  int            ip_mask;
-  int            gtype = 0;
-  time_t         expire = 0;
-
-  /*
-   * Remove expired G-lines
-   */
-  gline_remove_expired(TStime());
-#ifdef BADCHAN
-  /*
-   * Remove expired bad channels
-   */
-  bad_channel_remove_expired(TStime());
-#endif
-
-  if (IsServer(cptr)) {
-    if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) {
-      if (parc < 3 || (*parv[2] != '-' && (parc < 5 || *parv[4] == '\0')))
-        return need_more_params(sptr, "GLINE");
-
-      if (*parv[2] == '-') /* add mode or delete mode? */
-        active = 0;
-      else
-        active = 1;
-
-      if (*parv[2] == '+' || *parv[2] == '-')
-        parv[2]++; /* step past mode indicator */
-
-      /*
-       * forward the message appropriately
-       */
-      if (0 == ircd_strcmp(parv[1], "*")) {
-        /*
-         * global!
-         */
-        sendto_serv_butone(cptr,
-                     active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
-                     NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
-      }
-      else if ((
-#if 1
-          /*
-           * REMOVE THIS after all servers upgraded to 2.10.01 and
-           * Uworld uses a numeric too
-           */
-          (strlen(parv[1]) != 1 && !(acptr = FindClient(parv[1])))) ||
-          (strlen(parv[1]) == 1 &&
-#endif
-          !(acptr = FindNServer(parv[1]))))
-        return 0;               /* no such server/user exists; forget it */
-      else
-#if 1
-/*
- * REMOVE THIS after all servers upgraded to 2.10.01 and
- * Uworld uses a numeric too
- */
-      if (IsServer(acptr) || !MyConnect(acptr))
-#endif
-      {
-        /* single destination */
-        sendto_one(acptr,
-               active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
-               NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
-        return 0;               /* only the intended  destination
-                                   should add this gline */
-      }
-
-      if (!(host = strchr(parv[2], '@'))) {
-        /*
-         * convert user@host no @'s; assume username is '*'
-         */
-        user = "*";     
-        host = parv[2];
-      }
-      else {
-        user = parv[2];
-        *(host++) = '\0';       /* break up string at the '@' */
-      }
-      ip_mask = check_if_ipmask(host);  /* Store this boolean */
-#ifdef BADCHAN
-      if ('#' == *host || '&' == *host || '+' == *host)
-         gtype = 1;                /* BAD CHANNEL GLINE */
-#endif
-      for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
-           gline = gline->next)
-      {
-        if (0 == ircd_strcmp(gline->name, user) &&
-            0 == ircd_strcmp(gline->host, host))
-          break;
-        prev = gline;
-      }
-
-      if (!active && gline)
-      {
-        /*
-         * removing the gline, notify opers
-         */
-        sendto_op_mask(SNO_GLINE, "%s removing %s for %s@%s", parv[0],
-            gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
-
-#ifdef GPATH
-       write_log(GPATH, "# " TIME_T_FMT " %s removing %s for %s@%s\n",
-           TStime(), parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, 
-            gline->host);
-#endif /* GPATH */
-
-        free_gline(gline, prev);        /* remove the gline */
-      }
-      else if (active)
-      {                         /* must be adding a gline */
-        expire = atoi(parv[3]) + TStime();      /* expire time? */
-        if (gline && gline->expire < expire)
-        {                       /* new expire time? */
-          /* yes, notify the opers */
-          sendto_op_mask(SNO_GLINE,
-             "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
-             parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host, 
-             expire);
-#ifdef GPATH
-          write_log(GPATH, "# " TIME_T_FMT " %s resetting expiration time "
-              "on %s for %s@%s to " TIME_T_FMT "\n",
-              TStime(), parv[0], gtype ? "BADCHAN" : "GLINE",
-              gline->name, gline->host, expire);
-#endif /* GPATH */
-
-          gline->expire = expire;       /* reset the expire time */
-        }
-        else if (!gline)
-        {                       /* create gline */
-          for (gline = (gtype) ? BadChanGlineList : GlobalGlineList; gline; gline = gline->next)
-            if (!mmatch(gline->name, user) &&
-                (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
-                !mmatch(gline->host, host))
-              return 0;         /* found an existing G-line that matches */
-
-          /* add the line: */
-          add_gline(sptr, ip_mask, host, parv[4], user, expire, 0);
-        }
-      }
-    }
-  }
-  else if (parc < 2 || *parv[1] == '\0')
-  {
-    /* Not enough args and a user; list glines */
-    for (gline = GlobalGlineList; gline; gline = gline->next)
-      sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0],
-          gline->name, gline->host, gline->expire, gline->reason,
-          GlineIsActive(gline) ? (GlineIsLocal(gline) ? " (local)" : "") :
-          " (Inactive)");
-    sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
-  }
-  else
-  {
-    int priv;
-
-#ifdef LOCOP_LGLINE
-    priv = IsAnOper(cptr);
-#else
-    priv = IsOper(cptr);
-#endif
-
-    if (priv)
-    {                           /* non-oper not permitted to change things */
-      if (*parv[1] == '-')
-      {                         /* oper wants to deactivate the gline */
-        active = 0;
-        parv[1]++;
-      }
-      else if (*parv[1] == '+')
-      {                         /* oper wants to activate inactive gline */
-        active = 1;
-        parv[1]++;
-      }
-      else
-        active = -1;
-
-      if (parc > 2)
-        expire = atoi(parv[2]) + TStime();      /* oper wants to reset
-                                                   expire TS */
-    }
-    else
-      active = -1;
-
-    if (!(host = strchr(parv[1], '@')))
-    {
-      user = "*";               /* no @'s; assume username is '*' */
-      host = parv[1];
-    }
-    else
-    {
-      user = parv[1];
-      *(host++) = '\0';         /* break up string at the '@' */
-    }
-    ip_mask = check_if_ipmask(host);    /* Store this boolean */
-#ifdef BADCHAN
-    if ('#' == *host || '&' == *host || '+' == *host)
-#ifndef LOCAL_BADCHAN
-     return 0;
-#else
-     gtype = 1;  /* BAD CHANNEL */
-#endif
-#endif
-
-    for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
-         gline = gline->next)
-    {
-      if (!mmatch(gline->name, user) &&
-          (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
-          !mmatch(gline->host, host))
-        break;
-      prev = gline;
-    }
-
-    if (!gline)
-    {
-#ifdef OPER_LGLINE
-      if (priv && active && expire > CurrentTime)
-      {
-        /* Add local G-line */
-        if (parc < 4 || !strchr(parv[3], ' '))
-          return need_more_params(sptr, "GLINE");
-
-        add_gline(sptr, ip_mask, host, parv[3], user, expire, 1);
-      }
-      else
-#endif
-        sendto_one(cptr, err_str(ERR_NOSUCHGLINE), me.name, parv[0], user,
-            host);
-
-      return 0;
-    }
-
-    if (expire <= gline->expire)
-      expire = 0;
-
-    if ((active == -1 ||
-        (active ? GlineIsActive(gline) : !GlineIsActive(gline))) &&
-        expire == 0)
-    {
-      /* oper wants a list of one gline only */
-      sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0], gline->name,
-          gline->host, gline->expire, gline->reason,
-          GlineIsActive(gline) ? "" : " (Inactive)");
-      sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
-      return 0;
-    }
-
-    if (active != -1 &&
-        (active ? !GlineIsActive(gline) : GlineIsActive(gline)))
-    {
-      if (active)               /* reset activation on gline */
-        SetActive(gline);
-#ifdef OPER_LGLINE
-      else if (GlineIsLocal(gline))
-      {
-        /* Remove local G-line */
-        sendto_op_mask(SNO_GLINE, "%s removed local %s for %s@%s",
-            parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
-#ifdef GPATH
-        write_log(GPATH, "# " TIME_T_FMT
-            " %s!%s@%s removed local %s for %s@%s\n",
-            TStime(), parv[0], cptr->user->username, cptr->user->host,
-            gtype ? "BADCHAN" : "GLINE",
-            gline->name, gline->host);
-#endif /* GPATH */
-        free_gline(gline, prev);        /* remove the gline */
-        return 0;
-      }
-#endif
-      else
-        ClearActive(gline);
-    }
-    else
-      active = -1;              /* for later sendto_ops and logging functions */
-
-    if (expire)
-      gline->expire = expire;   /* reset expiration time */
-
-    /* inform the operators what's up */
-    if (active != -1)
-    {                           /* changing the activation */
-       sendto_op_mask(SNO_GLINE, !expire ? "%s %sactivating %s for %s@%s" :
-          "%s %sactivating %s for %s@%s and "
-          "resetting expiration time to " TIME_T_FMT,
-          parv[0], active ? "re" : "de", gtype ? "BADCHAN" : "GLINE",
-          gline->name, gline->host, gline->expire);
-#ifdef GPATH
-      write_log(GPATH, !expire ? "# " TIME_T_FMT " %s!%s@%s %sactivating "
-          "%s for %s@%s\n" : "# " TIME_T_FMT " %s!%s@%s %sactivating %s "
-          "for %s@%s and resetting expiration time to " TIME_T_FMT "\n",
-          TStime(), parv[0], cptr->user->username, cptr->user->host,
-          active ? "re" : "de", gtype ? "BADCHAN" : "GLINE", gline->name, 
-          gline->host, gline->expire);
-#endif /* GPATH */
-
-    }
-    else if (expire)
-    {                           /* changing only the expiration */
-      sendto_op_mask(SNO_GLINE,
-          "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
-          parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host, 
-          gline->expire);
-#ifdef GPATH
-      write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s resetting expiration "
-          "time on %s for %s@%s to " TIME_T_FMT "\n", TStime(), parv[0],
-          cptr->user->username, cptr->user->host, gtype ? "BADCHAN" : "GLINE",
-          gline->name, gline->host, gline->expire);
-#endif /* GPATH */
-    }
-  }
-  return 0;
-}
-
-/*
- * mo_gline - oper message handler
- *
- * parv[0] = Send prefix
- *
- * From server:
- *
- * parv[1] = Target: server numeric
- * parv[2] = [+|-]<G-line mask>
- * parv[3] = Expiration offset
- * parv[4] = Comment
- *
- * From client:
- *
- * parv[1] = [+|-]<G-line mask>
- * parv[2] = Expiration offset
- * parv[3] = Comment
- *
- */
-int mo_gline(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
-{
-  struct Client* acptr = 0;  /* Init. to avoid compiler warning. */
-  struct Gline*  gline;
-  struct Gline*  prev;
-  char*          user;
-  char*          host;
-  int            active;
-  int            ip_mask;
-  int            gtype = 0;
-  time_t         expire = 0;
-
-  /*
-   * Remove expired G-lines
-   */
-  gline_remove_expired(TStime());
-#ifdef BADCHAN
-  /*
-   * Remove expired bad channels
-   */
-  bad_channel_remove_expired(TStime());
-#endif
-
-  if (IsServer(cptr)) {
-    if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) {
-      if (parc < 3 || (*parv[2] != '-' && (parc < 5 || *parv[4] == '\0')))
-        return need_more_params(sptr, "GLINE");
-
-      if (*parv[2] == '-') /* add mode or delete mode? */
-        active = 0;
-      else
-        active = 1;
-
-      if (*parv[2] == '+' || *parv[2] == '-')
-        parv[2]++; /* step past mode indicator */
-
-      /*
-       * forward the message appropriately
-       */
-      if (0 == ircd_strcmp(parv[1], "*")) {
-        /*
-         * global!
-         */
-        sendto_serv_butone(cptr,
-                     active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
-                     NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
-      }
-      else if ((
-#if 1
-          /*
-           * REMOVE THIS after all servers upgraded to 2.10.01 and
-           * Uworld uses a numeric too
-           */
-          (strlen(parv[1]) != 1 && !(acptr = FindClient(parv[1])))) ||
-          (strlen(parv[1]) == 1 &&
-#endif
-          !(acptr = FindNServer(parv[1]))))
-        return 0;               /* no such server/user exists; forget it */
-      else
-#if 1
-/*
- * REMOVE THIS after all servers upgraded to 2.10.01 and
- * Uworld uses a numeric too
- */
-      if (IsServer(acptr) || !MyConnect(acptr))
-#endif
-      {
-        /* single destination */
-        sendto_one(acptr,
-               active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
-               NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
-        return 0;               /* only the intended  destination
-                                   should add this gline */
-      }
-
-      if (!(host = strchr(parv[2], '@'))) {
-        /*
-         * convert user@host no @'s; assume username is '*'
-         */
-        user = "*";     
-        host = parv[2];
-      }
-      else {
-        user = parv[2];
-        *(host++) = '\0';       /* break up string at the '@' */
-      }
-      ip_mask = check_if_ipmask(host);  /* Store this boolean */
-#ifdef BADCHAN
-      if ('#' == *host || '&' == *host || '+' == *host)
-         gtype = 1;                /* BAD CHANNEL GLINE */
-#endif
-      for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
-           gline = gline->next)
-      {
-        if (0 == ircd_strcmp(gline->name, user) &&
-            0 == ircd_strcmp(gline->host, host))
-          break;
-        prev = gline;
-      }
-
-      if (!active && gline)
-      {
-        /*
-         * removing the gline, notify opers
-         */
-        sendto_op_mask(SNO_GLINE, "%s removing %s for %s@%s", parv[0],
-            gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
-
-#ifdef GPATH
-       write_log(GPATH, "# " TIME_T_FMT " %s removing %s for %s@%s\n",
-           TStime(), parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, 
-            gline->host);
-#endif /* GPATH */
-
-        free_gline(gline, prev);        /* remove the gline */
-      }
-      else if (active)
-      {                         /* must be adding a gline */
-        expire = atoi(parv[3]) + TStime();      /* expire time? */
-        if (gline && gline->expire < expire)
-        {                       /* new expire time? */
-          /* yes, notify the opers */
-          sendto_op_mask(SNO_GLINE,
-             "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
-             parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host, 
-             expire);
-#ifdef GPATH
-          write_log(GPATH, "# " TIME_T_FMT " %s resetting expiration time "
-              "on %s for %s@%s to " TIME_T_FMT "\n",
-              TStime(), parv[0], gtype ? "BADCHAN" : "GLINE",
-              gline->name, gline->host, expire);
-#endif /* GPATH */
-
-          gline->expire = expire;       /* reset the expire time */
-        }
-        else if (!gline)
-        {                       /* create gline */
-          for (gline = (gtype) ? BadChanGlineList : GlobalGlineList; gline; gline = gline->next)
-            if (!mmatch(gline->name, user) &&
-                (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
-                !mmatch(gline->host, host))
-              return 0;         /* found an existing G-line that matches */
-
-          /* add the line: */
-          add_gline(sptr, ip_mask, host, parv[4], user, expire, 0);
-        }
-      }
-    }
-  }
-  else if (parc < 2 || *parv[1] == '\0')
-  {
-    /* Not enough args and a user; list glines */
-    for (gline = GlobalGlineList; gline; gline = gline->next)
-      sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0],
-          gline->name, gline->host, gline->expire, gline->reason,
-          GlineIsActive(gline) ? (GlineIsLocal(gline) ? " (local)" : "") :
-          " (Inactive)");
-    sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
-  }
-  else
-  {
-    int priv;
-
-#ifdef LOCOP_LGLINE
-    priv = IsAnOper(cptr);
-#else
-    priv = IsOper(cptr);
-#endif
-
-    if (priv)
-    {                           /* non-oper not permitted to change things */
-      if (*parv[1] == '-')
-      {                         /* oper wants to deactivate the gline */
-        active = 0;
-        parv[1]++;
-      }
-      else if (*parv[1] == '+')
-      {                         /* oper wants to activate inactive gline */
-        active = 1;
-        parv[1]++;
-      }
-      else
-        active = -1;
-
-      if (parc > 2)
-        expire = atoi(parv[2]) + TStime();      /* oper wants to reset
-                                                   expire TS */
-    }
-    else
-      active = -1;
-
-    if (!(host = strchr(parv[1], '@')))
-    {
-      user = "*";               /* no @'s; assume username is '*' */
-      host = parv[1];
-    }
-    else
-    {
-      user = parv[1];
-      *(host++) = '\0';         /* break up string at the '@' */
-    }
-    ip_mask = check_if_ipmask(host);    /* Store this boolean */
-#ifdef BADCHAN
-    if ('#' == *host || '&' == *host || '+' == *host)
-#ifndef LOCAL_BADCHAN
-     return 0;
-#else
-     gtype = 1;  /* BAD CHANNEL */
-#endif
-#endif
-
-    for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
-         gline = gline->next)
-    {
-      if (!mmatch(gline->name, user) &&
-          (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
-          !mmatch(gline->host, host))
-        break;
-      prev = gline;
-    }
-
-    if (!gline)
-    {
-#ifdef OPER_LGLINE
-      if (priv && active && expire > CurrentTime)
-      {
-        /* Add local G-line */
-        if (parc < 4 || !strchr(parv[3], ' '))
-          return need_more_params(sptr, "GLINE");
-
-        add_gline(sptr, ip_mask, host, parv[3], user, expire, 1);
-      }
-      else
-#endif
-        sendto_one(cptr, err_str(ERR_NOSUCHGLINE), me.name, parv[0], user,
-            host);
-
-      return 0;
-    }
-
-    if (expire <= gline->expire)
-      expire = 0;
-
-    if ((active == -1 ||
-        (active ? GlineIsActive(gline) : !GlineIsActive(gline))) &&
-        expire == 0)
-    {
-      /* oper wants a list of one gline only */
-      sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0], gline->name,
-          gline->host, gline->expire, gline->reason,
-          GlineIsActive(gline) ? "" : " (Inactive)");
-      sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
-      return 0;
-    }
-
-    if (active != -1 &&
-        (active ? !GlineIsActive(gline) : GlineIsActive(gline)))
-    {
-      if (active)               /* reset activation on gline */
-        SetActive(gline);
-#ifdef OPER_LGLINE
-      else if (GlineIsLocal(gline))
-      {
-        /* Remove local G-line */
-        sendto_op_mask(SNO_GLINE, "%s removed local %s for %s@%s",
-            parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
-#ifdef GPATH
-        write_log(GPATH, "# " TIME_T_FMT
-            " %s!%s@%s removed local %s for %s@%s\n",
-            TStime(), parv[0], cptr->user->username, cptr->user->host,
-            gtype ? "BADCHAN" : "GLINE",
-            gline->name, gline->host);
-#endif /* GPATH */
-        free_gline(gline, prev);        /* remove the gline */
-        return 0;
-      }
-#endif
-      else
-        ClearActive(gline);
-    }
-    else
-      active = -1;              /* for later sendto_ops and logging functions */
-
-    if (expire)
-      gline->expire = expire;   /* reset expiration time */
-
-    /* inform the operators what's up */
-    if (active != -1)
-    {                           /* changing the activation */
-       sendto_op_mask(SNO_GLINE, !expire ? "%s %sactivating %s for %s@%s" :
-          "%s %sactivating %s for %s@%s and "
-          "resetting expiration time to " TIME_T_FMT,
-          parv[0], active ? "re" : "de", gtype ? "BADCHAN" : "GLINE",
-          gline->name, gline->host, gline->expire);
-#ifdef GPATH
-      write_log(GPATH, !expire ? "# " TIME_T_FMT " %s!%s@%s %sactivating "
-          "%s for %s@%s\n" : "# " TIME_T_FMT " %s!%s@%s %sactivating %s "
-          "for %s@%s and resetting expiration time to " TIME_T_FMT "\n",
-          TStime(), parv[0], cptr->user->username, cptr->user->host,
-          active ? "re" : "de", gtype ? "BADCHAN" : "GLINE", gline->name, 
-          gline->host, gline->expire);
-#endif /* GPATH */
-
-    }
-    else if (expire)
-    {                           /* changing only the expiration */
-      sendto_op_mask(SNO_GLINE,
-          "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
-          parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host, 
-          gline->expire);
-#ifdef GPATH
-      write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s resetting expiration "
-          "time on %s for %s@%s to " TIME_T_FMT "\n", TStime(), parv[0],
-          cptr->user->username, cptr->user->host, gtype ? "BADCHAN" : "GLINE",
-          gline->name, gline->host, gline->expire);
-#endif /* GPATH */
-    }
-  }
-  return 0;
-}
-
-
-#if 0
-/*
- * m_gline
- *
- * parv[0] = Send prefix
- *
- * From server:
- *
- * parv[1] = Target: server numeric
- * parv[2] = [+|-]<G-line mask>
- * parv[3] = Expiration offset
- * parv[4] = Comment
- *
- * From client:
- *
- * parv[1] = [+|-]<G-line mask>
- * parv[2] = Expiration offset
- * parv[3] = Comment
- *
- */
-int m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
-  struct Client* acptr = 0;  /* Init. to avoid compiler warning. */
-  struct Gline*  gline;
-  struct Gline*  prev;
-  char*          user;
-  char*          host;
-  int            active;
-  int            ip_mask;
-  int            gtype = 0;
-  time_t         expire = 0;
-
-  /*
-   * Remove expired G-lines
-   */
-  gline_remove_expired(TStime());
-#ifdef BADCHAN
-  /*
-   * Remove expired bad channels
-   */
-  bad_channel_remove_expired(TStime());
-#endif
-
-  if (IsServer(cptr)) {
-    if (find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)) {
-      if (parc < 3 || (*parv[2] != '-' && (parc < 5 || *parv[4] == '\0')))
-        return need_more_params(sptr, "GLINE");
-
-      if (*parv[2] == '-') /* add mode or delete mode? */
-        active = 0;
-      else
-        active = 1;
-
-      if (*parv[2] == '+' || *parv[2] == '-')
-        parv[2]++; /* step past mode indicator */
-
-      /*
-       * forward the message appropriately
-       */
-      if (0 == ircd_strcmp(parv[1], "*")) {
-        /*
-         * global!
-         */
-        sendto_serv_butone(cptr,
-                     active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
-                     NumServ(cptr), parv[1], parv[2], parv[3], parv[4]);
-      }
-      else if ((
-#if 1
-          /*
-           * REMOVE THIS after all servers upgraded to 2.10.01 and
-           * Uworld uses a numeric too
-           */
-          (strlen(parv[1]) != 1 && !(acptr = FindClient(parv[1])))) ||
-          (strlen(parv[1]) == 1 &&
-#endif
-          !(acptr = FindNServer(parv[1]))))
-        return 0;               /* no such server/user exists; forget it */
-      else
-#if 1
-/*
- * REMOVE THIS after all servers upgraded to 2.10.01 and
- * Uworld uses a numeric too
- */
-      if (IsServer(acptr) || !MyConnect(acptr))
-#endif
-      {
-        /* single destination */
-        sendto_one(acptr,
-               active ? "%s " TOK_GLINE " %s +%s %s :%s" : "%s " TOK_GLINE " %s -%s",
-               NumServ(sptr), parv[1], parv[2], parv[3], parv[4]);
-        return 0;               /* only the intended  destination
-                                   should add this gline */
-      }
-
-      if (!(host = strchr(parv[2], '@'))) {
-        /*
-         * convert user@host no @'s; assume username is '*'
-         */
-        user = "*";     
-        host = parv[2];
-      }
-      else {
-        user = parv[2];
-        *(host++) = '\0';       /* break up string at the '@' */
-      }
-      ip_mask = check_if_ipmask(host);  /* Store this boolean */
-#ifdef BADCHAN
-      if ('#' == *host || '&' == *host || '+' == *host)
-         gtype = 1;                /* BAD CHANNEL GLINE */
-#endif
-      for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
-           gline = gline->next)
-      {
-        if (0 == ircd_strcmp(gline->name, user) &&
-            0 == ircd_strcmp(gline->host, host))
-          break;
-        prev = gline;
-      }
-
-      if (!active && gline)
-      {
-        /*
-         * removing the gline, notify opers
-         */
-        sendto_op_mask(SNO_GLINE, "%s removing %s for %s@%s", parv[0],
-            gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
-
-#ifdef GPATH
-       write_log(GPATH, "# " TIME_T_FMT " %s removing %s for %s@%s\n",
-           TStime(), parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, 
-            gline->host);
-#endif /* GPATH */
-
-        free_gline(gline, prev);        /* remove the gline */
-      }
-      else if (active)
-      {                         /* must be adding a gline */
-        expire = atoi(parv[3]) + TStime();      /* expire time? */
-        if (gline && gline->expire < expire)
-        {                       /* new expire time? */
-          /* yes, notify the opers */
-          sendto_op_mask(SNO_GLINE,
-             "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
-             parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host, 
-             expire);
-#ifdef GPATH
-          write_log(GPATH, "# " TIME_T_FMT " %s resetting expiration time "
-              "on %s for %s@%s to " TIME_T_FMT "\n",
-              TStime(), parv[0], gtype ? "BADCHAN" : "GLINE",
-              gline->name, gline->host, expire);
-#endif /* GPATH */
-
-          gline->expire = expire;       /* reset the expire time */
-        }
-        else if (!gline)
-        {                       /* create gline */
-          for (gline = (gtype) ? BadChanGlineList : GlobalGlineList; gline; gline = gline->next)
-            if (!mmatch(gline->name, user) &&
-                (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
-                !mmatch(gline->host, host))
-              return 0;         /* found an existing G-line that matches */
-
-          /* add the line: */
-          add_gline(sptr, ip_mask, host, parv[4], user, expire, 0);
-        }
-      }
-    }
-  }
-  else if (parc < 2 || *parv[1] == '\0')
-  {
-    /* Not enough args and a user; list glines */
-    for (gline = GlobalGlineList; gline; gline = gline->next)
-      sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0],
-          gline->name, gline->host, gline->expire, gline->reason,
-          GlineIsActive(gline) ? (GlineIsLocal(gline) ? " (local)" : "") :
-          " (Inactive)");
-    sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
-  }
-  else
-  {
-    int priv;
-
-#ifdef LOCOP_LGLINE
-    priv = IsAnOper(cptr);
-#else
-    priv = IsOper(cptr);
-#endif
-
-    if (priv)
-    {                           /* non-oper not permitted to change things */
-      if (*parv[1] == '-')
-      {                         /* oper wants to deactivate the gline */
-        active = 0;
-        parv[1]++;
-      }
-      else if (*parv[1] == '+')
-      {                         /* oper wants to activate inactive gline */
-        active = 1;
-        parv[1]++;
-      }
-      else
-        active = -1;
-
-      if (parc > 2)
-        expire = atoi(parv[2]) + TStime();      /* oper wants to reset
-                                                   expire TS */
-    }
-    else
-      active = -1;
-
-    if (!(host = strchr(parv[1], '@')))
-    {
-      user = "*";               /* no @'s; assume username is '*' */
-      host = parv[1];
-    }
-    else
-    {
-      user = parv[1];
-      *(host++) = '\0';         /* break up string at the '@' */
-    }
-    ip_mask = check_if_ipmask(host);    /* Store this boolean */
-#ifdef BADCHAN
-    if ('#' == *host || '&' == *host || '+' == *host)
-#ifndef LOCAL_BADCHAN
-     return 0;
-#else
-     gtype = 1;  /* BAD CHANNEL */
-#endif
-#endif
-
-    for (gline = (gtype) ? BadChanGlineList : GlobalGlineList, prev = 0; gline;
-         gline = gline->next)
-    {
-      if (!mmatch(gline->name, user) &&
-          (ip_mask ? GlineIsIpMask(gline) : !GlineIsIpMask(gline)) &&
-          !mmatch(gline->host, host))
-        break;
-      prev = gline;
-    }
-
-    if (!gline)
-    {
-#ifdef OPER_LGLINE
-      if (priv && active && expire > CurrentTime)
-      {
-        /* Add local G-line */
-        if (parc < 4 || !strchr(parv[3], ' '))
-          return need_more_params(sptr, "GLINE");
-
-        add_gline(sptr, ip_mask, host, parv[3], user, expire, 1);
-      }
-      else
-#endif
-        sendto_one(cptr, err_str(ERR_NOSUCHGLINE), me.name, parv[0], user,
-            host);
-
-      return 0;
-    }
-
-    if (expire <= gline->expire)
-      expire = 0;
-
-    if ((active == -1 ||
-        (active ? GlineIsActive(gline) : !GlineIsActive(gline))) &&
-        expire == 0)
-    {
-      /* oper wants a list of one gline only */
-      sendto_one(cptr, rpl_str(RPL_GLIST), me.name, parv[0], gline->name,
-          gline->host, gline->expire, gline->reason,
-          GlineIsActive(gline) ? "" : " (Inactive)");
-      sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, parv[0]);
-      return 0;
-    }
-
-    if (active != -1 &&
-        (active ? !GlineIsActive(gline) : GlineIsActive(gline)))
-    {
-      if (active)               /* reset activation on gline */
-        SetActive(gline);
-#ifdef OPER_LGLINE
-      else if (GlineIsLocal(gline))
-      {
-        /* Remove local G-line */
-        sendto_op_mask(SNO_GLINE, "%s removed local %s for %s@%s",
-            parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host);
-#ifdef GPATH
-        write_log(GPATH, "# " TIME_T_FMT
-            " %s!%s@%s removed local %s for %s@%s\n",
-            TStime(), parv[0], cptr->user->username, cptr->user->host,
-            gtype ? "BADCHAN" : "GLINE",
-            gline->name, gline->host);
-#endif /* GPATH */
-        free_gline(gline, prev);        /* remove the gline */
-        return 0;
-      }
-#endif
-      else
-        ClearActive(gline);
-    }
-    else
-      active = -1;              /* for later sendto_ops and logging functions */
-
-    if (expire)
-      gline->expire = expire;   /* reset expiration time */
-
-    /* inform the operators what's up */
-    if (active != -1)
-    {                           /* changing the activation */
-       sendto_op_mask(SNO_GLINE, !expire ? "%s %sactivating %s for %s@%s" :
-          "%s %sactivating %s for %s@%s and "
-          "resetting expiration time to " TIME_T_FMT,
-          parv[0], active ? "re" : "de", gtype ? "BADCHAN" : "GLINE",
-          gline->name, gline->host, gline->expire);
-#ifdef GPATH
-      write_log(GPATH, !expire ? "# " TIME_T_FMT " %s!%s@%s %sactivating "
-          "%s for %s@%s\n" : "# " TIME_T_FMT " %s!%s@%s %sactivating %s "
-          "for %s@%s and resetting expiration time to " TIME_T_FMT "\n",
-          TStime(), parv[0], cptr->user->username, cptr->user->host,
-          active ? "re" : "de", gtype ? "BADCHAN" : "GLINE", gline->name, 
-          gline->host, gline->expire);
-#endif /* GPATH */
-
-    }
-    else if (expire)
-    {                           /* changing only the expiration */
-      sendto_op_mask(SNO_GLINE,
-          "%s resetting expiration time on %s for %s@%s to " TIME_T_FMT,
-          parv[0], gtype ? "BADCHAN" : "GLINE", gline->name, gline->host, 
-          gline->expire);
-#ifdef GPATH
-      write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s resetting expiration "
-          "time on %s for %s@%s to " TIME_T_FMT "\n", TStime(), parv[0],
-          cptr->user->username, cptr->user->host, gtype ? "BADCHAN" : "GLINE",
-          gline->name, gline->host, gline->expire);
-#endif /* GPATH */
-    }
-  }
-  return 0;
-}
-
-#endif /* 0 */
-
-#endif /* 0 */