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