OperServ: JUPE — hold a server name against a rogue link

JUPE <server.name> [reason] introduces a fake server holding the name so
the real one can't link; JUPE DEL <name> squits it; JUPE LIST shows them.
Node-local (the introducing node owns the jupe, so it isn't federated —
that would collide SIDs across nodes) and re-asserted at burst. A fake
server id is allocated per jupe. New JupeServer/Squit actions serialise to
the mid-link SERVER introduction and SQUIT. Admin-only.
This commit is contained in:
Jean Chevronnet 2026-07-14 01:51:07 +00:00
parent 76a7162227
commit 1daebc94a5
No known key found for this signature in database
6 changed files with 179 additions and 2 deletions

View file

@ -338,6 +338,15 @@ fn gline_kind() -> String {
"G".to_string()
}
// A valid 3-char server id for a juped server from a counter: a leading digit
// (kept high to avoid colliding with typical real SIDs) then two base-36 chars.
fn jupe_sid(seq: u32) -> String {
const C: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let b = C[(seq / 36 % 36) as usize];
let c = C[(seq % 36) as usize];
String::from_utf8(vec![b'9', b, c]).unwrap()
}
// A services ignore: services silently drop commands from a matching user. Node-
// local and in-memory (like the auth throttle) — a fast, transient moderation
// tool, not persisted or federated.
@ -956,6 +965,18 @@ pub struct Db {
net: NetData,
// Services ignores (OperServ IGNORE), node-local and in-memory.
ignores: Vec<Ignore>,
// Juped servers (OperServ JUPE), node-local: the introducing node owns them,
// so they aren't federated (that would collide SIDs across nodes).
jupes: Vec<Jupe>,
jupe_seq: u32,
}
// A juped server: the held name, the fake server id we allocated for it, and why.
#[derive(Debug, Clone)]
pub struct Jupe {
pub name: String,
pub sid: String,
pub reason: String,
}
// Network-wide HostServ configuration, rebuilt from the event log.
@ -1011,7 +1032,7 @@ impl Db {
apply(&mut accounts, &mut channels, &mut grouped, &mut bots, &mut host_cfg, &mut net, event);
}
tracing::info!(accounts = accounts.len(), channels = channels.len(), "account store loaded");
Self { accounts, channels, grouped, log, scram_iterations: scram::DEFAULT_ITERATIONS, email_enabled: false, email_brand: "Network Services".to_string(), email_accent: "#4f46e5".to_string(), email_logo: String::new(), codes: HashMap::new(), auth_fails: HashMap::new(), vhost_req_times: HashMap::new(), bots, host_cfg, net, ignores: Vec::new() }
Self { accounts, channels, grouped, log, scram_iterations: scram::DEFAULT_ITERATIONS, email_enabled: false, email_brand: "Network Services".to_string(), email_accent: "#4f46e5".to_string(), email_logo: String::new(), codes: HashMap::new(), auth_fails: HashMap::new(), vhost_req_times: HashMap::new(), bots, host_cfg, net, ignores: Vec::new(), jupes: Vec::new(), jupe_seq: 0 }
}
/// Fold an entry authored by another node into the store — the services-side
@ -2004,6 +2025,30 @@ impl Db {
.collect()
}
/// Jupe a server name: allocate a fake sid, store it, return the sid to
/// introduce (or the existing sid if the name is already juped).
pub fn jupe_add(&mut self, name: &str, reason: &str) -> String {
if let Some(j) = self.jupes.iter().find(|j| j.name.eq_ignore_ascii_case(name)) {
return j.sid.clone();
}
let sid = jupe_sid(self.jupe_seq);
self.jupe_seq += 1;
self.jupes.push(Jupe { name: name.to_string(), sid: sid.clone(), reason: reason.to_string() });
sid
}
/// Lift a jupe. Returns the sid to squit if it existed.
pub fn jupe_del(&mut self, name: &str) -> Option<String> {
let sid = self.jupes.iter().find(|j| j.name.eq_ignore_ascii_case(name)).map(|j| j.sid.clone())?;
self.jupes.retain(|j| !j.name.eq_ignore_ascii_case(name));
Some(sid)
}
/// The juped servers, as (name, sid, reason).
pub fn jupes(&self) -> Vec<(String, String, String)> {
self.jupes.iter().map(|j| (j.name.clone(), j.sid.clone(), j.reason.clone())).collect()
}
/// Add a services ignore, replacing any existing entry for the same mask.
pub fn ignore_add(&mut self, mask: &str, reason: &str, expires: Option<u64>) {
self.ignores.retain(|i| !i.mask.eq_ignore_ascii_case(mask));
@ -3245,6 +3290,15 @@ impl Store for Db {
fn ignores(&self) -> Vec<IgnoreView> {
Db::ignores(self)
}
fn jupe_add(&mut self, name: &str, reason: &str) -> String {
Db::jupe_add(self, name, reason)
}
fn jupe_del(&mut self, name: &str) -> Option<String> {
Db::jupe_del(self, name)
}
fn jupes(&self) -> Vec<(String, String, String)> {
Db::jupes(self)
}
fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool {
Db::set_account_note(self, account, note)
}

View file

@ -719,6 +719,10 @@ impl Engine {
let duration = a.expires.map(|e| e.saturating_sub(now)).unwrap_or(0);
out.push(NetAction::AddLine { kind: a.kind, mask: a.mask, setter: a.setter, duration, reason: a.reason });
}
// Re-introduce our juped servers over the fresh link.
for (name, sid, reason) in self.db.jupes() {
out.push(NetAction::JupeServer { name, sid, reason });
}
out.push(NetAction::Metadata {
target: "*".to_string(),
key: "saslmechlist".to_string(),
@ -4086,6 +4090,48 @@ mod tests {
}
}
// OperServ JUPE: hold a server name with a fake server, re-assert it at burst,
// and lift it with a squit. Admin-only.
#[test]
fn operserv_jupe_holds_and_lifts() {
use fedserv_operserv::OperServ;
let path = std::env::temp_dir().join("fedserv-osjupe.jsonl");
let _ = std::fs::remove_file(&path);
let mut db = Db::open(&path, "42S");
db.scram_iterations = 4096;
db.register("staff", "password1", None).unwrap();
let mut e = Engine::new(
vec![
Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }),
Box::new(OperServ { uid: "42SAAAAAH".into() }),
],
db,
);
e.set_sid("42S".into());
let mut opers = std::collections::HashMap::new();
opers.insert("staff".to_string(), Privs::default().with(fedserv_api::Priv::Admin));
e.set_opers(opers);
let os = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAH".into(), text: t.into() });
e.handle(NetEvent::UserConnect { uid: "000AAAAAS".into(), nick: "staff".into(), host: "h".into(), ip: "9.9.9.9".into() });
e.handle(NetEvent::Privmsg { from: "000AAAAAS".into(), to: "42SAAAAAA".into(), text: "IDENTIFY password1".into() });
// Juping introduces a fake server holding the name.
let out = os(&mut e, "000AAAAAS", "JUPE rogue.example evil twin");
assert!(out.iter().any(|a| matches!(a, NetAction::JupeServer { name, .. } if name == "rogue.example")), "jupe introduced: {out:?}");
// A bare name (no dot) isn't a server — syntax refused.
assert!(os(&mut e, "000AAAAAS", "JUPE notaserver").iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("Syntax"))), "needs a server name");
// It's re-introduced at burst.
assert!(e.startup_actions().iter().any(|a| matches!(a, NetAction::JupeServer { name, .. } if name == "rogue.example")), "re-asserted at burst");
// LIST shows it.
assert!(os(&mut e, "000AAAAAS", "JUPE LIST").iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("rogue.example"))), "listed");
// DEL squits the fake server.
assert!(os(&mut e, "000AAAAAS", "JUPE DEL rogue.example").iter().any(|a| matches!(a, NetAction::Squit { .. })), "squit on lift");
assert!(!e.startup_actions().iter().any(|a| matches!(a, NetAction::JupeServer { .. })), "gone after DEL");
}
// OperServ session limiting: the connection that puts an IP over its limit is
// killed; SESSION inspects counts; EXCEPTION raises the allowance per IP-mask.
#[test]