From 92df36a87f89e32b462995f55771405df29b5fba Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 4 Oct 2019 11:30:27 +0200 Subject: [PATCH] Return values of various functions changed, in particular the ones that deal with finding TKL's or spamfilters etc. More will likely follow, to make things more logical. Also, run_spamfilter -> match_spamfilter place_host_ban, can_privmsg, check_dcc, find_tkline_match all impacted. --- include/h.h | 2 +- src/aliases.c | 16 ++++----- src/api-efunctions.c | 4 +-- src/ircd.c | 9 +++-- src/misc.c | 8 ++--- src/modules/antimixedutf8.c | 3 +- src/modules/away.c | 8 ++--- src/modules/blacklist.c | 2 +- src/modules/message.c | 70 +++++++++++++++---------------------- src/modules/nick.c | 34 +++++++++--------- src/modules/part.c | 7 ++-- src/modules/quit.c | 9 ++--- src/modules/setname.c | 7 ++-- src/modules/tkl.c | 61 ++++++++++++++++---------------- src/modules/topic.c | 2 +- 15 files changed, 113 insertions(+), 129 deletions(-) diff --git a/include/h.h b/include/h.h index a4d7ef79f..74ad405f9 100644 --- a/include/h.h +++ b/include/h.h @@ -715,7 +715,7 @@ extern MODVAR void (*tkl_stats)(Client *cptr, int type, char *para); extern MODVAR void (*tkl_synch)(Client *sptr); extern MODVAR void (*cmd_tkl)(Client *sptr, MessageTag *recv_mtags, int parc, char *parv[]); extern MODVAR int (*place_host_ban)(Client *sptr, BanAction action, char *reason, long duration); -extern MODVAR int (*run_spamfilter)(Client *sptr, char *str_in, int type, char *target, int flags, TKL **rettk); +extern MODVAR int (*match_spamfilter)(Client *sptr, char *str_in, int type, char *target, int flags, TKL **rettk); extern MODVAR int (*join_viruschan)(Client *sptr, TKL *tk, int type); extern MODVAR unsigned char *(*StripColors)(unsigned char *text); extern MODVAR const char *(*StripControlCodes)(unsigned char *text); diff --git a/src/aliases.c b/src/aliases.c index b83f20060..db24ba629 100644 --- a/src/aliases.c +++ b/src/aliases.c @@ -66,7 +66,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm { if (SERVICES_NAME && (acptr = find_person(alias->nick, NULL))) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, parv[1], SPAMF_USERMSG, alias->nick, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, parv[1], SPAMF_USERMSG, alias->nick, 0, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", sptr->name, alias->nick, SERVICES_NAME, parv[1]); @@ -78,7 +78,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm { if (STATS_SERVER && (acptr = find_person(alias->nick, NULL))) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, parv[1], SPAMF_USERMSG, alias->nick, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, parv[1], SPAMF_USERMSG, alias->nick, 0, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", sptr->name, alias->nick, STATS_SERVER, parv[1]); @@ -90,7 +90,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm { if ((acptr = find_person(alias->nick, NULL))) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, parv[1], SPAMF_USERMSG, alias->nick, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, parv[1], SPAMF_USERMSG, alias->nick, 0, NULL)) return; if (MyUser(acptr)) sendto_one(acptr, NULL, ":%s!%s@%s PRIVMSG %s :%s", sptr->name, @@ -112,7 +112,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm char *errmsg = NULL; if (!can_send(sptr, chptr, &msg, &errmsg, 0)) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, parv[1], SPAMF_CHANMSG, chptr->chname, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, parv[1], SPAMF_CHANMSG, chptr->chname, 0, NULL)) return; new_message(sptr, NULL, &mtags); sendto_channel(chptr, sptr, sptr, @@ -203,7 +203,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm { if (SERVICES_NAME && (acptr = find_person(format->nick, NULL))) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, output, SPAMF_USERMSG, format->nick, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, output, SPAMF_USERMSG, format->nick, 0, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", sptr->name, format->nick, SERVICES_NAME, output); @@ -214,7 +214,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm { if (STATS_SERVER && (acptr = find_person(format->nick, NULL))) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, output, SPAMF_USERMSG, format->nick, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, output, SPAMF_USERMSG, format->nick, 0, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", sptr->name, format->nick, STATS_SERVER, output); @@ -225,7 +225,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm { if ((acptr = find_person(format->nick, NULL))) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, output, SPAMF_USERMSG, format->nick, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, output, SPAMF_USERMSG, format->nick, 0, NULL)) return; if (MyUser(acptr)) sendto_one(acptr, NULL, ":%s!%s@%s PRIVMSG %s :%s", sptr->name, @@ -247,7 +247,7 @@ void cmd_alias(Client *sptr, MessageTag *mtags, int parc, char *parv[], char *cm char *errmsg = NULL; if (!can_send(sptr, chptr, &msg, &errmsg, 0)) { - if (alias->spamfilter && (ret = run_spamfilter(sptr, output, SPAMF_CHANMSG, chptr->chname, 0, NULL)) < 0) + if (alias->spamfilter && match_spamfilter(sptr, output, SPAMF_CHANMSG, chptr->chname, 0, NULL)) return; new_message(sptr, NULL, &mtags); sendto_channel(chptr, sptr, sptr, diff --git a/src/api-efunctions.c b/src/api-efunctions.c index 5295b525f..4f184b0e3 100644 --- a/src/api-efunctions.c +++ b/src/api-efunctions.c @@ -67,7 +67,7 @@ void (*tkl_stats)(Client *cptr, int type, char *para); void (*tkl_synch)(Client *sptr); void (*cmd_tkl)(Client *sptr, MessageTag *mtags, int parc, char *parv[]); int (*place_host_ban)(Client *sptr, BanAction action, char *reason, long duration); -int (*run_spamfilter)(Client *sptr, char *str_in, int type, char *target, int flags, TKL **rettk); +int (*match_spamfilter)(Client *sptr, char *str_in, int type, char *target, int flags, TKL **rettk); int (*join_viruschan)(Client *sptr, TKL *tk, int type); unsigned char *(*StripColors)(unsigned char *text); const char *(*StripControlCodes)(unsigned char *text); @@ -304,7 +304,7 @@ void efunctions_init(void) efunc_init_function(EFUNC_TKL_SYNCH, tkl_synch, NULL); efunc_init_function(EFUNC_CMD_TKL, cmd_tkl, NULL); efunc_init_function(EFUNC_PLACE_HOST_BAN, place_host_ban, NULL); - efunc_init_function(EFUNC_DOSPAMFILTER, run_spamfilter, NULL); + efunc_init_function(EFUNC_DOSPAMFILTER, match_spamfilter, NULL); efunc_init_function(EFUNC_DOSPAMFILTER_VIRUSCHAN, join_viruschan, NULL); efunc_init_function(EFUNC_STRIPCOLORS, StripColors, NULL); efunc_init_function(EFUNC_STRIPCONTROLCODES, StripControlCodes, NULL); diff --git a/src/ircd.c b/src/ircd.c index 52fb901bd..45c2adb10 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -331,7 +331,7 @@ int check_tkls(Client *cptr) char killflag = 0; /* Process dynamic *LINES */ - if (find_tkline_match(cptr, 0) < 0) + if (find_tkline_match(cptr, 0)) return 0; /* stop processing this user, as (s)he is dead now. */ find_shun(cptr); /* check for shunned and take action, if so */ @@ -374,9 +374,12 @@ int check_tkls(Client *cptr) if (loop.do_bancheck_spamf_user && IsUser(cptr) && find_spamfilter_user(cptr, SPAMFLAG_NOWARN) == FLUSH_BUFFER) return 0; - if (loop.do_bancheck_spamf_away && IsUser(cptr) && cptr->user->away != NULL && - run_spamfilter(cptr, cptr->user->away, SPAMF_AWAY, NULL, SPAMFLAG_NOWARN, NULL) == FLUSH_BUFFER) + if (loop.do_bancheck_spamf_away && IsUser(cptr) && + cptr->user->away != NULL && + match_spamfilter(cptr, cptr->user->away, SPAMF_AWAY, NULL, SPAMFLAG_NOWARN, NULL)) + { return 0; + } return 1; } diff --git a/src/misc.c b/src/misc.c index 25cfa6086..f0f2f6176 100644 --- a/src/misc.c +++ b/src/misc.c @@ -848,10 +848,10 @@ static char buf[512], *i, *o; return buf; } -/** This is basically only used internally by run_spamfilter()... */ +/** This is basically only used internally by match_spamfilter()... */ char *cmdname_by_spamftarget(int target) { -SpamfilterTargetTable *e; + SpamfilterTargetTable *e; for (e = &spamfiltertargettable[0]; e->value; e++) if (e->value == target) @@ -861,8 +861,8 @@ SpamfilterTargetTable *e; int is_autojoin_chan(char *chname) { -char buf[512]; -char *p, *name; + char buf[512]; + char *p, *name; if (OPER_AUTO_JOIN_CHANS) { diff --git a/src/modules/antimixedutf8.c b/src/modules/antimixedutf8.c index ff6083580..949b2db3f 100644 --- a/src/modules/antimixedutf8.c +++ b/src/modules/antimixedutf8.c @@ -195,8 +195,7 @@ CMD_OVERRIDE_FUNC(override_msg) sendnotice(sptr, "%s", cfg.ban_reason); return; } else { - ret = place_host_ban(sptr, cfg.ban_action, cfg.ban_reason, cfg.ban_time); - if (ret != 0) + if (place_host_ban(sptr, cfg.ban_action, cfg.ban_reason, cfg.ban_time)) return; /* a return value of 0 means the user is exempted, so fallthrough.. */ } diff --git a/src/modules/away.c b/src/modules/away.c index b9b059d92..354644bb8 100644 --- a/src/modules/away.c +++ b/src/modules/away.c @@ -86,12 +86,8 @@ CMD_FUNC(cmd_away) } /* Check spamfilters */ - if (MyUser(sptr)) - { - n = run_spamfilter(sptr, new_reason, SPAMF_AWAY, NULL, 0, NULL); - if (n < 0) - return; - } + if (MyUser(sptr) && match_spamfilter(sptr, new_reason, SPAMF_AWAY, NULL, 0, NULL)) + return; /* Check set::anti-flood::away-flood */ if (MyUser(sptr) && AWAY_PERIOD && !ValidatePermissionsForPath("immune:away-flood",sptr,NULL,NULL,NULL)) diff --git a/src/modules/blacklist.c b/src/modules/blacklist.c index 913147a88..76ac95390 100644 --- a/src/modules/blacklist.c +++ b/src/modules/blacklist.c @@ -726,7 +726,7 @@ void blacklist_hit(Client *acptr, Blacklist *bl, int reply) const char *name[4], *value[4]; BLUser *blu = BLUSER(acptr); - if (find_tkline_match(acptr, 1) < 0) + if (find_tkline_match(acptr, 1)) return; /* already klined/glined. Don't send the warning from below. */ if (IsUser(acptr)) diff --git a/src/modules/message.c b/src/modules/message.c index 64fb8c89a..fce559fdb 100644 --- a/src/modules/message.c +++ b/src/modules/message.c @@ -88,11 +88,11 @@ static int check_dcc_soft(Client *from, Client *to, char *text); * RETURN VALUES: * CANPRIVMSG_CONTINUE: issue a 'continue' in target nickname list (aka: skip further processing this target) * CANPRIVMSG_SEND: send the message (use text/newcmd!) - * Other: return with this value (can be anything like 0, -1, FLUSH_BUFFER, etc) + * Other: return with this value (can be anything) */ static int can_privmsg(Client *sptr, Client *acptr, int notice, char **text, char **cmd) { -int ret; + int ret; if (IsVirus(sptr)) { @@ -103,8 +103,8 @@ int ret; if (MyUser(sptr) && !strncasecmp(*text, "\001DCC", 4)) { ret = check_dcc(sptr, acptr->name, acptr, *text); - if (ret < 0) - return ret; + if (IsDead(sptr)) + return 0; if (ret == 0) return CANPRIVMSG_CONTINUE; } @@ -124,12 +124,8 @@ int ret; sendnumeric(sptr, RPL_AWAY, acptr->name, acptr->user->away); - if (MyUser(sptr)) - { - ret = run_spamfilter(sptr, *text, (notice ? SPAMF_USERNOTICE : SPAMF_USERMSG), acptr->name, 0, NULL); - if (ret < 0) - return ret; - } + if (MyUser(sptr) && match_spamfilter(sptr, *text, (notice ? SPAMF_USERNOTICE : SPAMF_USERMSG), acptr->name, 0, NULL)) + return 0; for (tmphook = Hooks[HOOKTYPE_PRE_USERMSG]; tmphook; tmphook = tmphook->next) { *text = (*(tmphook->func.pcharfunc))(sptr, acptr, *text, notice); @@ -304,7 +300,7 @@ void cmd_message(Client *sptr, MessageTag *recv_mtags, int parc, char *parv[], i if (MyUser(sptr) && (*parv[2] == 1)) { ret = check_dcc(sptr, chptr->chname, NULL, parv[2]); - if (ret < 0) + if (IsDead(sptr)) return; if (ret == 0) continue; @@ -342,12 +338,8 @@ void cmd_message(Client *sptr, MessageTag *recv_mtags, int parc, char *parv[], i text = parv[2]; - if (MyUser(sptr)) - { - ret = run_spamfilter(sptr, text, notice ? SPAMF_CHANNOTICE : SPAMF_CHANMSG, chptr->chname, 0, NULL); - if (ret < 0) - return; - } + if (MyUser(sptr) && match_spamfilter(sptr, text, notice ? SPAMF_CHANNOTICE : SPAMF_CHANMSG, chptr->chname, 0, NULL)) + return; new_message(sptr, recv_mtags, &mtags); @@ -414,6 +406,8 @@ void cmd_message(Client *sptr, MessageTag *recv_mtags, int parc, char *parv[], i text = parv[2]; newcmd = cmd; ret = can_privmsg(sptr, acptr, notice, &text, &newcmd); + if (IsDead(sptr)) + return; if (ret == CANPRIVMSG_SEND) { MessageTag *mtags = NULL; @@ -510,26 +504,19 @@ size_t n = strlen(f); return buf; } -/** Checks if a DCC is allowed. - * PARAMETERS: - * sptr: the client to check for - * target: the target (eg a user or a channel) - * targetcli: the target client, NULL in case of a channel - * text: the whole msg - * RETURNS: - * 1: allowed (no dcc, etc) - * 0: block - * <0: immediately return with this value (could be FLUSH_BUFFER) - * HISTORY: - * Dcc ban stuff by _Jozeph_ added by Stskeeps with comments. - * moved and various improvements by Syzop. +/** Checks if a DCC SEND is allowed. + * @param sptr Sending client + * @param target Target name (user or channel) + * @param targetcli Target client (NULL in case of channel!) + * @param text The entire message + * @returns 1 if DCC SEND allowed, 0 if rejected */ static int check_dcc(Client *sptr, char *target, Client *targetcli, char *text) { -char *ctcp; -ConfigItem_deny_dcc *fl; -char *end, realfile[BUFSIZE]; -int size_string, ret; + char *ctcp; + ConfigItem_deny_dcc *fl; + char *end, realfile[BUFSIZE]; + int size_string, ret; if ((*text != 1) || ValidatePermissionsForPath("immune:dcc",sptr,targetcli,NULL,NULL) || (targetcli && ValidatePermissionsForPath("self:getbaddcc",targetcli,NULL,NULL,NULL))) return 1; @@ -567,8 +554,8 @@ int size_string, ret; strlcpy(realfile, ctcp, size_string+1); - if ((ret = run_spamfilter(sptr, realfile, SPAMF_DCC, target, 0, NULL)) < 0) - return ret; + if (match_spamfilter(sptr, realfile, SPAMF_DCC, target, 0, NULL)) + return 0; /* deny */ if ((fl = dcc_isforbidden(sptr, realfile))) { @@ -587,8 +574,7 @@ int size_string, ret; if (!targetcli && ((fl = dcc_isdiscouraged(sptr, realfile)))) { char *displayfile = dcc_displayfile(realfile); - sendnumericfmt(sptr, - RPL_TEXT, "*** Cannot DCC SEND file %s to %s (%s)", displayfile, target, fl->reason); + sendnumericfmt(sptr, RPL_TEXT, "*** Cannot DCC SEND file %s to %s (%s)", displayfile, target, fl->reason); return 0; /* block */ } return 1; /* allowed */ @@ -605,10 +591,10 @@ int size_string, ret; */ static int check_dcc_soft(Client *from, Client *to, char *text) { -char *ctcp; -ConfigItem_deny_dcc *fl; -char *end, realfile[BUFSIZE]; -int size_string; + char *ctcp; + ConfigItem_deny_dcc *fl; + char *end, realfile[BUFSIZE]; + int size_string; if ((*text != 1) || ValidatePermissionsForPath("immune:dcc",from,to,NULL,NULL)|| ValidatePermissionsForPath("self:getbaddcc",to,NULL,NULL,NULL)) return 1; diff --git a/src/modules/nick.c b/src/modules/nick.c index c1bfa797a..15696fc0a 100644 --- a/src/modules/nick.c +++ b/src/modules/nick.c @@ -614,8 +614,7 @@ CMD_FUNC(cmd_nick) { int xx; spamfilter_build_user_string(spamfilter_user, nick, sptr); - xx = run_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, NULL); - if (xx < 0) + if (match_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, NULL)) return; } if (!IsULine(sptr) && (tklban = find_qline(sptr, nick, &ishold))) @@ -1228,26 +1227,29 @@ int _register_user(Client *sptr, char *nick, char *username, char *umode, char * return FLUSH_BUFFER; } /* Check G/Z lines before shuns -- kill before quite -- codemastr */ - if ((xx = find_tkline_match(sptr, 0)) < 0) + if (find_tkline_match(sptr, 0)) { ircstats.is_ref++; - return xx; + return FLUSH_BUFFER; } find_shun(sptr); - /* Technical note regarding next few lines of code: - * If the spamfilter matches, depending on the action: - * If it's block/dccblock/whatever the retval is -1 ===> we return, client stays "locked forever". - * If it's kill/tklline the retval is -2 ==> we return with -2 (aka: FLUSH_BUFFER) - * If it's action is viruschan the retval is -5 ==> we continue, and at the end of this return - * take special actions. We cannot do that directly here since the user is not fully registered - * yet (at all). - * -- Syzop - */ spamfilter_build_user_string(spamfilter_user, sptr->name, sptr); - xx = run_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, &savetkl); - if ((xx < 0) && (xx != -5)) - return xx; + if (match_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, &savetkl)) + { + if (savetkl && ((savetkl->ptr.spamfilter->action == BAN_ACT_VIRUSCHAN) || + (savetkl->ptr.spamfilter->action == BAN_ACT_SOFT_VIRUSCHAN))) + { + /* 'viruschan' action: + * Continue with registering the client, and at the end + * of this function we will do the actual joining to the + * virus channel. + */ + } else { + /* Client is either dead or blocked (will hang, on purpose, and timeout) */ + return 0; + } + } RunHookReturnInt(HOOKTYPE_PRE_LOCAL_CONNECT, sptr, !=0); } diff --git a/src/modules/part.c b/src/modules/part.c index a22644a37..5db66f880 100644 --- a/src/modules/part.c +++ b/src/modules/part.c @@ -89,11 +89,10 @@ CMD_FUNC(cmd_part) } if (commentx) { - n = run_spamfilter(sptr, commentx, SPAMF_PART, parv[1], 0, NULL); - if (n == FLUSH_BUFFER) - return; - if (n < 0) + if (match_spamfilter(sptr, commentx, SPAMF_PART, parv[1], 0, NULL)) commentx = NULL; + if (IsDead(sptr)) + return; } } diff --git a/src/modules/quit.c b/src/modules/quit.c index cf8d324f3..f41186a90 100644 --- a/src/modules/quit.c +++ b/src/modules/quit.c @@ -76,11 +76,12 @@ CMD_FUNC(cmd_quit) if (IsVirus(sptr)) return exit_client(sptr, recv_mtags, "Client exited"); - n = run_spamfilter(sptr, comment, SPAMF_QUIT, NULL, 0, NULL); - if (n == FLUSH_BUFFER) - return; - if (n < 0) + if (match_spamfilter(sptr, comment, SPAMF_QUIT, NULL, 0, NULL)) + { comment = sptr->name; + if (IsDead(sptr)) + return; + } if (!ValidatePermissionsForPath("immune:anti-spam-quit-message-time",sptr,NULL,NULL,NULL) && ANTI_SPAM_QUIT_MSG_TIME) { diff --git a/src/modules/setname.c b/src/modules/setname.c index 49ddc39a8..27f7c060d 100644 --- a/src/modules/setname.c +++ b/src/modules/setname.c @@ -89,11 +89,10 @@ CMD_FUNC(cmd_setname) /* set the new name before we check, but don't send to servers unless it is ok */ strcpy(sptr->info, parv[1]); spamfilter_build_user_string(spamfilter_user, sptr->name, sptr); - xx = run_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, NULL); - if (xx < 0) + if (!match_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, NULL)) { - if (xx != FLUSH_BUFFER) - strcpy(sptr->info, tmpinfo); /* restore (if client wasn't killed already, that is) */ + /* Was rejected by spamfilter, restore the realname */ + strcpy(sptr->info, tmpinfo); return; } diff --git a/src/modules/tkl.c b/src/modules/tkl.c index 17921144d..53639b340 100644 --- a/src/modules/tkl.c +++ b/src/modules/tkl.c @@ -34,7 +34,7 @@ ModuleHeader MOD_HEADER /* Forward declarations */ int tkl_config_test_spamfilter(ConfigFile *, ConfigEntry *, int, int *); -int tkl_config_run_spamfilter(ConfigFile *, ConfigEntry *, int); +int tkl_config_match_spamfilter(ConfigFile *, ConfigEntry *, int); int tkl_config_test_ban(ConfigFile *, ConfigEntry *, int, int *); int tkl_config_run_ban(ConfigFile *, ConfigEntry *, int); int tkl_config_test_except(ConfigFile *, ConfigEntry *, int, int *); @@ -79,7 +79,7 @@ void _tkl_stats(Client *cptr, int type, char *para); void _tkl_synch(Client *sptr); CMD_FUNC(_cmd_tkl); int _place_host_ban(Client *sptr, BanAction action, char *reason, long duration); -int _run_spamfilter(Client *sptr, char *str_in, int type, char *target, int flags, TKL **rettk); +int _match_spamfilter(Client *sptr, char *str_in, int type, char *target, int flags, TKL **rettk); int _join_viruschan(Client *sptr, TKL *tk, int type); void _spamfilter_build_user_string(char *buf, char *nick, Client *acptr); int _match_user(char *rmask, Client *acptr, int options); @@ -162,7 +162,7 @@ MOD_TEST() EfunctionAddVoid(modinfo->handle, EFUNC_TKL_SYNCH, _tkl_synch); EfunctionAddVoid(modinfo->handle, EFUNC_CMD_TKL, _cmd_tkl); EfunctionAdd(modinfo->handle, EFUNC_PLACE_HOST_BAN, _place_host_ban); - EfunctionAdd(modinfo->handle, EFUNC_DOSPAMFILTER, _run_spamfilter); + EfunctionAdd(modinfo->handle, EFUNC_DOSPAMFILTER, _match_spamfilter); EfunctionAdd(modinfo->handle, EFUNC_DOSPAMFILTER_VIRUSCHAN, _join_viruschan); EfunctionAddVoid(modinfo->handle, EFUNC_SPAMFILTER_BUILD_USER_STRING, _spamfilter_build_user_string); EfunctionAdd(modinfo->handle, EFUNC_MATCH_USER, _match_user); @@ -177,7 +177,7 @@ MOD_TEST() MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); - HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, tkl_config_run_spamfilter); + HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, tkl_config_match_spamfilter); HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, tkl_config_run_ban); HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, tkl_config_run_except); CommandAdd(modinfo->handle, "GLINE", cmd_gline, 3, CMD_OPER); @@ -421,7 +421,7 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e } /** Process a spamfilter { } block in the configuration file */ -int tkl_config_run_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) +int tkl_config_match_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) { ConfigEntry *cep; ConfigEntry *cepp; @@ -2625,8 +2625,9 @@ int find_tkline_match_matcher(Client *cptr, int skip_soft, TKL *tkl) } /** Check if user matches a *LINE. If so, kill the user. - * @retval <0 if client is banned (user is killed, don't touch 'cptr' anymore), - * otherwise the client is not banned (either no match or on an exception list). + * @retval 1 if client is banned, 0 if not + * @note Do not continue processing if the client is killed (0 return value). + * @note Return value changed with regards to UnrealIRCd 4! */ int _find_tkline_match(Client *cptr, int skip_soft) { @@ -2635,7 +2636,7 @@ int _find_tkline_match(Client *cptr, int skip_soft) int index, index2; if (IsServer(cptr) || IsMe(cptr)) - return 1; + return 0; /* First, the TKL ip hash table entries.. */ index2 = tkl_ip_hash(GetIP(cptr)); @@ -2671,7 +2672,7 @@ int _find_tkline_match(Client *cptr, int skip_soft) } if (!banned) - return 1; + return 0; /* User is banned... */ @@ -2684,16 +2685,16 @@ int _find_tkline_match(Client *cptr, int skip_soft) banned_client(cptr, "G-Lined", tkl->ptr.serverban->reason, 1, 0); else banned_client(cptr, "K-Lined", tkl->ptr.serverban->reason, 0, 0); - return -1; /* killed */ + return 1; /* killed */ } else if (tkl->type & TKL_ZAP) { ircstats.is_ref++; banned_client(cptr, "Z-Lined", tkl->ptr.serverban->reason, (tkl->type & TKL_GLOBAL)?1:0, 0); - return -1; /* killed */ + return 1; /* killed */ } - return 3; + return 0; } /** Check if user is shunned. Returns 2 in such a case (FIXME: why 2 ?) */ @@ -2769,7 +2770,7 @@ void _spamfilter_build_user_string(char *buf, char *nick, Client *acptr) * nick!user@host:realname ban). * Written by: Syzop * Assumes: only call for clients, possible assume on local clients [?] - * Return values: see run_spamfilter() + * Return values: see match_spamfilter() */ int _find_spamfilter_user(Client *sptr, int flags) { @@ -2779,7 +2780,7 @@ int _find_spamfilter_user(Client *sptr, int flags) return 0; spamfilter_build_user_string(spamfilter_user, sptr->name, sptr); - return run_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, flags, NULL); + return match_spamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, flags, NULL); } /** Check a spamfilter against all local users and print a message. @@ -4034,11 +4035,9 @@ CMD_FUNC(_cmd_tkl) * @param reason The ban reason. * @param duration The ban duration in seconds. * @note This function assumes that sptr is a locally connected user. - * @retval -1 in case of block/tempshun. - * @retval -2 in case of kill/zline/gline/etc (-2 = FLUSH_BUFFER). - * one should no longer read from 'sptr' as the client - * has been freed. - * @retval 0 no action is taken, the user is exempted. + * @retval 1 if action is taken, 0 if user is exempted. + * @note Be sure to check IsDead(sptr) if return value is 1 and you are + * considering to continue processing. */ int _place_host_ban(Client *sptr, BanAction action, char *reason, long duration) { @@ -4130,7 +4129,7 @@ int _place_host_ban(Client *sptr, BanAction action, char *reason, long duration) if ((action == BAN_ACT_SHUN) || (action == BAN_ACT_SOFT_SHUN)) { find_shun(sptr); - return -1; + return 1; } else return find_tkline_match(sptr, 0); } @@ -4138,7 +4137,7 @@ int _place_host_ban(Client *sptr, BanAction action, char *reason, long duration) case BAN_ACT_KILL: default: exit_client(sptr, NULL, reason); - return FLUSH_BUFFER; + return 1; } return 0; /* no action taken (weird) */ } @@ -4247,19 +4246,17 @@ int _join_viruschan(Client *sptr, TKL *tkl, int type) return 0; } -/** run_spamfilter: executes the spamfilter on the input string. +/** match_spamfilter: executes the spamfilter on the input string. * @param str The text (eg msg text, notice text, part text, quit text, etc * @param target The spamfilter target (SPAMF_*) * @param destination The destination as a text string (eg: "somenick", can be NULL.. eg for away) * @param flags Any flags (SPAMFLAG_*) * @param rettkl Pointer to an aTKLline struct, _used for special circumstances only_ * RETURN VALUE: - * 0 if not matched, non-0 if it should be blocked. - * Return value can be FLUSH_BUFFER (-2) which means 'sptr' is - * _NOT_ valid anymore so you should return immediately - * (like from cmd_message, cmd_part, cmd_quit, etc). + * 1 if spamfilter matched and it should be blocked (or client exited), 0 if not matched. + * In case of 1, be sure to check IsDead(sptr).. */ -int _run_spamfilter(Client *sptr, char *str_in, int target, char *destination, int flags, TKL **rettkl) +int _match_spamfilter(Client *sptr, char *str_in, int target, char *destination, int flags, TKL **rettkl) { TKL *tkl; TKL *winner_tkl = NULL; @@ -4413,7 +4410,7 @@ int _run_spamfilter(Client *sptr, char *str_in, int target, char *destination, i default: break; } - return -1; + return 1; } else if ((tkl->ptr.spamfilter->action == BAN_ACT_WARN) || (tkl->ptr.spamfilter->action == BAN_ACT_SOFT_WARN)) { @@ -4429,7 +4426,7 @@ int _run_spamfilter(Client *sptr, char *str_in, int target, char *destination, i sendnotice(sptr, "*** You have been blocked from sending files, reconnect to regain permission to send files"); SetDCCBlock(sptr); } - return -1; + return 1; } else if ((tkl->ptr.spamfilter->action == BAN_ACT_VIRUSCHAN) || (tkl->ptr.spamfilter->action == BAN_ACT_SOFT_VIRUSCHAN)) { @@ -4443,13 +4440,15 @@ int _run_spamfilter(Client *sptr, char *str_in, int target, char *destination, i { if (rettkl) *rettkl = tkl; - return -5; + return 1; } join_viruschan(sptr, tkl, target); - return -5; + return 1; } else + { return place_host_ban(sptr, tkl->ptr.spamfilter->action, reason, tkl->ptr.spamfilter->tkl_duration); + } return 0; /* NOTREACHED */ } diff --git a/src/modules/topic.c b/src/modules/topic.c index 4c9fbda49..6bf98414f 100644 --- a/src/modules/topic.c +++ b/src/modules/topic.c @@ -245,7 +245,7 @@ CMD_FUNC(cmd_topic) Hook *tmphook; int n; - if ((n = run_spamfilter(sptr, topic, SPAMF_TOPIC, chptr->chname, 0, NULL)) < 0) + if (match_spamfilter(sptr, topic, SPAMF_TOPIC, chptr->chname, 0, NULL)) return; for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_TOPIC]; tmphook; tmphook = tmphook->next) {