]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/User.h
Audit round 1
[thirdparty/squid.git] / src / auth / User.h
1 /*
2 * Copyright (C) 1996-2015 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 #ifndef SQUID_AUTH_USER_H
10 #define SQUID_AUTH_USER_H
11
12 #if USE_AUTH
13
14 #include "auth/CredentialState.h"
15 #include "auth/Type.h"
16 #include "base/CbcPointer.h"
17 #include "base/RefCount.h"
18 #include "dlink.h"
19 #include "ip/Address.h"
20 #include "Notes.h"
21 #include "SBuf.h"
22
23 class StoreEntry;
24
25 namespace Auth
26 {
27
28 class Config;
29 class UserNameCache;
30
31 /**
32 * \ingroup AuthAPI
33 * This is the main user related structure. It stores user-related data,
34 * and is persistent across requests. It can even persist across
35 * multiple external authentications. One major benefit of preserving this
36 * structure is the cached ACL match results. This structure, is private to
37 * the authentication framework.
38 */
39 class User : public RefCountable
40 {
41 public:
42 typedef RefCount<User> Pointer;
43
44 /* extra fields for proxy_auth */
45 /* auth_type and auth_module are deprecated. Do Not add new users of these fields.
46 * Aim to remove shortly
47 */
48 /** \deprecated this determines what scheme owns the user data. */
49 Auth::Type auth_type;
50 /** the config for this user */
51 Auth::Config *config;
52 dlink_list proxy_match_cache;
53 size_t ipcount;
54 long expiretime;
55
56 /// list of key=value pairs the helper produced
57 NotePairs notes;
58
59 public:
60 static SBuf BuildUserKey(const char *username, const char *realm);
61
62 void absorb(Auth::User::Pointer from);
63 virtual ~User();
64 char const *username() const { return username_; }
65 void username(char const *); ///< set stored username and userKey
66
67 // NP: key is set at the same time as username_. Until then both are empty/NULL.
68 const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : NULL;}
69 // user key as a SBuf
70 const SBuf SBufUserKey() const {return userKey_;}
71
72 /**
73 * How long these credentials are still valid for.
74 * Negative numbers means already expired.
75 */
76 virtual int32_t ttl() const = 0;
77
78 /* Manage list of IPs using this username */
79 void clearIp();
80 void removeIp(Ip::Address);
81 void addIp(Ip::Address);
82
83 /// add the Auth::User to the protocol-specific username cache.
84 virtual void addToNameCache() = 0;
85 static void UsernameCacheStats(StoreEntry * output);
86
87 // userKey ->Auth::User::Pointer cache
88 // must be reimplemented in subclasses
89 static CbcPointer<Auth::UserNameCache> Cache();
90
91 CredentialState credentials() const;
92 void credentials(CredentialState);
93
94 private:
95 /**
96 * The current state these credentials are in:
97 * Unchecked
98 * Authenticated
99 * Pending helper result
100 * Handshake happening in stateful auth.
101 * Failed auth
102 */
103 CredentialState credentials_state;
104
105 protected:
106 User(Auth::Config *, const char *requestRealm);
107
108 private:
109 /**
110 * DPW 2007-05-08
111 * The username_ memory will be allocated via
112 * xstrdup(). It is our responsibility.
113 */
114 const char *username_;
115
116 /**
117 * A realm for the user depending on request, designed to identify users,
118 * with the same username and different authentication domains.
119 */
120 SBuf requestRealm_;
121
122 /**
123 * A Unique key for the user, consist by username and requestRealm_
124 */
125 SBuf userKey_;
126
127 /** what ip addresses has this user been seen at?, plus a list length cache */
128 dlink_list ip_list;
129 };
130
131 } // namespace Auth
132
133 #endif /* USE_AUTH */
134 #endif /* SQUID_AUTH_USER_H */
135