HostServ: ident@host vhosts (CHGIDENT)

A vhost may be ident@host, not just host: apply_vhost splits it and sends
CHGIDENT for the ident plus CHGHOST for the host. valid_vhost validates
the optional ident part; ON/SET/ACTIVATE/identify all route through
apply_vhost, so a bare host still works unchanged. New SetIdent action.
This commit is contained in:
Jean Chevronnet 2026-07-13 22:04:16 +00:00
parent 1edf250952
commit 898461d1c2
No known key found for this signature in database
8 changed files with 65 additions and 8 deletions

View file

@ -29,7 +29,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
match db.set_vhost(account, &host, from.nick) {
Ok(()) => {
for uid in net.uids_logged_into(account) {
ctx.set_host(&uid, &host);
ctx.apply_vhost(&uid, &host);
}
ctx.notice(me, from.uid, format!("Activated vhost \x02{host}\x02 for \x02{account}\x02."));
}

View file

@ -64,9 +64,18 @@ fn require_oper(me: &str, from: &Sender, ctx: &mut ServiceCtx) -> bool {
false
}
// Whether `host` is a syntactically valid vhost: a hostname of dot-separated
// labels using letters, digits and hyphens, not too long.
pub(crate) fn valid_vhost(host: &str) -> bool {
// Whether `spec` is a valid vhost: an optional `ident@` (letters, digits, a few
// punctuation) followed by a hostname of dot-separated alphanumeric/hyphen labels.
pub(crate) fn valid_vhost(spec: &str) -> bool {
let (ident, host) = match spec.split_once('@') {
Some((i, h)) => (Some(i), h),
None => (None, spec),
};
if let Some(i) = ident {
if i.is_empty() || i.len() > 12 || !i.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_' || b == b'.') {
return false;
}
}
if host.is_empty() || host.len() > 64 || !host.contains('.') {
return false;
}

View file

@ -8,7 +8,7 @@ pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &dyn Store) {
};
match db.vhost(account) {
Some(v) => {
ctx.set_host(from.uid, &v.host);
ctx.apply_vhost(from.uid, &v.host);
ctx.notice(me, from.uid, format!("Your vhost \x02{}\x02 is now active.", v.host));
}
None => ctx.notice(me, from.uid, "You have no vhost assigned."),

View file

@ -21,7 +21,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net:
match db.set_vhost(account, host, from.nick) {
Ok(()) => {
for uid in net.uids_logged_into(account) {
ctx.set_host(&uid, host);
ctx.apply_vhost(&uid, host);
}
ctx.notice(me, from.uid, format!("Vhost \x02{host}\x02 assigned to \x02{account}\x02."));
}