]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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" |
12daeef6 | 10 | #include "auth/basic/Config.h" |
aa110616 | 11 | #include "auth/basic/User.h" |
5db226c8 | 12 | #include "auth/Config.h" |
638cfbc4 | 13 | #include "auth/CredentialsCache.h" |
675b8408 | 14 | #include "debug/Stream.h" |
aa110616 | 15 | |
dc79fed8 | 16 | Auth::Basic::User::User(Auth::SchemeConfig *aConfig, const char *aRequestRealm) : |
f53969cc | 17 | Auth::User(aConfig, aRequestRealm), |
aee3523a AR |
18 | passwd(nullptr), |
19 | queue(nullptr), | |
20 | currentRequest(nullptr) | |
46b1e6bf | 21 | {} |
aa110616 AJ |
22 | |
23 | Auth::Basic::User::~User() | |
24 | { | |
25 | safe_free(passwd); | |
26 | } | |
27 | ||
28 | int32_t | |
29 | Auth::Basic::User::ttl() const | |
30 | { | |
31 | if (credentials() != Auth::Ok && credentials() != Auth::Pending) | |
32 | return -1; // TTL is obsolete NOW. | |
33 | ||
34 | int32_t basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL; | |
00ef8d82 | 35 | int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + Auth::TheConfig.credentialsTtl); |
aa110616 AJ |
36 | |
37 | return min(basic_ttl, global_ttl); | |
38 | } | |
39 | ||
40 | bool | |
41 | Auth::Basic::User::authenticated() const | |
42 | { | |
43 | if ((credentials() == Auth::Ok) && (expiretime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL > squid_curtime)) | |
44 | return true; | |
45 | ||
46 | debugs(29, 4, "User not authenticated or credentials need rechecking."); | |
47 | ||
48 | return false; | |
49 | } | |
50 | ||
51 | bool | |
52 | Auth::Basic::User::valid() const | |
53 | { | |
aee3523a | 54 | if (username() == nullptr) |
aa110616 | 55 | return false; |
aee3523a | 56 | if (passwd == nullptr) |
aa110616 AJ |
57 | return false; |
58 | return true; | |
59 | } | |
60 | ||
61 | void | |
62 | Auth::Basic::User::updateCached(Auth::Basic::User *from) | |
63 | { | |
bf95c10a | 64 | debugs(29, 9, "Found user '" << from->username() << "' already in the user cache as '" << this << "'"); |
aa110616 AJ |
65 | |
66 | assert(strcmp(from->username(), username()) == 0); | |
67 | ||
68 | if (strcmp(from->passwd, passwd)) { | |
bf95c10a | 69 | debugs(29, 4, "new password found. Updating in user master record and resetting auth state to unchecked"); |
aa110616 AJ |
70 | credentials(Auth::Unchecked); |
71 | xfree(passwd); | |
72 | passwd = from->passwd; | |
aee3523a | 73 | from->passwd = nullptr; |
aa110616 AJ |
74 | } |
75 | ||
76 | if (credentials() == Auth::Failed) { | |
bf95c10a | 77 | debugs(29, 4, "last attempt to authenticate this user failed, resetting auth state to unchecked"); |
aa110616 AJ |
78 | credentials(Auth::Unchecked); |
79 | } | |
80 | } | |
81 | ||
638cfbc4 | 82 | CbcPointer<Auth::CredentialsCache> |
e1568a40 FC |
83 | Auth::Basic::User::Cache() |
84 | { | |
455bb54d | 85 | static CbcPointer<Auth::CredentialsCache> p(new Auth::CredentialsCache("basic", "GC Basic user credentials")); |
e1568a40 FC |
86 | return p; |
87 | } | |
88 | ||
283c905d FC |
89 | void |
90 | Auth::Basic::User::addToNameCache() | |
91 | { | |
97821413 | 92 | Cache()->insert(userKey(), this); |
283c905d | 93 | } |
7512e3f9 | 94 |