whoisport: report the port the user actually connected to (User.port, set at accept) instead of conf("bind")/conf("bind_tls") — those are Vec-valued so conf() returned only the LAST configured listener, giving every user the same wrong port on a multi-listener server

This commit is contained in:
Jean Chevronnet 2026-08-19 00:43:03 +00:00
parent 25702c9541
commit 35bb901455

View file

@ -1,20 +1,15 @@
//! Shows an IRC operator, in WHOIS, the listener port the target connected to. //! Shows an IRC operator, in WHOIS, the listener port the target connected to —
//! Derives the port from the `bind` / `bind_tls` listeners. //! read straight from the user's own connection (set at accept time), so it's
//! correct even when the server has several `bind` / `bind_tls` listeners.
use crate::server::Server; use crate::server::Server;
use crate::Uid; use crate::Uid;
fn port_of(addr: &str) -> u16 {
addr.rsplit(':')
.next()
.and_then(|p| p.parse().ok())
.unwrap_or(0)
}
/// The `is using port N` WHOIS line for opers, or `None` if the port is unknown. /// The `is using port N` WHOIS line for opers, or `None` if the port is unknown.
pub fn line(s: &Server, target: Uid) -> Option<String> { pub fn line(s: &Server, target: Uid) -> Option<String> {
let secure = s.users.get(&target).map(|u| u.secure).unwrap_or(false); s.users
let bind = if secure { "bind_tls" } else { "bind" }; .get(&target)
let port = s.conf(bind).map(port_of).unwrap_or(0); .map(|u| u.port)
(port != 0).then(|| format!("is using port {port}")) .filter(|&p| p != 0)
.map(|p| format!("is using port {p}"))
} }