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