]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Merge commit 'danieldg/out-12'
[user/henk/code/inspircd.git] / src / configreader.cpp
index 5735b395c93217dabd0f46e58adf9eec4dfaeef0..ca03056c5c35645dbd6fcfeff15e2244dd003cba 100644 (file)
@@ -455,18 +455,35 @@ bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueItem &dat
  */
 bool InitConnect(ServerConfig* conf, const char*)
 {
-       conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes...");
+       conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes... class list is:");
 
-       /*
-        * 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())
+       for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; )
        {
-               ConnectClass *c = *conf->Classes.begin();
+               ConnectClass* c = *i;
 
-               delete c;
-               conf->Classes.erase(conf->Classes.begin());
+               /*
+                * 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;
@@ -497,6 +514,8 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
 
        conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Adding a connect class!");
 
+       ConnectClass *cc = NULL;
+
        if (*parent)
        {
                /* Find 'parent' and inherit a new class from it,
@@ -505,13 +524,13 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
                ClassVector::iterator item = conf->Classes.begin();
                for (; item != conf->Classes.end(); ++item)
                {
-                       ConnectClass* cc = *item;
+                       cc = *item;
                        conf->GetInstance()->Logs->Log("CONFIG",DEBUG,"Class: %s", cc->GetName().c_str());
                        if (cc->GetName() == parent)
                        {
-                               ConnectClass* newclass = new ConnectClass(name, cc);
-                               newclass->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
-                               conf->Classes.push_back(newclass);
+                               cc = new ConnectClass(name, cc);
+                               cc->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
+                               conf->Classes.push_back(cc);
                                break;
                        }
                }
@@ -525,13 +544,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);
                                        return true;
                                }
                        }
-                       ConnectClass* cc = new ConnectClass(name, timeout, flood, allow, pingfreq, password, hashtype, threshold, sendq, recvq, localmax, globalmax, maxchans);
+                       cc = new ConnectClass(name, timeout, flood, allow, pingfreq, password, hashtype, threshold, sendq, recvq, localmax, globalmax, maxchans);
                        cc->limit = limit;
                        cc->SetPort(port);
                        conf->Classes.push_back(cc);
@@ -541,14 +560,14 @@ 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);
                                        return true;
                                }
                        }
-                       ConnectClass* cc = new ConnectClass(name, deny);
+                       cc = new ConnectClass(name, deny);
                        cc->SetPort(port);
                        conf->Classes.push_back(cc);
                }
@@ -561,23 +580,6 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
  */
 bool DoneConnect(ServerConfig *conf, const char*)
 {
-       /*
-        * Update connect classes on all users.
-        */
-       for (std::vector<User*>::iterator n = conf->GetInstance()->Users->local_users.begin(); n != conf->GetInstance()->Users->local_users.end(); n++)
-       {
-               User *u = *n;
-
-               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, "Done adding connect classes!");
        return true;
 }
@@ -740,7 +742,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();
 
@@ -933,11 +936,14 @@ 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
@@ -971,7 +977,10 @@ 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);