Skip to content

Commit

Permalink
Send 318 EndOfWhois for invalid/nonexistent nicknames
Browse files Browse the repository at this point in the history
  • Loading branch information
spb committed Oct 8, 2024
1 parent 2bb9c27 commit 0082a84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions sable_ircd/src/command/handlers/whois.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use super::*;
#[command_handler("WHOIS")]
/// Syntax: WHOIS [<server|target>] <target>
fn whois_handler(
command: &dyn Command,
response: &dyn CommandResponse,
source: UserSource,
server: &ClientServer,
net: &Network,
mut args: ArgList,
) -> CommandResult {
let target: wrapper::User = match args.len() {
let target_str: &str = match args.len() {
0 => return Err(CommandError::NotEnoughParameters),
1 => args.next()?,
_ => {
Expand All @@ -17,6 +19,25 @@ fn whois_handler(
}
};

// We need to handle the no-such-user and invalid-nick cases manually because we have to send
// EndOfWhois even when the arguments are invalid
let target_nick = match Nickname::try_from(target_str) {
Ok(nick) => nick,
Err(err) => {
command.notify_error(err.into());
response.numeric(make_numeric!(EndOfWhois, target_str));
return Ok(());
}
};
let target = match net.user_by_nick(&target_nick) {
Ok(user) => user,
Err(err) => {
command.notify_error(err.into());
response.numeric(make_numeric!(EndOfWhois, target_str));
return Ok(());
}
};

response.numeric(make_numeric!(WhoisUser, &target));

if let Ok(Some(account)) = target.account() {
Expand All @@ -29,7 +50,9 @@ fn whois_handler(

if server.policy().can_see_connection_info(&source, &target) {
for conn in target.connections() {
response.numeric(make_numeric!(WhoisServer, &target, &conn.server()?));
if let Ok(server) = conn.server() {
response.numeric(make_numeric!(WhoisServer, &target, &server));
}
response.numeric(make_numeric!(
WhoisHost,
&target,
Expand All @@ -39,6 +62,6 @@ fn whois_handler(
}
}

response.numeric(make_numeric!(EndOfWhois, &target));
response.numeric(make_numeric!(EndOfWhois, &target_str));
Ok(())
}
2 changes: 1 addition & 1 deletion sable_ircd/src/messages/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define_messages! {
314(WhowasUser) => { (nick: &HistoricUser.nick(), user=nick.user(), host=nick.visible_host(), realname=nick.realname())
=> "{nick} {user} {host} * :{realname}" },
315(EndOfWho) => { (arg: &str) => "{arg} :End of /WHO list" },
318(EndOfWhois) => { (user: &User.nick()) => "{user} :End of /WHOIS" },
318(EndOfWhois) => { (user: &str) => "{user} :End of /WHOIS" },
319(WhoisChannels) => { (user: &User.nick(), chanlist: &str)
=> "{user} :{chanlist}" },
378(WhoisHost) => { (user: &User.nick(), username=user.user(), host: &Hostname, ip: &std::net::IpAddr)
Expand Down

0 comments on commit 0082a84

Please sign in to comment.