operlevels: oper = <name> <pass> <level>; a lower-level oper can't KILL a higher-level one

This commit is contained in:
Jean Chevronnet 2026-08-11 18:50:12 +00:00
parent 3b2f30965a
commit 3b43abc88a
7 changed files with 64 additions and 8 deletions

View file

@ -238,7 +238,7 @@ impl Command for Stats {
);
}
'o' => {
let opers: Vec<String> = s.opers.iter().map(|(n, _)| n.clone()).collect();
let opers: Vec<String> = s.opers.iter().map(|(n, _, _)| n.clone()).collect();
for n in opers {
s.numeric(uid, RPL_STATSOLINE, &format!("O * * {n} :oper"));
}

View file

@ -122,11 +122,14 @@ impl Command for Oper {
}
fn handle(&self, s: &mut Server, uid: Uid, params: &[String]) -> CmdResult {
let (name, pass) = (&params[0], &params[1]);
if s.opers
let level = s
.opers
.iter()
.any(|(n, p)| n == name && crate::modules::password_hash::verify(p, pass))
{
.find(|(n, p, _)| n == name && crate::modules::password_hash::verify(p, pass))
.map(|(_, _, lvl)| *lvl);
if let Some(level) = level {
s.oper_up(uid);
crate::modules::operlevels::set(s, uid, level); // operlevels: KILL protection
CmdResult::Ok
} else {
s.numeric(uid, ERR_PASSWDMISMATCH, ":Password incorrect");
@ -165,6 +168,11 @@ impl Command for Kill {
);
return CmdResult::Fail;
};
// operlevels: a lower-level oper can't KILL a higher-level oper
if let Some(reason) = crate::modules::operlevels::deny_kill(s, uid, tuid) {
s.numeric(uid, ERR_NOPRIVILEGES, &format!(":{reason}"));
return CmdResult::Fail;
}
let killer = s
.users
.get(&uid)