Added concurrency protection within the SASL auxprop plugin code. Review: https://reviews.apache.org/r/31960
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/17a06589 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/17a06589 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/17a06589 Branch: refs/heads/master Commit: 17a06589e6e64d0fee38b7e45fa338af7547a8e5 Parents: 43abc21 Author: Till Toenshoff <[email protected]> Authored: Fri Mar 27 15:24:50 2015 -0700 Committer: Adam B <[email protected]> Committed: Fri Mar 27 15:24:50 2015 -0700 ---------------------------------------------------------------------- src/authentication/cram_md5/auxprop.cpp | 2 ++ src/authentication/cram_md5/auxprop.hpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/17a06589/src/authentication/cram_md5/auxprop.cpp ---------------------------------------------------------------------- diff --git a/src/authentication/cram_md5/auxprop.cpp b/src/authentication/cram_md5/auxprop.cpp index cf503a2..4cabaa3 100644 --- a/src/authentication/cram_md5/auxprop.cpp +++ b/src/authentication/cram_md5/auxprop.cpp @@ -30,6 +30,8 @@ namespace cram_md5 { // Storage for the static members. Multimap<string, Property> InMemoryAuxiliaryPropertyPlugin::properties; sasl_auxprop_plug_t InMemoryAuxiliaryPropertyPlugin::plugin; +pthread_mutex_t InMemoryAuxiliaryPropertyPlugin::mutex = + PTHREAD_MUTEX_INITIALIZER; int InMemoryAuxiliaryPropertyPlugin::initialize( http://git-wip-us.apache.org/repos/asf/mesos/blob/17a06589/src/authentication/cram_md5/auxprop.hpp ---------------------------------------------------------------------- diff --git a/src/authentication/cram_md5/auxprop.hpp b/src/authentication/cram_md5/auxprop.hpp index b894386..6aa3ce6 100644 --- a/src/authentication/cram_md5/auxprop.hpp +++ b/src/authentication/cram_md5/auxprop.hpp @@ -19,6 +19,8 @@ #ifndef __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__ #define __AUTHENTICATION_CRAM_MD5_AUXPROP_HPP__ +#include <pthread.h> + #include <string> #include <sasl/sasl.h> @@ -29,6 +31,8 @@ #include <stout/none.hpp> #include <stout/option.hpp> +#include "common/lock.hpp" + namespace mesos { namespace internal { namespace cram_md5 { @@ -47,6 +51,7 @@ public: static void load(const Multimap<std::string, Property>& _properties) { + Lock lock(&mutex); properties = _properties; } @@ -54,6 +59,7 @@ public: const std::string& user, const std::string& name) { + Lock lock(&mutex); if (properties.contains(user)) { foreach (const Property& property, properties.get(user)) { if (property.name == name) { @@ -84,9 +90,15 @@ private: const char* user, unsigned length); + // TODO(tillt): For allowing multiple authenticators with differing + // credentials, consider using a non-static credential properties. static Multimap<std::string, Property> properties; static sasl_auxprop_plug_t plugin; + + // Access to 'properties' has to be protected as multiple + // authenticator instances may be active concurrently. + static pthread_mutex_t mutex; }; } // namespace cram_md5 {
