/*
- suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
+ suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
This file is part of suPHP.
std::string str = bstr;
// Convert upper characters to lower characters
for (int i=0; i<str.size(); i++) {
- if (str[i] >= 65 && str[i] <= 90)
- str[i] += 32;
+ if (str[i] >= 65 && str[i] <= 90)
+ str[i] += 32;
}
if (str == std::string("true")) {
- return true;
+ return true;
} else if (str == std::string("yes")) {
- return true;
+ return true;
} else if (str == std::string("on")) {
- return true;
+ return true;
} else if (str == std::string("enabled")) {
- return true;
+ return true;
} else if (str == std::string("1")) {
- return true;
+ return true;
} else if (str == std::string("false")) {
- return false;
+ return false;
} else if (str == std::string("no")) {
- return false;
+ return false;
} else if (str == std::string("off")) {
- return false;
+ return false;
} else if (str == std::string("disabled")) {
- return false;
+ return false;
} else if (str == std::string("0")) {
- return false;
+ return false;
} else {
- throw ParsingException("\"" + str + "\" is not a valid boolean value",
- __FILE__, __LINE__);
+ throw ParsingException("\"" + str + "\" is not a valid boolean value",
+ __FILE__, __LINE__);
}
-
+
}
LogLevel suPHP::Configuration::strToLogLevel(const std::string& str) const
throw (ParsingException) {
if (str == "none")
- return LOGLEVEL_NONE;
+ return LOGLEVEL_NONE;
else if (str == "error")
- return LOGLEVEL_ERROR;
+ return LOGLEVEL_ERROR;
else if (str == "warn")
- return LOGLEVEL_WARN;
+ return LOGLEVEL_WARN;
else if (str == "info")
- return LOGLEVEL_INFO;
+ return LOGLEVEL_INFO;
else
- throw ParsingException("\"" + str + "\" is not a valid log level",
- __FILE__, __LINE__);
+ throw ParsingException("\"" + str + "\" is not a valid log level",
+ __FILE__, __LINE__);
}
suPHP::Configuration::Configuration() {
#else
this->webserver_user = "wwwrun";
#endif
- this->docroot = "/";
+ this->docroots.push_back("/");
this->allow_file_group_writeable = false;
this->allow_directory_group_writeable = false;
this->allow_file_others_writeable = false;
this->allow_directory_others_writeable = false;
#ifdef OPT_DISABLE_CHECKPATH
- this->check_vhos_docroot = false;
+ this->check_vhost_docroot = false;
#else
this->check_vhost_docroot = true;
#endif
this->min_gid = 1;
#endif
this->umask = 0077;
+ this->chroot_path = "";
}
void suPHP::Configuration::readFromFile(File& file)
IniFile ini;
ini.parse(file);
if (ini.hasSection("global")) {
- IniSection& sect = ini.getSection("global");
- std::vector<std::string> keys = sect.getKeys();
- std::vector<std::string>::iterator i;
- for (i = keys.begin(); i < keys.end(); i++) {
- std::string key = *i;
- std::string value = sect.getValue(key);
-
- if (key == "logfile")
- this->logfile = value;
- else if (key == "webserver_user")
- this->webserver_user = value;
- else if (key == "docroot")
- this->docroot = value;
- else if (key == "allow_file_group_writeable")
- this->allow_file_group_writeable = this->strToBool(value);
- else if (key == "allow_directory_group_writeable")
- this->allow_directory_group_writeable = this->strToBool(value);
- else if (key == "allow_file_others_writeable")
- this->allow_file_others_writeable = this->strToBool(value);
- else if (key == "allow_directory_others_writeable")
- this->allow_directory_others_writeable =
- this->strToBool(value);
- else if (key == "check_vhost_docroot")
- this->check_vhost_docroot = this->strToBool(value);
- else if (key == "errors_to_browser")
- this->errors_to_browser = this->strToBool(value);
- else if (key == "env_path")
- this->env_path = value;
- else if (key == "loglevel")
- this->loglevel = this->strToLogLevel(value);
- else if (key == "min_uid")
- this->min_uid = Util::strToInt(value);
- else if (key == "min_gid")
- this->min_gid = Util::strToInt(value);
- else if (key == "umask")
- this->umask = Util::octalStrToInt(value);
- else
- throw ParsingException("Unknown option \"" + key +
- "\" in section [global]",
- __FILE__, __LINE__);
- }
+ const IniSection& sect = ini.getSection("global");
+ const std::vector<std::string> keys = sect.getKeys();
+ std::vector<std::string>::const_iterator i;
+ for (i = keys.begin(); i < keys.end(); i++) {
+ std::string key = *i;
+ std::string value = sect.getValue(key);
+
+ if (key == "logfile")
+ this->logfile = value;
+ else if (key == "webserver_user")
+ this->webserver_user = value;
+ else if (key == "docroot") {
+ this->docroots = sect.getValues(key);
+ } else if (key == "allow_file_group_writeable")
+ this->allow_file_group_writeable = this->strToBool(value);
+ else if (key == "allow_directory_group_writeable")
+ this->allow_directory_group_writeable = this->strToBool(value);
+ else if (key == "allow_file_others_writeable")
+ this->allow_file_others_writeable = this->strToBool(value);
+ else if (key == "allow_directory_others_writeable")
+ this->allow_directory_others_writeable =
+ this->strToBool(value);
+ else if (key == "check_vhost_docroot")
+ this->check_vhost_docroot = this->strToBool(value);
+ else if (key == "errors_to_browser")
+ this->errors_to_browser = this->strToBool(value);
+ else if (key == "env_path")
+ this->env_path = value;
+ else if (key == "loglevel")
+ this->loglevel = this->strToLogLevel(value);
+ else if (key == "min_uid")
+ this->min_uid = Util::strToInt(value);
+ else if (key == "min_gid")
+ this->min_gid = Util::strToInt(value);
+ else if (key == "umask")
+ this->umask = Util::octalStrToInt(value);
+ else if (key == "chroot")
+ this->chroot_path = value;
+ else
+ throw ParsingException("Unknown option \"" + key +
+ "\" in section [global]",
+ __FILE__, __LINE__);
+ }
}
// Get handlers / interpreters
if (ini.hasSection("handlers")) {
- IniSection sect = ini.getSection("handlers");
- std::vector<std::string> keys = sect.getKeys();
- std::vector<std::string>::iterator i;
- for (i = keys.begin(); i < keys.end(); i++) {
- std::string key = *i;
- std::string value = sect.getValue(key);
- std::pair<std::string, std::string> p;
- p.first = key;
- p.second = value;
- this->handlers.insert(p);
- }
+ IniSection sect = ini.getSection("handlers");
+ const std::vector<std::string> keys = sect.getKeys();
+ std::vector<std::string>::const_iterator i;
+ for (i = keys.begin(); i < keys.end(); i++) {
+ std::string key = *i;
+ std::string value = sect.getValue(key);
+ std::pair<std::string, std::string> p;
+ p.first = key;
+ p.second = value;
+ this->handlers.insert(p);
+ }
}
}
return this->webserver_user;
}
-std::string suPHP::Configuration::getDocroot() const {
- return this->docroot;
+const std::vector<std::string>& suPHP::Configuration::getDocroots() const {
+ return this->docroots;
}
bool suPHP::Configuration::getCheckVHostDocroot() const {
std::string suPHP::Configuration::getInterpreter(std::string handler) const
throw (KeyNotFoundException) {
if (this->handlers.find(handler) != this->handlers.end()) {
- return this->handlers.find(handler) -> second;
+ return this->handlers.find(handler) -> second;
} else {
- throw KeyNotFoundException("Handler \"" + handler + "\" not found",
- __FILE__, __LINE__);
+ throw KeyNotFoundException("Handler \"" + handler + "\" not found",
+ __FILE__, __LINE__);
}
}
int suPHP::Configuration::getUmask() const {
return this->umask;
}
+
+std::string suPHP::Configuration::getChrootPath() const {
+ return this->chroot_path;
+}