]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-mode.c
DEFAULT_WHOWAS->DEF_RPL_WHOWAS; MAX_CMODES_ARG->MAX_HNDL_MODES_ARG
[ngircd-alex.git] / src / ngircd / irc-mode.c
index b469a16911f65292b0fddb3df21574dcaee0c642..0c63e7277b2fc3a6a2a172cc96fa07c9b9aa478d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -253,7 +253,6 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
                                                        set ? '+' : '-',
                                                        *mode_ptr);
                                x[0] = '\0';
-                               goto client_exit;
                        } else {
                                Log(LOG_DEBUG,
                                    "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
@@ -278,11 +277,10 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
                                strlcat(the_modes, x, sizeof(the_modes));
                }
        }
-client_exit:
 
        /* Are there changed modes? */
        if (the_modes[1]) {
-               /* Remoce needless action modifier characters */
+               /* Remove needless action modifier characters */
                len = strlen(the_modes) - 1;
                if (the_modes[len] == '+' || the_modes[len] == '-')
                        the_modes[len] = '\0';
@@ -377,7 +375,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
        char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
            argadd[CLIENT_PASS_LEN], *mode_ptr;
        bool connected, set, skiponce, retval, onchannel, modeok, use_servermode;
-       int mode_arg, arg_arg;
+       int mode_arg, arg_arg, mode_arg_count = 0;
        CLIENT *client;
        long l;
        size_t len;
@@ -430,6 +428,8 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                        mode_ptr++;
                if (!*mode_ptr) {
                        /* Try next argument if there's any */
+                       if (arg_arg < 0)
+                               break;
                        if (arg_arg > mode_arg)
                                mode_arg = arg_arg;
                        else
@@ -479,6 +479,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                case 'i': /* Invite only */
                case 'm': /* Moderated */
                case 'n': /* Only members can write */
+               case 'R': /* Registered users only */
                case 's': /* Secret channel */
                case 't': /* Topic locked */
                case 'z': /* Secure connections only */
@@ -490,6 +491,8 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                        Client_ID(Origin), Channel_Name(Channel));
                        break;
                case 'k': /* Channel key */
+                       if (mode_arg_count++ >= MAX_HNDL_MODES_ARG)
+                               goto chan_exit;
                        if (!set) {
                                if (modeok)
                                        x[0] = *mode_ptr;
@@ -524,6 +527,8 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                        }
                        break;
                case 'l': /* Member limit */
+                       if (mode_arg_count++ >= MAX_HNDL_MODES_ARG)
+                               goto chan_exit;
                        if (!set) {
                                if (modeok)
                                        x[0] = *mode_ptr;
@@ -594,6 +599,16 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                        Channel_Name(Channel));
                        break;
                /* --- Channel user modes --- */
+               case 'a':
+               case 'h':
+               case 'q':
+                       if (Client_Type(Client) != CLIENT_SERVER) {
+                               connected = IRC_WriteStrClient(Origin,
+                                       ERR_CHANOPRIVSNEEDED_MSG,
+                                       Client_ID(Origin),
+                                       Channel_Name(Channel));
+                               goto chan_exit;
+                       }
                case 'o': /* Channel operator */
                case 'v': /* Voice */
                        if (arg_arg > mode_arg) {
@@ -624,6 +639,8 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                /* --- Channel lists --- */
                case 'I': /* Invite lists */
                case 'b': /* Ban lists */
+                       if (mode_arg_count++ >= MAX_HNDL_MODES_ARG)
+                               goto chan_exit;
                        if (arg_arg > mode_arg) {
                                /* modify list */
                                if (modeok) {
@@ -650,18 +667,24 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                        }
                        break;
                default:
-                       Log(LOG_DEBUG,
-                           "Unknown mode \"%c%c\" from \"%s\" on %s!?",
-                           set ? '+' : '-', *mode_ptr, Client_ID(Origin),
-                           Channel_Name(Channel));
-                       if (Client_Type(Client) != CLIENT_SERVER)
+                       if (Client_Type(Client) != CLIENT_SERVER) {
+                               Log(LOG_DEBUG,
+                                   "Unknown mode \"%c%c\" from \"%s\" on %s!?",
+                                   set ? '+' : '-', *mode_ptr,
+                                   Client_ID(Origin), Channel_Name(Channel));
                                connected = IRC_WriteStrClient(Origin,
                                        ERR_UMODEUNKNOWNFLAG2_MSG,
                                        Client_ID(Origin),
                                        set ? '+' : '-', *mode_ptr);
-                       x[0] = '\0';
-                       goto chan_exit;
-               }       /* switch() */
+                               x[0] = '\0';
+                       } else {
+                               Log(LOG_DEBUG,
+                                   "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
+                                   set ? '+' : '-', *mode_ptr,
+                                   Client_ID(Origin), Channel_Name(Channel));
+                               x[0] = *mode_ptr;
+                       }
+               }
 
                if (!connected)
                        break;