Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / gline.c
index 3de628d19ad5d13a975ef3e1ce6d61b36494ea28..7f0186ff9c5cd53b38664bc725ce66b945b5b0b6 100644 (file)
  *
  * $Id$
  */
+#include "config.h"
+
 #include "gline.h"
 #include "client.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "match.h"
@@ -164,20 +167,20 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
      * get the users!
      */
     if ((acptr = LocalClientArray[fd])) {
-      if (!acptr->user)
+      if (!cli_user(acptr))
        continue;
        
-      if (acptr->user->username && 
-          match (gline->gl_user, acptr->user->username) != 0)
+      if (cli_user(acptr)->username && 
+          match (gline->gl_user, (cli_user(acptr))->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 ((acptr->ip.s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+        Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",(cli_ip(cptr)).s_addr,gline->ipnum.s_addr,gline->bits));
+        if (((cli_ip(acptr)).s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
           continue;
       }
       else {
-        if (match(gline->gl_host, acptr->sockhost) != 0)
+        if (match(gline->gl_host, cli_sockhost(acptr)) != 0)
           continue;
       }
 
@@ -187,7 +190,7 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
 
       /* let the ops know about it */
       sendto_opmask_butone(0, SNO_GLINE, "G-line active for %s",
-                    get_client_name(acptr, FALSE));
+                    get_client_name(acptr, TRUE));
 
       /* and get rid of him */
       if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)",
@@ -198,11 +201,11 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
   return retval;
 }
 
-static void
-propagate_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
+int
+gline_propagate(struct Client *cptr, struct Client *sptr, struct Gline *gline)
 {
   if (GlineIsLocal(gline) || (IsUser(sptr) && !gline->gl_lastmod))
-    return;
+    return 0;
 
   if (gline->gl_lastmod)
     sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu :%s",
@@ -212,11 +215,14 @@ propagate_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
                          gline->gl_expire - CurrentTime, gline->gl_lastmod,
                          gline->gl_reason);
   else
-    sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s %Tu :%s",
-                         GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
-                         GlineIsBadChan(gline) ? "" : "@",
+    sendcmdto_serv_butone(sptr, CMD_GLINE, cptr,
+                         (GlineIsRemActive(gline) ?
+                          "* +%s%s%s %Tu :%s" : "* -%s%s%s"),
+                         gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
                          GlineIsBadChan(gline) ? "" : gline->gl_host,
                          gline->gl_expire - CurrentTime, gline->gl_reason);
+
+  return 0;
 }
 
 int 
@@ -246,28 +252,26 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
       || userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+'
 # endif /* OLD_GLINE */
       ) {
-# ifndef LOCAL_BADCHAN
-    if (flags & GLINE_LOCAL)
-      return 0;
-# endif
+    if ((flags & GLINE_LOCAL) && !HasPriv(sptr, PRIV_LOCAL_BADCHAN))
+      return send_reply(sptr, ERR_NOPRIVILEGES);
+
     flags |= GLINE_BADCHAN;
   }
 
   /* Inform ops... */
   sendto_opmask_butone(0, SNO_GLINE, "%s adding %s %s for %s, expiring at "
-                      "%Tu: %s",
-                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      "%Tu: %s", IsServer(sptr) ? cli_name(sptr) :
+                      cli_name((cli_user(sptr))->server),
                       flags & GLINE_LOCAL ? "local" : "global",
                       flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
                       expire + TSoffset, reason);
 
-#ifdef GPATH
   /* and log it */
-  write_log(GPATH, "# %Tu %C adding %s %s for %s, expiring at %Tu: %s\n",
-           TStime(), sptr, flags & GLINE_LOCAL ? "local" : "global",
+  log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+           "%#C adding %s %s for %s, expiring at %Tu: %s", 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);
@@ -275,17 +279,11 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
   if (!agline) /* if it overlapped, silently return */
     return 0;
 
-  propagate_gline(cptr, sptr, agline);
+  gline_propagate(cptr, sptr, agline);
 
   if (GlineIsBadChan(agline))
     return 0;
 
-#ifdef GPATH
-  /* this can be inserted into the conf */
-  write_log(GPATH, "%c:%s:%s:%s\n", GlineIsIpMask(agline) ? 'k' : 'K',
-           GlineHost(agline), GlineReason(agline), GlineUser(agline));
-#endif /* GPATH */
-
   return do_gline(cptr, sptr, agline); /* knock off users if necessary */
 }
 
@@ -304,10 +302,12 @@ gline_activate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
   else {
     gline->gl_flags |= GLINE_ACTIVE;
 
-    if (gline->gl_lastmod >= lastmod) /* force lastmod to increase */
-      gline->gl_lastmod++;
-    else
-      gline->gl_lastmod = lastmod;
+    if (gline->gl_lastmod) {
+      if (gline->gl_lastmod >= lastmod) /* force lastmod to increase */
+       gline->gl_lastmod++;
+      else
+       gline->gl_lastmod = lastmod;
+    }
   }
 
   if ((saveflags & GLINE_ACTMASK) == GLINE_ACTIVE)
