/** Handle a GLINE message from a normal client. * * \a parv has the following elements: * \li \a parv[1] is the target for which to show G-lines. * * See @ref m_functions for discussion of the arguments. * @param[in] cptr Client that sent us the message. * @param[in] sptr Original source of message. * @param[in] parc Number of arguments. * @param[in] parv Argument vector. */ int m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { if (parc < 2) return send_reply(sptr, ERR_NOSUCHGLINE, ""); return gline_list(sptr, parv[1]); }
/* * m_gline - user message handler * * parv[0] = Sender prefix * parv[1] = [<server name>] * */ int m_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { if (feature_bool(FEAT_HIS_USERGLINE)) return send_reply(sptr, ERR_DISABLED, "GLINE"); if (parc < 2) return send_reply(sptr, ERR_NOSUCHGLINE, ""); return gline_list(sptr, parv[1]); }
/* * mo_gline - oper message handler * * parv[0] = Sender prefix * parv[1] = [[+|-]<G-line mask>] * * Local (to me) style: * * parv[2] = [Expiration offset] * parv[3] = [Comment] * * Global (or remote local) style: * * parv[2] = [target] * parv[3] = [Expiration offset] * parv[4] = [Comment] * */ int mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { struct Client *acptr = 0; struct Gline *agline; unsigned int flags = 0; time_t expire_off; char *mask = parv[1], *target = 0, *reason; if (parc < 2) return gline_list(sptr, 0); if (*mask == '!') { mask++; if (HasPriv(sptr, PRIV_WIDE_GLINE)) flags |= GLINE_OPERFORCE; } if (*mask == '+') { flags |= GLINE_ACTIVE; mask++; } else if (*mask == '-') mask++; else return gline_list(sptr, mask); if (parc == 4) { expire_off = atoi(parv[2]); reason = parv[3]; flags |= GLINE_LOCAL; } else if (parc > 4) { target = parv[2]; expire_off = atoi(parv[3]); reason = parv[4]; } else return need_more_params(sptr, "GLINE"); if (target) { if (!(target[0] == '*' && target[1] == '\0')) { if (!(acptr = find_match_server(target))) return send_reply(sptr, ERR_NOSUCHSERVER, target); /* manually propagate, since we don't set it */ if (!IsMe(acptr)) { if (!feature_bool(FEAT_CONFIG_OPERCMDS)) return send_reply(sptr, ERR_DISABLED, "GLINE"); if (!HasPriv(sptr, PRIV_GLINE)) return send_reply(sptr, ERR_NOPRIVILEGES); sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s %s %Tu :%s", acptr, flags & GLINE_OPERFORCE ? "!" : "", flags & GLINE_ACTIVE ? '+' : '-', mask, parv[3], TStime(), reason); return 0; } flags |= GLINE_LOCAL; } } if (!(flags & GLINE_LOCAL) && !feature_bool(FEAT_CONFIG_OPERCMDS)) return send_reply(sptr, ERR_DISABLED, "GLINE"); if (!HasPriv(sptr, (flags & GLINE_LOCAL ? PRIV_LOCAL_GLINE : PRIV_GLINE))) return send_reply(sptr, ERR_NOPRIVILEGES); agline = gline_find(mask, GLINE_ANY | GLINE_EXACT); if (agline) { if (GlineIsLocal(agline) && !(flags & GLINE_LOCAL)) /* global over local */ gline_free(agline); else { if (!GlineLastMod(agline)) /* force mods to Uworld-set G-lines local */ flags |= GLINE_LOCAL; if (flags & GLINE_ACTIVE) return gline_activate(cptr, sptr, agline, GlineLastMod(agline) ? TStime() : 0, flags); else return gline_deactivate(cptr, sptr, agline, GlineLastMod(agline) ? TStime() : 0, flags); } } return gline_add(cptr, sptr, mask, reason, expire_off, TStime(), flags); }
/** Handle a GLINE message from an operator. * * \a parv has the following elements: * \li \a parv[1] is the G-line mask (preceded by modifier flags) * \li \a parv[2] (optional) is the target server numnick or '*' * \li \a parv[N+1] is the G-line lifetime in seconds * \li \a parv[\a parc - 1] is the G-line comment * * Three modifier flags are recognized, and must be present in this * order: * \li '!' Indicates an G-line that an oper forcibly applied. * \li '-' Indicates that the following G-line should be removed. * \li '+' (exclusive of '-') indicates that the G-line should be * activated. * * See @ref m_functions for discussion of the arguments. * @param[in] cptr Client that sent us the message. * @param[in] sptr Original source of message. * @param[in] parc Number of arguments. * @param[in] parv Argument vector. */ int mo_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { struct Client *acptr = 0; struct Gline *agline = 0; unsigned int flags = 0; enum GlineAction action = GLINE_MODIFY; time_t expire = 0; char *mask = parv[1], *target = 0, *reason = 0, *end; if (parc < 2) return gline_list(sptr, 0); if (*mask == '!') { mask++; if (HasPriv(sptr, PRIV_WIDE_GLINE)) flags |= GLINE_OPERFORCE; } switch (*mask) { /* handle +, -, <, and > */ case '+': /* activate the G-line */ action = GLINE_ACTIVATE; mask++; break; case '-': /* deactivate the G-line */ action = GLINE_DEACTIVATE; mask++; break; case '>': /* locally activate the G-line */ action = GLINE_LOCAL_ACTIVATE; mask++; break; case '<': /* locally deactivate the G-line */ action = GLINE_LOCAL_DEACTIVATE; mask++; break; } /* OK, let's figure out the parameters... */ switch (action) { case GLINE_MODIFY: /* no specific action on the G-line... */ if (parc == 2) /* user wants a listing of a specific G-line */ return gline_list(sptr, mask); else if (parc < 4) /* must have target and expire, minimum */ return need_more_params(sptr, "GLINE"); target = parv[2]; /* get the target... */ expire = strtol(parv[3], &end, 10) + TStime(); /* and the expiration */ if (*end != '\0') return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE, "%s :Bad expire time", parv[3]); flags |= GLINE_EXPIRE; /* remember that we got an expire time */ if (parc > 4) { /* also got a reason... */ reason = parv[parc - 1]; flags |= GLINE_REASON; } /* target is not global, interpolate action and require reason */ if (target[0] != '*' || target[1] != '\0') { if (!reason) /* have to have a reason for this */ return need_more_params(sptr, "GLINE"); action = GLINE_ACTIVATE; } break; case GLINE_LOCAL_ACTIVATE: /* locally activate a G-line */ case GLINE_LOCAL_DEACTIVATE: /* locally deactivate a G-line */ if (parc > 2) { /* if target is available, pick it */ target = parv[2]; if (target[0] == '*' && target[1] == '\0') return send_reply(sptr, ERR_NOSUCHSERVER, target); } break; case GLINE_ACTIVATE: /* activating/adding a G-line */ case GLINE_DEACTIVATE: /* deactivating/removing a G-line */ if (parc < 3) return need_more_params(sptr, "GLINE"); if (parc > 3) { /* get expiration and target */ reason = parv[parc - 1]; expire = strtol(parv[parc - 2], &end, 10) + TStime(); if (*end != '\0') return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE, "%s :Bad expire time", parv[parc - 2]); flags |= GLINE_EXPIRE | GLINE_REASON; /* remember that we got 'em */ if (parc > 4) /* also have a target! */ target = parv[2]; } else { target = parv[2]; /* target has to be present, and has to be '*' */ if (target[0] != '*' || target[1] != '\0') return need_more_params(sptr, "GLINE"); } break; } /* Is there no mask left? */ if (mask[0] == '\0') return need_more_params(sptr, "GLINE"); /* Now let's figure out which is the target server */ if (!target) /* no target, has to be me... */ acptr = &me; /* if it's not '*', look up the server */ else if ((target[0] != '*' || target[1] != '\0') && !(acptr = find_match_server(target))) return send_reply(sptr, ERR_NOSUCHSERVER, target); /* Now, is the G-line local or global? */ if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE || !acptr) flags |= GLINE_GLOBAL; else /* it's some form of local G-line */ flags |= GLINE_LOCAL; /* If it's a local activate/deactivate and server isn't me, propagate it */ if ((action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE) && !IsMe(acptr)) { /* check for permissions... */ if (!feature_bool(FEAT_CONFIG_OPERCMDS)) return send_reply(sptr, ERR_DISABLED, "GLINE"); else if (!HasPriv(sptr, PRIV_GLINE)) return send_reply(sptr, ERR_NOPRIVILEGES); Debug((DEBUG_DEBUG, "I am forwarding a local change to a global gline " "to a remote server; target %s, mask %s, operforce %s, action %c", cli_name(acptr), mask, flags & GLINE_OPERFORCE ? "YES" : "NO", action == GLINE_LOCAL_ACTIVATE ? '>' : '<')); sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s", acptr, flags & GLINE_OPERFORCE ? "!" : "", action == GLINE_LOCAL_ACTIVATE ? '>' : '<', mask); return 0; /* all done */ } /* 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 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)) { /* check for permissions... */ if (!feature_bool(FEAT_CONFIG_OPERCMDS)) return send_reply(sptr, ERR_DISABLED, "GLINE"); else if (!HasPriv(sptr, PRIV_GLINE)) return send_reply(sptr, ERR_NOPRIVILEGES); Debug((DEBUG_DEBUG, "I am forwarding a local G-line to a remote " "server; target %s, mask %s, operforce %s, action %c, " "expire %Tu, reason %s", target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO", action == GLINE_ACTIVATE ? '+' : '-', expire, reason)); sendcmdto_one(sptr, CMD_GLINE, acptr, "%C %s%c%s %Tu %Tu :%s", acptr, flags & GLINE_OPERFORCE ? "!" : "", action == GLINE_ACTIVATE ? '+' : '-', mask, expire - TStime(), TStime(), reason); return 0; /* all done */ } /* check local G-line permissions... */ if (!HasPriv(sptr, PRIV_LOCAL_GLINE)) return send_reply(sptr, ERR_NOPRIVILEGES); /* let's handle activation... */ if (action == GLINE_ACTIVATE) { if (agline) /* G-line already exists, so let's ignore it... */ return 0; /* OK, create the local G-line */ Debug((DEBUG_DEBUG, "I am creating 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, reason)); return gline_add(cptr, sptr, mask, reason, expire, 0, 0, flags | GLINE_ACTIVE); } else { /* OK, it's a deactivation/destruction */ if (!agline) /* G-line doesn't exist, so let's complain... */ return send_reply(sptr, ERR_NOSUCHGLINE, mask); /* Let's now destroy the G-line */ Debug((DEBUG_DEBUG, "I am destroying a local G-line here; target %s, " "mask %s, operforce %s, action %s", target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO", action == GLINE_ACTIVATE ? "+" : "-")); return gline_destroy(cptr, sptr, agline); } } /* can't modify a G-line that doesn't exist... * (and if we are creating a new one, we need a reason and expiration) */ if (!agline && (action == GLINE_MODIFY || action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE || !reason || !expire)) return send_reply(sptr, ERR_NOSUCHGLINE, mask); /* check for G-line permissions... */ if (action == GLINE_LOCAL_ACTIVATE || action == GLINE_LOCAL_DEACTIVATE) { /* only need local privileges for locally-limited status changes */ if (!HasPriv(sptr, PRIV_LOCAL_GLINE)) return send_reply(sptr, ERR_NOPRIVILEGES); } else { /* global privileges required */ if (!feature_bool(FEAT_CONFIG_OPERCMDS)) return send_reply(sptr, ERR_DISABLED, "GLINE"); else if (!HasPriv(sptr, PRIV_GLINE)) return send_reply(sptr, ERR_NOPRIVILEGES); } Debug((DEBUG_DEBUG, "I have a global G-line I am acting upon now; " "target %s, mask %s, operforce %s, action %s, expire %Tu, " "reason: %s; gline %s! (fields present: %s %s)", target, mask, flags & GLINE_OPERFORCE ? "YES" : "NO", action == GLINE_ACTIVATE ? "+" : (action == GLINE_DEACTIVATE ? "-" : (action == GLINE_LOCAL_ACTIVATE ? ">" : (action == GLINE_LOCAL_DEACTIVATE ? "<" : "(MODIFY)"))), expire, reason, agline ? "EXISTS" : "does not exist", flags & GLINE_EXPIRE ? "expire" : "", flags & GLINE_REASON ? "reason" : "")); if (agline) /* modifying an existing G-line */ return gline_modify(cptr, sptr, agline, action, reason, expire, TStime(), 0, flags); assert(action != GLINE_LOCAL_ACTIVATE); assert(action != GLINE_LOCAL_DEACTIVATE); assert(action != GLINE_MODIFY); /* create a new G-line */ return gline_add(cptr, sptr, mask, reason, expire, TStime(), 0, flags | ((action == GLINE_ACTIVATE) ? GLINE_ACTIVE : 0)); }