User.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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/basic/Config.h"
11 #include "auth/basic/User.h"
12 #include "auth/Config.h"
13 #include "auth/CredentialsCache.h"
14 #include "Debug.h"
15 
16 Auth::Basic::User::User(Auth::SchemeConfig *aConfig, const char *aRequestRealm) :
17  Auth::User(aConfig, aRequestRealm),
18  passwd(NULL),
19  queue(NULL),
20  currentRequest(NULL)
21 {}
22 
23 Auth::Basic::User::~User()
24 {
25  safe_free(passwd);
26 }
27 
28 int32_t
29 Auth::Basic::User::ttl() const
30 {
32  return -1; // TTL is obsolete NOW.
33 
34  int32_t basic_ttl = expiretime - squid_curtime + static_cast<Auth::Basic::Config*>(config)->credentialsTTL;
35  int32_t global_ttl = static_cast<int32_t>(expiretime - squid_curtime + Auth::TheConfig.credentialsTtl);
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 {
54  if (username() == NULL)
55  return false;
56  if (passwd == NULL)
57  return false;
58  return true;
59 }
60 
61 void
62 Auth::Basic::User::updateCached(Auth::Basic::User *from)
63 {
64  debugs(29, 9, HERE << "Found user '" << from->username() << "' already in the user cache as '" << this << "'");
65 
66  assert(strcmp(from->username(), username()) == 0);
67 
68  if (strcmp(from->passwd, passwd)) {
69  debugs(29, 4, HERE << "new password found. Updating in user master record and resetting auth state to unchecked");
71  xfree(passwd);
72  passwd = from->passwd;
73  from->passwd = NULL;
74  }
75 
76  if (credentials() == Auth::Failed) {
77  debugs(29, 4, HERE << "last attempt to authenticate this user failed, resetting auth state to unchecked");
79  }
80 }
81 
84 {
85  static CbcPointer<Auth::CredentialsCache> p(new Auth::CredentialsCache("basic", "GC Basic user credentials"));
86  return p;
87 }
88 
89 void
90 Auth::Basic::User::addToNameCache()
91 {
92  Cache()->insert(userKey(), this);
93 }
94 
#define assert(EX)
Definition: assert.h:17
#define safe_free(x)
Definition: xalloc.h:73
struct _Cache Cache
char * p
Definition: membanger.c:43
Cache of Auth::User credentials, keyed by Auth::User::userKey.
time_t squid_curtime
Definition: stub_time.cc:17
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
Auth::Config TheConfig
Definition: stub_libauth.cc:21
static char credentials[MAX_USERNAME_LEN+MAX_DOMAIN_LEN+2]
#define xfree
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
time_t credentialsTtl
the authenticate_ttl
Definition: Config.h:46
A const & min(A const &lhs, A const &rhs)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors