NickServ: add SASET for operator account edits
Some checks failed
CI / check (push) Has been cancelled
Some checks failed
CI / check (push) Has been cancelled
This commit is contained in:
parent
d819b2c75f
commit
c646ccc0ec
3 changed files with 96 additions and 0 deletions
|
|
@ -16,6 +16,8 @@ mod info;
|
|||
mod alist;
|
||||
#[path = "set.rs"]
|
||||
mod set;
|
||||
#[path = "saset.rs"]
|
||||
mod saset;
|
||||
#[path = "drop.rs"]
|
||||
mod drop;
|
||||
#[path = "group.rs"]
|
||||
|
|
@ -53,6 +55,7 @@ const TOPICS: &[HelpEntry] = &[
|
|||
HelpEntry { cmd: "INFO", summary: "show account information", detail: "Syntax: \x02INFO [account]\x02\nShows account information. The email is shown only to the owner." },
|
||||
HelpEntry { cmd: "ALIST", summary: "list channels you have access on", detail: "Syntax: \x02ALIST\x02\nLists the channels you hold access on." },
|
||||
HelpEntry { cmd: "SET", summary: "change password or email", detail: "Syntax: \x02SET PASSWORD <new>\x02 or \x02SET EMAIL <address>\x02\nChanges your account password or email." },
|
||||
HelpEntry { cmd: "SASET", summary: "change another account's settings (operator)", detail: "Syntax: \x02SASET <account> PASSWORD <new>\x02, \x02EMAIL [address]\x02, or \x02GREET [message]\x02\nEdits another account's settings. Operators only." },
|
||||
HelpEntry { cmd: "GROUP", summary: "link this nick to an account", detail: "Syntax: \x02GROUP <account> <password>\x02\nLinks your current nick to an account as an alias, so identifying under it logs into that account." },
|
||||
HelpEntry { cmd: "GLIST", summary: "list your grouped nicks", detail: "Syntax: \x02GLIST\x02\nLists the nicks grouped to your account." },
|
||||
HelpEntry { cmd: "UNGROUP", summary: "remove a grouped nick", detail: "Syntax: \x02UNGROUP [nick]\x02\nRemoves a grouped nick (your current one by default)." },
|
||||
|
|
@ -114,6 +117,7 @@ impl Service for NickServ {
|
|||
Some("INFO") => info::handle(me, from, args, ctx, db),
|
||||
Some("ALIST") => alist::handle(me, from, ctx, db),
|
||||
Some("SET") => set::handle(me, from, args, ctx, db),
|
||||
Some("SASET") => saset::handle(me, from, args, ctx, db),
|
||||
Some("DROP") => drop::handle(me, from, args, ctx, net, db),
|
||||
Some("GROUP") => group::handle(me, from, args, ctx, db),
|
||||
Some("GLIST") => glist::handle(me, from, ctx, db),
|
||||
|
|
|
|||
57
modules/nickserv/src/saset.rs
Normal file
57
modules/nickserv/src/saset.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use echo_api::{Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// SASET <account> <option> [value]: the operator counterpart of SET, editing
|
||||
// another account's settings. Oper-only (Priv::Admin). Mirrors the self-service
|
||||
// SET options that make sense to change on someone else's behalf.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
if !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, "Access denied — that command is for services operators.");
|
||||
return;
|
||||
}
|
||||
let (Some(&target), sub) = (args.get(1), args.get(2).map(|s| s.to_ascii_uppercase())) else {
|
||||
ctx.notice(me, from.uid, "Syntax: SASET <account> PASSWORD <newpassword> | EMAIL [address] | GREET [message]");
|
||||
return;
|
||||
};
|
||||
let Some(account) = db.resolve_account(target).map(str::to_string) else {
|
||||
ctx.notice(me, from.uid, format!("\x02{target}\x02 isn't registered."));
|
||||
return;
|
||||
};
|
||||
// Credential/identity fields are owned by the website in external mode.
|
||||
if db.external_accounts() && matches!(sub.as_deref(), Some("PASSWORD" | "PASS" | "EMAIL")) {
|
||||
ctx.notice(me, from.uid, "That's managed on the website — change it there.");
|
||||
return;
|
||||
}
|
||||
match sub.as_deref() {
|
||||
Some("PASSWORD") | Some("PASS") => {
|
||||
let Some(&password) = args.get(3) else {
|
||||
ctx.notice(me, from.uid, "Syntax: SASET <account> PASSWORD <newpassword>");
|
||||
return;
|
||||
};
|
||||
if let Err(reason) = crate::password::validate_password(password, &account) {
|
||||
ctx.notice(me, from.uid, reason);
|
||||
return;
|
||||
}
|
||||
// The link layer derives the new password off-thread, then commits it.
|
||||
ctx.defer_password(account, password, me, from.uid);
|
||||
}
|
||||
Some("EMAIL") => {
|
||||
let email = args.get(3).map(|s| s.to_string());
|
||||
let cleared = email.is_none();
|
||||
match db.set_email(&account, email) {
|
||||
Ok(()) if cleared => ctx.notice(me, from.uid, format!("Email for \x02{account}\x02 cleared.")),
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Email for \x02{account}\x02 updated.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
Some("GREET") => {
|
||||
let greet = if args.len() > 3 { args[3..].join(" ") } else { String::new() };
|
||||
let cleared = greet.is_empty();
|
||||
match db.set_greet(&account, &greet) {
|
||||
Ok(()) if cleared => ctx.notice(me, from.uid, format!("Greet for \x02{account}\x02 cleared.")),
|
||||
Ok(()) => ctx.notice(me, from.uid, format!("Greet for \x02{account}\x02 is now: {greet}")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
_ => ctx.notice(me, from.uid, "Syntax: SASET <account> PASSWORD <newpassword> | EMAIL [address] | GREET [message]"),
|
||||
}
|
||||
}
|
||||
|
|
@ -837,6 +837,41 @@
|
|||
assert_eq!(e.db.unread_memos("bob"), 1);
|
||||
}
|
||||
|
||||
// NickServ SASET lets an operator edit another account's settings, and is
|
||||
// refused to non-operators.
|
||||
#[test]
|
||||
fn nickserv_saset_greet_by_operator() {
|
||||
use echo_nickserv::NickServ;
|
||||
let path = std::env::temp_dir().join("echo-nssaset.jsonl");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut db = Db::open(&path, "42S");
|
||||
db.scram_iterations = 4096;
|
||||
db.register("boss", "pw", None).unwrap();
|
||||
db.register("alice", "pw", None).unwrap();
|
||||
let mut e = Engine::new(
|
||||
vec![Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 })],
|
||||
db,
|
||||
);
|
||||
let mut opers = std::collections::HashMap::new();
|
||||
opers.insert("boss".to_string(), Privs::default().with(echo_api::Priv::Admin));
|
||||
e.set_opers(opers);
|
||||
let ns = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAA".into(), text: t.into() });
|
||||
let notice = |out: &[NetAction], n: &str| out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains(n)));
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "boss".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||
ns(&mut e, "000AAAAAB", "IDENTIFY pw");
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAC".into(), nick: "alice".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||
ns(&mut e, "000AAAAAC", "IDENTIFY pw");
|
||||
|
||||
// A non-operator cannot use it.
|
||||
assert!(notice(&ns(&mut e, "000AAAAAC", "SASET boss GREET nope"), "Access denied"), "non-oper refused");
|
||||
// The operator sets alice's greet.
|
||||
assert!(notice(&ns(&mut e, "000AAAAAB", "SASET alice GREET hello there"), "is now"), "oper sets greet");
|
||||
assert_eq!(e.db.account("alice").map(|a| a.greet.clone()), Some("hello there".to_string()), "greet stored");
|
||||
// And clears it.
|
||||
assert!(notice(&ns(&mut e, "000AAAAAB", "SASET alice GREET"), "cleared"), "oper clears greet");
|
||||
assert_eq!(e.db.account("alice").map(|a| a.greet.clone()), Some(String::new()), "greet cleared");
|
||||
}
|
||||
|
||||
// MemoServ IGNORE: a memo from an ignored sender is silently dropped, and the
|
||||
// sender is still told it was sent (so the ignore isn't revealed).
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue