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); */
}
/*