diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-26 19:18:26 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-26 19:18:26 +0000 |
commit | 9ce18436e94c2cdebeba90eba30b3c3e1ca311ed (patch) | |
tree | 1e4ae4080759edadfde9ae232f7c465e326a230c /src | |
parent | a6e0557f91998c30469030f08464cc8cb6c11fd6 (diff) |
Revert configure so that we can uh, actually compile.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9037 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/configreader.cpp | 51 | ||||
-rw-r--r-- | src/modules.cpp | 4 |
2 files changed, 42 insertions, 13 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index 11c74f88c..7a7934f16 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -950,7 +950,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 +1266,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; @@ -1289,9 +1288,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,7 +1301,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o include_stack.push_back(filename); /* Start reading characters... */ - while (conf.get(ch)) + while ((ch = fgetc(conf))) { /* @@ -1364,7 +1360,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o { line += ch; char real_character; - if (conf.get(real_character)) + if ((real_character = fgetc(conf))) { if (real_character == 'n') real_character = '\n'; @@ -1470,9 +1466,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 +1573,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 +1601,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 +1643,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) diff --git a/src/modules.cpp b/src/modules.cpp index 6271213fd..8fd1e84de 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -823,8 +823,8 @@ ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : Se this->data = new ConfigDataHash; this->privatehash = true; this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out); - /*** XXX: Can return a 'not ready yet!' code! */ - this->readerror = ServerInstance->Config->LoadConf(*this->data, filename, *this->errorlog); + /*** XXX: This might block! */ + this->readerror = ServerInstance->Config->DoInclude(*this->data, filename, *this->errorlog); if (!this->readerror) this->error = CONF_FILE_NOT_FOUND; } |