Author: Entrope <mdpoole@troilus.org>
[ircu2.10.12-pk.git] / ircd / gline.c
index f294d99f456f07694a4c5fd5e22324339c299ebd..487dde94962d28779587bb39f5f7db5d69f4ff8d 100644 (file)
@@ -354,11 +354,15 @@ gline_propagate(struct Client *cptr, struct Client *sptr, struct Gline *gline)
 static int
 count_users(char *mask)
 {
+  struct irc_in_addr ipmask;
   struct Client *acptr;
   int count = 0;
+  int ipmask_valid;
   char namebuf[USERLEN + HOSTLEN + 2];
   char ipbuf[USERLEN + SOCKIPLEN + 2];
+  unsigned char ipmask_len;
 
+  ipmask_valid = ipmask_parse(mask, &ipmask, &ipmask_len);
   for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
     if (!IsUser(acptr))
       continue;
@@ -368,7 +372,9 @@ count_users(char *mask)
     ircd_snprintf(0, ipbuf, sizeof(ipbuf), "%s@%s", cli_user(acptr)->username,
                  ircd_ntoa(&cli_ip(acptr)));
 
-    if (!match(mask, namebuf) || !match(mask, ipbuf))
+    if (!match(mask, namebuf)
+        || !match(mask, ipbuf)
+        || (ipmask_valid && ipmask_check(&cli_ip(acptr), &ipmask, ipmask_len)))
       count++;
   }
 
@@ -429,6 +435,8 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
 
   assert(0 != userhost);
   assert(0 != reason);
+  assert(((flags & (GLINE_GLOBAL | GLINE_LOCAL)) == GLINE_GLOBAL) ||
+         ((flags & (GLINE_GLOBAL | GLINE_LOCAL)) == GLINE_LOCAL));
 
   Debug((DEBUG_DEBUG, "gline_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu "
         "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), userhost, reason,
@@ -664,6 +672,42 @@ gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
   return 0;
 }
 
+/** Send a deactivation request for a locally unknown G-line.
+ * @param[in] cptr Client that sent us the G-line modification.
+ * @param[in] sptr Client that originated the G-line modification.
+ * @param[in] userhost Text representation of G-line target.
+ * @param[in] expire Expiration time of G-line.
+ * @param[in] lastmod Last modification time of G-line.
+ * @param[in] lifetime Lifetime of G-line.
+ * @param[in] flags Bitwise combination of GLINE_* flags.
+ * @return Zero.
+ */
+int
+gline_forward_deactivation(struct Client *cptr, struct Client *sptr,
+                           char *userhost, time_t expire, time_t lastmod,
+                           time_t lifetime, unsigned int flags)
+{
+  char *msg = "deactivating unknown global";
+
+  if (!lifetime)
+    lifetime = expire;
+
+  /* Inform ops and log it */
+  sendto_opmask_butone(0, SNO_GLINE, "%s %s GLINE for %s, expiring at %Tu",
+                       (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
+                         cli_name(sptr) : cli_name((cli_user(sptr))->server),
+                      msg, userhost, expire + TSoffset);
+
+  log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+           "%#C %s GLINE for %s, expiring at %Tu", sptr, msg, userhost,
+           expire);
+
+  sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* -%s %Tu %Tu %Tu",
+                        userhost, expire, lastmod, lifetime);
+
+  return 0;
+}
+
 /** Modify a global G-line.
  * @param[in] cptr Client that sent us the G-line modification.
  * @param[in] sptr Client that originated the G-line modification.
@@ -918,8 +962,7 @@ gline_find(char *userhost, unsigned int flags)
 
   if (flags & (GLINE_BADCHAN | GLINE_ANY)) {
     gliter(BadChanGlineList, gline, sgline) {
-      if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
-         (flags & GLINE_LOCAL && gline->gl_flags & GLINE_GLOBAL) ||
+        if ((flags & (GlineIsLocal(gline) ? GLINE_GLOBAL : GLINE_LOCAL)) ||
          (flags & GLINE_LASTMOD && !gline->gl_lastmod))
        continue;
       else if ((flags & GLINE_EXACT ? ircd_strcmp(gline->gl_user, userhost) :
@@ -936,8 +979,7 @@ gline_find(char *userhost, unsigned int flags)
   canon_userhost(t_uh, &user, &host, "*");
 
   gliter(GlobalGlineList, gline, sgline) {
-    if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
-       (flags & GLINE_LOCAL && gline->gl_flags & GLINE_GLOBAL) ||
+    if ((flags & (GlineIsLocal(gline) ? GLINE_GLOBAL : GLINE_LOCAL)) ||
        (flags & GLINE_LASTMOD && !gline->gl_lastmod))
       continue;
     else if (flags & GLINE_EXACT) {