AclProxyAuth.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 /* DEBUG: section 28 Access Control */
10 
11 #include "squid.h"
12 #include "acl/FilledChecklist.h"
13 #include "acl/RegexData.h"
14 #include "acl/UserData.h"
15 #include "auth/Acl.h"
16 #include "auth/AclProxyAuth.h"
17 #include "auth/Gadgets.h"
18 #include "auth/User.h"
19 #include "auth/UserRequest.h"
20 #include "client_side.h"
21 #include "http/Stream.h"
22 #include "HttpRequest.h"
23 
25 {
26  delete data;
27 }
28 
29 ACLProxyAuth::ACLProxyAuth(ACLData<char const *> *newData, char const *theType) :
30  data(newData),
31  type_(theType)
32 {}
33 
34 char const *
36 {
37  return type_;
38 }
39 
40 const Acl::Options &
42 {
43  return data->lineOptions();
44 }
45 
46 void
48 {
49  data->parse();
50 }
51 
52 int
54 {
55  auto answer = AuthenticateAcl(checklist, *this);
56 
57  // convert to tri-state ACL match 1,0,-1
58  switch (answer) {
59  case ACCESS_ALLOWED:
60  // check for a match
61  return matchProxyAuth(checklist);
62 
63  case ACCESS_DENIED:
64  return 0; // non-match
65 
66  case ACCESS_DUNNO:
68  default:
69  // If the answer is not allowed or denied (matches/not matches) and
70  // async authentication is not in progress, then we are done.
71  if (checklist->keepMatching())
72  checklist->markFinished(answer, "AuthenticateAcl exception");
73  return -1; // other
74  }
75 }
76 
79 {
80  return data->dump();
81 }
82 
83 bool
85 {
86  return data->empty();
87 }
88 
89 bool
91 {
92  if (authenticateSchemeCount() == 0) {
93  debugs(28, DBG_CRITICAL, "ERROR: Cannot use proxy auth because no authentication schemes were compiled.");
94  return false;
95  }
96 
97  if (authenticateActiveSchemeCount() == 0) {
98  debugs(28, DBG_CRITICAL, "ERROR: Cannot use proxy auth because no authentication schemes are fully configured.");
99  return false;
100  }
101 
102  return true;
103 }
104 
105 void
107 {
108  debugs(28, 3, "checking password via authenticator");
109 
110  /* make sure someone created auth_user_request for us */
111  assert(cl.auth_user_request != nullptr);
113  cl.auth_user_request->start(cl.request.getRaw(), cl.al, LookupDone, &cl);
114 }
115 
116 void
118 {
119  ACLFilledChecklist *checklist = Filled(static_cast<ACLChecklist*>(data));
120 
121  if (checklist->auth_user_request == nullptr || !checklist->auth_user_request->valid() || checklist->conn() == nullptr) {
122  /* credentials could not be checked either way
123  * restart the whole process */
124  /* OR the connection was closed, there's no way to continue */
125  checklist->auth_user_request = nullptr;
126 
127  if (checklist->conn() != nullptr) {
128  checklist->conn()->setAuth(nullptr, "proxy_auth ACL failure");
129  }
130  }
131 
132  checklist->resumeNonBlockingCheck();
133 }
134 
135 int
137 {
138  ACLFilledChecklist *checklist = Filled(cl);
139  assert (checklist->auth_user_request != nullptr);
140  return data->match(checklist->auth_user_request->username());
141 }
142 
143 /* aclMatchProxyAuth can return two exit codes:
144  * 0 : Authorisation for this ACL failed. (Did not match)
145  * 1 : Authorisation OK. (Matched)
146  */
147 int
149 {
150  ACLFilledChecklist *checklist = Filled(cl);
151  if (!checklist->request->flags.sslBumped) {
153  return 0;
154  }
155  }
156  /* check to see if we have matched the user-acl before */
157  int result = cacheMatchAcl(&checklist->auth_user_request->user()->proxy_match_cache, checklist);
158  checklist->auth_user_request = nullptr;
159  return result;
160 }
161 
static void StartLookup(ACLFilledChecklist &, const Acl::Node &)
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
Definition: Data.h:26
#define DBG_CRITICAL
Definition: Stream.h:37
static void LookupDone(void *data)
const char * typeString() const override
Definition: AclProxyAuth.cc:35
std::vector< const Option * > Options
Definition: Options.h:217
void setAuth(const Auth::UserRequest::Pointer &aur, const char *cause)
Definition: client_side.cc:494
RequestFlags flags
Definition: HttpRequest.h:141
std::list< SBuf > SBufList
Definition: forward.h:22
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition: Checklist.h:96
const Acl::Options & lineOptions() override
Definition: AclProxyAuth.cc:41
C * getRaw() const
Definition: RefCount.h:89
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
virtual User::Pointer user()
Definition: UserRequest.h:143
bool valid() const override
Definition: AclProxyAuth.cc:90
int matchProxyAuth(ACLChecklist *)
ConnStateData * conn() const
The client connection manager.
@ ACCESS_AUTH_REQUIRED
Definition: Acl.h:46
bool valid() const
Definition: UserRequest.cc:53
ACLData< char const * > * data
Definition: AclProxyAuth.h:46
const char * username() const
Definition: UserRequest.cc:32
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
const char * type_
Definition: AclProxyAuth.h:47
HttpRequest::Pointer request
void markFinished(const Acl::Answer &newAnswer, const char *reason)
Definition: Checklist.cc:45
#define assert(EX)
Definition: assert.h:17
bool authenticateUserAuthenticated(const Auth::UserRequest::Pointer &auth_user_request)
Definition: UserRequest.cc:189
void start(HttpRequest *request, AccessLogEntry::Pointer &al, AUTHCB *handler, void *data)
Definition: UserRequest.cc:44
Acl::Answer AuthenticateAcl(ACLChecklist *ch, const Acl::Node &acl)
Definition: Acl.cc:28
SBufList dump() const override
Definition: AclProxyAuth.cc:78
virtual void parse()=0
ACLProxyAuth(ACLData< char const * > *, char const *)
Definition: AclProxyAuth.cc:29
int authenticateSchemeCount(void)
Definition: Gadgets.cc:53
~ACLProxyAuth() override
Definition: AclProxyAuth.cc:24
Definition: Node.h:25
int cacheMatchAcl(dlink_list *cache, ACLChecklist *)
Definition: Acl.cc:401
int authenticateActiveSchemeCount(void)
Definition: Gadgets.cc:38
@ ACCESS_ALLOWED
Definition: Acl.h:42
@ ACCESS_DENIED
Definition: Acl.h:41
virtual bool match(M)=0
@ ACCESS_DUNNO
Definition: Acl.h:43
int matchForCache(ACLChecklist *checklist) override
virtual bool empty() const =0
bool empty() const override
Definition: AclProxyAuth.cc:84
Auth::UserRequest::Pointer auth_user_request
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this Acl::Node.
Definition: AclProxyAuth.cc:53
void parse() override
parses node representation in squid.conf; dies on failures
Definition: AclProxyAuth.cc:47
void resumeNonBlockingCheck()
Definition: Checklist.cc:230
virtual SBufList dump() const =0

 

Introduction

Documentation

Support

Miscellaneous