summaryrefslogtreecommitdiffstats
path: root/src/Common/UserManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/UserManager.cpp')
-rw-r--r--src/Common/UserManager.cpp76
1 files changed, 76 insertions, 0 deletions
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 <Core/ConfigEntry.h>
+#include <Core/ConfigManager.h>
+
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<UserDBBackend> backend) {
boost::lock_guard<boost::shared_mutex> 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<boost::shared_ptr<UserConfigBackend> >::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<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) {