]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Fix SID-sourced KILL being displayed to killee as from SID not from server name
[user/henk/code/inspircd.git] / src / configreader.cpp
index 617d5fdd507cf759d32701247e6534a09e8c89c0..e7613ce5a6c1b92803652f10bb6d74004e714378 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
 /* $CopyInstall: conf/modules.conf.example $(CONPATH) */
 /* $CopyInstall: conf/opers.conf.example $(CONPATH) */
 /* $CopyInstall: conf/links.conf.example $(CONPATH) */
+/* $CopyInstall: .gdbargs $(BASE) */
 
 #include "inspircd.h"
 #include <fstream>
 #include "xline.h"
 #include "exitcodes.h"
 #include "commands/cmd_whowas.h"
+#include "modes/cmode_h.h"
 
 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
 
@@ -358,6 +360,24 @@ bool ValidateMaxWho(ServerConfig* conf, const char*, const char*, ValueItem &dat
        return true;
 }
 
+bool ValidateHalfOp(ServerConfig* conf, const char*, const char*, ValueItem &data)
+{
+       ModeHandler* mh = conf->GetInstance()->Modes->FindMode('h', MODETYPE_CHANNEL);
+       if (data.GetBool() && !mh)
+       {
+               conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Enabling halfop mode.");
+               mh = new ModeChannelHalfOp(conf->GetInstance());
+               conf->GetInstance()->Modes->AddMode(mh);
+       }
+       else if (!data.GetBool() && mh)
+       {
+               conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Disabling halfop mode.");
+               conf->GetInstance()->Modes->DelMode(mh);
+               delete mh;
+       }
+       return true;
+}
+
 bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        conf->ReadFile(conf->MOTD, data.GetString());
@@ -457,24 +477,33 @@ bool InitConnect(ServerConfig* conf, const char*)
 {
        conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes... class list is:");
 
-       for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); item++)
+       for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; )
        {
-               conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "class: %p", *(item));
-       }
-
-
-       /*
-        * Remove all connect classes.. we'll reset the pointers in user classes
-        * once all new classes have been read from config.
-        */
-       while (conf->Classes.begin() != conf->Classes.end())
-       {
-               ConnectClass *c = *(conf->Classes.begin());
-               conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Deleting an old class! :) (%p)", c);
-
+               ConnectClass* c = *i;
 
-               conf->Classes.erase(conf->Classes.begin());
-               delete c;
+               /*
+                * only delete a class with refcount 0.
+                * this is needed to avoid trampling on a wild pointer (User::MyClass)!
+                * it's also the most simple way to do it, given that we're looking at threads..
+                * -- w00t
+                */
+               if (c->RefCount == 0)
+               {
+                       conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Removing connect class, refcount is 0!");
+
+                       /* This was causing a crash, because we'd set i to .begin() just here, but then the for loop's increment would
+                        * set it to .begin() + 1. Which if it was already the last thing in the list, wasn't good.
+                        * Now the increment is in the else { } below.
+                        */
+                       conf->Classes.erase(i);
+                       i = conf->Classes.begin(); // start over so we don't trample on a bad iterator
+               }
+               else
+               {
+                       /* also mark all existing classes disabled, if they still exist in the conf, they will be reenabled. */
+                       c->SetDisabled(true);
+                       i++;
+               }
        }
 
        return true;
@@ -490,18 +519,16 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
        const char* password = values[2].GetString();
        int timeout = values[3].GetInteger();
        int pingfreq = values[4].GetInteger();
-       int flood = values[5].GetInteger();
-       int threshold = values[6].GetInteger();
-       int sendq = values[7].GetInteger();
-       int recvq = values[8].GetInteger();
-       int localmax = values[9].GetInteger();
-       int globalmax = values[10].GetInteger();
-       int port = values[11].GetInteger();
-       const char* name = values[12].GetString();
-       const char* parent = values[13].GetString();
-       int maxchans = values[14].GetInteger();
-       unsigned long limit = values[15].GetInteger();
-       const char* hashtype = values[16].GetString();
+       int sendq = values[5].GetInteger();
+       int recvq = values[6].GetInteger();
+       int localmax = values[7].GetInteger();
+       int globalmax = values[8].GetInteger();
+       int port = values[9].GetInteger();
+       const char* name = values[10].GetString();
+       const char* parent = values[11].GetString();
+       int maxchans = values[12].GetInteger();
+       unsigned long limit = values[13].GetInteger();
+       const char* hashtype = values[14].GetString();
 
        conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Adding a connect class!");
 
@@ -520,7 +547,7 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
                        if (cc->GetName() == parent)
                        {
                                cc = new ConnectClass(name, cc);
-                               cc->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
+                               cc->Update(timeout, *allow ? allow : deny, pingfreq, password, sendq, recvq, localmax, globalmax, maxchans, port, limit);
                                conf->Classes.push_back(cc);
                                break;
                        }
@@ -535,13 +562,13 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
                        /* Find existing class by mask, the mask should be unique */
                        for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
                        {
-                               if ((*item)->GetHost() == allow)
+                               if ((*item)->GetHost() == allow && !(*item)->GetDisabled())
                                {
-                                       (*item)->Update(timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
+                                       (*item)->Update(timeout, allow, pingfreq, password, sendq, recvq, localmax, globalmax, maxchans, port, limit);
                                        return true;
                                }
                        }
-                       cc = new ConnectClass(name, timeout, flood, allow, pingfreq, password, hashtype, threshold, sendq, recvq, localmax, globalmax, maxchans);
+                       cc = new ConnectClass(name, timeout, allow, pingfreq, password, hashtype, sendq, recvq, localmax, globalmax, maxchans);
                        cc->limit = limit;
                        cc->SetPort(port);
                        conf->Classes.push_back(cc);
@@ -551,7 +578,7 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
                        /* Find existing class by mask, the mask should be unique */
                        for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
                        {
-                               if ((*item)->GetHost() == deny)
+                               if ((*item)->GetHost() == deny && !(*item)->GetDisabled())
                                {
                                        (*item)->Update(name, deny);
                                        (*item)->SetPort(port);
@@ -564,7 +591,6 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
                }
        }
 
-       conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Class added: %p", cc);
        return true;
 }
 
@@ -572,35 +598,6 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
  */
 bool DoneConnect(ServerConfig *conf, const char*)
 {
-       for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); item++)
-       {
-               conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "class: %p", *(item));
-       }
-
-       /*
-        * Update connect classes on all users.
-        */
-       conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Resetting connect classes for users...");
-       for (std::vector<User*>::iterator n = conf->GetInstance()->Users->local_users.begin(); n != conf->GetInstance()->Users->local_users.end(); n++)
-       {
-               User *u = *n;
-
-               /*
-                * Make their existing class go away so that SetClass doesn't touch a wild ptr, important!
-                */
-               u->MyClass = NULL;
-
-               u->SetClass();
-
-               /*
-                * Check that the user falls into a valid class block.. if they don't,
-                * they need to be quit, which CheckClass will do. -- w00t
-                */
-               u->CheckClass();
-               conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "%s is now in %p", u->uuid.c_str(), u->MyClass);
-       }
-
-
        conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Done adding connect classes!");
        return true;
 }
@@ -763,7 +760,8 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
        static char announceinvites[MAXBUF];    /* options:announceinvites setting */
        static char disabledumodes[MAXBUF]; /* Disabled usermodes */
        static char disabledcmodes[MAXBUF]; /* Disabled chanmodes */
-       errstr.clear();
+       /* std::ostringstream::clear() does not clear the string itself, only the error flags. */
+       this->errstr = new std::ostringstream(std::stringstream::in | std::stringstream::out);
 
        include_stack.clear();
 
@@ -818,14 +816,14 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
                {"options",     "fixedpart",    "",                     new ValueContainerChar (this->FixedPart),               DT_CHARPTR,  NoValidation},
                {"performance", "netbuffersize","10240",                new ValueContainerInt  (&this->NetBufferSize),          DT_INTEGER,  ValidateNetBufferSize},
                {"performance", "maxwho",       "128",                  new ValueContainerInt  (&this->MaxWhoResults),          DT_INTEGER,  ValidateMaxWho},
-               {"options",     "allowhalfop",  "0",                    new ValueContainerBool (&this->AllowHalfop),            DT_BOOLEAN,  NoValidation},
+               {"options",     "allowhalfop",  "0",                    new ValueContainerBool (&this->AllowHalfop),            DT_BOOLEAN,  ValidateHalfOp},
                {"dns",         "server",       "",                     new ValueContainerChar (this->DNSServer),               DT_IPADDRESS,DNSServerValidator},
                {"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},
-               {"disabled",    "fakenonexistant",      "0",                    new ValueContainerBool (&this->DisabledDontExist),              DT_BOOLEAN,  NoValidation},
+               {"disabled",    "fakenonexistant",      "0",            new ValueContainerBool (&this->DisabledDontExist),              DT_BOOLEAN,  NoValidation},
 
                {"security",            "runasuser",    "",             new ValueContainerChar(this->SetUser),                          DT_CHARPTR, NoValidation},
                {"security",            "runasgroup",   "",             new ValueContainerChar(this->SetGroup),                         DT_CHARPTR, NoValidation},
@@ -836,6 +834,8 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
                {"security",    "hidewhois",    "",                     new ValueContainerChar (this->HideWhoisServer),         DT_NOSPACES, NoValidation},
                {"security",    "hidekills",    "",                     new ValueContainerChar (this->HideKillsServer),         DT_NOSPACES,  NoValidation},
                {"security",    "operspywhois", "0",                    new ValueContainerBool (&this->OperSpyWhois),           DT_BOOLEAN,  NoValidation},
+               {"security",    "restrictbannedusers",  "1",            new ValueContainerBool (&this->RestrictBannedUsers),            DT_BOOLEAN,  NoValidation},
+               {"security",    "genericoper",  "0",                    new ValueContainerBool (&this->GenericOper),            DT_BOOLEAN,  NoValidation},
                {"performance", "nouserdns",    "0",                    new ValueContainerBool (&this->NoUserDns),              DT_BOOLEAN,  NoValidation},
                {"options",     "syntaxhints",  "0",                    new ValueContainerBool (&this->SyntaxHints),            DT_BOOLEAN,  NoValidation},
                {"options",     "cyclehosts",   "0",                    new ValueContainerBool (&this->CycleHosts),             DT_BOOLEAN,  NoValidation},
@@ -875,18 +875,16 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
        MultiConfig MultiValues[] = {
 
                {"connect",
-                               {"allow",       "deny",         "password",     "timeout",      "pingfreq",     "flood",
-                               "threshold",    "sendq",        "recvq",        "localmax",     "globalmax",    "port",
+                               {"allow",       "deny",         "password",     "timeout",      "pingfreq",
+                               "sendq",        "recvq",        "localmax",     "globalmax",    "port",
                                "name",         "parent",       "maxchans",     "limit",        "hash",
                                NULL},
-                               {"",            "",             "",             "",             "120",          "",
-                                "",            "",             "",             "3",            "3",            "0",
-                                "",            "",             "0",        "0",        "",
+                               {"",            "",                             "",                     "",                     "120",
+                                "",            "",                             "3",            "3",            "0",
+                                "",            "",                             "0",        "0",                "",
                                 NULL},
-                               {DT_IPADDRESS|DT_ALLOW_WILD,
-                                               DT_IPADDRESS|DT_ALLOW_WILD,
-                                                               DT_CHARPTR,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
-                               DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
+                               {DT_IPADDRESS|DT_ALLOW_WILD, DT_IPADDRESS|DT_ALLOW_WILD, DT_CHARPTR,    DT_INTEGER,     DT_INTEGER,
+                               DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
                                DT_NOSPACES,    DT_NOSPACES,    DT_INTEGER,     DT_INTEGER,     DT_CHARPTR},
                                InitConnect, DoConnect, DoneConnect},
 
@@ -919,7 +917,7 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
                                {"No reason",   "",             NULL},
                                {DT_CHARPTR,    DT_CHARPTR},
                                InitXLine, DoQLine, DoneConfItem},
-       
+
                {"badhost",
                                {"reason",      "host",         NULL},
                                {"No reason",   "",             NULL},
@@ -931,7 +929,7 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
                                {"No reason",   "",             NULL},
                                {DT_CHARPTR,    DT_CHARPTR},
                                InitXLine, DoELine, DoneELine},
-       
+
                {"type",
                                {"name",        "classes",      NULL},
                                {"",            "",             NULL},
@@ -943,7 +941,7 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
                                {"",            "",                             "",                             "",                     "",                     NULL},
                                {DT_NOSPACES,   DT_CHARPTR,     DT_CHARPTR,     DT_CHARPTR, DT_CHARPTR},
                                InitClasses, DoClass, DoneClassesAndTypes},
-       
+
                {NULL,
                                {NULL},
                                {NULL},
@@ -956,12 +954,15 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
        /* Make a copy here so if it fails then we can carry on running with an unaffected config */
        newconfig.clear();
 
-       if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr))
+       if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, *errstr))
        {
-               ReportConfigError(errstr.str(), bail, useruid);
+               ReportConfigError(errstr->str(), bail, useruid);
+               delete errstr;
                return;
        }
 
+       delete errstr;
+
        /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
        try
        {
@@ -994,14 +995,17 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
 
                        /* Silently ignore boot only values */
                        if (bootonly && !bail)
+                       {
+                               delete Values[Index].val;
                                continue;
+                       }
 
                        ConfValue(newconfig, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines);
                        ValueItem vi(item);
-                       
+
                        if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
                                throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
-       
+
                        ServerInstance->Threads->Lock();
                        switch (dt)
                        {
@@ -1240,12 +1244,6 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
        // write once here, to try it out and make sure its ok
        ServerInstance->WritePID(this->PID);
 
-       /* Switch over logfiles */
-       ServerInstance->Logs->CloseLogs();
-       ServerInstance->Logs->OpenFileLogs();
-
-       ServerInstance->Logs->Log("CONFIG", DEFAULT, "Done reading configuration file.");
-
        /* If we're rehashing, let's load any new modules, and unload old ones
         */
        if (!bail)
@@ -1336,24 +1334,11 @@ void ServerConfig::Read(bool bail, const std::string &useruid)
                                }
                        }
                }
-
-               ServerInstance->Logs->Log("CONFIG", DEFAULT, "Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(),(unsigned long)add,(unsigned long)added_modules.size());
-
                ServerInstance->Threads->Unlock();
 
        }
 
-       if (bail)
-       {
-               /** Note: This is safe, the method checks for user == NULL */
-               ServerInstance->Threads->Lock();
-               User* user = NULL;
-               if (!useruid.empty())
-                       user = ServerInstance->FindNick(useruid);
-               ServerInstance->Parser->SetupCommandTable(user);
-               ServerInstance->Threads->Unlock();
-       }
-       else
+       if (!bail)
        {
                if (!useruid.empty())
                {
@@ -1546,7 +1531,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* fil
                                {
                                        // errorstream << "Closing config tag on line " << linenumber << std::endl;
                                        in_tag = false;
-       
+
                                        /*
                                         * If this finds an <include> then ParseLine can simply call
                                         * LoadConf() and load the included config into the same ConfigDataHash
@@ -1557,7 +1542,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* fil
                                        last_successful_parse = linenumber;
 
                                        linenumber = bl;
-       
+
                                        line.clear();
                                }
                                else
@@ -1702,7 +1687,7 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, const std::string &filename
                                                got_key = false;
 
                                                if ((tagname == "include") && (current_key == "file"))
-                                               {       
+                                               {
                                                        if (!this->DoInclude(target, current_value, errorstream))
                                                                return false;
                                                }
@@ -2042,7 +2027,7 @@ bool ServerConfig::FileExists(const char* file)
 
        if ((sb.st_mode & S_IFDIR) > 0)
                return false;
-            
+
        FILE *input;
        if ((input = fopen (file, "r")) == NULL)
                return false;
@@ -2391,4 +2376,3 @@ void ConfigReaderThread::Run()
        this->SetExitFlag();
        ServerInstance->Threads->Unlock();
 }
-