From: Amos Jeffries Date: Thu, 15 Dec 2016 06:25:06 +0000 (+1300) Subject: Add new Auth::Config class for libauth directives X-Git-Tag: M-staged-PR71~333^2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c1125752bccc005a4707445c497ebf5c1040a76;p=thirdparty%2Fsquid.git Add new Auth::Config class for libauth directives Also, reduce some for loops using C++11 range-for. --- diff --git a/src/auth/Config.cc b/src/auth/Config.cc new file mode 100644 index 0000000000..bdc30fc507 --- /dev/null +++ b/src/auth/Config.cc @@ -0,0 +1,14 @@ +/* + * Copyright (C) 1996-2016 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +/* DEBUG: section 29 Authenticator */ + +#include "squid.h" +#include "auth/Config.h" + +Auth::Config Auth::TheConfig; diff --git a/src/auth/Config.h b/src/auth/Config.h new file mode 100644 index 0000000000..23c074727f --- /dev/null +++ b/src/auth/Config.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 1996-2016 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#ifndef SQUID_SRC_AUTH_CONFIG_H +#define SQUID_SRC_AUTH_CONFIG_H + +#if USE_AUTH + +#include "auth/SchemeConfig.h" +#include "auth/SchemesConfig.h" + +namespace Auth +{ + +class Config +{ +public: + /// set of auth_params directives + Auth::ConfigVector schemes; + + /// set of auth_schemes directives + Auth::SchemesConfig *schemeLists = nullptr; +}; + +extern Auth::Config TheConfig; + +} // namespace Auth + +#endif /* USE_AUTH */ +#endif /* SQUID_SRC_AUTH_CONFIG_H */ + diff --git a/src/auth/Gadgets.cc b/src/auth/Gadgets.cc index 0d41c7e97d..f03f8268b7 100644 --- a/src/auth/Gadgets.cc +++ b/src/auth/Gadgets.cc @@ -17,13 +17,13 @@ #include "acl/FilledChecklist.h" #include "auth/AclProxyAuth.h" #include "auth/basic/User.h" +#include "auth/Config.h" #include "auth/CredentialsCache.h" #include "auth/digest/User.h" #include "auth/Gadgets.h" #include "auth/negotiate/User.h" #include "auth/ntlm/User.h" #include "auth/Scheme.h" -#include "auth/SchemeConfig.h" #include "auth/User.h" #include "auth/UserRequest.h" #include "client_side.h" @@ -39,9 +39,10 @@ authenticateActiveSchemeCount(void) { int rv = 0; - for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i) - if ((*i)->configured()) + for (auto *scheme : Auth::TheConfig.schemes) { + if (scheme->configured()) ++rv; + } debugs(29, 9, HERE << rv << " active."); @@ -61,10 +62,8 @@ authenticateSchemeCount(void) static void authenticateRegisterWithCacheManager(Auth::ConfigVector * config) { - for (Auth::ConfigVector::iterator i = config->begin(); i != config->end(); ++i) { - Auth::SchemeConfig *scheme = *i; + for (auto *scheme : *config) scheme->registerWithCacheManager(); - } } void @@ -74,11 +73,9 @@ authenticateInit(Auth::ConfigVector * config) if (!config) return; - for (Auth::ConfigVector::iterator i = config->begin(); i != config->end(); ++i) { - Auth::SchemeConfig *schemeCfg = *i; - - if (schemeCfg->configured()) - schemeCfg->init(schemeCfg); + for (auto *scheme : *config) { + if (scheme->configured()) + scheme->init(scheme); } authenticateRegisterWithCacheManager(config); @@ -87,9 +84,10 @@ authenticateInit(Auth::ConfigVector * config) void authenticateRotate(void) { - for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i) - if ((*i)->configured()) - (*i)->rotateHelpers(); + for (auto *scheme : Auth::TheConfig.schemes) { + if (scheme->configured()) + scheme->rotateHelpers(); + } } void @@ -103,7 +101,7 @@ authenticateReset(void) authenticateRotate(); /* free current global config details too. */ - Auth::TheConfig.clear(); + Auth::TheConfig.schemes.clear(); } std::vector diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am index a3b3b5caf6..29eeba31cd 100644 --- a/src/auth/Makefile.am +++ b/src/auth/Makefile.am @@ -19,6 +19,8 @@ noinst_LTLIBRARIES = libauth.la libacls.la libauth_la_SOURCES = \ Type.h \ Type.cc \ + Config.cc \ + Config.h \ CredentialsCache.h \ CredentialsCache.cc \ CredentialState.cc \ diff --git a/src/auth/SchemeConfig.cc b/src/auth/SchemeConfig.cc index 36e5bd5913..0b7d933af1 100644 --- a/src/auth/SchemeConfig.cc +++ b/src/auth/SchemeConfig.cc @@ -9,8 +9,8 @@ /* DEBUG: section 29 Authenticator */ #include "squid.h" +#include "auth/Config.h" #include "auth/forward.h" -#include "auth/SchemeConfig.h" #include "auth/Gadgets.h" #include "auth/UserRequest.h" #include "cache_cf.h" @@ -21,8 +21,6 @@ #include "Store.h" #include "wordlist.h" -Auth::ConfigVector Auth::TheConfig; - /** * Get an User credentials object filled out for the given Proxy- or WWW-Authenticate header. * Any decoding which needs to be done will be done. @@ -59,9 +57,10 @@ Auth::SchemeConfig::CreateAuthUser(const char *proxy_auth, AccessLogEntry::Point Auth::SchemeConfig * Auth::SchemeConfig::Find(const char *proxy_auth) { - for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i) - if (strncasecmp(proxy_auth, (*i)->type(), strlen((*i)->type())) == 0) - return *i; + for (auto *scheme : Auth::TheConfig.schemes) { + if (strncasecmp(proxy_auth, scheme->type(), strlen(scheme->type())) == 0) + return scheme; + } return NULL; } diff --git a/src/auth/SchemeConfig.h b/src/auth/SchemeConfig.h index 53fd1f5dff..d8c56b5e0f 100644 --- a/src/auth/SchemeConfig.h +++ b/src/auth/SchemeConfig.h @@ -135,8 +135,6 @@ protected: SBuf realm; }; -extern ConfigVector TheConfig; - } // namespace Auth #endif /* USE_AUTH */ diff --git a/src/auth/SchemesConfig.cc b/src/auth/SchemesConfig.cc index b80c30389d..d217821583 100644 --- a/src/auth/SchemesConfig.cc +++ b/src/auth/SchemesConfig.cc @@ -7,7 +7,7 @@ */ #include "squid.h" -#include "auth/SchemesConfig.h" +#include "auth/Config.h" #include "fatal.h" #include "parser/Tokenizer.h" @@ -21,7 +21,7 @@ addUnique(const SBuf &scheme, std::vector &vec) { static const SBuf all("ALL"); if (scheme == all) { - for (const auto config: Auth::TheConfig) + for (const auto config: Auth::TheConfig.schemes) addUnique(SBuf(config->type()), vec); } else if (std::find(vec.begin(), vec.end(), scheme) == vec.end()) vec.push_back(scheme); diff --git a/src/auth/UserRequest.cc b/src/auth/UserRequest.cc index 8b36eb88d0..cd988df894 100644 --- a/src/auth/UserRequest.cc +++ b/src/auth/UserRequest.cc @@ -14,11 +14,7 @@ #include "squid.h" #include "acl/FilledChecklist.h" -#include "auth/SchemeConfig.h" -#include "auth/Scheme.h" -#include "auth/SchemesConfig.h" -#include "auth/User.h" -#include "auth/UserRequest.h" +#include "auth/Config.h" #include "client_side.h" #include "comm/Connection.h" #include "fatal.h" @@ -475,7 +471,7 @@ schemesConfig(HttpRequest *request, HttpReply *rep) if (answer == ACCESS_ALLOWED) return Auth::SchemeListConfig.at(answer.kind).authConfigs; } - return Auth::TheConfig; + return Auth::TheConfig.schemes; } void diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 3f1ae523de..75236de293 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -18,7 +18,8 @@ #include "acl/Tree.h" #include "anyp/PortCfg.h" #include "anyp/UriScheme.h" -#include "auth/SchemesConfig.h" +#include "auth/Config.h" +#include "auth/Scheme.h" #include "AuthReg.h" #include "base/RunnersRegistry.h" #include "cache_cf.h" @@ -78,11 +79,6 @@ #include "ssl/Config.h" #include "ssl/support.h" #endif -#if USE_AUTH -#include "auth/SchemeConfig.h" -#include "auth/Scheme.h" -#include "auth/SchemesConfig.h" -#endif #if USE_SQUID_ESI #include "esi/Parser.h" #endif diff --git a/src/cf.data.pre b/src/cf.data.pre index cf495e3772..62a2e4c408 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -481,7 +481,7 @@ COMMENT_END NAME: auth_param TYPE: authparam IFDEF: USE_AUTH -LOC: Auth::TheConfig +LOC: Auth::TheConfig.schemes DEFAULT: none DOC_START This is used to define parameters for the various authentication diff --git a/src/main.cc b/src/main.cc index 588aed0b44..f78cb2e2a8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -13,6 +13,8 @@ #include "acl/Acl.h" #include "acl/Asn.h" #include "AuthReg.h" +#include "auth/Config.h" +#include "auth/Gadgets.h" #include "base/RunnersRegistry.h" #include "base/Subscription.h" #include "base/TextException.h" @@ -87,9 +89,6 @@ #include "adaptation/icap/Config.h" #include "adaptation/icap/icap_log.h" #endif -#if USE_AUTH -#include "auth/Gadgets.h" -#endif #if USE_DELAY_POOLS #include "ClientDelayConfig.h" #endif @@ -964,7 +963,7 @@ mainReconfigureFinish(void *) redirectInit(); #if USE_AUTH - authenticateInit(&Auth::TheConfig); + authenticateInit(&Auth::TheConfig.schemes); #endif externalAclInit(); @@ -1031,7 +1030,7 @@ mainRotate(void) icmpEngine.Open(); redirectInit(); #if USE_AUTH - authenticateInit(&Auth::TheConfig); + authenticateInit(&Auth::TheConfig.schemes); #endif externalAclInit(); } @@ -1175,7 +1174,7 @@ mainInitialize(void) redirectInit(); #if USE_AUTH - authenticateInit(&Auth::TheConfig); + authenticateInit(&Auth::TheConfig.schemes); #endif externalAclInit();