botserv: bots join channels as protected admins (+a) so ordinary ops can't kick or deop them
All checks were successful
CI / check (push) Successful in 3m50s

This commit is contained in:
Jean Chevronnet 2026-07-17 16:52:00 +00:00
parent e2330c56ff
commit 73467b91ca
No known key found for this signature in database
4 changed files with 25 additions and 21 deletions

View file

@ -444,7 +444,9 @@ impl Engine {
for (bot_lc, chan) in &desired {
if !self.bot_channels.contains(&(bot_lc.clone(), chan.clone())) {
if let Some(uid) = self.bot_uids.get(bot_lc) {
out.push(NetAction::ServiceJoin { uid: uid.clone(), channel: chan.clone() });
// BotServ bots join as protected admins (+a) so ordinary ops
// can't kick or deop them — the standard bot default.
out.push(NetAction::ServiceJoin { uid: uid.clone(), channel: chan.clone(), modes: "a".into() });
self.bot_channels.insert((bot_lc.clone(), chan.clone()));
}
}
@ -1025,7 +1027,7 @@ impl Engine {
}
// All service pseudo-clients sit in the services channel (configurable).
if !self.services_channel.is_empty() {
out.push(NetAction::ServiceJoin { uid: svc.uid().to_string(), channel: self.services_channel.clone() });
out.push(NetAction::ServiceJoin { uid: svc.uid().to_string(), channel: self.services_channel.clone(), modes: "o".into() });
}
}
// Advertise our SASL mechanisms so the uplink can offer `sasl=PLAIN` to
@ -1036,7 +1038,7 @@ impl Engine {
// already joined it above as the services channel.
if let (false, Some(chan)) = (self.debugserv_uid.is_empty(), self.log_channel.clone()) {
if !chan.eq_ignore_ascii_case(&self.services_channel) {
out.push(NetAction::ServiceJoin { uid: self.debugserv_uid.clone(), channel: chan });
out.push(NetAction::ServiceJoin { uid: self.debugserv_uid.clone(), channel: chan, modes: "o".into() });
}
}
// Re-assert the network bans over the fresh link, each with its remaining

View file

@ -546,7 +546,7 @@
e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAD".into(), text: "BOT ADD Bendy bot serv.host Helper".into() });
let out = e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAD".into(), text: "ASSIGN #room Bendy".into() });
let botuid = out.iter().find_map(|a| match a {
NetAction::ServiceJoin { uid, channel } if channel == "#room" => Some(uid.clone()),
NetAction::ServiceJoin { uid, channel, .. } if channel == "#room" => Some(uid.clone()),
_ => None,
}).expect("bot joins #room");
@ -591,7 +591,7 @@
let _ = assign;
let out = e.handle(NetEvent::Privmsg { from: "000AAAAAA".into(), to: "42SAAAAAD".into(), text: "ASSIGN #room Bendy".into() });
let botuid = out.iter().find_map(|a| match a {
NetAction::ServiceJoin { uid, channel } if channel == "#room" => Some(uid.clone()),
NetAction::ServiceJoin { uid, channel, .. } if channel == "#room" => Some(uid.clone()),
_ => None,
}).expect("bot joins #room");
@ -2217,9 +2217,9 @@
ns(&mut e, "000AAAAAC", "IDENTIFY password1");
bs(&mut e, "000AAAAAC", "BOT ADD Bendy bot serv.host Helper"); // goes live
// The founder assigns the bot: it joins the channel.
// The founder assigns the bot: it joins the channel as a protected admin (+a).
let out = bs(&mut e, "000AAAAAB", "ASSIGN #c Bendy");
assert!(out.iter().any(|a| matches!(a, NetAction::ServiceJoin { channel, .. } if channel == "#c")), "joins on assign: {out:?}");
assert!(out.iter().any(|a| matches!(a, NetAction::ServiceJoin { channel, modes, .. } if channel == "#c" && modes == "a")), "joins +a on assign: {out:?}");
// Unassigning parts it.
let out = bs(&mut e, "000AAAAAB", "UNASSIGN #c");
assert!(out.iter().any(|a| matches!(a, NetAction::ServicePart { channel, .. } if channel == "#c")), "parts on unassign: {out:?}");
@ -2254,13 +2254,13 @@
ns(&mut e, "IDENTIFY password1");
bs(&mut e, "BOT ADD Bendy bot serv.host Helper");
let bot_uid = bs(&mut e, "ASSIGN #c Bendy").iter().find_map(|a| match a {
NetAction::ServiceJoin { uid, channel } if channel == "#c" => Some(uid.clone()),
NetAction::ServiceJoin { uid, channel, .. } if channel == "#c" => Some(uid.clone()),
_ => None,
}).expect("bot joined on assign");
// The bot is kicked out (the ircd relays this as a PART for its uid).
let out = e.handle(NetEvent::Part { uid: bot_uid.clone(), channel: "#c".into() });
assert!(out.iter().any(|a| matches!(a, NetAction::ServiceJoin { uid, channel } if uid == &bot_uid && channel == "#c")), "kicked bot rejoins: {out:?}");
assert!(out.iter().any(|a| matches!(a, NetAction::ServiceJoin { uid, channel, .. } if uid == &bot_uid && channel == "#c")), "kicked bot rejoins: {out:?}");
}
// A KILL forgets a real user, but a killed services bot is reintroduced and
@ -2292,7 +2292,7 @@
ns(&mut e, "IDENTIFY password1");
bs(&mut e, "BOT ADD Bendy bot serv.host Helper");
let bot_uid = bs(&mut e, "ASSIGN #c Bendy").iter().find_map(|a| match a {
NetAction::ServiceJoin { uid, channel } if channel == "#c" => Some(uid.clone()),
NetAction::ServiceJoin { uid, channel, .. } if channel == "#c" => Some(uid.clone()),
_ => None,
}).expect("bot joined on assign");