5 * DEBUG: section 29 Authenticator
6 * AUTHOR: Robert Collins
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36 /* The functions in this file handle authentication.
37 * They DO NOT perform access control or auditing.
38 * See acl.c for access control and client_side.c for auditing */
41 #include "authenticate.h"
43 #include "client_side.h"
44 #include "AuthConfig.h"
45 #include "AuthScheme.h"
47 #include "HttpReply.h"
48 #include "HttpRequest.h"
50 /**** PUBLIC FUNCTIONS (ALL GENERIC!) ****/
53 authenticateActiveSchemeCount(void)
57 for (authConfig::iterator i
= Config
.authConfiguration
.begin(); i
!= Config
.authConfiguration
.end(); ++i
)
58 if ((*i
)->configured())
61 debugs(29, 9, "authenticateActiveSchemeCount: " << rv
<< " active.");
67 authenticateSchemeCount(void)
69 int rv
= AuthScheme::Schemes().size();
71 debugs(29, 9, "authenticateSchemeCount: " << rv
<< " active.");
77 authenticateRegisterWithCacheManager(authConfig
* config
)
79 for (authConfig::iterator i
= config
->begin(); i
!= config
->end(); ++i
) {
80 AuthConfig
*scheme
= *i
;
81 scheme
->registerWithCacheManager();
86 authenticateInit(authConfig
* config
)
88 for (authConfig::iterator i
= config
->begin(); i
!= config
->end(); ++i
) {
89 AuthConfig
*scheme
= *i
;
91 if (scheme
->configured())
95 if (!proxy_auth_username_cache
)
96 AuthUser::cacheInit();
98 AuthUser::CachedACLsReset();
100 authenticateRegisterWithCacheManager(&Config
.authConfiguration
);
104 authenticateShutdown(void)
106 debugs(29, 2, "authenticateShutdown: shutting down auth schemes");
107 /* free the cache if we are shutting down */
110 hashFreeItems(proxy_auth_username_cache
, AuthUserHashPointer::removeFromCache
);
111 AuthScheme::FreeAll();
113 for (AuthScheme::const_iterator i
= AuthScheme::Schemes().begin(); i
!= AuthScheme::Schemes().end(); ++i
)
123 authenticateAuthUserInuse(AuthUser
* auth_user
)
125 assert(auth_user
!= NULL
);
126 return auth_user
->references
;
130 authenticateAuthUserMerge(AuthUser
* from
, AuthUser
* to
)
136 * Cleans all config-dependent data from the auth_user cache.
137 \note It DOES NOT Flush the user cache.
140 authenticateUserCacheRestart(void)
142 AuthUserHashPointer
*usernamehash
;
144 debugs(29, 3, HERE
<< "Clearing config dependent cache data.");
145 hash_first(proxy_auth_username_cache
);
147 while ((usernamehash
= ((AuthUserHashPointer
*) hash_next(proxy_auth_username_cache
)))) {
148 auth_user
= usernamehash
->user();
149 debugs(29, 5, "authenticateUserCacheRestat: Clearing cache ACL results for user: " << auth_user
->username());
155 AuthUserHashPointer::removeFromCache(void *usernamehash_p
)
157 AuthUserHashPointer
*usernamehash
= static_cast<AuthUserHashPointer
*>(usernamehash_p
);
158 AuthUser
*auth_user
= usernamehash
->auth_user
;
160 if ((authenticateAuthUserInuse(auth_user
) - 1))
161 debugs(29, 1, "AuthUserHashPointer::removeFromCache: entry in use - not freeing");
165 /** \todo change behaviour - we remove from the auth user list here, and then unlock, and the
170 AuthUserHashPointer::AuthUserHashPointer(AuthUser
* anAuth_user
):
171 auth_user(anAuth_user
)
173 key
= (void *)anAuth_user
->username();
175 hash_join(proxy_auth_username_cache
, (hash_link
*) this);
177 /** lock for presence in the cache */
182 AuthUserHashPointer::user() const