summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-06 21:28:41 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-06 21:28:41 +0200
commit0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f (patch)
treebd12565104b27cb6f28b8c0b2544dd65baf94b5b /src/Common
parentf7d433e6e8559b4584263cae025d3addd1342df4 (diff)
downloadmad-0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f.tar
mad-0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f.zip
Revised server config format
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/UserManager.cpp76
-rw-r--r--src/Common/UserManager.h11
2 files changed, 85 insertions, 2 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) {
diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h
index 5eece35..c70894a 100644
--- a/src/Common/UserManager.h
+++ b/src/Common/UserManager.h
@@ -23,6 +23,7 @@
#include "UserInfo.h"
#include "GroupInfo.h"
+#include <Core/Configurable.h>
#include <Core/Exception.h>
#include <map>
@@ -39,7 +40,7 @@ class UserConfigBackend;
class UserDBBackend;
class UserCache;
-class UserManager : private boost::noncopyable {
+class UserManager : public Core::Configurable, private boost::noncopyable {
private:
friend class Application;
@@ -54,9 +55,15 @@ class UserManager : private boost::noncopyable {
boost::shared_ptr<UserDBBackend> dbBackend;
+ unsigned long minUid, maxUid, minGid, maxGid;
+
boost::shared_mutex mutex;
- UserManager(Application *application0) : application(application0) {}
+ UserManager(Application *application0);
+ ~UserManager();
+
+ protected:
+ virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/);
public:
void registerBackend(boost::shared_ptr<UserDBBackend> backend);