From e9e2504bf4c49b17c0c8981cd761b90080426ccf Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 25 Jun 2021 11:16:12 +0200 Subject: [PATCH] Don't allow remote servers to write to our MD client objects by default. Modules can still opt-in via mreq.remote_write=1 to allow it for certain moddata. For example, k4be may want to do this for his geoip-base module which allows a single server to set moddata "geoip" for all connecting clients, including remote clients. If you are a moddata provider then you can enable it like this: ModDataInfo mreq; [..] #if UNREAL_VERSION_TIME >= 202125 mreq.remote_write = 1; #endif [..] See discussion on https://github.com/unrealircd/unrealircd/pull/142 --- include/modules.h | 1 + include/version.h | 2 +- src/api-moddata.c | 1 + src/modules/md.c | 22 ++++++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/modules.h b/include/modules.h index 5bd22ec8d..e446b6beb 100644 --- a/include/modules.h +++ b/include/modules.h @@ -151,6 +151,7 @@ struct ModDataInfo { char *(*serialize)(ModData *m); /**< Function which converts the data to a string. May return NULL if 'm' contains no data (since for example m->ptr may be NULL). */ void (*unserialize)(char *str, ModData *m); /**< Function which converts the string back to data */ int sync; /**< Send in netsynch (when servers connect) */ + int remote_write; /**< Allow remote servers to set/unset this moddata, even if it they target one of our own clients */ }; #define moddata_client(acptr, md) acptr->moddata[md->slot] diff --git a/include/version.h b/include/version.h index 281fdf93b..9e44370ae 100644 --- a/include/version.h +++ b/include/version.h @@ -54,7 +54,7 @@ * Can be useful if the above 3 versionids are insufficient for you (eg: you want to support CVS). * This is updated automatically on the CVS server every Monday. so don't touch it. */ -#define UNREAL_VERSION_TIME 202120 +#define UNREAL_VERSION_TIME 202125 #define UnrealProtocol 5002 #define PATCH1 macro_to_str(UNREAL_VERSION_GENERATION) diff --git a/src/api-moddata.c b/src/api-moddata.c index 84be03b74..919bce8fb 100644 --- a/src/api-moddata.c +++ b/src/api-moddata.c @@ -80,6 +80,7 @@ moddataadd_isok: m->serialize = req.serialize; m->unserialize = req.unserialize; m->sync = req.sync; + m->remote_write = req.remote_write; m->owner = module; if (new_struct) diff --git a/src/modules/md.c b/src/modules/md.c index 485e8a4b0..0ac8e3a82 100644 --- a/src/modules/md.c +++ b/src/modules/md.c @@ -105,6 +105,14 @@ CMD_FUNC(cmd_md) md = findmoddata_byname(varname, MODDATATYPE_CLIENT); if (!md || !md->unserialize || !target) return; + + if (MyConnect(target) && !md->remote_write) + { + ircd_log(LOG_ERROR, "Remote server '%s' tried to write moddata '%s' of a client from ours '%s' -- attempt blocked.", + client->name, md->name, target->name); + return; + } + if (value) md->unserialize(value, &moddata_client(target, md)); else @@ -162,6 +170,13 @@ CMD_FUNC(cmd_md) if (!md || !md->unserialize) return; + if (MyConnect(target) && !md->remote_write) + { + ircd_log(LOG_ERROR, "Remote server '%s' tried to write moddata '%s' of a client from ours '%s' -- attempt blocked.", + client->name, md->name, target->name); + return; + } + if (value) md->unserialize(value, &moddata_member(m, md)); else @@ -202,6 +217,13 @@ CMD_FUNC(cmd_md) if (!md || !md->unserialize) return; + if (MyConnect(target) && !md->remote_write) + { + ircd_log(LOG_ERROR, "Remote server '%s' tried to write moddata '%s' of a client from ours '%s' -- attempt blocked.", + client->name, md->name, target->name); + return; + } + if (value) md->unserialize(value, &moddata_membership(m, md)); else