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