]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/digest/Scheme.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / auth / digest / Scheme.cc
1 /*
2 * Copyright (C) 1996-2014 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 #include "squid.h"
10 #include "auth/digest/Config.h"
11 #include "auth/digest/Scheme.h"
12 #include "Debug.h"
13 #include "globals.h"
14 #include "helper.h"
15
16 Auth::Scheme::Pointer Auth::Digest::Scheme::_instance = NULL;
17
18 Auth::Scheme::Pointer
19 Auth::Digest::Scheme::GetInstance()
20 {
21 if (_instance == NULL) {
22 _instance = new Auth::Digest::Scheme();
23 AddScheme(_instance);
24 }
25 return _instance;
26 }
27
28 char const *
29 Auth::Digest::Scheme::type() const
30 {
31 return "digest";
32 }
33
34 void
35 Auth::Digest::Scheme::shutdownCleanup()
36 {
37 if (_instance == NULL)
38 return;
39
40 PurgeCredentialsCache();
41 authenticateDigestNonceShutdown();
42
43 _instance = NULL;
44 debugs(29, DBG_CRITICAL, "Shutdown: Digest authentication.");
45 }
46
47 Auth::Config *
48 Auth::Digest::Scheme::createConfig()
49 {
50 Auth::Digest::Config *digestCfg = new Auth::Digest::Config;
51 return dynamic_cast<Auth::Config*>(digestCfg);
52 }
53
54 void
55 Auth::Digest::Scheme::PurgeCredentialsCache(void)
56 {
57 AuthUserHashPointer *usernamehash;
58
59 debugs(29, 2, HERE << "Erasing Digest authentication credentials from username cache.");
60 hash_first(proxy_auth_username_cache);
61
62 while ((usernamehash = static_cast<AuthUserHashPointer *>(hash_next(proxy_auth_username_cache)) )) {
63 Auth::User::Pointer auth_user = usernamehash->user();
64
65 if (strcmp(auth_user->config->type(), "digest") == 0) {
66 hash_remove_link(proxy_auth_username_cache, static_cast<hash_link*>(usernamehash));
67 delete usernamehash;
68 }
69 }
70 }
71