HostServ: normalise vhosts + enforce uniqueness
Canonicalise a requested vhost the way the ircd displays it (a disallowed underscore becomes a hyphen) before storing and applying, so what we keep matches what shows on the network. A vhost can no longer be assigned to two accounts: prepare_vhost normalises, validates, and checks vhost_owner at every assignment point (SET/REQUEST/ACTIVATE/TAKE/DEFAULT), so two inputs that collapse to the same host are caught as one. Approach recommended by siniStar (the ns_nethost normalisation logic).
This commit is contained in:
parent
271e06fa77
commit
31d23cf6b3
9 changed files with 130 additions and 18 deletions
|
|
@ -17,11 +17,14 @@ pub fn handle(me: &str, from: &Sender, ctx: &mut ServiceCtx, db: &mut dyn Store)
|
|||
ctx.notice(me, from.uid, "Your account name has no usable characters for a vhost.");
|
||||
return;
|
||||
}
|
||||
let host = template.replace("$account", &label);
|
||||
if !super::valid_vhost(&host) || db.vhost_is_forbidden(&host) {
|
||||
ctx.notice(me, from.uid, "Sorry, a vhost couldn't be generated for your account.");
|
||||
return;
|
||||
}
|
||||
let generated = template.replace("$account", &label);
|
||||
let host = match super::prepare_vhost(&generated, account, db) {
|
||||
Ok(h) if !db.vhost_is_forbidden(&h) => h,
|
||||
_ => {
|
||||
ctx.notice(me, from.uid, "Sorry, a vhost couldn't be generated for your account.");
|
||||
return;
|
||||
}
|
||||
};
|
||||
match db.set_vhost(account, &host, "template", None) {
|
||||
Ok(()) => {
|
||||
ctx.apply_vhost(from.uid, &host);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue