]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Implement <disabled:usermodes> and <disabled:chanmodes>.
authoraquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 18 Jul 2008 15:29:58 +0000 (15:29 +0000)
committeraquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 18 Jul 2008 15:29:58 +0000 (15:29 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10032 e03df62e-2008-0410-955e-edbf42e46eb7

include/configreader.h
src/configreader.cpp
src/mode.cpp
src/modules/m_conn_umodes.cpp

index 877cb823df2d71fb376056bdd038cce877f490d5..7a753bcc705a5d37070959391605bac9b4fa0350 100644 (file)
@@ -446,6 +446,15 @@ class CoreExport ServerConfig : public Extensible
         */
        char DisabledCommands[MAXBUF];
 
+       /** This variable identifies which usermodes have been diabled.
+        */
+
+       char DisabledUModes[64];
+
+       /** This variable identifies which chanmodes have been disabled.
+        */
+       char DisabledCModes[64];
+
        /** The full path to the modules directory.
         * This is either set at compile time, or
         * overridden in the configuration file via
index 29ee55eb9c64b8d806e26a3fd988133825fdeadc..a302dd6ea2d451e901f902d65af894fba2a21bca 100644 (file)
@@ -299,6 +299,28 @@ bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance)
        return true;
 }
 
+bool ValidateDisabledUModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
+{
+       memset(conf->DisabledUModes, 0, 64);
+       for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
+       {
+               if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found.");
+               conf->DisabledUModes[*p - 'A'] = 1;
+       }
+       return true;
+}
+
+bool ValidateDisabledCModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
+{
+       memset(conf->DisabledCModes, 0, 64);
+       for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
+       {
+               if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found.");
+               conf->DisabledCModes[*p - 'A'] = 1;
+       }
+       return true;
+}
+
 bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if (!*(data.GetString()))
@@ -763,6 +785,8 @@ void ServerConfig::Read(bool bail, User* user)
        static char hidemodes[MAXBUF];  /* Modes to not allow listing from users below halfop */
        static char exemptchanops[MAXBUF];      /* Exempt channel ops from these modes */
        static char announceinvites[MAXBUF];    /* options:announceinvites setting */
+       static char disabledumodes[MAXBUF]; /* Disabled usermodes */
+       static char disabledcmodes[MAXBUF]; /* Disabled chanmodes */
        errstr.clear();
 
        include_stack.clear();
@@ -823,6 +847,8 @@ void ServerConfig::Read(bool bail, User* user)
                {"dns",         "timeout",      "5",                    new ValueContainerInt  (&this->dns_timeout),            DT_INTEGER,  NoValidation},
                {"options",     "moduledir",    MOD_PATH,               new ValueContainerChar (this->ModPath),                 DT_CHARPTR,  NoValidation},
                {"disabled",    "commands",     "",                     new ValueContainerChar (this->DisabledCommands),        DT_CHARPTR,  NoValidation},
+               {"disabled",    "usermodes",    "",                     new ValueContainerChar (disabledumodes),                DT_CHARPTR,  ValidateDisabledUModes},
+               {"disabled",    "chanmodes",    "",                     new ValueContainerChar (disabledcmodes),                DT_CHARPTR,  ValidateDisabledCModes},
                {"security",    "userstats",    "",                     new ValueContainerChar (this->UserStats),               DT_CHARPTR,  NoValidation},
                {"security",    "customversion","",                     new ValueContainerChar (this->CustomVersion),           DT_CHARPTR,  NoValidation},
                {"security",    "hidesplits",   "0",                    new ValueContainerBool (&this->HideSplits),             DT_BOOLEAN,  NoValidation},
index ca30f1b699ad569ab7cc2913f1bb0895dc1f6c4a..bce2b20191493a115f6957470bbe4d1f71f06847 100644 (file)
@@ -641,6 +641,17 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                        if (abort)
                                                                continue;
 
+                                                       /* If it's disabled, they have to be an oper.
+                                                        */
+                                                       if (IS_LOCAL(user) && !IS_OPER(user) && ((type == MODETYPE_CHANNEL ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes)[modehandlers[handler_id]->GetModeChar() - 'A']))
+                                                       {
+                                                               user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - %s mode %c has been locked by the administrator",
+                                                                               user->nick.c_str(),
+                                                                               type == MODETYPE_CHANNEL ? "channel" : "user",
+                                                                               modehandlers[handler_id]->GetModeChar());
+                                                               continue;
+                                                       }
+
                                                        /* It's an oper only mode, check if theyre an oper. If they arent,
                                                         * eat any parameter that  came with the mode, and continue to next
                                                         */
index e7ff2c584c706a5b2b600c2283f3df011c434ebc..42c0ec660d4022f3c2ead5ec523c8e66db59da00 100644 (file)
@@ -54,6 +54,11 @@ class ModuleModesOnConnect : public Module
                if (!IS_LOCAL(user))
                        return;
 
+               // Backup and zero out the disabled usermodes, so that we can override them here.
+               char save[64];
+               memcpy(save, ServerInstance->Config->DisabledUModes, 64);
+               memset(ServerInstance->Config->DisabledUModes, 0, 64);
+
                for (int j = 0; j < Conf->Enumerate("connect"); j++)
                {
                        std::string hostn = Conf->ReadValue("connect","allow",j);
@@ -90,6 +95,8 @@ class ModuleModesOnConnect : public Module
                                break;
                        }
                }
+
+               memcpy(ServerInstance->Config->DisabledUModes, save, 64);
        }
 };