Cleanup code so it builds with C++ again
[ircu2.10.12-pk.git] / ircd / gline.c
index 7ed3f1cfcab2b8de4eb5cadf91e401af81d14b3d..e2672f457a4fbdec703ee8881c7bbf91ec1d5157 100644 (file)
@@ -27,7 +27,6 @@
 #include "ircd_alloc.h"
 #include "ircd_features.h"
 #include "ircd_log.h"
-#include "ircd_policy.h"
 #include "ircd_reply.h"
 #include "ircd_snprintf.h"
 #include "ircd_string.h"
@@ -36,6 +35,7 @@
 #include "s_bsd.h"
 #include "s_debug.h"
 #include "s_misc.h"
+#include "s_stats.h"
 #include "send.h"
 #include "struct.h"
 #include "support.h"
@@ -132,20 +132,21 @@ make_gline(char *user, char *host, char *reason, time_t expire, time_t lastmod,
     DupString(gline->gl_host, host);
 
     if (check_if_ipmask(host)) { /* mark if it's an IP mask */
-      int class;
+      int c_class;
       char ipname[16];
       int ad[4] = { 0 };
       int bits2 = 0;
        
-      class = sscanf(host,"%d.%d.%d.%d/%d",
+      c_class = sscanf(host,"%d.%d.%d.%d/%d",
                      &ad[0],&ad[1],&ad[2],&ad[3], &bits2);
-      if (class!=5) {
-        gline->bits=class*8;
+      if (c_class!=5) {
+        gline->bits=c_class*8;
       }
       else {
         gline->bits=bits2;
       }
-      sprintf_irc(ipname,"%d.%d.%d.%d",ad[0],ad[1],ad[2],ad[3]);
+      ircd_snprintf(0, ipname, sizeof(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;
@@ -316,9 +317,9 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
   assert(0 != reason);
 
   /* NO_OLD_GLINE allows *@#channel to work correctly */
-  if (*userhost == '#' || *userhost == '&' || *userhost == '+'
+  if (*userhost == '#' || *userhost == '&'
 # ifndef NO_OLD_GLINE
-      || userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+'
+      || userhost[2] == '#' || userhost[2] == '&'
 # endif /* OLD_GLINE */
       ) {
     if ((flags & GLINE_LOCAL) && !HasPriv(sptr, PRIV_LOCAL_BADCHAN))
@@ -326,7 +327,7 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
 
     flags |= GLINE_BADCHAN;
 # ifndef NO_OLD_GLINE
-    if (userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+')
+    if (userhost[2] == '#' || userhost[2] == '&')
       user = userhost + 2;
     else
 # endif /* OLD_GLINE */
@@ -367,18 +368,16 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
   expire += CurrentTime; /* convert from lifetime to timestamp */
 
   /* Inform ops... */
-  sendto_opmask_butone(0, SNO_GLINE, "%s adding %s %s for %s%s%s, expiring at "
-                      "%Tu: %s",
-#ifdef HEAD_IN_SAND_SNOTICES
-                      cli_name(sptr),
-#else
-                      IsServer(sptr) ? cli_name(sptr) :
-                      cli_name((cli_user(sptr))->server),
-#endif
-                      flags & GLINE_LOCAL ? "local" : "global",
-                      flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", user,
-                      flags & GLINE_BADCHAN ? "" : "@",
-                      flags & GLINE_BADCHAN ? "" : host,
+  sendto_opmask_butone(0, ircd_strncmp(reason, "AUTO", 4) ? SNO_GLINE :
+                       SNO_AUTO, "%s adding %s %s for %s%s%s, expiring at "
+                       "%Tu: %s",
+                       (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
+                         cli_name(sptr) :
+                         cli_name((cli_user(sptr))->server),
+                      (flags & GLINE_LOCAL) ? "local" : "global",
+                      (flags & GLINE_BADCHAN) ? "BADCHAN" : "GLINE", user,
+                      (flags & GLINE_BADCHAN) ? "" : "@",
+                      (flags & GLINE_BADCHAN) ? "" : host,
                       expire + TSoffset, reason);
 
   /* and log it */
@@ -430,18 +429,15 @@ 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",
-#ifdef HEAD_IN_SAND_SNOTICES
-                      cli_name(sptr),
-#else
-                      IsServer(sptr) ? cli_name(sptr) :
-                      cli_name((cli_user(sptr))->server),
-#endif
-                      GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-                      gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-                      GlineIsBadChan(gline) ? "" : gline->gl_host,
-                      gline->gl_expire + TSoffset, gline->gl_reason);
-
+                       "expiring at %Tu: %s",
+                       (feature_bool(FEAT_HIS_SNOTICES) || 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);
+  
   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,
@@ -494,12 +490,9 @@ 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",
-#ifdef HEAD_IN_SAND_SNOTICES
-                      cli_name(sptr),
-#else
-                      IsServer(sptr) ? cli_name(sptr) :
-                      cli_name((cli_user(sptr))->server),
-#endif
+                       (feature_bool(FEAT_HIS_SNOTICES) || 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,
@@ -545,9 +538,9 @@ gline_find(char *userhost, unsigned int flags)
   }
 
   if ((flags & (GLINE_BADCHAN | GLINE_ANY)) == GLINE_BADCHAN ||
-      *userhost == '#' || *userhost == '&' || *userhost == '+'
+      *userhost == '#' || *userhost == '&'
 #ifndef NO_OLD_GLINE
-      || userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+'
+      || userhost[2] == '#' || userhost[2] == '&'
 #endif /* NO_OLD_GLINE */
       )
     return 0;
@@ -555,6 +548,9 @@ gline_find(char *userhost, unsigned int flags)
   DupString(t_uh, userhost);
   canon_userhost(t_uh, &user, &host, 0);
 
+  if (BadPtr(user))
+    return 0;
+
   for (gline = GlobalGlineList; gline; gline = sgline) {
     sgline = gline->gl_next;
 
@@ -608,7 +604,7 @@ gline_lookup(struct Client *cptr, unsigned int flags)
         continue;
     }
     else {
-      if (match(gline->gl_host, (cli_user(cptr))->host) != 0) 
+      if (match(gline->gl_host, (cli_user(cptr))->realhost) != 0) 
         continue;
     }
     return gline;
@@ -730,7 +726,8 @@ gline_list(struct Client *sptr, char *userhost)
 }
 
 void
-gline_stats(struct Client *sptr)
+gline_stats(struct Client *sptr, struct StatDesc *sd, int stat,
+            char *param)
 {
   struct Gline *gline;
   struct Gline *sgline;
@@ -745,3 +742,21 @@ gline_stats(struct Client *sptr)
                 gline->gl_expire + TSoffset, gline->gl_reason);
   }
 }
+
+int
+gline_memory_count(size_t *gl_size)
+{
+  struct Gline *gline;
+  unsigned int gl = 0;
+  
+  for (gline = GlobalGlineList; gline; gline = gline->gl_next)
+  {
+    gl++;
+    gl_size += sizeof(struct Gline);
+    gl_size += gline->gl_user ? (strlen(gline->gl_user) + 1) : 0;
+    gl_size += gline->gl_host ? (strlen(gline->gl_host) + 1) : 0;
+    gl_size += gline->gl_reason ? (strlen(gline->gl_reason) + 1) : 0;
+  }
+  return gl;
+}
+