]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Fix multiple (useless) linefeeds on the end of ADDLINE in burst
[user/henk/code/inspircd.git] / src / configreader.cpp
index 11c74f88c56f6b893baec71c2fc4b61d71c64469..7ca1a81250c3f403975553df77c603ff9351c4e3 100644 (file)
@@ -520,13 +520,6 @@ bool InitConnect(ServerConfig* conf, const char*)
 {
        conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes...");
 
-       for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end(); i++)
-       {
-               ConnectClass *c = *i;
-
-               conf->GetInstance()->Logs->Log("CONFIG",DEBUG, "Address of class is %p", c);
-       }
-
        for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; )
        {
                ConnectClass* c = *i;
@@ -950,7 +943,7 @@ void ServerConfig::Read(bool bail, User* user)
        /* Make a copy here so if it fails then we can carry on running with an unaffected config */
        newconfig.clear();
 
-       if (this->LoadConf(newconfig, ServerInstance->ConfigFileName, errstr))
+       if (this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr))
        {
                /* If we succeeded, set the ircd config to the new one */
                ServerInstance->Threads->Mutex(true);
@@ -1266,9 +1259,8 @@ void ServerConfig::Read(bool bail, User* user)
 }
 
 
-bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::ostringstream &errorstream)
+bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* filename, std::ostringstream &errorstream)
 {
-       std::ifstream conf(filename);
        std::string line;
        char ch;
        long linenumber;
@@ -1282,6 +1274,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
        in_quote = false;
        in_comment = false;
 
+       ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading %s", filename);
+
        /* Check if the file open failed first */
        if (!conf)
        {
@@ -1289,9 +1283,6 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                return false;
        }
 
-       /* Fix the chmod of the file to restrict it to the current user and group */
-       chmod(filename,0600);
-
        for (unsigned int t = 0; t < include_stack.size(); t++)
        {
                if (std::string(filename) == include_stack[t])
@@ -1305,9 +1296,9 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
        include_stack.push_back(filename);
 
        /* Start reading characters... */
-       while (conf.get(ch))
+       while (!feof(conf))
        {
-
+               ch = fgetc(conf);
                /*
                 * Fix for moronic windows issue spotted by Adremelech.
                 * Some windows editors save text files as utf-16, which is
@@ -1364,8 +1355,9 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                {
                        line += ch;
                        char real_character;
-                       if (conf.get(real_character))
+                       if (!feof(conf))
                        {
+                               real_character = fgetc(conf);
                                if (real_character == 'n')
                                        real_character = '\n';
                                line += real_character;
@@ -1470,9 +1462,9 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
 }
 
 
-bool ServerConfig::LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream)
+bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const std::string &filename, std::ostringstream &errorstream)
 {
-       return this->LoadConf(target, filename.c_str(), errorstream);
+       return this->LoadConf(target, conf, filename.c_str(), errorstream);
 }
 
 bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long &linenumber, std::ostringstream &errorstream)
@@ -1577,6 +1569,12 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long &li
                                                        if (!this->DoInclude(target, current_value, errorstream))
                                                                return false;
                                                }
+                                               else if ((tagname == "include") && (current_key == "executable"))
+                                               {
+                                                       /* Pipe an executable and use its stdout as config data */
+                                                       if (!this->DoPipe(target, current_value, errorstream))
+                                                               return false;
+                                               }
 
                                                current_key.clear();
                                                current_value.clear();
@@ -1599,6 +1597,22 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long &li
        return true;
 }
 
+bool ServerConfig::DoPipe(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream)
+{
+       FILE* conf = popen(file.c_str(), "r");
+       bool ret = false;
+
+       if (conf)
+       {
+               ret = LoadConf(target, conf, file.c_str(), errorstream);
+               pclose(conf);
+       }
+       else
+               errorstream << "Couldn't execute: " << file << std::endl;
+
+       return ret;
+}
+
 bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream)
 {
        std::string confpath;
@@ -1625,7 +1639,18 @@ bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, st
                }
        }
 
-       return LoadConf(target, newfile, errorstream);
+       FILE* conf = fopen(newfile.c_str(), "r");
+       bool ret = false;
+
+       if (conf)
+       {
+               ret = LoadConf(target, conf, newfile, errorstream);
+               fclose(conf);
+       }
+       else
+               errorstream << "Couldn't open config file: " << file << std::endl;
+
+       return ret;
 }
 
 bool ServerConfig::ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds)