diff --git a/src/modules.c b/src/modules.c index d802ee287..f1c8f347b 100644 --- a/src/modules.c +++ b/src/modules.c @@ -364,6 +364,33 @@ char *Module_GetRelPath(char *fullpath) return buf; } +/** Validate a modules' ModuleHeader. + * @returns Error message is returned, or NULL if everything is OK. + */ +static char *validate_mod_header(ModuleHeader *mod_header) +{ + char *p; + + if (!mod_header->name || !mod_header->version || !mod_header->author || !mod_header->description) + return "NULL values encountered in Mod_Header struct members"; + + /* Validate module name */ + for (p = mod_header->name; *p; p++) + if (!isalnum(*p) && !strchr("._-/", *p)) + return "ModuleHeader.name contains illegal characters (must be: a-zA-Z0-9._-/)"; + + /* Validate version, even more strict */ + if (!isdigit(mod_header->version[0])) + return "ModuleHeader.version must start with a digit"; + for (p = mod_header->version; *p; p++) + if (!isalnum(*p) && !strchr("._-", *p)) + return "ModuleHeader.version contains illegal characters (must be: a-zA-Z0-9._-)"; + + /* Author and description are not checked, has no constraints */ + + return NULL; /* SUCCESS */ +} + /* * Returns an error if insucessful .. yes NULL is OK! */ @@ -384,6 +411,7 @@ char *Module_Create(char *path_) char *path, *tmppath; ModuleHeader *mod_header = NULL; int ret = 0; + char *reterr; Module *mod = NULL, **Mod_Handle = NULL; char *expectedmodversion = our_mod_version; unsigned int expectedcompilerversion = our_compiler_version; @@ -466,12 +494,11 @@ char *Module_Create(char *path_) remove(tmppath); return(errorbuf); } - if (!mod_header->name || !mod_header->version || - !mod_header->description) + if ((reterr = validate_mod_header(mod_header))) { irc_dlclose(Mod); remove(tmppath); - return("Lacking sane header pointer"); + return(reterr); } if (Module_Find(mod_header->name)) { @@ -887,9 +914,9 @@ CMD_FUNC(m_module) return 0; if (all) - sendnotice(sptr, "Showing ALL loaded modules:"); + sendtxtnumeric(sptr, "Showing ALL loaded modules:"); else - sendnotice(sptr, "Showing loaded 3rd party modules (use \"MODULE -all\" to show all modules):"); + sendtxtnumeric(sptr, "Showing loaded 3rd party modules (use \"MODULE -all\" to show all modules):"); for (mi = Modules; mi; mi = mi->next) { @@ -907,15 +934,21 @@ CMD_FUNC(m_module) if (!(mi->options & MOD_OPT_OFFICIAL)) strlcat(tmp, "[3RD] ", sizeof(tmp)); if (!ValidatePermissionsForPath("server:module",sptr,NULL,NULL,NULL)) - sendnotice(sptr, "*** %s (%s)%s", - mi->header->name, mi->header->description, - mi->options & MOD_OPT_OFFICIAL ? "" : " [3RD]"); + sendtxtnumeric(sptr, "*** %s - %s - by %s %s", + mi->header->name, + mi->header->description, + mi->header->author, + mi->options & MOD_OPT_OFFICIAL ? "" : "[3RD]"); else - sendnotice(sptr, "*** %s - %s (%s) %s", - mi->header->name, mi->header->version, mi->header->description, tmp); + sendtxtnumeric(sptr, "*** %s %s - %s - by %s %s", + mi->header->name, + mi->header->version, + mi->header->description, + mi->header->author, + tmp); } - sendnotice(sptr, "End of module list"); + sendtxtnumeric(sptr, "End of module list"); if (!ValidatePermissionsForPath("server:module",sptr,NULL,NULL,NULL)) return 0; @@ -930,12 +963,12 @@ CMD_FUNC(m_module) p += strlen(p); if (p > tmp + 380) { - sendnotice(sptr, "Hooks: %s", tmp); + sendtxtnumeric(sptr, "Hooks: %s", tmp); tmp[0] = '\0'; p = tmp; } } - sendnotice(sptr, "Hooks: %s ", tmp); + sendtxtnumeric(sptr, "Hooks: %s ", tmp); tmp[0] = '\0'; p = tmp; @@ -948,20 +981,20 @@ CMD_FUNC(m_module) p += strlen(p); if (p > tmp+380) { - sendnotice(sptr, "Override: %s", tmp); + sendtxtnumeric(sptr, "Override: %s", tmp); tmp[0] = '\0'; p = tmp; } } } - sendnotice(sptr, "Override: %s", tmp); + sendtxtnumeric(sptr, "Override: %s", tmp); #ifdef DEBUGMODE - sendnotice(sptr, "Efunctions dump:"); + sendtxtnumeric(sptr, "Efunctions dump:"); for (i=0; i < MAXEFUNCTIONS; i++) if ((e = Efunctions[i])) { - sendnotice(sptr, "type=%d, name=%s, pointer=%p %s, owner=%s", + sendtxtnumeric(sptr, "type=%d, name=%s, pointer=%p %s, owner=%s", e->type, efunction_table[e->type].name ? efunction_table[e->type].name : "", e->func.voidfunc, diff --git a/src/modules/antirandom.c b/src/modules/antirandom.c index 03f99fd61..74510d50d 100644 --- a/src/modules/antirandom.c +++ b/src/modules/antirandom.c @@ -36,8 +36,8 @@ ModuleHeader MOD_HEADER(antirandom) = { "antirandom", - "v1.4", - "Randomness detector", + "1.4", + "Detect and ban users with random names", "UnrealIRCd Team", "unrealircd-5", }; diff --git a/src/modules/chanmodes/delayjoin.c b/src/modules/chanmodes/delayjoin.c index 07c715108..03ae3840e 100644 --- a/src/modules/chanmodes/delayjoin.c +++ b/src/modules/chanmodes/delayjoin.c @@ -8,7 +8,7 @@ ModuleHeader MOD_HEADER(delayjoin) = { "delayjoin", /* Name of module */ - "v0.0.1", /* Version */ + "5.0", /* Version */ "delayed join (+D,+d)", /* Short description of module */ "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/chanmodes/floodprot.c b/src/modules/chanmodes/floodprot.c index fa3bacdd8..bcd5fdef4 100644 --- a/src/modules/chanmodes/floodprot.c +++ b/src/modules/chanmodes/floodprot.c @@ -22,7 +22,7 @@ ModuleHeader MOD_HEADER(floodprot) = { "chanmodes/floodprot", - "$Id: floodprot.c,v 1.2 2019/08/10 syzop Exp $", + "5.0", "Channel Mode +f", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/channeldb.c b/src/modules/channeldb.c index 7741d8670..a725040c7 100644 --- a/src/modules/channeldb.c +++ b/src/modules/channeldb.c @@ -6,6 +6,14 @@ #include "unrealircd.h" +ModuleHeader MOD_HEADER(channeldb) = { + "channeldb", + "1.0", + "Stores and retrieves channel settings for persistent (+P) channels", + "UnrealIRCd Team", + "unrealircd-5", +}; + #define CHANNELDB_VERSION 100 #define CHANNELDB_SAVE_EVERY 299 @@ -61,14 +69,6 @@ static struct cfgstruct cfg; static int channeldb_loaded = 0; -ModuleHeader MOD_HEADER(channeldb) = { - "channeldb", - "v1.0", - "Stores and retrieves channel settings for persistent (+P) channels", - "UnrealIRCd Team", - "unrealircd-5", -}; - MOD_TEST(channeldb) { memset(&cfg, 0, sizeof(cfg)); diff --git a/src/modules/cloak.c b/src/modules/cloak.c index cd09b8322..862129de6 100644 --- a/src/modules/cloak.c +++ b/src/modules/cloak.c @@ -50,7 +50,7 @@ Callback *cloak = NULL, *cloak_csum = NULL; ModuleHeader MOD_HEADER(cloak) = { "cloak", - "v1.0", + "1.0", "Official cloaking module (md5)", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/extbans/textban.c b/src/modules/extbans/textban.c index 34959d259..3c4957a58 100644 --- a/src/modules/extbans/textban.c +++ b/src/modules/extbans/textban.c @@ -73,7 +73,7 @@ ModuleHeader MOD_HEADER(textban) = { "textban", - "v2.2", + "2.2", "ExtBan ~T (textban) by Syzop", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/extbans/timedban.c b/src/modules/extbans/timedban.c index 9d00c425d..af9f94c0c 100644 --- a/src/modules/extbans/timedban.c +++ b/src/modules/extbans/timedban.c @@ -23,8 +23,6 @@ #include "unrealircd.h" -#define TIMEDBAN_VERSION "v1.0" - /* Maximum time (in minutes) for a ban */ #define TIMEDBAN_MAX_TIME 9999 @@ -50,7 +48,7 @@ ModuleHeader MOD_HEADER(timedban) = { "timedban", - TIMEDBAN_VERSION, + "1.0", "ExtBan ~t: automatically removed timed bans", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/ircops.c b/src/modules/ircops.c index e1192e28d..ff9f253fd 100644 --- a/src/modules/ircops.c +++ b/src/modules/ircops.c @@ -28,7 +28,7 @@ CMD_FUNC(m_ircops); ModuleHeader MOD_HEADER(ircops) = { "ircops", - "v3.71", + "3.71", "/IRCOPS command that lists IRC Operators", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/jumpserver.c b/src/modules/jumpserver.c index b70765bfb..2bd7ab0ad 100644 --- a/src/modules/jumpserver.c +++ b/src/modules/jumpserver.c @@ -22,7 +22,7 @@ ModuleHeader MOD_HEADER(jumpserver) = { "jumpserver", - "v1.1", + "1.1", "/jumpserver command", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/nocodes.c b/src/modules/nocodes.c index 67de1e751..87a16af14 100644 --- a/src/modules/nocodes.c +++ b/src/modules/nocodes.c @@ -20,14 +20,12 @@ #include "unrealircd.h" -#define NOCODES_VERSION "v1.2" - ModuleHeader MOD_HEADER(nocodes) = { "nocodes", /* Name of module */ - NOCODES_VERSION, /* Version */ + "1.2", /* Version */ "Strip/block bold/underline/reverse - by Syzop", /* Short description of module */ - "UnrealIRCd Team", + "UnrealIRCd Team", /* Author */ "unrealircd-5", }; diff --git a/src/modules/restrict-commands.c b/src/modules/restrict-commands.c index 39b9e44cc..d2afd894e 100644 --- a/src/modules/restrict-commands.c +++ b/src/modules/restrict-commands.c @@ -19,6 +19,14 @@ #include "unrealircd.h" +ModuleHeader MOD_HEADER(restrict-commands) = { + "restrict-commands", + "1.0", + "Restrict specific commands unless certain conditions have been met", + "UnrealIRCd Team", + "unrealircd-5", +}; + #define GetReputation(acptr) (moddata_client_get(acptr, "reputation") ? atoi(moddata_client_get(acptr, "reputation")) : 0) typedef struct restrictedcmd RestrictedCmd; @@ -60,14 +68,6 @@ CmdMap conf_cmdmaps[] = { { NULL, NULL, }, // REQUIRED for the loop to properly work }; -ModuleHeader MOD_HEADER(restrict-commands) = { - "restrict-commands", - "v1.0", - "Restrict specific commands unless certain conditions have been met", - "UnrealIRCd Team", - "unrealircd-5", -}; - MOD_TEST(restrict-commands) { memcpy(&ModInf, modinfo, modinfo->size); diff --git a/src/modules/rmtkl.c b/src/modules/rmtkl.c index e94d04636..51679e5ee 100644 --- a/src/modules/rmtkl.c +++ b/src/modules/rmtkl.c @@ -19,6 +19,14 @@ #include "unrealircd.h" +ModuleHeader MOD_HEADER(rmtkl) = { + "rmtkl", + "1.4", + "Adds /rmtkl command to easily remove *-Lines in bulk", + "Gottem and the UnrealIRCd Team", + "unrealircd-5", +}; + #define IsParam(x) (parc > (x) && !BadPtr(parv[(x)])) #define IsNotParam(x) (parc <= (x) || BadPtr(parv[(x)])) @@ -69,16 +77,9 @@ static char *rmtkl_help[] = { NULL }; -ModuleHeader MOD_HEADER(rmtkl) = { - "rmtkl", - "$Id: v1.4 2019/08/10 Gottem$", - "Adds /rmtkl command to easily remove *-Lines in bulk", - "UnrealIRCd Team", - "unrealircd-5", -}; - MOD_INIT(rmtkl) { + MARK_AS_OFFICIAL_MODULE(modinfo); if (CommandExists("RMTKL")) { config_error("Command RMTKL already exists"); diff --git a/src/modules/sinfo.c b/src/modules/sinfo.c index 6d58b8ad1..c0a25d094 100644 --- a/src/modules/sinfo.c +++ b/src/modules/sinfo.c @@ -20,6 +20,7 @@ CMD_FUNC(m_sinfo); MOD_INIT(sinfo) { + MARK_AS_OFFICIAL_MODULE(modinfo); CommandAdd(modinfo->handle, "SINFO", m_sinfo, MAXPARA, M_USER|M_SERVER); return MOD_SUCCESS; diff --git a/src/modules/staff.c b/src/modules/staff.c index f13d4fd21..b8698c710 100644 --- a/src/modules/staff.c +++ b/src/modules/staff.c @@ -19,9 +19,15 @@ */ #include "unrealircd.h" -#ifdef USE_LIBCURL -#include "url.h" -#endif + +ModuleHeader MOD_HEADER(staff) + = { + "staff", + "3.8", + "/STAFF command", + "UnrealIRCd Team", + "unrealircd-5", + }; #define MSG_STAFF "STAFF" @@ -70,15 +76,6 @@ struct { } Download; #endif -ModuleHeader MOD_HEADER(staff) - = { - "staff", - "v3.8", - "/STAFF command", - "UnrealIRCd Team", - "unrealircd-5", - }; - MOD_TEST(staff) { HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, cb_test); diff --git a/src/modules/tkldb.c b/src/modules/tkldb.c index 78e58037e..98884eea8 100644 --- a/src/modules/tkldb.c +++ b/src/modules/tkldb.c @@ -19,6 +19,14 @@ #include "unrealircd.h" +ModuleHeader MOD_HEADER(tkldb) = { + "tkldb", + "1.10", + "Stores active TKL entries (*-Lines) persistently/across IRCd restarts", + "UnrealIRCd Team", + "unrealircd-5", +}; + #define TKL_DB_VERSION 1100 #define TKL_DB_SAVE_EVERY 299 @@ -104,14 +112,6 @@ static struct cfgstruct cfg; static int tkls_loaded = 0; -ModuleHeader MOD_HEADER(tkldb) = { - "tkldb", - "v1.10", - "Stores active TKL entries (*-Lines) persistently/across IRCd restarts", - "UnrealIRCd Team", - "unrealircd-5", -}; - MOD_TEST(tkldb) { memset(&cfg, 0, sizeof(cfg)); diff --git a/src/modules/usermodes/privdeaf.c b/src/modules/usermodes/privdeaf.c index 0ed3f5a4f..41e35e8ab 100644 --- a/src/modules/usermodes/privdeaf.c +++ b/src/modules/usermodes/privdeaf.c @@ -8,7 +8,7 @@ ModuleHeader MOD_HEADER(privdeaf) = { "privdeaf", - "v1.2", + "1.2", "Private Messages Deaf (+D) -- by Syzop", "UnrealIRCd Team", "unrealircd-5", diff --git a/src/modules/webredir.c b/src/modules/webredir.c index 9266b45cd..4c25c2f5c 100644 --- a/src/modules/webredir.c +++ b/src/modules/webredir.c @@ -26,7 +26,7 @@ CMD_FUNC(webredir); ModuleHeader MOD_HEADER(webredir) = { "webredir", - "v1.0", + "1.0", "Do 301 redirect for HEAD/GET/POST/PUT commands", "UnrealIRCd Team", "unrealircd-5",