@@ -315,24 +315,22 @@ gline_activate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
 
   /* Inform ops and log it */
   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,
+                      "expiring at %Tu: %s", IsServer(sptr) ? cli_name(sptr) :
+                      cli_name((cli_user(sptr))->server),
                       GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
                       gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
                       GlineIsBadChan(gline) ? "" : gline->gl_host,
                       gline->gl_expire + TSoffset, gline->gl_reason);
 
-#ifdef GPATH
-  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) ? "" : "@",
+  log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+           "%#C activating global %s for %s%s%s, expiring at %Tu: %s", sptr,
+           GlineIsBadChan(gline) ? "BADCHAN" : "GLINE", gline->gl_user,
+           GlineIsBadChan(gline) ? "" : "@",
            GlineIsBadChan(gline) ? "" : gline->gl_host,
            gline->gl_expire + TSoffset, gline->gl_reason);
-#endif /* GPATH */
 
   if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
-    propagate_gline(cptr, sptr, gline);
+    gline_propagate(cptr, sptr, gline);
 
   return GlineIsBadChan(gline) ? 0 : do_gline(cptr, sptr, gline);
 }
@@ -350,9 +348,10 @@ gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
 
   if (GlineIsLocal(gline))
     msg = "removing local";
-  else if (!gline->gl_lastmod && !(flags & GLINE_LOCAL))
+  else if (!gline->gl_lastmod && !(flags & GLINE_LOCAL)) {
     msg = "removing global";
-  else {
+    gline->gl_flags &= ~GLINE_ACTIVE; /* propagate a -<mask> */
+  } else {
     msg = "deactivating global";
 
     if (flags & GLINE_LOCAL)
@@ -360,10 +359,12 @@ gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
     else {
       gline->gl_flags &= ~GLINE_ACTIVE;
 
-      if (gline->gl_lastmod >= lastmod)
-       gline->gl_lastmod++;
-      else
-       gline->gl_lastmod = lastmod;
+      if (gline->gl_lastmod) {
+       if (gline->gl_lastmod >= lastmod)
+         gline->gl_lastmod++;
+       else
+         gline->gl_lastmod = lastmod;
+      }
     }
 
     if ((saveflags & GLINE_ACTMASK) != GLINE_ACTIVE)
@@ -372,25 +373,26 @@ gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
 
   /* Inform ops and log it */
   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,
+                      "%s", IsServer(sptr) ? cli_name(sptr) :
+                      cli_name((cli_user(sptr))->server),
                       msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
                       gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
                       GlineIsBadChan(gline) ? "" : gline->gl_host,
                       gline->gl_expire + TSoffset, gline->gl_reason);
 
-#ifdef GPATH
-  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) ? "" : "@",
+  log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+           "%#C %s %s for %s%s%s, expiring at %Tu: %s", 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 (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
+    gline_propagate(cptr, sptr, gline);
+
+  /* if it's a local gline or a Uworld gline (and not locally deactivated).. */
   if (GlineIsLocal(gline) || (!gline->gl_lastmod && !(flags & GLINE_LOCAL)))
-    gline_free(gline);
-  else if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
-    propagate_gline(cptr, sptr, gline);
+    gline_free(gline); /* get rid of it */
 
   return 0;
 }
@@ -472,16 +474,16 @@ gline_lookup(struct Client *cptr, unsigned int flags)
             (flags & GLINE_LASTMOD && !gline->gl_lastmod))
       continue;
      
-    if (match(gline->gl_user, cptr->user->username) != 0)
+    if (match(gline->gl_user, (cli_user(cptr))->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)
+      Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",(cli_ip(cptr)).s_addr,gline->ipnum.s_addr,gline->bits));
+      if (((cli_ip(cptr)).s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
         continue;
     }
     else {
-      if (match(gline->gl_host, cptr->user->host) != 0) 
+      if (match(gline->gl_host, (cli_user(cptr))->host) != 0) 
         continue;
     }
     return gline;
@@ -570,7 +572,7 @@ gline_list(struct Client *sptr, char *userhost)
               GlineIsBadChan(gline) ? "" : "@",
               GlineIsBadChan(gline) ? "" : gline->gl_host,
               gline->gl_expire + TSoffset,
-              GlineIsLocal(gline) ? me.name : "*",
+              GlineIsLocal(gline) ? cli_name(&me) : "*",
               GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
   } else {
     for (gline = GlobalGlineList; gline; gline = sgline) {
@@ -581,7 +583,7 @@ gline_list(struct Client *sptr, char *userhost)
       else
        send_reply(sptr, RPL_GLIST, gline->gl_user, "@", gline->gl_host,
                   gline->gl_expire + TSoffset,
-                  GlineIsLocal(gline) ? me.name : "*",
+                  GlineIsLocal(gline) ? cli_name(&me) : "*",
                   GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
     }
 
@@ -593,7 +595,7 @@ gline_list(struct Client *sptr, char *userhost)
       else
        send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
                   gline->gl_expire + TSoffset,
-                  GlineIsLocal(gline) ? me.name : "*",
+                  GlineIsLocal(gline) ? cli_name(&me) : "*",
                   GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
     }
   }