UNBAN <nick> can use cached whowas info to unset bans

The use of the whowas cache in userhost_unban() would never work, because it was passing 'args' as the channel
name which also included the window number.

Rework this substantially, including using lookup_channel() and set_display_target() in place of prepare_command().
This commit is contained in:
Kevin Easton
2017-02-25 00:34:58 +11:00
parent 3a5a489f25
commit 1fbafddc59
2 changed files with 52 additions and 29 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2.2] [Changes 1.2.2]
* /UNBAN <nick> can use cached whowas info to unset bans. (caf)
* Unsetting CMDCHARS sets it back to the default. (caf) * Unsetting CMDCHARS sets it back to the default. (caf)
* Fix a double-free bug when a window on an alternate screen queries an exec * Fix a double-free bug when a window on an alternate screen queries an exec

View File

@@ -294,47 +294,68 @@ char * ban_it(char *nick, char *user, char *host, char *ip)
return banstr; return banstr;
} }
void userhost_unban(UserhostItem *stuff, char *nick1, char *args) /* userhost_unban()
*
* userhostbase() callback for /UNBAN <nick>.
* Expected 'args' are channel and server number. Uses userhost or cached
* whowas information to unset all matching bans on the channel.
*/
void userhost_unban(UserhostItem *uhi, char *nick, char *args)
{ {
ChannelList *chan; ChannelList *chan;
BanList *bans; BanList *bans;
WhowasList *whowas; WhowasList *whowas;
NickList *n = NULL; NickList *n = NULL;
char *channel, *ip_str = NULL, *host = NULL; char *channel, *ip_str = NULL, *host = NULL;
int count = 0, old_server = from_server; int count = 0;
int server = -1;
if (!stuff || !stuff->nick || !strcmp(stuff->user, "<UNKNOWN>") || my_stricmp(stuff->nick, nick1))
{
if ((whowas = check_whowas_nick_buffer(nick1, args)))
{
malloc_sprintf(&host, "%s!%s", whowas->nicklist->nick, whowas->nicklist->host);
bitchsay("Using WhoWas info for unban of %s ", nick1);
n = whowas->nicklist;
}
else
{
bitchsay("No match for the unban of %s on %s", nick1, args);
return;
}
}
else
malloc_sprintf(&host, "%s!%s@%s",stuff->nick, stuff->user, stuff->host);
channel = next_arg(args, &args); channel = next_arg(args, &args);
if (args && *args) if (args && *args)
from_server = atoi(args); server = atoi(args);
if (!(chan = prepare_command(&from_server, channel, NEED_OP))) /* Should not happen, indicates a bug in the code that setup this callback. */
if (!channel || server == -1)
return;
set_display_target(channel, LOG_CRAP);
if (!(chan = lookup_channel(channel, server, 0)) || (!chan->have_op && !chan->hop))
{ {
new_free(&host); bitchsay("No longer opped on channel %s", channel);
from_server = old_server; reset_display_target();
return;
}
if (uhi && uhi->nick && strcmp(uhi->user, "<UNKNOWN>") && !my_stricmp(uhi->nick, nick))
{
host = m_sprintf("%s!%s@%s", uhi->nick, uhi->user, uhi->host);
n = find_nicklist_in_channellist(uhi->nick, chan, 0);
}
else if ((whowas = check_whowas_nick_buffer(nick, channel)))
{
n = whowas->nicklist;
host = m_sprintf("%s!%s", n->nick, n->host);
bitchsay("Using WhoWas info for unban of %s", nick);
}
else
{
bitchsay("No matching nick for the unban of %s on %s", nick, channel);
reset_display_target();
return; return;
} }
if (!n)
n = find_nicklist_in_channellist(stuff->nick, chan, 0);
if (n && n->ip) if (n && n->ip)
malloc_sprintf(&ip_str, "%s!%s@%s", stuff->nick, stuff->user, n->ip); {
char *user = m_strdup(n->host);
char *p = strchr(user, '@');
if (p)
*p = 0;
ip_str = m_sprintf("%s!%s@%s", n->nick, user, n->ip);
new_free(&user);
}
for (bans = chan->bans; bans; bans = bans->next) for (bans = chan->bans; bans; bans = bans->next)
{ {
@@ -348,10 +369,10 @@ void userhost_unban(UserhostItem *stuff, char *nick1, char *args)
flush_mode_all(chan); flush_mode_all(chan);
if (!count) if (!count)
bitchsay("No match for Unban of %s on %s", nick1, args); bitchsay("No matching bans for %s on %s", host, channel);
new_free(&host); new_free(&host);
new_free(&ip_str); new_free(&ip_str);
from_server = old_server; reset_display_target();
} }
void userhost_ban(UserhostItem *stuff, char *nick1, char *args) void userhost_ban(UserhostItem *stuff, char *nick1, char *args)
@@ -893,7 +914,7 @@ BUILT_IN_COMMAND(unban)
count = atoi(spec + 1); count = atoi(spec + 1);
else if (!strchr(spec, '*')) else if (!strchr(spec, '*'))
{ {
userhostbase(spec, userhost_unban, 1, "%s %d", chan->channel, current_window->refnum); userhostbase(spec, userhost_unban, 1, "%s %d", chan->channel, server);
reset_display_target(); reset_display_target();
return; return;
} }