]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/digest/User.cc
Merge from trunk rev.14289
[thirdparty/squid.git] / src / auth / digest / User.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 #include "squid.h"
10 #include "auth/digest/Config.h"
11 #include "auth/digest/User.h"
12 #include "auth/CredentialsCache.h"
13 #include "Debug.h"
14 #include "dlink.h"
15 #include "SquidConfig.h"
16 #include "SquidTime.h"
17
18 Auth::Digest::User::User(Auth::Config *aConfig, const char *aRequestRealm) :
19 Auth::User(aConfig, aRequestRealm),
20 HA1created(0)
21 {
22 memset(HA1, 0, sizeof(HA1));
23 }
24
25 Auth::Digest::User::~User()
26 {
27 dlink_node *link, *tmplink;
28 link = nonces.head;
29
30 while (link) {
31 tmplink = link;
32 link = link->next;
33 dlinkDelete(tmplink, &nonces);
34 authDigestNoncePurge(static_cast < digest_nonce_h * >(tmplink->data));
35 authDigestNonceUnlink(static_cast < digest_nonce_h * >(tmplink->data));
36 dlinkNodeDelete(tmplink);
37 }
38 }
39
40 int32_t
41 Auth::Digest::User::ttl() const
42 {
43 int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + ::Config.authenticateTTL);
44
45 /* find the longest lasting nonce. */
46 int32_t latest_nonce = -1;
47 dlink_node *link = nonces.head;
48 while (link) {
49 digest_nonce_h *nonce = static_cast<digest_nonce_h *>(link->data);
50 if (nonce->flags.valid && nonce->noncedata.creationtime > latest_nonce)
51 latest_nonce = nonce->noncedata.creationtime;
52
53 link = link->next;
54 }
55 if (latest_nonce == -1)
56 return min(-1, global_ttl);
57
58 int32_t nonce_ttl = latest_nonce - current_time.tv_sec + static_cast<Config*>(Auth::Config::Find("digest"))->noncemaxduration;
59
60 return min(nonce_ttl, global_ttl);
61 }
62
63 digest_nonce_h *
64 Auth::Digest::User::currentNonce()
65 {
66 digest_nonce_h *nonce = NULL;
67 dlink_node *link = nonces.tail;
68 if (link) {
69 nonce = static_cast<digest_nonce_h *>(link->data);
70 if (authDigestNonceIsStale(nonce))
71 nonce = NULL;
72 }
73 return nonce;
74 }
75
76 CbcPointer<Auth::CredentialsCache>
77 Auth::Digest::User::Cache()
78 {
79 static CbcPointer<Auth::CredentialsCache> p(new Auth::CredentialsCache("digest","GC Digest user credentials"));
80 return p;
81 }
82
83 void
84 Auth::Digest::User::addToNameCache()
85 {
86 Cache()->insert(this);
87 }
88