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