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 request (nullptr),
30 reply (nullptr),
31#if USE_AUTH
32 auth_user_request (nullptr),
33#endif
34#if SQUID_SNMP
35 snmp_community(nullptr),
36#endif
37 requestErrorType(ERR_MAX),
38 conn_(nullptr),
39 fd_(-1),
40 destinationDomainChecked_(false),
41 sourceDomainChecked_(false)
42{
46 rfc931[0] = '\0';
47}
48
50{
52
53 safe_free(dst_rdns); // created by xstrdup().
54
56
58
60
61 debugs(28, 4, "ACLFilledChecklist destroyed " << this);
62}
63
64static void
65showDebugWarning(const char *msg)
66{
67 static uint16_t count = 0;
68 if (count > 10)
69 return;
70
71 ++count;
72 debugs(28, Important(58), "ERROR: ALE missing " << msg);
73}
74
75void
77{
78 // make sure the ALE fields used by Format::assemble to
79 // fill the old external_acl_type codes are set if any
80 // data on them exists in the Checklist
81
82 if (!al->cache.port && conn()) {
83 showDebugWarning("listening port");
84 al->cache.port = conn()->port;
85 }
86
87 if (request) {
88 if (!al->request) {
89 showDebugWarning("HttpRequest object");
90 // XXX: al->request should be original,
91 // but the request may be already adapted
94 }
95
96 if (!al->adapted_request) {
97 showDebugWarning("adapted HttpRequest object");
100 }
101
102 if (al->url.isEmpty()) {
103 showDebugWarning("URL");
104 // XXX: al->url should be the request URL from client,
105 // but request->url may be different (e.g.,redirected)
107 }
108 }
109
110 if (reply && !al->reply) {
111 showDebugWarning("HttpReply object");
112 al->reply = reply;
113 }
114
115#if USE_IDENT
116 if (*rfc931 && !al->cache.rfc931) {
117 showDebugWarning("IDENT");
119 }
120#endif
121}
122
123void
124ACLFilledChecklist::syncAle(HttpRequest *adaptedRequest, const char *logUri) const
125{
126 if (!al)
127 return;
128 if (adaptedRequest && !al->adapted_request) {
129 al->adapted_request = adaptedRequest;
131 }
132 if (logUri && al->url.isEmpty())
133 al->url = logUri;
134}
135
138{
139 return cbdataReferenceValid(conn_) ? conn_ : nullptr;
140}
141
142void
144{
145 if (conn_ == aConn)
146 return; // no new information
147
148 // no conn_ replacement/removal to reduce inconsistent fill concerns
149 assert(!conn_);
150 assert(aConn);
151
152 // To reduce inconsistent fill concerns, we should be the only ones calling
153 // fillConnectionLevelDetails(). Set conn_ first so that the filling method
154 // can detect (some) direct calls from others.
155 conn_ = cbdataReference(aConn);
156 aConn->fillConnectionLevelDetails(*this);
157}
158
159int
161{
162 const auto c = conn();
163 return (c && c->clientConnection) ? c->clientConnection->fd : fd_;
164}
165
166void
168{
169 const auto c = conn();
170 assert(!c || !c->clientConnection || c->clientConnection->fd == aDescriptor);
171 fd_ = aDescriptor;
172}
173
174bool
176{
178}
179
180void
182{
185}
186
187bool
189{
191}
192
193void
195{
198}
199
200/*
201 * There are two common ACLFilledChecklist lifecycles paths:
202 *
203 * A) Using aclCheckFast(): The caller creates an ACLFilledChecklist object
204 * on stack and calls aclCheckFast().
205 *
206 * B) Using aclNBCheck() and callbacks: The caller allocates an
207 * ACLFilledChecklist object (via operator new) and passes it to
208 * aclNBCheck(). Control eventually passes to ACLChecklist::checkCallback(),
209 * which will invoke the callback function as requested by the
210 * original caller of aclNBCheck(). This callback function must
211 * *not* delete the list. After the callback function returns,
212 * checkCallback() will delete the list (i.e., self).
213 */
214ACLFilledChecklist::ACLFilledChecklist(const acl_access *A, HttpRequest *http_request, const char *ident):
215 dst_rdns(nullptr),
216 request(nullptr),
217 reply(nullptr),
218#if USE_AUTH
219 auth_user_request(nullptr),
220#endif
221#if SQUID_SNMP
222 snmp_community(nullptr),
223#endif
224 requestErrorType(ERR_MAX),
225 conn_(nullptr),
226 fd_(-1),
227 destinationDomainChecked_(false),
228 sourceDomainChecked_(false)
229{
233 rfc931[0] = '\0';
234
235 changeAcl(A);
236 setRequest(http_request);
237 setIdent(ident);
238}
239
241{
242 assert(!request);
243 if (httpRequest) {
244 request = httpRequest;
246#if FOLLOW_X_FORWARDED_FOR
249 else
250#endif /* FOLLOW_X_FORWARDED_FOR */
253
254 if (const auto cmgr = request->clientConnectionManager.get())
255 setConn(cmgr);
256 }
257}
258
259void
261{
262#if USE_IDENT
263 assert(!rfc931[0]);
264 if (ident)
266#else
267 (void)ident;
268#endif
269}
270
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_
HttpRequest * request
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
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
bool isEmpty() const
Definition: SBuf.h:431
int acl_uses_indirect_client
Definition: SquidConfig.h:325
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