]> git.ipfire.org Git - thirdparty/squid.git/blame - src/external_acl.cc
Remove AclMatchedName from ACL::ParseAclLine() (#1642)
[thirdparty/squid.git] / src / external_acl.cc
CommitLineData
d9572179 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
d9572179 3 *
bbc27441
AJ
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.
d9572179 7 */
8
bbc27441
AJ
9/* DEBUG: section 82 External ACL */
10
582c2af2 11#include "squid.h"
c0941a6a 12#include "acl/Acl.h"
582c2af2 13#include "acl/FilledChecklist.h"
8a01b99e 14#include "cache_cf.h"
a46d2c0e 15#include "client_side.h"
4e56d7f6 16#include "client_side_request.h"
5c336a3b 17#include "comm/Connection.h"
2eceb328 18#include "ConfigParser.h"
582c2af2 19#include "ExternalACL.h"
f9b6ff6e 20#include "ExternalACLEntry.h"
582c2af2 21#include "fde.h"
4e56d7f6 22#include "format/Token.h"
aa839030 23#include "helper.h"
24438ec5 24#include "helper/Reply.h"
d3dddfb5 25#include "http/Stream.h"
a5bac1d2 26#include "HttpHeaderTools.h"
582c2af2
FC
27#include "HttpReply.h"
28#include "HttpRequest.h"
29#include "ip/tools.h"
0eb49b6d 30#include "MemBuf.h"
582c2af2 31#include "mgr/Registration.h"
1fa9b1a7 32#include "rfc1738.h"
4d5904f7 33#include "SquidConfig.h"
f9b6ff6e 34#include "SquidString.h"
582c2af2 35#include "Store.h"
4e540555 36#include "tools.h"
d295d770 37#include "wordlist.h"
cb4f4424 38#if USE_OPENSSL
cedca6e7 39#include "ssl/ServerBump.h"
4db984be
CT
40#include "ssl/support.h"
41#endif
582c2af2
FC
42#if USE_AUTH
43#include "auth/Acl.h"
44#include "auth/Gadgets.h"
45#include "auth/UserRequest.h"
46#endif
47#if USE_IDENT
48#include "ident/AclIdent.h"
49#endif
d9572179 50
51#ifndef DEFAULT_EXTERNAL_ACL_TTL
52#define DEFAULT_EXTERNAL_ACL_TTL 1 * 60 * 60
53#endif
d4f2f353 54#ifndef DEFAULT_EXTERNAL_ACL_CHILDREN
55#define DEFAULT_EXTERNAL_ACL_CHILDREN 5
d9572179 56#endif
57
abdd93d0
AJ
58static void external_acl_cache_delete(external_acl * def, const ExternalACLEntryPointer &entry);
59static int external_acl_entry_expired(external_acl * def, const ExternalACLEntryPointer &entry);
60static int external_acl_grace_expired(external_acl * def, const ExternalACLEntryPointer &entry);
61static void external_acl_cache_touch(external_acl * def, const ExternalACLEntryPointer &entry);
62static ExternalACLEntryPointer external_acl_cache_add(external_acl * def, const char *key, ExternalACLEntryData const &data);
d9572179 63
64/******************************************************************
65 * external_acl directive
66 */
62e76326 67
1e5562e3 68class external_acl
62e76326 69{
9837567d 70 /* XXX: These are not really cbdata, but it is an easy way
f205a92e 71 * to get them pooled, refcounted, accounted and freed properly...
9837567d 72 * Use RefCountable MEMPROXY_CLASS instead
f205a92e 73 */
f963b531 74 CBDATA_CLASS(external_acl);
1e5562e3 75
76public:
f963b531
AJ
77 external_acl();
78 ~external_acl();
79
d9572179 80 external_acl *next;
1e5562e3 81
abdd93d0 82 void add(const ExternalACLEntryPointer &);
1e5562e3 83
84 void trimCache();
85
329c128c 86 bool maybeCacheable(const Acl::Answer &) const;
194ccc9c 87
d9572179 88 int ttl;
1e5562e3 89
d9572179 90 int negative_ttl;
1e5562e3 91
47b0c1fa 92 int grace;
93
d9572179 94 char *name;
1e5562e3 95
4e56d7f6 96 Format::Format format;
1e5562e3 97
d9572179 98 wordlist *cmdline;
1e5562e3 99
76d9b994 100 Helper::ChildConfig children;
07eca7e0 101
e05a9d51 102 Helper::Client::Pointer theHelper;
1e5562e3 103
d9572179 104 hash_table *cache;
1e5562e3 105
d9572179 106 dlink_list lru_list;
1e5562e3 107
d9572179 108 int cache_size;
1e5562e3 109
d9572179 110 int cache_entries;
1e5562e3 111
d9572179 112 dlink_list queue;
1e5562e3 113
2f1431ea 114#if USE_AUTH
3265364b
AJ
115 /**
116 * Configuration flag. May only be altered by the configuration parser.
117 *
118 * Indicates that all uses of this external_acl_type helper require authentication
119 * details to be processed. If none are available its a fail match.
120 */
e870b1f8 121 bool require_auth;
2f1431ea 122#endif
dc1af3cf 123
95d78f10 124 Format::Quoting quote; // default quoting to use, set by protocol= parameter
cc192b50 125
b7ac5457 126 Ip::Address local_addr;
d9572179 127};
128
f963b531
AJ
129CBDATA_CLASS_INIT(external_acl);
130
131external_acl::external_acl() :
aee3523a 132 next(nullptr),
f963b531
AJ
133 ttl(DEFAULT_EXTERNAL_ACL_TTL),
134 negative_ttl(-1),
135 grace(1),
aee3523a 136 name(nullptr),
4e56d7f6 137 format("external_acl_type"),
aee3523a 138 cmdline(nullptr),
f963b531 139 children(DEFAULT_EXTERNAL_ACL_CHILDREN),
aee3523a
AR
140 theHelper(nullptr),
141 cache(nullptr),
f963b531
AJ
142 cache_size(256*1024),
143 cache_entries(0),
144#if USE_AUTH
145 require_auth(0),
146#endif
95d78f10 147 quote(Format::LOG_QUOTE_URL)
d9572179 148{
f963b531
AJ
149 local_addr.setLocalhost();
150}
62e76326 151
f963b531
AJ
152external_acl::~external_acl()
153{
154 xfree(name);
f963b531
AJ
155 wordlistDestroy(&cmdline);
156
157 if (theHelper) {
158 helperShutdown(theHelper);
aee3523a 159 theHelper = nullptr;
d9572179 160 }
62e76326 161
f963b531
AJ
162 while (lru_list.tail) {
163 ExternalACLEntryPointer e(static_cast<ExternalACLEntry *>(lru_list.tail->data));
164 external_acl_cache_delete(this, e);
165 }
166 if (cache)
167 hashFreeMemory(cache);
168
169 while (next) {
170 external_acl *node = next;
171 next = node->next;
aee3523a 172 node->next = nullptr; // prevent recursion
f963b531 173 delete node;
abdd93d0 174 }
d9572179 175}
176
177void
178parse_externalAclHelper(external_acl ** list)
179{
f963b531 180 char *token = ConfigParser::NextToken();
62e76326 181
7b6ce1c0 182 if (!token) {
62e76326 183 self_destruct();
7b6ce1c0
AJ
184 return;
185 }
62e76326 186
7b6ce1c0 187 external_acl *a = new external_acl;
d9572179 188 a->name = xstrdup(token);
189
2eceb328
CT
190 // Allow supported %macros inside quoted tokens
191 ConfigParser::EnableMacros();
192 token = ConfigParser::NextToken();
62e76326 193
d9572179 194 /* Parse options */
195 while (token) {
62e76326 196 if (strncmp(token, "ttl=", 4) == 0) {
197 a->ttl = atoi(token + 4);
198 } else if (strncmp(token, "negative_ttl=", 13) == 0) {
199 a->negative_ttl = atoi(token + 13);
07eca7e0 200 } else if (strncmp(token, "children=", 9) == 0) {
48d54e4d 201 a->children.n_max = atoi(token + 9);
fa84c01d 202 debugs(0, DBG_CRITICAL, "WARNING: external_acl_type option children=N has been deprecated in favor of children-max=N and children-startup=N");
48d54e4d
AJ
203 } else if (strncmp(token, "children-max=", 13) == 0) {
204 a->children.n_max = atoi(token + 13);
205 } else if (strncmp(token, "children-startup=", 17) == 0) {
206 a->children.n_startup = atoi(token + 17);
207 } else if (strncmp(token, "children-idle=", 14) == 0) {
208 a->children.n_idle = atoi(token + 14);
07eca7e0 209 } else if (strncmp(token, "concurrency=", 12) == 0) {
48d54e4d 210 a->children.concurrency = atoi(token + 12);
6825b101
CT
211 } else if (strncmp(token, "queue-size=", 11) == 0) {
212 a->children.queue_size = atoi(token + 11);
213 a->children.defaultQueueSize = false;
62e76326 214 } else if (strncmp(token, "cache=", 6) == 0) {
215 a->cache_size = atoi(token + 6);
47b0c1fa 216 } else if (strncmp(token, "grace=", 6) == 0) {
217 a->grace = atoi(token + 6);
dc1af3cf 218 } else if (strcmp(token, "protocol=2.5") == 0) {
95d78f10 219 a->quote = Format::LOG_QUOTE_SHELL;
dc1af3cf 220 } else if (strcmp(token, "protocol=3.0") == 0) {
05e52854 221 debugs(3, DBG_PARSE_NOTE(2), "WARNING: external_acl_type option protocol=3.0 is deprecated. Remove this from your config.");
95d78f10 222 a->quote = Format::LOG_QUOTE_URL;
dc1af3cf 223 } else if (strcmp(token, "quote=url") == 0) {
05e52854 224 debugs(3, DBG_PARSE_NOTE(2), "WARNING: external_acl_type option quote=url is deprecated. Remove this from your config.");
95d78f10 225 a->quote = Format::LOG_QUOTE_URL;
dc1af3cf 226 } else if (strcmp(token, "quote=shell") == 0) {
05e52854 227 debugs(3, DBG_PARSE_NOTE(2), "WARNING: external_acl_type option quote=shell is deprecated. Use protocol=2.5 if still needed.");
95d78f10 228 a->quote = Format::LOG_QUOTE_SHELL;
cc192b50 229
26ac0430
AJ
230 /* INET6: allow admin to configure some helpers explicitly to
231 bind to IPv4/v6 localhost port. */
cc192b50 232 } else if (strcmp(token, "ipv4") == 0) {
4dd643d5 233 if ( !a->local_addr.setIPv4() ) {
fa84c01d 234 debugs(3, DBG_CRITICAL, "WARNING: Error converting " << a->local_addr << " to IPv4 in " << a->name );
cc192b50 235 }
236 } else if (strcmp(token, "ipv6") == 0) {
055421ee 237 if (!Ip::EnableIpv6)
fa84c01d 238 debugs(3, DBG_CRITICAL, "WARNING: --enable-ipv6 required for external ACL helpers to use IPv6: " << a->name );
055421ee 239 // else nothing to do.
62e76326 240 } else {
241 break;
242 }
243
2eceb328 244 token = ConfigParser::NextToken();
d9572179 245 }
2eceb328 246 ConfigParser::DisableMacros();
62e76326 247
6f78f0ed 248 /* check that child startup value is sane. */
a3cecd6c
AJ
249 if (a->children.n_startup > a->children.n_max)
250 a->children.n_startup = a->children.n_max;
48d54e4d 251
6f78f0ed 252 /* check that child idle value is sane. */
a3cecd6c
AJ
253 if (a->children.n_idle > a->children.n_max)
254 a->children.n_idle = a->children.n_max;
255 if (a->children.n_idle < 1)
256 a->children.n_idle = 1;
48d54e4d 257
d9572179 258 if (a->negative_ttl == -1)
62e76326 259 a->negative_ttl = a->ttl;
d9572179 260
e44a3ec4 261 if (a->children.defaultQueueSize)
6825b101
CT
262 a->children.queue_size = 2 * a->children.n_max;
263
4e56d7f6
AJ
264 /* Legacy external_acl_type format parser.
265 * Handles a series of %... tokens where any non-% means
266 * the start of another parameter field (ie the path to binary).
267 */
268 enum Format::Quoting quote = Format::LOG_QUOTE_NONE;
269 Format::Token **fmt = &a->format.format;
712fa21e 270 bool data_used = false;
d9572179 271 while (token) {
4e56d7f6 272 /* stop on first non-% token found */
62e76326 273 if (*token != '%')
274 break;
275
4e56d7f6 276 *fmt = new Format::Token;
09e34608
AJ
277 // these tokens are whitespace delimited
278 (*fmt)->space = true;
4e56d7f6 279
3a80bdd7 280 // set the default encoding to match the protocol= config
95d78f10
AJ
281 // this will be overridden by explicit %macro attributes
282 (*fmt)->quote = a->quote;
283
4e56d7f6 284 // compatibility for old tokens incompatible with Format::Token syntax
61beade2 285#if USE_OPENSSL // do not bother unless we have to.
4e56d7f6
AJ
286 if (strncmp(token, "%USER_CERT_", 11) == 0) {
287 (*fmt)->type = Format::LFT_EXT_ACL_USER_CERT;
288 (*fmt)->data.string = xstrdup(token + 11);
289 (*fmt)->data.header.header = (*fmt)->data.string;
f06585e0 290 } else if (strncmp(token, "%USER_CA_CERT_", 14) == 0) {
4e56d7f6
AJ
291 (*fmt)->type = Format::LFT_EXT_ACL_USER_CA_CERT;
292 (*fmt)->data.string = xstrdup(token + 14);
293 (*fmt)->data.header.header = (*fmt)->data.string;
f06585e0 294 } else if (strncmp(token, "%CA_CERT_", 9) == 0) {
3650c90e 295 debugs(82, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: external_acl_type %CA_CERT_* code is obsolete. Use %USER_CA_CERT_* instead");
4e56d7f6
AJ
296 (*fmt)->type = Format::LFT_EXT_ACL_USER_CA_CERT;
297 (*fmt)->data.string = xstrdup(token + 9);
298 (*fmt)->data.header.header = (*fmt)->data.string;
299 } else
a7ad6e4e 300#endif
62b9cc19 301 if (strncmp(token,"%<{", 3) == 0) {
302 SBuf tmp("%<h");
303 tmp.append(token+2);
304 debugs(82, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: external_acl_type format %<{...} is deprecated. Use " << tmp);
305 const size_t parsedLen = (*fmt)->parse(tmp.c_str(), &quote);
306 assert(parsedLen == tmp.length());
307 assert((*fmt)->type == Format::LFT_REPLY_HEADER ||
308 (*fmt)->type == Format::LFT_REPLY_HEADER_ELEM);
309
310 } else if (strncmp(token,"%>{", 3) == 0) {
311 SBuf tmp("%>ha");
312 tmp.append(token+2);
313 debugs(82, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: external_acl_type format %>{...} is deprecated. Use " << tmp);
314 const size_t parsedLen = (*fmt)->parse(tmp.c_str(), &quote);
315 assert(parsedLen == tmp.length());
316 assert((*fmt)->type == Format::LFT_ADAPTED_REQUEST_HEADER ||
317 (*fmt)->type == Format::LFT_ADAPTED_REQUEST_HEADER_ELEM);
318
319 } else {
320 // we can use the Format::Token::parse() method since it
321 // only pulls off one token. Since we already checked
322 // for '%' prefix above this is guaranteed to be a token.
323 const size_t len = (*fmt)->parse(token, &quote);
324 assert(len == strlen(token));
325 }
4e56d7f6
AJ
326
327 // process special token-specific actions (only if necessary)
2f1431ea 328#if USE_AUTH
4e56d7f6
AJ
329 if ((*fmt)->type == Format::LFT_USER_LOGIN)
330 a->require_auth = true;
2f1431ea 331#endif
62e76326 332
95d78f10
AJ
333 if ((*fmt)->type == Format::LFT_EXT_ACL_DATA)
334 data_used = true;
712fa21e 335
4e56d7f6 336 fmt = &((*fmt)->next);
2eceb328 337 token = ConfigParser::NextToken();
d9572179 338 }
339
340 /* There must be at least one format token */
7b6ce1c0
AJ
341 if (!a->format.format) {
342 delete a;
62e76326 343 self_destruct();
7b6ce1c0
AJ
344 return;
345 }
d9572179 346
712fa21e
AJ
347 // format has implicit %DATA on the end if not used explicitly
348 if (!data_used) {
349 *fmt = new Format::Token;
350 (*fmt)->type = Format::LFT_EXT_ACL_DATA;
262eaf9a 351 (*fmt)->quote = Format::LOG_QUOTE_NONE;
712fa21e
AJ
352 }
353
d9572179 354 /* helper */
7b6ce1c0
AJ
355 if (!token) {
356 delete a;
62e76326 357 self_destruct();
7b6ce1c0
AJ
358 return;
359 }
62e76326 360
d9572179 361 wordlistAdd(&a->cmdline, token);
362
363 /* arguments */
a336d130 364 parse_wordlist(&a->cmdline);
d9572179 365
366 while (*list)
62e76326 367 list = &(*list)->next;
368
d9572179 369 *list = a;
370}
371
372void
373dump_externalAclHelper(StoreEntry * sentry, const char *name, const external_acl * list)
374{
375 const external_acl *node;
d9572179 376 const wordlist *word;
62e76326 377
d9572179 378 for (node = list; node; node = node->next) {
62e76326 379 storeAppendPrintf(sentry, "%s %s", name, node->name);
380
4dd643d5 381 if (!node->local_addr.isIPv6())
cc192b50 382 storeAppendPrintf(sentry, " ipv4");
383 else
384 storeAppendPrintf(sentry, " ipv6");
385
62e76326 386 if (node->ttl != DEFAULT_EXTERNAL_ACL_TTL)
387 storeAppendPrintf(sentry, " ttl=%d", node->ttl);
388
389 if (node->negative_ttl != node->ttl)
390 storeAppendPrintf(sentry, " negative_ttl=%d", node->negative_ttl);
391
47b0c1fa 392 if (node->grace)
393 storeAppendPrintf(sentry, " grace=%d", node->grace);
394
48d54e4d
AJ
395 if (node->children.n_max != DEFAULT_EXTERNAL_ACL_CHILDREN)
396 storeAppendPrintf(sentry, " children-max=%d", node->children.n_max);
62e76326 397
2ccfb9a7 398 if (node->children.n_startup != 0) // sync with helper/ChildConfig.cc default
48d54e4d 399 storeAppendPrintf(sentry, " children-startup=%d", node->children.n_startup);
62e76326 400
2ccfb9a7 401 if (node->children.n_idle != 1) // sync with helper/ChildConfig.cc default
48d54e4d
AJ
402 storeAppendPrintf(sentry, " children-idle=%d", node->children.n_idle);
403
2ccfb9a7 404 if (node->children.concurrency != 0)
48d54e4d 405 storeAppendPrintf(sentry, " concurrency=%d", node->children.concurrency);
07eca7e0 406
47b0c1fa 407 if (node->cache)
408 storeAppendPrintf(sentry, " cache=%d", node->cache_size);
409
95d78f10 410 if (node->quote == Format::LOG_QUOTE_SHELL)
05e52854
AJ
411 storeAppendPrintf(sentry, " protocol=2.5");
412
aee3523a 413 node->format.dump(sentry, nullptr, false);
62e76326 414
415 for (word = node->cmdline; word; word = word->next)
416 storeAppendPrintf(sentry, " %s", word->key);
417
418 storeAppendPrintf(sentry, "\n");
d9572179 419 }
420}
421
422void
423free_externalAclHelper(external_acl ** list)
424{
f963b531 425 delete *list;
aee3523a 426 *list = nullptr;
d9572179 427}
428
429static external_acl *
430find_externalAclHelper(const char *name)
431{
432 external_acl *node;
433
434 for (node = Config.externalAclHelperList; node; node = node->next) {
62e76326 435 if (strcmp(node->name, name) == 0)
436 return node;
d9572179 437 }
62e76326 438
aee3523a 439 return nullptr;
d9572179 440}
441
1e5562e3 442void
abdd93d0 443external_acl::add(const ExternalACLEntryPointer &anEntry)
1e5562e3 444{
445 trimCache();
aee3523a
AR
446 assert(anEntry != nullptr);
447 assert (anEntry->def == nullptr);
1e5562e3 448 anEntry->def = this;
abdd93d0
AJ
449 ExternalACLEntry *e = const_cast<ExternalACLEntry *>(anEntry.getRaw()); // XXX: make hash a std::map of Pointer.
450 hash_join(cache, e);
451 dlinkAdd(e, &e->lru, &lru_list);
452 e->lock(); //cbdataReference(e); // lock it on behalf of the hash
95dc7ff4 453 ++cache_entries;
1e5562e3 454}
455
456void
457external_acl::trimCache()
458{
abdd93d0
AJ
459 if (cache_size && cache_entries >= cache_size) {
460 ExternalACLEntryPointer e(static_cast<ExternalACLEntry *>(lru_list.tail->data));
461 external_acl_cache_delete(this, e);
462 }
1e5562e3 463}
464
194ccc9c 465bool
329c128c 466external_acl::maybeCacheable(const Acl::Answer &result) const
194ccc9c
CT
467{
468 if (cache_size <= 0)
469 return false; // cache is disabled
470
471 if (result == ACCESS_DUNNO)
472 return false; // non-cacheable response
473
06bf5384 474 if ((result.allowed() ? ttl : negative_ttl) <= 0)
194ccc9c
CT
475 return false; // not caching this type of response
476
477 return true;
478}
479
d9572179 480/******************************************************************
481 * external acl type
482 */
483
f963b531
AJ
484class external_acl_data
485{
486 CBDATA_CLASS(external_acl_data);
487
488public:
aee3523a 489 explicit external_acl_data(external_acl *aDef) : def(cbdataReference(aDef)), name(nullptr), arguments(nullptr) {}
f963b531
AJ
490 ~external_acl_data();
491
d9572179 492 external_acl *def;
ec2d5242 493 const char *name;
d9572179 494 wordlist *arguments;
495};
496
f963b531
AJ
497CBDATA_CLASS_INIT(external_acl_data);
498
499external_acl_data::~external_acl_data()
d9572179 500{
f963b531
AJ
501 xfree(name);
502 wordlistDestroy(&arguments);
503 cbdataReferenceDone(def);
d9572179 504}
505
506void
b0dd28ba 507ACLExternal::parse()
d9572179 508{
7b6ce1c0 509 if (data) {
62e76326 510 self_destruct();
7b6ce1c0
AJ
511 return;
512 }
62e76326 513
16c5ad96 514 char *token = ConfigParser::strtokFile();
62e76326 515
7b6ce1c0 516 if (!token) {
62e76326 517 self_destruct();
7b6ce1c0
AJ
518 return;
519 }
62e76326 520
f963b531 521 data = new external_acl_data(find_externalAclHelper(token));
62e76326 522
7b6ce1c0
AJ
523 if (!data->def) {
524 delete data;
62e76326 525 self_destruct();
7b6ce1c0
AJ
526 return;
527 }
62e76326 528
ec2d5242
HN
529 // def->name is the name of the external_acl_type.
530 // this is the name of the 'acl' directive being tested
b5818136 531 data->name = xstrdup(name);
ec2d5242 532
16c5ad96 533 while ((token = ConfigParser::strtokFile())) {
62e76326 534 wordlistAdd(&data->arguments, token);
d9572179 535 }
d9572179 536}
537
4b0f5de8 538bool
539ACLExternal::valid () const
540{
2f1431ea 541#if USE_AUTH
4b0f5de8 542 if (data->def->require_auth) {
543 if (authenticateSchemeCount() == 0) {
d816f28d 544 debugs(28, DBG_CRITICAL, "ERROR: Cannot use proxy auth because no authentication schemes were compiled.");
4b0f5de8 545 return false;
546 }
547
548 if (authenticateActiveSchemeCount() == 0) {
d816f28d 549 debugs(28, DBG_CRITICAL, "ERROR: Cannot use proxy auth because no authentication schemes are fully configured.");
4b0f5de8 550 return false;
551 }
552 }
2f1431ea 553#endif
4b0f5de8 554
555 return true;
556}
557
558bool
559ACLExternal::empty () const
560{
561 return false;
562}
563
b0dd28ba 564ACLExternal::~ACLExternal()
d9572179 565{
f963b531
AJ
566 delete data;
567 xfree(class_);
d9572179 568}
569
1abe0161 570static void
f05e4f37 571copyResultsFromEntry(const HttpRequest::Pointer &req, const ExternalACLEntryPointer &entry)
1abe0161
AJ
572{
573 if (req) {
574#if USE_AUTH
575 if (entry->user.size())
576 req->extacl_user = entry->user;
577
578 if (entry->password.size())
579 req->extacl_passwd = entry->password;
580#endif
581 if (!req->tag.size())
582 req->tag = entry->tag;
583
584 if (entry->log.size())
585 req->extacl_log = entry->log;
586
587 if (entry->message.size())
588 req->extacl_message = entry->message;
a1df1417
NH
589
590 // attach the helper kv-pair to the transaction
591 UpdateRequestNotes(req->clientConnectionManager.get(), *req, entry->notes);
1abe0161
AJ
592 }
593}
594
5fb6afec
EB
595// TODO: Diff reduction. Rename this helper method to match_() or similar.
596Acl::Answer
597ACLExternal::aclMatchExternal(external_acl_data *acl, ACLFilledChecklist *ch) const
d9572179 598{
bf95c10a 599 debugs(82, 9, "acl=\"" << acl->def->name << "\"");
abdd93d0 600 ExternalACLEntryPointer entry = ch->extacl_entry;
62e76326 601
6f58d7d7
AR
602 external_acl_message = "MISSING REQUIRED INFORMATION";
603
aee3523a 604 if (entry != nullptr) {
abdd93d0 605 if (entry->def == acl->def) {
ad06254e 606 /* Ours, use it.. if the key matches */
6f58d7d7
AR
607 const char *key = makeExternalAclKey(ch, acl);
608 if (!key)
2f8abb64 609 return ACCESS_DUNNO; // insufficient data to continue
ad06254e 610 if (strcmp(key, (char*)entry->key) != 0) {
61beade2 611 debugs(82, 9, "entry key='" << (char *)entry->key << "', our key='" << key << "' do not match. Discarded.");
ad06254e 612 // too bad. need a new lookup.
aee3523a 613 entry = ch->extacl_entry = nullptr;
ad06254e 614 }
62e76326 615 } else {
abdd93d0
AJ
616 /* Not ours.. get rid of it */
617 debugs(82, 9, "entry " << entry << " not valid or not ours. Discarded.");
aee3523a 618 if (entry != nullptr) {
abdd93d0 619 debugs(82, 9, "entry def=" << entry->def << ", our def=" << acl->def);
6f58d7d7 620 const char *key = makeExternalAclKey(ch, acl); // may be nil
abdd93d0 621 debugs(82, 9, "entry key='" << (char *)entry->key << "', our key='" << key << "'");
c69ce640 622 }
aee3523a 623 entry = ch->extacl_entry = nullptr;
62e76326 624 }
d9572179 625 }
62e76326 626
d9572179 627 if (!entry) {
bf95c10a 628 debugs(82, 9, "No helper entry available");
2f1431ea 629#if USE_AUTH
62e76326 630 if (acl->def->require_auth) {
62e76326 631 /* Make sure the user is authenticated */
bf95c10a 632 debugs(82, 3, acl->def->name << " check user authenticated.");
5fb6afec 633 const auto ti = AuthenticateAcl(ch, *this);
06bf5384 634 if (!ti.allowed()) {
bf95c10a 635 debugs(82, 2, acl->def->name << " user not authenticated (" << ti << ")");
e0f7153c 636 return ti;
62e76326 637 }
bf95c10a 638 debugs(82, 3, acl->def->name << " user is authenticated.");
62e76326 639 }
2f1431ea 640#endif
6f58d7d7 641 const char *key = makeExternalAclKey(ch, acl);
41218131 642
643 if (!key) {
644 /* Not sufficient data to process */
e5f825ea 645 return ACCESS_DUNNO;
41218131 646 }
647
abdd93d0 648 entry = static_cast<ExternalACLEntry *>(hash_lookup(acl->def->cache, key));
62e76326 649
abdd93d0 650 const ExternalACLEntryPointer staleEntry = entry;
aee3523a
AR
651 if (entry != nullptr && external_acl_entry_expired(acl->def, entry))
652 entry = nullptr;
e0f7153c 653
aee3523a 654 if (entry != nullptr && external_acl_grace_expired(acl->def, entry)) {
e0f7153c 655 // refresh in the background
5fb6afec 656 startLookup(ch, acl, true);
bf95c10a 657 debugs(82, 4, "no need to wait for the refresh of '" <<
e0f7153c
AR
658 key << "' in '" << acl->def->name << "' (ch=" << ch << ").");
659 }
660
661 if (!entry) {
bf95c10a 662 debugs(82, 2, acl->def->name << "(\"" << key << "\") = lookup needed");
95a83c22 663
6082a0e2
EB
664 // TODO: All other helpers allow temporary overload. Should not we?
665 if (!acl->def->theHelper->willOverload()) {
bf95c10a 666 debugs(82, 2, "\"" << key << "\": queueing a call.");
5fb6afec 667 if (!ch->goAsync(StartLookup, *this))
6f58d7d7 668 debugs(82, 2, "\"" << key << "\": no async support!");
bf95c10a 669 debugs(82, 2, "\"" << key << "\": return -1.");
e0f7153c 670 return ACCESS_DUNNO; // expired cached or simply absent entry
47b0c1fa 671 } else {
e0f7153c 672 if (!staleEntry) {
e5f825ea 673 debugs(82, DBG_IMPORTANT, "WARNING: external ACL '" << acl->def->name <<
6082a0e2 674 "' queue full. Request rejected '" << key << "'.");
4a972fa2 675 external_acl_message = "SYSTEM TOO BUSY, TRY AGAIN LATER";
e5f825ea 676 return ACCESS_DUNNO;
47b0c1fa 677 } else {
e5f825ea 678 debugs(82, DBG_IMPORTANT, "WARNING: external ACL '" << acl->def->name <<
6082a0e2 679 "' queue full. Using stale result. '" << key << "'.");
e0f7153c 680 entry = staleEntry;
47b0c1fa 681 /* Fall thru to processing below */
682 }
683 }
684 }
d9572179 685 }
62e76326 686
bf95c10a 687 debugs(82, 4, "entry = { date=" <<
e0f7153c
AR
688 (long unsigned int) entry->date <<
689 ", result=" << entry->result <<
690 " tag=" << entry->tag <<
691 " log=" << entry->log << " }");
692#if USE_AUTH
bf95c10a 693 debugs(82, 4, "entry user=" << entry->user);
e0f7153c
AR
694#endif
695
d9572179 696 external_acl_cache_touch(acl->def, entry);
a7a42b14 697 external_acl_message = entry->message.termedBuf();
4a972fa2 698
bf95c10a 699 debugs(82, 2, acl->def->name << " = " << entry->result);
1abe0161 700 copyResultsFromEntry(ch->request, entry);
e5f825ea 701 return entry->result;
d9572179 702}
703
b0dd28ba 704int
705ACLExternal::match(ACLChecklist *checklist)
706{
329c128c 707 auto answer = aclMatchExternal(data, Filled(checklist));
e5f825ea
AJ
708
709 // convert to tri-state ACL match 1,0,-1
9b831d57 710 switch (answer) {
e5f825ea 711 case ACCESS_ALLOWED:
e5f825ea
AJ
712 return 1; // match
713
714 case ACCESS_DENIED:
e5f825ea
AJ
715 return 0; // non-match
716
717 case ACCESS_DUNNO:
718 case ACCESS_AUTH_REQUIRED:
719 default:
e0f7153c 720 // If the answer is not allowed or denied (matches/not matches) and
6f58d7d7
AR
721 // async authentication is not in progress, then we are done.
722 if (checklist->keepMatching())
e0f7153c 723 checklist->markFinished(answer, "aclMatchExternal exception");
e5f825ea
AJ
724 return -1; // other
725 }
b0dd28ba 726}
727
dfad5100 728SBufList
b0dd28ba 729ACLExternal::dump() const
d9572179 730{
b0dd28ba 731 external_acl_data const *acl = data;
dfad5100
FC
732 SBufList rv;
733 rv.push_back(SBuf(acl->def->name));
62e76326 734
dfad5100
FC
735 for (wordlist *arg = acl->arguments; arg; arg = arg->next) {
736 SBuf s;
737 s.Printf(" %s", arg->key);
738 rv.push_back(s);
d9572179 739 }
62e76326 740
dfad5100 741 return rv;
d9572179 742}
743
744/******************************************************************
745 * external_acl cache
746 */
747
d9572179 748static void
abdd93d0 749external_acl_cache_touch(external_acl * def, const ExternalACLEntryPointer &entry)
d9572179 750{
c69ce640 751 // this must not be done when nothing is being cached.
194ccc9c 752 if (!def->maybeCacheable(entry->result))
c69ce640
AJ
753 return;
754
d9572179 755 dlinkDelete(&entry->lru, &def->lru_list);
abdd93d0
AJ
756 ExternalACLEntry *e = const_cast<ExternalACLEntry *>(entry.getRaw()); // XXX: make hash a std::map of Pointer.
757 dlinkAdd(e, &entry->lru, &def->lru_list);
d9572179 758}
759
5fb6afec
EB
760char *
761ACLExternal::makeExternalAclKey(ACLFilledChecklist * ch, external_acl_data * acl_data) const
d9572179 762{
032785bf 763 static MemBuf mb;
09e34608 764 mb.reset();
62e76326 765
4e56d7f6
AJ
766 // check for special case tokens in the format
767 for (Format::Token *t = acl_data->def->format.format; t ; t = t->next) {
62e76326 768
4e56d7f6
AJ
769 if (t->type == Format::LFT_EXT_ACL_NAME) {
770 // setup for %ACL
4ff6370b
AJ
771 safe_free(ch->al->lastAclName);
772 ch->al->lastAclName = xstrdup(acl_data->name);
789dda8d
CT
773 }
774
778647be 775 if (t->type == Format::LFT_EXT_ACL_DATA) {
4e56d7f6
AJ
776 // setup string for %DATA
777 SBuf sb;
4e56d7f6 778 for (auto arg = acl_data->arguments; arg; arg = arg->next) {
778647be 779 if (sb.length())
ec2d5242
HN
780 sb.append(" ", 1);
781
95d78f10 782 if (acl_data->def->quote == Format::LOG_QUOTE_URL) {
ec2d5242
HN
783 const char *quoted = rfc1738_escape(arg->key);
784 sb.append(quoted, strlen(quoted));
785 } else {
786 static MemBuf mb2;
787 mb2.init();
788 strwordquote(&mb2, arg->key);
789 sb.append(mb2.buf, mb2.size);
790 mb2.clean();
791 }
ec2d5242 792 }
778647be 793
b0e14ce2 794 ch->al->lastAclData = sb;
dc1af3cf 795 }
62e76326 796
33c2eb4d 797#if USE_IDENT
4e56d7f6 798 if (t->type == Format::LFT_USER_IDENT) {
a51ed963 799 if (!*ch->rfc931) {
4e56d7f6
AJ
800 // if we fail to go async, we still return NULL and the caller
801 // will detect the failure in ACLExternal::match().
5fb6afec 802 (void)ch->goAsync(ACLIdent::StartLookup, *this);
aee3523a 803 return nullptr;
ec2d5242 804 }
ec2d5242 805 }
33c2eb4d 806#endif
d9572179 807 }
62e76326 808
712fa21e 809 // assemble the full helper lookup string
4e56d7f6
AJ
810 acl_data->def->format.assemble(mb, ch->al, 0);
811
d9572179 812 return mb.buf;
d9572179 813}
814
815static int
abdd93d0 816external_acl_entry_expired(external_acl * def, const ExternalACLEntryPointer &entry)
d9572179 817{
194ccc9c 818 if (def->cache_size <= 0 || entry->result == ACCESS_DUNNO)
c69ce640
AJ
819 return 1;
820
06bf5384 821 if (entry->date + (entry->result.allowed() ? def->ttl : def->negative_ttl) < squid_curtime)
62e76326 822 return 1;
d9572179 823 else
62e76326 824 return 0;
d9572179 825}
62e76326 826
47b0c1fa 827static int
abdd93d0 828external_acl_grace_expired(external_acl * def, const ExternalACLEntryPointer &entry)
47b0c1fa 829{
194ccc9c 830 if (def->cache_size <= 0 || entry->result == ACCESS_DUNNO)
c69ce640
AJ
831 return 1;
832
47b0c1fa 833 int ttl;
06bf5384 834 ttl = entry->result.allowed() ? def->ttl : def->negative_ttl;
47b0c1fa 835 ttl = (ttl * (100 - def->grace)) / 100;
836
98b70eff 837 if (entry->date + ttl <= squid_curtime)
47b0c1fa 838 return 1;
839 else
840 return 0;
841}
842
abdd93d0 843static ExternalACLEntryPointer
1e5562e3 844external_acl_cache_add(external_acl * def, const char *key, ExternalACLEntryData const & data)
d9572179 845{
abdd93d0 846 ExternalACLEntryPointer entry;
c69ce640 847
194ccc9c 848 if (!def->maybeCacheable(data.result)) {
bf95c10a 849 debugs(82,6, MYNAME);
194ccc9c
CT
850
851 if (data.result == ACCESS_DUNNO) {
852 if (const ExternalACLEntryPointer oldentry = static_cast<ExternalACLEntry *>(hash_lookup(def->cache, key)))
853 external_acl_cache_delete(def, oldentry);
854 }
c69ce640
AJ
855 entry = new ExternalACLEntry;
856 entry->key = xstrdup(key);
857 entry->update(data);
858 entry->def = def;
859 return entry;
860 }
861
862 entry = static_cast<ExternalACLEntry *>(hash_lookup(def->cache, key));
bf8fe701 863 debugs(82, 2, "external_acl_cache_add: Adding '" << key << "' = " << data.result);
62e76326 864
aee3523a 865 if (entry != nullptr) {
abdd93d0 866 debugs(82, 3, "updating existing entry");
c69ce640 867 entry->update(data);
62e76326 868 external_acl_cache_touch(def, entry);
62e76326 869 return entry;
d9572179 870 }
62e76326 871
1e5562e3 872 entry = new ExternalACLEntry;
4a8b20e8 873 entry->key = xstrdup(key);
c69ce640 874 entry->update(data);
1e5562e3 875
6ca34f6f 876 def->add(entry);
1e5562e3 877
d9572179 878 return entry;
879}
880
881static void
abdd93d0 882external_acl_cache_delete(external_acl * def, const ExternalACLEntryPointer &entry)
d9572179 883{
aee3523a 884 assert(entry != nullptr);
c69ce640 885 assert(def->cache_size > 0 && entry->def == def);
abdd93d0
AJ
886 ExternalACLEntry *e = const_cast<ExternalACLEntry *>(entry.getRaw()); // XXX: make hash a std::map of Pointer.
887 hash_remove_link(def->cache, e);
888 dlinkDelete(&e->lru, &def->lru_list);
889 e->unlock(); // unlock on behalf of the hash
d9572179 890 def->cache_entries -= 1;
d9572179 891}
892
893/******************************************************************
894 * external_acl helpers
895 */
896
f963b531
AJ
897class externalAclState
898{
899 CBDATA_CLASS(externalAclState);
900
901public:
902 externalAclState(external_acl* aDef, const char *aKey) :
aee3523a
AR
903 callback(nullptr),
904 callback_data(nullptr),
f963b531
AJ
905 key(xstrdup(aKey)),
906 def(cbdataReference(aDef)),
aee3523a 907 queue(nullptr)
f963b531
AJ
908 {}
909 ~externalAclState();
62e76326 910
d9572179 911 EAH *callback;
912 void *callback_data;
913 char *key;
914 external_acl *def;
915 dlink_node list;
916 externalAclState *queue;
917};
918
f963b531
AJ
919CBDATA_CLASS_INIT(externalAclState);
920
921externalAclState::~externalAclState()
d9572179 922{
f963b531
AJ
923 xfree(key);
924 cbdataReferenceDone(callback_data);
925 cbdataReferenceDone(def);
d9572179 926}
927
d9572179 928/*
929 * The helper program receives queries on stdin, one
07eca7e0 930 * per line, and must return the result on on stdout
d9572179 931 *
932 * General result syntax:
933 *
934 * OK/ERR keyword=value ...
935 *
936 * Keywords:
937 *
4a972fa2 938 * user= The users name (login)
939 * message= Message describing the reason
f53969cc
SM
940 * tag= A string tag to be applied to the request that triggered the acl match.
941 * applies to both OK and ERR responses.
942 * Won't override existing request tags.
943 * log= A string to be used in access logging
d9572179 944 *
945 * Other keywords may be added to the protocol later
946 *
05e52854
AJ
947 * value needs to be URL-encoded or enclosed in double quotes (")
948 * with \-escaping on any whitespace, quotes, or slashes (\).
d9572179 949 */
d9572179 950static void
24438ec5 951externalAclHandleReply(void *data, const Helper::Reply &reply)
d9572179 952{
e6ccf245 953 externalAclState *state = static_cast<externalAclState *>(data);
d9572179 954 externalAclState *next;
1e5562e3 955 ExternalACLEntryData entryData;
d9572179 956
bf95c10a 957 debugs(82, 2, "reply=" << reply);
d9572179 958
2428ce02 959 if (reply.result == Helper::Okay)
0272dd08 960 entryData.result = ACCESS_ALLOWED;
194ccc9c
CT
961 else if (reply.result == Helper::Error)
962 entryData.result = ACCESS_DENIED;
963 else //BrokenHelper,TimedOut or Unknown. Should not cached.
964 entryData.result = ACCESS_DUNNO;
62e76326 965
24438ec5 966 // XXX: make entryData store a proper Helper::Reply object instead of copying.
ab332e27 967
a0592634
AJ
968 entryData.notes.append(&reply.notes);
969
cf9f0261 970 const char *label = reply.notes.findFirst("tag");
aee3523a 971 if (label != nullptr && *label != '\0')
cf9f0261 972 entryData.tag = label;
62e76326 973
cf9f0261 974 label = reply.notes.findFirst("message");
aee3523a 975 if (label != nullptr && *label != '\0')
cf9f0261 976 entryData.message = label;
62e76326 977
cf9f0261 978 label = reply.notes.findFirst("log");
aee3523a 979 if (label != nullptr && *label != '\0')
cf9f0261 980 entryData.log = label;
62e76326 981
2f1431ea 982#if USE_AUTH
cf9f0261 983 label = reply.notes.findFirst("user");
aee3523a 984 if (label != nullptr && *label != '\0')
cf9f0261 985 entryData.user = label;
7bbefa01 986
cf9f0261 987 label = reply.notes.findFirst("password");
aee3523a 988 if (label != nullptr && *label != '\0')
cf9f0261 989 entryData.password = label;
2f1431ea 990#endif
62e76326 991
23da195f
CT
992 // XXX: This state->def access conflicts with the cbdata validity check
993 // below.
d9572179 994 dlinkDelete(&state->list, &state->def->queue);
62e76326 995
abdd93d0 996 ExternalACLEntryPointer entry;
194ccc9c
CT
997 if (cbdataReferenceValid(state->def))
998 entry = external_acl_cache_add(state->def, state->key, entryData);
d9572179 999
1000 do {
62e76326 1001 void *cbdata;
47b0c1fa 1002 if (state->callback && cbdataReferenceValidDone(state->callback_data, &cbdata))
62e76326 1003 state->callback(cbdata, entry);
1004
1005 next = state->queue;
aee3523a 1006 state->queue = nullptr;
d9572179 1007
f963b531 1008 delete state;
d9572179 1009
62e76326 1010 state = next;
d9572179 1011 } while (state);
1012}
1013
5fb6afec
EB
1014/// Asks the helper (if needed) or returns the [cached] result (otherwise).
1015/// Does not support "background" lookups. See also: ACLExternal::Start().
d9572179 1016void
922513e5 1017ACLExternal::StartLookup(ACLFilledChecklist &checklist, const Acl::Node &acl)
d9572179 1018{
5fb6afec
EB
1019 const auto &me = dynamic_cast<const ACLExternal&>(acl);
1020 me.startLookup(&checklist, me.data, false);
e0f7153c 1021}
c8e7608c 1022
5fb6afec
EB
1023// If possible, starts an asynchronous lookup of an external ACL.
1024// Otherwise, asserts (or bails if background refresh is requested).
e0f7153c 1025void
5fb6afec 1026ACLExternal::startLookup(ACLFilledChecklist *ch, external_acl_data *acl, bool inBackground) const
e0f7153c
AR
1027{
1028 external_acl *def = acl->def;
c0f81932 1029
c8e7608c 1030 const char *key = makeExternalAclKey(ch, acl);
6f58d7d7 1031 assert(key); // XXX: will fail if EXT_ACL_IDENT case needs an async lookup
62e76326 1032
bf95c10a 1033 debugs(82, 2, (inBackground ? "bg" : "fg") << " lookup in '" <<
e0f7153c 1034 def->name << "' for '" << key << "'");
62e76326 1035
47b0c1fa 1036 /* Check for a pending lookup to hook into */
c69ce640 1037 // only possible if we are caching results.
aee3523a 1038 externalAclState *oldstate = nullptr;
c69ce640 1039 if (def->cache_size > 0) {
e0f7153c 1040 for (dlink_node *node = def->queue.head; node; node = node->next) {
c69ce640 1041 externalAclState *oldstatetmp = static_cast<externalAclState *>(node->data);
62e76326 1042
c69ce640
AJ
1043 if (strcmp(key, oldstatetmp->key) == 0) {
1044 oldstate = oldstatetmp;
1045 break;
1046 }
47b0c1fa 1047 }
1048 }
62e76326 1049
e0f7153c
AR
1050 // A background refresh has no need to piggiback on a pending request:
1051 // When the pending request completes, the cache will be refreshed anyway.
1052 if (oldstate && inBackground) {
bf95c10a 1053 debugs(82, 7, "'" << def->name << "' queue is already being refreshed (ch=" << ch << ")");
47b0c1fa 1054 return;
1055 }
62e76326 1056
f963b531 1057 externalAclState *state = new externalAclState(def, key);
62e76326 1058
e0f7153c 1059 if (!inBackground) {
5fb6afec
EB
1060 state->callback = &LookupDone;
1061 state->callback_data = cbdataReference(ch);
d9572179 1062 }
62e76326 1063
47b0c1fa 1064 if (oldstate) {
1065 /* Hook into pending lookup */
1066 state->queue = oldstate->queue;
1067 oldstate->queue = state;
1068 } else {
e0f7153c
AR
1069 /* No pending lookup found. Sumbit to helper */
1070
e0f7153c 1071 MemBuf buf;
2fe7eff9 1072 buf.init();
4391cd15 1073 buf.appendf("%s\n", key);
bf8fe701 1074 debugs(82, 4, "externalAclLookup: looking up for '" << key << "' in '" << def->name << "'.");
ab321f4b 1075
6825b101 1076 if (!def->theHelper->trySubmit(buf.buf, externalAclHandleReply, state)) {
bf95c10a 1077 debugs(82, 7, "'" << def->name << "' submit to helper failed");
6825b101 1078 assert(inBackground); // or the caller should have checked
f963b531 1079 delete state;
6825b101
CT
1080 return;
1081 }
62e76326 1082
47b0c1fa 1083 dlinkAdd(state, &state->list, &def->queue);
62e76326 1084
2fe7eff9 1085 buf.clean();
47b0c1fa 1086 }
62e76326 1087
bf8fe701 1088 debugs(82, 4, "externalAclLookup: will wait for the result of '" << key <<
1089 "' in '" << def->name << "' (ch=" << ch << ").");
d9572179 1090}
1091
1092static void
1093externalAclStats(StoreEntry * sentry)
1094{
f963b531 1095 for (external_acl *p = Config.externalAclHelperList; p; p = p->next) {
62e76326 1096 storeAppendPrintf(sentry, "External ACL Statistics: %s\n", p->name);
1097 storeAppendPrintf(sentry, "Cache size: %d\n", p->cache->count);
bf3e8d5a
AJ
1098 assert(p->theHelper);
1099 p->theHelper->packStatsInto(sentry);
62e76326 1100 storeAppendPrintf(sentry, "\n");
d9572179 1101 }
1102}
1103
6b7d87bb
FC
1104static void
1105externalAclRegisterWithCacheManager(void)
1106{
8822ebee 1107 Mgr::RegisterAction("external_acl",
d9fc6862
A
1108 "External ACL stats",
1109 externalAclStats, 0, 1);
6b7d87bb
FC
1110}
1111
d9572179 1112void
1113externalAclInit(void)
1114{
f963b531 1115 for (external_acl *p = Config.externalAclHelperList; p; p = p->next) {
62e76326 1116 if (!p->cache)
30abd221 1117 p->cache = hash_create((HASHCMP *) strcmp, hashPrime(1024), hash4);
62e76326 1118
1119 if (!p->theHelper)
e05a9d51 1120 p->theHelper = Helper::Client::Make("external_acl_type");
62e76326 1121
1122 p->theHelper->cmdline = p->cmdline;
1123
1af735c7 1124 p->theHelper->childs.updateLimits(p->children);
07eca7e0 1125
62e76326 1126 p->theHelper->ipc_type = IPC_TCP_SOCKET;
1127
cc192b50 1128 p->theHelper->addr = p->local_addr;
1129
bd71920d 1130 p->theHelper->openSessions();
d9572179 1131 }
62e76326 1132
ea391f18 1133 externalAclRegisterWithCacheManager();
d9572179 1134}
1135
1136void
1137externalAclShutdown(void)
1138{
1139 external_acl *p;
62e76326 1140
d9572179 1141 for (p = Config.externalAclHelperList; p; p = p->next) {
62e76326 1142 helperShutdown(p->theHelper);
d9572179 1143 }
1144}
225b7b10 1145
e0f7153c 1146/// Called when an async lookup returns
225b7b10 1147void
5fb6afec 1148ACLExternal::LookupDone(void *data, const ExternalACLEntryPointer &result)
225b7b10 1149{
c0941a6a 1150 ACLFilledChecklist *checklist = Filled(static_cast<ACLChecklist*>(data));
abdd93d0 1151 checklist->extacl_entry = result;
5fb6afec 1152 checklist->resumeNonBlockingCheck();
225b7b10 1153}
b0dd28ba 1154
aee3523a 1155ACLExternal::ACLExternal(char const *theClass) : data(nullptr), class_(xstrdup(theClass))
b0dd28ba 1156{}
1157
b0dd28ba 1158char const *
1159ACLExternal::typeString() const
1160{
1161 return class_;
1162}
1163
e870b1f8 1164bool
1165ACLExternal::isProxyAuth() const
1166{
2f1431ea 1167#if USE_AUTH
e870b1f8 1168 return data->def->require_auth;
2f1431ea
AJ
1169#else
1170 return false;
1171#endif
e870b1f8 1172}
f53969cc 1173