NickServ: add SET AUTOOP per-account auto-op opt-out

A user with SET AUTOOP OFF is never auto-opped on join, even where they
hold channel access — they op themselves via ChanServ UP. Stored inverted
(no_autoop) so the default stays auto-op. Join gates on both the channel
setting and the account preference; either can opt out.
This commit is contained in:
Jean Chevronnet 2026-07-16 01:37:31 +00:00
parent 0027decdb7
commit 87e21ff85f
No known key found for this signature in database
11 changed files with 111 additions and 11 deletions

View file

@ -21,7 +21,7 @@ impl Db {
ajoin: Vec::new(),
suspension: None,
memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None,
greet: String::new(),
greet: String::new(), no_autoop: false,
vhost: None,
vhost_request: None,
last_seen: now(),
@ -60,7 +60,7 @@ impl Db {
ajoin: Vec::new(),
suspension: None,
memos: Vec::new(), memo_ignore: Vec::new(), memo_notify: true, memo_limit: None,
greet: String::new(),
greet: String::new(), no_autoop: false,
vhost: None,
vhost_request: None,
last_seen: now(),
@ -418,6 +418,22 @@ impl Db {
Ok(())
}
/// Set whether `account` wants to be auto-opped on join (NickServ SET AUTOOP).
pub fn set_account_autoop(&mut self, account: &str, on: bool) -> Result<(), RegError> {
let k = key(account);
if !self.accounts.contains_key(&k) {
return Err(RegError::Internal);
}
self.log.append(Event::AccountAutoOpSet { account: account.to_string(), on }).map_err(|_| RegError::Internal)?;
self.accounts.get_mut(&k).unwrap().no_autoop = !on;
Ok(())
}
/// Whether `account` wants auto-op on join (default true). Unknown = true.
pub fn account_wants_autoop(&self, account: &str) -> bool {
self.accounts.get(&key(account)).is_none_or(|a| !a.no_autoop)
}
/// Replace `account`'s password with freshly derived credentials.
pub fn set_credentials(&mut self, account: &str, creds: Credentials) -> Result<(), RegError> {
let k = key(account);

View file

@ -15,6 +15,7 @@ pub enum Event {
CertRemoved { account: String, fp: String },
AccountEmailSet { account: String, email: Option<String> },
AccountGreetSet { account: String, greet: String },
AccountAutoOpSet { account: String, on: bool },
AccountPasswordSet { account: String, scram256: String, scram512: String },
AccountDropped { account: String },
AccountVerified { account: String },
@ -147,6 +148,7 @@ impl Event {
| Event::CertRemoved { .. }
| Event::AccountEmailSet { .. }
| Event::AccountGreetSet { .. }
| Event::AccountAutoOpSet { .. }
| Event::AccountPasswordSet { .. }
| Event::AccountDropped { .. }
| Event::AccountVerified { .. }
@ -273,6 +275,11 @@ pub(crate) fn apply(accounts: &mut HashMap<String, Account>, channels: &mut Hash
a.greet = greet;
}
}
Event::AccountAutoOpSet { account, on } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.no_autoop = !on;
}
}
Event::AccountPasswordSet { account, scram256, scram512 } => {
if let Some(a) = accounts.get_mut(&key(&account)) {
a.scram256 = Some(scram256);

View file

@ -91,6 +91,11 @@ pub struct Account {
// Personal greet a bot shows when this account joins a greet-enabled channel.
#[serde(default)]
pub greet: String,
// NickServ SET AUTOOP: when off, this user is never auto-opped on join even
// where they hold access (they op themselves). Stored inverted so the default
// (auto-op enabled) is the zero value.
#[serde(default)]
pub no_autoop: bool,
// Assigned vhost (HostServ), applied to the displayed host on identify.
#[serde(default)]
pub vhost: Option<Vhost>,

View file

@ -82,6 +82,12 @@ impl Store for Db {
fn set_greet(&mut self, account: &str, greet: &str) -> Result<(), RegError> {
Db::set_greet(self, account, greet)
}
fn set_account_autoop(&mut self, account: &str, on: bool) -> Result<(), RegError> {
Db::set_account_autoop(self, account, on)
}
fn account_wants_autoop(&self, account: &str) -> bool {
Db::account_wants_autoop(self, account)
}
fn set_vhost(&mut self, account: &str, host: &str, setter: &str, ttl: Option<u64>) -> Result<(), RegError> {
Db::set_vhost(self, account, host, setter, ttl)
}

View file

@ -32,7 +32,7 @@
// which of the two competing registrations we're looking at.
let alice = |tag: &str, ts: u64, home: &str| Account {
name: "alice".into(), email: Some(tag.into()),
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None,
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None,
};
let converge = |first: &Account, second: &Account| {
let (mut acc, mut ch, mut gr, mut bo, mut hc, mut nd) = (HashMap::new(), HashMap::new(), HashMap::new(), HashMap::new(), HostConfig::default(), NetData::default());
@ -329,7 +329,7 @@
db.register("alice", "pw", None).unwrap();
let bob = Account {
name: "bob".into(), email: None,
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], memo_ignore: vec![], memo_notify: true, memo_limit: None, greet: String::new(), no_autoop: false, vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
};
let entry = LogEntry { origin: "peer".into(), seq: 0, lamport: 1, event: Event::AccountRegistered(Box::new(bob)) };
db.ingest(entry).unwrap();