Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_gline.c
index 7d1c69535dcccf8025ab48dfe59c2b6d3e3fb22c..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,8 +136,8 @@ 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 == 5) {
-    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];
@@ -151,10 +154,11 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
     if (!IsMe(acptr)) { /* manually propagate */
       if (!lastmod)
-       sendcmdto_one(acptr, CMD_GLINE, sptr, "%s %s %s :%s", target, mask,
+       sendcmdto_one(sptr, CMD_GLINE, acptr,
+                     (parc == 3) ? "%C %s" : "%C %s %s :%s", acptr, mask,
                      parv[3], reason);
       else
-       sendcmdto_one(acptr, CMD_GLINE, sptr, "%s %s %s %s :%s", target, mask,
+       sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s %s %s :%s", acptr, mask,
                      parv[3], parv[4], reason);
 
       return 0;
@@ -171,23 +175,33 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   } else
     flags |= GLINE_ACTIVE;
 
-  expire_off = atoi(parv[3]);
+  expire_off = parc < 5 ? 0 : atoi(parv[3]);
 
   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);
 }
@@ -198,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]
@@ -225,18 +239,12 @@ 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 == 4) {
     expire_off = atoi(parv[2]);
     reason = parv[3];
@@ -251,27 +259,29 @@ 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)))
-       return send_error_to_client(sptr, ERR_NOSUCHSERVER, target);
+       return send_reply(sptr, ERR_NOSUCHSERVER, target);
 
       if (!IsMe(acptr)) { /* manually propagate, since we don't set it */
-       if (!IsOper(sptr))
-         return send_error_to_client(sptr, ERR_NOPRIVILEGES);
+       if (!feature_bool(FEAT_CONFIG_OPERCMDS))
+         return send_reply(sptr, ERR_DISABLED, "GLINE");
 
-       sendcmdto_one(acptr, CMD_GLINE, sptr, "%C %c%s %s %Tu :%s", acptr,
-                     flags & GLINE_ACTIVE ? '?' : '-', mask, parv[3],
+       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))
-      return send_error_to_client(sptr, ERR_NOPRIVILEGES);
+    } else if (!HasPriv(sptr, PRIV_GLINE))
+      return send_reply(sptr, ERR_NOPRIVILEGES);
   }
 
-#ifndef CONFIG_OPERCMDS
-  if (!(flags & GLINE_LOCAL))
-    return send_error_to_client(sptr, ERR_DISABLED, "GLINE");
-#endif /* CONFIG_OPERCMDS */
+  if (!(flags & GLINE_LOCAL) && !feature_bool(FEAT_CONFIG_OPERCMDS))
+    return send_reply(sptr, ERR_DISABLED, "GLINE");
 
   agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
 
@@ -279,12 +289,15 @@ mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     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,
-                             GlineLastMod(agline) ? TStime() : 0);
+                             GlineLastMod(agline) ? TStime() : 0, flags);
       else
        return gline_deactivate(cptr, sptr, agline,
-                               GlineLastMod(agline) ? TStime() : 0);
+                               GlineLastMod(agline) ? TStime() : 0, flags);
     }
   }
 
@@ -302,7 +315,7 @@ int
 m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 {
   if (parc < 2)
-    return send_error_to_client(sptr, ERR_NOSUCHGLINE, "");
+    return send_reply(sptr, ERR_NOSUCHGLINE, "");
 
   return gline_list(sptr, parv[1]);
 }