operserv: OPER ADD rejects unknown privilege names instead of silently dropping them

This commit is contained in:
Jean Chevronnet 2026-07-17 13:53:53 +00:00
parent ef34c04c8d
commit ee95225eaf
No known key found for this signature in database

View file

@ -27,14 +27,22 @@ fn add(me: &str, from: &Sender, account: Option<&str>, privs: Option<&str>, dur:
ctx.notice(me, from.uid, format!("\x02{account}\x02 isn't registered.")); ctx.notice(me, from.uid, format!("\x02{account}\x02 isn't registered."));
return; return;
}; };
// Keep only recognised privilege names. // Parse the privilege names, rejecting the whole grant on a typo rather than
let names: Vec<String> = privs // silently dropping it (which would grant less than the oper intended).
.split(',') let mut names = Vec::new();
.map(|p| p.trim().to_ascii_lowercase()) let mut unknown = Vec::new();
.filter(|p| matches!(p.as_str(), "auspex" | "suspend" | "admin")) for p in privs.split(',').map(str::trim).filter(|p| !p.is_empty()) {
.collect(); match Priv::from_name(p) {
Some(pr) => names.push(pr.name().to_string()),
None => unknown.push(p.to_string()),
}
}
if !unknown.is_empty() {
ctx.notice(me, from.uid, format!("Unknown privilege(s): \x02{}\x02 (valid: {}).", unknown.join(", "), Priv::valid_names()));
return;
}
if names.is_empty() { if names.is_empty() {
ctx.notice(me, from.uid, "No valid privileges given (auspex, suspend, admin)."); ctx.notice(me, from.uid, format!("No privileges given (valid: {}).", Priv::valid_names()));
return; return;
} }
let expires = dur.and_then(|d| d.strip_prefix('+')).and_then(parse_duration).map(|secs| now() + secs); let expires = dur.and_then(|d| d.strip_prefix('+')).and_then(parse_duration).map(|secs| now() + secs);