X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Firc-channel.c;h=6ddad88b1a9f3817d28a6c3962f03064348eaf3a;hb=05cc9bf9b064c7048f6b197462a686c5a9100798;hp=8aa27c01aabfc586ebede81d5586df2a0d071e6c;hpb=02592f912e9f4e43f4501ff4f15953d21b77d8b2;p=ngircd-alex.git diff --git a/src/ngircd/irc-channel.c b/src/ngircd/irc-channel.c index 8aa27c01..6ddad88b 100644 --- a/src/ngircd/irc-channel.c +++ b/src/ngircd/irc-channel.c @@ -7,13 +7,15 @@ * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. - * - * IRC channel commands */ - #include "portab.h" +/** + * @file + * IRC channel commands + */ + #include "imp.h" #include #include @@ -37,13 +39,18 @@ #include "irc-channel.h" -/* +/** + * Part from all channels. + * * RFC 2812, (3.2.1 Join message Command): - * Note that this message - * accepts a special argument ("0"), which is a special request to leave all - * channels the user is currently a member of. The server will process this - * message as if the user had sent a PART command (See Section 3.2.2) for - * each channel he is a member of. + * Note that this message accepts a special argument ("0"), which is a + * special request to leave all channels the user is currently a member of. + * The server will process this message as if the user had sent a PART + * command (See Section 3.2.2) for each channel he is a member of. + * + * @param client Client that initiated the part request + * @param target Client that should part all joined channels + * @returns CONNECTED or DISCONNECTED */ static bool part_from_all_channels(CLIENT* client, CLIENT *target) @@ -57,17 +64,18 @@ part_from_all_channels(CLIENT* client, CLIENT *target) Channel_Part(target, client, Channel_Name(chan), Client_ID(target)); } return CONNECTED; -} +} /* part_from_all_channels */ /** * Check weather a local client is allowed to join an already existing * channel or not. - * @param Client Client that sent the JOIN command - * @param chan Channel to check - * @param channame Name of the channel - * @param key Provided channel key (or NULL if none has been provided) - * @return true if client is allowed to join channel, false otherwise + * + * @param Client Client that sent the JOIN command + * @param chan Channel to check + * @param channame Name of the channel + * @param key Provided channel key (or NULL) + * @returns true if client is allowed to join, false otherwise */ static bool join_allowed(CLIENT *Client, CHANNEL *chan, const char *channame, @@ -122,10 +130,31 @@ join_allowed(CLIENT *Client, CHANNEL *chan, const char *channame, return false; } + if (strchr(channel_modes, 'O') && !Client_OperByMe(Client)) { + /* Only IRC operators are allowed! */ + IRC_WriteStrClient(Client, ERR_OPONLYCHANNEL_MSG, + Client_ID(Client), channame); + return false; + } + + if (strchr(channel_modes, 'R') && !strchr(Client_Modes(Client), 'R')) { + /* Only registered users are allowed! */ + IRC_WriteStrClient(Client, ERR_REGONLYCHANNEL_MSG, + Client_ID(Client), channame); + return false; + } + return true; -} +} /* join_allowed */ +/** + * Set user channel modes. + * + * @param chan Channel + * @param target User to set modes for + * @param flags Channel modes to add + */ static void join_set_channelmodes(CHANNEL *chan, CLIENT *target, const char *flags) { @@ -139,9 +168,22 @@ join_set_channelmodes(CHANNEL *chan, CLIENT *target, const char *flags) /* If channel persistent and client is ircop: make client chanop */ if (strchr(Channel_Modes(chan), 'P') && strchr(Client_Modes(target), 'o')) Channel_UserModeAdd(chan, target, 'o'); -} +} /* join_set_channelmodes */ +/** + * Forward JOIN command to a specific server + * + * This function diffentiates between servers using RFC 2813 mode that + * support the JOIN command with appended ASCII 7 character and channel + * modes, and servers using RFC 1459 protocol which require separate JOIN + * and MODE commands. + * + * @param To Forward JOIN (and MODE) command to this peer server + * @param Prefix Client used to prefix the genrated commands + * @param Data Parameters of JOIN command to forward, probably + * containing channel modes separated by ASCII 7. + */ static void cb_join_forward(CLIENT *To, CLIENT *Prefix, void *Data) { @@ -166,12 +208,25 @@ cb_join_forward(CLIENT *To, CLIENT *Prefix, void *Data) } /* cb_join_forward */ +/** + * Forward JOIN command to all servers + * + * This function calls cb_join_forward(), which differentiates between + * protocol implementations (e.g. RFC 2812, RFC 1459). + * + * @param Client Client used to prefix the genrated commands + * @param target Forward JOIN (and MODE) command to this peer server + * @param chan Channel structure + * @param channame Channel name + */ static void join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan, const char *channame) { char modes[CHANNEL_MODE_LEN], str[COMMAND_LEN]; + /* RFC 2813, 4.2.1: channel modes are separated from the channel + * name with ASCII 7, if any, and not spaces: */ strlcpy(&modes[1], Channel_UserModes(chan, target), sizeof(modes) - 1); if (modes[1]) modes[0] = 0x7; @@ -189,7 +244,7 @@ join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan, IRC_WriteStrChannelPrefix(Client, chan, target, false, "JOIN :%s", channame); - /* syncronize channel modes */ + /* synchronize channel modes */ if (modes[1]) { IRC_WriteStrChannelPrefix(Client, chan, target, false, "MODE %s +%s %s", channame, @@ -198,6 +253,14 @@ join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan, } /* join_forward */ +/** + * Aknowledge user JOIN request and send "channel info" numerics. + * + * @param Client Client used to prefix the genrated commands + * @param target Forward commands/numerics to this user + * @param chan Channel structure + * @param channame Channel name + */ static bool join_send_topic(CLIENT *Client, CLIENT *target, CHANNEL *chan, const char *channame) @@ -228,10 +291,20 @@ join_send_topic(CLIENT *Client, CLIENT *target, CHANNEL *chan, /* send list of channel members to client */ if (!IRC_Send_NAMES(Client, chan)) return false; - return IRC_WriteStrClient(Client, RPL_ENDOFNAMES_MSG, Client_ID(Client), Channel_Name(chan)); -} + return IRC_WriteStrClient(Client, RPL_ENDOFNAMES_MSG, Client_ID(Client), + Channel_Name(chan)); +} /* join_send_topic */ +/** + * Handler for the IRC "JOIN" command. + * + * See RFC 2812, 3.2.1 "Join message"; RFC 2813, 4.2.1 "Join message". + * + * @param Client The client from which this command has been received + * @param Req Request structure with prefix and all parameters + * @returns CONNECTED or DISCONNECTED + */ GLOBAL bool IRC_JOIN( CLIENT *Client, REQUEST *Req ) { @@ -239,8 +312,8 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) CLIENT *target; CHANNEL *chan; - assert( Client != NULL ); - assert( Req != NULL ); + assert (Client != NULL); + assert (Req != NULL); /* Bad number of arguments? */ if (Req->argc < 1 || Req->argc > 2) @@ -254,7 +327,8 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) target = Client; if (!target) - return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix); + return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, + Client_ID(Client), Req->prefix); /* Is argument "0"? */ if (Req->argc == 1 && !strncmp("0", Req->argv[0], 2)) @@ -286,8 +360,9 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) chan = Channel_Search(channame); if (!chan && Conf_PredefChannelsOnly) { - /* channel must be created, but server does not allow this */ - IRC_WriteStrClient(Client, ERR_BANNEDFROMCHAN_MSG, Client_ID(Client), channame); + /* channel must be created, but forbidden by config */ + IRC_WriteStrClient(Client, ERR_BANNEDFROMCHAN_MSG, + Client_ID(Client), channame); break; } @@ -326,7 +401,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) /* Join channel (and create channel if it doesn't exist) */ if (!Channel_Join(target, channame)) - break; + goto join_next; if (!chan) { /* channel is new; it has been created above */ chan = Channel_Search(channame); @@ -345,6 +420,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) if (!join_send_topic(Client, target, chan, channame)) break; /* write error */ + join_next: /* next channel? */ channame = strtok_r(NULL, ",", &lastchan); if (channame && key) @@ -356,6 +432,12 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) /** * Handler for the IRC "PART" command. + * + * See RFC 2812, 3.2.2: "Part message". + * + * @param Client The client from which this command has been received + * @param Req Request structure with prefix and all parameters + * @returns CONNECTED or DISCONNECTED */ GLOBAL bool IRC_PART(CLIENT * Client, REQUEST * Req) @@ -401,13 +483,22 @@ IRC_PART(CLIENT * Client, REQUEST * Req) } /* IRC_PART */ +/** + * Handler for the IRC "TOPIC" command. + * + * See RFC 2812, 3.2.4 "Topic message". + * + * @param Client The client from which this command has been received + * @param Req Request structure with prefix and all parameters + * @returns CONNECTED or DISCONNECTED + */ GLOBAL bool IRC_TOPIC( CLIENT *Client, REQUEST *Req ) { CHANNEL *chan; CLIENT *from; char *topic; - bool r; + bool onchannel, topicok, use_servermode, r; assert( Client != NULL ); assert( Req != NULL ); @@ -430,7 +521,10 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) return IRC_WriteStrClient(from, ERR_NOSUCHCHANNEL_MSG, Client_ID(from), Req->argv[0]); - if (!Channel_IsMemberOf(chan, from)) + Channel_CheckAdminRights(chan, Client, from, + &onchannel, &topicok, &use_servermode); + + if (!onchannel && !topicok) return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(from), Req->argv[0]); @@ -442,6 +536,8 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) Client_ID(Client), Channel_Name(chan), topic); #ifndef STRICT_RFC + if (!r) + return r; r = IRC_WriteStrClient(from, RPL_TOPICSETBY_MSG, Client_ID(Client), Channel_Name(chan), @@ -457,8 +553,8 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) } if (strchr(Channel_Modes(chan), 't')) { - /* Topic Lock. Is the user a channel operator? */ - if (!strchr(Channel_UserModes(chan, from), 'o')) + /* Topic Lock. Is the user a channel or IRC operator? */ + if (!topicok) return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(from), Channel_Name(chan)); @@ -470,6 +566,9 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) Client_TypeText(from), Client_Mask(from), Channel_Name(chan), Req->argv[1][0] ? Req->argv[1] : ""); + if (use_servermode) + from = Client_ThisServer(); + /* Update channel and forward new topic to other servers */ if (!Channel_IsLocal(chan)) IRC_WriteStrServersPrefix(Client, from, "TOPIC %s :%s", @@ -487,8 +586,15 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) /** * Handler for the IRC "LIST" command. + * + * See RFC 2812, 3.2.6 "List message". + * * This implementation handles the local case as well as the forwarding of the * LIST command to other servers in the IRC network. + * + * @param Client The client from which this command has been received + * @param Req Request structure with prefix and all parameters + * @returns CONNECTED or DISCONNECTED */ GLOBAL bool IRC_LIST( CLIENT *Client, REQUEST *Req ) @@ -572,6 +678,16 @@ IRC_LIST( CLIENT *Client, REQUEST *Req ) } /* IRC_LIST */ +/** + * Handler for the IRC+ command "CHANINFO". + * + * See doc/Protocol.txt, section II.3: + * "Exchange channel-modes, topics, and persistent channels". + * + * @param Client The client from which this command has been received + * @param Req Request structure with prefix and all parameters + * @returns CONNECTED or DISCONNECTED + */ GLOBAL bool IRC_CHANINFO( CLIENT *Client, REQUEST *Req ) { @@ -584,7 +700,9 @@ IRC_CHANINFO( CLIENT *Client, REQUEST *Req ) assert( Req != NULL ); /* Bad number of parameters? */ - if(( Req->argc < 2 ) || ( Req->argc == 4 ) || ( Req->argc > 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); + if (Req->argc < 2 || Req->argc == 4 || Req->argc > 5) + return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, + Client_ID(Client), Req->command); /* Compatibility kludge */ if( Req->argc == 5 ) arg_topic = 4;