standard replies: emit IRCv3 FAIL/WARN/NOTE for service errors, config-gated
All checks were successful
CI / check (push) Successful in 3m42s

This commit is contained in:
Jean Chevronnet 2026-07-17 02:53:48 +00:00
parent fcca7ac12b
commit 75c6537532
No known key found for this signature in database
8 changed files with 153 additions and 5 deletions

View file

@ -106,6 +106,7 @@ pub struct Engine {
service_host: String, // hostname the service pseudo-clients wear
service_oper_type: String, // oper type our services are flagged with (WHOIS "is a <this>"); empty = don't oper
services_channel: String, // channel all service pseudo-clients join at startup; empty = none
standard_replies: bool, // emit IRCv3 FAIL/WARN/NOTE for service errors; off = degrade to notices
enforce_seq: u32, // counter appended to guest_nick
pending_enforce: Vec<PendingEnforce>, // registered nicks awaiting identify-or-rename
bot_uids: HashMap<String, String>, // casefolded bot nick -> live uid (per connection)
@ -242,6 +243,7 @@ impl Engine {
service_host: "services.local".to_string(),
service_oper_type: String::new(),
services_channel: String::new(),
standard_replies: false,
enforce_seq: 0,
pending_enforce: Vec::new(),
bot_uids: HashMap::new(),
@ -785,6 +787,10 @@ impl Engine {
self.services_channel = channel.into();
}
pub fn set_standard_replies(&mut self, on: bool) {
self.standard_replies = on;
}
// A user arrived on (or changed to) a registered nick: if they aren't logged
// into that account, prompt them to IDENTIFY and schedule a rename. Gated on
// `synced` so a netburst can't enforce every already-online user; a user who
@ -1287,9 +1293,30 @@ impl Engine {
// Give every user-removal a traceable incident id, stamped into its reason
// and recorded in the searchable log (OperServ LOGSEARCH).
self.stamp_incidents(&mut out);
// When standard replies are off (or the ircd module isn't loaded), a
// FAIL/WARN/NOTE would be dropped — degrade each to a plain notice so the
// user always hears the outcome.
if !self.standard_replies {
self.degrade_standard_replies(&mut out);
}
out
}
// Rewrite any StandardReply into an equivalent Notice `*** command: text`
// (or `*** text` when there's no command), sourced from the same service.
fn degrade_standard_replies(&self, actions: &mut [NetAction]) {
for a in actions.iter_mut() {
if let NetAction::StandardReply { from, to, command, text, .. } = a {
let body = if command.is_empty() || command == "*" {
format!("*** {text}")
} else {
format!("*** {command}: {text}")
};
*a = NetAction::Notice { from: std::mem::take(from), to: std::mem::take(to), text: body };
}
}
}
// Mint an incident id for each kick/kill in `actions`, append `[#id]` to its
// reason, and record a searchable summary. One choke-point so every removal —
// from a bot kicker, a fantasy command, a vote, or an operator — is logged.

View file

@ -281,7 +281,7 @@ impl Engine {
let mut ctx = ServiceCtx::default();
if !ok {
ctx.count("nickserv.identify_fail");
ctx.notice(&agent, &uid, "Invalid password. Please try again.");
ctx.fail(&agent, &uid, "IDENTIFY", "INVALID_CREDENTIALS", "Invalid password. Please try again.");
} else {
ctx.login(&uid, &account);
ctx.count("nickserv.identify");

View file

@ -325,6 +325,36 @@
assert!(matches!(e.db.certfp_add("bar", fp), Err(db::CertError::InUse)), "a fingerprint maps to one account");
}
// Standard replies gate: off (default) degrades a service FAIL to a notice so
// nothing is lost; on, the structured FAIL survives with command + code.
#[test]
fn standard_replies_gate_service_failures() {
let connect = |e: &mut Engine| {
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "foo".into(), host: "h".into(), ip: "0.0.0.0".into() });
};
let identify_unregistered = |e: &mut Engine| e.handle(NetEvent::Privmsg {
from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY ghost pw".into(),
});
// Off: no StandardReply reaches the wire; the user still gets a notice.
let mut off = engine_with("stdrploff", "foo", "sesame");
connect(&mut off);
let a = identify_unregistered(&mut off);
assert!(a.iter().any(|x| matches!(x, NetAction::Notice { text, .. } if text.contains("isn't registered"))), "{a:?}");
assert!(!a.iter().any(|x| matches!(x, NetAction::StandardReply { .. })), "off must degrade: {a:?}");
// On: the FAIL survives, carrying the command and machine code.
let mut on = engine_with("stdrplon", "foo", "sesame");
on.set_standard_replies(true);
connect(&mut on);
let b = identify_unregistered(&mut on);
let hit = b.iter().find_map(|x| match x {
NetAction::StandardReply { kind, command, code, .. } => Some((kind.verb(), command.clone(), code.clone())),
_ => None,
});
assert_eq!(hit, Some(("FAIL", "IDENTIFY".to_string(), "ACCOUNT_NOT_REGISTERED".to_string())), "{b:?}");
}
// IDENTIFY logs in, LOGOUT clears the accountname (ircd emits RPL_LOGGEDOUT).
#[test]
fn nickserv_logout_clears_account() {