From 0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 6 Aug 2009 21:28:41 +0200 Subject: Revised server config format --- src/Common/UserManager.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/Common/UserManager.cpp') diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index 7f50f28..bb4d205 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -22,9 +22,79 @@ #include "UserCache.h" #include "UserConfigBackend.h" +#include +#include + namespace Mad { namespace Common { +UserManager::UserManager(Application *application0) : application(application0), minUid(1000), maxUid(29999), minGid(1000), maxGid(29999) { + application->getConfigManager()->registerConfigurable(this); +} + +UserManager::~UserManager() { + application->getConfigManager()->unregisterConfigurable(this); +} + +bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/) { + if(entry[0].getKey().matches("UserManager")) { + if(entry[1].getKey().matches("MinUid")) { + if(entry[2].empty()) { + char *endptr; + unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); + if(entry[1][0].empty() || *endptr) { + application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].c_str()); + } + else { + minUid = val; + } + } + } + else if(entry[1].getKey().matches("MaxUid")) { + if(entry[2].empty()) { + char *endptr; + unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); + if(entry[1][0].empty() || *endptr) { + application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].c_str()); + } + else { + maxUid = val; + } + } + } + else if(entry[1].getKey().matches("MinGid")) { + if(entry[2].empty()) { + char *endptr; + unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); + if(entry[1][0].empty() || *endptr) { + application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].c_str()); + } + else { + minGid = val; + } + } + } + else if(entry[1].getKey().matches("MaxGid")) { + if(entry[2].empty()) { + char *endptr; + unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); + if(entry[1][0].empty() || *endptr) { + application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].c_str()); + } + else { + maxGid = val; + } + } + } + else if(!entry[1].empty()) + return false; + + return true; + } + + return false; +} + void UserManager::registerBackend(boost::shared_ptr backend) { boost::lock_guard lock(mutex); @@ -143,6 +213,9 @@ void UserManager::checkUserInfo(const UserInfo &userInfo) throw(Core::Exception) if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + if(userInfo.getUid() < minUid || userInfo.getUid() > maxUid) + throw Core::Exception(Core::Exception::INVALID_INPUT); + dbBackend->checkUserInfo(userInfo); for(std::set >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { @@ -223,6 +296,9 @@ void UserManager::checkGroupInfo(const GroupInfo &groupInfo) throw(Core::Excepti if(!dbBackend) throw Core::Exception(Core::Exception::NOT_AVAILABLE); + if(groupInfo.getGid() < minGid || groupInfo.getGid() > maxGid) + throw Core::Exception(Core::Exception::INVALID_INPUT); + dbBackend->checkGroupInfo(groupInfo); for(std::set >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { -- cgit v1.2.3