source: squid-ssl/trunk/fuentes/src/auth/digest/User.cc @ 5496

Last change on this file since 5496 was 5495, checked in by Juanma, 2 years ago

Initial release

File size: 2.0 KB
Line 
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 "Debug.h"
13#include "dlink.h"
14#include "SquidConfig.h"
15#include "SquidTime.h"
16
17Auth::Digest::User::User(Auth::Config *aConfig, const char *aRequestRealm) :
18    Auth::User(aConfig, aRequestRealm),
19    HA1created(0)
20{
21    memset(HA1, 0, sizeof(HA1));
22}
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;
51
52        link = link->next;
53    }
54    if (latest_nonce == -1)
55        return min(-1, global_ttl);
56
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}
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}
74
Note: See TracBrowser for help on using the repository browser.