FilledChecklist.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#include "squid.h"
10#include "acl/FilledChecklist.h"
11#include "client_side.h"
12#include "comm/Connection.h"
13#include "comm/forward.h"
14#include "debug/Messages.h"
15#include "ExternalACLEntry.h"
16#include "http/Stream.h"
17#include "HttpReply.h"
18#include "HttpRequest.h"
19#include "SquidConfig.h"
20#if USE_AUTH
21#include "auth/AclProxyAuth.h"
22#include "auth/UserRequest.h"
23#endif
24
26
28 dst_rdns(nullptr),
29 reply (nullptr),
30#if USE_AUTH
31 auth_user_request (nullptr),
32#endif
33#if SQUID_SNMP
34 snmp_community(nullptr),
35#endif
36 requestErrorType(ERR_MAX),
37 conn_(nullptr),
38 fd_(-1),
39 destinationDomainChecked_(false),
40 sourceDomainChecked_(false)
41{
45 rfc931[0] = '\0';
46}
47
49{
51
52 safe_free(dst_rdns); // created by xstrdup().
53
55
57
58 debugs(28, 4, "ACLFilledChecklist destroyed " << this);
59}
60
61static void
62showDebugWarning(const char *msg)
63{
64 static uint16_t count = 0;
65 if (count > 10)
66 return;
67
68 ++count;
69 debugs(28, Important(58), "ERROR: ALE missing " << msg);
70}
71
72void
74{
75 // make sure the ALE fields used by Format::assemble to
76 // fill the old external_acl_type codes are set if any
77 // data on them exists in the Checklist
78
79 if (!al->cache.port && conn()) {
80 showDebugWarning("listening port");
81 al->cache.port = conn()->port;
82 }
83
84 if (request) {
85 if (!al->request) {
86 showDebugWarning("HttpRequest object");
87 // XXX: al->request should be original,
88 // but the request may be already adapted
91 }
92
93 if (!al->adapted_request) {
94 showDebugWarning("adapted HttpRequest object");
97 }
98
99 if (al->url.isEmpty()) {
100 showDebugWarning("URL");
101 // XXX: al->url should be the request URL from client,
102 // but request->url may be different (e.g.,redirected)
104 }
105 }
106
107 if (reply && !al->reply) {
108 showDebugWarning("HttpReply object");
109 al->reply = reply;
110 }
111
112#if USE_IDENT
113 if (*rfc931 && !al->cache.rfc931) {
114 showDebugWarning("IDENT");
116 }
117#endif
118}
119
120void
121ACLFilledChecklist::syncAle(HttpRequest *adaptedRequest, const char *logUri) const
122{
123 if (!al)
124 return;
125 if (adaptedRequest && !al->adapted_request) {
126 al->adapted_request = adaptedRequest;
128 }
129 if (logUri && al->url.isEmpty())
130 al->url = logUri;
131}
132
135{
136 return cbdataReferenceValid(conn_) ? conn_ : nullptr;
137}
138
139void
141{
142 if (conn_ == aConn)
143 return; // no new information
144
145 // no conn_ replacement/removal to reduce inconsistent fill concerns
146 assert(!conn_);
147 assert(aConn);
148
149 // To reduce inconsistent fill concerns, we should be the only ones calling
150 // fillConnectionLevelDetails(). Set conn_ first so that the filling method
151 // can detect (some) direct calls from others.
152 conn_ = cbdataReference(aConn);
153 aConn->fillConnectionLevelDetails(*this);
154}
155
156int
158{
159 const auto c = conn();
160 return (c && c->clientConnection) ? c->clientConnection->fd : fd_;
161}
162
163void
165{
166 const auto c = conn();
167 assert(!c || !c->clientConnection || c->clientConnection->fd == aDescriptor);
168 fd_ = aDescriptor;
169}
170
171bool
173{
175}
176
177void
179{
182}
183
184bool
186{
188}
189
190void
192{
195}
196
197/*
198 * There are two common ACLFilledChecklist lifecycles paths:
199 *
200 * A) Using aclCheckFast(): The caller creates an ACLFilledChecklist object
201 * on stack and calls aclCheckFast().
202 *
203 * B) Using aclNBCheck() and callbacks: The caller allocates an
204 * ACLFilledChecklist object (via operator new) and passes it to
205 * aclNBCheck(). Control eventually passes to ACLChecklist::checkCallback(),
206 * which will invoke the callback function as requested by the
207 * original caller of aclNBCheck(). This callback function must
208 * *not* delete the list. After the callback function returns,
209 * checkCallback() will delete the list (i.e., self).
210 */
211ACLFilledChecklist::ACLFilledChecklist(const acl_access *A, HttpRequest *http_request, const char *ident):
212 dst_rdns(nullptr),
213 reply(nullptr),
214#if USE_AUTH
215 auth_user_request(nullptr),
216#endif
217#if SQUID_SNMP
218 snmp_community(nullptr),
219#endif
220 requestErrorType(ERR_MAX),
221 conn_(nullptr),
222 fd_(-1),
223 destinationDomainChecked_(false),
224 sourceDomainChecked_(false)
225{
229 rfc931[0] = '\0';
230
231 changeAcl(A);
232 setRequest(http_request);
233 setIdent(ident);
234}
235
237{
238 assert(!request);
239 if (httpRequest) {
240 request = httpRequest;
241#if FOLLOW_X_FORWARDED_FOR
244 else
245#endif /* FOLLOW_X_FORWARDED_FOR */
248
249 if (const auto cmgr = request->clientConnectionManager.get())
250 setConn(cmgr);
251 }
252}
253
254void
256{
257#if USE_IDENT
258 assert(!rfc931[0]);
259 if (ident)
261#else
262 (void)ident;
263#endif
264}
265
static void showDebugWarning(const char *msg)
CBDATA_CLASS_INIT(ACLFilledChecklist)
class SquidConfig Config
Definition: SquidConfig.cc:12
#define acl_access
Definition: forward.h:45
#define assert(EX)
Definition: assert.h:17
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:265
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
const Acl::Tree * changeAcl(const Acl::Tree *t)
Definition: Checklist.h:176
bool finished() const
whether markFinished() was called
Definition: Checklist.h:149
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:151
bool destinationDomainChecked() const
void setIdent(const char *userIdentity)
configure rfc931 user identity for the first time
ConnStateData * conn_
ConnStateData * conn() const
The client connection manager.
Ip::Address dst_addr
void setRequest(HttpRequest *)
configure client request-related fields for the first time
~ACLFilledChecklist() override
void setConn(ConnStateData *)
set either conn
int fd() const
The client side fd. It uses conn() if available.
char rfc931[USER_IDENT_SZ]
Ip::Address src_addr
void verifyAle() const override
warns if there are uninitialized ALE components and fills them
void markDestinationDomainChecked()
bool sourceDomainChecked() const
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
HttpRequest::Pointer request
AnyP::PortCfgPointer port
HttpReplyPointer reply
class AccessLogEntry::CacheDetails cache
HttpRequest * adapted_request
HttpRequest * request
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
Definition: CbcPointer.h:159
AnyP::Port port
destination port of the request that caused serverConnection
Definition: client_side.h:145
void fillConnectionLevelDetails(ACLFilledChecklist &) const
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
Ip::Address my_addr
Definition: HttpRequest.h:155
Ip::Address client_addr
Definition: HttpRequest.h:149
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:744
void setEmpty()
Fast reset of the stored content to what would be after default constructor.
Definition: Address.cc:184
C * getRaw() const
Definition: RefCount.h:89
bool isEmpty() const
Definition: SBuf.h:431
int acl_uses_indirect_client
Definition: SquidConfig.h:326
struct SquidConfig::@106 onoff
#define Important(id)
Definition: Messages.h:93
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define USER_IDENT_SZ
Definition: defines.h:37
@ ERR_MAX
Definition: forward.h:88
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:150
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
static uint32 A
Definition: md4.c:43
#define xstrdup
#define safe_free(x)
Definition: xalloc.h:73
char * xstrncpy(char *dst, const char *src, size_t n)
Definition: xstring.cc:37

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors