]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/Gadgets.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / auth / Gadgets.cc
1 /*
2 * Copyright (C) 1996-2016 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 "HttpReply.h"
32 #include "HttpRequest.h"
33
34 /**** PUBLIC FUNCTIONS (ALL GENERIC!) ****/
35
36 int
37 authenticateActiveSchemeCount(void)
38 {
39 int rv = 0;
40
41 for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i)
42 if ((*i)->configured())
43 ++rv;
44
45 debugs(29, 9, HERE << rv << " active.");
46
47 return rv;
48 }
49
50 int
51 authenticateSchemeCount(void)
52 {
53 int rv = Auth::Scheme::GetSchemes().size();
54
55 debugs(29, 9, HERE << rv << " active.");
56
57 return rv;
58 }
59
60 static void
61 authenticateRegisterWithCacheManager(Auth::ConfigVector * config)
62 {
63 for (Auth::ConfigVector::iterator i = config->begin(); i != config->end(); ++i) {
64 Auth::Config *scheme = *i;
65 scheme->registerWithCacheManager();
66 }
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 (Auth::ConfigVector::iterator i = config->begin(); i != config->end(); ++i) {
77 Auth::Config *schemeCfg = *i;
78
79 if (schemeCfg->configured())
80 schemeCfg->init(schemeCfg);
81 }
82
83 authenticateRegisterWithCacheManager(config);
84 }
85
86 void
87 authenticateRotate(void)
88 {
89 for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i)
90 if ((*i)->configured())
91 (*i)->rotateHelpers();
92 }
93
94 void
95 authenticateReset(void)
96 {
97 debugs(29, 2, "Reset authentication State.");
98
99 // username cache is cleared via Runner registry
100
101 /* schedule shutdown of the helpers */
102 authenticateRotate();
103
104 /* free current global config details too. */
105 Auth::TheConfig.clear();
106 }
107
108 std::vector<Auth::User::Pointer>
109 authenticateCachedUsersList()
110 {
111 auto aucp_compare = [=](const Auth::User::Pointer lhs, const Auth::User::Pointer rhs) {
112 return lhs->userKey() < rhs->userKey();
113 };
114 std::vector<Auth::User::Pointer> v1, v2, rv, u1, u2;
115 #if HAVE_AUTH_MODULE_BASIC
116 if (Auth::Config::Find("basic") != nullptr)
117 u1 = Auth::Basic::User::Cache()->sortedUsersList();
118 #endif
119 #if HAVE_AUTH_MODULE_DIGEST
120 if (Auth::Config::Find("digest") != nullptr)
121 u2 = Auth::Digest::User::Cache()->sortedUsersList();
122 #endif
123 if (u1.size() > 0 || u2.size() > 0) {
124 v1.reserve(u1.size()+u2.size());
125 std::merge(u1.begin(), u1.end(),u2.begin(), u2.end(),
126 std::back_inserter(v1), aucp_compare);
127 u1.clear();
128 u2.clear();
129 }
130 #if HAVE_AUTH_MODULE_NEGOTIATE
131 if (Auth::Config::Find("negotiate") != nullptr)
132 u1 = Auth::Negotiate::User::Cache()->sortedUsersList();
133 #endif
134 #if HAVE_AUTH_MODULE_NTLM
135 if (Auth::Config::Find("ntlm") != nullptr)
136 u2 = Auth::Ntlm::User::Cache()->sortedUsersList();
137 #endif
138 if (u1.size() > 0 || u2.size() > 0) {
139 v2.reserve(u1.size()+u2.size());
140 std::merge(u1.begin(), u1.end(),u2.begin(), u2.end(),
141 std::back_inserter(v2), aucp_compare);
142 }
143 rv.reserve(v1.size()+v2.size());
144 std::merge(v1.begin(), v1.end(),v2.begin(), v2.end(),
145 std::back_inserter(rv), aucp_compare);
146 return rv;
147 }
148