From 98ac35197b5d0683ddd8323a2ffa1b40c0e42fff Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 12:49:19 -0600 Subject: [PATCH 01/23] invite: remove hardcoded callerid logic --- modules/m_invite.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/modules/m_invite.c b/modules/m_invite.c index bbdee565..0b882aab 100644 --- a/modules/m_invite.c +++ b/modules/m_invite.c @@ -201,30 +201,6 @@ m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source if(MyConnect(target_p)) { - if(!IsOper(source_p) && IsSetCallerId(target_p) && !accept_message(source_p, target_p)) - { - sendto_one_numeric(source_p, ERR_TARGUMODEG, - form_str(ERR_TARGUMODEG), - target_p->name); - - if((target_p->localClient->last_caller_id_time + - ConfigFileEntry.caller_id_wait) < rb_current_time()) - { - sendto_one_numeric(source_p, RPL_TARGNOTIFY, - form_str(RPL_TARGNOTIFY), - target_p->name); - - add_reply_target(target_p, source_p); - sendto_one(target_p, form_str(RPL_UMODEGMSG), - me.name, target_p->name, source_p->name, - source_p->username, source_p->host); - - target_p->localClient->last_caller_id_time = rb_current_time(); - } - - return; - } - hdata.chptr = chptr; hdata.msptr = msptr; hdata.client = source_p; From 4a9cf8698155cbcc9b758c0191d031fd952adc17 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 12:49:52 -0600 Subject: [PATCH 02/23] message: remove hardcoded +G logic --- modules/core/m_message.c | 72 ++-------------------------------------- 1 file changed, 2 insertions(+), 70 deletions(-) diff --git a/modules/core/m_message.c b/modules/core/m_message.c index e329e7bf..227745d6 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -718,32 +718,6 @@ msg_client(enum message_type msgtype, if(MyClient(source_p)) { - /* - * XXX: Controversial? Allow target users to send replies - * through a +g. Rationale is that people can presently use +g - * as a way to taunt users, e.g. harass them and hide behind +g - * as a way of griefing. --nenolod - */ - if(msgtype != MESSAGE_TYPE_NOTICE && - IsSetCallerId(source_p) && - !accept_message(target_p, source_p) && - !IsOper(target_p)) - { - if(rb_dlink_list_length(&source_p->localClient->allow_list) < - (unsigned long)ConfigFileEntry.max_accept) - { - rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); - rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); - } - else - { - sendto_one_numeric(source_p, ERR_OWNMODE, - form_str(ERR_OWNMODE), - target_p->name, "+g"); - return; - } - } - /* reset idle time for message only if its not to self * and its not a notice */ if(msgtype != MESSAGE_TYPE_NOTICE) @@ -816,50 +790,8 @@ msg_client(enum message_type msgtype, return; } - /* XXX Controversial? allow opers always to send through a +g */ - if(!IsServer(source_p) && IsSetCallerId(target_p)) - { - /* Here is the anti-flood bot/spambot code -db */ - if(accept_message(source_p, target_p) || IsOper(source_p)) - { - add_reply_target(target_p, source_p); - sendto_one(target_p, ":%s!%s@%s %s %s :%s", - source_p->name, - source_p->username, - source_p->host, cmdname[msgtype], target_p->name, text); - } - else - { - /* check for accept, flag recipient incoming message */ - if(msgtype != MESSAGE_TYPE_NOTICE) - { - sendto_one_numeric(source_p, ERR_TARGUMODEG, - form_str(ERR_TARGUMODEG), - target_p->name); - } - - if((target_p->localClient->last_caller_id_time + - ConfigFileEntry.caller_id_wait) < rb_current_time()) - { - if(msgtype != MESSAGE_TYPE_NOTICE) - sendto_one_numeric(source_p, RPL_TARGNOTIFY, - form_str(RPL_TARGNOTIFY), - target_p->name); - - add_reply_target(target_p, source_p); - sendto_one(target_p, form_str(RPL_UMODEGMSG), - me.name, target_p->name, source_p->name, - source_p->username, source_p->host); - - target_p->localClient->last_caller_id_time = rb_current_time(); - } - } - } - else - { - add_reply_target(target_p, source_p); - sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text); - } + add_reply_target(target_p, source_p); + sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text); } else sendto_anywhere(target_p, source_p, cmdname[msgtype], ":%s", text); From 303e85c59e4c04cb7100ebb4641c0ff214c40542 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 12:50:24 -0600 Subject: [PATCH 03/23] remove callerid definitions --- include/client.h | 2 -- ircd/newconf.c | 1 - ircd/s_user.c | 2 +- ircd/supported.c | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/include/client.h b/include/client.h index 0f132160..e43838b9 100644 --- a/include/client.h +++ b/include/client.h @@ -444,7 +444,6 @@ struct ListClient #define UMODE_WALLOP 0x0002 /* send wallops to them */ #define UMODE_OPERWALL 0x0004 /* Operwalls */ #define UMODE_INVISIBLE 0x0008 /* makes user invisible */ -#define UMODE_CALLERID 0x0010 /* block unless caller id's */ #define UMODE_LOCOPS 0x0020 /* show locops */ #define UMODE_SERVICE 0x0040 #define UMODE_DEAF 0x0080 @@ -535,7 +534,6 @@ struct ListClient #define SendLocops(x) ((x)->umodes & UMODE_LOCOPS) #define SendServNotice(x) ((x)->umodes & UMODE_SERVNOTICE) #define SendOperwall(x) ((x)->umodes & UMODE_OPERWALL) -#define IsSetCallerId(x) ((x)->umodes & UMODE_CALLERID) #define IsService(x) ((x)->umodes & UMODE_SERVICE) #define IsDeaf(x) ((x)->umodes & UMODE_DEAF) #define IsNoForward(x) ((x)->umodes & UMODE_NOFORWARD) diff --git a/ircd/newconf.c b/ircd/newconf.c index 6f8a3b58..9e200fd7 100644 --- a/ircd/newconf.c +++ b/ircd/newconf.c @@ -316,7 +316,6 @@ struct mode_table /* *INDENT-OFF* */ static struct mode_table umode_table[] = { - {"callerid", UMODE_CALLERID }, {"deaf", UMODE_DEAF }, {"invisible", UMODE_INVISIBLE }, {"locops", UMODE_LOCOPS }, diff --git a/ircd/s_user.c b/ircd/s_user.c index cb4cf9db..bda9bca8 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -97,7 +97,7 @@ int user_modes[256] = { 0, /* d */ 0, /* e */ 0, /* f */ - UMODE_CALLERID, /* g */ + 0, /* g */ 0, /* h */ UMODE_INVISIBLE, /* i */ 0, /* j */ diff --git a/ircd/supported.c b/ircd/supported.c index 09de6ce0..3dbbcd66 100644 --- a/ircd/supported.c +++ b/ircd/supported.c @@ -318,7 +318,6 @@ init_isupport(void) add_isupport("MODES", isupport_intptr, &maxmodes); add_isupport("NETWORK", isupport_stringptr, &ServerInfo.network_name); add_isupport("STATUSMSG", isupport_string, "@+"); - add_isupport("CALLERID", isupport_umode, "g"); add_isupport("CASEMAPPING", isupport_string, "rfc1459"); add_isupport("NICKLEN", isupport_nicklen, NULL); add_isupport("MAXNICKLEN", isupport_intptr, &maxnicklen); From 921b508b1bdd8777eba994990548d631ceb85948 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 12:50:34 -0600 Subject: [PATCH 04/23] add callerid module --- modules/Makefile.am | 1 + modules/um_callerid.c | 200 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 modules/um_callerid.c diff --git a/modules/Makefile.am b/modules/Makefile.am index 7f532db7..d7005577 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -15,6 +15,7 @@ auto_load_mod_LTLIBRARIES = \ cap_server_time.la \ chm_nocolour.la \ chm_noctcp.la \ + um_callerid.la \ um_regonlymsg.la \ m_accept.la \ m_admin.la \ diff --git a/modules/um_callerid.c b/modules/um_callerid.c new file mode 100644 index 00000000..371c0c7d --- /dev/null +++ b/modules/um_callerid.c @@ -0,0 +1,200 @@ +/* + * modules/um_callerid.c + * Copyright (c) 2020 Ariadne Conill + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stdinc.h" +#include "modules.h" +#include "hook.h" +#include "client.h" +#include "ircd.h" +#include "send.h" +#include "hash.h" +#include "s_conf.h" +#include "s_user.h" +#include "s_serv.h" +#include "numeric.h" +#include "privilege.h" +#include "s_newconf.h" +#include "hook.h" +#include "supported.h" + +static int +um_callerid_modinit(void) +{ + user_modes['g'] = find_umode_slot(); + construct_umodebuf(); + + add_isupport("CALLERID", isupport_stringptr, "g"); + + return 0; +} + +static void +um_callerid_moddeinit(void) +{ + user_modes['g'] = 0; + construct_umodebuf(); + + delete_isupport("CALLERID"); +} + +#define IsSetCallerID(c) ((c->umodes & user_modes['g']) == user_modes['g']) + +static const char um_callerid_desc[] = + "Provides usermode +g which restricts messages from unauthorized users."; + +static bool +allow_message(struct Client *source_p, struct Client *target_p) +{ + if (!MyClient(target_p)) + return true; + + if (!IsSetCallerID(target_p)) + return true; + + if (IsServer(source_p)) + return true; + + /* XXX: controversial? allow opers to send through +g */ + if (IsOper(source_p)) + return true; + + if (accept_message(source_p, target_p)) + return true; + + return false; +} + +static void +send_callerid_notice(enum message_type msgtype, struct Client *source_p, struct Client *target_p) +{ + if (!MyClient(target_p)) + return; + + if (msgtype == MESSAGE_TYPE_NOTICE) + return; + + sendto_one_numeric(source_p, ERR_TARGUMODEG, form_str(ERR_TARGUMODEG), + target_p->name); + + if ((target_p->localClient->last_caller_id_time + ConfigFileEntry.caller_id_wait) < rb_current_time()) + { + sendto_one_numeric(source_p, RPL_TARGNOTIFY, form_str(RPL_TARGNOTIFY), + target_p->name); + + sendto_one(target_p, form_str(RPL_UMODEGMSG), + me.name, target_p->name, source_p->name, + source_p->username, source_p->host); + + target_p->localClient->last_caller_id_time = rb_current_time(); + } +} + +static bool +add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_p, struct Client *target_p) +{ + /* + * XXX: Controversial? Allow target users to send replies + * through a +g. Rationale is that people can presently use +g + * as a way to taunt users, e.g. harass them and hide behind +g + * as a way of griefing. --nenolod + */ + if(msgtype != MESSAGE_TYPE_NOTICE && + IsSetCallerID(source_p) && + !accept_message(target_p, source_p) && + !IsOper(target_p)) + { + if(rb_dlink_list_length(&source_p->localClient->allow_list) < + (unsigned long)ConfigFileEntry.max_accept) + { + rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); + rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); + } + else + { + sendto_one_numeric(source_p, ERR_OWNMODE, + form_str(ERR_OWNMODE), + target_p->name, "+g"); + return false; + } + } + + return true; +} + +static void +h_can_invite(void *vdata) +{ + hook_data_channel_approval *data = vdata; + struct Client *source_p = data->client; + struct Client *target_p = data->target; + + if (!add_callerid_accept_for_source(MESSAGE_TYPE_PRIVMSG, source_p, target_p)) + { + data->approved = ERR_TARGUMODEG; + return; + } + + if (allow_message(source_p, target_p)) + return; + + send_callerid_notice(MESSAGE_TYPE_PRIVMSG, source_p, target_p); + + data->approved = ERR_TARGUMODEG; +} + +static void +h_hdl_privmsg_user(void *vdata) +{ + hook_data_privmsg_user *data = vdata; + enum message_type msgtype = data->msgtype; + struct Client *source_p = data->source_p; + struct Client *target_p = data->target_p; + + if (!add_callerid_accept_for_source(msgtype, source_p, target_p)) + { + data->approved = ERR_TARGUMODEG; + return; + } + + if (allow_message(source_p, target_p)) + return; + + send_callerid_notice(msgtype, source_p, target_p); + + data->approved = ERR_TARGUMODEG; +} + +static mapi_hfn_list_av1 um_callerid_hfnlist[] = { + { "can_invite", h_can_invite }, + { "privmsg_user", h_hdl_privmsg_user }, + { NULL, NULL } +}; + +DECLARE_MODULE_AV2(um_callerid, um_callerid_modinit, um_callerid_moddeinit, + NULL, NULL, um_callerid_hfnlist, NULL, NULL, um_callerid_desc); From 6558648dc3cf656a06d82ab9f19eecc3b702f98b Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 13:05:17 -0600 Subject: [PATCH 05/23] callerid: don't clobber other modules --- modules/um_callerid.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 371c0c7d..452b7b96 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -154,6 +154,9 @@ h_can_invite(void *vdata) struct Client *source_p = data->client; struct Client *target_p = data->target; + if (data->approved) + return; + if (!add_callerid_accept_for_source(MESSAGE_TYPE_PRIVMSG, source_p, target_p)) { data->approved = ERR_TARGUMODEG; @@ -176,6 +179,9 @@ h_hdl_privmsg_user(void *vdata) struct Client *source_p = data->source_p; struct Client *target_p = data->target_p; + if (data->approved) + return; + if (!add_callerid_accept_for_source(msgtype, source_p, target_p)) { data->approved = ERR_TARGUMODEG; From 7106e36ed37410d4149b8c2d6edfc80a2bface61 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 19:11:46 +0000 Subject: [PATCH 06/23] callerid: fix up isupport --- modules/um_callerid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 452b7b96..44bf52f0 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -49,7 +49,7 @@ um_callerid_modinit(void) user_modes['g'] = find_umode_slot(); construct_umodebuf(); - add_isupport("CALLERID", isupport_stringptr, "g"); + add_isupport("CALLERID", isupport_string, "g"); return 0; } From 7b60cca0f1d6dcd47a6ae1eb5cb0b649ee36a461 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 19:33:49 +0000 Subject: [PATCH 07/23] callerid: implement relaxed caller id mode (+G) --- modules/um_callerid.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 44bf52f0..4edc0f67 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -47,6 +47,7 @@ static int um_callerid_modinit(void) { user_modes['g'] = find_umode_slot(); + user_modes['G'] = find_umode_slot(); construct_umodebuf(); add_isupport("CALLERID", isupport_string, "g"); @@ -58,16 +59,33 @@ static void um_callerid_moddeinit(void) { user_modes['g'] = 0; + user_modes['G'] = 0; construct_umodebuf(); delete_isupport("CALLERID"); } #define IsSetCallerID(c) ((c->umodes & user_modes['g']) == user_modes['g']) +#define IsSetRelaxedCallerID(c) ((c->umodes & user_modes['G']) == user_modes['G']) static const char um_callerid_desc[] = "Provides usermode +g which restricts messages from unauthorized users."; +static bool +has_common_channel(struct Client *source_p, struct Client *target_p) +{ + rb_dlink_node *ptr; + + RB_DLINK_FOREACH(ptr, source_p->user->channel.head) + { + struct membership *msptr = ptr->data; + if (IsMember(target_p, msptr->chptr)) + return msptr->chptr; + } + + return NULL; +} + static bool allow_message(struct Client *source_p, struct Client *target_p) { @@ -77,6 +95,9 @@ allow_message(struct Client *source_p, struct Client *target_p) if (!IsSetCallerID(target_p)) return true; + if (IsSetRelaxedCallerID(target_p) && has_common_channel(source_p, target_p)) + return true; + if (IsServer(source_p)) return true; From db8076342721092ccd24b417a40554b8a9690843 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 14:23:02 -0600 Subject: [PATCH 08/23] callerid: use invite instead of can_invite hook --- modules/um_callerid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 4edc0f67..5aa50438 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -169,7 +169,7 @@ add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_ } static void -h_can_invite(void *vdata) +h_hdl_invite(void *vdata) { hook_data_channel_approval *data = vdata; struct Client *source_p = data->client; @@ -218,7 +218,7 @@ h_hdl_privmsg_user(void *vdata) } static mapi_hfn_list_av1 um_callerid_hfnlist[] = { - { "can_invite", h_can_invite }, + { "invite", h_hdl_invite }, { "privmsg_user", h_hdl_privmsg_user }, { NULL, NULL } }; From fdff78f8912e225894af21622416cbf6f0cc9239 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 15:32:11 -0600 Subject: [PATCH 09/23] callerid: catch find_umode_slot() failures --- modules/um_callerid.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 5aa50438..f483dd47 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -42,12 +42,25 @@ #include "s_newconf.h" #include "hook.h" #include "supported.h" +#include "logger.h" static int um_callerid_modinit(void) { user_modes['g'] = find_umode_slot(); + if (!user_modes['g']) + { + ierror("um_callerid: unable to allocate usermode slot for +g; unloading module."); + return -1; + } + user_modes['G'] = find_umode_slot(); + if (!user_modes['G']) + { + ierror("um_callerid: unable to allocate usermode slot for +G; unloading module."); + return -1; + } + construct_umodebuf(); add_isupport("CALLERID", isupport_string, "g"); From c6edf6541145d22df3cf3bece1d72881ae69699e Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 26 Jun 2020 15:40:03 -0600 Subject: [PATCH 10/23] callerid: use hdata.error where available --- modules/um_callerid.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index f483dd47..1e8a7423 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -187,6 +187,7 @@ h_hdl_invite(void *vdata) hook_data_channel_approval *data = vdata; struct Client *source_p = data->client; struct Client *target_p = data->target; + static char errorbuf[BUFSIZE]; if (data->approved) return; @@ -200,9 +201,11 @@ h_hdl_invite(void *vdata) if (allow_message(source_p, target_p)) return; - send_callerid_notice(MESSAGE_TYPE_PRIVMSG, source_p, target_p); + snprintf(errorbuf, sizeof errorbuf, form_str(ERR_TARGUMODEG), + target_p->name); data->approved = ERR_TARGUMODEG; + data->error = errorbuf; } static void From 5419d3c286f0326e6dc4d88a8c14c561750631b0 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 10:54:31 +0000 Subject: [PATCH 11/23] help: document soft callerid mode --- help/opers/umode | 1 + help/users/umode | 1 + 2 files changed, 2 insertions(+) diff --git a/help/opers/umode b/help/opers/umode index e961a738..178752e6 100644 --- a/help/opers/umode +++ b/help/opers/umode @@ -18,6 +18,7 @@ User modes: (* designates that the umode is oper only) * +z - Can see operwalls. ? +C - Prevents you from receiving CTCPs other than ACTION. +D - Deaf - ignores all channel messages. + +G - Allow users with common channels to bypass "caller id" mode. +Q - Prevents you from being affected by channel forwarding. +R - Prevents unidentified users that you have not accepted from messaging you. diff --git a/help/users/umode b/help/users/umode index 71b01305..b3b5b444 100644 --- a/help/users/umode +++ b/help/users/umode @@ -13,6 +13,7 @@ User modes: (? designates that the umode is provided by an extension +w - Can see oper wallops. ? +C - Prevents you from receiving CTCPs other than ACTION. +D - Deaf - ignores all channel messages. + +G - Allow users with common channels to bypass "caller id" mode. +Q - Prevents you from being affected by channel forwarding. +R - Prevents unidentified users that you have not accepted from messaging you. From 915bb5614b1233148a4ec1d302ebd21d6451b7e4 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 15:59:44 +0000 Subject: [PATCH 12/23] callerid: unregister usermode +g if usermode +G cannot be allocated --- modules/um_callerid.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 1e8a7423..616ac87f 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -57,6 +57,8 @@ um_callerid_modinit(void) user_modes['G'] = find_umode_slot(); if (!user_modes['G']) { + user_modes['g'] = 0; + ierror("um_callerid: unable to allocate usermode slot for +G; unloading module."); return -1; } From 4d07382c2d7fc7188414ed3b8794792b67d40aa3 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 16:00:07 +0000 Subject: [PATCH 13/23] callerid: fix module description --- modules/um_callerid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 616ac87f..d63476d4 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -84,7 +84,7 @@ um_callerid_moddeinit(void) #define IsSetRelaxedCallerID(c) ((c->umodes & user_modes['G']) == user_modes['G']) static const char um_callerid_desc[] = - "Provides usermode +g which restricts messages from unauthorized users."; + "Provides usermodes +g and +G which restrict messages from unauthorized users."; static bool has_common_channel(struct Client *source_p, struct Client *target_p) From 5d4cce6cc05751106dcc7b94e80e603348c99294 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 16:01:58 +0000 Subject: [PATCH 14/23] callerid: has_common_channels(): fix return value --- modules/um_callerid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index d63476d4..08f90305 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -95,10 +95,10 @@ has_common_channel(struct Client *source_p, struct Client *target_p) { struct membership *msptr = ptr->data; if (IsMember(target_p, msptr->chptr)) - return msptr->chptr; + return true; } - return NULL; + return false; } static bool From 8906ffd1b78d8cb43acf65bcb7d36bc7481eee25 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 16:03:00 +0000 Subject: [PATCH 15/23] supported: make isupport_umode() public --- include/supported.h | 1 + ircd/supported.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/supported.h b/include/supported.h index 27d8e07a..2a77f095 100644 --- a/include/supported.h +++ b/include/supported.h @@ -44,5 +44,6 @@ extern const char *isupport_intptr(const void *); extern const char *isupport_boolean(const void *); extern const char *isupport_string(const void *); extern const char *isupport_stringptr(const void *); +extern const char *isupport_umode(const void *); #endif /* INCLUDED_supported_h */ diff --git a/ircd/supported.c b/ircd/supported.c index 3dbbcd66..35c6ea93 100644 --- a/ircd/supported.c +++ b/ircd/supported.c @@ -223,7 +223,7 @@ isupport_stringptr(const void *ptr) return *(char * const *)ptr; } -static const char * +const char * isupport_umode(const void *ptr) { const char *str; From 3ed61fba8c2b27ce783e79c3309a880f519bc273 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 16:03:52 +0000 Subject: [PATCH 16/23] callerid: use public isupport_umode --- modules/um_callerid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 08f90305..943b58a9 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -65,7 +65,7 @@ um_callerid_modinit(void) construct_umodebuf(); - add_isupport("CALLERID", isupport_string, "g"); + add_isupport("CALLERID", isupport_umode, "g"); return 0; } From 4841ad61978109e2b216c3833848b22cf280e0a8 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 16:10:29 +0000 Subject: [PATCH 17/23] callerid: only check the target's accept list on their own local server --- modules/um_callerid.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 943b58a9..bbe70d3c 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -154,6 +154,10 @@ send_callerid_notice(enum message_type msgtype, struct Client *source_p, struct static bool add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_p, struct Client *target_p) { + /* only do this on target_p's server */ + if (!MyClient(target_p)) + return true; + /* * XXX: Controversial? Allow target users to send replies * through a +g. Rationale is that people can presently use +g @@ -161,9 +165,9 @@ add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_ * as a way of griefing. --nenolod */ if(msgtype != MESSAGE_TYPE_NOTICE && - IsSetCallerID(source_p) && - !accept_message(target_p, source_p) && - !IsOper(target_p)) + IsSetCallerID(source_p) && + !accept_message(target_p, source_p) && + !IsOper(target_p)) { if(rb_dlink_list_length(&source_p->localClient->allow_list) < (unsigned long)ConfigFileEntry.max_accept) From 4abf8eb2e6066c1c1456f5978cd9a613992a468e Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 27 Jun 2020 16:13:03 +0000 Subject: [PATCH 18/23] callerid: actually the guard should be for source_p --- modules/um_callerid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index bbe70d3c..92c673b1 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -154,8 +154,8 @@ send_callerid_notice(enum message_type msgtype, struct Client *source_p, struct static bool add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_p, struct Client *target_p) { - /* only do this on target_p's server */ - if (!MyClient(target_p)) + /* only do this on source_p's server */ + if (!MyClient(source_p)) return true; /* From 92f5320e1de8b713efe4dbdc3d401f70d3576c6e Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Thu, 9 Jul 2020 16:04:56 -0600 Subject: [PATCH 19/23] message: run privmsg_user hook on both source and target --- modules/core/m_message.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/core/m_message.c b/modules/core/m_message.c index 227745d6..d146eab8 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -765,22 +765,22 @@ msg_client(enum message_type msgtype, sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), target_p->name, target_p->user->away); + hdata.msgtype = msgtype; + hdata.source_p = source_p; + hdata.target_p = target_p; + hdata.text = text; + hdata.approved = 0; + + call_hook(h_privmsg_user, &hdata); + + /* buffer location may have changed. */ + text = hdata.text; + + if (hdata.approved != 0) + return; + if(MyClient(target_p)) { - hdata.msgtype = msgtype; - hdata.source_p = source_p; - hdata.target_p = target_p; - hdata.text = text; - hdata.approved = 0; - - call_hook(h_privmsg_user, &hdata); - - /* buffer location may have changed. */ - text = hdata.text; - - if (hdata.approved != 0) - return; - if (EmptyString(text)) { /* could be empty after colour stripping and From b07445c6d96ae4002fcec19453e2e12aabe3812b Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 10 Jul 2020 18:06:51 -0600 Subject: [PATCH 20/23] extensions/umode_noctcp: skip privmsg_user hook except on recipient server --- extensions/umode_noctcp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions/umode_noctcp.c b/extensions/umode_noctcp.c index bb1b6490..0a485733 100644 --- a/extensions/umode_noctcp.c +++ b/extensions/umode_noctcp.c @@ -42,6 +42,9 @@ mapi_hfn_list_av1 umode_noctcp_hfnlist[] = { static void umode_noctcp_process(hook_data_privmsg_user *data) { + if (!MyClient(data->target_p)) + return; + if (data->approved || data->msgtype == MESSAGE_TYPE_NOTICE) { return; } From ace0c8655b772003299bd3c5fda319fdaaa49dab Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 10 Jul 2020 18:17:50 -0600 Subject: [PATCH 21/23] callerid: align soft caller-id behavior with ircd-hybrid implementation --- include/messages.h | 4 ++-- modules/um_callerid.c | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/messages.h b/include/messages.h index d37bf327..1fa36d82 100644 --- a/include/messages.h +++ b/include/messages.h @@ -217,9 +217,9 @@ #define NUMERIC_STR_713 "%s :Channel is open." #define NUMERIC_STR_714 ":%s 714 %s %s :You are already on that channel." #define NUMERIC_STR_715 ":%s 715 %s :KNOCKs are disabled." -#define NUMERIC_STR_716 "%s :is in +g mode (server-side ignore.)" +#define NUMERIC_STR_716 "%s :is in %s mode (server-side ignore.)" #define NUMERIC_STR_717 "%s :has been informed that you messaged them." -#define NUMERIC_STR_718 ":%s 718 %s %s %s@%s :is messaging you, and you have umode +g." +#define NUMERIC_STR_718 ":%s 718 %s %s %s@%s :is messaging you, and you have umode %s." #define NUMERIC_STR_720 ":%s 720 %s :Start of OPER MOTD" #define NUMERIC_STR_721 ":%s 721 %s :%s" #define NUMERIC_STR_722 ":%s 722 %s :End of OPER MOTD" diff --git a/modules/um_callerid.c b/modules/um_callerid.c index 92c673b1..cbd495de 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -80,8 +80,9 @@ um_callerid_moddeinit(void) delete_isupport("CALLERID"); } -#define IsSetCallerID(c) ((c->umodes & user_modes['g']) == user_modes['g']) +#define IsSetStrictCallerID(c) ((c->umodes & user_modes['g']) == user_modes['g']) #define IsSetRelaxedCallerID(c) ((c->umodes & user_modes['G']) == user_modes['G']) +#define IsSetAnyCallerID(c) (IsSetStrictCallerID(c) || IsSetRelaxedCallerID(c)) static const char um_callerid_desc[] = "Provides usermodes +g and +G which restrict messages from unauthorized users."; @@ -107,10 +108,10 @@ allow_message(struct Client *source_p, struct Client *target_p) if (!MyClient(target_p)) return true; - if (!IsSetCallerID(target_p)) + if (!IsSetAnyCallerID(target_p)) return true; - if (IsSetRelaxedCallerID(target_p) && has_common_channel(source_p, target_p)) + if (IsSetRelaxedCallerID(target_p) && has_common_channel(source_p, target_p) && !IsSetStrictCallerID(target_p)) return true; if (IsServer(source_p)) @@ -136,7 +137,7 @@ send_callerid_notice(enum message_type msgtype, struct Client *source_p, struct return; sendto_one_numeric(source_p, ERR_TARGUMODEG, form_str(ERR_TARGUMODEG), - target_p->name); + target_p->name, IsSetStrictCallerID(target_p) ? "+g" : "+G"); if ((target_p->localClient->last_caller_id_time + ConfigFileEntry.caller_id_wait) < rb_current_time()) { @@ -145,7 +146,7 @@ send_callerid_notice(enum message_type msgtype, struct Client *source_p, struct sendto_one(target_p, form_str(RPL_UMODEGMSG), me.name, target_p->name, source_p->name, - source_p->username, source_p->host); + source_p->username, source_p->host, IsSetStrictCallerID(target_p) ? "+g" : "+G"); target_p->localClient->last_caller_id_time = rb_current_time(); } @@ -165,7 +166,7 @@ add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_ * as a way of griefing. --nenolod */ if(msgtype != MESSAGE_TYPE_NOTICE && - IsSetCallerID(source_p) && + IsSetAnyCallerID(source_p) && !accept_message(target_p, source_p) && !IsOper(target_p)) { From c6e584dd1bd65da6a06e29288f339a91fb956815 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 10 Jul 2020 18:43:31 -0600 Subject: [PATCH 22/23] callerid: fix invite case --- modules/um_callerid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index cbd495de..afbd624b 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -209,7 +209,7 @@ h_hdl_invite(void *vdata) return; snprintf(errorbuf, sizeof errorbuf, form_str(ERR_TARGUMODEG), - target_p->name); + target_p->name, IsSetStrictCallerID(target_p) ? "+g" : "+G"); data->approved = ERR_TARGUMODEG; data->error = errorbuf; From 8ad8fd34f52c7b71790d179d4b3f3255b372e6e4 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 10 Jul 2020 21:25:25 -0600 Subject: [PATCH 23/23] callerid: fix a missed instance of hardcoded +g --- modules/um_callerid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/um_callerid.c b/modules/um_callerid.c index afbd624b..1e7a9e75 100644 --- a/modules/um_callerid.c +++ b/modules/um_callerid.c @@ -180,7 +180,7 @@ add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_ { sendto_one_numeric(source_p, ERR_OWNMODE, form_str(ERR_OWNMODE), - target_p->name, "+g"); + target_p->name, IsSetStrictCallerID(target_p) ? "+g" : "+G"); return false; } }