]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/basic/User.cc
Fix cbdata-related parts of UserNameCache.
[thirdparty/squid.git] / src / auth / basic / User.cc
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 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"
e1568a40 12#include "auth/UserNameCache.h"
aa110616 13#include "Debug.h"
4d5904f7 14#include "SquidConfig.h"
aa110616
AJ
15#include "SquidTime.h"
16
d4806c91 17Auth::Basic::User::User(Auth::Config *aConfig, const char *aRequestRealm) :
f53969cc
SM
18 Auth::User(aConfig, aRequestRealm),
19 passwd(NULL),
20 queue(NULL),
21 currentRequest(NULL)
c2eec79f
FC
22{
23 Cache()->insert(Pointer(this));
24}
aa110616
AJ
25
26Auth::Basic::User::~User()
27{
28 safe_free(passwd);
29}
30
31int32_t
32Auth::Basic::User::ttl() const
33{
34 if (credentials() != Auth::Ok && credentials() != Auth::Pending)
35 return -1; // TTL is obsolete NOW.
36
37 int32_t basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL;
38 int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + ::Config.authenticateTTL);
39
40 return min(basic_ttl, global_ttl);
41}
42
43bool
44Auth::Basic::User::authenticated() const
45{
46 if ((credentials() == Auth::Ok) && (expiretime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL > squid_curtime))
47 return true;
48
49 debugs(29, 4, "User not authenticated or credentials need rechecking.");
50
51 return false;
52}
53
54bool
55Auth::Basic::User::valid() const
56{
57 if (username() == NULL)
58 return false;
59 if (passwd == NULL)
60 return false;
61 return true;
62}
63
64void
65Auth::Basic::User::updateCached(Auth::Basic::User *from)
66{
67 debugs(29, 9, HERE << "Found user '" << from->username() << "' already in the user cache as '" << this << "'");
68
69 assert(strcmp(from->username(), username()) == 0);
70
71 if (strcmp(from->passwd, passwd)) {
72 debugs(29, 4, HERE << "new password found. Updating in user master record and resetting auth state to unchecked");
73 credentials(Auth::Unchecked);
74 xfree(passwd);
75 passwd = from->passwd;
76 from->passwd = NULL;
77 }
78
79 if (credentials() == Auth::Failed) {
80 debugs(29, 4, HERE << "last attempt to authenticate this user failed, resetting auth state to unchecked");
81 credentials(Auth::Unchecked);
82 }
83}
84
e1568a40
FC
85CbcPointer<Auth::UserNameCache>
86Auth::Basic::User::Cache()
87{
c2eec79f 88 static CbcPointer<Auth::UserNameCache> p(new Auth::UserNameCache("basic"));
e1568a40
FC
89 return p;
90}
91