#include "squid.h"
#include "auth/Config.h"
+#include "auth/Gadgets.h"
#include "auth/UserRequest.h"
#include "cache_cf.h"
#include "ConfigParser.h"
keyExtras = NULL;
keyExtrasLine.clean();
}
+
+Auth::User::Pointer
+Auth::Config::findUserInCache(const char *nameKey, Auth::Type type)
+{
+ AuthUserHashPointer *usernamehash;
+ debugs(29, 9, "Looking for user '" << nameKey << "'");
+
+ if (nameKey && (usernamehash = static_cast<AuthUserHashPointer *>(hash_lookup(proxy_auth_username_cache, nameKey)))) {
+ while (usernamehash) {
+ if ((usernamehash->user()->auth_type == type) &&
+ !strcmp(nameKey, (char const *)usernamehash->key))
+ return usernamehash->user();
+
+ usernamehash = static_cast<AuthUserHashPointer *>(usernamehash->next);
+ }
+ }
+
+ return NULL;
+}
/** add headers as needed when challenging for auth */
virtual void fixHeader(UserRequest::Pointer, HttpReply *, http_hdr_type, HttpRequest *) = 0;
+ /// Find any existing user credentials in the authentication cache by name and type.
+ virtual Auth::User::Pointer findUserInCache(const char *nameKey, Auth::Type type);
+
/** prepare to handle requests */
virtual void init(Config *) = 0;
helperStats(sentry, basicauthenticators, "Basic Authenticator Statistics");
}
-static Auth::User::Pointer
-authBasicAuthUserFindUsername(const char *userkey)
-{
- AuthUserHashPointer *usernamehash;
- debugs(29, 9, "Looking for user '" << userkey << "'");
-
- if (userkey && (usernamehash = static_cast<AuthUserHashPointer *>(hash_lookup(proxy_auth_username_cache, userkey)))) {
- while (usernamehash) {
- if ((usernamehash->user()->auth_type == Auth::AUTH_BASIC) &&
- !strcmp(userkey, (char const *)usernamehash->key))
- return usernamehash->user();
-
- usernamehash = static_cast<AuthUserHashPointer *>(usernamehash->next);
- }
- }
-
- return NULL;
-}
-
char *
Auth::Basic::Config::decodeCleartext(const char *httpAuthHeader)
{
/* now lookup and see if we have a matching auth_user structure in memory. */
Auth::User::Pointer auth_user;
- if ((auth_user = authBasicAuthUserFindUsername(lb->userKey())) == NULL) {
+ if ((auth_user = findUserInCache(lb->userKey(), Auth::AUTH_BASIC)) == NULL) {
/* the user doesn't exist in the username cache yet */
/* save the credentials */
debugs(29, 9, HERE << "Creating new user '" << lb->username() << "'");
authDigestNonceUnlink(nonce);
}
-/* USER related functions */
-static Auth::User::Pointer
-authDigestUserFindUsername(const char *userkey)
-{
- AuthUserHashPointer *usernamehash;
- debugs(29, 9, "Looking for user '" << userkey << "'");
-
- if ((usernamehash = static_cast < AuthUserHashPointer * >(hash_lookup(proxy_auth_username_cache, userkey)))) {
- while ((usernamehash->user()->auth_type != Auth::AUTH_DIGEST) && (usernamehash->next))
- usernamehash = static_cast<AuthUserHashPointer *>(usernamehash->next);
-
- if (usernamehash->user()->auth_type == Auth::AUTH_DIGEST) {
- return usernamehash->user();
- }
- }
-
- return NULL;
-}
-
void
Auth::Digest::Config::rotateHelpers()
{
{
dlink_node *node;
- if (!user || !nonce)
+ if (!user || !nonce || !nonce->user)
return;
Auth::Digest::User *digest_user = user;
Auth::User::Pointer auth_user;
SBuf key = Auth::User::BuildUserKey(username, aRequestRealm);
- if (key.isEmpty() || (auth_user = authDigestUserFindUsername(key.c_str())) == NULL) {
+ if (key.isEmpty() || (auth_user = findUserInCache(key.c_str(), Auth::AUTH_DIGEST)) == NULL) {
/* the user doesn't exist in the username cache yet */
debugs(29, 9, HERE << "Creating new digest user '" << username << "'");
digest_user = new Auth::Digest::User(this, aRequestRealm);