operserv: REHASH announces the reload in the log channel via DebugServ
All checks were successful
CI / check (push) Successful in 4m1s

This commit is contained in:
Jean Chevronnet 2026-07-17 11:02:29 +00:00
parent 64b675e61f
commit e3b83f4a92
No known key found for this signature in database
2 changed files with 62 additions and 16 deletions

View file

@ -804,14 +804,23 @@ impl Engine {
// keycard endpoint are NOT reloadable — they need a restart. // keycard endpoint are NOT reloadable — they need a restart.
pub fn rehash(&mut self, requester: &str, agent: &str) -> Vec<NetAction> { pub fn rehash(&mut self, requester: &str, agent: &str) -> Vec<NetAction> {
let path = self.config_path.clone(); let path = self.config_path.clone();
// Who ran it, for the DebugServ log-channel line (account, else nick).
let oper = self
.network
.account_of(requester)
.or_else(|| self.network.nick_of(requester))
.unwrap_or("an operator")
.to_string();
let notice = |text: String| NetAction::Notice { from: agent.to_string(), to: requester.to_string(), text };
let cfg = match crate::config::Config::load(&path) { let cfg = match crate::config::Config::load(&path) {
Ok(cfg) => cfg, Ok(cfg) => cfg,
Err(e) => { Err(e) => {
return vec![NetAction::Notice { let mut out = Vec::new();
from: agent.to_string(), if let Some(line) = self.feed("OPER", format!("\x02{oper}\x02 ran \x02REHASH\x02 · config.toml failed to parse, keeping the running config · {e}")) {
to: requester.to_string(), out.push(line);
text: format!("REHASH failed: {e}. The running configuration is unchanged."), }
}]; out.push(notice(format!("REHASH failed: {e}. The running configuration is unchanged.")));
return out;
} }
}; };
let opers = cfg.opers(); let opers = cfg.opers();
@ -828,17 +837,21 @@ impl Engine {
if let Some(session) = &cfg.session { if let Some(session) = &cfg.session {
self.set_session_limit(session.limit()); self.set_session_limit(session.limit());
} }
let notice = |text: String| NetAction::Notice { from: agent.to_string(), to: requester.to_string(), text }; let sr = if self.standard_replies { "on" } else { "off" };
vec![ let chan = if self.services_channel.is_empty() { "(none)" } else { &self.services_channel };
notice(format!("Configuration reloaded from \x02{path}\x02.")), let opers_word = if oper_count == 1 { "oper" } else { "opers" };
notice(format!( let mut out = Vec::new();
"Applied: \x02{oper_count}\x02 oper(s), standard-replies \x02{}\x02, services channel \x02{}\x02, service oper-type \x02{}\x02.", // Announce it in the log channel so staff see who reloaded what, when.
if self.standard_replies { "on" } else { "off" }, if let Some(line) = self.feed("OPER", format!("\x02{oper}\x02 reloaded the configuration live · \x02{oper_count}\x02 {opers_word} · standard-replies \x02{sr}\x02 · services \x02{chan}\x02 · no restart needed")) {
if self.services_channel.is_empty() { "(none)" } else { &self.services_channel }, out.push(line);
}
out.push(notice(format!("Configuration reloaded from \x02{path}\x02.")));
out.push(notice(format!(
"Applied: \x02{oper_count}\x02 oper(s), standard-replies \x02{sr}\x02, services channel \x02{chan}\x02, service oper-type \x02{}\x02.",
if self.service_oper_type.is_empty() { "(none)" } else { &self.service_oper_type }, if self.service_oper_type.is_empty() { "(none)" } else { &self.service_oper_type },
)), )));
notice("Not reloadable (need a RESTART): server name/SID/protocol, uplink, service umodes, keycard.".to_string()), out.push(notice("Not reloadable (need a RESTART): server name/SID/protocol, uplink, service umodes, keycard.".to_string()));
] out
} }
// A user arrived on (or changed to) a registered nick: if they aren't logged // A user arrived on (or changed to) a registered nick: if they aren't logged

View file

@ -711,6 +711,39 @@
assert!(b.iter().any(|x| matches!(x, NetAction::Notice { text, .. } if text.contains("admin"))), "{b:?}"); assert!(b.iter().any(|x| matches!(x, NetAction::Notice { text, .. } if text.contains("admin"))), "{b:?}");
} }
// REHASH re-reads the file, applies the reloadable settings, and announces the
// reload in the log channel as a DebugServ feed line.
#[test]
fn rehash_applies_config_and_announces_in_log_channel() {
use echo_operserv::OperServ;
let cfgpath = std::env::temp_dir().join("echo-rehash-fixture.toml");
std::fs::write(&cfgpath, concat!(
"[uplink]\nhost = \"127.0.0.1\"\nport = 7000\npassword = \"x\"\n\n",
"[server]\nname = \"services.test\"\nsid = \"42S\"\ndescription = \"t\"\n",
"standard_replies = true\nservices_channel = \"#svc\"\n\n",
"[log]\nchannel = \"#services\"\n\n",
"[[oper]]\naccount = \"reverse\"\nprivs = [\"admin\"]\n",
)).unwrap();
let path = std::env::temp_dir().join("echo-rehash-eng.jsonl");
let _ = std::fs::remove_file(&path);
let mut db = Db::open(&path, "test");
db.scram_iterations = 4096;
let mut e = Engine::new(vec![Box::new(OperServ { uid: "42SAAAAAH".into() })], db);
e.set_sid("42S".into());
e.set_config_path(cfgpath.to_string_lossy().to_string());
e.set_debugserv_uid("42SAAAAAO");
e.set_log_channel(Some("#services".to_string()));
let out = e.rehash("000AAAAAB", "42SAAAAAH");
let feed = out.iter().find_map(|a| match a {
NetAction::Privmsg { from, to, text } if from == "42SAAAAAO" && to == "#services" => Some(text.clone()),
_ => None,
}).expect("DebugServ announces the reload in the log channel");
assert!(feed.contains("reloaded the configuration"), "{feed}");
assert!(feed.contains("#svc"), "the reloaded services channel is applied and shown: {feed}");
let _ = std::fs::remove_file(&cfgpath);
}
// A login that finishes off the handle() path (the link layer's deferred // A login that finishes off the handle() path (the link layer's deferred
// password/keycard verify) must still make echo's OWN account map authoritative. // password/keycard verify) must still make echo's OWN account map authoritative.
// Otherwise re-identifying an already-logged-in user after a services relink — // Otherwise re-identifying an already-logged-in user after a services relink —