From ec42501899cc356f56eae834c8111d5ee8d223dc Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Mon, 25 Oct 2021 09:30:34 +0200 Subject: [PATCH 1/6] Fix net-type check/handling, fatal() only during bot startup --- src/mod/server.mod/server.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/server.mod/server.c b/src/mod/server.mod/server.c index 702735071..014df5682 100644 --- a/src/mod/server.mod/server.c +++ b/src/mod/server.mod/server.c @@ -1563,10 +1563,14 @@ static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, else if (!strcasecmp(net_type, "5")) { /* For backwards compatibility */ net_type_int = NETT_OTHER; warn = 1; - } else { + } else if (!online_since) { fatal("ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, EFnet, freenode, " "Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", 0); } + else + putlog(LOG_MISC, "*", "ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, " + "EFnet, freenode, Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", + 0); if (warn) { putlog(LOG_MISC, "*", "INFO: The config setting for \"net-type\" has transitioned from a number\n" From 5abb9b3f7bcd2242e76d21273c282e69efaef294 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 30 Oct 2021 02:52:02 +0200 Subject: [PATCH 2/6] fix #1218, trace net-type only in irc.mod and call from there into server.mod --- src/mod/irc.mod/irc.c | 67 +++++++++++++++++++++++++++--- src/mod/server.mod/server.c | 83 +++---------------------------------- src/mod/server.mod/server.h | 4 +- 3 files changed, 70 insertions(+), 84 deletions(-) diff --git a/src/mod/irc.mod/irc.c b/src/mod/irc.mod/irc.c index 82b2862b9..5ba1ac858 100644 --- a/src/mod/irc.mod/irc.c +++ b/src/mod/irc.mod/irc.c @@ -1102,7 +1102,7 @@ static void irc_report(int idx, int details) * they support max_modes. If they support max_modes, set each of * other sub-max settings equal to max_modes */ -static void do_nettype() +static void do_nettype_irc() { switch (net_type_int) { case NETT_EFNET: @@ -1230,13 +1230,70 @@ static void do_nettype() } /* Update all rfc_ function pointers */ add_hook(HOOK_RFC_CASECMP, (Function) (intptr_t) rfc_compliant); + do_nettype_server(); } static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, EGG_CONST char *name1, EGG_CONST char *name2, int flags) { - do_nettype(); + const char *value; + int warn = 0; + + value = Tcl_GetVar2(irp, name1, name2, TCL_GLOBAL_ONLY); + if (!strcasecmp(value, "DALnet")) + net_type_int = NETT_DALNET; + else if (!strcasecmp(value, "EFnet")) + net_type_int = NETT_EFNET; + else if (!strcasecmp(value, "freenode")) + net_type_int = NETT_FREENODE; + else if (!strcasecmp(value, "IRCnet")) + net_type_int = NETT_IRCNET; + else if (!strcasecmp(value, "Libera")) + net_type_int = NETT_LIBERA; + else if (!strcasecmp(value, "QuakeNet")) + net_type_int = NETT_QUAKENET; + else if (!strcasecmp(value, "Rizon")) + net_type_int = NETT_RIZON; + else if (!strcasecmp(value, "Undernet")) + net_type_int = NETT_UNDERNET; + else if (!strcasecmp(value, "Twitch")) + net_type_int = NETT_TWITCH; + else if (!strcasecmp(value, "Other")) + net_type_int = NETT_OTHER; + else if (!strcasecmp(value, "0")) { /* For backwards compatibility */ + net_type_int = NETT_EFNET; + warn = 1; + } else if (!strcasecmp(value, "1")) { /* For backwards compatibility */ + net_type_int = NETT_IRCNET; + warn = 1; + } else if (!strcasecmp(value, "2")) { /* For backwards compatibility */ + net_type_int = NETT_UNDERNET; + warn = 1; + } else if (!strcasecmp(value, "3")) { /* For backwards compatibility */ + net_type_int = NETT_DALNET; + warn = 1; + } else if (!strcasecmp(value, "4")) { /* For backwards compatibility */ + net_type_int = NETT_HYBRID_EFNET; + warn = 1; + } else if (!strcasecmp(value, "5")) { /* For backwards compatibility */ + net_type_int = NETT_OTHER; + warn = 1; + } else if (!online_since) { + fatal("ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, EFnet, freenode, " + "Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", 0); + } else + putlog(LOG_MISC, "*", "ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, " + "EFnet, freenode, Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", + 0); + if (warn) { + putlog(LOG_MISC, "*", + "INFO: The config setting for \"net-type\" has transitioned from a number\n" + "to a text string. Please update your choice to one of the allowed values\n" + "listed in the current configuration file from the source directory\n"); + } + strlcpy(net_type, value, sizeof net_type); + do_nettype_irc(); return NULL; } @@ -1298,7 +1355,7 @@ static char *irc_close() TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_rfccompliant, NULL); Tcl_UntraceVar(interp, "net-type", - TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, + TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_nettype, NULL); module_undepend(MODULE_NAME); return NULL; @@ -1383,7 +1440,7 @@ char *irc_start(Function *global_funcs) add_hook(HOOK_ADD_MODE, (Function) real_add_mode); add_hook(HOOK_IDLE, (Function) flush_modes); Tcl_TraceVar(interp, "net-type", - TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, + TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_nettype, NULL); Tcl_TraceVar(interp, "rfc-compliant", TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, @@ -1413,6 +1470,6 @@ char *irc_start(Function *global_funcs) H_need = add_bind_table("need", HT_STACKABLE, channels_2char); H_ircaway = add_bind_table("ircaway", HT_STACKABLE, channels_5char); H_monitor = add_bind_table("monitor", HT_STACKABLE, monitor_2char); - do_nettype(); + do_nettype_irc(); return NULL; } diff --git a/src/mod/server.mod/server.c b/src/mod/server.mod/server.c index 014df5682..b1554451b 100644 --- a/src/mod/server.mod/server.c +++ b/src/mod/server.mod/server.c @@ -1457,7 +1457,7 @@ static char *traced_botname(ClientData cdata, Tcl_Interp *irp, return NULL; } -static void do_nettype(void) +void do_nettype_server() { switch (net_type_int) { case NETT_EFNET: @@ -1514,73 +1514,6 @@ static void do_nettype(void) } } -static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, - EGG_CONST char *name1, - EGG_CONST char *name2, int flags) -{ - int warn = 0; - - if (!strcasecmp(net_type, "DALnet")) - net_type_int = NETT_DALNET; - else if (!strcasecmp(net_type, "EFnet")) - net_type_int = NETT_EFNET; - else if (!strcasecmp(net_type, "freenode")) - net_type_int = NETT_FREENODE; - else if (!strcasecmp(net_type, "IRCnet")) - net_type_int = NETT_IRCNET; - else if (!strcasecmp(net_type, "Libera")) - net_type_int = NETT_LIBERA; - else if (!strcasecmp(net_type, "QuakeNet")) - net_type_int = NETT_QUAKENET; - else if (!strcasecmp(net_type, "Rizon")) - net_type_int = NETT_RIZON; - else if (!strcasecmp(net_type, "Undernet")) - net_type_int = NETT_UNDERNET; - else if (!strcasecmp(net_type, "Twitch")) - net_type_int = NETT_TWITCH; - else if (!strcasecmp(net_type, "Other")) - net_type_int = NETT_OTHER; - else if (!strcasecmp(net_type, "0")) { /* For backwards compatibility */ - net_type_int = NETT_EFNET; - warn = 1; - } - else if (!strcasecmp(net_type, "1")) { /* For backwards compatibility */ - net_type_int = NETT_IRCNET; - warn = 1; - } - else if (!strcasecmp(net_type, "2")) { /* For backwards compatibility */ - net_type_int = NETT_UNDERNET; - warn = 1; - } - else if (!strcasecmp(net_type, "3")) { /* For backwards compatibility */ - net_type_int = NETT_DALNET; - warn = 1; - } - else if (!strcasecmp(net_type, "4")) { /* For backwards compatibility */ - net_type_int = NETT_HYBRID_EFNET; - warn = 1; - } - else if (!strcasecmp(net_type, "5")) { /* For backwards compatibility */ - net_type_int = NETT_OTHER; - warn = 1; - } else if (!online_since) { - fatal("ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, EFnet, freenode, " - "Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", 0); - } - else - putlog(LOG_MISC, "*", "ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, " - "EFnet, freenode, Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", - 0); - if (warn) { - putlog(LOG_MISC, "*", - "INFO: The config setting for \"net-type\" has transitioned from a number\n" - "to a text string. Please update your choice to one of the allowed values\n" - "listed in the current configuration file from the source directory\n"); - } - do_nettype(); - return NULL; -} - static char *traced_nicklen(ClientData cdata, Tcl_Interp *irp, EGG_CONST char *name1, EGG_CONST char *name2, int flags) @@ -2149,9 +2082,6 @@ static char *server_close() Tcl_UntraceVar(interp, "serveraddress", TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_serveraddress, NULL); - Tcl_UntraceVar(interp, "net-type", - TCL_TRACE_WRITES | TCL_TRACE_UNSETS, - traced_nettype, NULL); Tcl_UntraceVar(interp, "nick-len", TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_nicklen, NULL); @@ -2234,8 +2164,10 @@ static Function server_table[] = { (Function) & account_notify, /* int */ (Function) & H_isupport, /* p_tcl_bind_list */ (Function) & isupport_get, /* */ - /* 48 - 52 */ - (Function) & isupport_parseint/* */ + /* 48 - 51 */ + (Function) & isupport_parseint, + (Function) do_nettype_server, + (Function) & net_type /* int */ }; char *server_start(Function *global_funcs) @@ -2329,9 +2261,6 @@ char *server_start(Function *global_funcs) Tcl_TraceVar(interp, "serveraddress", TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_serveraddress, NULL); - Tcl_TraceVar(interp, "net-type", - TCL_TRACE_WRITES | TCL_TRACE_UNSETS, - traced_nettype, NULL); Tcl_TraceVar(interp, "nick-len", TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS, traced_nicklen, NULL); @@ -2394,7 +2323,5 @@ char *server_start(Function *global_funcs) newserver[0] = 0; newserverport = 0; curserv = 999; - /* Because this reads the interp variable, the read trace MUST be after */ - do_nettype(); return NULL; } diff --git a/src/mod/server.mod/server.h b/src/mod/server.mod/server.h index 736f592da..7121317fa 100644 --- a/src/mod/server.mod/server.h +++ b/src/mod/server.mod/server.h @@ -93,8 +93,10 @@ #define account_notify (*(int *)(server_funcs[45])) #define H_isupport (*(p_tcl_bind_list *)(server_funcs[46])) #define isupport_get ((struct isupport *(*)(const char *, size_t))(server_funcs[47])) -/* 48 - 52 */ +/* 48 - 51 */ #define isupport_parseint ((int (*)(const char *, const char *, int, int, int, int, int *))(server_funcs[48])) +#define do_nettype_server ((void (*) (void))server_funcs[49]) +#define net_type ((char *)(server_funcs[50])) #endif /* MAKING_SERVER */ struct server_list { From e99a8225f5839c805a728837d76ed178b549f3be Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:09:20 +0200 Subject: [PATCH 3/6] fix error handling --- src/mod/irc.mod/irc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mod/irc.mod/irc.c b/src/mod/irc.mod/irc.c index 5ba1ac858..3ea2d76be 100644 --- a/src/mod/irc.mod/irc.c +++ b/src/mod/irc.mod/irc.c @@ -1283,9 +1283,8 @@ static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, fatal("ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, EFnet, freenode, " "Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", 0); } else - putlog(LOG_MISC, "*", "ERROR: NET-TYPE NOT SET.\n Must be one of DALNet, " - "EFnet, freenode, Libera, IRCnet, Quakenet, Rizon, Undernet, Other.", - 0); + return("Must be one of DALNet, EFnet, freenode, Libera, IRCnet, Quakenet, " + "Rizon, Undernet, Other."); if (warn) { putlog(LOG_MISC, "*", "INFO: The config setting for \"net-type\" has transitioned from a number\n" From 9829fdd55761e8a4943f6cb4d6e73f9489ccdaac Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 30 Oct 2021 13:13:01 +0200 Subject: [PATCH 4/6] cleanup --- src/mod/irc.mod/irc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mod/irc.mod/irc.c b/src/mod/irc.mod/irc.c index 3ea2d76be..5f6fa81cc 100644 --- a/src/mod/irc.mod/irc.c +++ b/src/mod/irc.mod/irc.c @@ -1291,7 +1291,6 @@ static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, "to a text string. Please update your choice to one of the allowed values\n" "listed in the current configuration file from the source directory\n"); } - strlcpy(net_type, value, sizeof net_type); do_nettype_irc(); return NULL; } From e4fd7d8bb4bef2a57f2c086abac23d2955a4af71 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 30 Oct 2021 13:20:19 +0200 Subject: [PATCH 5/6] cleanup --- src/mod/server.mod/server.c | 3 +-- src/mod/server.mod/server.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mod/server.mod/server.c b/src/mod/server.mod/server.c index b1554451b..8ef3b2b33 100644 --- a/src/mod/server.mod/server.c +++ b/src/mod/server.mod/server.c @@ -2166,8 +2166,7 @@ static Function server_table[] = { (Function) & isupport_get, /* */ /* 48 - 51 */ (Function) & isupport_parseint, - (Function) do_nettype_server, - (Function) & net_type /* int */ + (Function) do_nettype_server }; char *server_start(Function *global_funcs) diff --git a/src/mod/server.mod/server.h b/src/mod/server.mod/server.h index 7121317fa..24c121b1b 100644 --- a/src/mod/server.mod/server.h +++ b/src/mod/server.mod/server.h @@ -96,7 +96,6 @@ /* 48 - 51 */ #define isupport_parseint ((int (*)(const char *, const char *, int, int, int, int, int *))(server_funcs[48])) #define do_nettype_server ((void (*) (void))server_funcs[49]) -#define net_type ((char *)(server_funcs[50])) #endif /* MAKING_SERVER */ struct server_list { From 5bee0586f883d573ab70b523eb881ff3ea8405e2 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 30 Oct 2021 23:09:04 +0200 Subject: [PATCH 6/6] fix --- src/mod/irc.mod/irc.c | 2 +- src/mod/server.mod/server.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mod/irc.mod/irc.c b/src/mod/irc.mod/irc.c index 5f6fa81cc..b718397cc 100644 --- a/src/mod/irc.mod/irc.c +++ b/src/mod/irc.mod/irc.c @@ -1230,7 +1230,6 @@ static void do_nettype_irc() } /* Update all rfc_ function pointers */ add_hook(HOOK_RFC_CASECMP, (Function) (intptr_t) rfc_compliant); - do_nettype_server(); } static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, @@ -1292,6 +1291,7 @@ static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, "listed in the current configuration file from the source directory\n"); } do_nettype_irc(); + do_nettype_server(); return NULL; } diff --git a/src/mod/server.mod/server.c b/src/mod/server.mod/server.c index 8ef3b2b33..08cbeb541 100644 --- a/src/mod/server.mod/server.c +++ b/src/mod/server.mod/server.c @@ -74,8 +74,8 @@ static int exclusive_binds; /* configures PUBM and MSGM binds to be static int answer_ctcp; /* answer how many stacked ctcp's ? */ static int lowercase_ctcp; /* answer lowercase CTCP's (non-standard) */ static int check_mode_r; /* check for IRCnet +r modes */ -static char net_type[9]; -static int net_type_int; +static char net_type[9] = "EFnet"; +static int net_type_int = NETT_EFNET; static char connectserver[121]; /* what, if anything, to do before connect * to the server */ static int resolvserv; /* in the process of resolving a server host */ @@ -2212,7 +2212,6 @@ char *server_start(Function *global_funcs) check_mode_r = 0; maxqmsg = 300; burst = 0; - strlcpy(net_type, "EFnet", sizeof net_type); double_mode = 0; double_server = 0; double_help = 0; @@ -2322,5 +2321,6 @@ char *server_start(Function *global_funcs) newserver[0] = 0; newserverport = 0; curserv = 999; + do_nettype_server(); return NULL; }