From 2afc57aa38f7d78759b646ccb1f9fc2f9ea4cc85 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 26 Jun 2021 11:43:32 +0200 Subject: [PATCH] Use IsLoggedIn() macro everywhere where possible. Based on previous reports and patches from k4be in https://github.com/unrealircd/unrealircd/pull/129 Looks much cleaner now. This also filters out the edge case where user_account_login() could have been called when a user transitioned from "not logged in" to "unconfirmed account". It did not cause any issues AFAICT but it is not really expected either. --- src/modules/account-notify.c | 2 +- src/modules/account-tag.c | 2 +- src/modules/chanmodes/delayjoin.c | 4 ++-- src/modules/join.c | 4 ++-- src/modules/nick.c | 2 +- src/modules/sasl.c | 3 ++- src/modules/svsmode.c | 12 +++++++++++- src/modules/tkl.c | 4 +--- src/modules/whois.c | 2 +- src/modules/whox.c | 5 ++--- 10 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/modules/account-notify.c b/src/modules/account-notify.c index b2e9c3b7a..b40fa295a 100644 --- a/src/modules/account-notify.c +++ b/src/modules/account-notify.c @@ -70,7 +70,7 @@ int account_notify_account_login(Client *client, MessageTag *recv_mtags) CAP_ACCOUNT_NOTIFY, mtags, ":%s ACCOUNT %s", client->name, - !isdigit(*client->user->svid) ? client->user->svid : "*"); + IsLoggedIn(client) ? client->user->svid : "*"); free_message_tags(mtags); return 0; } diff --git a/src/modules/account-tag.c b/src/modules/account-tag.c index 523da0770..11c5e659e 100644 --- a/src/modules/account-tag.c +++ b/src/modules/account-tag.c @@ -87,7 +87,7 @@ void mtag_add_account(Client *client, MessageTag *recv_mtags, MessageTag **mtag_ { MessageTag *m; - if (client && client->user && (*client->user->svid != '*') && !isdigit(*client->user->svid)) + if (IsLoggedIn(client)) { m = safe_alloc(sizeof(MessageTag)); safe_strdup(m->name, "account"); diff --git a/src/modules/chanmodes/delayjoin.c b/src/modules/chanmodes/delayjoin.c index 2cbb3259e..d6f948d36 100644 --- a/src/modules/chanmodes/delayjoin.c +++ b/src/modules/chanmodes/delayjoin.c @@ -221,7 +221,7 @@ void clear_user_invisible_announce(Channel *channel, Client *client, MessageTag ircsnprintf(exjoinbuf, sizeof(exjoinbuf), ":%s!%s@%s JOIN %s %s :%s", client->name, client->user->username, GetHost(client), channel->chname, - !isdigit(*client->user->svid) ? client->user->svid : "*", + IsLoggedIn(client) ? client->user->svid : "*", client->info); new_message_special(client, recv_mtags, &mtags, ":%s JOIN %s", client->name, channel->chname); @@ -343,7 +343,7 @@ int moded_chanmode(Client *client, Channel *channel, MessageTag *recv_mtags, cha sendto_one(user, mtags, ":%s!%s@%s JOIN %s %s :%s", i->client->name, i->client->user->username, GetHost(i->client), channel->chname, - !isdigit(*i->client->user->svid) ? i->client->user->svid : "*", + IsLoggedIn(i->client) ? i->client->user->svid : "*", i->client->info); } else { sendto_one(user, mtags, ":%s!%s@%s JOIN :%s", i->client->name, i->client->user->username, GetHost(i->client), channel->chname); diff --git a/src/modules/join.c b/src/modules/join.c index 3e0e1294a..eab4eb88b 100644 --- a/src/modules/join.c +++ b/src/modules/join.c @@ -198,7 +198,7 @@ void _send_join_to_local_users(Client *client, Channel *channel, MessageTag *mta ircsnprintf(exjoinbuf, sizeof(exjoinbuf), ":%s!%s@%s JOIN %s %s :%s", client->name, client->user->username, GetHost(client), channel->chname, - !isdigit(*client->user->svid) ? client->user->svid : "*", + IsLoggedIn(client) ? client->user->svid : "*", client->info); for (lp = channel->members; lp; lp = lp->next) @@ -722,7 +722,7 @@ void _userhost_changed(Client *client) ircsnprintf(exjoinbuf, sizeof(exjoinbuf), ":%s!%s@%s JOIN %s %s :%s", client->name, client->user->username, GetHost(client), channel->chname, - !isdigit(*client->user->svid) ? client->user->svid : "*", + IsLoggedIn(client) ? client->user->svid : "*", client->info); modes = get_chmodes_for_user(client, flags); diff --git a/src/modules/nick.c b/src/modules/nick.c index a686f719d..660f54247 100644 --- a/src/modules/nick.c +++ b/src/modules/nick.c @@ -689,7 +689,7 @@ nickkill2done: if (IsDead(client)) return; - if (client->user->svid[0] != '0') + if (IsLoggedIn(client)) { user_account_login(recv_mtags, client); /* no need to check for kill upon user_account_login() here diff --git a/src/modules/sasl.c b/src/modules/sasl.c index cceb9fef0..a25b38c1b 100644 --- a/src/modules/sasl.c +++ b/src/modules/sasl.c @@ -69,8 +69,9 @@ int sasl_account_login(Client *client, MessageTag *mtags) { if (!MyConnect(client)) return 0; + /* Notify user */ - if (client->user->svid[0] != '0') + if (IsLoggedIn(client)) { sendnumeric(client, RPL_LOGGEDIN, BadPtr(client->name) ? "*" : client->name, diff --git a/src/modules/svsmode.c b/src/modules/svsmode.c index 3bbd85beb..3f282218c 100644 --- a/src/modules/svsmode.c +++ b/src/modules/svsmode.c @@ -406,8 +406,18 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, char *parv[], case 'd': if (parv[3]) { + int was_logged_in = IsLoggedIn(target) ? 1 : 0; strlcpy(target->user->svid, parv[3], sizeof(target->user->svid)); - user_account_login(recv_mtags, target); + if (!was_logged_in && !IsLoggedIn(target)) + { + /* We don't care about users going from not logged in + * to not logged in, which is something that can happen + * from 0 to 123456, eg from no account to unconfirmed account. + */ + } else { + /* LOGIN or LOGOUT (or account change) */ + user_account_login(recv_mtags, target); + } if (MyConnect(target) && IsDead(target)) return; /* was killed due to *LINE on ~a probably */ } diff --git a/src/modules/tkl.c b/src/modules/tkl.c index 7f7a2c07f..c2a972431 100644 --- a/src/modules/tkl.c +++ b/src/modules/tkl.c @@ -4422,9 +4422,7 @@ void ban_target_to_tkl_layer(BanTarget ban_target, BanAction action, Client *cli if (ban_target == BAN_TARGET_ACCOUNT) { - if (client->user && client->user->svid && - strcmp(client->user->svid, "0") && - (*client->user->svid != ':')) + if (IsLoggedIn(client) && (*client->user->svid != ':')) { /* Place a ban on ~a:Accountname */ strlcpy(username, "~a:", sizeof(username)); diff --git a/src/modules/whois.c b/src/modules/whois.c index 20d8f7788..97b451c7b 100644 --- a/src/modules/whois.c +++ b/src/modules/whois.c @@ -328,7 +328,7 @@ CMD_FUNC(cmd_whois) * display services account name if it's actually a services account name and * not a legacy timestamp. --nenolod */ - if (!isdigit(*target->user->svid)) + if (IsLoggedIn(target)) sendnumeric(client, RPL_WHOISLOGGEDIN, name, target->user->svid); /* diff --git a/src/modules/whox.c b/src/modules/whox.c index 1a84664d2..5866ee376 100644 --- a/src/modules/whox.c +++ b/src/modules/whox.c @@ -426,8 +426,7 @@ static int do_match(Client *client, Client *acptr, char *mask, struct who_format return 1; /* match account */ - if (IsMatch(fmt, WMATCH_ACCOUNT) && !BadPtr(acptr->user->svid) && - !isdigit(*acptr->user->svid) && match_simple(mask, acptr->user->svid)) + if (IsMatch(fmt, WMATCH_ACCOUNT) && IsLoggedIn(acptr) && match_simple(mask, acptr->user->svid)) { return 1; } @@ -813,7 +812,7 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f (int)((MyUser(acptr) && !hide_idle_time(client, acptr)) ? (TStime() - acptr->local->last) : 0)); } if (HasField(fmt, FIELD_ACCOUNT)) - append_format(str, sizeof str, &pos, " %s", (!isdigit(*acptr->user->svid)) ? acptr->user->svid : "0"); + append_format(str, sizeof str, &pos, " %s", IsLoggedIn(acptr) ? acptr->user->svid : "0"); if (HasField(fmt, FIELD_OPLEVEL)) append_format(str, sizeof str, &pos, " %s", (channel && is_skochanop(acptr, channel)) ? "999" : "n/a"); if (HasField(fmt, FIELD_REPUTATION))