From febc4a45f30bf468d068a6d8b5c025c4e76c1525 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 8 Feb 2020 08:09:53 +0100 Subject: [PATCH] Updated labeled-response: drop the draft/ prefix now that the specification is ratified and also fix a serious flood bug in the implementation. Oh, and move the loadmodule line to the correct place in modules.default.conf. --- doc/RELEASE-NOTES.md | 14 ++++++---- doc/conf/modules.default.conf | 2 +- src/modules/batch.c | 15 +++++++--- src/modules/labeled-response.c | 51 ++++++++-------------------------- 4 files changed, 32 insertions(+), 50 deletions(-) diff --git a/doc/RELEASE-NOTES.md b/doc/RELEASE-NOTES.md index 64d04a498..af8436ca4 100644 --- a/doc/RELEASE-NOTES.md +++ b/doc/RELEASE-NOTES.md @@ -3,6 +3,12 @@ UnrealIRCd 5.0.3 Release Notes UnrealIRCd 5.0.3 ----------------- +Fixes: +* Fix serious flood issue in labeled-response implementation. +* An IRCOp SQUIT'ing a far remote server may cause a broken link topology +* In channels that are +D (delayed join), PARTs were not shown correctly to + channel operators. + Enhancements: * A new HISTORY command for history playback (```HISTORY #channel number-of-lines```) which allows you to fetch more lines than the on-join history playback. @@ -13,12 +19,10 @@ Enhancements: ```unrealircd.org/userip``` and ```unrealircd.org/userhost``` which communicate the user@ip and real user@host to IRCOps. -Fixes: -* An IRCOp SQUIT'ing a far remote server may cause a broken link topology -* In channels that are +D (delayed join), PARTs were not shown correctly to - channel operators. - Changes: +* Drop the draft/ prefix now that the IRCv3 + [labeled-response](https://ircv3.net/specs/extensions/labeled-response.html) + specification is out of draft. * The operclass permission ```immune:target-limit``` is now called ```immune:max-concurrent-conversations```, since it bypasses [set::anti-flood::max-concurrent-conversations](https://www.unrealircd.org/docs/Set_block#set::anti-flood::max-concurrent-conversations). diff --git a/doc/conf/modules.default.conf b/doc/conf/modules.default.conf index 8ae8d06ba..06de7eacd 100644 --- a/doc/conf/modules.default.conf +++ b/doc/conf/modules.default.conf @@ -205,6 +205,7 @@ loadmodule "plaintext-policy"; /* plaintext-policy announce */ loadmodule "server-time"; /* adds server timestamp to various messages */ loadmodule "sts"; /* strict transport policy (set::tls::sts-policy) */ loadmodule "echo-message"; /* shows clients if their messages are altered/filtered */ +loadmodule "labeled-response"; /* correlate requests and responses easily */ /*** Other ***/ @@ -224,6 +225,5 @@ loadmodule "rmtkl"; /* Easily remove *-Lines in bulk with /RMTKL */ loadmodule "restrict-commands"; /* Provides set::restrict-commands settings */ loadmodule "reputation"; /* used by Connthrottle and others, see next */ loadmodule "connthrottle"; /* see https://www.unrealircd.org/docs/Connthrottle */ -loadmodule "labeled-response"; /* currently in draft - loaded here to get it tested*/ loadmodule "userip-tag"; /* unrealircd.org/userip-tag for ircops */ loadmodule "userhost-tag"; /* unrealircd.org/userhost-tag for ircops */ diff --git a/src/modules/batch.c b/src/modules/batch.c index b18f2d4b9..e1ca1a8f1 100644 --- a/src/modules/batch.c +++ b/src/modules/batch.c @@ -93,10 +93,17 @@ CMD_FUNC(cmd_batch) if (MyConnect(target) && !IsServer(target) && !HasCapability(target, "batch")) return; - /* Relay the batch message to the client (or server) */ - parv[1] = "BATCH"; - concat_params(buf, sizeof(buf), parc, parv); - sendto_prefix_one(target, client, recv_mtags, "%s", buf); + if (MyUser(target)) + { + /* Send the batch message to the client */ + parv[1] = "BATCH"; + concat_params(buf, sizeof(buf), parc, parv); + sendto_prefix_one(target, client, recv_mtags, ":%s %s", client->name, buf); + } else { + /* Relay the batch message to the server */ + concat_params(buf, sizeof(buf), parc, parv); + sendto_prefix_one(target, client, recv_mtags, ":%s BATCH %s", client->name, buf); + } } /** This function verifies if the client sending diff --git a/src/modules/labeled-response.c b/src/modules/labeled-response.c index 1859fa05a..a32441ff0 100644 --- a/src/modules/labeled-response.c +++ b/src/modules/labeled-response.c @@ -39,7 +39,6 @@ struct LabeledResponseContext { char batch[BATCHLEN+1]; /**< The generated batch id */ int responses; /**< Number of lines sent back to client */ int sent_remote; /**< Command has been sent to remote server */ - int version; /**< Which version? Zero for official, non-zero is draft */ char firstbuf[4096]; /**< First buffered response */ }; @@ -84,11 +83,11 @@ MOD_INIT() memset(¤tcmd, 0, sizeof(currentcmd)); memset(&cap, 0, sizeof(cap)); - cap.name = "draft/labeled-response-0.2"; + cap.name = "labeled-response"; c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_LABELED_RESPONSE); memset(&mtag, 0, sizeof(mtag)); - mtag.name = "draft/label"; + mtag.name = "label"; mtag.is_ok = labeled_response_mtag_is_ok; mtag.clicap_handler = c; MessageTagHandlerAdd(modinfo->handle, &mtag); @@ -115,12 +114,13 @@ int lr_pre_command(Client *from, MessageTag *mtags, char *buf) memset(¤tcmd, 0, sizeof(currentcmd)); labeled_response_inhibit = labeled_response_inhibit_end = labeled_response_force = 0; + if (IsServer(from)) + return 0; + for (; mtags; mtags = mtags->next) { - if ((!strcmp(mtags->name, "draft/label") || !strcmp(mtags->name, "label")) && mtags->value) + if (!strcmp(mtags->name, "label") && mtags->value) { - if (!strcmp(mtags->name, "draft/label")) - currentcmd.version = -1; strlcpy(currentcmd.label, mtags->value, sizeof(currentcmd.label)); currentcmd.client = from; break; @@ -130,30 +130,6 @@ int lr_pre_command(Client *from, MessageTag *mtags, char *buf) return 0; } -char *labeled_response_tag_type(int version) -{ - if (version == 0) - return "label"; - else - return "draft/label"; -} - -char *labeled_response_batch_type(int version) -{ - if (version == 0) - return "labeled-response"; - else - return "draft/labeled-response"; -} - -char *labeled_response_message_tag(int version) -{ - if (version == 0) - return "label"; - else - return "draft/label"; -} - char *gen_start_batch(void) { static char buf[512]; @@ -163,21 +139,17 @@ char *gen_start_batch(void) if (MyConnect(currentcmd.client)) { /* Local connection */ - snprintf(buf, sizeof(buf), "@%s=%s :%s BATCH +%s %s", - labeled_response_message_tag(currentcmd.version), + snprintf(buf, sizeof(buf), "@label=%s :%s BATCH +%s labeled-response", currentcmd.label, me.name, - currentcmd.batch, - labeled_response_batch_type(currentcmd.version)); + currentcmd.batch); } else { /* Remote connection: requires intra-server BATCH syntax */ - snprintf(buf, sizeof(buf), "@%s=%s :%s BATCH %s +%s %s", - labeled_response_message_tag(currentcmd.version), + snprintf(buf, sizeof(buf), "@label=%s :%s BATCH %s +%s labeled-response", currentcmd.label, me.name, currentcmd.client->name, - currentcmd.batch, - labeled_response_batch_type(currentcmd.version)); + currentcmd.batch); } return buf; } @@ -222,8 +194,7 @@ int lr_post_command(Client *from, MessageTag *mtags, char *buf) int more_tags = currentcmd.firstbuf[0] == '@'; currentcmd.client = NULL; /* prevent lr_packet from interfering */ snprintf(packet, sizeof(packet), - "@%s=%s%s%s\r\n", - labeled_response_tag_type(currentcmd.version), + "@label=%s%s%s\r\n", currentcmd.label, more_tags ? ";" : " ", more_tags ? currentcmd.firstbuf+1 : currentcmd.firstbuf);