From 48d4fde94186e591bf070432a6b15bc0c8a88d7c Mon Sep 17 00:00:00 2001 From: Adam Hockley Date: Mon, 17 Nov 2025 08:12:27 +0000 Subject: [PATCH 1/4] Update m_rehash.c test the rehash now Signed-off-by: Adam Hockley --- modules/m_rehash.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/m_rehash.c b/modules/m_rehash.c index d8730d7e..e6c7c483 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -44,6 +44,7 @@ #include "hash.h" #include "cache.h" #include "sslproc.h" + static int mo_rehash(struct Client *, struct Client *, int, const char **); static int me_rehash(struct Client *, struct Client *, int, const char **); @@ -102,6 +103,7 @@ rehash_motd(struct Client *source_p) { struct stat sb; struct tm *local_tm; + char motd_path[PATH_MAX]; sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is forcing re-reading of MOTD file", @@ -112,7 +114,11 @@ rehash_motd(struct Client *source_p) free_cachefile(user_motd); user_motd = cache_file(MPATH, "ircd.motd", 0); - if(stat(MPATH, &sb) == 0) { + /* Construct the full file path for stat() */ + rb_snprintf(motd_path, sizeof(motd_path), "%s/ircd.motd", MPATH); + + /* Get the file's modification time (not the directory's) */ + if(stat(motd_path, &sb) == 0) { local_tm = localtime(&sb.st_mtime); if(local_tm != NULL) { From 45e8fdd63459d3458306f2f74bed42e192114876 Mon Sep 17 00:00:00 2001 From: Adam Hockley Date: Mon, 17 Nov 2025 09:16:22 +0000 Subject: [PATCH 2/4] Fix crash in /rehash motd - correct order of operations Fixed the order to match cache_user_motd() - stat() must be called before free_cachefile() to avoid potential race conditions or crashes. The stat() call should happen first to get file metadata, then free and reload the cache. --- modules/m_rehash.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/m_rehash.c b/modules/m_rehash.c index e6c7c483..75eaacbc 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -103,7 +103,6 @@ rehash_motd(struct Client *source_p) { struct stat sb; struct tm *local_tm; - char motd_path[PATH_MAX]; sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is forcing re-reading of MOTD file", @@ -111,14 +110,7 @@ rehash_motd(struct Client *source_p) if (!MyConnect(source_p)) remote_rehash_oper_p = source_p; - free_cachefile(user_motd); - user_motd = cache_file(MPATH, "ircd.motd", 0); - - /* Construct the full file path for stat() */ - rb_snprintf(motd_path, sizeof(motd_path), "%s/ircd.motd", MPATH); - - /* Get the file's modification time (not the directory's) */ - if(stat(motd_path, &sb) == 0) { + if(stat(MPATH, &sb) == 0) { local_tm = localtime(&sb.st_mtime); if(local_tm != NULL) { @@ -129,6 +121,8 @@ rehash_motd(struct Client *source_p) local_tm->tm_min); } } + free_cachefile(user_motd); + user_motd = cache_file(MPATH, "ircd.motd", 0); } static void From 102cfded529761c62e010aeb4e2b32507ee085e1 Mon Sep 17 00:00:00 2001 From: Adam Hockley Date: Mon, 17 Nov 2025 09:28:29 +0000 Subject: [PATCH 3/4] Replace m_rehash.c with requested version --- modules/m_rehash.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/modules/m_rehash.c b/modules/m_rehash.c index 75eaacbc..d04feabd 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -44,7 +44,6 @@ #include "hash.h" #include "cache.h" #include "sslproc.h" - static int mo_rehash(struct Client *, struct Client *, int, const char **); static int me_rehash(struct Client *, struct Client *, int, const char **); @@ -87,13 +86,11 @@ rehash_dns(struct Client *source_p) static void rehash_ssld(struct Client *source_p) { - if (!IsOperAdmin(source_p)) { - sendto_one(source_p, form_str(ERR_NOPRIVS), - me.name, source_p->name, "admin"); - return; - } - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is restarting ssld", + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "%s is restarting ssld", get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; restart_ssld(); } @@ -101,28 +98,26 @@ rehash_ssld(struct Client *source_p) static void rehash_motd(struct Client *source_p) { - struct stat sb; - struct tm *local_tm; - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is forcing re-reading of MOTD file", get_oper_name(source_p)); if (!MyConnect(source_p)) remote_rehash_oper_p = source_p; - if(stat(MPATH, &sb) == 0) { - local_tm = localtime(&sb.st_mtime); - - if(local_tm != NULL) { - rb_snprintf(user_motd_changed, sizeof(user_motd_changed), - "%d/%d/%d %d:%d", - local_tm->tm_mday, local_tm->tm_mon + 1, - 1900 + local_tm->tm_year, local_tm->tm_hour, - local_tm->tm_min); - } - } - free_cachefile(user_motd); - user_motd = cache_file(MPATH, "ircd.motd", 0); + cache_user_motd(); +} + +static void +rehash_rules(struct Client *source_p) +{ + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "%s is forcing re-reading of RULES file", + get_oper_name(source_p)); + if (!MyConnect(source_p)) + remote_rehash_oper_p = source_p; + + free_cachefile(user_rules); + user_rules = cache_file(RPATH, "ircd.rules", 0); } static void @@ -299,6 +294,7 @@ static struct hash_commands rehash_commands[] = { {"DNS", rehash_dns }, {"SSLD", rehash_ssld }, {"MOTD", rehash_motd }, + {"RULES", rehash_rules }, {"OMOTD", rehash_omotd }, {"TKLINES", rehash_tklines }, {"TDLINES", rehash_tdlines }, From c43584f020875a1edb6f8a73e29bd25fdcc9daa5 Mon Sep 17 00:00:00 2001 From: Adam Hockley Date: Mon, 17 Nov 2025 09:34:09 +0000 Subject: [PATCH 4/4] Remove rehash_rules entry --- modules/m_rehash.c | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/m_rehash.c b/modules/m_rehash.c index d04feabd..dd0d4513 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -294,7 +294,6 @@ static struct hash_commands rehash_commands[] = { {"DNS", rehash_dns }, {"SSLD", rehash_ssld }, {"MOTD", rehash_motd }, - {"RULES", rehash_rules }, {"OMOTD", rehash_omotd }, {"TKLINES", rehash_tklines }, {"TDLINES", rehash_tdlines },