]> git.ipfire.org Git - thirdparty/squid.git/blame - src/cache_cf.cc
Cleanup cleanup: Do not silently violate The Big Three after r14743.
[thirdparty/squid.git] / src / cache_cf.cc
CommitLineData
30a4f2a8 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
e25c139f 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.
30a4f2a8 7 */
cf5fd929 8
bbc27441
AJ
9/* DEBUG: section 03 Configuration File Parsing */
10
582c2af2 11#include "squid.h"
82b7abe3 12#include "acl/Acl.h"
7f0b3324 13#include "acl/AclDenyInfoList.h"
6be70545 14#include "acl/AclNameList.h"
1328cfb7 15#include "acl/AclSizeLimit.h"
289848ca 16#include "acl/Address.h"
82b7abe3
AJ
17#include "acl/Gadgets.h"
18#include "acl/MethodData.h"
6f58d7d7 19#include "acl/Tree.h"
582c2af2 20#include "anyp/PortCfg.h"
1ca54a54 21#include "anyp/UriScheme.h"
89736861 22#include "AuthReg.h"
582c2af2 23#include "base/RunnersRegistry.h"
602d9612 24#include "cache_cf.h"
a011edee 25#include "CachePeer.h"
582c2af2
FC
26#include "ConfigParser.h"
27#include "CpuAffinityMap.h"
28#include "DiskIO/DiskIOModule.h"
29#include "eui/Config.h"
f0c32849 30#include "ExternalACL.h"
582c2af2 31#include "format/Format.h"
ecb19f1a 32#include "ftp/Elements.h"
582c2af2 33#include "globals.h"
a5bac1d2 34#include "HttpHeaderTools.h"
7a9d36e3 35#include "icmp/IcmpConfig.h"
582c2af2
FC
36#include "ident/Config.h"
37#include "ip/Intercept.h"
38#include "ip/QosConfig.h"
39#include "ip/tools.h"
40#include "ipc/Kids.h"
41#include "log/Config.h"
8f645002 42#include "log/CustomLog.h"
582c2af2 43#include "MemBuf.h"
602d9612 44#include "mgr/ActionPasswordList.h"
582c2af2 45#include "mgr/Registration.h"
602d9612 46#include "neighbors.h"
5844d003 47#include "NeighborTypeDomainList.h"
582c2af2 48#include "Parsing.h"
e8dca475 49#include "pconn.h"
e35609f5 50#include "PeerDigest.h"
e8dca475 51#include "PeerPoolMgr.h"
faf2558a 52#include "redirect.h"
8d9a8184 53#include "RefreshPattern.h"
582c2af2 54#include "rfc1738.h"
58d8264f 55#include "sbuf/List.h"
4d5904f7 56#include "SquidConfig.h"
f9b6ff6e 57#include "SquidString.h"
d9c7489e 58#include "ssl/ProxyCerts.h"
582c2af2 59#include "Store.h"
2745fea5
AR
60#include "store/Disk.h"
61#include "store/Disks.h"
582c2af2 62#include "StoreFileSystem.h"
4e540555 63#include "tools.h"
ed6e9fb9 64#include "util.h"
602d9612 65#include "wordlist.h"
b007d04d
FC
66/* wccp2 has its own conditional definitions */
67#include "wccp2.h"
82b7abe3
AJ
68#if USE_ADAPTATION
69#include "adaptation/Config.h"
70#endif
71#if ICAP_CLIENT
72#include "adaptation/icap/Config.h"
73#endif
74#if USE_ECAP
75#include "adaptation/ecap/Config.h"
76#endif
cb4f4424 77#if USE_OPENSSL
95d2589c 78#include "ssl/Config.h"
602d9612 79#include "ssl/support.h"
95d2589c 80#endif
2f1431ea 81#if USE_AUTH
2d2b0bb7
AR
82#include "auth/Config.h"
83#include "auth/Scheme.h"
2f1431ea 84#endif
82b7abe3
AJ
85#if USE_SQUID_ESI
86#include "esi/Parser.h"
87#endif
82b7abe3
AJ
88#if SQUID_SNMP
89#include "snmp.h"
90#endif
582c2af2 91
52303a3d 92#if HAVE_GLOB_H
592a09dc 93#include <glob.h>
52303a3d 94#endif
425de4c8 95#include <limits>
f4698e0b 96#include <list>
582c2af2
FC
97#if HAVE_PWD_H
98#include <pwd.h>
99#endif
100#if HAVE_GRP_H
101#include <grp.h>
102#endif
103#if HAVE_SYS_STAT_H
104#include <sys/stat.h>
105#endif
f4698e0b 106
cb4f4424 107#if USE_OPENSSL
95d2589c
CT
108#include "ssl/gadgets.h"
109#endif
110
62c7f90e 111#if USE_ADAPTATION
62c7f90e 112static void parse_adaptation_service_set_type();
a22e6cd3 113static void parse_adaptation_service_chain_type();
62c7f90e 114static void parse_adaptation_access_type();
62c7f90e
AR
115#endif
116
3a69ddf3 117#if ICAP_CLIENT
26cc52cb
AR
118static void parse_icap_service_type(Adaptation::Icap::Config *);
119static void dump_icap_service_type(StoreEntry *, const char *, const Adaptation::Icap::Config &);
120static void free_icap_service_type(Adaptation::Icap::Config *);
c939dc70
AR
121static void parse_icap_class_type();
122static void parse_icap_access_type();
8277060a
CT
123
124static void parse_icap_service_failure_limit(Adaptation::Icap::Config *);
125static void dump_icap_service_failure_limit(StoreEntry *, const char *, const Adaptation::Icap::Config &);
126static void free_icap_service_failure_limit(Adaptation::Icap::Config *);
3a69ddf3 127#endif
128
21a26d31 129#if USE_ECAP
574b508c
AR
130static void parse_ecap_service_type(Adaptation::Ecap::Config *);
131static void dump_ecap_service_type(StoreEntry *, const char *, const Adaptation::Ecap::Config &);
132static void free_ecap_service_type(Adaptation::Ecap::Config *);
21a26d31
AR
133#endif
134
6a9136ad
FC
135static peer_t parseNeighborType(const char *s);
136
fd0f51c4 137static const char *const T_MILLISECOND_STR = "millisecond";
8813e606 138static const char *const T_SECOND_STR = "second";
139static const char *const T_MINUTE_STR = "minute";
140static const char *const T_HOUR_STR = "hour";
141static const char *const T_DAY_STR = "day";
142static const char *const T_WEEK_STR = "week";
143static const char *const T_FORTNIGHT_STR = "fortnight";
144static const char *const T_MONTH_STR = "month";
145static const char *const T_YEAR_STR = "year";
146static const char *const T_DECADE_STR = "decade";
aa0a0c7c 147
9906e724 148static const char *const B_BYTES_STR = "bytes";
149static const char *const B_KBYTES_STR = "KB";
150static const char *const B_MBYTES_STR = "MB";
151static const char *const B_GBYTES_STR = "GB";
152
4db43fab 153static const char *const list_sep = ", \t\n\r";
b0e7d2d5 154
87ddff6e
FC
155static void parse_access_log(CustomLog ** customlog_definitions);
156static int check_null_access_log(CustomLog *customlog_definitions);
157static void dump_access_log(StoreEntry * entry, const char *name, CustomLog * definitions);
158static void free_access_log(CustomLog ** definitions);
fb0c2f17 159static bool setLogformat(CustomLog *cl, const char *name, const bool dieWhenMissing);
7684c4b1 160
f5b8bbc4 161static void configDoConfigure(void);
8d9a8184 162static void parse_refreshpattern(RefreshPattern **);
9b741834 163static uint64_t parseTimeUnits(const char *unit, bool allowMsec);
32fd6d8a 164static void parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec, bool expectMoreArguments);
f45dd259 165static void parse_u_short(unsigned short * var);
f5b8bbc4 166static void parse_string(char **);
f5b8bbc4 167static void default_all(void);
168static void defaults_if_none(void);
10d914f6 169static void defaults_postscriptum(void);
f5b8bbc4 170static int parse_line(char *);
76f44481 171static void parse_obsolete(const char *);
f5b8bbc4 172static void parseBytesLine(size_t * bptr, const char *units);
cb4f4424 173#if USE_OPENSSL
95d2589c
CT
174static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value);
175#endif
e210930b 176static void parseBytesLineSigned(ssize_t * bptr, const char *units);
f5b8bbc4 177static size_t parseBytesUnits(const char *unit);
f5b8bbc4 178static void free_all(void);
94439e4e 179void requirePathnameExists(const char *name, const char *path);
ed7f5615 180static OBJH dump_config;
626096be 181#if USE_HTTP_VIOLATIONS
3b07476b
CT
182static void free_HeaderManglers(HeaderManglers **pm);
183static void dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
184static void parse_http_header_access(HeaderManglers **manglers);
185#define free_http_header_access free_HeaderManglers
186static void dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
187static void parse_http_header_replace(HeaderManglers **manglers);
188#define free_http_header_replace free_HeaderManglers
9e8b2f1c 189#endif
f4698e0b
CT
190static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers);
191static void parse_HeaderWithAclList(HeaderWithAclList **header);
192static void free_HeaderWithAclList(HeaderWithAclList **header);
d7f4a0b7
CT
193static void parse_note(Notes *);
194static void dump_note(StoreEntry *, const char *, Notes &);
195static void free_note(Notes *);
7f0b3324
FC
196static void parse_denyinfo(AclDenyInfoList ** var);
197static void dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var);
198static void free_denyinfo(AclDenyInfoList ** var);
e1a88700 199
0b0cfcf2 200#if USE_WCCPv2
b7ac5457
AJ
201static void parse_IpAddress_list(Ip::Address_list **);
202static void dump_IpAddress_list(StoreEntry *, const char *, const Ip::Address_list *);
203static void free_IpAddress_list(Ip::Address_list **);
0b0cfcf2 204#if CURRENTLY_UNUSED
b7ac5457 205static int check_null_IpAddress_list(const Ip::Address_list *);
3f38a55e 206#endif /* CURRENTLY_UNUSED */
e1a88700 207#endif /* USE_WCCPv2 */
208
fa720bfb 209static void parsePortCfg(AnyP::PortCfgPointer *, const char *protocol);
65d448bc 210#define parse_PortCfg(l) parsePortCfg((l), token)
fa720bfb
AJ
211static void dump_PortCfg(StoreEntry *, const char *, const AnyP::PortCfgPointer &);
212#define free_PortCfg(h) *(h)=NULL
e1a88700 213
cb4f4424 214#if USE_OPENSSL
aebe6888
CT
215static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign);
216static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign);
217static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign);
fb2178bb
CT
218static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt);
219static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt);
220static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt);
caf3666d
AR
221static void parse_sslproxy_ssl_bump(acl_access **ssl_bump);
222static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump);
223static void free_sslproxy_ssl_bump(acl_access **ssl_bump);
cb4f4424 224#endif /* USE_OPENSSL */
e1a88700 225
ddf5aa2b
CT
226static void parse_ftp_epsv(acl_access **ftp_epsv);
227static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv);
228static void free_ftp_epsv(acl_access **ftp_epsv);
229
ef1955a5 230static void parse_b_size_t(size_t * var);
47f6e231 231static void parse_b_int64_t(int64_t * var);
270b86af 232
96c2bb61
AR
233static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
234static void dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap);
235static void free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
236
ced8def3
AJ
237static void parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout *);
238static void dump_UrlHelperTimeout(StoreEntry *, const char *, SquidConfig::UrlHelperTimeout &);
239static void free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout *);
32fd6d8a 240
cfcb6b30 241static int parseOneConfigFile(const char *file_name, unsigned int depth);
242
bde7a8ce
CT
243static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues);
244static void dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool recognizeQuotedValues);
245static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues);
3248e962
CT
246static void parse_on_unsupported_protocol(acl_access **access);
247static void dump_on_unsupported_protocol(StoreEntry *entry, const char *name, acl_access *access);
248static void free_on_unsupported_protocol(acl_access **access);
bde7a8ce 249
a385afc3 250/*
251 * LegacyParser is a parser for legacy code that uses the global
252 * approach. This is static so that it is only exposed to cache_cf.
253 * Other modules needing access to a ConfigParser should have it
254 * provided to them in their parserFOO methods.
255 */
256static ConfigParser LegacyParser = ConfigParser();
a9f20260 257
0e4e0e7d 258void
0673c0ba 259self_destruct(void)
090089c4 260{
a9f20260 261 LegacyParser.destruct();
6b8e7481 262}
263
76b9daa5 264static void
265SetConfigFilename(char const *file_name, bool is_pipe)
266{
76b9daa5 267 if (is_pipe)
268 cfg_filename = file_name + 1;
328a3f05
AJ
269 else
270 cfg_filename = file_name;
76b9daa5 271}
272
130bff33 273static const char*
274skip_ws(const char* s)
275{
276 while (xisspace(*s))
277 ++s;
278
279 return s;
280}
281
cfcb6b30 282static int
283parseManyConfigFiles(char* files, int depth)
284{
285 int error_count = 0;
d7ac36b9 286 char* saveptr = NULL;
52303a3d 287#if HAVE_GLOB
592a09dc 288 char *path;
289 glob_t globbuf;
290 int i;
291 memset(&globbuf, 0, sizeof(globbuf));
292 for (path = strwordtok(files, &saveptr); path; path = strwordtok(NULL, &saveptr)) {
26ac0430 293 if (glob(path, globbuf.gl_pathc ? GLOB_APPEND : 0, NULL, &globbuf) != 0) {
b69e9ffa
AJ
294 int xerrno = errno;
295 fatalf("Unable to find configuration file: %s: %s", path, xstrerr(xerrno));
26ac0430
AJ
296 }
297 }
a38ec4b1 298 for (i = 0; i < (int)globbuf.gl_pathc; ++i) {
26ac0430 299 error_count += parseOneConfigFile(globbuf.gl_pathv[i], depth);
cfcb6b30 300 }
592a09dc 301 globfree(&globbuf);
52303a3d 302#else
303 char* file = strwordtok(files, &saveptr);
304 while (file != NULL) {
26ac0430
AJ
305 error_count += parseOneConfigFile(file, depth);
306 file = strwordtok(NULL, &saveptr);
52303a3d 307 }
308#endif /* HAVE_GLOB */
cfcb6b30 309 return error_count;
310}
311
d4a3e179
AR
312static void
313ReplaceSubstr(char*& str, int& len, unsigned substrIdx, unsigned substrLen, const char* newSubstr)
314{
315 assert(str != NULL);
316 assert(newSubstr != NULL);
317
318 unsigned newSubstrLen = strlen(newSubstr);
319 if (newSubstrLen > substrLen)
320 str = (char*)realloc(str, len - substrLen + newSubstrLen + 1);
321
322 // move tail part including zero
323 memmove(str + substrIdx + newSubstrLen, str + substrIdx + substrLen, len - substrIdx - substrLen + 1);
324 // copy new substring in place
325 memcpy(str + substrIdx, newSubstr, newSubstrLen);
326
327 len = strlen(str);
328}
329
330static void
331SubstituteMacro(char*& line, int& len, const char* macroName, const char* substStr)
332{
333 assert(line != NULL);
334 assert(macroName != NULL);
335 assert(substStr != NULL);
336 unsigned macroNameLen = strlen(macroName);
337 while (const char* macroPos = strstr(line, macroName)) // we would replace all occurrences
338 ReplaceSubstr(line, len, macroPos - line, macroNameLen, substStr);
339}
340
341static void
342ProcessMacros(char*& line, int& len)
343{
d5f21615 344 SubstituteMacro(line, len, "${service_name}", service_name.c_str());
9de6c973 345 SubstituteMacro(line, len, "${process_name}", TheKidName);
d4a3e179
AR
346 SubstituteMacro(line, len, "${process_number}", xitoa(KidIdentifier));
347}
348
a7ea9b13
AR
349static void
350trim_trailing_ws(char* str)
351{
352 assert(str != NULL);
353 unsigned i = strlen(str);
354 while ((i > 0) && xisspace(str[i - 1]))
355 --i;
356 str[i] = '\0';
357}
358
359static const char*
360FindStatement(const char* line, const char* statement)
361{
362 assert(line != NULL);
363 assert(statement != NULL);
364
365 const char* str = skip_ws(line);
366 unsigned len = strlen(statement);
367 if (strncmp(str, statement, len) == 0) {
368 str += len;
369 if (*str == '\0')
370 return str;
371 else if (xisspace(*str))
372 return skip_ws(str);
373 }
374
375 return NULL;
376}
377
378static bool
379StrToInt(const char* str, long& number)
380{
381 assert(str != NULL);
382
383 char* end;
384 number = strtol(str, &end, 0);
385
386 return (end != str) && (*end == '\0'); // returns true if string contains nothing except number
387}
388
389static bool
390EvalBoolExpr(const char* expr)
391{
392 assert(expr != NULL);
393 if (strcmp(expr, "true") == 0) {
394 return true;
395 } else if (strcmp(expr, "false") == 0) {
396 return false;
397 } else if (const char* equation = strchr(expr, '=')) {
398 const char* rvalue = skip_ws(equation + 1);
399 char* lvalue = (char*)xmalloc(equation - expr + 1);
400 xstrncpy(lvalue, expr, equation - expr + 1);
401 trim_trailing_ws(lvalue);
402
403 long number1;
404 if (!StrToInt(lvalue, number1))
405 fatalf("String is not a integer number: '%s'\n", lvalue);
406 long number2;
407 if (!StrToInt(rvalue, number2))
408 fatalf("String is not a integer number: '%s'\n", rvalue);
409
410 xfree(lvalue);
411 return number1 == number2;
412 }
413 fatalf("Unable to evaluate expression '%s'\n", expr);
414 return false; // this place cannot be reached
415}
416
cfcb6b30 417static int
418parseOneConfigFile(const char *file_name, unsigned int depth)
2546fcb3 419{
270b86af 420 FILE *fp = NULL;
cfcb6b30 421 const char *orig_cfg_filename = cfg_filename;
422 const int orig_config_lineno = config_lineno;
270b86af 423 char *token = NULL;
81c161d0 424 char *tmp_line = NULL;
425 int tmp_line_len = 0;
e13ee7ad 426 int err_count = 0;
1741cbad 427 int is_pipe = 0;
cfcb6b30 428
e0236918 429 debugs(3, DBG_IMPORTANT, "Processing Configuration File: " << file_name << " (depth " << depth << ")");
cfcb6b30 430 if (depth > 16) {
431 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name);
432 return 1;
433 }
62e76326 434
1741cbad 435 if (file_name[0] == '!' || file_name[0] == '|') {
62e76326 436 fp = popen(file_name + 1, "r");
437 is_pipe = 1;
1741cbad 438 } else {
62e76326 439 fp = fopen(file_name, "r");
1741cbad 440 }
62e76326 441
b69e9ffa
AJ
442 if (!fp) {
443 int xerrno = errno;
444 fatalf("Unable to open configuration file: %s: %s", file_name, xstrerr(xerrno));
445 }
62e76326 446
be266cb2 447#if _SQUID_WINDOWS_
c4aefe96 448 setmode(fileno(fp), O_TEXT);
449#endif
62e76326 450
76b9daa5 451 SetConfigFilename(file_name, bool(is_pipe));
62e76326 452
270b86af 453 memset(config_input_line, '\0', BUFSIZ);
62e76326 454
270b86af 455 config_lineno = 0;
62e76326 456
c8ea3cc0 457 std::vector<bool> if_states;
270b86af 458 while (fgets(config_input_line, BUFSIZ, fp)) {
a38ec4b1 459 ++config_lineno;
62e76326 460
461 if ((token = strchr(config_input_line, '\n')))
462 *token = '\0';
463
d866e2ad 464 if ((token = strchr(config_input_line, '\r')))
465 *token = '\0';
466
f068973f
AJ
467 // strip any prefix whitespace off the line.
468 const char *p = skip_ws(config_input_line);
469 if (config_input_line != p)
470 memmove(config_input_line, p, strlen(p)+1);
471
62e76326 472 if (strncmp(config_input_line, "#line ", 6) == 0) {
473 static char new_file_name[1024];
474 static char *file;
475 static char new_lineno;
476 token = config_input_line + 6;
477 new_lineno = strtol(token, &file, 0) - 1;
478
479 if (file == token)
f53969cc 480 continue; /* Not a valid #line directive, may be a comment */
62e76326 481
e4755e29 482 while (*file && xisspace((unsigned char) *file))
a38ec4b1 483 ++file;
62e76326 484
485 if (*file) {
486 if (*file != '"')
f53969cc 487 continue; /* Not a valid #line directive, may be a comment */
62e76326 488
489 xstrncpy(new_file_name, file + 1, sizeof(new_file_name));
490
491 if ((token = strchr(new_file_name, '"')))
492 *token = '\0';
493
328a3f05 494 SetConfigFilename(new_file_name, false);
62e76326 495 }
496
497 config_lineno = new_lineno;
498 }
499
500 if (config_input_line[0] == '#')
501 continue;
502
503 if (config_input_line[0] == '\0')
504 continue;
505
130bff33 506 const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line;
507
508 size_t append_len = strlen(append);
62e76326 509
130bff33 510 tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1);
81c161d0 511
130bff33 512 strcpy(tmp_line + tmp_line_len, append);
81c161d0 513
130bff33 514 tmp_line_len += append_len;
81c161d0 515
516 if (tmp_line[tmp_line_len-1] == '\\') {
bf8fe701 517 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'");
81c161d0 518 tmp_line[--tmp_line_len] = '\0';
519 continue;
520 }
521
a7ea9b13 522 trim_trailing_ws(tmp_line);
d4a3e179 523 ProcessMacros(tmp_line, tmp_line_len);
dad047ab 524 debugs(3, (opt_parse_cfg_only?1:5), "Processing: " << tmp_line);
62e76326 525
a7ea9b13
AR
526 if (const char* expr = FindStatement(tmp_line, "if")) {
527 if_states.push_back(EvalBoolExpr(expr)); // store last if-statement meaning
528 } else if (FindStatement(tmp_line, "endif")) {
529 if (!if_states.empty())
530 if_states.pop_back(); // remove last if-statement meaning
531 else
532 fatalf("'endif' without 'if'\n");
533 } else if (FindStatement(tmp_line, "else")) {
534 if (!if_states.empty())
535 if_states.back() = !if_states.back();
536 else
537 fatalf("'else' without 'if'\n");
538 } else if (if_states.empty() || if_states.back()) { // test last if-statement meaning if present
539 /* Handle includes here */
540 if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) {
541 err_count += parseManyConfigFiles(tmp_line + 8, depth + 1);
542 } else if (!parse_line(tmp_line)) {
fa84c01d 543 debugs(3, DBG_CRITICAL, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'");
a38ec4b1 544 ++err_count;
a7ea9b13 545 }
26ac0430 546 }
62e76326 547
548 safe_free(tmp_line);
81c161d0 549 tmp_line_len = 0;
550
270b86af 551 }
a7ea9b13
AR
552 if (!if_states.empty())
553 fatalf("if-statement without 'endif'\n");
62e76326 554
1741cbad 555 if (is_pipe) {
62e76326 556 int ret = pclose(fp);
557
558 if (ret != 0)
559 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret);
1741cbad 560 } else {
62e76326 561 fclose(fp);
1741cbad 562 }
62e76326 563
328a3f05 564 SetConfigFilename(orig_cfg_filename, false);
cfcb6b30 565 config_lineno = orig_config_lineno;
566
5c6dae44 567 xfree(tmp_line);
cfcb6b30 568 return err_count;
569}
570
571int
dd9b1081 572parseConfigFile(const char *file_name)
cfcb6b30 573{
574 int err_count = 0;
575
5817ee13
AJ
576 debugs(5, 4, HERE);
577
cfcb6b30 578 configFreeMemory();
579
5491c11e 580 ACLMethodData::ThePurgeCount = 0;
cfcb6b30 581 default_all();
582
583 err_count = parseOneConfigFile(file_name, 0);
584
f0b19334 585 defaults_if_none();
f9ad0106 586
10d914f6
CT
587 defaults_postscriptum();
588
9c46ca97 589 /*
590 * We must call configDoConfigure() before leave_suid() because
591 * configDoConfigure() is where we turn username strings into
592 * uid values.
593 */
594 configDoConfigure();
595
f9ad0106 596 if (!Config.chroot_dir) {
597 leave_suid();
c642c141 598 setUmask(Config.umask);
62493678 599 _db_init(Debug::cache_log, Debug::debugOptions);
f9ad0106 600 enter_suid();
601 }
602
478c4f2f 603 if (opt_send_signal == -1) {
8822ebee 604 Mgr::RegisterAction("config",
d9fc6862
A
605 "Current Squid Configuration",
606 dump_config,
607 1, 1);
478c4f2f 608 }
609
e13ee7ad 610 return err_count;
f0b19334 611}
270b86af 612
f0b19334 613static void
614configDoConfigure(void)
615{
f0b19334 616 memset(&Config2, '\0', sizeof(SquidConfig2));
7021844c 617 /* init memory as early as possible */
618 memConfigure();
270b86af 619 /* Sanity checks */
62e76326 620
b69575d6 621 Config.cacheSwap.n_strands = 0; // no diskers by default
7895fa18
AJ
622 if (Config.cacheSwap.swapDirs == NULL) {
623 /* Memory-only cache probably in effect. */
624 /* turn off the cache rebuild delays... */
625 StoreController::store_dirs_rebuilding = 0;
3b581957
DK
626 } else if (InDaemonMode()) { // no diskers in non-daemon mode
627 for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
628 const RefCount<SwapDir> sd = Config.cacheSwap.swapDirs[i];
629 if (sd->needsDiskStrand())
630 sd->disker = Config.workers + (++Config.cacheSwap.n_strands);
631 }
7895fa18
AJ
632 }
633
47df1aa7
AJ
634 if (Debug::rotateNumber < 0) {
635 Debug::rotateNumber = Config.Log.rotateNumber;
636 }
637
5aecb102 638#if SIZEOF_OFF_T <= 4
639 if (Config.Store.maxObjectSize > 0x7FFF0000) {
fa84c01d 640 debugs(3, DBG_CRITICAL, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
26ac0430 641 Config.Store.maxObjectSize = 0x7FFF0000;
5aecb102 642 }
643#endif
62e76326 644
84f42bac 645 if (Config.Announce.period > 0) {
62e76326 646 Config.onoff.announce = 1;
9376d64c 647 } else {
f53969cc 648 Config.Announce.period = 86400 * 365; /* one year */
62e76326 649 Config.onoff.announce = 0;
270b86af 650 }
62e76326 651
d3caee79 652 if (Config.onoff.httpd_suppress_version_string)
653 visible_appname_string = (char *)appname_string;
654 else
7dbca7a4 655 visible_appname_string = (char const *)APP_FULLNAME;
d3caee79 656
270b86af 657 if (Config.Program.redirect) {
48d54e4d
AJ
658 if (Config.redirectChildren.n_max < 1) {
659 Config.redirectChildren.n_max = 0;
62e76326 660 wordlistDestroy(&Config.Program.redirect);
661 }
fea2e6e0 662 }
62e76326 663
a8a0b1c2
EC
664 if (Config.Program.store_id) {
665 if (Config.storeIdChildren.n_max < 1) {
666 Config.storeIdChildren.n_max = 0;
667 wordlistDestroy(&Config.Program.store_id);
668 }
669 }
670
f1dc9b30 671 if (Config.appendDomain)
62e76326 672 if (*Config.appendDomain != '.')
673 fatal("append_domain must begin with a '.'");
674
270b86af 675 if (Config.errHtmlText == NULL)
62e76326 676 Config.errHtmlText = xstrdup(null_string);
677
1b7fae06
AJ
678#if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
679 if (Config.max_filedescriptors > 0) {
3a9087af 680 debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
1b7fae06
AJ
681 }
682#elif USE_SELECT || USE_SELECT_WIN32
683 if (Config.max_filedescriptors > FD_SETSIZE) {
3a9087af 684 debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors limited to " << FD_SETSIZE << " by select() algorithm.");
1b7fae06
AJ
685 }
686#endif
687
270b86af 688 storeConfigure();
62e76326 689
52f772de 690 snprintf(ThisCache, sizeof(ThisCache), "%s (%s)",
62e76326 691 uniqueHostname(),
d3caee79 692 visible_appname_string);
fbdba7c4 693
38a6c74e 694 /*
695 * the extra space is for loop detection in client_side.c -- we search
696 * for substrings in the Via header.
697 */
52f772de 698 snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)",
62e76326 699 uniqueHostname(),
d3caee79 700 visible_appname_string);
62e76326 701
b2b40d8c
AJ
702 /* Use visible_hostname as default surrogate_id */
703 if (!Config.Accel.surrogate_id) {
704 const char *t = getMyHostname();
705 Config.Accel.surrogate_id = xstrdup( (t?t:"unset-id") );
706 }
707
270b86af 708 if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
62e76326 709 Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
710
270b86af 711 if (Config.appendDomain)
62e76326 712 Config.appendDomainLen = strlen(Config.appendDomain);
270b86af 713 else
62e76326 714 Config.appendDomainLen = 0;
715
31ef19cd
AJ
716 if (Config.connect_retries > 10) {
717 debugs(0,DBG_CRITICAL, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
718 Config.connect_retries = 10;
5210854d 719 }
62e76326 720
f0b19334 721 requirePathnameExists("MIME Config Table", Config.mimeTablePathname);
a3d0a19d 722#if USE_UNLINKD
62e76326 723
f0b19334 724 requirePathnameExists("unlinkd_program", Config.Program.unlinkd);
a3d0a19d 725#endif
82b7abe3 726 requirePathnameExists("logfile_daemon", Log::TheConfig.logfile_daemon);
f0b19334 727 if (Config.Program.redirect)
62e76326 728 requirePathnameExists("redirect_program", Config.Program.redirect->key);
729
a8a0b1c2
EC
730 if (Config.Program.store_id)
731 requirePathnameExists("store_id_program", Config.Program.store_id->key);
732
f0b19334 733 requirePathnameExists("Icon Directory", Config.icons.directory);
62e76326 734
26ac0430 735 if (Config.errorDirectory)
43000484 736 requirePathnameExists("Error Directory", Config.errorDirectory);
62e76326 737
626096be 738#if USE_HTTP_VIOLATIONS
62e76326 739
9f60cfdf 740 {
8d9a8184 741 const RefreshPattern *R;
62e76326 742
26ac0430 743 for (R = Config.Refresh; R; R = R->next) {
62e76326 744 if (!R->flags.override_expire)
745 continue;
746
e0236918 747 debugs(22, DBG_IMPORTANT, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
62e76326 748
749 break;
750 }
751
26ac0430 752 for (R = Config.Refresh; R; R = R->next) {
62e76326 753 if (!R->flags.override_lastmod)
754 continue;
755
e0236918 756 debugs(22, DBG_IMPORTANT, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
62e76326 757
758 break;
759 }
760
26ac0430 761 for (R = Config.Refresh; R; R = R->next) {
38f9c547 762 if (!R->flags.reload_into_ims)
763 continue;
764
e0236918 765 debugs(22, DBG_IMPORTANT, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
38f9c547 766
767 break;
768 }
769
26ac0430 770 for (R = Config.Refresh; R; R = R->next) {
38f9c547 771 if (!R->flags.ignore_reload)
772 continue;
773
e0236918 774 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
38f9c547 775
776 break;
777 }
778
26ac0430 779 for (R = Config.Refresh; R; R = R->next) {
38f9c547 780 if (!R->flags.ignore_no_store)
781 continue;
782
e0236918 783 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
38f9c547 784
785 break;
786 }
787
26ac0430 788 for (R = Config.Refresh; R; R = R->next) {
38f9c547 789 if (!R->flags.ignore_private)
790 continue;
791
e0236918 792 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
38f9c547 793
794 break;
795 }
9f60cfdf 796 }
c2f5c744 797#endif
626096be 798#if !USE_HTTP_VIOLATIONS
c2f5c744 799 Config.onoff.via = 1;
800#else
62e76326 801
c2f5c744 802 if (!Config.onoff.via)
e0236918 803 debugs(22, DBG_IMPORTANT, "WARNING: HTTP requires the use of Via");
62e76326 804
9f60cfdf 805#endif
62e76326 806
5491c11e
AR
807 // we enable runtime PURGE checks if there is at least one PURGE method ACL
808 // TODO: replace with a dedicated "purge" ACL option?
3d9019c7 809 Config2.onoff.enable_purge = (ACLMethodData::ThePurgeCount > 0);
62e76326 810
8749fa47 811 if (geteuid() == 0) {
62e76326 812 if (NULL != Config.effectiveUser) {
813
814 struct passwd *pwd = getpwnam(Config.effectiveUser);
815
5ad8d199 816 if (NULL == pwd) {
62e76326 817 /*
818 * Andres Kroonmaa <andre@online.ee>:
819 * Some getpwnam() implementations (Solaris?) require
820 * an available FD < 256 for opening a FILE* to the
821 * passwd file.
822 * DW:
823 * This should be safe at startup, but might still fail
824 * during reconfigure.
825 */
826 fatalf("getpwnam failed to find userid for effective user '%s'",
827 Config.effectiveUser);
5ad8d199 828 return;
829 }
62e76326 830
831 Config2.effectiveUserID = pwd->pw_uid;
832
833 Config2.effectiveGroupID = pwd->pw_gid;
08ac5ea7 834
cff61cb8 835#if HAVE_PUTENV
cff61cb8 836 if (pwd->pw_dir && *pwd->pw_dir) {
96b9d962
AR
837 // putenv() leaks by design; avoid leaks when nothing changes
838 static SBuf lastDir;
839 if (lastDir.isEmpty() || !lastDir.cmp(pwd->pw_dir)) {
840 lastDir = pwd->pw_dir;
841 int len = strlen(pwd->pw_dir) + 6;
842 char *env_str = (char *)xcalloc(len, 1);
843 snprintf(env_str, len, "HOME=%s", pwd->pw_dir);
844 putenv(env_str);
845 }
cff61cb8 846 }
cff61cb8 847#endif
62e76326 848 }
8749fa47 849 } else {
62e76326 850 Config2.effectiveUserID = geteuid();
851 Config2.effectiveGroupID = getegid();
d20b1cd0 852 }
62e76326 853
d20b1cd0 854 if (NULL != Config.effectiveGroup) {
62e76326 855
856 struct group *grp = getgrnam(Config.effectiveGroup);
857
5ad8d199 858 if (NULL == grp) {
62e76326 859 fatalf("getgrnam failed to find groupid for effective group '%s'",
860 Config.effectiveGroup);
5ad8d199 861 return;
862 }
62e76326 863
864 Config2.effectiveGroupID = grp->gr_gid;
d20b1cd0 865 }
62e76326 866
866be11c
CT
867#if USE_OPENSSL
868 if (Config.ssl_client.foreignIntermediateCertsPath)
869 Ssl::loadSquidUntrusted(Config.ssl_client.foreignIntermediateCertsPath);
870#endif
871
a465e144
AJ
872 if (Security::ProxyOutgoingConfig.encryptTransport) {
873 debugs(3, DBG_IMPORTANT, "Initializing https:// proxy context");
874 Config.ssl_client.sslContext = Security::ProxyOutgoingConfig.createClientContext(false);
91667ff4 875 if (!Config.ssl_client.sslContext) {
79ff8023
AJ
876#if USE_OPENSSL
877 fatal("ERROR: Could not initialize https:// proxy context");
878#else
879 debugs(3, DBG_IMPORTANT, "ERROR: proxying https:// currently still requires --with-openssl");
880#endif
91667ff4 881 }
866be11c 882#if USE_OPENSSL
900daee3 883 Ssl::useSquidUntrusted(Config.ssl_client.sslContext.get());
866be11c 884#endif
a465e144 885 }
f9ad0106 886
a3c6762c 887 for (CachePeer *p = Config.peers; p != NULL; p = p->next) {
1f1f29e8
AJ
888
889 // default value for ssldomain= is the peer host/IP
890 if (p->secure.sslDomain.isEmpty())
891 p->secure.sslDomain = p->host;
892
893 if (p->secure.encryptTransport) {
91667ff4 894 debugs(3, DBG_IMPORTANT, "Initializing cache_peer " << p->name << " TLS context");
a465e144 895 p->sslContext = p->secure.createClientContext(true);
91667ff4
AJ
896 if (!p->sslContext) {
897 debugs(3, DBG_CRITICAL, "ERROR: Could not initialize cache_peer " << p->name << " TLS context");
898 self_destruct();
ba724607 899 return;
91667ff4 900 }
f9ad0106 901 }
04401ab0 902 }
f9ad0106 903
a465e144 904#if USE_OPENSSL
fa720bfb 905 for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) {
339e4d7a 906 if (!s->secure.encryptTransport)
04401ab0 907 continue;
339e4d7a 908 debugs(3, DBG_IMPORTANT, "Initializing " << AnyP::UriScheme(s->transport.protocol) << "_port " << s->s << " TLS context");
5ae65581 909 s->configureSslServerContext();
04401ab0 910 }
a7ad6e4e 911#endif
1f771fed
AJ
912
913 // prevent infinite fetch loops in the request parser
914 // due to buffer full but not enough data recived to finish parse
915 if (Config.maxRequestBufferSize <= Config.maxRequestHeaderSize) {
d0bbf50e 916 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
1f771fed 917 " Change client_request_buffer_max or request_header_max_size limits.",
d0bbf50e 918 (uint32_t)Config.maxRequestBufferSize, (uint32_t)Config.maxRequestHeaderSize);
1f771fed 919 }
a0e23afd 920
079a8480
AJ
921 /*
922 * Disable client side request pipelining if client_persistent_connections OFF.
923 * Waste of resources queueing any pipelined requests when the first will close the connection.
924 */
925 if (Config.pipeline_max_prefetch > 0 && !Config.onoff.client_pconns) {
926 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: pipeline_prefetch " << Config.pipeline_max_prefetch <<
cba78478 927 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
079a8480
AJ
928 Config.pipeline_max_prefetch = 0;
929 }
930
2f1431ea 931#if USE_AUTH
a0e23afd
AJ
932 /*
933 * disable client side request pipelining. There is a race with
934 * Negotiate and NTLM when the client sends a second request on an
935 * connection before the authenticate challenge is sent. With
936 * pipelining OFF, the client may fail to authenticate, but squid's
937 * state will be preserved.
938 */
079a8480 939 if (Config.pipeline_max_prefetch > 0) {
9f3d2b2e
AJ
940 Auth::Config *nego = Auth::Config::Find("Negotiate");
941 Auth::Config *ntlm = Auth::Config::Find("NTLM");
a0e23afd 942 if ((nego && nego->active()) || (ntlm && ntlm->active())) {
079a8480
AJ
943 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
944 Config.pipeline_max_prefetch = 0;
a0e23afd
AJ
945 }
946 }
2f1431ea 947#endif
090089c4 948}
949
76f44481
AJ
950/** Parse a line containing an obsolete directive.
951 * To upgrade it where possible instead of just "Bungled config" for
952 * directives which cannot be marked as simply aliases of the some name.
953 * For example if the parameter order and content has changed.
954 * Or if the directive has been completely removed.
955 */
956void
957parse_obsolete(const char *name)
958{
959 // Directives which have been radically changed rather than removed
960 if (!strcmp(name, "url_rewrite_concurrency")) {
254d8ef1
AJ
961 int cval;
962 parse_int(&cval);
76f44481 963 debugs(3, DBG_CRITICAL, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
254d8ef1 964 Config.redirectChildren.concurrency = cval;
76f44481 965 }
8ebad780 966
ba724607 967 if (!strcmp(name, "log_access")) {
8ebad780 968 self_destruct();
ba724607
AJ
969 return;
970 }
8ebad780 971
ba724607 972 if (!strcmp(name, "log_icap")) {
8ebad780 973 self_destruct();
ba724607
AJ
974 return;
975 }
96598f93
AJ
976
977 if (!strcmp(name, "ignore_ims_on_miss")) {
978 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
979 // than the 2.7 directive. We need to parse and invert the configured value.
980 int temp = 0;
981 parse_onoff(&temp);
982 Config.onoff.cache_miss_revalidate = !temp;
983 }
7e62a74f
AJ
984
985 if (!strncmp(name, "sslproxy_", 9)) {
986 // the replacement directive tls_outgoing_options uses options instead of whole-line input
987 SBuf tmp;
988 if (!strcmp(name, "sslproxy_cafile"))
989 tmp.append("cafile=");
990 else if (!strcmp(name, "sslproxy_capath"))
991 tmp.append("capath=");
992 else if (!strcmp(name, "sslproxy_cipher"))
993 tmp.append("cipher=");
994 else if (!strcmp(name, "sslproxy_client_certificate"))
995 tmp.append("cert=");
996 else if (!strcmp(name, "sslproxy_client_key"))
997 tmp.append("key=");
998 else if (!strcmp(name, "sslproxy_flags"))
999 tmp.append("flags=");
1000 else if (!strcmp(name, "sslproxy_options"))
1001 tmp.append("options=");
1002 else if (!strcmp(name, "sslproxy_version"))
1003 tmp.append("version=");
1004 else {
1005 debugs(3, DBG_CRITICAL, "ERROR: unknown directive: " << name);
1006 self_destruct();
ba724607 1007 return;
7e62a74f
AJ
1008 }
1009
1010 // add the value as unquoted-string because the old values did not support whitespace
1011 const char *token = ConfigParser::NextQuotedOrToEol();
1012 tmp.append(token, strlen(token));
1013 Security::ProxyOutgoingConfig.parse(tmp.c_str());
1014 }
76f44481
AJ
1015}
1016
270b86af 1017/* Parse a time specification from the config file. Store the
f1dc9b30 1018 * result in 'tptr', after converting it to 'units' */
8203a132 1019static void
32fd6d8a 1020parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec, bool expectMoreArguments = false)
090089c4 1021{
ba724607
AJ
1022 time_msec_t u = parseTimeUnits(units, allowMsec);
1023 if (u == 0) {
62e76326 1024 self_destruct();
ba724607
AJ
1025 return;
1026 }
62e76326 1027
ba724607
AJ
1028 char *token = ConfigParser::NextToken();;
1029 if (!token) {
62e76326 1030 self_destruct();
ba724607
AJ
1031 return;
1032 }
62e76326 1033
65ae31c6 1034 double d = xatof(token);
62e76326 1035
65ae31c6 1036 time_msec_t m = u; /* default to 'units' if none specified */
62e76326 1037
65ae31c6
AJ
1038 if (d) {
1039 if ((token = ConfigParser::PeekAtToken()) && (m = parseTimeUnits(token, allowMsec))) {
1040 (void)ConfigParser::NextToken();
62e76326 1041
65ae31c6 1042 } else if (!expectMoreArguments) {
32fd6d8a 1043 self_destruct();
ba724607 1044 return;
65ae31c6
AJ
1045
1046 } else {
1047 token = NULL; // show default units if dying below
1048 debugs(3, DBG_CRITICAL, "WARNING: No units on '" << config_input_line << "', assuming " << d << " " << units);
1049 }
1050 } else
1051 token = NULL; // show default units if dying below.
62e76326 1052
fd0f51c4 1053 *tptr = static_cast<time_msec_t>(m * d);
54a063a2
TX
1054
1055 if (static_cast<double>(*tptr) * 2 != m * d * 2) {
65ae31c6
AJ
1056 debugs(3, DBG_CRITICAL, "FATAL: Invalid value '" <<
1057 d << " " << (token ? token : units) << ": integer overflow (time_msec_t).");
54a063a2
TX
1058 self_destruct();
1059 }
090089c4 1060}
1061
fd0f51c4 1062static uint64_t
9b741834 1063parseTimeUnits(const char *unit, bool allowMsec)
270b86af 1064{
9b741834 1065 if (allowMsec && !strncasecmp(unit, T_MILLISECOND_STR, strlen(T_MILLISECOND_STR)))
62e76326 1066 return 1;
1067
fd0f51c4
CT
1068 if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR)))
1069 return 1000;
1070
270b86af 1071 if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR)))
fd0f51c4 1072 return 60 * 1000;
62e76326 1073
270b86af 1074 if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR)))
fd0f51c4 1075 return 3600 * 1000;
62e76326 1076
270b86af 1077 if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR)))
fd0f51c4 1078 return 86400 * 1000;
62e76326 1079
270b86af 1080 if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR)))
fd0f51c4 1081 return 86400 * 7 * 1000;
62e76326 1082
270b86af 1083 if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR)))
fd0f51c4 1084 return 86400 * 14 * 1000;
62e76326 1085
270b86af 1086 if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR)))
fd0f51c4 1087 return static_cast<uint64_t>(86400) * 30 * 1000;
62e76326 1088
270b86af 1089 if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR)))
fd0f51c4 1090 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
62e76326 1091
270b86af 1092 if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR)))
fd0f51c4 1093 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
62e76326 1094
e0236918 1095 debugs(3, DBG_IMPORTANT, "parseTimeUnits: unknown time unit '" << unit << "'");
62e76326 1096
270b86af 1097 return 0;
1098}
1099
47f6e231 1100static void
1101parseBytesLine64(int64_t * bptr, const char *units)
1102{
1103 char *token;
1104 double d;
1105 int64_t m;
1106 int64_t u;
1107
9eeb8e4b 1108 if ((u = parseBytesUnits(units)) == 0) {
47f6e231 1109 self_destruct();
9eeb8e4b 1110 return;
1111 }
47f6e231 1112
2eceb328 1113 if ((token = ConfigParser::NextToken()) == NULL) {
47f6e231 1114 self_destruct();
9eeb8e4b 1115 return;
1116 }
47f6e231 1117
1118 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
bc41416d 1119 *bptr = -1;
47f6e231 1120 return;
1121 }
1122
1123 d = xatof(token);
1124
f53969cc 1125 m = u; /* default to 'units' if none specified */
47f6e231 1126
1127 if (0.0 == d)
1128 (void) 0;
2eceb328 1129 else if ((token = ConfigParser::NextToken()) == NULL)
fa84c01d 1130 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
26ac0430
AJ
1131 config_input_line << "', assuming " <<
1132 d << " " << units );
9eeb8e4b 1133 else if ((m = parseBytesUnits(token)) == 0) {
47f6e231 1134 self_destruct();
9eeb8e4b 1135 return;
1136 }
47f6e231 1137
1138 *bptr = static_cast<int64_t>(m * d / u);
1139
54a063a2
TX
1140 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2) {
1141 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1142 d << " " << token << ": integer overflow (int64_t).");
47f6e231 1143 self_destruct();
54a063a2 1144 }
47f6e231 1145}
1146
9906e724 1147static void
9e975e4e 1148parseBytesLine(size_t * bptr, const char *units)
9906e724 1149{
1150 char *token;
1151 double d;
47f6e231 1152 int m;
1153 int u;
62e76326 1154
9eeb8e4b 1155 if ((u = parseBytesUnits(units)) == 0) {
62e76326 1156 self_destruct();
9eeb8e4b 1157 return;
1158 }
62e76326 1159
2eceb328 1160 if ((token = ConfigParser::NextToken()) == NULL) {
62e76326 1161 self_destruct();
9eeb8e4b 1162 return;
1163 }
62e76326 1164
f8ecd7d7 1165 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
b2d729e6 1166 *bptr = static_cast<size_t>(-1);
ef1955a5 1167 return;
1168 }
1169
5c20d6fa 1170 d = xatof(token);
62e76326 1171
f53969cc 1172 m = u; /* default to 'units' if none specified */
62e76326 1173
343f47a3 1174 if (0.0 == d)
62e76326 1175 (void) 0;
2eceb328 1176 else if ((token = ConfigParser::NextToken()) == NULL)
fa84c01d 1177 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
26ac0430
AJ
1178 config_input_line << "', assuming " <<
1179 d << " " << units );
9eeb8e4b 1180 else if ((m = parseBytesUnits(token)) == 0) {
62e76326 1181 self_destruct();
9eeb8e4b 1182 return;
1183 }
62e76326 1184
e6ccf245 1185 *bptr = static_cast<size_t>(m * d / u);
347ae7c4 1186
54a063a2
TX
1187 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2) {
1188 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1189 d << " " << token << ": integer overflow (size_t).");
347ae7c4 1190 self_destruct();
54a063a2 1191 }
9906e724 1192}
1193
e210930b
AJ
1194static void
1195parseBytesLineSigned(ssize_t * bptr, const char *units)
1196{
1197 char *token;
1198 double d;
1199 int m;
1200 int u;
1201
1202 if ((u = parseBytesUnits(units)) == 0) {
1203 self_destruct();
1204 return;
1205 }
1206
2eceb328 1207 if ((token = ConfigParser::NextToken()) == NULL) {
e210930b
AJ
1208 self_destruct();
1209 return;
1210 }
1211
1212 if (strcmp(token, "none") == 0 || token[0] == '-' /* -N */) {
1213 *bptr = -1;
1214 return;
1215 }
1216
1217 d = xatof(token);
1218
f53969cc 1219 m = u; /* default to 'units' if none specified */
e210930b
AJ
1220
1221 if (0.0 == d)
1222 (void) 0;
2eceb328 1223 else if ((token = ConfigParser::NextToken()) == NULL)
fa84c01d 1224 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
e210930b
AJ
1225 config_input_line << "', assuming " <<
1226 d << " " << units );
1227 else if ((m = parseBytesUnits(token)) == 0) {
1228 self_destruct();
1229 return;
1230 }
1231
54a063a2 1232 *bptr = static_cast<ssize_t>(m * d / u);
e210930b 1233
54a063a2
TX
1234 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2) {
1235 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1236 d << " " << token << ": integer overflow (ssize_t).");
e210930b 1237 self_destruct();
54a063a2 1238 }
e210930b 1239}
e210930b 1240
95d2589c
CT
1241/**
1242 * Parse bytes from a string.
1243 * Similar to the parseBytesLine function but parses the string value instead of
1244 * the current token value.
1245 */
1246static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value)
1247{
1248 int u;
1249 if ((u = parseBytesUnits(units)) == 0) {
1250 self_destruct();
1251 return;
1252 }
1253
1254 // Find number from string beginning.
1255 char const * number_begin = value;
1256 char const * number_end = value;
1257
1258 while ((*number_end >= '0' && *number_end <= '9')) {
a38ec4b1 1259 ++number_end;
95d2589c
CT
1260 }
1261
1262 String number;
1263 number.limitInit(number_begin, number_end - number_begin);
1264
1265 int d = xatoi(number.termedBuf());
1266 int m;
1267 if ((m = parseBytesUnits(number_end)) == 0) {
1268 self_destruct();
1269 return;
1270 }
1271
1272 *bptr = static_cast<size_t>(m * d / u);
54a063a2 1273 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2)
95d2589c
CT
1274 self_destruct();
1275}
95d2589c 1276
9906e724 1277static size_t
1278parseBytesUnits(const char *unit)
1279{
1280 if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR)))
62e76326 1281 return 1;
1282
9906e724 1283 if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR)))
62e76326 1284 return 1 << 10;
1285
9906e724 1286 if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR)))
62e76326 1287 return 1 << 20;
1288
9906e724 1289 if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR)))
62e76326 1290 return 1 << 30;
1291
fa37412f 1292 debugs(3, DBG_CRITICAL, "WARNING: Unknown bytes unit '" << unit << "'");
62e76326 1293
9906e724 1294 return 0;
1295}
1296
8203a132 1297static void
dfad5100 1298dump_SBufList(StoreEntry * entry, const SBufList &words)
090089c4 1299{
dfad5100
FC
1300 for (SBufList::const_iterator i = words.begin(); i != words.end(); ++i) {
1301 entry->append(i->rawContent(), i->length());
1302 entry->append(" ",1);
1303 }
86f84bd1 1304 entry->append("\n",1);
6f58d7d7 1305}
62e76326 1306
6f58d7d7
AR
1307static void
1308dump_acl(StoreEntry * entry, const char *name, ACL * ae)
1309{
9ef28b60 1310 while (ae != NULL) {
bf8fe701 1311 debugs(3, 3, "dump_acl: " << name << " " << ae->name);
33810b1d 1312 storeAppendPrintf(entry, "%s %s %s %s ",
62e76326 1313 name,
1314 ae->name,
33810b1d
CT
1315 ae->typeString(),
1316 ae->flags.flagsStr());
dfad5100 1317 dump_SBufList(entry, ae->dump());
62e76326 1318 ae = ae->next;
56b63fa1 1319 }
090089c4 1320}
1321
8203a132 1322static void
97427e90 1323parse_acl(ACL ** ae)
090089c4 1324{
a9f20260 1325 ACL::ParseAclLine(LegacyParser, ae);
f1dc9b30 1326}
1327
1328static void
97427e90 1329free_acl(ACL ** ae)
f1dc9b30 1330{
9ef28b60 1331 aclDestroyAcls(ae);
090089c4 1332}
1333
425de4c8 1334void
76cd39d7 1335dump_acl_list(StoreEntry * entry, ACLList * head)
30a4f2a8 1336{
dfad5100 1337 dump_SBufList(entry, head->dump());
d6827718 1338}
1339
b67e2c8c 1340void
d6827718 1341dump_acl_access(StoreEntry * entry, const char *name, acl_access * head)
1342{
dfad5100 1343 if (head)
fbe0f952 1344 dump_SBufList(entry, head->treeDump(name,NULL));
30a4f2a8 1345}
090089c4 1346
8203a132 1347static void
16300b58 1348parse_acl_access(acl_access ** head)
090089c4 1349{
6f58d7d7
AR
1350 aclParseAccessLine(cfg_directive, LegacyParser, head);
1351}
1352
0153d498 1353static void
16300b58 1354free_acl_access(acl_access ** head)
0153d498 1355{
a47b9029 1356 aclDestroyAccessList(head);
0153d498 1357}
1358
8203a132 1359static void
b7ac5457 1360dump_address(StoreEntry * entry, const char *name, Ip::Address &addr)
270b86af 1361{
cc192b50 1362 char buf[MAX_IPSTRLEN];
4dd643d5 1363 storeAppendPrintf(entry, "%s %s\n", name, addr.toStr(buf,MAX_IPSTRLEN) );
270b86af 1364}
1365
1366static void
b7ac5457 1367parse_address(Ip::Address *addr)
090089c4 1368{
2eceb328 1369 char *token = ConfigParser::NextToken();
270b86af 1370
9eeb8e4b 1371 if (!token) {
62e76326 1372 self_destruct();
9eeb8e4b 1373 return;
1374 }
62e76326 1375
9f2665ee 1376 if (!strcmp(token,"any_addr"))
4dd643d5 1377 addr->setAnyAddr();
9f2665ee 1378 else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) )
4dd643d5 1379 addr->setNoAddr();
9f2665ee 1380 else if ( (*addr = token) ) // try parse numeric/IPA
26ac0430 1381 (void) 0;
36a83790
AJ
1382 else if (addr->GetHostByName(token)) // dont use ipcache
1383 (void) 0;
1384 else { // not an IP and not a hostname
1385 debugs(3, DBG_CRITICAL, "FATAL: invalid IP address or domain name '" << token << "'");
1386 self_destruct();
1387 }
090089c4 1388}
1389
0153d498 1390static void
b7ac5457 1391free_address(Ip::Address *addr)
0153d498 1392{
4dd643d5 1393 addr->setEmpty();
0153d498 1394}
1395
d6827718 1396static void
289848ca 1397dump_acl_address(StoreEntry * entry, const char *name, Acl::Address * head)
d6827718 1398{
cc192b50 1399 char buf[MAX_IPSTRLEN];
62e76326 1400
289848ca 1401 for (Acl::Address *l = head; l; l = l->next) {
4dd643d5
AJ
1402 if (!l->addr.isAnyAddr())
1403 storeAppendPrintf(entry, "%s %s", name, l->addr.toStr(buf,MAX_IPSTRLEN));
62e76326 1404 else
1405 storeAppendPrintf(entry, "%s autoselect", name);
1406
1407 dump_acl_list(entry, l->aclList);
1408
1409 storeAppendPrintf(entry, "\n");
d6827718 1410 }
1411}
1412
1413static void
289848ca 1414parse_acl_address(Acl::Address ** head)
d6827718 1415{
289848ca 1416 Acl::Address *l = new Acl::Address;
d6827718 1417 parse_address(&l->addr);
6f58d7d7 1418 aclParseAclList(LegacyParser, &l->aclList, l->addr);
62e76326 1419
289848ca 1420 Acl::Address **tail = head;
d6827718 1421 while (*tail)
62e76326 1422 tail = &(*tail)->next;
1423
d6827718 1424 *tail = l;
1425}
1426
1427static void
289848ca 1428free_acl_address(Acl::Address ** head)
d6827718 1429{
289848ca
AJ
1430 delete *head;
1431 *head = NULL;
d6827718 1432}
1433
d6827718 1434static void
1435dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head)
1436{
1437 acl_tos *l;
62e76326 1438
d6827718 1439 for (l = head; l; l = l->next) {
62e76326 1440 if (l->tos > 0)
1441 storeAppendPrintf(entry, "%s 0x%02X", name, l->tos);
1442 else
1443 storeAppendPrintf(entry, "%s none", name);
1444
1445 dump_acl_list(entry, l->aclList);
1446
1447 storeAppendPrintf(entry, "\n");
d6827718 1448 }
1449}
1450
d6827718 1451static void
1452parse_acl_tos(acl_tos ** head)
1453{
425de4c8 1454 unsigned int tos; /* Initially uint for strtoui. Casted to tos_t before return */
2eceb328 1455 char *token = ConfigParser::NextToken();
62e76326 1456
9eeb8e4b 1457 if (!token) {
62e76326 1458 self_destruct();
9eeb8e4b 1459 return;
1460 }
62e76326 1461
425de4c8 1462 if (!xstrtoui(token, NULL, &tos, 0, std::numeric_limits<tos_t>::max())) {
62e76326 1463 self_destruct();
9eeb8e4b 1464 return;
1465 }
62e76326 1466
c6f168c1
CT
1467 const unsigned int chTos = tos & 0xFC;
1468 if (chTos != tos) {
1469 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: Tos value '" << tos << "' adjusted to '" << chTos << "'");
1470 tos = chTos;
1471 }
1472
60019fea 1473 acl_tos *l = new acl_tos;
62e76326 1474
425de4c8 1475 l->tos = (tos_t)tos;
62e76326 1476
6f58d7d7 1477 aclParseAclList(LegacyParser, &l->aclList, token);
62e76326 1478
60019fea 1479 acl_tos **tail = head; /* sane name below */
d6827718 1480 while (*tail)
62e76326 1481 tail = &(*tail)->next;
1482
d6827718 1483 *tail = l;
1484}
1485
1486static void
1487free_acl_tos(acl_tos ** head)
1488{
60019fea
AJ
1489 delete *head;
1490 head = NULL;
d6827718 1491}
1492
11e8cfe3 1493#if SO_MARK && USE_LIBCAP
f4f6c2e0 1494
425de4c8
AJ
1495static void
1496dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head)
1497{
60019fea 1498 for (acl_nfmark *l = head; l; l = l->next) {
425de4c8
AJ
1499 if (l->nfmark > 0)
1500 storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark);
1501 else
1502 storeAppendPrintf(entry, "%s none", name);
1503
1504 dump_acl_list(entry, l->aclList);
1505
1506 storeAppendPrintf(entry, "\n");
1507 }
1508}
1509
425de4c8
AJ
1510static void
1511parse_acl_nfmark(acl_nfmark ** head)
1512{
425de4c8 1513 nfmark_t mark;
2eceb328 1514 char *token = ConfigParser::NextToken();
425de4c8
AJ
1515
1516 if (!token) {
1517 self_destruct();
1518 return;
1519 }
1520
1521 if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) {
1522 self_destruct();
1523 return;
1524 }
1525
60019fea 1526 acl_nfmark *l = new acl_nfmark;
425de4c8
AJ
1527
1528 l->nfmark = mark;
1529
6f58d7d7 1530 aclParseAclList(LegacyParser, &l->aclList, token);
425de4c8 1531
60019fea 1532 acl_nfmark **tail = head; /* sane name below */
425de4c8
AJ
1533 while (*tail)
1534 tail = &(*tail)->next;
1535
1536 *tail = l;
1537}
1538
1539static void
1540free_acl_nfmark(acl_nfmark ** head)
1541{
60019fea
AJ
1542 delete *head;
1543 head = NULL;
425de4c8 1544}
f4f6c2e0 1545#endif /* SO_MARK */
425de4c8 1546
ef1955a5 1547static void
1328cfb7 1548dump_acl_b_size_t(StoreEntry * entry, const char *name, AclSizeLimit * head)
ef1955a5 1549{
d21b3722 1550 for (AclSizeLimit *l = head; l; l = l->next) {
ed013b6c 1551 if (l->size != -1)
ef1955a5 1552 storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR);
1553 else
1554 storeAppendPrintf(entry, "%s none", name);
1555
1556 dump_acl_list(entry, l->aclList);
1557
1558 storeAppendPrintf(entry, "\n");
1559 }
1560}
1561
ef1955a5 1562static void
1328cfb7 1563parse_acl_b_size_t(AclSizeLimit ** head)
ef1955a5 1564{
d21b3722 1565 AclSizeLimit *l = new AclSizeLimit;
ef1955a5 1566
47f6e231 1567 parse_b_int64_t(&l->size);
ef1955a5 1568
6f58d7d7 1569 aclParseAclList(LegacyParser, &l->aclList, l->size);
ef1955a5 1570
d21b3722 1571 AclSizeLimit **tail = head; /* sane name below */
ef1955a5 1572 while (*tail)
1573 tail = &(*tail)->next;
1574
1575 *tail = l;
1576}
1577
1578static void
1328cfb7 1579free_acl_b_size_t(AclSizeLimit ** head)
ef1955a5 1580{
d21b3722
AJ
1581 delete *head;
1582 *head = NULL;
ef1955a5 1583}
1584
9a0a18de 1585#if USE_DELAY_POOLS
59715b38 1586
b67e2c8c 1587#include "DelayConfig.h"
602d9612 1588#include "DelayPools.h"
59715b38 1589/* do nothing - free_delay_pool_count is the magic free function.
ae870270 1590 * this is why delay_pool_count isn't just marked TYPE: u_short
59715b38 1591 */
1592#define free_delay_pool_class(X)
1593#define free_delay_pool_access(X)
1594#define free_delay_pool_rates(X)
1595#define dump_delay_pool_class(X, Y, Z)
1596#define dump_delay_pool_access(X, Y, Z)
1597#define dump_delay_pool_rates(X, Y, Z)
1598
1599static void
b67e2c8c 1600free_delay_pool_count(DelayConfig * cfg)
59715b38 1601{
b67e2c8c 1602 cfg->freePoolCount();
59715b38 1603}
1604
1605static void
b67e2c8c 1606dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg)
59715b38 1607{
b67e2c8c 1608 cfg.dumpPoolCount (entry, name);
59715b38 1609}
1610
1611static void
b67e2c8c 1612parse_delay_pool_count(DelayConfig * cfg)
59715b38 1613{
b67e2c8c 1614 cfg->parsePoolCount();
59715b38 1615}
1616
1617static void
b67e2c8c 1618parse_delay_pool_class(DelayConfig * cfg)
59715b38 1619{
b67e2c8c 1620 cfg->parsePoolClass();
59715b38 1621}
1622
1623static void
b67e2c8c 1624parse_delay_pool_rates(DelayConfig * cfg)
59715b38 1625{
b67e2c8c 1626 cfg->parsePoolRates();
59715b38 1627}
1628
1629static void
b67e2c8c 1630parse_delay_pool_access(DelayConfig * cfg)
59715b38 1631{
a9f20260 1632 cfg->parsePoolAccess(LegacyParser);
59715b38 1633}
62e76326 1634
59715b38 1635#endif
1636
9a0a18de 1637#if USE_DELAY_POOLS
b4cd430a
CT
1638#include "ClientDelayConfig.h"
1639/* do nothing - free_client_delay_pool_count is the magic free function.
ae870270 1640 * this is why client_delay_pool_count isn't just marked TYPE: u_short
b4cd430a
CT
1641 */
1642
1643#define free_client_delay_pool_access(X)
1644#define free_client_delay_pool_rates(X)
1645#define dump_client_delay_pool_access(X, Y, Z)
1646#define dump_client_delay_pool_rates(X, Y, Z)
1647
1648static void
1649free_client_delay_pool_count(ClientDelayConfig * cfg)
1650{
1651 cfg->freePoolCount();
1652}
1653
1654static void
1655dump_client_delay_pool_count(StoreEntry * entry, const char *name, ClientDelayConfig &cfg)
1656{
1657 cfg.dumpPoolCount (entry, name);
1658}
1659
1660static void
1661parse_client_delay_pool_count(ClientDelayConfig * cfg)
1662{
1663 cfg->parsePoolCount();
1664}
1665
1666static void
1667parse_client_delay_pool_rates(ClientDelayConfig * cfg)
1668{
1669 cfg->parsePoolRates();
1670}
1671
1672static void
1673parse_client_delay_pool_access(ClientDelayConfig * cfg)
1674{
1675 cfg->parsePoolAccess(LegacyParser);
1676}
1677#endif
1678
626096be 1679#if USE_HTTP_VIOLATIONS
97474590 1680static void
3b07476b 1681dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
e3dd531e 1682{
3b07476b
CT
1683 if (manglers)
1684 manglers->dumpAccess(entry, name);
97474590 1685}
e3dd531e 1686
97474590 1687static void
3b07476b 1688parse_http_header_access(HeaderManglers **pm)
97474590 1689{
97474590 1690 char *t = NULL;
62e76326 1691
2eceb328 1692 if ((t = ConfigParser::NextToken()) == NULL) {
fa84c01d
FC
1693 debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1694 debugs(3, DBG_CRITICAL, "parse_http_header_access: missing header name.");
62e76326 1695 return;
97474590 1696 }
62e76326 1697
3b07476b
CT
1698 if (!*pm)
1699 *pm = new HeaderManglers;
1700 HeaderManglers *manglers = *pm;
001d55dc 1701 headerMangler *mangler = manglers->track(t);
3b07476b 1702 assert(mangler);
6f58d7d7
AR
1703
1704 std::string directive = "http_header_access ";
1705 directive += t;
2450353f 1706 aclParseAccessLine(directive.c_str(), LegacyParser, &mangler->access_list);
6bccf575 1707}
1708
1709static void
3b07476b 1710free_HeaderManglers(HeaderManglers **pm)
6bccf575 1711{
3b07476b
CT
1712 // we delete the entire http_header_* mangler configuration at once
1713 if (const HeaderManglers *manglers = *pm) {
1714 delete manglers;
1715 *pm = NULL;
6bccf575 1716 }
1717}
1718
1719static void
3b07476b 1720dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
6bccf575 1721{
3b07476b
CT
1722 if (manglers)
1723 manglers->dumpReplacement(entry, name);
97474590 1724}
e3dd531e 1725
97474590 1726static void
3b07476b 1727parse_http_header_replace(HeaderManglers **pm)
e3dd531e 1728{
6bccf575 1729 char *t = NULL;
62e76326 1730
2eceb328 1731 if ((t = ConfigParser::NextToken()) == NULL) {
fa84c01d
FC
1732 debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1733 debugs(3, DBG_CRITICAL, "parse_http_header_replace: missing header name.");
62e76326 1734 return;
6bccf575 1735 }
62e76326 1736
bde7a8ce 1737 const char *value = ConfigParser::NextQuotedOrToEol();
62e76326 1738
3b07476b
CT
1739 if (!*pm)
1740 *pm = new HeaderManglers;
1741 HeaderManglers *manglers = *pm;
1742 manglers->setReplacement(t, value);
97474590 1743}
62e76326 1744
9e8b2f1c 1745#endif
97474590 1746
e90100aa 1747static void
2745fea5 1748dump_cachedir(StoreEntry * entry, const char *name, const Store::DiskConfig &swap)
e90100aa 1749{
f53b06f9 1750 SwapDir *s;
1751 int i;
d3b3ab85 1752 assert (entry);
62e76326 1753
a38ec4b1 1754 for (i = 0; i < swap.n_configured; ++i) {
c8f4eac4 1755 s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw());
26ac0430 1756 if (!s) continue;
59b2d47f 1757 storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path);
62e76326 1758 s->dump(*entry);
62e76326 1759 storeAppendPrintf(entry, "\n");
f53b06f9 1760 }
1761}
1762
53ad48e6 1763static int
1764check_null_string(char *s)
1765{
1766 return s == NULL;
1767}
1768
2f1431ea 1769#if USE_AUTH
94439e4e 1770static void
9f3d2b2e 1771parse_authparam(Auth::ConfigVector * config)
94439e4e 1772{
ba724607
AJ
1773 char *type_str = ConfigParser::NextToken();
1774 if (!type_str) {
62e76326 1775 self_destruct();
ba724607
AJ
1776 return;
1777 }
94439e4e 1778
ba724607
AJ
1779 char *param_str = ConfigParser::NextToken();
1780 if (!param_str) {
62e76326 1781 self_destruct();
ba724607
AJ
1782 return;
1783 }
94439e4e 1784
5817ee13 1785 /* find a configuration for the scheme in the currently parsed configs... */
9f3d2b2e 1786 Auth::Config *schemeCfg = Auth::Config::Find(type_str);
62e76326 1787
5817ee13
AJ
1788 if (schemeCfg == NULL) {
1789 /* Create a configuration based on the scheme info */
c6cf8dee 1790 Auth::Scheme::Pointer theScheme = Auth::Scheme::Find(type_str);
f5691f9c 1791
5817ee13
AJ
1792 if (theScheme == NULL) {
1793 debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'.");
1794 self_destruct();
ba724607 1795 return;
62e76326 1796 }
94439e4e 1797
f5691f9c 1798 config->push_back(theScheme->createConfig());
9f3d2b2e 1799 schemeCfg = Auth::Config::Find(type_str);
5817ee13
AJ
1800 if (schemeCfg == NULL) {
1801 debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'.");
1802 self_destruct();
ba724607 1803 return;
5817ee13 1804 }
94439e4e 1805 }
62e76326 1806
5817ee13 1807 schemeCfg->parse(schemeCfg, config->size(), param_str);
94439e4e 1808}
1809
1810static void
9f3d2b2e 1811free_authparam(Auth::ConfigVector * cfg)
94439e4e 1812{
5817ee13 1813 /* Wipe the Auth globals and Detach/Destruct component config + state. */
c33a88ca 1814 cfg->clear();
62e76326 1815
5817ee13 1816 /* on reconfigure initialize new auth schemes for the new config. */
ec5858ff 1817 if (reconfiguring) {
ccd8a22a 1818 Auth::Init();
94439e4e 1819 }
94439e4e 1820}
1821
1822static void
9f3d2b2e 1823dump_authparam(StoreEntry * entry, const char *name, Auth::ConfigVector cfg)
94439e4e 1824{
9f3d2b2e 1825 for (Auth::ConfigVector::iterator i = cfg.begin(); i != cfg.end(); ++i)
f5691f9c 1826 (*i)->dump(entry, name, (*i));
94439e4e 1827}
2f1431ea 1828#endif /* USE_AUTH */
94439e4e 1829
59b2d47f 1830/* TODO: just return the object, the # is irrelevant */
cd748f27 1831static int
1832find_fstype(char *type)
1833{
59b2d47f 1834 for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i)
4c9eadc2 1835 if (strcasecmp(type, StoreFileSystem::FileSystems().at(i)->type()) == 0)
59b2d47f 1836 return (int)i;
62e76326 1837
cd748f27 1838 return (-1);
1839}
1840
0e4e0e7d 1841static void
2745fea5 1842parse_cachedir(Store::DiskConfig *swap)
0e4e0e7d 1843{
ba724607
AJ
1844 char *type_str = ConfigParser::NextToken();
1845 if (!type_str) {
62e76326 1846 self_destruct();
ba724607
AJ
1847 return;
1848 }
cd748f27 1849
ba724607
AJ
1850 char *path_str = ConfigParser::NextToken();
1851 if (!path_str) {
62e76326 1852 self_destruct();
ba724607
AJ
1853 return;
1854 }
cd748f27 1855
ba724607 1856 int fs = find_fstype(type_str);
d1a37072
AJ
1857 if (fs < 0) {
1858 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: This proxy does not support the '" << type_str << "' cache type. Ignoring.");
1859 return;
1860 }
c9e2e0e8 1861
1862 /* reconfigure existing dir */
cd748f27 1863
ba724607
AJ
1864 RefCount<SwapDir> sd;
1865 for (int i = 0; i < swap->n_configured; ++i) {
c8f4eac4 1866 assert (swap->swapDirs[i].getRaw());
62e76326 1867
2c9e9cba 1868 if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) {
c9e2e0e8 1869 /* this is specific to on-fs Stores. The right
26ac0430 1870 * way to handle this is probably to have a mapping
c9e2e0e8 1871 * from paths to stores, and have on-fs stores
1872 * register with that, and lookip in that in their
1873 * own setup logic. RBC 20041225. TODO.
1874 */
c8f4eac4 1875
1876 sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw());
1877
4c9eadc2 1878 if (strcmp(sd->type(), StoreFileSystem::FileSystems().at(fs)->type()) != 0) {
fa84c01d 1879 debugs(3, DBG_CRITICAL, "ERROR: Can't change type of existing cache_dir " <<
bf8fe701 1880 sd->type() << " " << sd->path << " to " << type_str << ". Restart required");
c9e2e0e8 1881 return;
1882 }
1883
afa75e4b 1884 sd->reconfigure();
62e76326 1885 return;
1886 }
cd748f27 1887 }
1888
c9e2e0e8 1889 /* new cache_dir */
af6a12ee 1890 if (swap->n_configured > 63) {
2c9e9cba
AJ
1891 /* 7 bits, signed */
1892 debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1893 debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many.");
1894 self_destruct();
1895 return;
1896 }
dc986280 1897
cd748f27 1898 allocate_new_swapdir(swap);
c9e2e0e8 1899
4c9eadc2 1900 swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().at(fs)->createSwapDir();
c9e2e0e8 1901
c8f4eac4 1902 sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw());
c9e2e0e8 1903
8e8d4f30 1904 /* parse the FS parameters and options */
d3b3ab85 1905 sd->parse(swap->n_configured, path_str);
c9e2e0e8 1906
d3b3ab85 1907 ++swap->n_configured;
752c3b27 1908}
1909
2d72d4fd 1910static const char *
505e35db 1911peer_type_str(const peer_t type)
1912{
1f140227 1913 const char * result;
1914
0cdcddb9 1915 switch (type) {
62e76326 1916
505e35db 1917 case PEER_PARENT:
1f140227 1918 result = "parent";
62e76326 1919 break;
1920
505e35db 1921 case PEER_SIBLING:
1f140227 1922 result = "sibling";
62e76326 1923 break;
1924
505e35db 1925 case PEER_MULTICAST:
1f140227 1926 result = "multicast";
62e76326 1927 break;
1928
505e35db 1929 default:
1f140227 1930 result = "unknown";
62e76326 1931 break;
505e35db 1932 }
1f140227 1933
1934 return result;
505e35db 1935}
1936
f1dc9b30 1937static void
a3c6762c 1938dump_peer(StoreEntry * entry, const char *name, CachePeer * p)
98ffb7e4 1939{
5844d003 1940 NeighborTypeDomainList *t;
505e35db 1941 LOCAL_ARRAY(char, xname, 128);
62e76326 1942
d41de3c1 1943 while (p != NULL) {
4bc48d15 1944 storeAppendPrintf(entry, "%s %s %s %d %d name=%s",
62e76326 1945 name,
1946 p->host,
1947 neighborTypeStr(p),
1948 p->http_port,
4bc48d15
AJ
1949 p->icp.port,
1950 p->name);
62e76326 1951 dump_peer_options(entry, p);
1952
62e76326 1953 if (p->access) {
1954 snprintf(xname, 128, "cache_peer_access %s", p->name);
1955 dump_acl_access(entry, xname, p->access);
1956 }
1957
1958 for (t = p->typelist; t; t = t->next) {
1959 storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
1960 p->host,
1961 peer_type_str(t->type),
1962 t->domain);
1963 }
1964
1965 p = p->next;
d41de3c1 1966 }
98ffb7e4 1967}
1968
86ae97bb
AJ
1969/**
1970 * utility function to prevent getservbyname() being called with a numeric value
1971 * on Windows at least it returns garage results.
1972 */
1973static bool
1974isUnsignedNumeric(const char *str, size_t len)
1975{
1976 if (len < 1) return false;
1977
5e263176 1978 for (; len >0 && *str; ++str, --len) {
86ae97bb
AJ
1979 if (! isdigit(*str))
1980 return false;
1981 }
1982 return true;
1983}
1984
609fac72 1985/**
f53969cc 1986 \param proto 'tcp' or 'udp' for protocol
609fac72 1987 \returns Port the named service is supposed to be listening on.
1988 */
f45dd259 1989static unsigned short
609fac72 1990GetService(const char *proto)
1991{
1992 struct servent *port = NULL;
1993 /** Parses a port number or service name from the squid.conf */
2eceb328 1994 char *token = ConfigParser::NextToken();
609fac72 1995 if (token == NULL) {
26ac0430
AJ
1996 self_destruct();
1997 return 0; /* NEVER REACHED */
609fac72 1998 }
1999 /** Returns either the service port number from /etc/services */
e1381638 2000 if ( !isUnsignedNumeric(token, strlen(token)) )
86ae97bb 2001 port = getservbyname(token, proto);
609fac72 2002 if (port != NULL) {
f45dd259 2003 return ntohs((unsigned short)port->s_port);
609fac72 2004 }
2005 /** Or a numeric translation of the config text. */
2006 return xatos(token);
2007}
2008
2009/**
2010 \returns Port the named TCP service is supposed to be listening on.
2011 \copydoc GetService(const char *proto)
2012 */
f45dd259 2013inline unsigned short
609fac72 2014GetTcpService(void)
2015{
2016 return GetService("tcp");
2017}
2018
2019/**
2020 \returns Port the named UDP service is supposed to be listening on.
2021 \copydoc GetService(const char *proto)
2022 */
f45dd259 2023inline unsigned short
609fac72 2024GetUdpService(void)
2025{
2026 return GetService("udp");
2027}
2028
8203a132 2029static void
a3c6762c 2030parse_peer(CachePeer ** head)
7813c6d5 2031{
ba724607
AJ
2032 char *host_str = ConfigParser::NextToken();
2033 if (!host_str) {
62e76326 2034 self_destruct();
ba724607
AJ
2035 return;
2036 }
62e76326 2037
ba724607
AJ
2038 char *token = ConfigParser::NextToken();
2039 if (!token) {
62e76326 2040 self_destruct();
ba724607
AJ
2041 return;
2042 }
62e76326 2043
ba724607
AJ
2044 CachePeer *p = new CachePeer;
2045 p->host = xstrdup(host_str);
2046 p->name = xstrdup(host_str);
40a1495e 2047 p->type = parseNeighborType(token);
62e76326 2048
0d5a2006 2049 if (p->type == PEER_MULTICAST) {
ccdf4138
FC
2050 p->options.no_digest = true;
2051 p->options.no_netdb_exchange = true;
0d5a2006 2052 }
2053
609fac72 2054 p->http_port = GetTcpService();
62e76326 2055
ba724607
AJ
2056 if (!p->http_port) {
2057 delete p;
0e656b69 2058 self_destruct();
ba724607
AJ
2059 return;
2060 }
62e76326 2061
609fac72 2062 p->icp.port = GetUdpService();
62e76326 2063
2eceb328 2064 while ((token = ConfigParser::NextToken())) {
a37d6070 2065 if (!strcmp(token, "proxy-only")) {
ccdf4138 2066 p->options.proxy_only = true;
a37d6070 2067 } else if (!strcmp(token, "no-query")) {
ccdf4138 2068 p->options.no_query = true;
a37d6070 2069 } else if (!strcmp(token, "background-ping")) {
ccdf4138 2070 p->options.background_ping = true;
a37d6070 2071 } else if (!strcmp(token, "no-digest")) {
ccdf4138 2072 p->options.no_digest = true;
a37d6070 2073 } else if (!strcmp(token, "no-tproxy")) {
ccdf4138 2074 p->options.no_tproxy = true;
a37d6070 2075 } else if (!strcmp(token, "multicast-responder")) {
ccdf4138 2076 p->options.mcast_responder = true;
8a368316 2077#if PEER_MULTICAST_SIBLINGS
a37d6070 2078 } else if (!strcmp(token, "multicast-siblings")) {
ccdf4138 2079 p->options.mcast_siblings = true;
8a368316 2080#endif
a37d6070 2081 } else if (!strncmp(token, "weight=", 7)) {
62e76326 2082 p->weight = xatoi(token + 7);
a37d6070 2083 } else if (!strncmp(token, "basetime=", 9)) {
62e76326 2084 p->basetime = xatoi(token + 9);
a37d6070 2085 } else if (!strcmp(token, "closest-only")) {
ccdf4138 2086 p->options.closest_only = true;
a37d6070 2087 } else if (!strncmp(token, "ttl=", 4)) {
62e76326 2088 p->mcast.ttl = xatoi(token + 4);
2089
2090 if (p->mcast.ttl < 0)
2091 p->mcast.ttl = 0;
2092
2093 if (p->mcast.ttl > 128)
2094 p->mcast.ttl = 128;
a37d6070 2095 } else if (!strcmp(token, "default")) {
ccdf4138 2096 p->options.default_parent = true;
a37d6070 2097 } else if (!strcmp(token, "round-robin")) {
ccdf4138 2098 p->options.roundrobin = true;
a37d6070 2099 } else if (!strcmp(token, "weighted-round-robin")) {
ccdf4138 2100 p->options.weighted_roundrobin = true;
dc9d133b 2101#if USE_HTCP
a37d6070 2102 } else if (!strcmp(token, "htcp")) {
ccdf4138 2103 p->options.htcp = true;
a37d6070 2104 } else if (!strncmp(token, "htcp=", 5) || !strncmp(token, "htcp-", 5)) {
18191440 2105 /* Note: The htcp- form is deprecated, replaced by htcp= */
ccdf4138 2106 p->options.htcp = true;
18191440
AJ
2107 char *tmp = xstrdup(token+5);
2108 char *mode, *nextmode;
2109 for (mode = nextmode = tmp; mode; mode = nextmode) {
2110 nextmode = strchr(mode, ',');
a38ec4b1
FC
2111 if (nextmode) {
2112 *nextmode = '\0';
2113 ++nextmode;
2114 }
a37d6070 2115 if (!strcmp(mode, "no-clr")) {
18191440
AJ
2116 if (p->options.htcp_only_clr)
2117 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
ccdf4138 2118 p->options.htcp_no_clr = true;
a37d6070 2119 } else if (!strcmp(mode, "no-purge-clr")) {
ccdf4138 2120 p->options.htcp_no_purge_clr = true;
a37d6070 2121 } else if (!strcmp(mode, "only-clr")) {
18191440
AJ
2122 if (p->options.htcp_no_clr)
2123 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
ccdf4138 2124 p->options.htcp_only_clr = true;
a37d6070 2125 } else if (!strcmp(mode, "forward-clr")) {
ccdf4138 2126 p->options.htcp_forward_clr = true;
a37d6070 2127 } else if (!strcmp(mode, "oldsquid")) {
ccdf4138 2128 p->options.htcp_oldsquid = true;
18191440
AJ
2129 } else {
2130 fatalf("invalid HTCP mode '%s'", mode);
2131 }
2132 }
2133 safe_free(tmp);
dc9d133b 2134#endif
a37d6070 2135 } else if (!strcmp(token, "no-netdb-exchange")) {
ccdf4138 2136 p->options.no_netdb_exchange = true;
62e76326 2137
a37d6070 2138 } else if (!strcmp(token, "carp")) {
62e76326 2139 if (p->type != PEER_PARENT)
2140 fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
2141
ccdf4138 2142 p->options.carp = true;
a37d6070 2143 } else if (!strncmp(token, "carp-key=", 9)) {
ccdf4138 2144 if (p->options.carp != true)
de03b596 2145 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port);
ccdf4138 2146 p->options.carp_key.set = true;
de03b596
FC
2147 char *nextkey=token+strlen("carp-key="), *key=nextkey;
2148 for (; key; key = nextkey) {
96f6f33b
A
2149 nextkey=strchr(key,',');
2150 if (nextkey) ++nextkey; // skip the comma, any
a37d6070 2151 if (0==strncmp(key,"scheme",6)) {
ccdf4138 2152 p->options.carp_key.scheme = true;
a37d6070 2153 } else if (0==strncmp(key,"host",4)) {
ccdf4138 2154 p->options.carp_key.host = true;
a37d6070 2155 } else if (0==strncmp(key,"port",4)) {
ccdf4138 2156 p->options.carp_key.port = true;
a37d6070 2157 } else if (0==strncmp(key,"path",4)) {
ccdf4138 2158 p->options.carp_key.path = true;
a37d6070 2159 } else if (0==strncmp(key,"params",6)) {
ccdf4138 2160 p->options.carp_key.params = true;
96f6f33b
A
2161 } else {
2162 fatalf("invalid carp-key '%s'",key);
2163 }
de03b596 2164 }
a37d6070 2165 } else if (!strcmp(token, "userhash")) {
2f1431ea 2166#if USE_AUTH
f7e1d9ce
HN
2167 if (p->type != PEER_PARENT)
2168 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port);
2169
ccdf4138 2170 p->options.userhash = true;
2f1431ea
AJ
2171#else
2172 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port);
2173#endif
a37d6070 2174 } else if (!strcmp(token, "sourcehash")) {
f7e1d9ce
HN
2175 if (p->type != PEER_PARENT)
2176 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port);
2177
ccdf4138 2178 p->options.sourcehash = true;
f7e1d9ce 2179
a37d6070 2180 } else if (!strcmp(token, "no-delay")) {
9a0a18de 2181#if USE_DELAY_POOLS
ccdf4138 2182 p->options.no_delay = true;
9a0a18de
AJ
2183#else
2184 debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
afd88fbe 2185#endif
a37d6070 2186 } else if (!strncmp(token, "login=", 6)) {
62e76326 2187 p->login = xstrdup(token + 6);
2188 rfc1738_unescape(p->login);
9825b398
AJ
2189 } else if (!strcmp(token, "auth-no-keytab")) {
2190 p->options.auth_no_keytab = 1;
a37d6070 2191 } else if (!strncmp(token, "connect-timeout=", 16)) {
62e76326 2192 p->connect_timeout = xatoi(token + 16);
a37d6070 2193 } else if (!strncmp(token, "connect-fail-limit=", 19)) {
ff9970cc 2194 p->connect_fail_limit = xatoi(token + 19);
7e3ce7b9 2195#if USE_CACHE_DIGESTS
a37d6070 2196 } else if (!strncmp(token, "digest-url=", 11)) {
62e76326 2197 p->digest_url = xstrdup(token + 11);
7e3ce7b9 2198#endif
62e76326 2199
a37d6070 2200 } else if (!strcmp(token, "allow-miss")) {
ccdf4138 2201 p->options.allow_miss = true;
a37d6070 2202 } else if (!strncmp(token, "max-conn=", 9)) {
62e76326 2203 p->max_conn = xatoi(token + 9);
e8dca475
CT
2204 } else if (!strncmp(token, "standby=", 8)) {
2205 p->standby.limit = xatoi(token + 8);
a37d6070 2206 } else if (!strcmp(token, "originserver")) {
ccdf4138 2207 p->options.originserver = true;
a37d6070 2208 } else if (!strncmp(token, "name=", 5)) {
62e76326 2209 safe_free(p->name);
2210
2211 if (token[5])
2212 p->name = xstrdup(token + 5);
a37d6070 2213 } else if (!strncmp(token, "forceddomain=", 13)) {
62e76326 2214 safe_free(p->domain);
62e76326 2215 if (token[13])
2216 p->domain = xstrdup(token + 13);
2217
cdfb670c
AJ
2218 } else if (strncmp(token, "ssl", 3) == 0) {
2219#if !USE_OPENSSL
2220 debugs(0, DBG_CRITICAL, "WARNING: cache_peer option '" << token << "' requires --with-openssl");
2221#else
0b0e0864 2222 p->secure.parse(token+3);
cdfb670c 2223#endif
1cc44095 2224 } else if (strncmp(token, "tls-", 4) == 0) {
1cc44095 2225 p->secure.parse(token+4);
0ff7e52d
AJ
2226 } else if (strncmp(token, "tls", 3) == 0) {
2227 p->secure.parse(token+3);
62e76326 2228 } else if (strcmp(token, "front-end-https") == 0) {
2229 p->front_end_https = 1;
2230 } else if (strcmp(token, "front-end-https=on") == 0) {
2231 p->front_end_https = 1;
2232 } else if (strcmp(token, "front-end-https=auto") == 0) {
2233 p->front_end_https = 2;
26ac0430 2234 } else if (strcmp(token, "connection-auth=off") == 0) {
d67acb4e
AJ
2235 p->connection_auth = 0;
2236 } else if (strcmp(token, "connection-auth") == 0) {
2237 p->connection_auth = 1;
2238 } else if (strcmp(token, "connection-auth=on") == 0) {
2239 p->connection_auth = 1;
2240 } else if (strcmp(token, "connection-auth=auto") == 0) {
2241 p->connection_auth = 2;
9d22bac3
AJ
2242 } else if (token[0] == '#') {
2243 // start of a text comment. stop reading this line.
2244 break;
62e76326 2245 } else {
9d22bac3 2246 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Ignoring unknown cache_peer option '" << token << "'");
62e76326 2247 }
270b86af 2248 }
62e76326 2249
be753325 2250 if (peerFindByName(p->name))
62e76326 2251 fatalf("ERROR: cache_peer %s specified twice\n", p->name);
2252
e8dca475
CT
2253 if (p->max_conn > 0 && p->max_conn < p->standby.limit)
2254 fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p->host, p->max_conn, p->standby.limit);
2255
40a1495e 2256 if (p->weight < 1)
62e76326 2257 p->weight = 1;
2258
ff9970cc 2259 if (p->connect_fail_limit < 1)
a4d889e0 2260 p->connect_fail_limit = 10;
ff9970cc 2261
e13ee7ad 2262#if USE_CACHE_DIGESTS
62e76326 2263
e13ee7ad 2264 if (!p->options.no_digest) {
62e76326 2265 /* XXX This looks odd.. who has the original pointer
2266 * then?
2267 */
2268 PeerDigest *pd = peerDigestCreate(p);
2269 p->digest = cbdataReference(pd);
8a6218c6 2270 }
62e76326 2271
e13ee7ad 2272#endif
cc192b50 2273
2274 p->index = ++Config.npeers;
2275
0153d498 2276 while (*head != NULL)
62e76326 2277 head = &(*head)->next;
2278
0153d498 2279 *head = p;
62e76326 2280
32a47e3e 2281 peerClearRRStart();
0153d498 2282}
2283
2284static void
a3c6762c 2285free_peer(CachePeer ** P)
0153d498 2286{
719815a0
AJ
2287 delete *P;
2288 *P = NULL;
987c67d1 2289 Config.npeers = 0;
270b86af 2290}
2291
2292static void
613924ee 2293dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list)
270b86af 2294{
d41de3c1 2295 wordlist *w;
62e76326 2296
d41de3c1 2297 while (list != NULL) {
62e76326 2298 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
2299 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
2300 else
2301 storeAppendPrintf(entry, "%s %s", name, list->passwd);
2302
2303 for (w = list->actions; w != NULL; w = w->next) {
2304 storeAppendPrintf(entry, " %s", w->key);
2305 }
2306
2307 storeAppendPrintf(entry, "\n");
2308 list = list->next;
d41de3c1 2309 }
270b86af 2310}
2311
2312static void
613924ee 2313parse_cachemgrpasswd(Mgr::ActionPasswordList ** head)
270b86af 2314{
2315 char *passwd = NULL;
2316 wordlist *actions = NULL;
613924ee
FC
2317 Mgr::ActionPasswordList *p;
2318 Mgr::ActionPasswordList **P;
270b86af 2319 parse_string(&passwd);
2320 parse_wordlist(&actions);
613924ee 2321 p = new Mgr::ActionPasswordList;
22f3fd98 2322 p->passwd = passwd;
2323 p->actions = actions;
62e76326 2324
26aa7e31 2325 for (P = head; *P; P = &(*P)->next) {
62e76326 2326 /*
2327 * See if any of the actions from this line already have a
2328 * password from previous lines. The password checking
2329 * routines in cache_manager.c take the the password from
613924ee 2330 * the first Mgr::ActionPasswordList that contains the
62e76326 2331 * requested action. Thus, we should warn users who might
2332 * think they can have two passwords for the same action.
2333 */
2334 wordlist *w;
2335 wordlist *u;
2336
2337 for (w = (*P)->actions; w; w = w->next) {
2338 for (u = actions; u; u = u->next) {
2339 if (strcmp(w->key, u->key))
2340 continue;
2341
fa84c01d 2342 debugs(0, DBG_CRITICAL, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password");
62e76326 2343 }
2344 }
26aa7e31 2345 }
62e76326 2346
22f3fd98 2347 *P = p;
270b86af 2348}
2349
2350static void
613924ee 2351free_cachemgrpasswd(Mgr::ActionPasswordList ** head)
270b86af 2352{
613924ee 2353 Mgr::ActionPasswordList *p;
62e76326 2354
79d39a72 2355 while ((p = *head) != NULL) {
62e76326 2356 *head = p->next;
2357 xfree(p->passwd);
2358 wordlistDestroy(&p->actions);
2359 xfree(p);
a47b9029 2360 }
270b86af 2361}
2362
8203a132 2363static void
7f0b3324 2364dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var)
270b86af 2365{
6be70545 2366 AclNameList *a;
62e76326 2367
d41de3c1 2368 while (var != NULL) {
62e76326 2369 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
2370
2371 for (a = var->acl_list; a != NULL; a = a->next)
2372 storeAppendPrintf(entry, " %s", a->name);
2373
2374 storeAppendPrintf(entry, "\n");
2375
2376 var = var->next;
d41de3c1 2377 }
270b86af 2378}
2379
2380static void
7f0b3324 2381parse_denyinfo(AclDenyInfoList ** var)
6e40f263 2382{
f1dc9b30 2383 aclParseDenyInfoLine(var);
6e40f263 2384}
403279e0 2385
1273d501 2386void
7f0b3324 2387free_denyinfo(AclDenyInfoList ** list)
3c5557f9 2388{
7f0b3324
FC
2389 AclDenyInfoList *a = NULL;
2390 AclDenyInfoList *a_next = NULL;
6be70545
FC
2391 AclNameList *l = NULL;
2392 AclNameList *l_next = NULL;
62e76326 2393
1273d501 2394 for (a = *list; a; a = a_next) {
62e76326 2395 for (l = a->acl_list; l; l = l_next) {
2396 l_next = l->next;
2397 memFree(l, MEM_ACL_NAME_LIST);
2398 l = NULL;
2399 }
2400
2401 a_next = a->next;
2402 memFree(a, MEM_ACL_DENY_INFO_LIST);
2403 a = NULL;
1273d501 2404 }
62e76326 2405
1273d501 2406 *list = NULL;
270b86af 2407}
2408
2409static void
505e35db 2410parse_peer_access(void)
270b86af 2411{
ba724607
AJ
2412 char *host = ConfigParser::NextToken();
2413 if (!host) {
62e76326 2414 self_destruct();
ba724607
AJ
2415 return;
2416 }
62e76326 2417
ba724607
AJ
2418 CachePeer *p = peerFindByName(host);
2419 if (!p) {
fa84c01d 2420 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
62e76326 2421 return;
0cdcddb9 2422 }
62e76326 2423
6f58d7d7
AR
2424 std::string directive = "peer_access ";
2425 directive += host;
2426 aclParseAccessLine(directive.c_str(), LegacyParser, &p->access);
270b86af 2427}
2428
270b86af 2429static void
2430parse_hostdomaintype(void)
2431{
ba724607
AJ
2432 char *host = ConfigParser::NextToken();
2433 if (!host) {
62e76326 2434 self_destruct();
ba724607
AJ
2435 return;
2436 }
62e76326 2437
ba724607
AJ
2438 char *type = ConfigParser::NextToken();
2439 if (!type) {
62e76326 2440 self_destruct();
ba724607
AJ
2441 return;
2442 }
62e76326 2443
ba724607 2444 char *domain = nullptr;
2eceb328 2445 while ((domain = ConfigParser::NextToken())) {
ba724607
AJ
2446 CachePeer *p = peerFindByName(host);
2447 if (!p) {
fa84c01d 2448 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
62e76326 2449 return;
2450 }
2451
ba724607 2452 auto *l = static_cast<NeighborTypeDomainList *>(xcalloc(1, sizeof(NeighborTypeDomainList)));
62e76326 2453 l->type = parseNeighborType(type);
2454 l->domain = xstrdup(domain);
2455
ba724607 2456 NeighborTypeDomainList **L = nullptr;
3d0ac046 2457 for (L = &(p->typelist); *L; L = &((*L)->next));
62e76326 2458 *L = l;
f1dc9b30 2459 }
270b86af 2460}
2461
270b86af 2462static void
a7d59104 2463dump_int(StoreEntry * entry, const char *name, int var)
270b86af 2464{
f53b06f9 2465 storeAppendPrintf(entry, "%s %d\n", name, var);
270b86af 2466}
c1c29eb6 2467
94439e4e 2468void
270b86af 2469parse_int(int *var)
2470{
270b86af 2471 int i;
0e4e0e7d 2472 i = GetInteger();
270b86af 2473 *var = i;
2474}
090089c4 2475
0153d498 2476static void
2477free_int(int *var)
2478{
a47b9029 2479 *var = 0;
0153d498 2480}
2481
8f7dbf74
DD
2482static void
2483dump_int64_t(StoreEntry * entry, const char *name, int64_t var)
2484{
2485 storeAppendPrintf(entry, "%s %" PRId64 "\n", name, var);
2486}
2487
2488void
2489parse_int64_t(int64_t *var)
2490{
2491 int64_t i;
2492 i = GetInteger64();
2493 *var = i;
2494}
2495
2496static void
2497free_int64_t(int64_t *var)
2498{
2499 *var = 0;
2500}
2501
270b86af 2502static void
a7d59104 2503dump_onoff(StoreEntry * entry, const char *name, int var)
270b86af 2504{
f53b06f9 2505 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
270b86af 2506}
090089c4 2507
d205783b 2508void
270b86af 2509parse_onoff(int *var)
2510{
2eceb328 2511 char *token = ConfigParser::NextToken();
ba724607 2512 if (!token) {
62e76326 2513 self_destruct();
ba724607
AJ
2514 return;
2515 }
62e76326 2516
a37d6070 2517 if (!strcmp(token, "on")) {
62e76326 2518 *var = 1;
a37d6070 2519 } else if (!strcmp(token, "enable")) {
54a063a2
TX
2520 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2521 *var = 1;
a37d6070 2522 } else if (!strcmp(token, "off")) {
62e76326 2523 *var = 0;
a37d6070 2524 } else if (!strcmp(token, "disable")) {
54a063a2
TX
2525 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2526 *var = 0;
2527 } else {
2528 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2529 self_destruct();
2530 }
270b86af 2531}
e90100aa 2532
0153d498 2533#define free_onoff free_int
52d3f198 2534
2535static void
2536dump_tristate(StoreEntry * entry, const char *name, int var)
2537{
2538 const char *state;
2539
2540 if (var > 0)
2541 state = "on";
2542 else if (var < 0)
2543 state = "warn";
2544 else
2545 state = "off";
2546
2547 storeAppendPrintf(entry, "%s %s\n", name, state);
2548}
2549
2550static void
2551parse_tristate(int *var)
2552{
2eceb328 2553 char *token = ConfigParser::NextToken();
ba724607 2554 if (!token) {
52d3f198 2555 self_destruct();
ba724607
AJ
2556 return;
2557 }
52d3f198 2558
a37d6070 2559 if (!strcmp(token, "on")) {
54a063a2 2560 *var = 1;
a37d6070 2561 } else if (!strcmp(token, "enable")) {
54a063a2 2562 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
52d3f198 2563 *var = 1;
a37d6070 2564 } else if (!strcmp(token, "warn")) {
52d3f198 2565 *var = -1;
a37d6070 2566 } else if (!strcmp(token, "off")) {
52d3f198 2567 *var = 0;
a37d6070 2568 } else if (!strcmp(token, "disable")) {
54a063a2
TX
2569 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2570 *var = 0;
2571 } else {
2572 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2573 self_destruct();
2574 }
52d3f198 2575}
2576
2577#define free_tristate free_int
30a4f2a8 2578
079a8480
AJ
2579void
2580parse_pipelinePrefetch(int *var)
2581{
bde7a8ce 2582 char *token = ConfigParser::PeekAtToken();
ba724607 2583 if (!token) {
079a8480 2584 self_destruct();
ba724607
AJ
2585 return;
2586 }
079a8480
AJ
2587
2588 if (!strcmp(token, "on")) {
2589 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2590 *var = 1;
bde7a8ce
CT
2591 //pop the token
2592 (void)ConfigParser::NextToken();
079a8480
AJ
2593 } else if (!strcmp(token, "off")) {
2594 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2595 *var = 0;
bde7a8ce
CT
2596 //pop the token
2597 (void)ConfigParser::NextToken();
2598 } else
079a8480 2599 parse_int(var);
079a8480
AJ
2600}
2601
2602#define free_pipelinePrefetch free_int
2603#define dump_pipelinePrefetch dump_int
2604
270b86af 2605static void
8d9a8184 2606dump_refreshpattern(StoreEntry * entry, const char *name, RefreshPattern * head)
270b86af 2607{
d41de3c1 2608 while (head != NULL) {
0e1d7629 2609 storeAppendPrintf(entry, "%s%s %s %d %d%% %d",
62e76326 2610 name,
95b8eae2
AJ
2611 head->pattern.flags&REG_ICASE ? " -i" : null_string,
2612 head->pattern.c_str(),
62e76326 2613 (int) head->min / 60,
2614 (int) (100.0 * head->pct + 0.5),
2615 (int) head->max / 60);
4c3ef9b2 2616
570d3f75
AJ
2617 if (head->max_stale >= 0)
2618 storeAppendPrintf(entry, " max-stale=%d", head->max_stale);
2619
4c3ef9b2 2620 if (head->flags.refresh_ims)
2621 storeAppendPrintf(entry, " refresh-ims");
2622
3d8b6ba4
AJ
2623 if (head->flags.store_stale)
2624 storeAppendPrintf(entry, " store-stale");
2625
626096be 2626#if USE_HTTP_VIOLATIONS
62e76326 2627
2628 if (head->flags.override_expire)
2629 storeAppendPrintf(entry, " override-expire");
2630
2631 if (head->flags.override_lastmod)
2632 storeAppendPrintf(entry, " override-lastmod");
2633
2634 if (head->flags.reload_into_ims)
2635 storeAppendPrintf(entry, " reload-into-ims");
2636
2637 if (head->flags.ignore_reload)
2638 storeAppendPrintf(entry, " ignore-reload");
2639
38f9c547 2640 if (head->flags.ignore_no_store)
2641 storeAppendPrintf(entry, " ignore-no-store");
2642
2643 if (head->flags.ignore_private)
2644 storeAppendPrintf(entry, " ignore-private");
9f60cfdf 2645#endif
62e76326 2646
2647 storeAppendPrintf(entry, "\n");
2648
2649 head = head->next;
d41de3c1 2650 }
270b86af 2651}
090089c4 2652
270b86af 2653static void
8d9a8184 2654parse_refreshpattern(RefreshPattern ** head)
270b86af 2655{
f1dc9b30 2656 char *token;
2657 char *pattern;
2658 time_t min = 0;
c3f6d204 2659 double pct = 0.0;
f1dc9b30 2660 time_t max = 0;
4c3ef9b2 2661 int refresh_ims = 0;
3d8b6ba4 2662 int store_stale = 0;
570d3f75 2663 int max_stale = -1;
3d8b6ba4 2664
626096be 2665#if USE_HTTP_VIOLATIONS
62e76326 2666
1dfa1d81 2667 int override_expire = 0;
2668 int override_lastmod = 0;
cbe3a719 2669 int reload_into_ims = 0;
2670 int ignore_reload = 0;
38f9c547 2671 int ignore_no_store = 0;
2672 int ignore_private = 0;
9f60cfdf 2673#endif
62e76326 2674
f1dc9b30 2675 int i;
8d9a8184 2676 RefreshPattern *t;
f1dc9b30 2677 regex_t comp;
2678 int errcode;
2679 int flags = REG_EXTENDED | REG_NOSUB;
62e76326 2680
bde7a8ce 2681 if ((token = ConfigParser::RegexPattern()) != NULL) {
2f3c75c3
AJ
2682
2683 if (strcmp(token, "-i") == 0) {
2684 flags |= REG_ICASE;
bde7a8ce 2685 token = ConfigParser::RegexPattern();
2f3c75c3
AJ
2686 } else if (strcmp(token, "+i") == 0) {
2687 flags &= ~REG_ICASE;
bde7a8ce 2688 token = ConfigParser::RegexPattern();
2f3c75c3 2689 }
62e76326 2690
f1dc9b30 2691 }
62e76326 2692
9eeb8e4b 2693 if (token == NULL) {
2f3c75c3 2694 debugs(3, DBG_CRITICAL, "FATAL: refresh_pattern missing the regex pattern parameter");
62e76326 2695 self_destruct();
9eeb8e4b 2696 return;
2697 }
62e76326 2698
f1dc9b30 2699 pattern = xstrdup(token);
62e76326 2700
f53969cc 2701 i = GetInteger(); /* token: min */
62e76326 2702
a632ba71
AJ
2703 /* catch negative and insanely huge values close to 32-bit wrap */
2704 if (i < 0) {
2705 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2706 i = 0;
2707 }
2708 if (i > 60*24*365) {
2709 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2710 i = 60*24*365;
2711 }
2712
f53969cc 2713 min = (time_t) (i * 60); /* convert minutes to seconds */
62e76326 2714
1454480a 2715 pct = GetPercentage(false); /* token: pct . with no limit on size */
62e76326 2716
f53969cc 2717 i = GetInteger(); /* token: max */
62e76326 2718
a632ba71
AJ
2719 /* catch negative and insanely huge values close to 32-bit wrap */
2720 if (i < 0) {
2721 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2722 i = 0;
2723 }
2724 if (i > 60*24*365) {
2725 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2726 i = 60*24*365;
2727 }
2728
f53969cc 2729 max = (time_t) (i * 60); /* convert minutes to seconds */
62e76326 2730
1dfa1d81 2731 /* Options */
2eceb328 2732 while ((token = ConfigParser::NextToken()) != NULL) {
4c3ef9b2 2733 if (!strcmp(token, "refresh-ims")) {
2734 refresh_ims = 1;
3d8b6ba4
AJ
2735 } else if (!strcmp(token, "store-stale")) {
2736 store_stale = 1;
570d3f75 2737 } else if (!strncmp(token, "max-stale=", 10)) {
54a063a2 2738 max_stale = xatoi(token + 10);
064679ea 2739
626096be 2740#if USE_HTTP_VIOLATIONS
62e76326 2741
4c3ef9b2 2742 } else if (!strcmp(token, "override-expire"))
62e76326 2743 override_expire = 1;
2744 else if (!strcmp(token, "override-lastmod"))
2745 override_lastmod = 1;
38f9c547 2746 else if (!strcmp(token, "ignore-no-store"))
2747 ignore_no_store = 1;
2748 else if (!strcmp(token, "ignore-private"))
2749 ignore_private = 1;
62e76326 2750 else if (!strcmp(token, "reload-into-ims")) {
2751 reload_into_ims = 1;
2752 refresh_nocache_hack = 1;
2753 /* tell client_side.c that this is used */
2754 } else if (!strcmp(token, "ignore-reload")) {
2755 ignore_reload = 1;
2756 refresh_nocache_hack = 1;
2757 /* tell client_side.c that this is used */
9f60cfdf 2758#endif
62e76326 2759
064679ea
AJ
2760 } else if (!strcmp(token, "ignore-no-cache") ||
2761 !strcmp(token, "ignore-must-revalidate") ||
2762 !strcmp(token, "ignore-auth")
7766dad3 2763 ) {
064679ea 2764 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token << "' is obsolete. Remove it.");
4c3ef9b2 2765 } else
fa84c01d 2766 debugs(22, DBG_CRITICAL, "refreshAddToList: Unknown option '" << pattern << "': " << token);
1dfa1d81 2767 }
62e76326 2768
f1dc9b30 2769 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
62e76326 2770 char errbuf[256];
2771 regerror(errcode, &comp, errbuf, sizeof errbuf);
fa84c01d
FC
2772 debugs(22, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2773 debugs(22, DBG_CRITICAL, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
eeaa522f 2774 xfree(pattern);
62e76326 2775 return;
f1dc9b30 2776 }
62e76326 2777
c3f6d204 2778 pct = pct < 0.0 ? 0.0 : pct;
f1dc9b30 2779 max = max < 0 ? 0 : max;
95b8eae2
AJ
2780 t = new RefreshPattern(pattern, flags);
2781 t->pattern.regex = comp;
f1dc9b30 2782 t->min = min;
c3f6d204 2783 t->pct = pct;
f1dc9b30 2784 t->max = max;
62e76326 2785
4c3ef9b2 2786 if (refresh_ims)
be4d35dc 2787 t->flags.refresh_ims = true;
4c3ef9b2 2788
3d8b6ba4 2789 if (store_stale)
be4d35dc 2790 t->flags.store_stale = true;
3d8b6ba4 2791
570d3f75
AJ
2792 t->max_stale = max_stale;
2793
626096be 2794#if USE_HTTP_VIOLATIONS
62e76326 2795
1dfa1d81 2796 if (override_expire)
be4d35dc 2797 t->flags.override_expire = true;
62e76326 2798
1dfa1d81 2799 if (override_lastmod)
be4d35dc 2800 t->flags.override_lastmod = true;
62e76326 2801
cbe3a719 2802 if (reload_into_ims)
be4d35dc 2803 t->flags.reload_into_ims = true;
62e76326 2804
cbe3a719 2805 if (ignore_reload)
be4d35dc 2806 t->flags.ignore_reload = true;
62e76326 2807
38f9c547 2808 if (ignore_no_store)
be4d35dc 2809 t->flags.ignore_no_store = true;
38f9c547 2810
2811 if (ignore_private)
be4d35dc 2812 t->flags.ignore_private = true;
9f60cfdf 2813#endif
62e76326 2814
f1dc9b30 2815 t->next = NULL;
62e76326 2816
f1dc9b30 2817 while (*head)
62e76326 2818 head = &(*head)->next;
2819
f1dc9b30 2820 *head = t;
62e76326 2821
95b8eae2 2822 xfree(pattern);
270b86af 2823}
090089c4 2824
270b86af 2825static void
8d9a8184 2826free_refreshpattern(RefreshPattern ** head)
270b86af 2827{
95b8eae2
AJ
2828 delete *head;
2829 *head = nullptr;
c2066637 2830
626096be 2831#if USE_HTTP_VIOLATIONS
c2066637 2832 refresh_nocache_hack = 0;
8970d351 2833
2834#endif
270b86af 2835}
12b9e9b1 2836
270b86af 2837static void
a7d59104 2838dump_string(StoreEntry * entry, const char *name, char *var)
270b86af 2839{
f53b06f9 2840 if (var != NULL)
62e76326 2841 storeAppendPrintf(entry, "%s %s\n", name, var);
270b86af 2842}
98ffb7e4 2843
270b86af 2844static void
0153d498 2845parse_string(char **var)
270b86af 2846{
270b86af 2847 safe_free(*var);
62e76326 2848
ba724607
AJ
2849 char *token = ConfigParser::NextToken();
2850 if (!token) {
62e76326 2851 self_destruct();
ba724607
AJ
2852 return;
2853 }
62e76326 2854
270b86af 2855 *var = xstrdup(token);
2856}
b15e6857 2857
0153d498 2858static void
2859free_string(char **var)
2860{
027acbaf 2861 safe_free(*var);
0153d498 2862}
caebbe00 2863
94439e4e 2864void
f1dc9b30 2865parse_eol(char *volatile *var)
270b86af 2866{
65657c1a
AJ
2867 if (!var) {
2868 self_destruct();
2869 return;
2870 }
2871
2eceb328 2872 unsigned char *token = (unsigned char *) ConfigParser::NextQuotedOrToEol();
270b86af 2873 safe_free(*var);
62e76326 2874
9eeb8e4b 2875 if (!token) {
62e76326 2876 self_destruct();
9eeb8e4b 2877 return;
2878 }
62e76326 2879
e4755e29 2880 while (*token && xisspace(*token))
a38ec4b1 2881 ++token;
62e76326 2882
9eeb8e4b 2883 if (!*token) {
62e76326 2884 self_destruct();
9eeb8e4b 2885 return;
2886 }
62e76326 2887
852751f7 2888 *var = xstrdup((char *) token);
270b86af 2889}
090089c4 2890
52d3f198 2891#define dump_eol dump_string
2892#define free_eol free_string
2893
b11724bb
CT
2894static void
2895parse_TokenOrQuotedString(char **var)
2896{
b11724bb
CT
2897 safe_free(*var);
2898
ba724607 2899 char *token = ConfigParser::NextQuotedToken();
ec1e53fa 2900 if (!token) {
b11724bb 2901 self_destruct();
ba724607
AJ
2902 return;
2903 }
b11724bb
CT
2904
2905 *var = xstrdup(token);
2906}
2907
2908#define dump_TokenOrQuotedString dump_string
2909#define free_TokenOrQuotedString free_string
2910
270b86af 2911static void
a7d59104 2912dump_time_t(StoreEntry * entry, const char *name, time_t var)
090089c4 2913{
f53b06f9 2914 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
090089c4 2915}
2916
94439e4e 2917void
a47b9029 2918parse_time_t(time_t * var)
0ffd22bc 2919{
fd0f51c4 2920 time_msec_t tval;
9b741834 2921 parseTimeLine(&tval, T_SECOND_STR, false);
fd0f51c4 2922 *var = static_cast<time_t>(tval/1000);
0ffd22bc 2923}
2924
270b86af 2925static void
a47b9029 2926free_time_t(time_t * var)
270b86af 2927{
a47b9029 2928 *var = 0;
270b86af 2929}
9906e724 2930
fd0f51c4
CT
2931static void
2932dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
2933{
2934 if (var % 1000)
c91ca3ce 2935 storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
fd0f51c4
CT
2936 else
2937 storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
2938}
2939
2940void
2941parse_time_msec(time_msec_t * var)
2942{
9b741834 2943 parseTimeLine(var, T_SECOND_STR, true);
fd0f51c4
CT
2944}
2945
2946static void
2947free_time_msec(time_msec_t * var)
2948{
2949 *var = 0;
2950}
2951
0477a072 2952#if UNUSED_CODE
9906e724 2953static void
a7d59104 2954dump_size_t(StoreEntry * entry, const char *name, size_t var)
1b635117 2955{
f53b06f9 2956 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
1b635117 2957}
0477a072 2958#endif
1b635117 2959
2960static void
a7d59104 2961dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
9906e724 2962{
f53b06f9 2963 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
9906e724 2964}
2965
e210930b
AJ
2966static void
2967dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var)
2968{
2969 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
2970}
e210930b 2971
3e62bd58 2972#if UNUSED_CODE
9906e724 2973static void
a7d59104 2974dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
9906e724 2975{
f53b06f9 2976 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
9906e724 2977}
3e62bd58 2978#endif
9906e724 2979
47f6e231 2980static void
2981dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
2982{
c91ca3ce 2983 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
47f6e231 2984}
2985
2986static void
2987dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
2988{
c91ca3ce 2989 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
47f6e231 2990}
2991
0477a072 2992#if UNUSED_CODE
9906e724 2993static void
a47b9029 2994parse_size_t(size_t * var)
1b635117 2995{
1b635117 2996 int i;
0e4e0e7d 2997 i = GetInteger();
1b635117 2998 *var = (size_t) i;
2999}
0477a072 3000#endif
1b635117 3001
3002static void
3003parse_b_size_t(size_t * var)
9906e724 3004{
3005 parseBytesLine(var, B_BYTES_STR);
3006}
3007
e210930b
AJ
3008static void
3009parse_b_ssize_t(ssize_t * var)
3010{
3011 parseBytesLineSigned(var, B_BYTES_STR);
3012}
e210930b 3013
3e62bd58 3014#if UNUSED_CODE
9906e724 3015static void
a47b9029 3016parse_kb_size_t(size_t * var)
9906e724 3017{
3018 parseBytesLine(var, B_KBYTES_STR);
3019}
3e62bd58 3020#endif
9906e724 3021
47f6e231 3022static void
3023parse_b_int64_t(int64_t * var)
3024{
3025 parseBytesLine64(var, B_BYTES_STR);
3026}
3027
3028static void
3029parse_kb_int64_t(int64_t * var)
3030{
3031 parseBytesLine64(var, B_KBYTES_STR);
3032}
3033
9906e724 3034static void
a47b9029 3035free_size_t(size_t * var)
9906e724 3036{
a47b9029 3037 *var = 0;
9906e724 3038}
3039
e210930b
AJ
3040static void
3041free_ssize_t(ssize_t * var)
3042{
3043 *var = 0;
3044}
e210930b 3045
47f6e231 3046static void
3047free_b_int64_t(int64_t * var)
3048{
3049 *var = 0;
3050}
3051
1b635117 3052#define free_b_size_t free_size_t
e210930b 3053#define free_b_ssize_t free_ssize_t
9906e724 3054#define free_kb_size_t free_size_t
3055#define free_mb_size_t free_size_t
3056#define free_gb_size_t free_size_t
47f6e231 3057#define free_kb_int64_t free_b_int64_t
090089c4 3058
8203a132 3059static void
f45dd259 3060dump_u_short(StoreEntry * entry, const char *name, unsigned short var)
090089c4 3061{
f53b06f9 3062 storeAppendPrintf(entry, "%s %d\n", name, var);
270b86af 3063}
090089c4 3064
0153d498 3065static void
f45dd259 3066free_u_short(unsigned short * u)
0153d498 3067{
3068 *u = 0;
3069}
3070
270b86af 3071static void
f45dd259 3072parse_u_short(unsigned short * var)
b67e2c8c 3073{
3074 ConfigParser::ParseUShort(var);
3075}
3076
3077void
f45dd259 3078ConfigParser::ParseUShort(unsigned short *var)
270b86af 3079{
0e656b69 3080 *var = GetShort();
090089c4 3081}
3082
3a69ddf3 3083void
3084ConfigParser::ParseBool(bool *var)
3085{
3086 int i = GetInteger();
3087
3088 if (0 == i)
3089 *var = false;
3090 else if (1 == i)
3091 *var = true;
3092 else
3093 self_destruct();
3094}
3095
270b86af 3096static void
a7d59104 3097dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
270b86af 3098{
270b86af 3099 while (list != NULL) {
62e76326 3100 storeAppendPrintf(entry, "%s %s\n", name, list->key);
3101 list = list->next;
429fdbec 3102 }
429fdbec 3103}
3104
3a69ddf3 3105void
3106ConfigParser::ParseWordList(wordlist ** list)
3107{
3108 parse_wordlist(list);
3109}
3110
94439e4e 3111void
270b86af 3112parse_wordlist(wordlist ** list)
429fdbec 3113{
270b86af 3114 char *token;
bde7a8ce 3115 while ((token = ConfigParser::NextQuotedToken()))
62e76326 3116 wordlistAdd(list, token);
429fdbec 3117}
270b86af 3118
b3d8a9e8 3119#if 0 /* now unused */
f8d9f54a 3120static int
5da06f20 3121check_null_wordlist(wordlist * w)
f8d9f54a 3122{
3123 return w == NULL;
3124}
b3d8a9e8 3125#endif
f8d9f54a 3126
63e9d884 3127static int
c6d5b87b 3128check_null_acl_access(acl_access * a)
63e9d884 3129{
3130 return a == NULL;
3131}
3132
0153d498 3133#define free_wordlist wordlistDestroy
270b86af 3134
d548ee64 3135#define free_uri_whitespace free_int
3136
3137static void
3138parse_uri_whitespace(int *var)
3139{
2eceb328 3140 char *token = ConfigParser::NextToken();
ba724607 3141 if (!token) {
62e76326 3142 self_destruct();
ba724607
AJ
3143 return;
3144 }
62e76326 3145
a37d6070 3146 if (!strcmp(token, "strip"))
62e76326 3147 *var = URI_WHITESPACE_STRIP;
a37d6070 3148 else if (!strcmp(token, "deny"))
62e76326 3149 *var = URI_WHITESPACE_DENY;
a37d6070 3150 else if (!strcmp(token, "allow"))
62e76326 3151 *var = URI_WHITESPACE_ALLOW;
a37d6070 3152 else if (!strcmp(token, "encode"))
62e76326 3153 *var = URI_WHITESPACE_ENCODE;
a37d6070 3154 else if (!strcmp(token, "chop"))
62e76326 3155 *var = URI_WHITESPACE_CHOP;
54a063a2
TX
3156 else {
3157 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
62e76326 3158 self_destruct();
54a063a2 3159 }
d548ee64 3160}
3161
d548ee64 3162static void
3163dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
3164{
c193c972 3165 const char *s;
62e76326 3166
d548ee64 3167 if (var == URI_WHITESPACE_ALLOW)
62e76326 3168 s = "allow";
d548ee64 3169 else if (var == URI_WHITESPACE_ENCODE)
62e76326 3170 s = "encode";
d548ee64 3171 else if (var == URI_WHITESPACE_CHOP)
62e76326 3172 s = "chop";
7e3ce7b9 3173 else if (var == URI_WHITESPACE_DENY)
62e76326 3174 s = "deny";
7e3ce7b9 3175 else
62e76326 3176 s = "strip";
3177
d548ee64 3178 storeAppendPrintf(entry, "%s %s\n", name, s);
3179}
3180
6a566b9c 3181static void
c1dd71ae 3182free_removalpolicy(RemovalPolicySettings ** settings)
6a566b9c 3183{
3184 if (!*settings)
62e76326 3185 return;
3186
6a566b9c 3187 free_string(&(*settings)->type);
62e76326 3188
6a566b9c 3189 free_wordlist(&(*settings)->args);
62e76326 3190
c8f4eac4 3191 delete *settings;
62e76326 3192
6a566b9c 3193 *settings = NULL;
3194}
3195
3196static void
c1dd71ae 3197parse_removalpolicy(RemovalPolicySettings ** settings)
6a566b9c 3198{
3199 if (*settings)
62e76326 3200 free_removalpolicy(settings);
3201
c8f4eac4 3202 *settings = new RemovalPolicySettings;
62e76326 3203
6a566b9c 3204 parse_string(&(*settings)->type);
62e76326 3205
6a566b9c 3206 parse_wordlist(&(*settings)->args);
3207}
3208
3209static void
c1dd71ae 3210dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
6a566b9c 3211{
3212 wordlist *args;
3213 storeAppendPrintf(entry, "%s %s", name, settings->type);
3214 args = settings->args;
62e76326 3215
6a566b9c 3216 while (args) {
62e76326 3217 storeAppendPrintf(entry, " %s", args->key);
3218 args = args->next;
6a566b9c 3219 }
62e76326 3220
be58afb5 3221 storeAppendPrintf(entry, "\n");
6a566b9c 3222}
c1dd71ae 3223
de0cb3d8
AR
3224inline void
3225free_YesNoNone(YesNoNone *)
ced8def3 3226{}
57af1e3f
AR
3227
3228static void
3229parse_YesNoNone(YesNoNone *option)
3230{
3231 int value = 0;
3232 parse_onoff(&value);
3233 option->configure(value > 0);
3234}
3235
3236static void
3237dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
3238{
3239 if (option.configured())
3240 dump_onoff(entry, name, option ? 1 : 0);
3241}
3242
ea21d497 3243static void
ced8def3
AJ
3244free_memcachemode(SquidConfig *)
3245{}
ea21d497
HN
3246
3247static void
ced8def3 3248parse_memcachemode(SquidConfig *)
ea21d497 3249{
2eceb328 3250 char *token = ConfigParser::NextToken();
ba724607 3251 if (!token) {
e1381638 3252 self_destruct();
ba724607
AJ
3253 return;
3254 }
ea21d497 3255
10aeba1d 3256 if (strcmp(token, "always") == 0) {
e1381638
AJ
3257 Config.onoff.memory_cache_first = 1;
3258 Config.onoff.memory_cache_disk = 1;
10aeba1d 3259 } else if (strcmp(token, "disk") == 0) {
e1381638
AJ
3260 Config.onoff.memory_cache_first = 0;
3261 Config.onoff.memory_cache_disk = 1;
ea21d497 3262 } else if (strncmp(token, "net", 3) == 0) {
e1381638
AJ
3263 Config.onoff.memory_cache_first = 1;
3264 Config.onoff.memory_cache_disk = 0;
10aeba1d 3265 } else if (strcmp(token, "never") == 0) {
e1381638
AJ
3266 Config.onoff.memory_cache_first = 0;
3267 Config.onoff.memory_cache_disk = 0;
54a063a2
TX
3268 } else {
3269 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
e1381638 3270 self_destruct();
54a063a2 3271 }
ea21d497
HN
3272}
3273
3274static void
ced8def3 3275dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &)
ea21d497
HN
3276{
3277 storeAppendPrintf(entry, "%s ", name);
3278 if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
e1381638 3279 storeAppendPrintf(entry, "always");
ea21d497 3280 else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
e1381638 3281 storeAppendPrintf(entry, "disk");
ea21d497 3282 else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
e1381638 3283 storeAppendPrintf(entry, "network");
ea21d497 3284 else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
e1381638 3285 storeAppendPrintf(entry, "none");
ea21d497
HN
3286 storeAppendPrintf(entry, "\n");
3287}
3288
cca8ba0d 3289#include "cf_parser.cci"
f1dc9b30 3290
3291peer_t
3292parseNeighborType(const char *s)
3293{
a37d6070 3294 if (!strcmp(s, "parent"))
62e76326 3295 return PEER_PARENT;
3296
a37d6070 3297 if (!strcmp(s, "neighbor"))
62e76326 3298 return PEER_SIBLING;
3299
a37d6070 3300 if (!strcmp(s, "neighbour"))
62e76326 3301 return PEER_SIBLING;
3302
a37d6070 3303 if (!strcmp(s, "sibling"))
62e76326 3304 return PEER_SIBLING;
3305
a37d6070 3306 if (!strcmp(s, "multicast"))
62e76326 3307 return PEER_MULTICAST;
3308
fa84c01d 3309 debugs(15, DBG_CRITICAL, "WARNING: Unknown neighbor type: " << s);
62e76326 3310
f1dc9b30 3311 return PEER_SIBLING;
3312}
f150dd4b 3313
0b0cfcf2 3314#if USE_WCCPv2
52f772de 3315static void
b7ac5457 3316parse_IpAddress_list(Ip::Address_list ** head)
52f772de 3317{
3318 char *token;
b7ac5457
AJ
3319 Ip::Address_list *s;
3320 Ip::Address ipa;
62e76326 3321
2eceb328 3322 while ((token = ConfigParser::NextToken())) {
82b7abe3
AJ
3323 if (GetHostWithPort(token, &ipa)) {
3324
3325 while (*head)
3326 head = &(*head)->next;
3327
b7ac5457 3328 s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s)));
82b7abe3
AJ
3329 s->s = ipa;
3330
3331 *head = s;
ba724607 3332 } else {
82b7abe3 3333 self_destruct();
ba724607
AJ
3334 return;
3335 }
7e3ce7b9 3336 }
3337}
3338
3339static void
b7ac5457 3340dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s)
7e3ce7b9 3341{
cc192b50 3342 char ntoabuf[MAX_IPSTRLEN];
3343
7e3ce7b9 3344 while (s) {
cc192b50 3345 storeAppendPrintf(e, "%s %s\n",
62e76326 3346 n,
4dd643d5 3347 s->s.toStr(ntoabuf,MAX_IPSTRLEN));
62e76326 3348 s = s->next;
7e3ce7b9 3349 }
3350}
3351
3352static void
b7ac5457 3353free_IpAddress_list(Ip::Address_list ** head)
7e3ce7b9 3354{
26ac0430
AJ
3355 if (*head) delete *head;
3356 *head = NULL;
7e3ce7b9 3357}
3358
0b0cfcf2 3359#if CURRENTLY_UNUSED
3360/* This code was previously used by http_port. Left as it really should
3361 * be used by icp_port and htcp_port
3362 */
7e3ce7b9 3363static int
b7ac5457 3364check_null_IpAddress_list(const Ip::Address_list * s)
7e3ce7b9 3365{
3366 return NULL == s;
3367}
62e76326 3368
3f38a55e 3369#endif /* CURRENTLY_UNUSED */
0b0cfcf2 3370#endif /* USE_WCCPv2 */
7e3ce7b9 3371
d193a436 3372static void
fa720bfb 3373parsePortSpecification(const AnyP::PortCfgPointer &s, char *token)
d193a436 3374{
3f38a55e 3375 char *host = NULL;
3f38a55e 3376 unsigned short port = 0;
cc192b50 3377 char *t = NULL;
3378 char *junk = NULL;
62e76326 3379
5529ca8a 3380 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
13adaf1f 3381 s->name = xstrdup(token);
d67acb4e 3382 s->connection_auth_disabled = false;
5529ca8a 3383
d31d59d8 3384 const SBuf &portType = AnyP::UriScheme(s->transport.protocol).image();
eb6ac808 3385
cc192b50 3386 if (*token == '[') {
3387 /* [ipv6]:port */
26ac0430
AJ
3388 host = token + 1;
3389 t = strchr(host, ']');
3390 if (!t) {
eb6ac808 3391 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing ']' on IPv6 address: " << token);
26ac0430 3392 self_destruct();
ba724607 3393 return;
cc192b50 3394 }
a38ec4b1
FC
3395 *t = '\0';
3396 ++t;
26ac0430 3397 if (*t != ':') {
eb6ac808 3398 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port in: " << token);
26ac0430 3399 self_destruct();
ba724607 3400 return;
cc192b50 3401 }
055421ee 3402 if (!Ip::EnableIpv6) {
eb6ac808 3403 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: IPv6 is not available.");
26ac0430 3404 self_destruct();
ba724607 3405 return;
26ac0430 3406 }
055421ee
AJ
3407 port = xatos(t + 1);
3408 } else if ((t = strchr(token, ':'))) {
3409 /* host:port */
3410 /* ipv4:port */
3411 host = token;
3412 *t = '\0';
3413 port = xatos(t + 1);
3414
54a063a2
TX
3415 } else if (strtol(token, &junk, 10) && !*junk) {
3416 port = xatos(token);
eb6ac808 3417 debugs(3, 3, portType << "_port: found Listen on Port: " << port);
055421ee 3418 } else {
eb6ac808 3419 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port: " << token);
055421ee 3420 self_destruct();
ba724607 3421 return;
055421ee 3422 }
62e76326 3423
859741ed 3424 if (port == 0 && host != NULL) {
eb6ac808 3425 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: Port cannot be 0: " << token);
0e656b69 3426 self_destruct();
ba724607 3427 return;
cc192b50 3428 }
0e656b69 3429
cc192b50 3430 if (NULL == host) {
4dd643d5
AJ
3431 s->s.setAnyAddr();
3432 s->s.port(port);
6df7ad56 3433 if (!Ip::EnableIpv6)
4dd643d5 3434 s->s.setIPv4();
eb6ac808 3435 debugs(3, 3, portType << "_port: found Listen on wildcard address: *:" << s->s.port());
c49d44e1 3436 } else if ( (s->s = host) ) { /* check/parse numeric IPA */
4dd643d5 3437 s->s.port(port);
6df7ad56 3438 if (!Ip::EnableIpv6)
4dd643d5 3439 s->s.setIPv4();
eb6ac808 3440 debugs(3, 3, portType << "_port: Listen on Host/IP: " << host << " --> " << s->s);
26ac0430 3441 } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
62e76326 3442 /* dont use ipcache */
62e76326 3443 s->defaultsite = xstrdup(host);
4dd643d5 3444 s->s.port(port);
6df7ad56 3445 if (!Ip::EnableIpv6)
4dd643d5 3446 s->s.setIPv4();
eb6ac808 3447 debugs(3, 3, portType << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
26ac0430 3448 } else {
eb6ac808 3449 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: failed to resolve Host/IP: " << host);
62e76326 3450 self_destruct();
cc192b50 3451 }
3f38a55e 3452}
3453
ecb19f1a
AR
3454/// parses the protocol= option of the *_port directive, returning parsed value
3455/// unsupported option values result in a fatal error message
3cc0f4e7 3456/// upper case values required; caller may convert for backward compatibility
ecb19f1a 3457static AnyP::ProtocolVersion
3cc0f4e7 3458parsePortProtocol(const SBuf &value)
ecb19f1a
AR
3459{
3460 // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3461 // and RFC 2616 requires us to upgrade 1.0 to 1.1
3cc0f4e7 3462 if (value.cmp("HTTP") == 0 || value.cmp("HTTP/1.1") == 0)
ecb19f1a
AR
3463 return AnyP::ProtocolVersion(AnyP::PROTO_HTTP, 1,1);
3464
3cc0f4e7 3465 if (value.cmp("HTTPS") == 0 || value.cmp("HTTPS/1.1") == 0)
ecb19f1a
AR
3466 return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS, 1,1);
3467
3cc0f4e7 3468 if (value.cmp("FTP") == 0)
aea65fec 3469 return Ftp::ProtocolVersion();
ecb19f1a 3470
3cc0f4e7 3471 fatalf("%s directive does not support protocol=" SQUIDSBUFPH "\n", cfg_directive, SQUIDSBUFPRINT(value));
ecb19f1a
AR
3472 return AnyP::ProtocolVersion(); // not reached
3473}
3474
3f38a55e 3475static void
fa720bfb 3476parse_port_option(AnyP::PortCfgPointer &s, char *token)
3f38a55e 3477{
c7b1dd5d
AJ
3478 /* modes first */
3479
3480 if (strcmp(token, "accel") == 0) {
151ba0d4 3481 if (s->flags.isIntercepted()) {
3cc0f4e7 3482 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Accelerator mode requires its own port. It cannot be shared with other modes.");
c7b1dd5d 3483 self_destruct();
ba724607 3484 return;
c7b1dd5d 3485 }
6a25a046 3486 s->flags.accelSurrogate = true;
86ab7a90 3487 s->vhost = true;
c7b1dd5d 3488 } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
151ba0d4 3489 if (s->flags.accelSurrogate || s->flags.tproxyIntercept) {
3cc0f4e7 3490 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
c7b1dd5d 3491 self_destruct();
ba724607 3492 return;
c7b1dd5d 3493 }
6a25a046 3494 s->flags.natIntercept = true;
c7b1dd5d
AJ
3495 Ip::Interceptor.StartInterception();
3496 /* Log information regarding the port modes under interception. */
3497 debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
3498 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
c7b1dd5d 3499 } else if (strcmp(token, "tproxy") == 0) {
151ba0d4 3500 if (s->flags.natIntercept || s->flags.accelSurrogate) {
3cc0f4e7 3501 debugs(3,DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
c7b1dd5d 3502 self_destruct();
ba724607 3503 return;
c7b1dd5d 3504 }
6a25a046 3505 s->flags.tproxyIntercept = true;
c7b1dd5d
AJ
3506 Ip::Interceptor.StartTransparency();
3507 /* Log information regarding the port modes under transparency. */
0d901ef4 3508 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (TPROXY enabled)");
c7b1dd5d 3509
151ba0d4 3510 if (s->flags.proxySurrogate) {
d3d92daa 3511 debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)");
151ba0d4
AJ
3512 }
3513
c7b1dd5d 3514 if (!Ip::Interceptor.ProbeForTproxy(s->s)) {
3cc0f4e7 3515 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY support in the system does not work.");
c7b1dd5d 3516 self_destruct();
ba724607 3517 return;
c7b1dd5d
AJ
3518 }
3519
d3d92daa 3520 } else if (strcmp(token, "require-proxy-header") == 0) {
00d0ce87 3521 s->flags.proxySurrogate = true;
13edf4cc
AJ
3522 if (s->flags.tproxyIntercept) {
3523 // receiving is still permitted, so we do not unset the TPROXY flag
3524 // spoofing access control override takes care of the spoof disable later
3525 debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)");
3526 }
00d0ce87 3527
c7b1dd5d 3528 } else if (strncmp(token, "defaultsite=", 12) == 0) {
6a25a046 3529 if (!s->flags.accelSurrogate) {
3cc0f4e7 3530 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": defaultsite option requires Acceleration mode flag.");
c7b1dd5d 3531 self_destruct();
ba724607 3532 return;
c7b1dd5d 3533 }
62e76326 3534 safe_free(s->defaultsite);
3535 s->defaultsite = xstrdup(token + 12);
3f38a55e 3536 } else if (strcmp(token, "vhost") == 0) {
6a25a046 3537 if (!s->flags.accelSurrogate) {
3cc0f4e7 3538 debugs(3, DBG_CRITICAL, "WARNING: " << cfg_directive << ": vhost option is deprecated. Use 'accel' mode flag instead.");
cf673853 3539 }
6a25a046 3540 s->flags.accelSurrogate = true;
86ab7a90 3541 s->vhost = true;
cf673853 3542 } else if (strcmp(token, "no-vhost") == 0) {
6a25a046 3543 if (!s->flags.accelSurrogate) {
3cc0f4e7 3544 debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": no-vhost option requires Acceleration mode flag.");
c7b1dd5d 3545 }
86ab7a90 3546 s->vhost = false;
3f38a55e 3547 } else if (strcmp(token, "vport") == 0) {
6a25a046 3548 if (!s->flags.accelSurrogate) {
3cc0f4e7 3549 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag.");
c7b1dd5d 3550 self_destruct();
ba724607 3551 return;
c7b1dd5d 3552 }
62e76326 3553 s->vport = -1;
3f38a55e 3554 } else if (strncmp(token, "vport=", 6) == 0) {
6a25a046 3555 if (!s->flags.accelSurrogate) {
3cc0f4e7 3556 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag.");
c7b1dd5d 3557 self_destruct();
ba724607 3558 return;
c7b1dd5d 3559 }
0e656b69 3560 s->vport = xatos(token + 6);
3f38a55e 3561 } else if (strncmp(token, "protocol=", 9) == 0) {
6a25a046 3562 if (!s->flags.accelSurrogate) {
3cc0f4e7 3563 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": protocol option requires Acceleration mode flag.");
c7b1dd5d 3564 self_destruct();
ba724607 3565 return;
c7b1dd5d 3566 }
3cc0f4e7 3567 s->transport = parsePortProtocol(ToUpper(SBuf(token + 9)));
7f7bdd96 3568 } else if (strcmp(token, "allow-direct") == 0) {
6a25a046 3569 if (!s->flags.accelSurrogate) {
3cc0f4e7 3570 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": allow-direct option requires Acceleration mode flag.");
c7b1dd5d 3571 self_destruct();
ba724607 3572 return;
c7b1dd5d 3573 }
86ab7a90 3574 s->allow_direct = true;
90fa5816 3575 } else if (strcmp(token, "act-as-origin") == 0) {
6a25a046 3576 if (!s->flags.accelSurrogate) {
3cc0f4e7 3577 debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": act-as-origin option requires Acceleration mode flag.");
90fa5816 3578 } else
86ab7a90 3579 s->actAsOrigin = true;
432bc83c 3580 } else if (strcmp(token, "ignore-cc") == 0) {
626096be 3581#if !USE_HTTP_VIOLATIONS
6a25a046 3582 if (!s->flags.accelSurrogate) {
3cc0f4e7 3583 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": ignore-cc option requires Acceleration mode flag.");
838daf3f 3584 self_destruct();
ba724607 3585 return;
838daf3f 3586 }
432bc83c 3587#endif
86ab7a90 3588 s->ignore_cc = true;
c7b1dd5d
AJ
3589 } else if (strncmp(token, "name=", 5) == 0) {
3590 safe_free(s->name);
3591 s->name = xstrdup(token + 5);
d67acb4e
AJ
3592 } else if (strcmp(token, "no-connection-auth") == 0) {
3593 s->connection_auth_disabled = true;
3594 } else if (strcmp(token, "connection-auth=off") == 0) {
26ac0430 3595 s->connection_auth_disabled = true;
d67acb4e 3596 } else if (strcmp(token, "connection-auth") == 0) {
26ac0430 3597 s->connection_auth_disabled = false;
d67acb4e 3598 } else if (strcmp(token, "connection-auth=on") == 0) {
26ac0430 3599 s->connection_auth_disabled = false;
5529ca8a 3600 } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
a37d6070 3601 if (!strcmp(token + 23, "off"))
5529ca8a 3602 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
a37d6070 3603 else if (!strcmp(token + 23, "transparent"))
5529ca8a 3604 s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
a37d6070 3605 else if (!strcmp(token + 23, "always"))
5529ca8a 3606 s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
ba724607 3607 else {
5529ca8a 3608 self_destruct();
ba724607
AJ
3609 return;
3610 }
cc192b50 3611 } else if (strcmp(token, "ipv4") == 0) {
4dd643d5 3612 if ( !s->s.setIPv4() ) {
3cc0f4e7 3613 debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": IPv6 addresses cannot be used as IPv4-Only. " << s->s );
cc192b50 3614 self_destruct();
ba724607 3615 return;
cc192b50 3616 }
26ac0430 3617 } else if (strcmp(token, "tcpkeepalive") == 0) {
86ab7a90 3618 s->tcp_keepalive.enabled = true;
b2130d58 3619 } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
26ac0430 3620 char *t = token + 13;
86ab7a90 3621 s->tcp_keepalive.enabled = true;
e398d16e 3622 s->tcp_keepalive.idle = xatoui(t,',');
26ac0430
AJ
3623 t = strchr(t, ',');
3624 if (t) {
a38ec4b1 3625 ++t;
e398d16e 3626 s->tcp_keepalive.interval = xatoui(t,',');
26ac0430
AJ
3627 t = strchr(t, ',');
3628 }
3629 if (t) {
a38ec4b1 3630 ++t;
54a063a2 3631 s->tcp_keepalive.timeout = xatoui(t);
26ac0430 3632 }
cb4f4424 3633#if USE_OPENSSL
a37d6070 3634 } else if (strcmp(token, "sslBump") == 0) {
9a622f3e 3635 debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token << "' is deprecated " <<
3cc0f4e7 3636 "in " << cfg_directive << ". Use 'ssl-bump' instead.");
c3d24490 3637 s->flags.tunnelSslBumping = true;
3a0c8eb5 3638 } else if (strcmp(token, "ssl-bump") == 0) {
c3d24490 3639 s->flags.tunnelSslBumping = true;
154dc884 3640 } else if (strncmp(token, "cert=", 5) == 0) {
9a622f3e 3641 s->secure.parse(token);
154dc884 3642 } else if (strncmp(token, "key=", 4) == 0) {
9a622f3e 3643 s->secure.parse(token);
154dc884 3644 } else if (strncmp(token, "version=", 8) == 0) {
1cc44095
AJ
3645 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token << "' is deprecated " <<
3646 "in " << cfg_directive << ". Use 'options=' instead.");
9a622f3e 3647 s->secure.parse(token);
154dc884 3648 } else if (strncmp(token, "options=", 8) == 0) {
9a622f3e 3649 s->secure.parse(token);
154dc884 3650 } else if (strncmp(token, "cipher=", 7) == 0) {
9a622f3e 3651 s->secure.parse(token);
154dc884 3652 } else if (strncmp(token, "clientca=", 9) == 0) {
3653 safe_free(s->clientca);
3654 s->clientca = xstrdup(token + 9);
3655 } else if (strncmp(token, "cafile=", 7) == 0) {
86a84cc0
AJ
3656 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token << "' is deprecated " <<
3657 "in " << cfg_directive << ". Use 'tls-cafile=' instead.");
9a622f3e 3658 s->secure.parse(token);
154dc884 3659 } else if (strncmp(token, "capath=", 7) == 0) {
9a622f3e 3660 s->secure.parse(token);
154dc884 3661 } else if (strncmp(token, "crlfile=", 8) == 0) {
9a622f3e 3662 s->secure.parse(token);
154dc884 3663 } else if (strncmp(token, "dhparams=", 9) == 0) {
54fbe371
PM
3664 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: '" << token << "' is deprecated " <<
3665 "in " << cfg_directive << ". Use 'tls-dh=' instead.");
474f076e 3666 s->secure.parse(token);
154dc884 3667 } else if (strncmp(token, "sslflags=", 9) == 0) {
8b253b83 3668 // NP: deprecation warnings output by secure.parse() when relevant
9a622f3e 3669 s->secure.parse(token+3);
154dc884 3670 } else if (strncmp(token, "sslcontext=", 11) == 0) {
95d2589c
CT
3671 safe_free(s->sslContextSessionId);
3672 s->sslContextSessionId = xstrdup(token + 11);
3673 } else if (strcmp(token, "generate-host-certificates") == 0) {
3674 s->generateHostCertificates = true;
3675 } else if (strcmp(token, "generate-host-certificates=on") == 0) {
3676 s->generateHostCertificates = true;
3677 } else if (strcmp(token, "generate-host-certificates=off") == 0) {
3678 s->generateHostCertificates = false;
3679 } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) {
3680 parseBytesOptionValue(&s->dynamicCertMemCacheSize, B_BYTES_STR, token + 28);
154dc884 3681#endif
9a622f3e
AJ
3682 } else if (strncmp(token, "tls-", 4) == 0) {
3683 s->secure.parse(token+4);
3cc0f4e7 3684 } else if (strcmp(token, "ftp-track-dirs") == 0) {
27c841f6 3685 s->ftp_track_dirs = true;
3f38a55e 3686 } else {
3cc0f4e7 3687 debugs(3, DBG_CRITICAL, "FATAL: Unknown " << cfg_directive << " option '" << token << "'.");
62e76326 3688 self_destruct();
3f38a55e 3689 }
3690}
3691
3f38a55e 3692void
3693add_http_port(char *portspec)
3694{
fa720bfb 3695 AnyP::PortCfgPointer s = new AnyP::PortCfg();
3cc0f4e7 3696 s->transport = parsePortProtocol(SBuf("HTTP"));
859741ed 3697 parsePortSpecification(s, portspec);
65d448bc 3698 // we may need to merge better if the above returns a list with clones
7e07ced1 3699 assert(s->next == NULL);
fa720bfb
AJ
3700 s->next = HttpPortList;
3701 HttpPortList = s;
3f38a55e 3702}
3703
3704static void
fa720bfb 3705parsePortCfg(AnyP::PortCfgPointer *head, const char *optionName)
d3388e1f 3706{
3cc0f4e7 3707 SBuf protoName;
d3388e1f 3708 if (strcmp(optionName, "http_port") == 0 ||
b5944cff 3709 strcmp(optionName, "ascii_port") == 0)
3cc0f4e7 3710 protoName = "HTTP";
d3388e1f 3711 else if (strcmp(optionName, "https_port") == 0)
3cc0f4e7 3712 protoName = "HTTPS";
434a79b0 3713 else if (strcmp(optionName, "ftp_port") == 0)
3cc0f4e7
AR
3714 protoName = "FTP";
3715 if (protoName.isEmpty()) {
d3388e1f
AR
3716 self_destruct();
3717 return;
3718 }
3719
2eceb328 3720 char *token = ConfigParser::NextToken();
62e76326 3721
9eeb8e4b 3722 if (!token) {
62e76326 3723 self_destruct();
9eeb8e4b 3724 return;
3725 }
62e76326 3726
fa720bfb 3727 AnyP::PortCfgPointer s = new AnyP::PortCfg();
3cc0f4e7 3728 s->transport = parsePortProtocol(protoName); // default; protocol=... overwrites
859741ed 3729 parsePortSpecification(s, token);
62e76326 3730
3f38a55e 3731 /* parse options ... */
2eceb328 3732 while ((token = ConfigParser::NextToken())) {
65d448bc 3733 parse_port_option(s, token);
3f38a55e 3734 }
62e76326 3735
86a84cc0
AJ
3736#if USE_OPENSSL
3737 // if clientca has been defined but not cafile, then use it to verify
3738 // but if cafile has been defined, only use that to verify
3739 if (s->clientca && !s->secure.caFiles.size())
3740 s->secure.caFiles.emplace_back(SBuf(s->clientca));
3741#endif
3742
6507233b 3743 if (s->transport.protocol == AnyP::PROTO_HTTPS) {
49d8cc6f 3744 s->secure.encryptTransport = true;
151ba0d4 3745#if USE_OPENSSL
38450a50 3746 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
c3d24490 3747 const bool hijacked = s->flags.isIntercepted();
6a25a046 3748 if (s->flags.tunnelSslBumping && !hijacked) {
38450a50 3749 debugs(3, DBG_CRITICAL, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
03f00a11 3750 self_destruct();
ba724607 3751 return;
03f00a11 3752 }
6a25a046 3753 if (hijacked && !s->flags.tunnelSslBumping) {
38450a50 3754 debugs(3, DBG_CRITICAL, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
03f00a11 3755 self_destruct();
ba724607 3756 return;
03f00a11 3757 }
03f00a11 3758#endif
a07a354f 3759 if (s->flags.proxySurrogate) {
d3d92daa 3760 debugs(3,DBG_CRITICAL, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
151ba0d4 3761 self_destruct();
ba724607 3762 return;
151ba0d4 3763 }
3cc0f4e7 3764 } else if (protoName.cmp("FTP") == 0) {
434a79b0
DK
3765 /* ftp_port does not support ssl-bump */
3766 if (s->flags.tunnelSslBumping) {
3767 debugs(3, DBG_CRITICAL, "FATAL: ssl-bump is not supported for ftp_port.");
3768 self_destruct();
ba724607 3769 return;
434a79b0 3770 }
a07a354f
AJ
3771 if (s->flags.proxySurrogate) {
3772 // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3773 debugs(3,DBG_CRITICAL, "FATAL: require-proxy-header option is not supported on ftp_port.");
3774 self_destruct();
ba724607 3775 return;
a07a354f 3776 }
151ba0d4 3777 }
03f00a11 3778
4dd643d5 3779 if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.isAnyAddr()) {
7e07ced1 3780 // clone the port options from *s to *(s->next)
fa720bfb 3781 s->next = s->clone();
4dd643d5 3782 s->next->s.setIPv4();
d31d59d8 3783 debugs(3, 3, AnyP::UriScheme(s->transport.protocol).image() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
7e07ced1 3784 }
7e07ced1 3785
fa720bfb
AJ
3786 while (*head != NULL)
3787 head = &((*head)->next);
62e76326 3788
fa720bfb 3789 *head = s;
3f38a55e 3790}
3791
3792static void
fa720bfb 3793dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s)
3f38a55e 3794{
cc192b50 3795 char buf[MAX_IPSTRLEN];
3796
3797 storeAppendPrintf(e, "%s %s",
62e76326 3798 n,
4dd643d5 3799 s->s.toUrl(buf,MAX_IPSTRLEN));
62e76326 3800
df1b20e4 3801 // MODES and specific sub-options.
6a25a046 3802 if (s->flags.natIntercept)
2ad20b4f 3803 storeAppendPrintf(e, " intercept");
62e76326 3804
6a25a046 3805 else if (s->flags.tproxyIntercept)
c7b1dd5d
AJ
3806 storeAppendPrintf(e, " tproxy");
3807
00d0ce87 3808 else if (s->flags.proxySurrogate)
d3d92daa 3809 storeAppendPrintf(e, " require-proxy-header");
00d0ce87 3810
6a25a046 3811 else if (s->flags.accelSurrogate) {
c7b1dd5d
AJ
3812 storeAppendPrintf(e, " accel");
3813
df1b20e4
AJ
3814 if (s->vhost)
3815 storeAppendPrintf(e, " vhost");
62e76326 3816
df1b20e4
AJ
3817 if (s->vport < 0)
3818 storeAppendPrintf(e, " vport");
3819 else if (s->vport > 0)
3820 storeAppendPrintf(e, " vport=%d", s->vport);
5529ca8a 3821
df1b20e4
AJ
3822 if (s->defaultsite)
3823 storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3824
eb6ac808
AJ
3825 // TODO: compare against prefix of 'n' instead of assuming http_port
3826 if (s->transport.protocol != AnyP::PROTO_HTTP)
d31d59d8 3827 storeAppendPrintf(e, " protocol=%s", AnyP::ProtocolType_str[s->transport.protocol]);
df1b20e4
AJ
3828
3829 if (s->allow_direct)
3830 storeAppendPrintf(e, " allow-direct");
3831
3832 if (s->ignore_cc)
3833 storeAppendPrintf(e, " ignore-cc");
3834
3835 }
3836
3837 // Generic independent options
3838
3839 if (s->name)
3840 storeAppendPrintf(e, " name=%s", s->name);
3841
33e701f3 3842#if USE_HTTP_VIOLATIONS
6a25a046 3843 if (!s->flags.accelSurrogate && s->ignore_cc)
df1b20e4
AJ
3844 storeAppendPrintf(e, " ignore-cc");
3845#endif
c7b1dd5d 3846
d67acb4e
AJ
3847 if (s->connection_auth_disabled)
3848 storeAppendPrintf(e, " connection-auth=off");
3849 else
3850 storeAppendPrintf(e, " connection-auth=on");
3851
5529ca8a 3852 if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3853 const char *pmtu;
3854
3855 if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3856 pmtu = "always";
3857 else
3858 pmtu = "transparent";
3859
3860 storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3861 }
b2130d58 3862
4dd643d5 3863 if (s->s.isAnyAddr() && !s->s.isIPv6())
df1b20e4
AJ
3864 storeAppendPrintf(e, " ipv4");
3865
b2130d58 3866 if (s->tcp_keepalive.enabled) {
26ac0430 3867 if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
68924b6d 3868 storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
26ac0430 3869 } else {
68924b6d 3870 storeAppendPrintf(e, " tcpkeepalive");
26ac0430 3871 }
b2130d58 3872 }
154dc884 3873
cb4f4424 3874#if USE_OPENSSL
6a25a046 3875 if (s->flags.tunnelSslBumping)
df1b20e4 3876 storeAppendPrintf(e, " ssl-bump");
9a622f3e 3877#endif
c7b1dd5d 3878
8250ca31 3879 s->secure.dumpCfg(e, "tls-");
154dc884 3880
9a622f3e 3881#if USE_OPENSSL
95d2589c
CT
3882 if (s->sslContextSessionId)
3883 storeAppendPrintf(e, " sslcontext=%s", s->sslContextSessionId);
3884
3885 if (s->generateHostCertificates)
3886 storeAppendPrintf(e, " generate-host-certificates");
3887
3888 if (s->dynamicCertMemCacheSize != std::numeric_limits<size_t>::max())
3889 storeAppendPrintf(e, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s->dynamicCertMemCacheSize, B_BYTES_STR);
154dc884 3890#endif
3f38a55e 3891}
62e76326 3892
3f38a55e 3893static void
fa720bfb 3894dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s)
3f38a55e 3895{
fa720bfb
AJ
3896 for (AnyP::PortCfgPointer p = s; p != NULL; p = p->next) {
3897 dump_generic_port(e, n, p);
62e76326 3898 storeAppendPrintf(e, "\n");
3f38a55e 3899 }
3900}
3901
f150dd4b 3902void
3903configFreeMemory(void)
3904{
23ff6968 3905 free_all();
900daee3 3906 Config.ssl_client.sslContext.reset();
cb4f4424 3907#if USE_OPENSSL
866be11c 3908 Ssl::unloadSquidUntrusted();
29bf4910 3909#endif
f150dd4b 3910}
f0b19334 3911
94439e4e 3912void
f0b19334 3913requirePathnameExists(const char *name, const char *path)
3914{
62e76326 3915
f0b19334 3916 struct stat sb;
08577e16 3917 char pathbuf[BUFSIZ];
f0b19334 3918 assert(path != NULL);
62e76326 3919
0b796acd 3920 if (Config.chroot_dir && (geteuid() == 0)) {
62e76326 3921 snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3922 path = pathbuf;
08577e16 3923 }
62e76326 3924
a572d8be 3925 if (stat(path, &sb) < 0) {
b69e9ffa
AJ
3926 int xerrno = errno;
3927 debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL: ":"ERROR: ") << name << " " << path << ": " << xstrerr(xerrno));
a32a190b
AJ
3928 // keep going to find more issues if we are only checking the config file with "-k parse"
3929 if (opt_parse_cfg_only)
3930 return;
3931 // this is fatal if it is found during startup or reconfigure
a572d8be 3932 if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
b69e9ffa 3933 fatalf("%s %s: %s", name, path, xstrerr(xerrno));
a572d8be 3934 }
f0b19334 3935}
d860a1aa 3936
450e0c10 3937#include "AccessLogEntry.h"
7684c4b1 3938
fb0c2f17
NH
3939/**
3940 * We support several access_log configuration styles:
3941 *
3942 * #1: Deprecated ancient style without an explicit logging module:
3943 * access_log /var/log/access.log
3944 *
3945 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
3946 * access_log none [acl ...]
3947 *
3948 * #3: Configurable logging module without named options:
3949 * Logformat or the first ACL name, whichever comes first, may not contain '='.
3950 * If no explicit logformat name is given, the first ACL name, if any,
3951 * should not be an existing logformat name or it will be treated as such.
3952 * access_log module:place [logformat_name] [acl ...]
3953 *
3954 * #4: Configurable logging module with name=value options such as logformat=x:
3955 * The first ACL name may not contain '='.
3956 * access_log module:place [option ...] [acl ...]
3957 *
3958 */
7684c4b1 3959static void
87ddff6e 3960parse_access_log(CustomLog ** logs)
7684c4b1 3961{
2eceb328 3962 const char *filename = ConfigParser::NextToken();
fb0c2f17 3963 if (!filename) {
7684c4b1 3964 self_destruct();
9eeb8e4b 3965 return;
3966 }
7684c4b1 3967
1847642b
AJ
3968 CustomLog *cl = (CustomLog *)xcalloc(1, sizeof(*cl));
3969
3970 cl->filename = xstrdup(filename);
3971 // default buffer size and fatal settings
3972 cl->bufferSize = 8*MAX_URL;
3973 cl->fatal = true;
3974
7684c4b1 3975 if (strcmp(filename, "none") == 0) {
20efa1c2 3976 cl->type = Log::Format::CLF_NONE;
6f58d7d7 3977 aclParseAclList(LegacyParser, &cl->aclList, filename);
6375a714
AJ
3978 while (*logs)
3979 logs = &(*logs)->next;
3980 *logs = cl;
3981 return;
7684c4b1 3982 }
3983
fb0c2f17 3984 cl->type = Log::Format::CLF_UNKNOWN;
efc23871 3985 cl->rotateCount = -1; // default: use global logfile_rotate setting.
fb0c2f17 3986
bde7a8ce 3987 const char *token = ConfigParser::PeekAtToken();
fb0c2f17
NH
3988 if (!token) { // style #1
3989 // no options to deal with
3990 } else if (!strchr(token, '=')) { // style #3
bde7a8ce
CT
3991 // if logformat name is recognized,
3992 // pop the previewed token; Else it must be an ACL name
3993 if (setLogformat(cl, token, false))
3994 (void)ConfigParser::NextToken();
fb0c2f17
NH
3995 } else { // style #4
3996 do {
3997 if (strncasecmp(token, "on-error=", 9) == 0) {
3998 if (strncasecmp(token+9, "die", 3) == 0) {
3999 cl->fatal = true;
4000 } else if (strncasecmp(token+9, "drop", 4) == 0) {
4001 cl->fatal = false;
4002 } else {
4003 debugs(3, DBG_CRITICAL, "Unknown value for on-error '" <<
4004 token << "' expected 'drop' or 'die'");
1847642b
AJ
4005 xfree(cl->filename);
4006 xfree(cl);
fb0c2f17 4007 self_destruct();
1847642b 4008 return;
fb0c2f17
NH
4009 }
4010 } else if (strncasecmp(token, "buffer-size=", 12) == 0) {
4011 parseBytesOptionValue(&cl->bufferSize, B_BYTES_STR, token+12);
efc23871
AJ
4012 } else if (strncasecmp(token, "rotate=", 7) == 0) {
4013 cl->rotateCount = xatoi(token + 7);
fb0c2f17
NH
4014 } else if (strncasecmp(token, "logformat=", 10) == 0) {
4015 setLogformat(cl, token+10, true);
4016 } else if (!strchr(token, '=')) {
bde7a8ce 4017 // Do not pop the token; it must be an ACL name
fb0c2f17
NH
4018 break; // done with name=value options, now to ACLs
4019 } else {
4020 debugs(3, DBG_CRITICAL, "Unknown access_log option " << token);
1847642b
AJ
4021 xfree(cl->filename);
4022 xfree(cl);
fb0c2f17 4023 self_destruct();
1847642b 4024 return;
fb0c2f17 4025 }
bde7a8ce
CT
4026 // Pop the token, it was a valid "name=value" option
4027 (void)ConfigParser::NextToken();
4028 // Get next with preview ConfigParser::NextToken call.
4029 } while ((token = ConfigParser::PeekAtToken()) != NULL);
fb0c2f17 4030 }
7684c4b1 4031
fb0c2f17
NH
4032 // set format if it has not been specified explicitly
4033 if (cl->type == Log::Format::CLF_UNKNOWN)
4034 setLogformat(cl, "squid", true);
7684c4b1 4035
0a003ce5 4036 aclParseAclList(LegacyParser, &cl->aclList, cl->filename);
fb0c2f17
NH
4037
4038 while (*logs)
4039 logs = &(*logs)->next;
4040
4041 *logs = cl;
4042}
4043
4044/// sets CustomLog::type and, if needed, CustomLog::lf
4045/// returns false iff there is no named log format
4046static bool
4047setLogformat(CustomLog *cl, const char *logdef_name, const bool dieWhenMissing)
4048{
4049 assert(cl);
4050 assert(logdef_name);
4051
4052 debugs(3, 9, "possible " << cl->filename << " logformat: " << logdef_name);
4053
4054 if (cl->type != Log::Format::CLF_UNKNOWN) {
4055 debugs(3, DBG_CRITICAL, "Second logformat name in one access_log: " <<
4056 logdef_name << " " << cl->type << " ? " << Log::Format::CLF_NONE);
4057 self_destruct();
4058 return false;
4059 }
7684c4b1 4060
4061 /* look for the definition pointer corresponding to this name */
38e16f92 4062 Format::Format *lf = Log::TheConfig.logformats;
7684c4b1 4063
4064 while (lf != NULL) {
bf8fe701 4065 debugs(3, 9, "Comparing against '" << lf->name << "'");
7684c4b1 4066
4067 if (strcmp(lf->name, logdef_name) == 0)
4068 break;
4069
4070 lf = lf->next;
4071 }
4072
4073 if (lf != NULL) {
20efa1c2 4074 cl->type = Log::Format::CLF_CUSTOM;
7684c4b1 4075 cl->logFormat = lf;
4076 } else if (strcmp(logdef_name, "auto") == 0) {
fa84c01d 4077 debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
20efa1c2 4078 cl->type = Log::Format::CLF_SQUID;
7684c4b1 4079 } else if (strcmp(logdef_name, "squid") == 0) {
20efa1c2 4080 cl->type = Log::Format::CLF_SQUID;
7684c4b1 4081 } else if (strcmp(logdef_name, "common") == 0) {
20efa1c2
AJ
4082 cl->type = Log::Format::CLF_COMMON;
4083 } else if (strcmp(logdef_name, "combined") == 0) {
4084 cl->type = Log::Format::CLF_COMBINED;
3ff65596
AR
4085#if ICAP_CLIENT
4086 } else if (strcmp(logdef_name, "icap_squid") == 0) {
20efa1c2 4087 cl->type = Log::Format::CLF_ICAP_SQUID;
3ff65596 4088#endif
20efa1c2
AJ
4089 } else if (strcmp(logdef_name, "useragent") == 0) {
4090 cl->type = Log::Format::CLF_USERAGENT;
4091 } else if (strcmp(logdef_name, "referrer") == 0) {
4092 cl->type = Log::Format::CLF_REFERER;
fb0c2f17 4093 } else if (dieWhenMissing) {
fa84c01d 4094 debugs(3, DBG_CRITICAL, "Log format '" << logdef_name << "' is not defined");
7684c4b1 4095 self_destruct();
fb0c2f17
NH
4096 return false;
4097 } else {
4098 return false;
7684c4b1 4099 }
4100
fb0c2f17 4101 return true;
7684c4b1 4102}
4103
d64bef4c 4104static int
87ddff6e 4105check_null_access_log(CustomLog *customlog_definitions)
d64bef4c 4106{
4107 return customlog_definitions == NULL;
4108}
4109
7684c4b1 4110static void
87ddff6e 4111dump_access_log(StoreEntry * entry, const char *name, CustomLog * logs)
7684c4b1 4112{
87ddff6e 4113 CustomLog *log;
7684c4b1 4114
4115 for (log = logs; log; log = log->next) {
4116 storeAppendPrintf(entry, "%s ", name);
4117
4118 switch (log->type) {
4119
20efa1c2 4120 case Log::Format::CLF_CUSTOM:
efc23871 4121 storeAppendPrintf(entry, "%s logformat=%s", log->filename, log->logFormat->name);
7684c4b1 4122 break;
4123
20efa1c2 4124 case Log::Format::CLF_NONE:
efc23871 4125 storeAppendPrintf(entry, "logformat=none");
7684c4b1 4126 break;
4127
20efa1c2 4128 case Log::Format::CLF_SQUID:
efc23871 4129 storeAppendPrintf(entry, "%s logformat=squid", log->filename);
7684c4b1 4130 break;
4131
20efa1c2 4132 case Log::Format::CLF_COMBINED:
efc23871 4133 storeAppendPrintf(entry, "%s logformat=combined", log->filename);
20efa1c2
AJ
4134 break;
4135
4136 case Log::Format::CLF_COMMON:
efc23871 4137 storeAppendPrintf(entry, "%s logformat=common", log->filename);
7684c4b1 4138 break;
20efa1c2 4139
3ff65596 4140#if ICAP_CLIENT
20efa1c2 4141 case Log::Format::CLF_ICAP_SQUID:
efc23871 4142 storeAppendPrintf(entry, "%s logformat=icap_squid", log->filename);
3ff65596
AR
4143 break;
4144#endif
20efa1c2 4145 case Log::Format::CLF_USERAGENT:
efc23871 4146 storeAppendPrintf(entry, "%s logformat=useragent", log->filename);
20efa1c2 4147 break;
7684c4b1 4148
20efa1c2 4149 case Log::Format::CLF_REFERER:
efc23871 4150 storeAppendPrintf(entry, "%s logformat=referrer", log->filename);
7684c4b1 4151 break;
4152
20efa1c2 4153 case Log::Format::CLF_UNKNOWN:
7684c4b1 4154 break;
4155 }
4156
efc23871
AJ
4157 // default is on-error=die
4158 if (!log->fatal)
4159 storeAppendPrintf(entry, " on-error=drop");
4160
4161 // default: 64KB
4162 if (log->bufferSize != 64*1024)
32d3025c 4163 storeAppendPrintf(entry, " buffer-size=%" PRIuSIZE, log->bufferSize);
efc23871
AJ
4164
4165 if (log->rotateCount >= 0)
4166 storeAppendPrintf(entry, " rotate=%d", log->rotateCount);
4167
7684c4b1 4168 if (log->aclList)
4169 dump_acl_list(entry, log->aclList);
4170
4171 storeAppendPrintf(entry, "\n");
4172 }
4173}
4174
7684c4b1 4175static void
87ddff6e 4176free_access_log(CustomLog ** definitions)
7684c4b1 4177{
4178 while (*definitions) {
87ddff6e 4179 CustomLog *log = *definitions;
7684c4b1 4180 *definitions = log->next;
4181
4182 log->logFormat = NULL;
20efa1c2 4183 log->type = Log::Format::CLF_UNKNOWN;
7684c4b1 4184
4185 if (log->aclList)
4186 aclDestroyAclList(&log->aclList);
4187
4188 safe_free(log->filename);
4189
4190 xfree(log);
4191 }
4192}
3a69ddf3 4193
ab7e1298 4194#if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
96c2bb61
AR
4195/// parses list of integers form name=N1,N2,N3,...
4196static bool
c8ea3cc0 4197parseNamedIntList(const char *data, const String &name, std::vector<int> &list)
96c2bb61
AR
4198{
4199 if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) {
4200 data += name.size();
4201 if (*data == '=') {
4202 while (true) {
4203 ++data;
4204 int value = 0;
4205 if (!StringToInt(data, value, &data, 10))
4206 break;
4207 list.push_back(value);
4208 if (*data == '\0' || *data != ',')
4209 break;
4210 }
4211 }
4212 }
cff99cec 4213 return data && *data == '\0';
96c2bb61 4214}
ab7e1298 4215#endif
96c2bb61
AR
4216
4217static void
212af65c
A
4218parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4219{
96c2bb61
AR
4220#if !HAVE_CPU_AFFINITY
4221 debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " <<
4222 "support, do not set 'cpu_affinity_map'");
4223 self_destruct();
96c2bb61 4224
ba724607 4225#else /* HAVE_CPU_AFFINITY */
96c2bb61
AR
4226 if (!*cpuAffinityMap)
4227 *cpuAffinityMap = new CpuAffinityMap;
4228
2eceb328
CT
4229 const char *const pToken = ConfigParser::NextToken();
4230 const char *const cToken = ConfigParser::NextToken();
c8ea3cc0 4231 std::vector<int> processes, cores;
96c2bb61
AR
4232 if (!parseNamedIntList(pToken, "process_numbers", processes)) {
4233 debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " <<
4234 "in 'cpu_affinity_map'");
4235 self_destruct();
4236 } else if (!parseNamedIntList(cToken, "cores", cores)) {
4237 debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " <<
4238 "'cpu_affinity_map'");
4239 self_destruct();
4240 } else if (!(*cpuAffinityMap)->add(processes, cores)) {
4241 debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " <<
4242 "process_numbers and cores lists differ in length or " <<
4243 "contain numbers <= 0");
4244 self_destruct();
4245 }
ba724607 4246#endif
96c2bb61
AR
4247}
4248
4249static void
212af65c
A
4250dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap)
4251{
96c2bb61
AR
4252 if (cpuAffinityMap) {
4253 storeAppendPrintf(entry, "%s process_numbers=", name);
4254 for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4255 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4256 cpuAffinityMap->processes()[i]);
4257 }
4258 storeAppendPrintf(entry, " cores=");
eaed60cc 4259 for (size_t i = 0; i < cpuAffinityMap->cores().size(); ++i) {
96c2bb61
AR
4260 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4261 cpuAffinityMap->cores()[i]);
4262 }
4263 storeAppendPrintf(entry, "\n");
4264 }
4265}
4266
4267static void
212af65c
A
4268free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4269{
96c2bb61
AR
4270 delete *cpuAffinityMap;
4271 *cpuAffinityMap = NULL;
4272}
4273
62c7f90e
AR
4274#if USE_ADAPTATION
4275
4276static void
4277parse_adaptation_service_set_type()
4278{
4279 Adaptation::Config::ParseServiceSet();
4280}
4281
a22e6cd3
AR
4282static void
4283parse_adaptation_service_chain_type()
4284{
4285 Adaptation::Config::ParseServiceChain();
4286}
4287
62c7f90e
AR
4288static void
4289parse_adaptation_access_type()
4290{
4291 Adaptation::Config::ParseAccess(LegacyParser);
4292}
62c7f90e
AR
4293#endif /* USE_ADAPTATION */
4294
3a69ddf3 4295#if ICAP_CLIENT
4296
4297static void
26cc52cb 4298parse_icap_service_type(Adaptation::Icap::Config * cfg)
3a69ddf3 4299{
462e63d3 4300 cfg->parseService();
3a69ddf3 4301}
4302
4303static void
26cc52cb 4304free_icap_service_type(Adaptation::Icap::Config * cfg)
3a69ddf3 4305{
462e63d3 4306 cfg->freeService();
3a69ddf3 4307}
4308
4309static void
26cc52cb 4310dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
3a69ddf3 4311{
462e63d3 4312 cfg.dumpService(entry, name);
3a69ddf3 4313}
4314
4315static void
c939dc70 4316parse_icap_class_type()
3a69ddf3 4317{
fa84c01d 4318 debugs(93, DBG_CRITICAL, "WARNING: 'icap_class' is depricated. " <<
26ac0430 4319 "Use 'adaptation_service_set' instead");
62c7f90e 4320 Adaptation::Config::ParseServiceSet();
3a69ddf3 4321}
4322
3a69ddf3 4323static void
c939dc70 4324parse_icap_access_type()
3a69ddf3 4325{
fa84c01d 4326 debugs(93, DBG_CRITICAL, "WARNING: 'icap_access' is depricated. " <<
26ac0430 4327 "Use 'adaptation_access' instead");
21a26d31 4328 Adaptation::Config::ParseAccess(LegacyParser);
3a69ddf3 4329}
4330
3a69ddf3 4331#endif
21a26d31 4332
21a26d31
AR
4333#if USE_ECAP
4334
4335static void
574b508c 4336parse_ecap_service_type(Adaptation::Ecap::Config * cfg)
21a26d31
AR
4337{
4338 cfg->parseService();
4339}
4340
4341static void
574b508c 4342free_ecap_service_type(Adaptation::Ecap::Config * cfg)
21a26d31
AR
4343{
4344 cfg->freeService();
4345}
4346
4347static void
574b508c 4348dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
21a26d31
AR
4349{
4350 cfg.dumpService(entry, name);
4351}
4352
4353#endif /* USE_ECAP */
8277060a
CT
4354
4355#if ICAP_CLIENT
4356static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4357{
4358 char *token;
4359 time_t d;
4360 time_t m;
4361 cfg->service_failure_limit = GetInteger();
4362
2eceb328 4363 if ((token = ConfigParser::NextToken()) == NULL)
8277060a
CT
4364 return;
4365
4366 if (strcmp(token,"in") != 0) {
fa84c01d 4367 debugs(3, DBG_CRITICAL, "expecting 'in' on'" << config_input_line << "'");
8277060a 4368 self_destruct();
ba724607 4369 return;
8277060a
CT
4370 }
4371
2eceb328 4372 if ((token = ConfigParser::NextToken()) == NULL) {
8277060a 4373 self_destruct();
ba724607 4374 return;
8277060a
CT
4375 }
4376
4377 d = static_cast<time_t> (xatoi(token));
a459e80a 4378
8277060a
CT
4379 m = static_cast<time_t> (1);
4380
4381 if (0 == d)
4382 (void) 0;
2eceb328 4383 else if ((token = ConfigParser::NextToken()) == NULL) {
fa84c01d 4384 debugs(3, DBG_CRITICAL, "No time-units on '" << config_input_line << "'");
8277060a 4385 self_destruct();
ba724607
AJ
4386 return;
4387 } else if ((m = parseTimeUnits(token, false)) == 0) {
8277060a 4388 self_destruct();
ba724607
AJ
4389 return;
4390 }
8277060a
CT
4391
4392 cfg->oldest_service_failure = (m * d);
4393}
4394
4395static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg)
4396{
4397 storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit);
4398 if (cfg.oldest_service_failure > 0) {
4399 storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure);
4400 }
4401 storeAppendPrintf(entry, "\n");
4402}
4403
4404static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4405{
4406 cfg->oldest_service_failure = 0;
4407 cfg->service_failure_limit = 0;
4408}
aebe6888 4409#endif
8277060a 4410
cb4f4424 4411#if USE_OPENSSL
fb2178bb
CT
4412static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
4413{
4414 char *al;
4415 sslproxy_cert_adapt *ca = (sslproxy_cert_adapt *) xcalloc(1, sizeof(sslproxy_cert_adapt));
2eceb328 4416 if ((al = ConfigParser::NextToken()) == NULL) {
1847642b 4417 xfree(ca);
fb2178bb
CT
4418 self_destruct();
4419 return;
4420 }
87f237a9 4421
fb2178bb
CT
4422 const char *param;
4423 if ( char *s = strchr(al, '{')) {
4424 *s = '\0'; // terminate the al string
a38ec4b1 4425 ++s;
fb2178bb
CT
4426 param = s;
4427 s = strchr(s, '}');
4428 if (!s) {
1847642b 4429 xfree(ca);
fb2178bb
CT
4430 self_destruct();
4431 return;
4432 }
4433 *s = '\0';
87f237a9 4434 } else
fb2178bb
CT
4435 param = NULL;
4436
4437 if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidAfter]) == 0) {
4438 ca->alg = Ssl::algSetValidAfter;
b8889258 4439 ca->param = xstrdup("on");
87f237a9 4440 } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidBefore]) == 0) {
fb2178bb 4441 ca->alg = Ssl::algSetValidBefore;
b8889258 4442 ca->param = xstrdup("on");
87f237a9 4443 } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetCommonName]) == 0) {
fb2178bb
CT
4444 ca->alg = Ssl::algSetCommonName;
4445 if (param) {
5367d845
CT
4446 if (strlen(param) > 64) {
4447 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param << "} : using common name longer than 64 bytes is not supported");
1847642b 4448 xfree(ca);
5367d845
CT
4449 self_destruct();
4450 return;
4451 }
b8889258 4452 ca->param = xstrdup(param);
fb2178bb
CT
4453 }
4454 } else {
4455 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al);
1847642b 4456 xfree(ca);
fb2178bb
CT
4457 self_destruct();
4458 return;
4459 }
4460
6f58d7d7 4461 aclParseAclList(LegacyParser, &ca->aclList, al);
fb2178bb 4462
87f237a9 4463 while (*cert_adapt)
fb2178bb
CT
4464 cert_adapt = &(*cert_adapt)->next;
4465
4466 *cert_adapt = ca;
4467}
4468
4469static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt)
4470{
4471 for (sslproxy_cert_adapt *ca = cert_adapt; ca != NULL; ca = ca->next) {
4472 storeAppendPrintf(entry, "%s ", name);
4473 storeAppendPrintf(entry, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca->alg), ca->param);
4474 if (ca->aclList)
4475 dump_acl_list(entry, ca->aclList);
4476 storeAppendPrintf(entry, "\n");
4477 }
4478}
4479
4480static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
4481{
87f237a9 4482 while (*cert_adapt) {
fb2178bb
CT
4483 sslproxy_cert_adapt *ca = *cert_adapt;
4484 *cert_adapt = ca->next;
4485 safe_free(ca->param);
4486
4487 if (ca->aclList)
4488 aclDestroyAclList(&ca->aclList);
4489
4490 safe_free(ca);
4491 }
4492}
aebe6888
CT
4493
4494static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign)
4495{
4496 char *al;
4497 sslproxy_cert_sign *cs = (sslproxy_cert_sign *) xcalloc(1, sizeof(sslproxy_cert_sign));
2eceb328 4498 if ((al = ConfigParser::NextToken()) == NULL) {
1847642b 4499 xfree(cs);
aebe6888
CT
4500 self_destruct();
4501 return;
4502 }
4503
4504 if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignTrusted]) == 0)
4505 cs->alg = Ssl::algSignTrusted;
4506 else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignUntrusted]) == 0)
4507 cs->alg = Ssl::algSignUntrusted;
4508 else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignSelf]) == 0)
4509 cs->alg = Ssl::algSignSelf;
4510 else {
4511 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al);
1847642b 4512 xfree(cs);
aebe6888
CT
4513 self_destruct();
4514 return;
4515 }
4516
6f58d7d7 4517 aclParseAclList(LegacyParser, &cs->aclList, al);
aebe6888 4518
87f237a9 4519 while (*cert_sign)
aebe6888
CT
4520 cert_sign = &(*cert_sign)->next;
4521
4522 *cert_sign = cs;
4523}
4524
4525static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign)
4526{
4527 sslproxy_cert_sign *cs;
4528 for (cs = cert_sign; cs != NULL; cs = cs->next) {
4529 storeAppendPrintf(entry, "%s ", name);
4530 storeAppendPrintf(entry, "%s ", Ssl::certSignAlgorithm(cs->alg));
4531 if (cs->aclList)
4532 dump_acl_list(entry, cs->aclList);
4533 storeAppendPrintf(entry, "\n");
4534 }
4535}
4536
4537static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign)
4538{
87f237a9 4539 while (*cert_sign) {
aebe6888
CT
4540 sslproxy_cert_sign *cs = *cert_sign;
4541 *cert_sign = cs->next;
4542
4543 if (cs->aclList)
4544 aclDestroyAclList(&cs->aclList);
4545
4546 safe_free(cs);
4547 }
4548}
fb2178bb 4549
38450a50
CT
4550class sslBumpCfgRr: public ::RegisteredRunner
4551{
4552public:
4553 static Ssl::BumpMode lastDeprecatedRule;
4554 /* RegisteredRunner API */
21b7990f 4555 virtual void finalizeConfig();
38450a50
CT
4556};
4557
4558Ssl::BumpMode sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
4559
21b7990f 4560RunnerRegistrationEntry(sslBumpCfgRr);
38450a50 4561
21b7990f
AR
4562void
4563sslBumpCfgRr::finalizeConfig()
38450a50
CT
4564{
4565 if (lastDeprecatedRule != Ssl::bumpEnd) {
4566 assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone);
4567 static char buf[1024];
4568 if (lastDeprecatedRule == Ssl::bumpClientFirst) {
4569 strcpy(buf, "ssl_bump deny all");
4570 debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated implicit "
4571 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4572 "must not use implicit rules. Update your ssl_bump rules.");
4573 } else {
4574 strcpy(buf, "ssl_bump allow all");
4575 debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated implicit "
4576 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4577 "inferior to the newer server-first bumping mode. New ssl_bump"
4578 " configurations must not use implicit rules. Update your ssl_bump rules.");
4579 }
4580 parse_line(buf);
4581 }
4582}
4583
caf3666d
AR
4584static void parse_sslproxy_ssl_bump(acl_access **ssl_bump)
4585{
38450a50
CT
4586 typedef const char *BumpCfgStyle;
4587 BumpCfgStyle bcsNone = NULL;
4588 BumpCfgStyle bcsNew = "new client/server-first/none";
4589 BumpCfgStyle bcsOld = "deprecated allow/deny";
4590 static BumpCfgStyle bumpCfgStyleLast = bcsNone;
4591 BumpCfgStyle bumpCfgStyleNow = bcsNone;
caf3666d 4592 char *bm;
2eceb328 4593 if ((bm = ConfigParser::NextToken()) == NULL) {
caf3666d
AR
4594 self_destruct();
4595 return;
4596 }
4597
38450a50
CT
4598 // if this is the first rule proccessed
4599 if (*ssl_bump == NULL) {
4600 bumpCfgStyleLast = bcsNone;
4601 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
4602 }
4603
6f58d7d7 4604 allow_t action = allow_t(ACCESS_ALLOWED);
caf3666d 4605
38450a50 4606 if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpClientFirst]) == 0) {
6f58d7d7 4607 action.kind = Ssl::bumpClientFirst;
38450a50
CT
4608 bumpCfgStyleNow = bcsNew;
4609 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpServerFirst]) == 0) {
6f58d7d7 4610 action.kind = Ssl::bumpServerFirst;
38450a50 4611 bumpCfgStyleNow = bcsNew;
5d65362c
CT
4612 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpPeek]) == 0) {
4613 action.kind = Ssl::bumpPeek;
4614 bumpCfgStyleNow = bcsNew;
4615 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpStare]) == 0) {
4616 action.kind = Ssl::bumpStare;
4617 bumpCfgStyleNow = bcsNew;
4618 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpSplice]) == 0) {
4619 action.kind = Ssl::bumpSplice;
4620 bumpCfgStyleNow = bcsNew;
4621 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpBump]) == 0) {
4622 action.kind = Ssl::bumpBump;
4623 bumpCfgStyleNow = bcsNew;
4624 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpTerminate]) == 0) {
4625 action.kind = Ssl::bumpTerminate;
4626 bumpCfgStyleNow = bcsNew;
38450a50 4627 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpNone]) == 0) {
6f58d7d7 4628 action.kind = Ssl::bumpNone;
38450a50
CT
4629 bumpCfgStyleNow = bcsNew;
4630 } else if (strcmp(bm, "allow") == 0) {
4631 debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated "
4632 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4633 "is usually inferior to the newer server-first "
4634 "bumping mode. Update your ssl_bump rules.");
6f58d7d7 4635 action.kind = Ssl::bumpClientFirst;
38450a50
CT
4636 bumpCfgStyleNow = bcsOld;
4637 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpClientFirst;
4638 } else if (strcmp(bm, "deny") == 0) {
4639 debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated "
4640 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4641 "your ssl_bump rules.");
6f58d7d7 4642 action.kind = Ssl::bumpNone;
38450a50
CT
4643 bumpCfgStyleNow = bcsOld;
4644 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpNone;
caf3666d
AR
4645 } else {
4646 debugs(3, DBG_CRITICAL, "FATAL: unknown ssl_bump mode: " << bm);
4647 self_destruct();
4648 return;
4649 }
4650
38450a50 4651 if (bumpCfgStyleLast != bcsNone && bumpCfgStyleNow != bumpCfgStyleLast) {
87f237a9 4652 debugs(3, DBG_CRITICAL, "FATAL: do not mix " << bumpCfgStyleNow << " actions with " <<
38450a50
CT
4653 bumpCfgStyleLast << " actions. Update your ssl_bump rules.");
4654 self_destruct();
4655 return;
4656 }
4657
4658 bumpCfgStyleLast = bumpCfgStyleNow;
4659
8984b8cd 4660 Acl::AndNode *rule = new Acl::AndNode;
6f58d7d7 4661 rule->context("(ssl_bump rule)", config_input_line);
8984b8cd
CT
4662 rule->lineParse();
4663 // empty rule OK
6f58d7d7
AR
4664
4665 assert(ssl_bump);
4666 if (!*ssl_bump) {
4667 *ssl_bump = new Acl::Tree;
4668 (*ssl_bump)->context("(ssl_bump rules)", config_input_line);
4669 }
caf3666d 4670
6f58d7d7 4671 (*ssl_bump)->add(rule, action);
caf3666d
AR
4672}
4673
4674static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump)
4675{
2cb8d372
FC
4676 if (ssl_bump)
4677 dump_SBufList(entry, ssl_bump->treeDump(name, Ssl::BumpModeStr));
caf3666d
AR
4678}
4679
4680static void free_sslproxy_ssl_bump(acl_access **ssl_bump)
4681{
4682 free_acl_access(ssl_bump);
4683}
8277060a
CT
4684
4685#endif
f4698e0b
CT
4686
4687static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers)
4688{
4689 if (!headers)
4690 return;
4691
4692 for (HeaderWithAclList::iterator hwa = headers->begin(); hwa != headers->end(); ++hwa) {
ced8def3 4693 storeAppendPrintf(entry, "%s %s %s", name, hwa->fieldName.c_str(), hwa->fieldValue.c_str());
f4698e0b
CT
4694 if (hwa->aclList)
4695 dump_acl_list(entry, hwa->aclList);
4696 storeAppendPrintf(entry, "\n");
4697 }
4698}
4699
4700static void parse_HeaderWithAclList(HeaderWithAclList **headers)
4701{
4702 char *fn;
4703 if (!*headers) {
4704 *headers = new HeaderWithAclList;
4705 }
2eceb328 4706 if ((fn = ConfigParser::NextToken()) == NULL) {
f4698e0b
CT
4707 self_destruct();
4708 return;
4709 }
4710 HeaderWithAcl hwa;
4711 hwa.fieldName = fn;
81ab22b6 4712 hwa.fieldId = Http::HeaderLookupTable.lookup(hwa.fieldName).id;
789217a2
FC
4713 if (hwa.fieldId == Http::HdrType::BAD_HDR)
4714 hwa.fieldId = Http::HdrType::OTHER;
f4698e0b 4715
2eceb328
CT
4716 Format::Format *nlf = new ::Format::Format("hdrWithAcl");
4717 ConfigParser::EnableMacros();
bde7a8ce 4718 String buf = ConfigParser::NextQuotedToken();
2eceb328 4719 ConfigParser::DisableMacros();
f4698e0b 4720 hwa.fieldValue = buf.termedBuf();
2eceb328 4721 hwa.quoted = ConfigParser::LastTokenWasQuoted();
f4698e0b 4722 if (hwa.quoted) {
f4698e0b
CT
4723 if (!nlf->parse(hwa.fieldValue.c_str())) {
4724 self_destruct();
4725 return;
4726 }
4727 hwa.valueFormat = nlf;
2eceb328
CT
4728 } else
4729 delete nlf;
6f58d7d7 4730 aclParseAclList(LegacyParser, &hwa.aclList, (hwa.fieldName + ':' + hwa.fieldValue).c_str());
f4698e0b
CT
4731 (*headers)->push_back(hwa);
4732}
4733
4734static void free_HeaderWithAclList(HeaderWithAclList **header)
4735{
4736 if (!(*header))
4737 return;
4738
4739 for (HeaderWithAclList::iterator hwa = (*header)->begin(); hwa != (*header)->end(); ++hwa) {
4740 if (hwa->aclList)
4741 aclDestroyAclList(&hwa->aclList);
4742
4743 if (hwa->valueFormat) {
4744 delete hwa->valueFormat;
4745 hwa->valueFormat = NULL;
4746 }
4747 }
4748 delete *header;
4749 *header = NULL;
4750}
d7f4a0b7
CT
4751
4752static void parse_note(Notes *notes)
4753{
4754 assert(notes);
4755 notes->parse(LegacyParser);
4756}
4757
4758static void dump_note(StoreEntry *entry, const char *name, Notes &notes)
4759{
4760 notes.dump(entry, name);
4761}
4762
4763static void free_note(Notes *notes)
4764{
4765 notes->clean();
4766}
bde7a8ce 4767
ddf5aa2b
CT
4768static bool FtpEspvDeprecated = false;
4769static void parse_ftp_epsv(acl_access **ftp_epsv)
4770{
4771 allow_t ftpEpsvDeprecatedAction;
4772 bool ftpEpsvIsDeprecatedRule = false;
4773
4774 char *t = ConfigParser::PeekAtToken();
e2849af8 4775 if (!t) {
ddf5aa2b
CT
4776 self_destruct();
4777 return;
4778 }
4779
4780 if (!strcmp(t, "off")) {
4781 (void)ConfigParser::NextToken();
4782 ftpEpsvIsDeprecatedRule = true;
4783 ftpEpsvDeprecatedAction = allow_t(ACCESS_DENIED);
4784 } else if (!strcmp(t, "on")) {
4785 (void)ConfigParser::NextToken();
4786 ftpEpsvIsDeprecatedRule = true;
4787 ftpEpsvDeprecatedAction = allow_t(ACCESS_ALLOWED);
4788 }
4789
4790 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4791 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4792 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4793 // then abort
4794 if ((!ftpEpsvIsDeprecatedRule && FtpEspvDeprecated) ||
e2849af8 4795 (ftpEpsvIsDeprecatedRule && !FtpEspvDeprecated && *ftp_epsv != NULL)) {
ddf5aa2b
CT
4796 debugs(3, DBG_CRITICAL, "FATAL: do not mix \"ftp_epsv on|off\" cfg lines with \"ftp_epsv allow|deny ...\" cfg lines. Update your ftp_epsv rules.");
4797 self_destruct();
1847642b 4798 return;
ddf5aa2b
CT
4799 }
4800
4801 if (ftpEpsvIsDeprecatedRule) {
4802 // overwrite previous ftp_epsv lines
4803 delete *ftp_epsv;
4804 if (ftpEpsvDeprecatedAction == allow_t(ACCESS_DENIED)) {
4805 Acl::AndNode *ftpEpsvRule = new Acl::AndNode;
4806 ftpEpsvRule->context("(ftp_epsv rule)", config_input_line);
4807 ACL *a = ACL::FindByName("all");
4808 if (!a) {
1847642b 4809 delete ftpEpsvRule;
ddf5aa2b
CT
4810 self_destruct();
4811 return;
4812 }
4813 ftpEpsvRule->add(a);
4814 *ftp_epsv = new Acl::Tree;
4815 (*ftp_epsv)->context("(ftp_epsv rules)", config_input_line);
4816 (*ftp_epsv)->add(ftpEpsvRule, ftpEpsvDeprecatedAction);
4817 } else
4818 *ftp_epsv = NULL;
4819 FtpEspvDeprecated = true;
4820 } else {
4821 aclParseAccessLine(cfg_directive, LegacyParser, ftp_epsv);
4822 }
4823}
4824
4825static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv)
4826{
dfad5100
FC
4827 if (ftp_epsv)
4828 dump_SBufList(entry, ftp_epsv->treeDump(name, NULL));
ddf5aa2b
CT
4829}
4830
4831static void free_ftp_epsv(acl_access **ftp_epsv)
4832{
4833 free_acl_access(ftp_epsv);
4834 FtpEspvDeprecated = false;
4835}
4836
bde7a8ce 4837static void
ced8def3 4838parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout *config)
32fd6d8a
CT
4839{
4840 time_msec_t tval;
4841 parseTimeLine(&tval, T_SECOND_STR, false, true);
4842 Config.Timeout.urlRewrite = static_cast<time_t>(tval/1000);
4843
4844 char *key, *value;
4845 while(ConfigParser::NextKvPair(key, value)) {
4846 if (strcasecmp(key, "on_timeout") == 0) {
4847 if (strcasecmp(value, "bypass") == 0)
ced8def3 4848 config->action = toutActBypass;
32fd6d8a 4849 else if (strcasecmp(value, "fail") == 0)
ced8def3 4850 config->action = toutActFail;
32fd6d8a 4851 else if (strcasecmp(value, "retry") == 0)
ced8def3 4852 config->action = toutActRetry;
32fd6d8a 4853 else if (strcasecmp(value, "use_configured_response") == 0) {
ced8def3 4854 config->action = toutActUseConfiguredResponse;
32fd6d8a
CT
4855 } else {
4856 debugs(3, DBG_CRITICAL, "FATAL: unsuported \"on_timeout\" action:" << value);
4857 self_destruct();
ba724607 4858 return;
32fd6d8a
CT
4859 }
4860 } else if (strcasecmp(key, "response") == 0) {
ced8def3 4861 config->response = xstrdup(value);
32fd6d8a
CT
4862 } else {
4863 debugs(3, DBG_CRITICAL, "FATAL: unsuported option " << key);
4864 self_destruct();
ba724607 4865 return;
32fd6d8a
CT
4866 }
4867 }
4868
ced8def3 4869 if (config->action == toutActUseConfiguredResponse && !config->response) {
32fd6d8a
CT
4870 debugs(3, DBG_CRITICAL, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4871 self_destruct();
4872 }
4873
ced8def3 4874 if (config->action != toutActUseConfiguredResponse && config->response) {
32fd6d8a
CT
4875 debugs(3, DBG_CRITICAL, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4876 self_destruct();
4877 }
4878}
4879
4880static void
ced8def3 4881dump_UrlHelperTimeout(StoreEntry *entry, const char *name, SquidConfig::UrlHelperTimeout &config)
32fd6d8a
CT
4882{
4883 const char *onTimedOutActions[] = {"bypass", "fail", "retry", "use_configured_response"};
ced8def3 4884 assert(config.action >= 0 && config.action <= toutActUseConfiguredResponse);
32fd6d8a
CT
4885
4886 dump_time_t(entry, name, Config.Timeout.urlRewrite);
ced8def3 4887 storeAppendPrintf(entry, " on_timeout=%s", onTimedOutActions[config.action]);
32fd6d8a 4888
ced8def3
AJ
4889 if (config.response)
4890 storeAppendPrintf(entry, " response=\"%s\"", config.response);
32fd6d8a
CT
4891
4892 storeAppendPrintf(entry, "\n");
4893}
4894
4895static void
ced8def3 4896free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout *config)
32fd6d8a
CT
4897{
4898 Config.Timeout.urlRewrite = 0;
ced8def3
AJ
4899 config->action = 0;
4900 safe_free(config->response);
32fd6d8a
CT
4901}
4902
bde7a8ce 4903static void
ced8def3 4904parse_configuration_includes_quoted_values(bool *)
bde7a8ce
CT
4905{
4906 int val = 0;
4907 parse_onoff(&val);
4908
4909 // If quoted values is set to on then enable new strict mode parsing
4910 if (val) {
4911 ConfigParser::RecognizeQuotedValues = true;
4912 ConfigParser::StrictMode = true;
4913 } else {
4914 ConfigParser::RecognizeQuotedValues = false;
4915 ConfigParser::StrictMode = false;
4916 }
4917}
4918
4919static void
ced8def3 4920dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool)
bde7a8ce
CT
4921{
4922 int val = ConfigParser::RecognizeQuotedValues ? 1 : 0;
4923 dump_onoff(entry, name, val);
4924}
4925
4926static void
ced8def3 4927free_configuration_includes_quoted_values(bool *)
bde7a8ce
CT
4928{
4929 ConfigParser::RecognizeQuotedValues = false;
4930 ConfigParser::StrictMode = false;
4931}
f53969cc 4932
3248e962
CT
4933static void
4934parse_on_unsupported_protocol(acl_access **access)
4935{
44352c16 4936 char *tm;
3248e962
CT
4937 if ((tm = ConfigParser::NextToken()) == NULL) {
4938 self_destruct();
4939 return;
4940 }
4941
4942 allow_t action = allow_t(ACCESS_ALLOWED);
4943 if (strcmp(tm, "tunnel") == 0)
4944 action.kind = 1;
4945 else if (strcmp(tm, "respond") == 0)
4946 action.kind = 2;
4947 else {
4948 debugs(3, DBG_CRITICAL, "FATAL: unknown on_unsupported_protocol mode: " << tm);
4949 self_destruct();
4950 return;
4951 }
4952
4953 Acl::AndNode *rule = new Acl::AndNode;
4954 rule->context("(on_unsupported_protocol rule)", config_input_line);
4955 rule->lineParse();
4956 // empty rule OK
4957
4958 assert(access);
4959 if (!*access) {
4960 *access = new Acl::Tree;
4961 (*access)->context("(on_unsupported_protocol rules)", config_input_line);
4962 }
4963
4964 (*access)->add(rule, action);
4965}
4966
4967static void
4968dump_on_unsupported_protocol(StoreEntry *entry, const char *name, acl_access *access)
4969{
4970 const char *on_error_tunnel_mode_str[] = {
4971 "none",
4972 "tunnel",
4973 "respond",
4974 NULL
4975 };
4976 if (access) {
4977 SBufList lines = access->treeDump(name, on_error_tunnel_mode_str);
4978 dump_SBufList(entry, lines);
4979 }
4980}
4981
4982static void
4983free_on_unsupported_protocol(acl_access **access)
4984{
4985 free_acl_access(access);
4986}
44352c16 4987