]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/digest/User.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / auth / digest / User.cc
CommitLineData
bbc27441
AJ
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
f7f3304a 9#include "squid.h"
12daeef6 10#include "auth/digest/Config.h"
aa110616
AJ
11#include "auth/digest/User.h"
12#include "Debug.h"
13#include "dlink.h"
4d5904f7 14#include "SquidConfig.h"
aa110616
AJ
15#include "SquidTime.h"
16
d4806c91 17Auth::Digest::User::User(Auth::Config *aConfig, const char *aRequestRealm) :
f53969cc
SM
18 Auth::User(aConfig, aRequestRealm),
19 HA1created(0)
1032a194
AJ
20{
21 memset(HA1, 0, sizeof(HA1));
22}
aa110616
AJ
23
24Auth::Digest::User::~User()
25{
26 dlink_node *link, *tmplink;
27 link = nonces.head;
28
29 while (link) {
30 tmplink = link;
31 link = link->next;
32 dlinkDelete(tmplink, &nonces);
33 authDigestNoncePurge(static_cast < digest_nonce_h * >(tmplink->data));
34 authDigestNonceUnlink(static_cast < digest_nonce_h * >(tmplink->data));
35 dlinkNodeDelete(tmplink);
36 }
37}
38
39int32_t
40Auth::Digest::User::ttl() const
41{
42 int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + ::Config.authenticateTTL);
43
44 /* find the longest lasting nonce. */
45 int32_t latest_nonce = -1;
46 dlink_node *link = nonces.head;
47 while (link) {
48 digest_nonce_h *nonce = static_cast<digest_nonce_h *>(link->data);
49 if (nonce->flags.valid && nonce->noncedata.creationtime > latest_nonce)
50 latest_nonce = nonce->noncedata.creationtime;
de76457e 51
aa110616
AJ
52 link = link->next;
53 }
54 if (latest_nonce == -1)
55 return min(-1, global_ttl);
de76457e 56
aa110616
AJ
57 int32_t nonce_ttl = latest_nonce - current_time.tv_sec + static_cast<Config*>(Auth::Config::Find("digest"))->noncemaxduration;
58
59 return min(nonce_ttl, global_ttl);
60}
572d2e31
HN
61
62digest_nonce_h *
63Auth::Digest::User::currentNonce()
64{
65 digest_nonce_h *nonce = NULL;
66 dlink_node *link = nonces.tail;
67 if (link) {
68 nonce = static_cast<digest_nonce_h *>(link->data);
69 if (authDigestNonceIsStale(nonce))
70 nonce = NULL;
71 }
72 return nonce;
73}
f53969cc 74