From da9a1be85b56372d2c23ccd8abc283d16c520162 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 4 Mar 2016 12:40:26 +0100 Subject: [PATCH] set::prefix-quit was not working, reported by capitaine (#4586). --- include/dynconf.h | 2 +- src/modules/m_quit.c | 52 +++++++++++++++++++++++--------------------- src/s_conf.c | 7 +++--- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/include/dynconf.h b/include/dynconf.h index 8d40cd1d9..a6917c003 100644 --- a/include/dynconf.h +++ b/include/dynconf.h @@ -188,7 +188,7 @@ extern MODVAR int ipv6_disabled; #define STATS_SERVER iConf.network.x_stats_server #define SASL_SERVER iConf.network.x_sasl_server #define iNAH iConf.network.x_inah -#define prefix_quit iConf.network.x_prefix_quit +#define PREFIX_QUIT iConf.network.x_prefix_quit #define SSL_SERVER_CERT_PEM iConf.x_server_cert_pem #define SSL_SERVER_KEY_PEM iConf.x_server_key_pem diff --git a/src/modules/m_quit.c b/src/modules/m_quit.c index be649483f..b79f1ca1a 100644 --- a/src/modules/m_quit.c +++ b/src/modules/m_quit.c @@ -79,51 +79,53 @@ MOD_UNLOAD(m_quit) */ CMD_FUNC(m_quit) { - char *ocomment = (parc > 1 && parv[1]) ? parv[1] : sptr->name; - static char comment[TOPICLEN + 1]; + char *comment = (parc > 1 && parv[1]) ? parv[1] : sptr->name; + static char commentbuf[TOPICLEN + 1]; Membership *lp; if (!IsServer(cptr) && IsPerson(sptr)) { int n; - char *s = comment; Hook *tmphook; + if (STATIC_QUIT) return exit_client(cptr, sptr, sptr, STATIC_QUIT); + if (IsVirus(sptr)) return exit_client(cptr, sptr, sptr, "Client exited"); - if (!prefix_quit || strcmp(prefix_quit, "no")) - s = ircsnprintf(comment, sizeof(comment), "%s ", - BadPtr(prefix_quit) ? "Quit:" : prefix_quit); - - n = dospamfilter(sptr, ocomment, SPAMF_QUIT, NULL, 0, NULL); + n = dospamfilter(sptr, comment, SPAMF_QUIT, NULL, 0, NULL); if (n == FLUSH_BUFFER) return n; if (n < 0) - ocomment = sptr->name; + comment = sptr->name; if (!ValidatePermissionsForPath("immune:antispamtimer",sptr,NULL,NULL,NULL) && ANTI_SPAM_QUIT_MSG_TIME) - if (sptr->local->firsttime+ANTI_SPAM_QUIT_MSG_TIME > TStime()) - ocomment = sptr->name; - - for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_QUIT]; tmphook; tmphook = tmphook->next) { - ocomment = (*(tmphook->func.pcharfunc))(sptr, ocomment); - if (!ocomment) - { - ocomment = sptr->name; - break; - } - } + if (sptr->local->firsttime+ANTI_SPAM_QUIT_MSG_TIME > TStime()) + comment = sptr->name; + } - strncpy(s, ocomment, TOPICLEN - (s - comment)); - comment[TOPICLEN] = '\0'; - return exit_client(cptr, sptr, sptr, comment); + for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_QUIT]; tmphook; tmphook = tmphook->next) + { + comment = (*(tmphook->func.pcharfunc))(sptr, comment); + if (!comment) + { + comment = sptr->name; + break; + } + } + + if (PREFIX_QUIT) + snprintf(commentbuf, sizeof(commentbuf), "%s: %s", PREFIX_QUIT, comment); + else + strlcpy(commentbuf, comment, sizeof(commentbuf)); + + return exit_client(cptr, sptr, sptr, commentbuf); } else { - return exit_client(cptr, sptr, sptr, ocomment); + /* Remote quits and non-person quits always use their original comment */ + return exit_client(cptr, sptr, sptr, comment); } } - diff --git a/src/s_conf.c b/src/s_conf.c index 1a821d9c3..484dad632 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -1416,6 +1416,7 @@ void config_setdefaultsettings(aConfiguration *i) i->x_server_key_pem = strdup(tmp); if (!ipv6_capable()) DISABLE_IPV6 = 1; + i->network.x_prefix_quit = strdup("Quit"); } /* 1: needed for set::options::allow-part-if-shunned, @@ -6844,10 +6845,8 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) tempiConf.hide_ban_reason = config_checkval(cep->ce_vardata, CFG_YESNO); } else if (!strcmp(cep->ce_varname, "prefix-quit")) { - if (*cep->ce_vardata == '0') - { - safestrdup(tempiConf.network.x_prefix_quit, ""); - } + if (!strcmp(cep->ce_vardata, "0") || !strcmp(cep->ce_vardata, "no")) + safefree(tempiConf.network.x_prefix_quit); else safestrdup(tempiConf.network.x_prefix_quit, cep->ce_vardata); }