return values[0];
}
+uid_t toUID(const std::vector<std::string>& values)
+{
+ if (values.empty())
+ return -1;
+ uid_t res = str2uid(values[0]);
+ if (res == static_cast<uid_t>(-1))
+ throw ParserError(0, "Invalid user name: '" + values[0] + "'");
+ return res;
+}
+
+gid_t toGID(const std::vector<std::string>& values)
+{
+ if (values.empty())
+ return -1;
+ gid_t res = str2gid(values[0]);
+ if (res == static_cast<gid_t>(-1))
+ throw ParserError(0, "Invalid group name: '" + values[0] + "'");
+ return res;
+}
+
+mode_t toMode(const std::vector<std::string>& values)
+{
+ if (values.empty())
+ return -1;
+ mode_t res = str2mode(values[0]);
+ if (res == static_cast<mode_t>(-1))
+ throw ParserError(0, "Invalid mode: '" + values[0] + "'");
+ return res;
+}
+
template <typename T>
T toInt(const std::vector<std::string>& values)
{
return 0;
}
-Config::Pairs parseVector(const std::string& paramName, const MODULE_SETTINGS& params)
+Config::Pairs parseVector(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
{
- for (size_t i = 0; i < params.moduleParams.size(); ++i)
- if (params.moduleParams[i].param == paramName)
- return toPairs(params.moduleParams[i].value);
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return toPairs(params[i].value);
return Config::Pairs();
}
-bool parseBool(const std::string& paramName, const MODULE_SETTINGS& params)
+bool parseBool(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
{
- for (size_t i = 0; i < params.moduleParams.size(); ++i)
- if (params.moduleParams[i].param == paramName)
- return toBool(params.moduleParams[i].value);
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return toBool(params[i].value);
return false;
}
-std::string parseString(const std::string& paramName, const MODULE_SETTINGS& params)
+std::string parseString(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
{
- for (size_t i = 0; i < params.moduleParams.size(); ++i)
- if (params.moduleParams[i].param == paramName)
- return toString(params.moduleParams[i].value);
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return toString(params[i].value);
return "";
}
-template <typename T>
-T parseInt(const std::string& paramName, const MODULE_SETTINGS& params)
-{
- for (size_t i = 0; i < params.moduleParams.size(); ++i)
- if (params.moduleParams[i].param == paramName)
- return toInt<T>(params.moduleParams[i].value);
- return 0;
-}
-
std::string parseAddress(const std::string& address)
{
size_t pos = address.find_first_of(':');
throw ParserError(0, "Invalid connection type. Should be either 'unix' or 'tcp', got '" + type + "'");
}
+Config::Section parseSection(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
+{
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return Config::Section(parseVector("match", params[i].sections),
+ parseVector("modify", params[i].sections),
+ parseVector("reply", params[i].sections));
+ return Config::Section();
+}
+
+uid_t parseUID(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
+{
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return toUID(params[i].value);
+ return -1;
+}
+
+gid_t parseGID(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
+{
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return toGID(params[i].value);
+ return -1;
+}
+
+mode_t parseMode(const std::string& paramName, const std::vector<PARAM_VALUE>& params)
+{
+ for (size_t i = 0; i < params.size(); ++i)
+ if (params[i].param == paramName)
+ return toMode(params[i].value);
+ return -1;
+}
+
} // namespace anonymous
Config::Config(const MODULE_SETTINGS& settings)
- : match(parseVector("match", settings)),
- modify(parseVector("modify", settings)),
- reply(parseVector("reply", settings)),
- verbose(parseBool("verbose", settings)),
- address(parseString("bind_address", settings)),
+ : autz(parseSection("autz", settings.moduleParams)),
+ auth(parseSection("auth", settings.moduleParams)),
+ postauth(parseSection("postauth", settings.moduleParams)),
+ preacct(parseSection("preacct", settings.moduleParams)),
+ acct(parseSection("acct", settings.moduleParams)),
+ verbose(parseBool("verbose", settings.moduleParams)),
+ address(parseString("bind_address", settings.moduleParams)),
bindAddress(parseAddress(address)),
connectionType(parseConnectionType(address)),
- portStr(parseString("port", settings)),
- port(parseInt<uint16_t>("port", settings)),
- key(parseString("key", settings))
+ key(parseString("key", settings.moduleParams)),
+ sockUID(parseUID("sock_owner", settings.moduleParams)),
+ sockGID(parseGID("sock_group", settings.moduleParams)),
+ sockMode(parseMode("sock_mode", settings.moduleParams))
{
}