/** List of BadChan G-lines. */
struct Gline* BadChanGlineList = 0;
+/** Iterate through \a list of G-lines. Use this like a for loop,
+ * i.e., follow it with braces and use whatever you passed as \a gl
+ * as a single G-line to be acted upon.
+ *
+ * @param[in] list List of G-lines to iterate over.
+ * @param[in] gl Name of a struct Gline pointer variable that will be made to point to the G-lines in sequence.
+ * @param[in] next Name of a scratch struct Gline pointer variable.
+ */
+#define gliter(list, gl, next) \
+ /* Iterate through the G-lines in the list */ \
+ for ((gl) = (list); (gl); (gl) = (next)) \
+ /* Figure out the next pointer in list... */ \
+ if ((((next) = (gl)->gl_next) || 1) && \
+ /* Then see if it's expired */ \
+ (gl)->gl_rexpire <= CurrentTime) \
+ /* Record has expired, so free the G-line */ \
+ gline_free((gl)); \
+ /* See if we need to expire the G-line */ \
+ else if (((gl)->gl_expire > CurrentTime || \
+ ((gl)->gl_flags &= ~GLINE_ACTIVE)) && 0) \
+ ; /* empty statement */ \
+ else
+
/** Find canonical user and host for a string.
* If \a userhost starts with '$', assign \a userhost to *user_p and NULL to *host_p.
* Otherwise, if \a userhost contains '@', assign the earlier part of it to *user_p and the rest to *host_p.
DupString(gline->gl_reason, reason); /* initialize gline... */
gline->gl_expire = expire;
+ gline->gl_rexpire = expire;
gline->gl_lastmod = lastmod;
gline->gl_flags = flags & GLINE_MASK;
struct Client *acptr;
int fd, retval = 0, tval;
+ if (feature_bool(FEAT_DISABLE_GLINES))
+ return 0; /* G-lines are disabled */
+
if (GlineIsBadChan(gline)) /* no action taken on badchan glines */
return 0;
if (!GlineIsActive(gline)) /* no action taken on inactive glines */
* <dt>GLINE_ANY</dt><dd>Search both BadChans and user G-lines.</dd>
* <dt>GLINE_BADCHAN</dt><dd>Search BadChans.</dd>
* <dt>GLINE_GLOBAL</dt><dd>Only match global G-lines.</dd>
+ * <dt>GLINE_LOCAL</dt><dd>Only match local G-lines.</dd>
* <dt>GLINE_LASTMOD</dt><dd>Only match G-lines with a last modification time.</dd>
* <dt>GLINE_EXACT</dt><dd>Require an exact match of G-line mask.</dd>
* <dt>anything else</dt><dd>Search user G-lines.</dd>
struct Gline *
gline_find(char *userhost, unsigned int flags)
{
- struct Gline *gline;
+ struct Gline *gline = 0;
struct Gline *sgline;
char *user, *host, *t_uh;
if (flags & (GLINE_BADCHAN | GLINE_ANY)) {
- for (gline = BadChanGlineList; gline; gline = sgline) {
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime)
- gline_free(gline);
- else if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
- (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+ gliter(BadChanGlineList, gline, sgline) {
+ if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+ (flags & GLINE_LOCAL && gline->gl_flags & GLINE_GLOBAL) ||
+ (flags & GLINE_LASTMOD && !gline->gl_lastmod))
continue;
else if ((flags & GLINE_EXACT ? ircd_strcmp(gline->gl_user, userhost) :
match(gline->gl_user, userhost)) == 0)
DupString(t_uh, userhost);
canon_userhost(t_uh, &user, &host, "*");
- for (gline = GlobalGlineList; gline; gline = sgline) {
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime)
- gline_free(gline);
- else if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
- (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+ gliter(GlobalGlineList, gline, sgline) {
+ if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+ (flags & GLINE_LOCAL && gline->gl_flags & GLINE_GLOBAL) ||
+ (flags & GLINE_LASTMOD && !gline->gl_lastmod))
continue;
else if (flags & GLINE_EXACT) {
if (((gline->gl_host && host && ircd_strcmp(gline->gl_host, host) == 0)
if (((gline->gl_host && host && match(gline->gl_host, host) == 0)
|| (!gline->gl_host && !host)) &&
(match(gline->gl_user, user) == 0))
- break;
+ break;
}
}
struct Gline *gline;
struct Gline *sgline;
- for (gline = GlobalGlineList; gline; gline = sgline) {
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime) {
- gline_free(gline);
- continue;
- }
-
+ gliter(GlobalGlineList, gline, sgline) {
if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
(flags & GLINE_LASTMOD && !gline->gl_lastmod))
continue;
struct Gline *gline;
struct Gline *sgline;
- for (gline = GlobalGlineList; gline; gline = sgline) { /* all glines */
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime) /* expire any that need expiring */
- gline_free(gline);
- else if (!GlineIsLocal(gline) && gline->gl_lastmod)
+ gliter(GlobalGlineList, gline, sgline) {
+ if (!GlineIsLocal(gline) && gline->gl_lastmod)
sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_reason);
}
- for (gline = BadChanGlineList; gline; gline = sgline) { /* all glines */
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime) /* expire any that need expiring */
- gline_free(gline);
- else if (!GlineIsLocal(gline) && gline->gl_lastmod)
+ gliter(BadChanGlineList, gline, sgline) {
+ if (!GlineIsLocal(gline) && gline->gl_lastmod)
sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_expire - CurrentTime, gline->gl_lastmod,
GlineIsLocal(gline) ? cli_name(&me) : "*",
GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
} else {
- for (gline = GlobalGlineList; gline; gline = sgline) {
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime)
- gline_free(gline);
- else
- send_reply(sptr, RPL_GLIST, gline->gl_user,
- gline->gl_host ? "@" : "",
- gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset,
- GlineIsLocal(gline) ? cli_name(&me) : "*",
- GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
+ gliter(GlobalGlineList, gline, sgline) {
+ send_reply(sptr, RPL_GLIST, gline->gl_user,
+ gline->gl_host ? "@" : "",
+ gline->gl_host ? gline->gl_host : "",
+ gline->gl_expire + TSoffset,
+ GlineIsLocal(gline) ? cli_name(&me) : "*",
+ GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
}
- for (gline = BadChanGlineList; gline; gline = sgline) {
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime)
- gline_free(gline);
- else
- send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
- gline->gl_expire + TSoffset,
- GlineIsLocal(gline) ? cli_name(&me) : "*",
- GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
+ gliter(BadChanGlineList, gline, sgline) {
+ send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
+ gline->gl_expire + TSoffset,
+ GlineIsLocal(gline) ? cli_name(&me) : "*",
+ GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
}
}
struct Gline *gline;
struct Gline *sgline;
- for (gline = GlobalGlineList; gline; gline = sgline) {
- sgline = gline->gl_next;
-
- if (gline->gl_expire <= CurrentTime)
- gline_free(gline);
- else
- send_reply(sptr, RPL_STATSGLINE, 'G', gline->gl_user,
- gline->gl_host ? "@" : "",
- gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset,
- GlineIsActive(gline) ? '+' : '-',
- gline->gl_reason);
+ gliter(GlobalGlineList, gline, sgline) {
+ send_reply(sptr, RPL_STATSGLINE, 'G', gline->gl_user,
+ gline->gl_host ? "@" : "",
+ gline->gl_host ? gline->gl_host : "",
+ gline->gl_expire + TSoffset,
+ GlineIsActive(gline) ? '+' : '-',
+ gline->gl_reason);
}
}
ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
struct Client *acptr = 0;
- struct Gline *agline;
+ struct Gline *agline = 0;
unsigned int flags = 0;
- time_t expire_off, lastmod = 0;
- char *mask = parv[2], *target = parv[1], *reason = "No reason";
+ enum GlineAction action = GLINE_MODIFY;
+ time_t expire_off = 0, lastmod = 0, lifetime = 0;
+ char *mask = parv[2], *target = parv[1], *reason = "No reason", *tmp = 0;
- if (*mask == '!')
- {
+ if (parc < 3)
+ return need_more_params(sptr, "GLINE");
+
+ if (*mask == '!') {
mask++;
flags |= GLINE_OPERFORCE; /* assume oper had WIDE_GLINE */
- }
+ } else if (IsServer(sptr))
+ flags |= GLINE_FORCE;
- if ((parc == 3 && *mask == '-') || parc == 5)
- {
- if (!find_conf_byhost(cli_confs(cptr), cli_name(sptr), CONF_UWORLD))
- return need_more_params(sptr, "GLINE");
+ switch (*mask) { /* handle +, -, <, and > */
+ case '+': /* activate the G-line */
+ action = GLINE_ACTIVATE;
+ mask++;
+ break;
- flags |= GLINE_FORCE;
- }
- else if (parc > 5)
- lastmod = atoi(parv[4]);
- else
- return need_more_params(sptr, "GLINE");
+ case '-': /* deactivate the G-line */
+ action = GLINE_DEACTIVATE;
+ mask++;
+ break;
- if (parc > 4)
- reason = parv[parc - 1];
+ case '>': /* locally activate the G-line */
+ action = GLINE_LOCAL_ACTIVATE;
+ mask++;
+ break;
- if (IsServer(sptr))
- flags |= GLINE_FORCE;
+ case '<': /* locally deactivate the G-line */
+ action = GLINE_LOCAL_DEACTIVATE;
+ mask++;
+ break;
+ }
- if (!(target[0] == '*' && target[1] == '\0')) {
+ /* Now, let's figure out if it's a local or global G-line */
+ if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE ||
+ (target[0] == '*' && target[1] == '\0'))
+ flags |= GLINE_GLOBAL;
+ else {
if (!(acptr = FindNServer(target)))
- return 0; /* no such server */
+ return 0; /* no such server, jump out */
- if (!IsMe(acptr)) { /* manually propagate */
- 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 :%s", acptr,
- flags & GLINE_OPERFORCE ? "!" : "", mask, parv[3],
- parv[4], reason);
+ flags |= GLINE_LOCAL;
+ }
- return 0;
+ /* Next, try to find the G-line... */
+ if ((flags & GLINE_GLOBAL) || IsMe(acptr)) /* don't bother if it's not me! */
+ agline = gline_find(mask, flags | GLINE_ANY | GLINE_EXACT);
+
+ /* We now have all the pieces to tell us what we've got; let's
+ * put it all together and convert the rest of the arguments.
+ */
+
+ /* Handle the local G-lines first... */
+ if (flags & GLINE_LOCAL) {
+ assert(acptr);
+
+ /* normalize the action, first */
+ if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_MODIFY)
+ action = GLINE_ACTIVATE;
+ else if (action == GLINE_LOCAL_DEACTIVATE)
+ action = GLINE_DEACTIVATE;
+
+ if (action == GLINE_ACTIVATE) { /* get expiration and reason */
+ if (parc < 5) /* check parameter count... */
+ return need_more_params(sptr, "GLINE");
+
+ expire_off = atoi(parv[3]); /* get expiration... */
+ reason = parv[parc - 1]; /* and reason */
+
+ if (IsMe(acptr)) {
+ /* XXX and create the local G-line */
+ sendwallto_group_butone(&me, WALL_DESYNCH, NULL,
+ "I would create a local G-line here; target "
+ "%s, mask %s, operforce %s, action %s, "
+ "expire %Tu, reason: %s", target, mask,
+ flags & GLINE_OPERFORCE ? "YES" : "NO",
+ action == GLINE_ACTIVATE ? "+" : "-",
+ expire_off, reason);
+ }
+ } else if (IsMe(acptr)) { /* destroying a local G-line */
+ /* XXX destroy the G-line */;
+ sendwallto_group_butone(&me, WALL_DESYNCH, NULL,
+ "I would destroy a local G-line here; target "
+ "%s, mask %s, operforce %s, action %s", target,
+ mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
+ action == GLINE_ACTIVATE ? "+" : "-");
}
- flags |= GLINE_LOCAL;
- }
+ /* OK, we've converted arguments; if it's not for us, forward */
+ /* UPDATE NOTE: Once all servers are updated to u2.10.12.11, the
+ * format string in this sendcmdto_one() may be updated to omit
+ * <lastmod> for GLINE_ACTIVATE and to omit <expire>, <lastmod>,
+ * and <reason> for GLINE_DEACTIVATE.
+ */
+ if (!IsMe(acptr)) {
+ sendwallto_group_butone(&me, WALL_DESYNCH, NULL,
+ "I am forwarding a local G-line to a remote "
+ "server; target %s, mask %s, operforce %s, "
+ "action %s, expire %Tu, lastmod %Tu, reason: %s",
+ target, mask,
+ flags & GLINE_OPERFORCE ? "YES" : "NO",
+ action == GLINE_ACTIVATE ? "+" : "-",
+ expire_off, CurrentTime, reason);
+ sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s %Tu %Tu :%s",
+ acptr, flags & GLINE_OPERFORCE ? "!" : "",
+ action == GLINE_ACTIVATE ? '+' : '-', mask, expire_off,
+ CurrentTime, reason);
+ }
- if (*mask == '-')
- mask++;
- else if (*mask == '+') {
- flags |= GLINE_ACTIVE;
- mask++;
- } else
- flags |= GLINE_ACTIVE;
+ return 0; /* all done */
+ }
- expire_off = parc < 5 ? 0 : atoi(parv[3]);
+ /* can't modify a G-line that doesn't exist, so remap to activate */
+ if (!agline && action == GLINE_MODIFY)
+ action = GLINE_ACTIVATE;
- agline = gline_find(mask, GLINE_ANY | GLINE_EXACT);
+ /* OK, let's figure out what other parameters we may have... */
+ switch (action) {
+ case GLINE_LOCAL_ACTIVATE: /* locally activating a G-line */
+ case GLINE_LOCAL_DEACTIVATE: /* locally deactivating a G-line */
+ break; /* no additional parameters to manipulate */
- 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, flags);
- else
- 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");
+ case GLINE_ACTIVATE: /* activating a G-line */
+ case GLINE_DEACTIVATE: /* deactivating a G-line */
+ /* in either of these cases, we have at least a lastmod parameter */
+ if (parc < 4)
+ return need_more_params(sptr, "GLINE");
+ else if (parc == 4) /* lastmod only form... */
+ lastmod = atoi(parv[3]);
+ /*FALLTHROUGH*/
+ case GLINE_MODIFY: /* modifying a G-line */
+ /* convert expire and lastmod, look for lifetime and reason */
+ if (parc > 4) { /* protect against fall-through from 4-param form */
+ if (parc < 5)
+ return need_more_params(sptr, "GLINE");
+
+ expire_off = atoi(parv[3]); /* convert expiration and lastmod */
+ lastmod = atoi(parv[4]);
+
+ if (parc > 6) { /* no question, have a lifetime and reason */
+ lifetime = atoi(parv[5]);
+ reason = parv[parc - 1];
+ } else if (parc == 6) { /* either a lifetime or a reason */
+ if (!agline || /* gline creation, has to be the reason */
+ /* trial-convert as lifetime, and if it doesn't fully convert,
+ * it must be the reason */
+ ((lifetime = strtoul(parv[5], &tmp, 10)) && !*tmp)) {
+ lifetime = 0;
+ reason = parv[5];
+ }
+ }
+ }
+ }
- return gline_add(cptr, sptr, mask, reason, expire_off, lastmod, flags);
+ sendwallto_group_butone(&me, WALL_DESYNCH, NULL,
+ "I have a global G-line I would act upon now; "
+ "target %s, mask %s, operforce %s, action %s, "
+ "expire %Tu, lastmod %Tu, lifetime %Tu, "
+ "reason: %s; gline %s!",
+ target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO",
+ action == GLINE_ACTIVATE ? "+" :
+ (action == GLINE_DEACTIVATE ? "-" :
+ (action == GLINE_LOCAL_ACTIVATE ? ">" :
+ (action == GLINE_LOCAL_DEACTIVATE ? "<" :
+ "(MODIFY)"))), expire_off, lastmod, lifetime,
+ reason, agline ? "EXISTS" : "does not exist");
+
+ /* OK, at this point, we have converted all available parameters.
+ * Let's actually do the action!
+ */
+ if (agline)
+ /* XXX modify the G-line */;
+
+ /* XXX create the G-line */return 0;
+
+
+
+
+
+/* if ((parc == 3 && *mask == '-') || parc == 5) */
+/* { */
+/* if (!find_conf_byhost(cli_confs(cptr), cli_name(sptr), CONF_UWORLD)) */
+/* return need_more_params(sptr, "GLINE"); */
+
+/* flags |= GLINE_FORCE; */
+/* } */
+/* else if (parc > 5) */
+/* lastmod = atoi(parv[4]); */
+/* else */
+/* return need_more_params(sptr, "GLINE"); */
+
+/* if (parc > 4) */
+/* reason = parv[parc - 1]; */
+
+/* if (IsServer(sptr)) */
+/* flags |= GLINE_FORCE; */
+
+/* if (!(target[0] == '*' && target[1] == '\0')) { */
+/* if (!(acptr = FindNServer(target))) */
+/* return 0; /\* no such server *\/ */
+
+/* if (!IsMe(acptr)) { /\* manually propagate *\/ */
+/* 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 :%s", acptr, */
+/* flags & GLINE_OPERFORCE ? "!" : "", mask, parv[3], */
+/* parv[4], reason); */
+
+/* return 0; */
+/* } */
+
+/* flags |= GLINE_LOCAL; */
+/* } */
+
+/* if (*mask == '-') */
+/* mask++; */
+/* else if (*mask == '+') { */
+/* flags |= GLINE_ACTIVE; */
+/* mask++; */
+/* } else */
+/* flags |= GLINE_ACTIVE; */
+
+/* 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, flags); */
+/* else */
+/* 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); */
}
/*