X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fjupe.c;h=243ae626df4fd5072160ef12934b922c15575e6e;hb=refs%2Fheads%2Fupstream;hp=c2eed4b3264a2aac499ecb22696f1fbde3ccb10b;hpb=a72cc43f3a9cac127d7641d189de3df9fb318a36;p=ircu2.10.12-pk.git diff --git a/ircd/jupe.c b/ircd/jupe.c index c2eed4b..243ae62 100644 --- a/ircd/jupe.c +++ b/ircd/jupe.c @@ -17,14 +17,20 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ */ +/** @file + * @brief Implementation of juped server handling functions. + * @version $Id$ + */ +#include "config.h" + #include "jupe.h" #include "client.h" #include "hash.h" #include "ircd.h" #include "ircd_alloc.h" +#include "ircd_features.h" +#include "ircd_log.h" #include "ircd_reply.h" #include "ircd_string.h" #include "match.h" @@ -35,13 +41,21 @@ #include "s_misc.h" #include "send.h" #include "struct.h" -#include "support.h" #include "sys.h" /* FALSE bleah */ -#include +/* #include -- Now using assert in ircd_log.h */ +#include +/** List of jupes. */ static struct Jupe *GlobalJupeList = 0; +/** Allocate a new jupe with the given parameters. + * @param[in] server Server name to jupe. + * @param[in] reason Reason for jupe. + * @param[in] expire Expiration time for jupe. + * @param[in] lastmod Last modification time for jupe. + * @param[in] flags Flags to set for the jupe. + */ static struct Jupe * make_jupe(char *server, char *reason, time_t expire, time_t lastmod, unsigned int flags) @@ -51,6 +65,7 @@ make_jupe(char *server, char *reason, time_t expire, time_t lastmod, ajupe = (struct Jupe*) MyMalloc(sizeof(struct Jupe)); /* alloc memory */ assert(0 != ajupe); + memset(ajupe, 0, sizeof(*ajupe)); DupString(ajupe->ju_server, server); /* copy vital information */ DupString(ajupe->ju_reason, reason); ajupe->ju_expire = expire; @@ -66,6 +81,11 @@ make_jupe(char *server, char *reason, time_t expire, time_t lastmod, return ajupe; } +/** Apply a jupe. + * @param[in] cptr Local client that sent us the jupe. + * @param[in] sptr Originator of the jupe. + * @param[in] jupe Jupe to check. + */ static int do_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe) { @@ -83,6 +103,11 @@ do_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe) return exit_client_msg(cptr, acptr, &me, "Juped: %s", jupe->ju_reason); } +/** Forward a jupe to another server. + * @param[in] cptr Local client that sent us the jupe. + * @param[in] sptr Originator of the jupe. + * @param[in] jupe Jupe to forward. + */ static void propagate_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe) { @@ -95,6 +120,17 @@ propagate_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe) jupe->ju_reason); } +/** Add a new server jupe. + * @param[in] cptr Local client that sent us the jupe. + * @param[in] sptr Originator of the jupe. + * @param[in] server Server name to jupe. + * @param[in] reason Reason for the jupe. + * @param[in] expire Jupe duration in seconds. + * @param[in] lastmod Last modification timestamp (or NULL). + * @param[in] flags Flags to set on jupe. + * @return Zero, unless the jupe causes \a cptr to be SQUIT, in which + * case CPTR_KILLED. + */ int jupe_add(struct Client *cptr, struct Client *sptr, char *server, char *reason, time_t expire, time_t lastmod, unsigned int flags) @@ -110,31 +146,25 @@ jupe_add(struct Client *cptr, struct Client *sptr, char *server, char *reason, */ if (expire <= 0 || expire > JUPE_MAX_EXPIRE) { if (!IsServer(cptr) && MyConnect(cptr)) - send_error_to_client(cptr, ERR_BADEXPIRE, expire); + send_reply(cptr, ERR_BADEXPIRE, expire); return 0; } expire += CurrentTime; /* convert from lifetime to timestamp */ /* Inform ops and log it */ - sendto_op_mask(SNO_NETWORK, "%s adding %sJUPE for %s, expiring at " - TIME_T_FMT ": %s", - IsServer(sptr) ? sptr->name : sptr->user->server->name, - flags & JUPE_LOCAL ? "local " : "", server, - expire + TSoffset, reason); - -#ifdef JPATH - if (IsServer(sptr)) - write_log(JPATH, TIME_T_FMT " %s adding %sJUPE for %s, expiring at " - TIME_T_FMT ": %s\n", TStime(), sptr->name, - flags & JUPE_LOCAL ? "local " : "", server, expire + TSoffset, - reason); - else - write_log(JPATH, TIME_T_FMT, " %s!%s@%s adding %sJUPE for %s, expiring at " - TIME_T_FMT ": %s\n", TStime(), sptr->name, sptr->user->username, - sptr->user->host, flags & JUPE_LOCAL ? "local " : "", server, - expire + TSoffset, reason); -#endif /* JPATH */ + sendto_opmask_butone(0, SNO_NETWORK, "%s adding %sJUPE for %s, expiring at " + "%Tu: %s", + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? + cli_name(sptr) : + cli_name((cli_user(sptr))->server), + flags & JUPE_LOCAL ? "local " : "", server, + expire + TSoffset, reason); + + log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE, + "%#C adding %sJUPE for %s, expiring at %Tu: %s", sptr, + flags & JUPE_LOCAL ? "local " : "", server, expire + TSoffset, + reason); /* make the jupe */ ajupe = make_jupe(server, reason, expire, lastmod, flags); @@ -144,6 +174,15 @@ jupe_add(struct Client *cptr, struct Client *sptr, char *server, char *reason, return do_jupe(cptr, sptr, ajupe); /* remove server if necessary */ } +/** Activate a jupe, optionally changing its lastmod and flags. + * @param[in] cptr Local client that sent us the jupe. + * @param[in] sptr Originator of the jupe. + * @param[in] jupe Jupe to activate. + * @param[in] lastmod New timestamp for last modification of the jupe. + * @param[in] flags Flags to set on the jupe. + * @return Zero, unless the jupe causes \a cptr to be SQUIT, in which + * case CPTR_KILLED. + */ int jupe_activate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe, time_t lastmod, unsigned int flags) @@ -151,7 +190,6 @@ jupe_activate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe, unsigned int saveflags = 0; assert(0 != jupe); - assert(!JupeIsLocal(jupe)); saveflags = jupe->ju_flags; @@ -170,28 +208,32 @@ jupe_activate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe, return 0; /* was active to begin with */ /* Inform ops and log it */ - sendto_op_mask(SNO_NETWORK, "%s activating JUPE for %s, expiring at " - TIME_T_FMT ": %s", - IsServer(sptr) ? sptr->name : sptr->user->server->name, - jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason); - -#ifdef JPATH - if (IsServer(sptr)) - write_log(JPATH, TIME_T_FMT " %s activating JUPE for %s, expiring at " - TIME_T_FMT ": %s\n", TStime(), sptr->name, jupe->ju_server, - jupe->ju_expire + TSoffset, jupe->ju_reason); - else - write_log(JPATH, TIME_T_FMT, " %s!%s@%s activating JUPE for %s, " - "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name, - sptr->user->username, sptr->user->host, jupe->ju_server, - jupe->ju_expire + TSoffset, jupe->ju_reason); -#endif /* JPATH */ - - propagate_jupe(cptr, sptr, jupe); + sendto_opmask_butone(0, SNO_NETWORK, "%s activating JUPE for %s, expiring " + "at %Tu: %s", + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? + cli_name(sptr) : + cli_name((cli_user(sptr))->server), + jupe->ju_server, jupe->ju_expire + TSoffset, + jupe->ju_reason); + + log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE, + "%#C activating JUPE for %s, expiring at %Tu: %s",sptr, + jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason); + + if (!(flags & JUPE_LOCAL)) /* don't propagate local changes */ + propagate_jupe(cptr, sptr, jupe); return do_jupe(cptr, sptr, jupe); } +/** Deactivate a jupe. + * @param[in] cptr Local client that sent us the jupe. + * @param[in] sptr Originator of the jupe. + * @param[in] jupe Jupe to deactivate. + * @param[in] lastmod New timestamp for last modification of the jupe. + * @param[in] flags Flags to set on the jupe. + * @return Zero. + */ int jupe_deactivate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe, time_t lastmod, unsigned int flags) @@ -219,34 +261,32 @@ jupe_deactivate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe, } /* Inform ops and log it */ - sendto_op_mask(SNO_NETWORK, "%s %s JUPE for %s, expiring at " TIME_T_FMT - ": %s", - IsServer(sptr) ? sptr->name : sptr->user->server->name, - JupeIsLocal(jupe) ? "removing local" : "deactivating", - jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason); - -#ifdef JPATH - if (IsServer(sptr)) - write_log(JPATH, TIME_T_FMT " %s %s JUPE for %s, expiring at " TIME_T_FMT - ": %s\n", TStime(), sptr->name, - JupeIsLocal(jupe) ? "removing local" : "deactivating", - jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason); - else - write_log(JPATH, TIME_T_FMT, " %s!%s@%s %s JUPE for %s, " - "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name, - sptr->user->username, sptr->user->host, - JupeIsLocal(jupe) ? "removing local" : "deactivating", - jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason); -#endif /* JPATH */ + sendto_opmask_butone(0, SNO_NETWORK, "%s %s JUPE for %s, expiring at %Tu: " + "%s", + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? + cli_name(sptr) : + cli_name((cli_user(sptr))->server), + JupeIsLocal(jupe) ? "removing local" : "deactivating", + jupe->ju_server, jupe->ju_expire + TSoffset, + jupe->ju_reason); + + log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE, + "%#C %s JUPE for %s, expiring at %Tu: %s", sptr, + JupeIsLocal(jupe) ? "removing local" : "deactivating", + jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason); if (JupeIsLocal(jupe)) jupe_free(jupe); - else + else if (!(flags & JUPE_LOCAL)) /* don't propagate local changes */ propagate_jupe(cptr, sptr, jupe); return 0; } +/** Find a jupe by name. + * @param[in] server %Jupe name to search for. + * @return Matching jupe (or NULL if none match). + */ struct Jupe * jupe_find(char *server) { @@ -265,6 +305,9 @@ jupe_find(char *server) return 0; } +/** Unlink and free an unused jupe. + * @param[in] jupe Server jupe to free. + */ void jupe_free(struct Jupe* jupe) { @@ -279,6 +322,9 @@ jupe_free(struct Jupe* jupe) MyFree(jupe); } +/** Send the full list of active global jupes to \a cptr. + * @param[in] cptr Local server to send jupes to. + */ void jupe_burst(struct Client *cptr) { @@ -298,6 +344,10 @@ jupe_burst(struct Client *cptr) } } +/** Forward a jupe to another server. + * @param[in] cptr %Server to send jupe to. + * @param[in] jupe Jupe to forward. + */ int jupe_resend(struct Client *cptr, struct Jupe *jupe) { @@ -312,6 +362,11 @@ jupe_resend(struct Client *cptr, struct Jupe *jupe) return 0; } +/** Send a jupe (or a list of jupes) to a server. + * @param[in] sptr Client searching for jupes. + * @param[in] server Name of jupe to search for (if NULL, list all). + * @return Zero. + */ int jupe_list(struct Client *sptr, char *server) { @@ -320,11 +375,11 @@ jupe_list(struct Client *sptr, char *server) if (server) { if (!(jupe = jupe_find(server))) /* no such jupe */ - return send_error_to_client(sptr, ERR_NOSUCHJUPE, server); + return send_reply(sptr, ERR_NOSUCHJUPE, server); /* send jupe information along */ send_reply(sptr, RPL_JUPELIST, jupe->ju_server, jupe->ju_expire + TSoffset, - JupeIsLocal(jupe) ? me.name : "*", + JupeIsLocal(jupe) ? cli_name(&me) : "*", JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason); } else { for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */ @@ -335,7 +390,7 @@ jupe_list(struct Client *sptr, char *server) else /* send jupe information along */ send_reply(sptr, RPL_JUPELIST, jupe->ju_server, jupe->ju_expire + TSoffset, - JupeIsLocal(jupe) ? me.name : "*", + JupeIsLocal(jupe) ? cli_name(&me) : "*", JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason); } } @@ -343,3 +398,23 @@ jupe_list(struct Client *sptr, char *server) /* end of jupe information */ return send_reply(sptr, RPL_ENDOFJUPELIST); } + +/** Count jupes and memory used by them. + * @param[out] ju_size Receives total number of bytes allocated for jupes. + * @return Number of jupes currently allocated. + */ +int +jupe_memory_count(size_t *ju_size) +{ + struct Jupe *jupe; + unsigned int ju = 0; + + for (jupe = GlobalJupeList; jupe; jupe = jupe->ju_next) + { + ju++; + *ju_size += sizeof(struct Jupe); + *ju_size += jupe->ju_server ? (strlen(jupe->ju_server) + 1) : 0; + *ju_size += jupe->ju_reason ? (strlen(jupe->ju_reason) + 1) : 0; + } + return ju; +}