]> git.ipfire.org Git - thirdparty/squid.git/blob - src/auth/Acl.cc
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / auth / Acl.cc
1 /*
2 * Copyright (C) 1996-2014 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 "acl/Acl.h"
11 #include "acl/FilledChecklist.h"
12 #include "auth/Acl.h"
13 #include "auth/AclProxyAuth.h"
14 #include "auth/UserRequest.h"
15 #include "client_side.h"
16 #include "HttpRequest.h"
17
18 /**
19 * \retval ACCESS_AUTH_REQUIRED credentials missing. challenge required.
20 * \retval ACCESS_DENIED user not authenticated (authentication error?)
21 * \retval ACCESS_DUNNO user authentication is in progress
22 * \retval ACCESS_DENIED user not authorized
23 * \retval ACCESS_ALLOWED user authenticated and authorized
24 */
25 allow_t
26 AuthenticateAcl(ACLChecklist *ch)
27 {
28 ACLFilledChecklist *checklist = Filled(ch);
29 HttpRequest *request = checklist->request;
30 http_hdr_type headertype;
31
32 if (NULL == request) {
33 fatal ("requiresRequest SHOULD have been true for this ACL!!");
34 return ACCESS_DENIED;
35 } else if (request->flags.sslBumped) {
36 debugs(28, 5, "SslBumped request: It is an encapsulated request do not authenticate");
37 checklist->auth_user_request = checklist->conn() != NULL ? checklist->conn()->getAuth() : request->auth_user_request;
38 if (checklist->auth_user_request != NULL)
39 return ACCESS_ALLOWED;
40 else
41 return ACCESS_DENIED;
42 } else if (request->flags.accelerated) {
43 /* WWW authorization on accelerated requests */
44 headertype = HDR_AUTHORIZATION;
45 } else if (request->flags.intercepted || request->flags.interceptTproxy) {
46 debugs(28, DBG_IMPORTANT, "NOTICE: Authentication not applicable on intercepted requests.");
47 return ACCESS_DENIED;
48 } else {
49 /* Proxy authorization on proxy requests */
50 headertype = HDR_PROXY_AUTHORIZATION;
51 }
52
53 /* get authed here */
54 /* Note: this fills in auth_user_request when applicable */
55 const AuthAclState result = Auth::UserRequest::tryToAuthenticateAndSetAuthUser(
56 &checklist->auth_user_request, headertype, request,
57 checklist->conn(), checklist->src_addr, checklist->al);
58 switch (result) {
59
60 case AUTH_ACL_CANNOT_AUTHENTICATE:
61 debugs(28, 4, HERE << "returning " << ACCESS_DENIED << " user authenticated but not authorised.");
62 return ACCESS_DENIED;
63
64 case AUTH_AUTHENTICATED:
65 return ACCESS_ALLOWED;
66 break;
67
68 case AUTH_ACL_HELPER:
69 if (checklist->goAsync(ProxyAuthLookup::Instance()))
70 debugs(28, 4, "returning " << ACCESS_DUNNO << " sending credentials to helper.");
71 else
72 debugs(28, 2, "cannot go async; returning " << ACCESS_DUNNO);
73 return ACCESS_DUNNO; // XXX: break this down into DUNNO, EXPIRED_OK, EXPIRED_BAD states
74
75 case AUTH_ACL_CHALLENGE:
76 debugs(28, 4, HERE << "returning " << ACCESS_AUTH_REQUIRED << " sending authentication challenge.");
77 /* Client is required to resend the request with correct authentication
78 * credentials. (This may be part of a stateful auth protocol.)
79 * The request is denied.
80 */
81 return ACCESS_AUTH_REQUIRED;
82
83 default:
84 fatal("unexpected authenticateAuthenticate reply\n");
85 return ACCESS_DENIED;
86 }
87 }