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