Squid Web Cache master
Loading...
Searching...
No Matches
AclProxyAuth.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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
29ACLProxyAuth::ACLProxyAuth(ACLData<char const *> *newData, char const *theType) :
30 data(newData),
31 type_(theType)
32{}
33
34char const *
36{
37 return type_;
38}
39
40const Acl::Options &
45
46void
51
52int
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
83bool
85{
86 return data->empty();
87}
88
89bool
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
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
105void
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);
114}
115
116void
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
135int
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 */
147int
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
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
bool authenticateUserAuthenticated(const Auth::UserRequest::Pointer &auth_user_request)
#define assert(EX)
Definition assert.h:17
Acl::Answer AuthenticateAcl(ACLChecklist *ch, const Acl::Node &acl)
Definition Acl.cc:28
int authenticateActiveSchemeCount(void)
Definition Gadgets.cc:38
int authenticateSchemeCount(void)
Definition Gadgets.cc:53
void markFinished(const Acl::Answer &newAnswer, const char *reason)
Definition Checklist.cc:45
void resumeNonBlockingCheck()
Definition Checklist.cc:230
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition Checklist.h:96
Configured ACL parameter(s) (e.g., domain names in dstdomain ACL).
Definition Data.h:18
virtual void parse()=0
virtual SBufList dump() const =0
virtual bool match(M)=0
virtual bool empty() const =0
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
Definition Data.h:26
ConnStateData * conn() const
The client connection manager.
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
Auth::UserRequest::Pointer auth_user_request
HttpRequest::Pointer request
SBufList dump() const override
int matchProxyAuth(ACLChecklist *)
void parse() override
parses node representation in squid.conf; dies on failures
const Acl::Options & lineOptions() override
ACLProxyAuth(ACLData< char const * > *, char const *)
static void StartLookup(ACLFilledChecklist &, const Acl::Node &)
ACLData< char const * > * data
char const * type_
static void LookupDone(void *data)
~ACLProxyAuth() override
bool valid() const override
char const * typeString() const override
int matchForCache(ACLChecklist *checklist) override
bool empty() const override
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this Acl::Node.
int cacheMatchAcl(dlink_list *cache, ACLChecklist *)
Definition Acl.cc:401
bool valid() const
void start(HttpRequest *request, AccessLogEntry::Pointer &al, AUTHCB *handler, void *data)
char const * username() const
virtual User::Pointer user()
void setAuth(const Auth::UserRequest::Pointer &aur, const char *cause)
RequestFlags flags
C * getRaw() const
Definition RefCount.h:89
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
@ ACCESS_AUTH_REQUIRED
Definition Acl.h:46
@ ACCESS_DENIED
Definition Acl.h:41
@ ACCESS_ALLOWED
Definition Acl.h:42
@ ACCESS_DUNNO
Definition Acl.h:43
std::vector< const Option * > Options
Definition Options.h:217
std::list< SBuf > SBufList
Definition forward.h:23