]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
f7f3304a | 9 | #include "squid.h" |
fde785ee | 10 | #include "auth/CredentialsCache.h" |
12daeef6 | 11 | #include "auth/digest/Config.h" |
aa110616 AJ |
12 | #include "auth/digest/User.h" |
13 | #include "Debug.h" | |
14 | #include "dlink.h" | |
4d5904f7 | 15 | #include "SquidConfig.h" |
aa110616 AJ |
16 | #include "SquidTime.h" |
17 | ||
d4806c91 | 18 | Auth::Digest::User::User(Auth::Config *aConfig, const char *aRequestRealm) : |
f53969cc SM |
19 | Auth::User(aConfig, aRequestRealm), |
20 | HA1created(0) | |
1032a194 AJ |
21 | { |
22 | memset(HA1, 0, sizeof(HA1)); | |
23 | } | |
aa110616 AJ |
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)); | |
195b97bf | 36 | delete tmplink; |
aa110616 AJ |
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; | |
de76457e | 52 | |
aa110616 AJ |
53 | link = link->next; |
54 | } | |
55 | if (latest_nonce == -1) | |
56 | return min(-1, global_ttl); | |
de76457e | 57 | |
aa110616 AJ |
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 | } | |
572d2e31 HN |
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 | } | |
f53969cc | 75 | |
638cfbc4 | 76 | CbcPointer<Auth::CredentialsCache> |
e1568a40 FC |
77 | Auth::Digest::User::Cache() |
78 | { | |
455bb54d | 79 | static CbcPointer<Auth::CredentialsCache> p(new Auth::CredentialsCache("digest","GC Digest user credentials")); |
e1568a40 FC |
80 | return p; |
81 | } | |
283c905d FC |
82 | |
83 | void | |
84 | Auth::Digest::User::addToNameCache() | |
85 | { | |
97821413 | 86 | Cache()->insert(userKey(), this); |
283c905d | 87 | } |
7512e3f9 | 88 |