From c655495025d970df5945413fd877691618b2e7c2 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 13 Feb 2014 21:08:37 +0100 Subject: [PATCH] Fixed problem when custom registered mechanism is used. User-defined mechanisms should be tested first. Added function to determine whether a mechanism is built-in. --- .../security/sasl/SASLMechanismFactory.cpp | 27 ++++++++++--------- .../security/sasl/SASLMechanismFactory.hpp | 9 +++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/vmime/security/sasl/SASLMechanismFactory.cpp b/src/vmime/security/sasl/SASLMechanismFactory.cpp index 255a13f1..7ccdce8d 100644 --- a/src/vmime/security/sasl/SASLMechanismFactory.cpp +++ b/src/vmime/security/sasl/SASLMechanismFactory.cpp @@ -73,19 +73,15 @@ shared_ptr SASLMechanismFactory::create { const string name(utility::stringUtils::toUpper(name_)); - // Check for built-in mechanisms - if (isMechanismSupported(name)) - { - return make_shared (ctx, name); - } // Check for registered mechanisms - else - { - MapType::iterator it = m_mechs.find(name); + MapType::iterator it = m_mechs.find(name); - if (it != m_mechs.end()) - return (*it).second->create(ctx, name); - } + if (it != m_mechs.end()) + return (*it).second->create(ctx, name); + + // Check for built-in mechanisms + if (isBuiltinMechanism(name)) + return make_shared (ctx, name); throw exceptions::no_such_mechanism(name); return null; @@ -130,8 +126,13 @@ const std::vector SASLMechanismFactory::getSupportedMechanisms() const bool SASLMechanismFactory::isMechanismSupported(const string& name) const { - return (gsasl_client_support_p(m_gsaslContext, name.c_str()) != 0 || - m_mechs.find(name) != m_mechs.end()); + return isBuiltinMechanism(name) || m_mechs.find(name) != m_mechs.end(); +} + + +bool SASLMechanismFactory::isBuiltinMechanism(const string& name) const +{ + return gsasl_client_support_p(m_gsaslContext, name.c_str()) != 0; } diff --git a/src/vmime/security/sasl/SASLMechanismFactory.hpp b/src/vmime/security/sasl/SASLMechanismFactory.hpp index 3503f71b..6d328f01 100644 --- a/src/vmime/security/sasl/SASLMechanismFactory.hpp +++ b/src/vmime/security/sasl/SASLMechanismFactory.hpp @@ -121,6 +121,15 @@ public: */ bool isMechanismSupported(const string& name) const; + /** Test whether an authentication mechanism is directly supported + * by the underlying SASL library. + * + * @param name mechanism name + * @return true if the specified mechanism is built-in, + * or false otherwise + */ + bool isBuiltinMechanism(const string& name) const; + private: #ifdef GSASL_VERSION