X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fm_join.c;h=e0049667ca8a1eb691f603312e453ad0bb8688b6;hb=refs%2Fheads%2Fupstream;hp=f00872a28389cc923f9a51235952a51aa6aca03c;hpb=94966734dd6bad72d239cb6640467e29c73ff38f;p=ircu2.10.12-pk.git diff --git a/ircd/m_join.c b/ircd/m_join.c index f00872a..e004966 100644 --- a/ircd/m_join.c +++ b/ircd/m_join.c @@ -23,62 +23,6 @@ * $Id$ */ -/* - * m_functions execute protocol messages on this server: - * - * cptr is always NON-NULL, pointing to a *LOCAL* client - * structure (with an open socket connected!). This - * identifies the physical socket where the message - * originated (or which caused the m_function to be - * executed--some m_functions may call others...). - * - * sptr is the source of the message, defined by the - * prefix part of the message if present. If not - * or prefix not found, then sptr==cptr. - * - * (!IsServer(cptr)) => (cptr == sptr), because - * prefixes are taken *only* from servers... - * - * (IsServer(cptr)) - * (sptr == cptr) => the message didn't - * have the prefix. - * - * (sptr != cptr && IsServer(sptr) means - * the prefix specified servername. (?) - * - * (sptr != cptr && !IsServer(sptr) means - * that message originated from a remote - * user (not local). - * - * combining - * - * (!IsServer(sptr)) means that, sptr can safely - * taken as defining the target structure of the - * message in this server. - * - * *Always* true (if 'parse' and others are working correct): - * - * 1) sptr->from == cptr (note: cptr->from == cptr) - * - * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr - * *cannot* be a local connection, unless it's - * actually cptr!). [MyConnect(x) should probably - * be defined as (x == x->from) --msa ] - * - * parc number of variable parameter strings (if zero, - * parv is allowed to be NULL) - * - * parv a NULL terminated list of parameter pointers, - * - * parv[0], sender (prefix string), if not present - * this points to an empty string. - * parv[1]...parv[parc-1] - * pointers to additional parameters - * parv[parc] == NULL, *always* - * - * note: it is guaranteed that parv[0]..parv[parc-1] are all - * non-NULL pointers. - */ #include "config.h" #include "channel.h" @@ -97,28 +41,31 @@ #include "s_debug.h" #include "s_user.h" #include "send.h" +#include "sys.h" /* #include -- Now using assert in ircd_log.h */ #include #include -/* - * Helper function to find last 0 in a comma-separated list of - * channel names. +/** Searches for and handles a 0 in a join list. + * @param[in] cptr Client that sent us the message. + * @param[in] sptr Original source of message. + * @param[in] chanlist List of channels to join. + * @return First token in \a chanlist after the final 0 entry, which + * may be its nul terminator (if the final entry is a 0 entry). */ static char * -last0(char *chanlist) +last0(struct Client *cptr, struct Client *sptr, char *chanlist) { char *p; + int join0 = 0; for (p = chanlist; p[0]; p++) /* find last "JOIN 0" */ - if (p[0] == '0' && (p[1] == ',' || p[1] == '\0' || !IsChannelChar(p[1]))) { - chanlist = p; /* we'll start parsing here */ - - if (!p[1]) /* hit the end */ - break; - - p++; + if (p[0] == '0' && (p[1] == ',' || p[1] == '\0')) { + if (p[1] == ',') + p++; + chanlist = p + 1; + join0 = 1; } else { while (p[0] != ',' && p[0] != '\0') /* skip past channel name */ p++; @@ -127,43 +74,33 @@ last0(char *chanlist) break; } - return chanlist; -} - -/* - * Helper function to perform a JOIN 0 if needed; returns 0 if channel - * name is not 0, else removes user from all channels and returns 1. - */ -static int -join0(struct JoinBuf *join, struct Client *cptr, struct Client *sptr, - char *chan) -{ - struct Membership *member; - struct JoinBuf part; + if (join0) { + struct JoinBuf part; + struct Membership *member; - /* is it a JOIN 0? */ - if (chan[0] != '0' || chan[1] != '\0') - return 0; - - joinbuf_join(join, 0, 0); /* join special channel 0 */ + joinbuf_init(&part, sptr, cptr, JOINBUF_TYPE_PARTALL, + "Left all channels", 0); - /* leave all channels */ - joinbuf_init(&part, sptr, cptr, JOINBUF_TYPE_PARTALL, - "Left all channels", 0); + joinbuf_join(&part, 0, 0); - while ((member = cli_user(sptr)->channel)) - joinbuf_join(&part, member->channel, - IsZombie(member) ? CHFL_ZOMBIE : - IsDelayedJoin(member) ? CHFL_DELAYED : - 0); + while ((member = cli_user(sptr)->channel)) + joinbuf_join(&part, member->channel, + IsZombie(member) ? CHFL_ZOMBIE : + IsDelayedJoin(member) ? CHFL_DELAYED : + 0); - joinbuf_flush(&part); + joinbuf_flush(&part); + } - return 1; + return chanlist; } -/* - * m_join - generic message handler +/** Handle a JOIN message from a client connection. + * See @ref m_functions for discussion of the arguments. + * @param[in] cptr Client that sent us the message. + * @param[in] sptr Original source of message. + * @param[in] parc Number of arguments. + * @param[in] parv Argument vector. */ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { @@ -171,7 +108,6 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) struct JoinBuf join; struct JoinBuf create; struct Gline *gline; - unsigned int flags; char *p = 0; char *chanlist; char *name; @@ -183,24 +119,36 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) joinbuf_init(&join, sptr, cptr, JOINBUF_TYPE_JOIN, 0, 0); joinbuf_init(&create, sptr, cptr, JOINBUF_TYPE_CREATE, 0, TStime()); - chanlist = last0(parv[1]); /* find last "JOIN 0" */ + chanlist = last0(cptr, sptr, parv[1]); /* find last "JOIN 0" */ keys = parv[2]; /* remember where keys are */ for (name = ircd_strtok(&p, chanlist, ","); name; name = ircd_strtok(&p, 0, ",")) { - clean_channelname(name); + char *key = 0; - if (join0(&join, cptr, sptr, name)) /* did client do a JOIN 0? */ - continue; + /* If we have any more keys, take the first for this channel. */ + if (!BadPtr(keys) + && (keys = strchr(key = keys, ','))) + *keys++ = '\0'; - if (!IsChannelName(name)) + /* Empty keys are the same as no keys. */ + if (key && !key[0]) + key = 0; + + if (!IsChannelName(name) || !strIsIrcCh(name)) { /* bad channel name */ send_reply(sptr, ERR_NOSUCHCHANNEL, name); continue; } + if (cli_user(sptr)->joined >= feature_int(FEAT_MAXCHANNELSPERUSER) + && !HasPriv(sptr, PRIV_CHAN_LIMIT)) { + send_reply(sptr, ERR_TOOMANYCHANNELS, name); + break; /* no point processing the other channels */ + } + /* BADCHANed channel */ if ((gline = gline_find(name, GLINE_BADCHAN | GLINE_EXACT)) && GlineIsActive(gline) && !IsAnOper(sptr)) { @@ -208,47 +156,42 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) continue; } - if (!(chptr = FindChannel(name))) - flags = CHFL_CHANOP; - else if (find_member_link(chptr, sptr)) - continue; /* already on channel */ - else - flags = CHFL_DEOPPED; - - /* disallow creating local channels */ - if ((name[0] == '&') && !chptr && !feature_bool(FEAT_LOCAL_CHANNELS)) { + if (!(chptr = FindChannel(name))) { + if (((name[0] == '&') && !feature_bool(FEAT_LOCAL_CHANNELS)) + || strlen(name) > IRCD_MIN(CHANNELLEN, feature_int(FEAT_CHANNELLEN))) { send_reply(sptr, ERR_NOSUCHCHANNEL, name); continue; - } - - if (cli_user(sptr)->joined >= feature_int(FEAT_MAXCHANNELSPERUSER) && - !HasPriv(sptr, PRIV_CHAN_LIMIT)) { - send_reply(sptr, ERR_TOOMANYCHANNELS, chptr ? chptr->chname : name); - break; /* no point processing the other channels */ - } + } - if (chptr) { - char *key = 0; - int is_level0_op = 0; - int err = 0; + if (!(chptr = get_channel(sptr, name, CGT_CREATE))) + continue; - /* Check target change limits. */ - if (check_target_limit(sptr, chptr, chptr->chname, 0)) - continue; + /* Try to add the new channel as a recent target for the user. */ + if (check_target_limit(sptr, chptr, chptr->chname, 0)) { + chptr->members = 0; + destruct_channel(chptr); + continue; + } - /* If we have any more keys, take the first for this channel. */ - if (!BadPtr(keys) - && (keys = strchr(key = keys, ','))) - *keys++ = '\0'; + joinbuf_join(&create, chptr, CHFL_CHANOP | CHFL_CHANNEL_MANAGER); + } else if (find_member_link(chptr, sptr)) { + continue; /* already on channel */ + } else if (check_target_limit(sptr, chptr, chptr->chname, 0)) { + continue; + } else { + int flags = CHFL_DEOPPED; + int err = 0; /* Check Apass/Upass -- since we only ever look at a single * "key" per channel now, this hampers brute force attacks. */ - if (!BadPtr(key) && !strcmp(key, chptr->mode.apass)) { - is_level0_op = 1; - flags = (flags & ~CHFL_DEOPPED) | CHFL_CHANOP | CHFL_CHANNEL_MANAGER; - } else if (!BadPtr(key) && !strcmp(key, chptr->mode.upass)) { - is_level0_op = 1; - flags = (flags & ~CHFL_DEOPPED) | CHFL_CHANOP; + if (key && !strcmp(key, chptr->mode.apass)) + flags = CHFL_CHANOP | CHFL_CHANNEL_MANAGER; + else if (key && !strcmp(key, chptr->mode.upass)) + flags = CHFL_CHANOP; + else if (chptr->users == 0 && !chptr->mode.apass[0]) { + /* Joining a zombie channel (zannel): give ops and increment TS. */ + flags = CHFL_CHANOP; + chptr->creationtime++; } else if (IsInvited(sptr, chptr)) { /* Invites bypass these other checks. */ } else if (chptr->mode.mode & MODE_INVITEONLY) @@ -259,7 +202,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) err = ERR_NEEDREGGEDNICK; else if (find_ban(sptr, chptr->banlist)) err = ERR_BANNEDFROMCHAN; - else if (*chptr->mode.key && (BadPtr(key) || strcmp(chptr->mode.key, key))) + else if (*chptr->mode.key && (!key || strcmp(key, chptr->mode.key))) err = ERR_BADCHANNELKEY; /* An oper with WALK_LCHAN privilege can join a local channel @@ -268,14 +211,18 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) * could normally join the channel. */ if (IsLocalChannel(chptr->chname) && HasPriv(sptr, PRIV_WALK_LCHAN) - && !is_level0_op - && !BadPtr(key) - && !strcmp("OVERRIDE", key)) + && !(flags & CHFL_CHANOP) + && key && !strcmp(key, "OVERRIDE")) { switch (err) { case 0: - send_reply(sptr, ERR_DONTCHEAT, chptr->chname); - continue; + if (strcmp(chptr->mode.key, "OVERRIDE") + && strcmp(chptr->mode.apass, "OVERRIDE") + && strcmp(chptr->mode.upass, "OVERRIDE")) { + send_reply(sptr, ERR_DONTCHEAT, chptr->chname); + continue; + } + break; case ERR_INVITEONLYCHAN: err = 'i'; break; case ERR_CHANNELISFULL: err = 'l'; break; case ERR_BANNEDFROMCHAN: err = 'b'; break; @@ -284,29 +231,43 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) default: err = '?'; break; } /* send accountability notice */ - sendto_opmask_butone(0, SNO_HACK4, "OPER JOIN: %C JOIN %H " - "(overriding +%c)", sptr, chptr, err); + if (err) + sendto_opmask_butone(0, SNO_HACK4, "OPER JOIN: %C JOIN %H " + "(overriding +%c)", sptr, chptr, err); err = 0; } /* Is there some reason the user may not join? */ if (err) { - send_reply(sptr, err, chptr->chname); + switch(err) { + case ERR_NEEDREGGEDNICK: + send_reply(sptr, + ERR_NEEDREGGEDNICK, + chptr->chname, + feature_str(FEAT_URLREG)); + break; + default: + send_reply(sptr, err, chptr->chname); + break; + } continue; } joinbuf_join(&join, chptr, flags); - } else if (!(chptr = get_channel(sptr, name, CGT_CREATE))) - continue; /* couldn't get channel */ - else if (check_target_limit(sptr, chptr, chptr->chname, 1)) - { - /* Note: check_target_limit will only ever return 0 here */ - chptr->members = 0; - destruct_channel(chptr); /* created it... */ - continue; + if (flags & CHFL_CHANOP) { + struct ModeBuf mbuf; + /* Always let the server op him: this is needed on a net with older servers + because they 'destruct' channels immediately when they become empty without + sending out a DESTRUCT message. As a result, they would always bounce a mode + (as HACK(2)) when the user ops himself. + (There is also no particularly good reason to have the user op himself.) + */ + modebuf_init(&mbuf, &me, cptr, chptr, MODEBUF_DEST_SERVER); + modebuf_mode_client(&mbuf, MODE_ADD | MODE_CHANOP, sptr, + chptr->mode.apass[0] ? ((flags & CHFL_CHANNEL_MANAGER) ? 0 : 1) : MAXOPLEVEL); + modebuf_flush(&mbuf); + } } - else - joinbuf_join(&create, chptr, flags | CHFL_CHANNEL_MANAGER); del_invite(sptr, chptr); @@ -325,8 +286,12 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) return 0; } -/* - * ms_join - server message handler +/** Handle a JOIN message from a server connection. + * See @ref m_functions for discussion of the arguments. + * @param[in] cptr Client that sent us the message. + * @param[in] sptr Original source of message. + * @param[in] parc Number of arguments. + * @param[in] parv Argument vector. */ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { @@ -357,26 +322,12 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) joinbuf_init(&join, sptr, cptr, JOINBUF_TYPE_JOIN, 0, 0); - chanlist = last0(parv[1]); /* find last "JOIN 0" */ + chanlist = last0(cptr, sptr, parv[1]); /* find last "JOIN 0" */ for (name = ircd_strtok(&p, chanlist, ","); name; name = ircd_strtok(&p, 0, ",")) { - if (join0(&join, cptr, sptr, name)) /* did client do a JOIN 0? */ - continue; - - if (name[0] == '0' && name[1] == ':') - { - flags = CHFL_CHANOP | CHFL_CHANNEL_MANAGER; - name += 2; - } - else if (name[0] == '1' && name[1] == ':') - { - flags = CHFL_CHANOP; - name += 2; - } - else - flags = CHFL_DEOPPED; + flags = CHFL_DEOPPED; if (IsLocalChannel(name) || !IsChannelName(name)) { @@ -395,8 +346,7 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) } flags |= HasFlag(sptr, FLAG_TS8) ? CHFL_SERVOPOK : 0; - /* when the network is 2.10.11+ then remove MAGIC_REMOTE_JOIN_TS */ - chptr->creationtime = creation ? creation : MAGIC_REMOTE_JOIN_TS; + chptr->creationtime = creation; } else { /* We have a valid channel? */ if ((member = find_member_link(chptr, sptr))) @@ -412,9 +362,70 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) else flags |= HasFlag(sptr, FLAG_TS8) ? CHFL_SERVOPOK : 0; /* Always copy the timestamp when it is older, that is the only way to - ensure network-wide synchronization of creation times. */ - if (creation && creation < chptr->creationtime) + ensure network-wide synchronization of creation times. + We now also copy a creation time that only 1 second younger... + this is needed because the timestamp must be incremented + by one when someone joins an existing, but empty, channel. + However, this is only necessary when the channel is still + empty (also here) and when this channel doesn't have +A set. + + To prevent this from allowing net-rides on the channel, we + clear all modes from the channel. + + (Scenario for a net ride: c1 - s1 - s2 - c2, with c1 the only + user in the channel; c1 parts and rejoins, gaining ops. + Before s2 sees c1's part, c2 joins the channel and parts + immediately. s1 sees c1 part, c1 create, c2 join, c2 part; + c2's join resets the timestamp. s2 sees c2 join, c2 part, c1 + part, c1 create; but since s2 sees the channel as a zannel or + non-existent, it does not bounce the create with the newer + timestamp.) + */ + if (creation && (creation < chptr->creationtime || + (!chptr->mode.apass[0] && chptr->users == 0))) { + struct Membership *member; + struct ModeBuf mbuf; + chptr->creationtime = creation; + /* Wipe out the current modes on the channel. */ + modebuf_init(&mbuf, sptr, cptr, chptr, MODEBUF_DEST_CHANNEL | MODEBUF_DEST_HACK3); + + modebuf_mode(&mbuf, MODE_DEL | chptr->mode.mode); + chptr->mode.mode &= MODE_BURSTADDED | MODE_WASDELJOINS; + + if (chptr->mode.limit) { + modebuf_mode_uint(&mbuf, MODE_DEL | MODE_LIMIT, chptr->mode.limit); + chptr->mode.limit = 0; + } + + if (chptr->mode.key[0]) { + modebuf_mode_string(&mbuf, MODE_DEL | MODE_KEY, chptr->mode.key, 0); + chptr->mode.key[0] = '\0'; + } + + if (chptr->mode.upass[0]) { + modebuf_mode_string(&mbuf, MODE_DEL | MODE_UPASS, chptr->mode.upass, 0); + chptr->mode.upass[0] = '\0'; + } + + if (chptr->mode.apass[0]) { + modebuf_mode_string(&mbuf, MODE_DEL | MODE_APASS, chptr->mode.apass, 0); + chptr->mode.apass[0] = '\0'; + } + + for (member = chptr->members; member; member = member->next_member) + { + if (IsChanOp(member)) { + modebuf_mode_client(&mbuf, MODE_DEL | MODE_CHANOP, member->user, OpLevel(member)); + member->status &= ~CHFL_CHANOP; + } + if (HasVoice(member)) { + modebuf_mode_client(&mbuf, MODE_DEL | MODE_VOICE, member->user, OpLevel(member)); + member->status &= ~CHFL_VOICE; + } + } + modebuf_flush(&mbuf); + } } joinbuf_join(&join, chptr, flags);