User.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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/Config.h"
12#include "auth/digest/Config.h"
13#include "auth/digest/User.h"
14#include "debug/Stream.h"
15#include "dlink.h"
16
17Auth::Digest::User::User(Auth::SchemeConfig *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 delete tmplink;
36 }
37}
38
39int32_t
40Auth::Digest::User::ttl() const
41{
42 int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + Auth::TheConfig.credentialsTtl);
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::SchemeConfig::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 = nullptr;
66 dlink_node *link = nonces.tail;
67 if (link) {
68 nonce = static_cast<digest_nonce_h *>(link->data);
69 if (authDigestNonceIsStale(nonce))
70 nonce = nullptr;
71 }
72 return nonce;
73}
74
77{
78 static CbcPointer<Auth::CredentialsCache> p(new Auth::CredentialsCache("digest","GC Digest user credentials"));
79 return p;
80}
81
82void
83Auth::Digest::User::addToNameCache()
84{
85 Cache()->insert(userKey(), this);
86}
87
time_t squid_curtime
Definition: stub_libtime.cc:20
class SquidConfig Config
Definition: SquidConfig.cc:12
void authDigestNonceUnlink(digest_nonce_h *nonce)
Definition: Config.cc:279
int authDigestNonceIsStale(digest_nonce_h *nonce)
Definition: Config.cc:363
void authDigestNoncePurge(digest_nonce_h *nonce)
Definition: Config.cc:426
time_t credentialsTtl
the authenticate_ttl
Definition: Config.h:43
Cache of Auth::User credentials, keyed by Auth::User::userKey.
static SchemeConfig * Find(const char *proxy_auth)
Definition: SchemeConfig.cc:59
A const & min(A const &lhs, A const &rhs)
HTTP Authentication.
Definition: Config.h:19
Auth::Config TheConfig
Definition: Config.cc:15
struct _Cache Cache
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors