From: Amos Jeffries Date: Mon, 28 Mar 2011 10:51:53 +0000 (-0600) Subject: SourceLayout: (Bug 3170) namespace for Auth::Scheme and children X-Git-Tag: take06~27^2~60 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6374be660ad9fdafe06d42d460e6b7c91d58025;p=thirdparty%2Fsquid.git SourceLayout: (Bug 3170) namespace for Auth::Scheme and children Also, * fix digest shutdown process so AuthDigestConfig does the config cleanup and Auth::Digest::Scheme does the scheme termination * fix all schemes shutdown to silence scheme messages (partial bug 3170) --- diff --git a/src/AuthReg.cc b/src/AuthReg.cc index 19c95937e3..d47b34cb70 100644 --- a/src/AuthReg.cc +++ b/src/AuthReg.cc @@ -27,19 +27,19 @@ InitAuthSchemes() { debugs(29,1,"Initializing Authentication Schemes ..."); #if HAVE_AUTH_MODULE_BASIC - static const char *basic_type = basicScheme::GetInstance()->type(); + static const char *basic_type = Auth::Basic::Scheme::GetInstance()->type(); debugs(29,1,"Initialized Authentication Scheme '" << basic_type << "'"); #endif #if HAVE_AUTH_MODULE_DIGEST - static const char *digest_type = digestScheme::GetInstance()->type(); + static const char *digest_type = Auth::Digest::Scheme::GetInstance()->type(); debugs(29,1,"Initialized Authentication Scheme '" << digest_type << "'"); #endif #if HAVE_AUTH_MODULE_NEGOTIATE - static const char *negotiate_type = negotiateScheme::GetInstance()->type(); + static const char *negotiate_type = Auth::Negotiate::Scheme::GetInstance()->type(); debugs(29,1,"Initialized Authentication Scheme '" << negotiate_type << "'"); #endif #if HAVE_AUTH_MODULE_NTLM - static const char *ntlm_type = ntlmScheme::GetInstance()->type(); + static const char *ntlm_type = Auth::Ntlm::Scheme::GetInstance()->type(); debugs(29,1,"Initialized Authentication Scheme '" << ntlm_type << "'"); #endif debugs(29,1,"Initializing Authentication Schemes Complete."); diff --git a/src/auth/Scheme.cc b/src/auth/Scheme.cc index 5a86b2edb3..0ec60226f7 100644 --- a/src/auth/Scheme.cc +++ b/src/auth/Scheme.cc @@ -57,7 +57,7 @@ AuthScheme::Pointer AuthScheme::Find(const char *typestr) { for (iterator i = GetSchemes().begin(); i != GetSchemes().end(); ++i) { - if (strcmp ((*i)->type(), typestr) == 0) + if (strcmp((*i)->type(), typestr) == 0) return *i; } diff --git a/src/auth/Scheme.h b/src/auth/Scheme.h index 46fee0f510..60940fa819 100644 --- a/src/auth/Scheme.h +++ b/src/auth/Scheme.h @@ -85,7 +85,7 @@ public: static AuthScheme::Pointer Find(const char *); /* per scheme methods */ - virtual char const *type () const = 0; + virtual char const *type() const = 0; virtual void done() = 0; virtual AuthConfig *createConfig() = 0; diff --git a/src/auth/basic/Scheme.cc b/src/auth/basic/Scheme.cc index ba93a05f81..e861912d15 100644 --- a/src/auth/basic/Scheme.cc +++ b/src/auth/basic/Scheme.cc @@ -37,35 +37,36 @@ /* for AuthConfig */ #include "auth/basic/auth_basic.h" -AuthScheme::Pointer basicScheme::_instance = NULL; +AuthScheme::Pointer Auth::Basic::Scheme::_instance = NULL; AuthScheme::Pointer -basicScheme::GetInstance() +Auth::Basic::Scheme::GetInstance() { if (_instance == NULL) { - _instance = new basicScheme(); + _instance = new Auth::Basic::Scheme(); AddScheme(_instance); } return _instance; } char const * -basicScheme::type () const +basicScheme::type() const { return "basic"; } void -basicScheme::done() +Auth::Basic::Scheme::done() { - /* clear the global handle to this scheme. */ - _instance = NULL; + if (_instance == NULL) + return; - debugs(29, DBG_CRITICAL, HERE << "Basic authentication Schema Detached."); + _instance = NULL; + debugs(29, DBG_CRITICAL, "Shutdown: Basic authentication."); } AuthConfig * -basicScheme::createConfig() +Auth::Basic::Scheme::createConfig() { AuthBasicConfig *newCfg = new AuthBasicConfig; return dynamic_cast(newCfg); diff --git a/src/auth/basic/Scheme.h b/src/auth/basic/Scheme.h index 587e49c594..c0d1871183 100644 --- a/src/auth/basic/Scheme.h +++ b/src/auth/basic/Scheme.h @@ -30,32 +30,38 @@ * */ -#ifndef SQUID_BASICSCHEME_H -#define SQUID_BASICSCHEME_H +#ifndef SQUID_AUTH_BASIC_SCHEME_H +#define SQUID_AUTH_BASIC_SCHEME_H #include "auth/Scheme.h" #include "auth/basic/auth_basic.h" +namespace Auth { +namespace Basic { + /// \ingroup AuthAPI /// \ingroup AuthSchemeAPI -class basicScheme : public AuthScheme +class Scheme : public AuthScheme { public: static AuthScheme::Pointer GetInstance(); - basicScheme() {}; - virtual ~basicScheme() {} + Scheme() {}; + virtual ~Scheme() {} /* per scheme */ - virtual char const *type () const; + virtual char const *type() const; virtual void done(); virtual AuthConfig *createConfig(); /* Not implemented */ - basicScheme (basicScheme const &); - basicScheme &operator=(basicScheme const &); + Scheme(Scheme const &); + Scheme &operator=(Scheme const &); private: static AuthScheme::Pointer _instance; }; -#endif /* SQUID_BASICSCHEME_H */ +} // namespace Basic +} // namespace Auth + +#endif /* SQUID_AUTH_BASIC_SCHEME_H */ diff --git a/src/auth/basic/auth_basic.cc b/src/auth/basic/auth_basic.cc index 299a22b8ad..8503eadd8a 100644 --- a/src/auth/basic/auth_basic.cc +++ b/src/auth/basic/auth_basic.cc @@ -91,7 +91,7 @@ AuthBasicConfig::configured() const const char * AuthBasicConfig::type() const { - return basicScheme::GetInstance()->type(); + return Auth::Basic::Scheme::GetInstance()->type(); } int32_t diff --git a/src/auth/digest/Scheme.cc b/src/auth/digest/Scheme.cc index 129335d55e..51ef0ca83d 100644 --- a/src/auth/digest/Scheme.cc +++ b/src/auth/digest/Scheme.cc @@ -34,40 +34,54 @@ #include "auth/digest/Scheme.h" #include "helper.h" +AuthScheme::Pointer Auth::Digest::Scheme::_instance = NULL; + AuthScheme::Pointer -digestScheme::GetInstance() +Auth::Digest::Scheme::GetInstance() { if (_instance == NULL) { - _instance = new digestScheme(); + _instance = new Auth::Digest::Scheme(); AddScheme(_instance); } return _instance; } char const * -digestScheme::type () const +Auth::Digest::Scheme::type() const { return "digest"; } -AuthScheme::Pointer digestScheme::_instance = NULL; +void +Auth::Digest::Scheme::done() +{ + if (_instance == NULL) + return; + + PurgeCredentialsCache(); + authenticateDigestNonceShutdown(); + + _instance = NULL; + debugs(29, DBG_CRITICAL, "Shutdown: Digest authentication."); +} AuthConfig * -digestScheme::createConfig() +Auth::Digest::Scheme::createConfig() { AuthDigestConfig *digestCfg = new AuthDigestConfig; return dynamic_cast(digestCfg); } void -digestScheme::PurgeCredentialsCache(void) +Auth::Digest::Scheme::PurgeCredentialsCache(void) { AuthUserHashPointer *usernamehash; - AuthUser::Pointer auth_user; + + debugs(29, 2, HERE << "Erasing Digest authentication credentials from username cache."); hash_first(proxy_auth_username_cache); while ((usernamehash = static_cast(hash_next(proxy_auth_username_cache)) )) { - auth_user = usernamehash->user(); + AuthUser::Pointer auth_user = usernamehash->user(); if (strcmp(auth_user->config->type(), "digest") == 0) { hash_remove_link(proxy_auth_username_cache, static_cast(usernamehash)); diff --git a/src/auth/digest/Scheme.h b/src/auth/digest/Scheme.h index 1d7652574b..f6e4f22004 100644 --- a/src/auth/digest/Scheme.h +++ b/src/auth/digest/Scheme.h @@ -30,21 +30,24 @@ * */ -#ifndef SQUID_DIGESTSCHEME_H -#define SQUID_DIGESTSCHEME_H +#ifndef SQUID_AUTH_DIGEST_SCHEME_H +#define SQUID_AUTH_DIGEST_SCHEME_H #include "auth/Scheme.h" #include "auth/digest/auth_digest.h" +namespace Auth { +namespace Digest { + /// \ingroup AuthSchemeAPI /// \ingroup AuthAPI -class digestScheme : public AuthScheme +class Scheme : public AuthScheme { public: static AuthScheme::Pointer GetInstance(); - digestScheme() {}; - virtual ~digestScheme() {} + Scheme() {}; + virtual ~Scheme() {} /* per scheme */ virtual char const *type () const; @@ -52,8 +55,8 @@ public: virtual AuthConfig *createConfig(); /* Not implemented */ - digestScheme (digestScheme const &); - digestScheme &operator=(digestScheme const &); + Scheme(Scheme const &); + Scheme &operator=(Scheme const &); private: static AuthScheme::Pointer _instance; @@ -66,4 +69,7 @@ private: static void PurgeCredentialsCache(void); }; -#endif /* SQUID_DIGESTSCHEME_H */ +} // namespace Digest +} // namespace Auth + +#endif /* SQUID_AUTH_DIGEST_SCHEME_H */ diff --git a/src/auth/digest/auth_digest.cc b/src/auth/digest/auth_digest.cc index 05417f3b7b..e1571ca116 100644 --- a/src/auth/digest/auth_digest.cc +++ b/src/auth/digest/auth_digest.cc @@ -103,8 +103,6 @@ static digest_nonce_h *authenticateDigestNonceFindNonce(const char *nonceb64); static digest_nonce_h *authenticateDigestNonceNew(void); static void authenticateDigestNonceDelete(digest_nonce_h * nonce); static void authenticateDigestNonceSetup(void); -static void authenticateDigestNonceShutdown(void); -static void authenticateDigestNonceReconfigure(void); static int authDigestNonceIsStale(digest_nonce_h * nonce); static void authDigestNonceEncode(digest_nonce_h * nonce); static void authDigestNonceLink(digest_nonce_h * nonce); @@ -231,7 +229,7 @@ authenticateDigestNonceSetup(void) } } -static void +void authenticateDigestNonceShutdown(void) { /* @@ -259,10 +257,6 @@ authenticateDigestNonceShutdown(void) debugs(29, 2, "authenticateDigestNonceShutdown: Nonce cache shutdown"); } -static void -authenticateDigestNonceReconfigure(void) -{} - static void authenticateDigestNonceCacheCleanup(void *data) { @@ -509,38 +503,6 @@ AuthDigestConfig::rotateHelpers() /* NP: dynamic helper restart will ensure they start up again as needed. */ } -/** delete the digest request structure. Does NOT delete related structures */ -void -digestScheme::done() -{ - /** \todo this should be a Config call. */ - - if (digestauthenticators) - helperShutdown(digestauthenticators); - - if (DigestFieldsInfo) { - httpHeaderDestroyFieldsInfo(DigestFieldsInfo, DIGEST_ENUM_END); - DigestFieldsInfo = NULL; - } - - authdigest_initialised = 0; - - if (!shutting_down) { - authenticateDigestNonceReconfigure(); - return; - } - - delete digestauthenticators; - digestauthenticators = NULL; - - PurgeCredentialsCache(); - authenticateDigestNonceShutdown(); - debugs(29, 2, "authenticateDigestDone: Digest authentication shut down."); - - /* clear the global handle to this scheme. */ - _instance = NULL; -} - void AuthDigestConfig::dump(StoreEntry * entry, const char *name, AuthConfig * scheme) { @@ -682,6 +644,22 @@ AuthDigestConfig::registerWithCacheManager(void) void AuthDigestConfig::done() { + authdigest_initialised = 0; + + if (digestauthenticators) + helperShutdown(digestauthenticators); + + if (DigestFieldsInfo) { + httpHeaderDestroyFieldsInfo(DigestFieldsInfo, DIGEST_ENUM_END); + DigestFieldsInfo = NULL; + } + + if (!shutting_down) + return; + + delete digestauthenticators; + digestauthenticators = NULL; + if (authenticateProgram) wordlistDestroy(&authenticateProgram); @@ -739,7 +717,7 @@ AuthDigestConfig::parse(AuthConfig * scheme, int n_configured, char *param_str) const char * AuthDigestConfig::type() const { - return digestScheme::GetInstance()->type(); + return Auth::Digest::Scheme::GetInstance()->type(); } diff --git a/src/auth/digest/auth_digest.h b/src/auth/digest/auth_digest.h index d1fc220f59..5545345db0 100644 --- a/src/auth/digest/auth_digest.h +++ b/src/auth/digest/auth_digest.h @@ -74,6 +74,7 @@ extern void authDigestNonceUnlink(digest_nonce_h * nonce); extern int authDigestNonceIsValid(digest_nonce_h * nonce, char nc[9]); extern const char *authenticateDigestNonceNonceb64(const digest_nonce_h * nonce); extern int authDigestNonceLastRequest(digest_nonce_h * nonce); +extern void authenticateDigestNonceShutdown(void); /* configuration runtime data */ diff --git a/src/auth/negotiate/Scheme.cc b/src/auth/negotiate/Scheme.cc index 95c02bca78..70a911d204 100644 --- a/src/auth/negotiate/Scheme.cc +++ b/src/auth/negotiate/Scheme.cc @@ -34,39 +34,36 @@ #include "auth/negotiate/Scheme.h" #include "helper.h" +AuthScheme::Pointer Auth::Negotiate::Scheme::_instance = NULL; + AuthScheme::Pointer -negotiateScheme::GetInstance() +Auth::Negotiate::Scheme::GetInstance() { if (_instance == NULL) { - _instance = new negotiateScheme(); + _instance = new Auth::Negotiate::Scheme(); AddScheme(_instance); } return _instance; } char const * -negotiateScheme::type () const +Auth::Negotiate::Scheme::type() const { return "negotiate"; } -AuthScheme::Pointer negotiateScheme::_instance = NULL; - -/** - \ingroup AuthNegotiateInternal - \todo move to negotiateScheme.cc - */ void -negotiateScheme::done() +Auth::Negotiate::Scheme::done() { - /* clear the global handle to this scheme. */ - _instance = NULL; + if (_instance == NULL) + return; - debugs(29, 2, "negotiateScheme::done: Negotiate authentication Shutdown."); + _instance = NULL; + debugs(29, DBG_CRITICAL, "Shutdown: Negotiate authentication."); } AuthConfig * -negotiateScheme::createConfig() +Auth::Negotiate::Scheme::createConfig() { AuthNegotiateConfig *negotiateCfg = new AuthNegotiateConfig; return dynamic_cast(negotiateCfg); diff --git a/src/auth/negotiate/Scheme.h b/src/auth/negotiate/Scheme.h index 89ad24495b..6ab2255566 100644 --- a/src/auth/negotiate/Scheme.h +++ b/src/auth/negotiate/Scheme.h @@ -30,33 +30,39 @@ * */ -#ifndef SQUID_NEGOTIATESCHEME_H -#define SQUID_NEGOTIATESCHEME_H +#ifndef SQUID_AUTH_NEGOTIATE_SCHEME_H +#define SQUID_AUTH_NEGOTIATE_SCHEME_H #include "auth/Scheme.h" #include "auth/negotiate/auth_negotiate.h" +namespace Auth { +namespace Negotiate { + /// \ingroup AuthSchemeAPI /// \ingroup AuthAPI -class negotiateScheme : public AuthScheme +class Scheme : public AuthScheme { public: static AuthScheme::Pointer GetInstance(); - negotiateScheme() {}; - virtual ~negotiateScheme() {}; + Scheme() {}; + virtual ~Scheme() {}; /* per scheme */ - virtual char const *type () const; + virtual char const *type() const; virtual void done(); virtual AuthConfig *createConfig(); /* Not implemented */ - negotiateScheme (negotiateScheme const &); - negotiateScheme &operator=(negotiateScheme const &); + Scheme (Scheme const &); + Scheme &operator=(Scheme const &); private: static AuthScheme::Pointer _instance; }; -#endif /* SQUID_negotiateSCHEME_H */ +} // namespace Negotiate +} // namespace Auth + +#endif /* SQUID_AUTH_NEGOTIATE_SCHEME_H */ diff --git a/src/auth/negotiate/auth_negotiate.cc b/src/auth/negotiate/auth_negotiate.cc index faf9401e37..f082e8158a 100644 --- a/src/auth/negotiate/auth_negotiate.cc +++ b/src/auth/negotiate/auth_negotiate.cc @@ -151,7 +151,7 @@ AuthNegotiateConfig::parse(AuthConfig * scheme, int n_configured, char *param_st const char * AuthNegotiateConfig::type() const { - return negotiateScheme::GetInstance()->type(); + return Auth::Negotiate::Scheme::GetInstance()->type(); } /** diff --git a/src/auth/ntlm/Scheme.cc b/src/auth/ntlm/Scheme.cc index bf727d8797..9ef0fc1d2b 100644 --- a/src/auth/ntlm/Scheme.cc +++ b/src/auth/ntlm/Scheme.cc @@ -35,35 +35,36 @@ #include "auth/ntlm/Scheme.h" #include "helper.h" +AuthScheme::Pointer Auth::Ntlm::Scheme::_instance = NULL; + AuthScheme::Pointer -ntlmScheme::GetInstance() +Auth::Ntlm::Scheme::GetInstance() { if (_instance == NULL) { - _instance = new ntlmScheme(); + _instance = new Auth::Ntlm::Scheme(); AddScheme(_instance); } return _instance; } char const * -ntlmScheme::type () const +Auth::Ntlm::Scheme::type() const { return "ntlm"; } -AuthScheme::Pointer ntlmScheme::_instance = NULL; - void -ntlmScheme::done() +Auth::Ntlm::Scheme::done() { - /* clear the global handle to this scheme. */ - _instance = NULL; + if (_instance == NULL) + return; - debugs(29, 2, "ntlmScheme::done: NTLM authentication Shutdown."); + _instance = NULL; + debugs(29, DBG_CRITICAL, "Shutdown: NTLM authentication."); } AuthConfig * -ntlmScheme::createConfig() +Auth::Ntlm::Scheme::createConfig() { auth_ntlm_config *ntlmCfg = new auth_ntlm_config; return dynamic_cast(ntlmCfg); diff --git a/src/auth/ntlm/Scheme.h b/src/auth/ntlm/Scheme.h index e48bf82d4c..ee7c1c43d5 100644 --- a/src/auth/ntlm/Scheme.h +++ b/src/auth/ntlm/Scheme.h @@ -1,4 +1,3 @@ - /* * $Id$ * @@ -31,30 +30,33 @@ * */ -#ifndef SQUID_NTLMSCHEME_H -#define SQUID_NTLMSCHEME_H +#ifndef SQUID_AUTH_NTLM_SCHEME_H +#define SQUID_AUTH_NTLM_SCHEME_H #include "auth/Scheme.h" #include "auth/ntlm/auth_ntlm.h" +namespace Auth { +namespace Ntlm { + /// \ingroup AuthSchemeAPI /// \ingroup AuthAPI -class ntlmScheme : public AuthScheme +class Scheme : public AuthScheme { public: static AuthScheme::Pointer GetInstance(); - ntlmScheme() {}; - virtual ~ntlmScheme() {}; + Scheme() {}; + virtual ~Scheme() {}; /* per scheme */ - virtual char const *type () const; + virtual char const *type() const; virtual void done(); virtual AuthConfig *createConfig(); /* Not implemented */ - ntlmScheme (ntlmScheme const &); - ntlmScheme &operator=(ntlmScheme const &); + Scheme (Scheme const &); + Scheme &operator=(Scheme const &); private: /** @@ -64,4 +66,7 @@ private: static AuthScheme::Pointer _instance; }; -#endif /* SQUID_ntlmSCHEME_H */ +} // namespace Ntlm +} // namespace Auth + +#endif /* SQUID_AUTH_NTLM_SCHEME_H */ diff --git a/src/auth/ntlm/auth_ntlm.cc b/src/auth/ntlm/auth_ntlm.cc index a38d524361..9e3e8ebf6e 100644 --- a/src/auth/ntlm/auth_ntlm.cc +++ b/src/auth/ntlm/auth_ntlm.cc @@ -140,7 +140,7 @@ AuthNTLMConfig::parse(AuthConfig * scheme, int n_configured, char *param_str) const char * AuthNTLMConfig::type() const { - return ntlmScheme::GetInstance()->type(); + return Auth::Ntlm::Scheme::GetInstance()->type(); } /* Initialize helpers and the like for this auth scheme. Called AFTER parsing the