summaryrefslogtreecommitdiff
path: root/src/inspircd_io.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-29 15:54:21 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-29 15:54:21 +0000
commit092c202a5e64852d38b3157c0d8c7b51b866a7f2 (patch)
tree238c8b9c38549fe88c68c166f911bd753b501bd5 /src/inspircd_io.cpp
parentef70e0ac9cd103adcfc1b879c0a6c946fd53413b (diff)
Added include stack to detect looped includes
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1553 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspircd_io.cpp')
-rw-r--r--src/inspircd_io.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp
index e28290ec5..de3d23689 100644
--- a/src/inspircd_io.cpp
+++ b/src/inspircd_io.cpp
@@ -37,6 +37,7 @@ extern int openSockfd[MAXSOCKS];
extern time_t TIME;
extern bool unlimitcore;
extern int MaxConn;
+std::vector<std::string> include_stack;
void WriteOpers(char* text, ...);
@@ -298,6 +299,15 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream
}
// Fix the chmod of the file to restrict it to the current user and group
chmod(filename,0600);
+ for (int t = 0; t < include_stack.size(); t++)
+ {
+ if (std::string(filename) == include_stack[t])
+ {
+ *errorstream << "File " << filename << " is included recursively (looped inclusion)." << endl;
+ return false;
+ }
+ }
+ include_stack.push_back(filename);
// now open it
FILE* conf = fopen(filename,"r");
char buffer[MAXBUF];
@@ -314,6 +324,7 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream
if (!strncmp(buffer,"<include file=\"",15))
{
char* buf = buffer;
+ char confpath[10240],newconf[10240];
// include file directive
buf += 15; // advance to filename
for (int j = 0; j < strlen(buffer); j++)
@@ -325,13 +336,25 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream
}
}
log(DEFAULT,"Opening included file '%s'",buf);
+ if (*buf != '/')
+ {
+ strlcpy(confpath,CONFIG_FILE,10240);
+ if (strstr(confpath,"/inspircd.conf"))
+ {
+ // leaves us with just the path
+ *(strstr(confpath,"/inspircd.conf")) = '\0';
+ }
+ snprintf(newconf,10240,"%s/%s",confpath,buf);
+ }
+ else snprintf(newconf,10240,"%s",buf);
std::stringstream merge(stringstream::in | stringstream::out);
// recursively call LoadConf and get the new data, use the same errorstream
- LoadConf(buf, &merge, errorstream);
- // append &merge to the end of the file
- std::string newstuff = merge.str();
- // append the new stuff to the end of the line
- *target << newstuff;
+ if (LoadConf(newconf, &merge, errorstream))
+ {
+ // append to the end of the file
+ std::string newstuff = merge.str();
+ *target << newstuff;
+ }
}
else
{