2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
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.
10 #include "acl/FilledChecklist.h"
11 #include "client_side.h"
12 #include "comm/Connection.h"
13 #include "comm/forward.h"
14 #include "ExternalACLEntry.h"
15 #include "http/Stream.h"
16 #include "HttpReply.h"
17 #include "HttpRequest.h"
18 #include "SquidConfig.h"
20 #include "auth/AclProxyAuth.h"
21 #include "auth/UserRequest.h"
24 CBDATA_CLASS_INIT(ACLFilledChecklist
);
26 ACLFilledChecklist::ACLFilledChecklist() :
31 auth_user_request (NULL
),
39 requestErrorType(ERR_MAX
),
42 destinationDomainChecked_(false),
43 sourceDomainChecked_(false)
51 ACLFilledChecklist::~ACLFilledChecklist()
53 assert (!asyncInProgress());
55 safe_free(dst_rdns
); // created by xstrdup().
57 HTTPMSGUNLOCK(request
);
61 cbdataReferenceDone(conn_
);
64 cbdataReferenceDone(sslErrors
);
67 debugs(28, 4, HERE
<< "ACLFilledChecklist destroyed " << this);
71 showDebugWarning(const char *msg
)
73 static uint16_t count
= 0;
78 debugs(28, DBG_IMPORTANT
, "ALE missing " << msg
);
82 ACLFilledChecklist::verifyAle() const
84 // make sure the ALE fields used by Format::assemble to
85 // fill the old external_acl_type codes are set if any
86 // data on them exists in the Checklist
88 if (!al
->cache
.port
&& conn()) {
89 showDebugWarning("listening port");
90 al
->cache
.port
= conn()->port
;
95 showDebugWarning("HttpRequest object");
96 // XXX: al->request should be original,
97 // but the request may be already adapted
98 al
->request
= request
;
99 HTTPMSGLOCK(al
->request
);
102 if (!al
->adapted_request
) {
103 showDebugWarning("adapted HttpRequest object");
104 al
->adapted_request
= request
;
105 HTTPMSGLOCK(al
->adapted_request
);
108 if (al
->url
.isEmpty()) {
109 showDebugWarning("URL");
110 // XXX: al->url should be the request URL from client,
111 // but request->url may be different (e.g.,redirected)
112 al
->url
= request
->effectiveRequestUri();
116 if (reply
&& !al
->reply
) {
117 showDebugWarning("HttpReply object");
122 if (*rfc931
&& !al
->cache
.rfc931
) {
123 showDebugWarning("IDENT");
124 al
->cache
.rfc931
= xstrdup(rfc931
);
130 ACLFilledChecklist::syncAle(HttpRequest
*adaptedRequest
, const char *logUri
) const
134 if (adaptedRequest
&& !al
->adapted_request
) {
135 al
->adapted_request
= adaptedRequest
;
136 HTTPMSGLOCK(al
->adapted_request
);
138 if (logUri
&& al
->url
.isEmpty())
143 ACLFilledChecklist::conn() const
145 return cbdataReferenceValid(conn_
) ? conn_
: nullptr;
149 ACLFilledChecklist::conn(ConnStateData
*aConn
)
153 assert (conn() == NULL
);
154 conn_
= cbdataReference(aConn
);
158 ACLFilledChecklist::fd() const
160 const auto c
= conn();
161 return (c
&& c
->clientConnection
) ? c
->clientConnection
->fd
: fd_
;
165 ACLFilledChecklist::fd(int aDescriptor
)
167 const auto c
= conn();
168 assert(!c
|| !c
->clientConnection
|| c
->clientConnection
->fd
== aDescriptor
);
173 ACLFilledChecklist::destinationDomainChecked() const
175 return destinationDomainChecked_
;
179 ACLFilledChecklist::markDestinationDomainChecked()
181 assert (!finished() && !destinationDomainChecked());
182 destinationDomainChecked_
= true;
186 ACLFilledChecklist::sourceDomainChecked() const
188 return sourceDomainChecked_
;
192 ACLFilledChecklist::markSourceDomainChecked()
194 assert (!finished() && !sourceDomainChecked());
195 sourceDomainChecked_
= true;
199 * There are two common ACLFilledChecklist lifecycles paths:
201 * A) Using aclCheckFast(): The caller creates an ACLFilledChecklist object
202 * on stack and calls aclCheckFast().
204 * B) Using aclNBCheck() and callbacks: The caller allocates an
205 * ACLFilledChecklist object (via operator new) and passes it to
206 * aclNBCheck(). Control eventually passes to ACLChecklist::checkCallback(),
207 * which will invoke the callback function as requested by the
208 * original caller of aclNBCheck(). This callback function must
209 * *not* delete the list. After the callback function returns,
210 * checkCallback() will delete the list (i.e., self).
212 ACLFilledChecklist::ACLFilledChecklist(const acl_access
*A
, HttpRequest
*http_request
, const char *ident
):
217 auth_user_request(NULL
),
220 snmp_community(NULL
),
225 requestErrorType(ERR_MAX
),
228 destinationDomainChecked_(false),
229 sourceDomainChecked_(false)
237 setRequest(http_request
);
241 void ACLFilledChecklist::setRequest(HttpRequest
*httpRequest
)
245 request
= httpRequest
;
246 HTTPMSGLOCK(request
);
247 #if FOLLOW_X_FORWARDED_FOR
248 if (Config
.onoff
.acl_uses_indirect_client
)
249 src_addr
= request
->indirect_client_addr
;
251 #endif /* FOLLOW_X_FORWARDED_FOR */
252 src_addr
= request
->client_addr
;
253 my_addr
= request
->my_addr
;
255 if (request
->clientConnectionManager
.valid())
256 conn(request
->clientConnectionManager
.get());
261 ACLFilledChecklist::setIdent(const char *ident
)
266 xstrncpy(rfc931
, ident
, USER_IDENT_SZ
);