]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/basic/User.cc
Removed squid-old.h
[thirdparty/squid.git] / src / auth / basic / User.cc
CommitLineData
f7f3304a 1#include "squid.h"
aa110616
AJ
2#include "auth/basic/auth_basic.h"
3#include "auth/basic/User.h"
4#include "Debug.h"
5#include "SquidTime.h"
582c2af2 6#include "structs.h"
aa110616
AJ
7
8Auth::Basic::User::User(Auth::Config *aConfig) :
9 Auth::User(aConfig),
10 passwd(NULL),
11 auth_queue(NULL),
de76457e 12 currentRequest(NULL)
aa110616
AJ
13{}
14
15Auth::Basic::User::~User()
16{
17 safe_free(passwd);
18}
19
20int32_t
21Auth::Basic::User::ttl() const
22{
23 if (credentials() != Auth::Ok && credentials() != Auth::Pending)
24 return -1; // TTL is obsolete NOW.
25
26 int32_t basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL;
27 int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + ::Config.authenticateTTL);
28
29 return min(basic_ttl, global_ttl);
30}
31
32bool
33Auth::Basic::User::authenticated() const
34{
35 if ((credentials() == Auth::Ok) && (expiretime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL > squid_curtime))
36 return true;
37
38 debugs(29, 4, "User not authenticated or credentials need rechecking.");
39
40 return false;
41}
42
43bool
44Auth::Basic::User::valid() const
45{
46 if (username() == NULL)
47 return false;
48 if (passwd == NULL)
49 return false;
50 return true;
51}
52
53void
54Auth::Basic::User::updateCached(Auth::Basic::User *from)
55{
56 debugs(29, 9, HERE << "Found user '" << from->username() << "' already in the user cache as '" << this << "'");
57
58 assert(strcmp(from->username(), username()) == 0);
59
60 if (strcmp(from->passwd, passwd)) {
61 debugs(29, 4, HERE << "new password found. Updating in user master record and resetting auth state to unchecked");
62 credentials(Auth::Unchecked);
63 xfree(passwd);
64 passwd = from->passwd;
65 from->passwd = NULL;
66 }
67
68 if (credentials() == Auth::Failed) {
69 debugs(29, 4, HERE << "last attempt to authenticate this user failed, resetting auth state to unchecked");
70 credentials(Auth::Unchecked);
71 }
72}
73