From fca6c1a831393e173706a5b5c798c35dc5f7d3e6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 3 Sep 2009 20:16:23 +0200 Subject: Thread-Sicherheit verbessert --- src/modules/AuthProviderFile/AuthProviderFile.cpp | 8 +++++++- src/modules/AuthProviderFile/AuthProviderFile.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/modules/AuthProviderFile') diff --git a/src/modules/AuthProviderFile/AuthProviderFile.cpp b/src/modules/AuthProviderFile/AuthProviderFile.cpp index 99af6b6..1756747 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.cpp +++ b/src/modules/AuthProviderFile/AuthProviderFile.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace Mad { namespace Modules { @@ -56,6 +57,7 @@ void AuthProviderFile::readFile(const std::string &name) { std::string password = match[2].str(); if(filehash.empty()) { + boost::lock_guard lock(mutex); userMap.insert(std::make_pair(match[1].str(), std::vector(password.begin(), password.end()))); } else { @@ -75,8 +77,10 @@ void AuthProviderFile::readFile(const std::string &name) { data.push_back(byte); } - if(!data.empty()) + if(!data.empty()) { + boost::lock_guard lock(mutex); userMap.insert(std::make_pair(match[1].str(), data)); + } } } } @@ -137,6 +141,8 @@ bool AuthProviderFile::checkPassword(const std::string &user, const std::vector< } std::vector AuthProviderFile::getPassword(const std::string &user, const std::string &hash) throw(Core::Exception) { + boost::lock_guard lock(mutex); + std::map >::iterator userIt = userMap.find(user); if(userIt == userMap.end()) return std::vector(); diff --git a/src/modules/AuthProviderFile/AuthProviderFile.h b/src/modules/AuthProviderFile/AuthProviderFile.h index 99deaa0..63f3d28 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.h +++ b/src/modules/AuthProviderFile/AuthProviderFile.h @@ -28,6 +28,8 @@ #include #include +#include + namespace Mad { namespace Modules { namespace AuthProviderFile { @@ -38,6 +40,8 @@ class MAD_MODULE_EXPORT AuthProviderFile : public Common::AuthProvider, private Common::Application *application; + boost::mutex mutex; + std::map > userMap; std::vector files; -- cgit v1.2.3