]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add new Auth::Config class for libauth directives
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 15 Dec 2016 06:25:06 +0000 (19:25 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 15 Dec 2016 06:25:06 +0000 (19:25 +1300)
Also, reduce some for loops using C++11 range-for.

src/auth/Config.cc [new file with mode: 0644]
src/auth/Config.h [new file with mode: 0644]
src/auth/Gadgets.cc
src/auth/Makefile.am
src/auth/SchemeConfig.cc
src/auth/SchemeConfig.h
src/auth/SchemesConfig.cc
src/auth/UserRequest.cc
src/cache_cf.cc
src/cf.data.pre
src/main.cc

diff --git a/src/auth/Config.cc b/src/auth/Config.cc
new file mode 100644 (file)
index 0000000..bdc30fc
--- /dev/null
@@ -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 (file)
index 0000000..23c0747
--- /dev/null
@@ -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 */
+
index 0d41c7e97df5e95f145107c9877e201800283271..f03f8268b72b5d8f81c52111b7fed43125b1c90a 100644 (file)
 #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<Auth::User::Pointer>
index a3b3b5caf6d5a43a97f7e9c6f8b2e5914a35fc92..29eeba31cdec8d41156919af17afd8c4e997e3c1 100644 (file)
@@ -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 \
index 36e5bd591366a450bb3c1410456b01df4675b428..0b7d933af111c1bce5ac4d67343078ca1b1322b2 100644 (file)
@@ -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;
 }
index 53fd1f5dff81e25e62aae0a0e5164bcc39ead8ca..d8c56b5e0f87dbd0fa80ef0907a475151ae83297 100644 (file)
@@ -135,8 +135,6 @@ protected:
     SBuf realm;
 };
 
-extern ConfigVector TheConfig;
-
 } // namespace Auth
 
 #endif /* USE_AUTH */
index b80c30389d8b8a5938d14ef3cab58e30504e0bff..d21782158386f5451ff5a0d1dd0a0f76e84964da 100644 (file)
@@ -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<SBuf> &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);
index 8b36eb88d07c576619bfc46962a5188e10af59fd..cd988df894986d896274c1887519a2d384c29fff 100644 (file)
 
 #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
index 3f1ae523de9793a0de2e8f929cae939b00aeb701..75236de293087b28de89a292f0139462bb083ed2 100644 (file)
@@ -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"
 #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
index cf495e37720a9617a99e2062795fe53136b06d22..62a2e4c408d9c5282363dd40c0d1655c1da2f3b8 100644 (file)
@@ -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
index 588aed0b445faf59121fb6c9797963a94d006007..f78cb2e2a87aee51baa763210e4c284cb9eb452d 100644 (file)
@@ -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();