* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
- * Copyright (C) 2013-2014, 2016-2019 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2013-2014, 2016-2020 Sadie Powell <sadie@witchery.services>
* Copyright (C) 2013 ChrisTX <xpipe@hotmail.de>
* Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
FLAG_NO_EXEC = 2,
// All includes are disabled.
- FLAG_NO_INC = 4
+ FLAG_NO_INC = 4,
+
+ // &env.FOO; is disabled.
+ FLAG_NO_ENV = 8
};
// Represents the position within a config file.
}
}
+ bool wordchar(char ch)
+ {
+ return isalnum(ch)
+ || ch == '-'
+ || ch == '.'
+ || ch == '_';
+ }
+
void nextword(std::string& rv)
{
int ch = next();
while (isspace(ch))
ch = next();
- while (isalnum(ch) || ch == '_'|| ch == '-')
+ while (wordchar(ch))
{
rv.push_back(ch);
ch = next();
while (1)
{
ch = next();
- if (isalnum(ch) || (varname.empty() && ch == '#'))
+ if (wordchar(ch) || (varname.empty() && ch == '#'))
varname.push_back(ch);
else if (ch == ';')
break;
throw CoreException("Invalid numeric character reference '&" + varname + ";'");
value.push_back(static_cast<char>(lvalue));
}
+ else if (varname.compare(0, 4, "env.") == 0)
+ {
+ if (flags & FLAG_NO_ENV)
+ throw CoreException("XML environment entity reference in file included with noenv=\"yes\"");
+
+ const char* envstr = getenv(varname.c_str() + 4);
+ if (!envstr)
+ throw CoreException("Undefined XML environment entity reference '&" + varname + ";'");
+
+ value.append(envstr);
+ }
else
{
insp::flat_map<std::string, std::string>::iterator var = stack.vars.find(varname);
flags |= FLAG_NO_INC;
if (tag->getBool("noexec", false))
flags |= FLAG_NO_EXEC;
+ if (tag->getBool("noenv", false))
+ flags |= FLAG_NO_ENV;
if (!ParseFile(ServerInstance->Config->Paths.PrependConfig(name), flags, mandatorytag))
throw CoreException("Included");
flags |= FLAG_NO_INC;
if (tag->getBool("noexec", false))
flags |= FLAG_NO_EXEC;
+ if (tag->getBool("noenv", false))
+ flags |= FLAG_NO_ENV;
const std::string includedir = ServerInstance->Config->Paths.PrependConfig(name);
std::vector<std::string> files;
if (!FileSystem::GetFileList(includedir, files, "*.conf"))
throw CoreException("Unable to read directory for include: " + includedir);
- std::sort(files.begin(), files.end());
+ std::sort(files.begin(), files.end());
for (std::vector<std::string>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
{
const std::string path = includedir + '/' + *iter;
flags |= FLAG_NO_INC;
if (tag->getBool("noexec", true))
flags |= FLAG_NO_EXEC;
+ if (tag->getBool("noenv", true))
+ flags |= FLAG_NO_ENV;
if (!ParseFile(name, flags, mandatorytag, true))
throw CoreException("Included");
if(!readString(key, result))
return def;
- if (result == "yes" || result == "true" || result == "1" || result == "on")
+ if (stdalgo::string::equalsci(result, "yes") || stdalgo::string::equalsci(result, "true") || stdalgo::string::equalsci(result, "on") || result == "1")
return true;
- if (result == "no" || result == "false" || result == "0" || result == "off")
+
+ if (stdalgo::string::equalsci(result, "no") || stdalgo::string::equalsci(result, "false") || stdalgo::string::equalsci(result, "off") || result == "0")
return false;
ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Value of <" + tag + ":" + key + "> at " + getTagLocation() +