]> git.ipfire.org Git - thirdparty/squid.git/blame - src/auth/UserRequest.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / auth / UserRequest.h
CommitLineData
f5691f9c 1/*
bbc27441 2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
f5691f9c 3 *
bbc27441
AJ
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.
f5691f9c 7 */
8
c7baff40
AJ
9#ifndef SQUID_AUTH_USERREQUEST_H
10#define SQUID_AUTH_USERREQUEST_H
f5691f9c 11
2f1431ea
AJ
12#if USE_AUTH
13
d4806c91 14#include "AccessLogEntry.h"
56a49fda 15#include "auth/AuthAclState.h"
5817ee13 16#include "auth/Scheme.h"
56a49fda 17#include "auth/User.h"
a33a428a 18#include "dlink.h"
e166785a 19#include "helper.h"
a33a428a 20#include "HttpHeader.h"
602d9612 21#include "ip/Address.h"
f5691f9c 22
f5691f9c 23class ConnStateData;
a33a428a
AJ
24class HttpReply;
25class HttpRequest;
f5691f9c 26
7afc3bf2
AJ
27/**
28 * Maximum length (buffer size) for token strings.
29 */
30// AYJ: must match re-definition in helpers/negotiate_auth/kerberos/negotiate_kerb_auth.cc
31#define MAX_AUTHTOKEN_LEN 32768
32
c35dd848
AJ
33/**
34 * Node used to link an IP address to some user credentials
35 * for the max_user_ip ACL feature.
36 *
37 * \ingroup AuthAPI
38 */
56a49fda
AJ
39class AuthUserIP
40{
41public:
f5691f9c 42 dlink_node node;
f5691f9c 43
c35dd848 44 /// IP address this user authenticated from
b7ac5457 45 Ip::Address ipaddr;
c35dd848
AJ
46
47 /** When this IP should be forgotten.
48 * Set to the time of last request made from this
49 * (user,IP) pair plus authenticate_ip_ttl seconds
50 */
f5691f9c 51 time_t ip_expiretime;
52};
53
4c535e87
AJ
54// TODO: make auth schedule AsyncCalls?
55typedef void AUTHCB(void*);
56
51a3dd58
AJ
57namespace Auth
58{
59
60// NP: numeric values specified for old code backward compatibility.
61// remove after transition is complete
62enum Direction {
63 CRED_CHALLENGE = 1, ///< Client needs to be challenged. secure token.
64 CRED_VALID = 0, ///< Credentials are valid and a up to date. The OK/Failed state is accurate.
65 CRED_LOOKUP = -1, ///< Credentials need to be validated with the backend helper
66 CRED_ERROR = -2 ///< ERROR in the auth module. Cannot determine the state of this request.
67};
51a3dd58 68
63be0a78 69/**
63be0a78 70 * This is a short lived structure is the visible aspect of the authentication framework.
928f3421
AJ
71 *
72 * It and its children hold the state data while processing authentication for a client request.
73 * The AuthenticationStateData object is merely a CBDATA wrapper for one of these.
63be0a78 74 */
c7baff40 75class UserRequest : public RefCountable
f5691f9c 76{
a33a428a 77public:
c7baff40
AJ
78 typedef RefCount<Auth::UserRequest> Pointer;
79
80 UserRequest();
81 virtual ~UserRequest();
82 void *operator new(size_t byteCount);
83 void operator delete(void *address);
f5691f9c 84
85public:
63be0a78 86 /**
87 * This is the object passed around by client_side and acl functions
88 * it has request specific data, and links to user specific data
89 * the user
90 */
c7baff40 91 User::Pointer _auth_user;
f5691f9c 92
63be0a78 93 /**
94 * Used by squid to determine what the next step in performing authentication for a given scheme is.
95 *
51a3dd58
AJ
96 * \retval CRED_ERROR ERROR in the auth module. Cannot determine request direction.
97 * \retval CRED_LOOKUP The auth module needs to send data to an external helper.
98 * Squid will prepare for a callback on the request and call the AUTHSSTART function.
99 * \retval CRED_VALID The auth module has all the information it needs to perform the authentication
100 * and provide a succeed/fail result.
101 * \retval CRED_CHALLENGE The auth module needs to send a new challenge to the request originator.
102 * Squid will return the appropriate status code (401 or 407) and call the registered
103 * FixError function to allow the auth module to insert it's challenge.
63be0a78 104 */
c7baff40 105 Direction direction();
63be0a78 106
107 /**
108 * Used by squid to determine whether the auth scheme has successfully authenticated the user request.
109 *
110 \retval true User has successfully been authenticated.
111 \retval false Timeouts on cached credentials have occurred or for any reason the credentials are not valid.
112 */
f5691f9c 113 virtual int authenticated() const = 0;
2e39494f
AJ
114
115 /**
116 * Check a auth_user pointer for validity.
117 * Does not check passwords, just data sensability. Broken or Unknown auth_types are not valid for use...
118 *
119 * \retval false User credentials are missing.
120 * \retval false User credentials use an unknown scheme type.
121 * \retval false User credentials are broken for their scheme.
122 *
123 * \retval true User credentials exist and may be able to authenticate.
124 */
125 bool valid() const;
126
69d779f8 127 virtual void authenticate(HttpRequest * request, ConnStateData * conn, http_hdr_type type) = 0;
7afc3bf2
AJ
128
129 /* template method - what needs to be done next? advertise schemes, challenge, handle error, nothing? */
c7baff40 130 virtual Direction module_direction() = 0;
7afc3bf2
AJ
131
132 /* add the [Proxy-]Authentication-Info header */
133 virtual void addAuthenticationInfoHeader(HttpReply * rep, int accel);
134
135 /* add the [Proxy-]Authentication-Info trailer */
136 virtual void addAuthenticationInfoTrailer(HttpReply * rep, int accel);
137
cc1e110a 138 virtual void releaseAuthServer();
63be0a78 139
c7baff40
AJ
140 // User credentials object this UserRequest is managing
141 virtual User::Pointer user() {return _auth_user;}
142 virtual const User::Pointer user() const {return _auth_user;}
143 virtual void user(User::Pointer aUser) {_auth_user=aUser;}
f5691f9c 144
c7baff40
AJ
145 /**
146 * Locate user credentials in one of several locations. Begin authentication if needed.
147 *
148 * Credentials may be found in one of the following locations (listed by order of preference):
149 * - the source passed as parameter aUR
150 * - cached in the HttpRequest parameter from a previous authentication of this request
151 * - cached in the ConnStateData paremeter from a previous authentication of this connection
152 * (only applies to some situations. ie NTLM, Negotiate, Kerberos auth schemes,
153 * or decrypted SSL requests from inside an authenticated CONNECT tunnel)
154 * - cached in the user credentials cache from a previous authentication of the same credentials
155 * (only applies to cacheable authentication methods, ie Basic auth)
156 * - new credentials created from HTTP headers in this request
157 *
158 * The found credentials are returned in aUR and if successfully authenticated
159 * may now be cached in one or more of the above locations.
160 *
161 * \return Some AUTH_ACL_* state
162 */
d4806c91 163 static AuthAclState tryToAuthenticateAndSetAuthUser(UserRequest::Pointer *aUR, http_hdr_type, HttpRequest *, ConnStateData *, Ip::Address &, AccessLogEntry::Pointer &);
f5691f9c 164
c7baff40
AJ
165 /// Add the appropriate [Proxy-]Authenticate header to the given reply
166 static void addReplyAuthHeader(HttpReply * rep, UserRequest::Pointer auth_user_request, HttpRequest * request, int accelerated, int internal);
f5691f9c 167
30c3f584
AJ
168 /** Start an asynchronous helper lookup to verify the user credentials
169 *
170 * Uses startHelperLookup() for scheme-specific actions.
171 *
172 * The given callback will be called when the auth module has performed
173 * it's external activities.
174 *
175 * \param handler Handler to process the callback when its run
176 * \param data CBDATA for handler
177 */
d4806c91 178 void start(HttpRequest *request, AccessLogEntry::Pointer &al, AUTHCB *handler, void *data);
30c3f584 179
e1f7507e 180 char const * denyMessage(char const * const default_message = NULL);
63be0a78 181
182 /** Possibly overrideable in future */
e1f7507e 183 void setDenyMessage(char const *);
63be0a78 184
185 /** Possibly overrideable in future */
e1f7507e 186 char const * getDenyMessage();
f5691f9c 187
63be0a78 188 /**
189 * Squid does not make assumptions about where the username is stored.
190 * This function must return a pointer to a NULL terminated string to be used in logging the request.
191 * The string should NOT be allocated each time this function is called.
192 *
193 \retval NULL No username/usercode is known.
194 \retval * Null-terminated username string.
195 */
f5691f9c 196 char const *username() const;
197
c7baff40 198 Scheme::Pointer scheme() const;
f5691f9c 199
6bf4f823 200 virtual const char * connLastHeader();
201
d4806c91
CT
202 /**
203 * The string representation of the credentials send by client
204 */
205 virtual const char *credentialsStr() = 0;
206
207 const char *helperRequestKeyExtras(HttpRequest *, AccessLogEntry::Pointer &al);
30c3f584
AJ
208
209protected:
210 /**
211 * The scheme-specific actions to be performed when sending helper lookup.
212 *
213 * \see void start(HttpRequest *, AccessLogEntry::Pointer &, AUTHCB *, void *);
214 */
215 virtual void startHelperLookup(HttpRequest *request, AccessLogEntry::Pointer &al, AUTHCB *handler, void *data) = 0;
216
f5691f9c 217private:
218
d4806c91 219 static AuthAclState authenticate(UserRequest::Pointer * auth_user_request, http_hdr_type headertype, HttpRequest * request, ConnStateData * conn, Ip::Address &src_addr, AccessLogEntry::Pointer &al);
f5691f9c 220
63be0a78 221 /** return a message on the 407 error pages */
f5691f9c 222 char *message;
223
63be0a78 224 /**
225 * We only attempt authentication once per http request. This
f5691f9c 226 * is to allow multiple auth acl references from different _access areas
227 * when using connection based authentication
228 */
56a49fda 229 AuthAclState lastReply;
f5691f9c 230};
231
c7baff40
AJ
232} // namespace Auth
233
f5691f9c 234/* AuthUserRequest */
63be0a78 235
63be0a78 236/// \ingroup AuthAPI
8a648e8d 237void authenticateFixHeader(HttpReply *, Auth::UserRequest::Pointer, HttpRequest *, int, int);
63be0a78 238/// \ingroup AuthAPI
8a648e8d 239void authenticateAddTrailer(HttpReply *, Auth::UserRequest::Pointer, HttpRequest *, int);
f5691f9c 240
63be0a78 241/// \ingroup AuthAPI
8a648e8d 242void authenticateAuthUserRequestRemoveIp(Auth::UserRequest::Pointer, Ip::Address const &);
63be0a78 243/// \ingroup AuthAPI
8a648e8d 244void authenticateAuthUserRequestClearIp(Auth::UserRequest::Pointer);
63be0a78 245/// \ingroup AuthAPI
8a648e8d 246int authenticateAuthUserRequestIPCount(Auth::UserRequest::Pointer);
f5691f9c 247
63be0a78 248/// \ingroup AuthAPI
c7baff40 249/// See Auth::UserRequest::authenticated()
8a648e8d 250int authenticateUserAuthenticated(Auth::UserRequest::Pointer);
4f0ef8e8 251
2f1431ea 252#endif /* USE_AUTH */
f5691f9c 253#endif /* SQUID_AUTHUSERREQUEST_H */