From ca2ba56d82d5fdd959cceaa68eee3722fe45f4f0 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 25 Apr 2020 17:01:41 +0200 Subject: [PATCH] Add is_invited(client, channel) function. --- include/h.h | 3 ++- src/channel.c | 14 ++++++++++++++ src/modules/chanmodes/secureonly.c | 7 +++---- src/modules/join.c | 19 +++++-------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/h.h b/include/h.h index 2d4cfc091..27596f3e0 100644 --- a/include/h.h +++ b/include/h.h @@ -174,7 +174,6 @@ extern void set_snomask(Client *client, char *snomask); extern char *get_snomask_string(Client *client); extern int check_tkls(Client *cptr); /* for services */ -extern void del_invite(Client *, Channel *); extern void send_user_joins(Client *, Client *); extern int valid_channelname(const char *); extern int valid_server_name(char *name); @@ -623,6 +622,8 @@ extern char *spamfilter_inttostring_long(int v); extern Channel *get_channel(Client *cptr, char *chname, int flag); extern MODVAR char backupbuf[]; extern void add_invite(Client *, Client *, Channel *, MessageTag *); +extern void del_invite(Client *, Channel *); +extern int is_invited(Client *client, Channel *channel); extern void channel_modes(Client *cptr, char *mbuf, char *pbuf, size_t mbuf_size, size_t pbuf_size, Channel *channel); extern MODVAR char modebuf[BUFSIZE], parabuf[BUFSIZE]; extern int op_can_override(char *acl, Client *client,Channel *channel,void* extra); diff --git a/src/channel.c b/src/channel.c index a2ce6529a..ddb48747f 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1031,6 +1031,20 @@ void del_invite(Client *client, Channel *channel) } } +/** Is the user 'client' invited to channel 'channel' by a chanop? + * @param client The client who was invited + * @param channel The channel to which the person was invited + */ +int is_invited(Client *client, Channel *channel) +{ + Link *lp; + + for (lp = client->user->invited; lp; lp = lp->next) + if (lp->value.channel == channel) + return 1; + return 0; +} + /** Subtract one user from channel i. Free the channel if it became empty. * @param channel The channel * @returns 1 if the channel was freed, 0 if the channel still exists. diff --git a/src/modules/chanmodes/secureonly.c b/src/modules/chanmodes/secureonly.c index 0330e701e..9d3bd68ed 100644 --- a/src/modules/chanmodes/secureonly.c +++ b/src/modules/chanmodes/secureonly.c @@ -140,11 +140,10 @@ int secureonly_check_join(Client *client, Channel *channel, char *key, char *par /* if the channel is +z we still allow an ircop to bypass it * if they are invited. */ - for (lp = client->user->invited; lp; lp = lp->next) - if (lp->value.channel == channel) - return HOOK_CONTINUE; + if (is_invited(client, channel)) + return HOOK_CONTINUE; } - return (ERR_SECUREONLYCHAN); + return ERR_SECUREONLYCHAN; } return 0; } diff --git a/src/modules/join.c b/src/modules/join.c index c50837cb0..334256e00 100644 --- a/src/modules/join.c +++ b/src/modules/join.c @@ -113,9 +113,8 @@ int _can_join(Client *client, Channel *channel, char *key, char *parv[]) if (banned && j == HOOK_DENY) return (ERR_BANNEDFROMCHAN); - for (lp = client->user->invited; lp; lp = lp->next) - if (lp->value.channel == channel) - return 0; + if (is_invited(client, channel)) + return 0; /* allowed */ if (channel->users >= channel->mode.limit) { @@ -515,20 +514,12 @@ void _do_join(Client *client, int parc, char *parv[]) !strcasecmp(name, SPAMFILTER_VIRUSCHAN) && !ValidatePermissionsForPath("immune:server-ban:viruschan",client,NULL,NULL,NULL) && !spamf_ugly_vchanoverride) { - int invited = 0; - Link *lp; Channel *channel = find_channel(name, NULL); - if (channel) + if (!channel || !is_invited(client, channel)) { - for (lp = client->user->invited; lp; lp = lp->next) - if (lp->value.channel == channel) - invited = 1; - } - if (!invited) - { - sendnotice(client, "*** Cannot join '%s' because it's the virus-help-channel which is " - "reserved for infected users only", name); + sendnotice(client, "*** Cannot join '%s' because it's the virus-help-channel " + "which is reserved for infected users only", name); continue; } }