]> 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-2015 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/Config.h"
20 #include "auth/Gadgets.h"
21 #include "auth/Scheme.h"
22 #include "auth/User.h"
23 #include "auth/UserRequest.h"
24 #include "client_side.h"
25 #include "globals.h"
26 #include "HttpReply.h"
27 #include "HttpRequest.h"
28
29 /**** PUBLIC FUNCTIONS (ALL GENERIC!) ****/
30
31 int
32 authenticateActiveSchemeCount(void)
33 {
34 int rv = 0;
35
36 for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i)
37 if ((*i)->configured())
38 ++rv;
39
40 debugs(29, 9, HERE << rv << " active.");
41
42 return rv;
43 }
44
45 int
46 authenticateSchemeCount(void)
47 {
48 int rv = Auth::Scheme::GetSchemes().size();
49
50 debugs(29, 9, HERE << rv << " active.");
51
52 return rv;
53 }
54
55 static void
56 authenticateRegisterWithCacheManager(Auth::ConfigVector * config)
57 {
58 for (Auth::ConfigVector::iterator i = config->begin(); i != config->end(); ++i) {
59 Auth::Config *scheme = *i;
60 scheme->registerWithCacheManager();
61 }
62 }
63
64 void
65 authenticateInit(Auth::ConfigVector * config)
66 {
67 /* Do this first to clear memory and remove dead state on a reconfigure */
68 if (proxy_auth_username_cache)
69 Auth::User::CachedACLsReset();
70
71 /* If we do not have any auth config state to create stop now. */
72 if (!config)
73 return;
74
75 for (Auth::ConfigVector::iterator i = config->begin(); i != config->end(); ++i) {
76 Auth::Config *schemeCfg = *i;
77
78 if (schemeCfg->configured())
79 schemeCfg->init(schemeCfg);
80 }
81
82 if (!proxy_auth_username_cache)
83 Auth::User::cacheInit();
84
85 authenticateRegisterWithCacheManager(config);
86 }
87
88 void
89 authenticateRotate(void)
90 {
91 for (Auth::ConfigVector::iterator i = Auth::TheConfig.begin(); i != Auth::TheConfig.end(); ++i)
92 if ((*i)->configured())
93 (*i)->rotateHelpers();
94 }
95
96 void
97 authenticateReset(void)
98 {
99 debugs(29, 2, HERE << "Reset authentication State.");
100
101 /* free all username cache entries */
102 hash_first(proxy_auth_username_cache);
103 AuthUserHashPointer *usernamehash;
104 while ((usernamehash = ((AuthUserHashPointer *) hash_next(proxy_auth_username_cache)))) {
105 debugs(29, 5, HERE << "Clearing entry for user: " << usernamehash->user()->username());
106 hash_remove_link(proxy_auth_username_cache, (hash_link *)usernamehash);
107 delete usernamehash;
108 }
109
110 /* schedule shutdown of the helpers */
111 authenticateRotate();
112
113 /* free current global config details too. */
114 Auth::TheConfig.clear();
115 }
116
117 AuthUserHashPointer::AuthUserHashPointer(Auth::User::Pointer anAuth_user):
118 auth_user(anAuth_user)
119 {
120 key = (void *)anAuth_user->userKey();
121 next = NULL;
122 hash_join(proxy_auth_username_cache, (hash_link *) this);
123 }
124
125 Auth::User::Pointer
126 AuthUserHashPointer::user() const
127 {
128 return auth_user;
129 }
130