]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/Gadgets.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / auth / Gadgets.cc
1 /*
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 29 Authenticator */
10
11 /* The functions in this file handle authentication.
12 * They DO NOT perform access control or auditing.
13 * See acl.c for access control and client_side.c for auditing */
14
15 #include "squid.h"
16 #include "acl/Acl.h"
17 #include "acl/FilledChecklist.h"
18 #include "auth/AclProxyAuth.h"
19 #include "auth/basic/User.h"
20 #include "auth/Config.h"
21 #include "auth/CredentialsCache.h"
22 #include "auth/digest/User.h"
23 #include "auth/Gadgets.h"
24 #include "auth/negotiate/User.h"
25 #include "auth/ntlm/User.h"
26 #include "auth/Scheme.h"
27 #include "auth/User.h"
28 #include "auth/UserRequest.h"
29 #include "client_side.h"
30 #include "globals.h"
31 #include "http/Stream.h"
32 #include "HttpReply.h"
33 #include "HttpRequest.h"
34
35 /**** PUBLIC FUNCTIONS (ALL GENERIC!) ****/
36
37 int
38 authenticateActiveSchemeCount(void)
39 {
40 int rv = 0;
41
42 for (const auto *scheme : Auth::TheConfig.schemes) {
43 if (scheme->configured())
44 ++rv;
45 }
46
47 debugs(29, 9, HERE << rv << " active.");
48
49 return rv;
50 }
51
52 int
53 authenticateSchemeCount(void)
54 {
55 int rv = Auth::Scheme::GetSchemes().size();
56
57 debugs(29, 9, HERE << rv << " active.");
58
59 return rv;
60 }
61
62 static void
63 authenticateRegisterWithCacheManager(Auth::ConfigVector * config)
64 {
65 for (auto *scheme : *config)
66 scheme->registerWithCacheManager();
67 }
68
69 void
70 authenticateInit(Auth::ConfigVector * config)
71 {
72 /* If we do not have any auth config state to create stop now. */
73 if (!config)
74 return;
75
76 for (auto *scheme : *config) {
77 if (scheme->configured())
78 scheme->init(scheme);
79 }
80
81 authenticateRegisterWithCacheManager(config);
82 }
83
84 void
85 authenticateRotate(void)
86 {
87 for (auto *scheme : Auth::TheConfig.schemes) {
88 if (scheme->configured())
89 scheme->rotateHelpers();
90 }
91 }
92
93 void
94 authenticateReset(void)
95 {
96 debugs(29, 2, "Reset authentication State.");
97
98 // username cache is cleared via Runner registry
99
100 /* schedule shutdown of the helpers */
101 authenticateRotate();
102
103 /* free current global config details too. */
104 Auth::TheConfig.schemes.clear();
105 }
106
107 std::vector<Auth::User::Pointer>
108 authenticateCachedUsersList()
109 {
110 auto aucp_compare = [=](const Auth::User::Pointer lhs, const Auth::User::Pointer rhs) {
111 return lhs->userKey() < rhs->userKey();
112 };
113 std::vector<Auth::User::Pointer> v1, v2, rv, u1, u2;
114 #if HAVE_AUTH_MODULE_BASIC
115 if (Auth::SchemeConfig::Find("basic"))
116 u1 = Auth::Basic::User::Cache()->sortedUsersList();
117 #endif
118 #if HAVE_AUTH_MODULE_DIGEST
119 if (Auth::SchemeConfig::Find("digest"))
120 u2 = Auth::Digest::User::Cache()->sortedUsersList();
121 #endif
122 if (u1.size() > 0 || u2.size() > 0) {
123 v1.reserve(u1.size()+u2.size());
124 std::merge(u1.begin(), u1.end(),u2.begin(), u2.end(),
125 std::back_inserter(v1), aucp_compare);
126 u1.clear();
127 u2.clear();
128 }
129 #if HAVE_AUTH_MODULE_NEGOTIATE
130 if (Auth::SchemeConfig::Find("negotiate"))
131 u1 = Auth::Negotiate::User::Cache()->sortedUsersList();
132 #endif
133 #if HAVE_AUTH_MODULE_NTLM
134 if (Auth::SchemeConfig::Find("ntlm"))
135 u2 = Auth::Ntlm::User::Cache()->sortedUsersList();
136 #endif
137 if (u1.size() > 0 || u2.size() > 0) {
138 v2.reserve(u1.size()+u2.size());
139 std::merge(u1.begin(), u1.end(),u2.begin(), u2.end(),
140 std::back_inserter(v2), aucp_compare);
141 }
142 rv.reserve(v1.size()+v2.size());
143 std::merge(v1.begin(), v1.end(),v2.begin(), v2.end(),
144 std::back_inserter(rv), aucp_compare);
145 return rv;
146 }
147