]> git.ipfire.org Git - thirdparty/squid.git/blame - src/cache_cf.cc
Audit updates
[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);
251
ef1955a5 252static void parse_b_size_t(size_t * var);
47f6e231 253static void parse_b_int64_t(int64_t * var);
270b86af 254
c8ea3cc0 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
c8ea3cc0 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
c6f168c1
CT
1466 const unsigned int chTos = tos & 0xFC;
1467 if (chTos != tos) {
1468 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: Tos value '" << tos << "' adjusted to '" << chTos << "'");
1469 tos = chTos;
1470 }
1471
d6827718 1472 CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos);
62e76326 1473
d6827718 1474 l = cbdataAlloc(acl_tos);
62e76326 1475
425de4c8 1476 l->tos = (tos_t)tos;
62e76326 1477
6f58d7d7 1478 aclParseAclList(LegacyParser, &l->aclList, token);
62e76326 1479
d6827718 1480 while (*tail)
62e76326 1481 tail = &(*tail)->next;
1482
d6827718 1483 *tail = l;
1484}
1485
1486static void
1487free_acl_tos(acl_tos ** head)
1488{
1489 while (*head) {
62e76326 1490 acl_tos *l = *head;
1491 *head = l->next;
1492 l->next = NULL;
1493 cbdataFree(l);
d6827718 1494 }
1495}
1496
11e8cfe3 1497#if SO_MARK && USE_LIBCAP
f4f6c2e0 1498
425de4c8
AJ
1499CBDATA_TYPE(acl_nfmark);
1500
1501static void
1502dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head)
1503{
1504 acl_nfmark *l;
1505
1506 for (l = head; l; l = l->next) {
1507 if (l->nfmark > 0)
1508 storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark);
1509 else
1510 storeAppendPrintf(entry, "%s none", name);
1511
1512 dump_acl_list(entry, l->aclList);
1513
1514 storeAppendPrintf(entry, "\n");
1515 }
1516}
1517
1518static void
1519freed_acl_nfmark(void *data)
1520{
1521 acl_nfmark *l = static_cast<acl_nfmark *>(data);
1522 aclDestroyAclList(&l->aclList);
1523}
1524
1525static void
1526parse_acl_nfmark(acl_nfmark ** head)
1527{
1528 acl_nfmark *l;
1529 acl_nfmark **tail = head; /* sane name below */
1530 nfmark_t mark;
2eceb328 1531 char *token = ConfigParser::NextToken();
425de4c8
AJ
1532
1533 if (!token) {
1534 self_destruct();
1535 return;
1536 }
1537
1538 if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) {
1539 self_destruct();
1540 return;
1541 }
1542
1543 CBDATA_INIT_TYPE_FREECB(acl_nfmark, freed_acl_nfmark);
1544
1545 l = cbdataAlloc(acl_nfmark);
1546
1547 l->nfmark = mark;
1548
6f58d7d7 1549 aclParseAclList(LegacyParser, &l->aclList, token);
425de4c8
AJ
1550
1551 while (*tail)
1552 tail = &(*tail)->next;
1553
1554 *tail = l;
1555}
1556
1557static void
1558free_acl_nfmark(acl_nfmark ** head)
1559{
1560 while (*head) {
1561 acl_nfmark *l = *head;
1562 *head = l->next;
1563 l->next = NULL;
1564 cbdataFree(l);
1565 }
1566}
f4f6c2e0 1567#endif /* SO_MARK */
425de4c8 1568
1328cfb7 1569CBDATA_TYPE(AclSizeLimit);
ef1955a5 1570
1571static void
1328cfb7 1572dump_acl_b_size_t(StoreEntry * entry, const char *name, AclSizeLimit * head)
ef1955a5 1573{
1328cfb7 1574 AclSizeLimit *l;
ef1955a5 1575
1576 for (l = head; l; l = l->next) {
ed013b6c 1577 if (l->size != -1)
ef1955a5 1578 storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR);
1579 else
1580 storeAppendPrintf(entry, "%s none", name);
1581
1582 dump_acl_list(entry, l->aclList);
1583
1584 storeAppendPrintf(entry, "\n");
1585 }
1586}
1587
1588static void
1589freed_acl_b_size_t(void *data)
1590{
1328cfb7 1591 AclSizeLimit *l = static_cast<AclSizeLimit *>(data);
ef1955a5 1592 aclDestroyAclList(&l->aclList);
1593}
1594
1595static void
1328cfb7 1596parse_acl_b_size_t(AclSizeLimit ** head)
ef1955a5 1597{
1328cfb7
FC
1598 AclSizeLimit *l;
1599 AclSizeLimit **tail = head; /* sane name below */
ef1955a5 1600
1328cfb7 1601 CBDATA_INIT_TYPE_FREECB(AclSizeLimit, freed_acl_b_size_t);
ef1955a5 1602
1328cfb7 1603 l = cbdataAlloc(AclSizeLimit);
ef1955a5 1604
47f6e231 1605 parse_b_int64_t(&l->size);
ef1955a5 1606
6f58d7d7 1607 aclParseAclList(LegacyParser, &l->aclList, l->size);
ef1955a5 1608
1609 while (*tail)
1610 tail = &(*tail)->next;
1611
1612 *tail = l;
1613}
1614
1615static void
1328cfb7 1616free_acl_b_size_t(AclSizeLimit ** head)
ef1955a5 1617{
1618 while (*head) {
1328cfb7 1619 AclSizeLimit *l = *head;
ef1955a5 1620 *head = l->next;
1621 l->next = NULL;
1622 cbdataFree(l);
1623 }
1624}
1625
9a0a18de 1626#if USE_DELAY_POOLS
59715b38 1627
b67e2c8c 1628#include "DelayConfig.h"
602d9612 1629#include "DelayPools.h"
59715b38 1630/* do nothing - free_delay_pool_count is the magic free function.
ae870270 1631 * this is why delay_pool_count isn't just marked TYPE: u_short
59715b38 1632 */
1633#define free_delay_pool_class(X)
1634#define free_delay_pool_access(X)
1635#define free_delay_pool_rates(X)
1636#define dump_delay_pool_class(X, Y, Z)
1637#define dump_delay_pool_access(X, Y, Z)
1638#define dump_delay_pool_rates(X, Y, Z)
1639
1640static void
b67e2c8c 1641free_delay_pool_count(DelayConfig * cfg)
59715b38 1642{
b67e2c8c 1643 cfg->freePoolCount();
59715b38 1644}
1645
1646static void
b67e2c8c 1647dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg)
59715b38 1648{
b67e2c8c 1649 cfg.dumpPoolCount (entry, name);
59715b38 1650}
1651
1652static void
b67e2c8c 1653parse_delay_pool_count(DelayConfig * cfg)
59715b38 1654{
b67e2c8c 1655 cfg->parsePoolCount();
59715b38 1656}
1657
1658static void
b67e2c8c 1659parse_delay_pool_class(DelayConfig * cfg)
59715b38 1660{
b67e2c8c 1661 cfg->parsePoolClass();
59715b38 1662}
1663
1664static void
b67e2c8c 1665parse_delay_pool_rates(DelayConfig * cfg)
59715b38 1666{
b67e2c8c 1667 cfg->parsePoolRates();
59715b38 1668}
1669
1670static void
b67e2c8c 1671parse_delay_pool_access(DelayConfig * cfg)
59715b38 1672{
a9f20260 1673 cfg->parsePoolAccess(LegacyParser);
59715b38 1674}
62e76326 1675
59715b38 1676#endif
1677
9a0a18de 1678#if USE_DELAY_POOLS
b4cd430a
CT
1679#include "ClientDelayConfig.h"
1680/* do nothing - free_client_delay_pool_count is the magic free function.
ae870270 1681 * this is why client_delay_pool_count isn't just marked TYPE: u_short
b4cd430a
CT
1682 */
1683
1684#define free_client_delay_pool_access(X)
1685#define free_client_delay_pool_rates(X)
1686#define dump_client_delay_pool_access(X, Y, Z)
1687#define dump_client_delay_pool_rates(X, Y, Z)
1688
1689static void
1690free_client_delay_pool_count(ClientDelayConfig * cfg)
1691{
1692 cfg->freePoolCount();
1693}
1694
1695static void
1696dump_client_delay_pool_count(StoreEntry * entry, const char *name, ClientDelayConfig &cfg)
1697{
1698 cfg.dumpPoolCount (entry, name);
1699}
1700
1701static void
1702parse_client_delay_pool_count(ClientDelayConfig * cfg)
1703{
1704 cfg->parsePoolCount();
1705}
1706
1707static void
1708parse_client_delay_pool_rates(ClientDelayConfig * cfg)
1709{
1710 cfg->parsePoolRates();
1711}
1712
1713static void
1714parse_client_delay_pool_access(ClientDelayConfig * cfg)
1715{
1716 cfg->parsePoolAccess(LegacyParser);
1717}
1718#endif
1719
626096be 1720#if USE_HTTP_VIOLATIONS
97474590 1721static void
3b07476b 1722dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
e3dd531e 1723{
3b07476b
CT
1724 if (manglers)
1725 manglers->dumpAccess(entry, name);
97474590 1726}
e3dd531e 1727
97474590 1728static void
3b07476b 1729parse_http_header_access(HeaderManglers **pm)
97474590 1730{
97474590 1731 char *t = NULL;
62e76326 1732
2eceb328 1733 if ((t = ConfigParser::NextToken()) == NULL) {
fa84c01d
FC
1734 debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1735 debugs(3, DBG_CRITICAL, "parse_http_header_access: missing header name.");
62e76326 1736 return;
97474590 1737 }
62e76326 1738
3b07476b
CT
1739 if (!*pm)
1740 *pm = new HeaderManglers;
1741 HeaderManglers *manglers = *pm;
001d55dc 1742 headerMangler *mangler = manglers->track(t);
3b07476b 1743 assert(mangler);
6f58d7d7
AR
1744
1745 std::string directive = "http_header_access ";
1746 directive += t;
2450353f 1747 aclParseAccessLine(directive.c_str(), LegacyParser, &mangler->access_list);
6bccf575 1748}
1749
1750static void
3b07476b 1751free_HeaderManglers(HeaderManglers **pm)
6bccf575 1752{
3b07476b
CT
1753 // we delete the entire http_header_* mangler configuration at once
1754 if (const HeaderManglers *manglers = *pm) {
1755 delete manglers;
1756 *pm = NULL;
6bccf575 1757 }
1758}
1759
1760static void
3b07476b 1761dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
6bccf575 1762{
3b07476b
CT
1763 if (manglers)
1764 manglers->dumpReplacement(entry, name);
97474590 1765}
e3dd531e 1766
97474590 1767static void
3b07476b 1768parse_http_header_replace(HeaderManglers **pm)
e3dd531e 1769{
6bccf575 1770 char *t = NULL;
62e76326 1771
2eceb328 1772 if ((t = ConfigParser::NextToken()) == NULL) {
fa84c01d
FC
1773 debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1774 debugs(3, DBG_CRITICAL, "parse_http_header_replace: missing header name.");
62e76326 1775 return;
6bccf575 1776 }
62e76326 1777
bde7a8ce 1778 const char *value = ConfigParser::NextQuotedOrToEol();
62e76326 1779
3b07476b
CT
1780 if (!*pm)
1781 *pm = new HeaderManglers;
1782 HeaderManglers *manglers = *pm;
1783 manglers->setReplacement(t, value);
97474590 1784}
62e76326 1785
9e8b2f1c 1786#endif
97474590 1787
e90100aa 1788static void
e1f7507e 1789dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap)
e90100aa 1790{
f53b06f9 1791 SwapDir *s;
1792 int i;
d3b3ab85 1793 assert (entry);
62e76326 1794
a38ec4b1 1795 for (i = 0; i < swap.n_configured; ++i) {
c8f4eac4 1796 s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw());
26ac0430 1797 if (!s) continue;
59b2d47f 1798 storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path);
62e76326 1799 s->dump(*entry);
62e76326 1800 storeAppendPrintf(entry, "\n");
f53b06f9 1801 }
1802}
1803
53ad48e6 1804static int
1805check_null_string(char *s)
1806{
1807 return s == NULL;
1808}
1809
2f1431ea 1810#if USE_AUTH
94439e4e 1811static void
9f3d2b2e 1812parse_authparam(Auth::ConfigVector * config)
94439e4e 1813{
1814 char *type_str;
1815 char *param_str;
94439e4e 1816
2eceb328 1817 if ((type_str = ConfigParser::NextToken()) == NULL)
62e76326 1818 self_destruct();
94439e4e 1819
2eceb328 1820 if ((param_str = ConfigParser::NextToken()) == NULL)
62e76326 1821 self_destruct();
94439e4e 1822
5817ee13 1823 /* find a configuration for the scheme in the currently parsed configs... */
9f3d2b2e 1824 Auth::Config *schemeCfg = Auth::Config::Find(type_str);
62e76326 1825
5817ee13
AJ
1826 if (schemeCfg == NULL) {
1827 /* Create a configuration based on the scheme info */
c6cf8dee 1828 Auth::Scheme::Pointer theScheme = Auth::Scheme::Find(type_str);
f5691f9c 1829
5817ee13
AJ
1830 if (theScheme == NULL) {
1831 debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'.");
1832 self_destruct();
62e76326 1833 }
94439e4e 1834
f5691f9c 1835 config->push_back(theScheme->createConfig());
9f3d2b2e 1836 schemeCfg = Auth::Config::Find(type_str);
5817ee13
AJ
1837 if (schemeCfg == NULL) {
1838 debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'.");
1839 self_destruct();
1840 }
94439e4e 1841 }
62e76326 1842
5817ee13 1843 schemeCfg->parse(schemeCfg, config->size(), param_str);
94439e4e 1844}
1845
1846static void
9f3d2b2e 1847free_authparam(Auth::ConfigVector * cfg)
94439e4e 1848{
5817ee13 1849 /* Wipe the Auth globals and Detach/Destruct component config + state. */
c33a88ca 1850 cfg->clear();
62e76326 1851
5817ee13 1852 /* on reconfigure initialize new auth schemes for the new config. */
ec5858ff 1853 if (reconfiguring) {
ccd8a22a 1854 Auth::Init();
94439e4e 1855 }
94439e4e 1856}
1857
1858static void
9f3d2b2e 1859dump_authparam(StoreEntry * entry, const char *name, Auth::ConfigVector cfg)
94439e4e 1860{
9f3d2b2e 1861 for (Auth::ConfigVector::iterator i = cfg.begin(); i != cfg.end(); ++i)
f5691f9c 1862 (*i)->dump(entry, name, (*i));
94439e4e 1863}
2f1431ea 1864#endif /* USE_AUTH */
94439e4e 1865
59b2d47f 1866/* TODO: just return the object, the # is irrelevant */
cd748f27 1867static int
1868find_fstype(char *type)
1869{
59b2d47f 1870 for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i)
4c9eadc2 1871 if (strcasecmp(type, StoreFileSystem::FileSystems().at(i)->type()) == 0)
59b2d47f 1872 return (int)i;
62e76326 1873
cd748f27 1874 return (-1);
1875}
1876
0e4e0e7d 1877static void
e1f7507e 1878parse_cachedir(SquidConfig::_cacheSwap * swap)
0e4e0e7d 1879{
1880 char *type_str;
cd748f27 1881 char *path_str;
c8f4eac4 1882 RefCount<SwapDir> sd;
cd748f27 1883 int i;
1884 int fs;
cd748f27 1885
2eceb328 1886 if ((type_str = ConfigParser::NextToken()) == NULL)
62e76326 1887 self_destruct();
cd748f27 1888
2eceb328 1889 if ((path_str = ConfigParser::NextToken()) == NULL)
62e76326 1890 self_destruct();
cd748f27 1891
c9e2e0e8 1892 fs = find_fstype(type_str);
1893
d1a37072
AJ
1894 if (fs < 0) {
1895 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: This proxy does not support the '" << type_str << "' cache type. Ignoring.");
1896 return;
1897 }
c9e2e0e8 1898
1899 /* reconfigure existing dir */
cd748f27 1900
a38ec4b1 1901 for (i = 0; i < swap->n_configured; ++i) {
c8f4eac4 1902 assert (swap->swapDirs[i].getRaw());
62e76326 1903
2c9e9cba 1904 if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) {
c9e2e0e8 1905 /* this is specific to on-fs Stores. The right
26ac0430 1906 * way to handle this is probably to have a mapping
c9e2e0e8 1907 * from paths to stores, and have on-fs stores
1908 * register with that, and lookip in that in their
1909 * own setup logic. RBC 20041225. TODO.
1910 */
c8f4eac4 1911
1912 sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw());
1913
4c9eadc2 1914 if (strcmp(sd->type(), StoreFileSystem::FileSystems().at(fs)->type()) != 0) {
fa84c01d 1915 debugs(3, DBG_CRITICAL, "ERROR: Can't change type of existing cache_dir " <<
bf8fe701 1916 sd->type() << " " << sd->path << " to " << type_str << ". Restart required");
c9e2e0e8 1917 return;
1918 }
1919
afa75e4b 1920 sd->reconfigure();
62e76326 1921 return;
1922 }
cd748f27 1923 }
1924
c9e2e0e8 1925 /* new cache_dir */
af6a12ee 1926 if (swap->n_configured > 63) {
2c9e9cba
AJ
1927 /* 7 bits, signed */
1928 debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1929 debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many.");
1930 self_destruct();
1931 return;
1932 }
dc986280 1933
cd748f27 1934 allocate_new_swapdir(swap);
c9e2e0e8 1935
4c9eadc2 1936 swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().at(fs)->createSwapDir();
c9e2e0e8 1937
c8f4eac4 1938 sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw());
c9e2e0e8 1939
8e8d4f30 1940 /* parse the FS parameters and options */
d3b3ab85 1941 sd->parse(swap->n_configured, path_str);
c9e2e0e8 1942
d3b3ab85 1943 ++swap->n_configured;
752c3b27 1944}
1945
2d72d4fd 1946static const char *
505e35db 1947peer_type_str(const peer_t type)
1948{
1f140227 1949 const char * result;
1950
0cdcddb9 1951 switch (type) {
62e76326 1952
505e35db 1953 case PEER_PARENT:
1f140227 1954 result = "parent";
62e76326 1955 break;
1956
505e35db 1957 case PEER_SIBLING:
1f140227 1958 result = "sibling";
62e76326 1959 break;
1960
505e35db 1961 case PEER_MULTICAST:
1f140227 1962 result = "multicast";
62e76326 1963 break;
1964
505e35db 1965 default:
1f140227 1966 result = "unknown";
62e76326 1967 break;
505e35db 1968 }
1f140227 1969
1970 return result;
505e35db 1971}
1972
f1dc9b30 1973static void
a3c6762c 1974dump_peer(StoreEntry * entry, const char *name, CachePeer * p)
98ffb7e4 1975{
b802d2cb 1976 CachePeerDomainList *d;
5844d003 1977 NeighborTypeDomainList *t;
505e35db 1978 LOCAL_ARRAY(char, xname, 128);
62e76326 1979
d41de3c1 1980 while (p != NULL) {
4bc48d15 1981 storeAppendPrintf(entry, "%s %s %s %d %d name=%s",
62e76326 1982 name,
1983 p->host,
1984 neighborTypeStr(p),
1985 p->http_port,
4bc48d15
AJ
1986 p->icp.port,
1987 p->name);
62e76326 1988 dump_peer_options(entry, p);
1989
1990 for (d = p->peer_domain; d; d = d->next) {
1991 storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n",
1992 p->host,
1993 d->do_ping ? null_string : "!",
1994 d->domain);
1995 }
1996
1997 if (p->access) {
1998 snprintf(xname, 128, "cache_peer_access %s", p->name);
1999 dump_acl_access(entry, xname, p->access);
2000 }
2001
2002 for (t = p->typelist; t; t = t->next) {
2003 storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
2004 p->host,
2005 peer_type_str(t->type),
2006 t->domain);
2007 }
2008
2009 p = p->next;
d41de3c1 2010 }
98ffb7e4 2011}
2012
86ae97bb
AJ
2013/**
2014 * utility function to prevent getservbyname() being called with a numeric value
2015 * on Windows at least it returns garage results.
2016 */
2017static bool
2018isUnsignedNumeric(const char *str, size_t len)
2019{
2020 if (len < 1) return false;
2021
5e263176 2022 for (; len >0 && *str; ++str, --len) {
86ae97bb
AJ
2023 if (! isdigit(*str))
2024 return false;
2025 }
2026 return true;
2027}
2028
609fac72 2029/**
2030 \param proto 'tcp' or 'udp' for protocol
2031 \returns Port the named service is supposed to be listening on.
2032 */
f45dd259 2033static unsigned short
609fac72 2034GetService(const char *proto)
2035{
2036 struct servent *port = NULL;
2037 /** Parses a port number or service name from the squid.conf */
2eceb328 2038 char *token = ConfigParser::NextToken();
609fac72 2039 if (token == NULL) {
26ac0430
AJ
2040 self_destruct();
2041 return 0; /* NEVER REACHED */
609fac72 2042 }
2043 /** Returns either the service port number from /etc/services */
e1381638 2044 if ( !isUnsignedNumeric(token, strlen(token)) )
86ae97bb 2045 port = getservbyname(token, proto);
609fac72 2046 if (port != NULL) {
f45dd259 2047 return ntohs((unsigned short)port->s_port);
609fac72 2048 }
2049 /** Or a numeric translation of the config text. */
2050 return xatos(token);
2051}
2052
2053/**
2054 \returns Port the named TCP service is supposed to be listening on.
2055 \copydoc GetService(const char *proto)
2056 */
f45dd259 2057inline unsigned short
609fac72 2058GetTcpService(void)
2059{
2060 return GetService("tcp");
2061}
2062
2063/**
2064 \returns Port the named UDP service is supposed to be listening on.
2065 \copydoc GetService(const char *proto)
2066 */
f45dd259 2067inline unsigned short
609fac72 2068GetUdpService(void)
2069{
2070 return GetService("udp");
2071}
2072
8203a132 2073static void
a3c6762c 2074parse_peer(CachePeer ** head)
7813c6d5 2075{
270b86af 2076 char *token = NULL;
a3c6762c
FC
2077 CachePeer *p;
2078 CBDATA_INIT_TYPE_FREECB(CachePeer, peerDestroy);
2079 p = cbdataAlloc(CachePeer);
40a1495e 2080 p->http_port = CACHE_HTTP_PORT;
399cabec 2081 p->icp.port = CACHE_ICP_PORT;
40a1495e 2082 p->weight = 1;
d1b63fc8 2083 p->basetime = 0;
dc835977 2084 p->stats.logged_state = PEER_ALIVE;
62e76326 2085
2eceb328 2086 if ((token = ConfigParser::NextToken()) == NULL)
62e76326 2087 self_destruct();
2088
40a1495e 2089 p->host = xstrdup(token);
26ac0430 2090
be753325 2091 p->name = xstrdup(token);
62e76326 2092
2eceb328 2093 if ((token = ConfigParser::NextToken()) == NULL)
62e76326 2094 self_destruct();
2095
40a1495e 2096 p->type = parseNeighborType(token);
62e76326 2097
0d5a2006 2098 if (p->type == PEER_MULTICAST) {
ccdf4138
FC
2099 p->options.no_digest = true;
2100 p->options.no_netdb_exchange = true;
0d5a2006 2101 }
2102
609fac72 2103 p->http_port = GetTcpService();
62e76326 2104
0e656b69 2105 if (!p->http_port)
2106 self_destruct();
62e76326 2107
609fac72 2108 p->icp.port = GetUdpService();
d67acb4e 2109 p->connection_auth = 2; /* auto */
62e76326 2110
2eceb328 2111 while ((token = ConfigParser::NextToken())) {
a37d6070 2112 if (!strcmp(token, "proxy-only")) {
ccdf4138 2113 p->options.proxy_only = true;
a37d6070 2114 } else if (!strcmp(token, "no-query")) {
ccdf4138 2115 p->options.no_query = true;
a37d6070 2116 } else if (!strcmp(token, "background-ping")) {
ccdf4138 2117 p->options.background_ping = true;
a37d6070 2118 } else if (!strcmp(token, "no-digest")) {
ccdf4138 2119 p->options.no_digest = true;
a37d6070 2120 } else if (!strcmp(token, "no-tproxy")) {
ccdf4138 2121 p->options.no_tproxy = true;
a37d6070 2122 } else if (!strcmp(token, "multicast-responder")) {
ccdf4138 2123 p->options.mcast_responder = true;
8a368316 2124#if PEER_MULTICAST_SIBLINGS
a37d6070 2125 } else if (!strcmp(token, "multicast-siblings")) {
ccdf4138 2126 p->options.mcast_siblings = true;
8a368316 2127#endif
a37d6070 2128 } else if (!strncmp(token, "weight=", 7)) {
62e76326 2129 p->weight = xatoi(token + 7);
a37d6070 2130 } else if (!strncmp(token, "basetime=", 9)) {
62e76326 2131 p->basetime = xatoi(token + 9);
a37d6070 2132 } else if (!strcmp(token, "closest-only")) {
ccdf4138 2133 p->options.closest_only = true;
a37d6070 2134 } else if (!strncmp(token, "ttl=", 4)) {
62e76326 2135 p->mcast.ttl = xatoi(token + 4);
2136
2137 if (p->mcast.ttl < 0)
2138 p->mcast.ttl = 0;
2139
2140 if (p->mcast.ttl > 128)
2141 p->mcast.ttl = 128;
a37d6070 2142 } else if (!strcmp(token, "default")) {
ccdf4138 2143 p->options.default_parent = true;
a37d6070 2144 } else if (!strcmp(token, "round-robin")) {
ccdf4138 2145 p->options.roundrobin = true;
a37d6070 2146 } else if (!strcmp(token, "weighted-round-robin")) {
ccdf4138 2147 p->options.weighted_roundrobin = true;
dc9d133b 2148#if USE_HTCP
a37d6070 2149 } else if (!strcmp(token, "htcp")) {
ccdf4138 2150 p->options.htcp = true;
a37d6070 2151 } else if (!strncmp(token, "htcp=", 5) || !strncmp(token, "htcp-", 5)) {
18191440 2152 /* Note: The htcp- form is deprecated, replaced by htcp= */
ccdf4138 2153 p->options.htcp = true;
18191440
AJ
2154 char *tmp = xstrdup(token+5);
2155 char *mode, *nextmode;
2156 for (mode = nextmode = tmp; mode; mode = nextmode) {
2157 nextmode = strchr(mode, ',');
a38ec4b1
FC
2158 if (nextmode) {
2159 *nextmode = '\0';
2160 ++nextmode;
2161 }
a37d6070 2162 if (!strcmp(mode, "no-clr")) {
18191440
AJ
2163 if (p->options.htcp_only_clr)
2164 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
ccdf4138 2165 p->options.htcp_no_clr = true;
a37d6070 2166 } else if (!strcmp(mode, "no-purge-clr")) {
ccdf4138 2167 p->options.htcp_no_purge_clr = true;
a37d6070 2168 } else if (!strcmp(mode, "only-clr")) {
18191440
AJ
2169 if (p->options.htcp_no_clr)
2170 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
ccdf4138 2171 p->options.htcp_only_clr = true;
a37d6070 2172 } else if (!strcmp(mode, "forward-clr")) {
ccdf4138 2173 p->options.htcp_forward_clr = true;
a37d6070 2174 } else if (!strcmp(mode, "oldsquid")) {
ccdf4138 2175 p->options.htcp_oldsquid = true;
18191440
AJ
2176 } else {
2177 fatalf("invalid HTCP mode '%s'", mode);
2178 }
2179 }
2180 safe_free(tmp);
dc9d133b 2181#endif
a37d6070 2182 } else if (!strcmp(token, "no-netdb-exchange")) {
ccdf4138 2183 p->options.no_netdb_exchange = true;
62e76326 2184
a37d6070 2185 } else if (!strcmp(token, "carp")) {
62e76326 2186 if (p->type != PEER_PARENT)
2187 fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
2188
ccdf4138 2189 p->options.carp = true;
a37d6070 2190 } else if (!strncmp(token, "carp-key=", 9)) {
ccdf4138 2191 if (p->options.carp != true)
de03b596 2192 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port);
ccdf4138 2193 p->options.carp_key.set = true;
de03b596
FC
2194 char *nextkey=token+strlen("carp-key="), *key=nextkey;
2195 for (; key; key = nextkey) {
96f6f33b
A
2196 nextkey=strchr(key,',');
2197 if (nextkey) ++nextkey; // skip the comma, any
a37d6070 2198 if (0==strncmp(key,"scheme",6)) {
ccdf4138 2199 p->options.carp_key.scheme = true;
a37d6070 2200 } else if (0==strncmp(key,"host",4)) {
ccdf4138 2201 p->options.carp_key.host = true;
a37d6070 2202 } else if (0==strncmp(key,"port",4)) {
ccdf4138 2203 p->options.carp_key.port = true;
a37d6070 2204 } else if (0==strncmp(key,"path",4)) {
ccdf4138 2205 p->options.carp_key.path = true;
a37d6070 2206 } else if (0==strncmp(key,"params",6)) {
ccdf4138 2207 p->options.carp_key.params = true;
96f6f33b
A
2208 } else {
2209 fatalf("invalid carp-key '%s'",key);
2210 }
de03b596 2211 }
a37d6070 2212 } else if (!strcmp(token, "userhash")) {
2f1431ea 2213#if USE_AUTH
f7e1d9ce
HN
2214 if (p->type != PEER_PARENT)
2215 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port);
2216
ccdf4138 2217 p->options.userhash = true;
2f1431ea
AJ
2218#else
2219 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port);
2220#endif
a37d6070 2221 } else if (!strcmp(token, "sourcehash")) {
f7e1d9ce
HN
2222 if (p->type != PEER_PARENT)
2223 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port);
2224
ccdf4138 2225 p->options.sourcehash = true;
f7e1d9ce 2226
a37d6070 2227 } else if (!strcmp(token, "no-delay")) {
9a0a18de 2228#if USE_DELAY_POOLS
ccdf4138 2229 p->options.no_delay = true;
9a0a18de
AJ
2230#else
2231 debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
afd88fbe 2232#endif
a37d6070 2233 } else if (!strncmp(token, "login=", 6)) {
62e76326 2234 p->login = xstrdup(token + 6);
2235 rfc1738_unescape(p->login);
a37d6070 2236 } else if (!strncmp(token, "connect-timeout=", 16)) {
62e76326 2237 p->connect_timeout = xatoi(token + 16);
a37d6070 2238 } else if (!strncmp(token, "connect-fail-limit=", 19)) {
ff9970cc 2239 p->connect_fail_limit = xatoi(token + 19);
7e3ce7b9 2240#if USE_CACHE_DIGESTS
a37d6070 2241 } else if (!strncmp(token, "digest-url=", 11)) {
62e76326 2242 p->digest_url = xstrdup(token + 11);
7e3ce7b9 2243#endif
62e76326 2244
a37d6070 2245 } else if (!strcmp(token, "allow-miss")) {
ccdf4138 2246 p->options.allow_miss = true;
a37d6070 2247 } else if (!strncmp(token, "max-conn=", 9)) {
62e76326 2248 p->max_conn = xatoi(token + 9);
e8dca475
CT
2249 } else if (!strncmp(token, "standby=", 8)) {
2250 p->standby.limit = xatoi(token + 8);
a37d6070 2251 } else if (!strcmp(token, "originserver")) {
ccdf4138 2252 p->options.originserver = true;
a37d6070 2253 } else if (!strncmp(token, "name=", 5)) {
62e76326 2254 safe_free(p->name);
2255
2256 if (token[5])
2257 p->name = xstrdup(token + 5);
a37d6070 2258 } else if (!strncmp(token, "forceddomain=", 13)) {
62e76326 2259 safe_free(p->domain);
2260
2261 if (token[13])
2262 p->domain = xstrdup(token + 13);
2263
cb4f4424 2264#if USE_OPENSSL
62e76326 2265
2266 } else if (strcmp(token, "ssl") == 0) {
2267 p->use_ssl = 1;
2268 } else if (strncmp(token, "sslcert=", 8) == 0) {
2269 safe_free(p->sslcert);
2270 p->sslcert = xstrdup(token + 8);
2271 } else if (strncmp(token, "sslkey=", 7) == 0) {
2272 safe_free(p->sslkey);
2273 p->sslkey = xstrdup(token + 7);
2274 } else if (strncmp(token, "sslversion=", 11) == 0) {
54a063a2 2275 p->sslversion = xatoi(token + 11);
62e76326 2276 } else if (strncmp(token, "ssloptions=", 11) == 0) {
2277 safe_free(p->ssloptions);
2278 p->ssloptions = xstrdup(token + 11);
2279 } else if (strncmp(token, "sslcipher=", 10) == 0) {
2280 safe_free(p->sslcipher);
2281 p->sslcipher = xstrdup(token + 10);
2282 } else if (strncmp(token, "sslcafile=", 10) == 0) {
2283 safe_free(p->sslcafile);
a82a4fe4 2284 p->sslcafile = xstrdup(token + 10);
62e76326 2285 } else if (strncmp(token, "sslcapath=", 10) == 0) {
2286 safe_free(p->sslcapath);
a82a4fe4 2287 p->sslcapath = xstrdup(token + 10);
2288 } else if (strncmp(token, "sslcrlfile=", 11) == 0) {
2289 safe_free(p->sslcrlfile);
eaed60cc 2290 p->sslcrlfile = xstrdup(token + 11);
62e76326 2291 } else if (strncmp(token, "sslflags=", 9) == 0) {
2292 safe_free(p->sslflags);
2293 p->sslflags = xstrdup(token + 9);
2294 } else if (strncmp(token, "ssldomain=", 10) == 0) {
2295 safe_free(p->ssldomain);
2296 p->ssldomain = xstrdup(token + 10);
a7ad6e4e 2297#endif
62e76326 2298
2299 } else if (strcmp(token, "front-end-https") == 0) {
2300 p->front_end_https = 1;
2301 } else if (strcmp(token, "front-end-https=on") == 0) {
2302 p->front_end_https = 1;
2303 } else if (strcmp(token, "front-end-https=auto") == 0) {
2304 p->front_end_https = 2;
26ac0430 2305 } else if (strcmp(token, "connection-auth=off") == 0) {
d67acb4e
AJ
2306 p->connection_auth = 0;
2307 } else if (strcmp(token, "connection-auth") == 0) {
2308 p->connection_auth = 1;
2309 } else if (strcmp(token, "connection-auth=on") == 0) {
2310 p->connection_auth = 1;
2311 } else if (strcmp(token, "connection-auth=auto") == 0) {
2312 p->connection_auth = 2;
9d22bac3
AJ
2313 } else if (token[0] == '#') {
2314 // start of a text comment. stop reading this line.
2315 break;
62e76326 2316 } else {
9d22bac3 2317 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Ignoring unknown cache_peer option '" << token << "'");
62e76326 2318 }
270b86af 2319 }
62e76326 2320
be753325 2321 if (peerFindByName(p->name))
62e76326 2322 fatalf("ERROR: cache_peer %s specified twice\n", p->name);
2323
e8dca475
CT
2324 if (p->max_conn > 0 && p->max_conn < p->standby.limit)
2325 fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p->host, p->max_conn, p->standby.limit);
2326
40a1495e 2327 if (p->weight < 1)
62e76326 2328 p->weight = 1;
2329
ff9970cc 2330 if (p->connect_fail_limit < 1)
a4d889e0 2331 p->connect_fail_limit = 10;
ff9970cc 2332
399cabec 2333 p->icp.version = ICP_VERSION_CURRENT;
62e76326 2334
cfd66529 2335 p->testing_now = false;
62e76326 2336
e13ee7ad 2337#if USE_CACHE_DIGESTS
62e76326 2338
e13ee7ad 2339 if (!p->options.no_digest) {
62e76326 2340 /* XXX This looks odd.. who has the original pointer
2341 * then?
2342 */
2343 PeerDigest *pd = peerDigestCreate(p);
2344 p->digest = cbdataReference(pd);
8a6218c6 2345 }
62e76326 2346
e13ee7ad 2347#endif
cc192b50 2348
2349 p->index = ++Config.npeers;
2350
0153d498 2351 while (*head != NULL)
62e76326 2352 head = &(*head)->next;
2353
0153d498 2354 *head = p;
62e76326 2355
32a47e3e 2356 peerClearRRStart();
0153d498 2357}
2358
2359static void
a3c6762c 2360free_peer(CachePeer ** P)
0153d498 2361{
a3c6762c 2362 CachePeer *p;
62e76326 2363
79d39a72 2364 while ((p = *P) != NULL) {
62e76326 2365 *P = p->next;
3855c318 2366#if USE_CACHE_DIGESTS
62e76326 2367
2368 cbdataReferenceDone(p->digest);
3855c318 2369#endif
62e76326 2370
e8dca475
CT
2371 // the mgr job will notice that its owner is gone and stop
2372 PeerPoolMgr::Checkpoint(p->standby.mgr, "peer gone");
2373 delete p->standby.pool;
62e76326 2374 cbdataFree(p);
a47b9029 2375 }
62e76326 2376
987c67d1 2377 Config.npeers = 0;
270b86af 2378}
2379
2380static void
613924ee 2381dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list)
270b86af 2382{
d41de3c1 2383 wordlist *w;
62e76326 2384
d41de3c1 2385 while (list != NULL) {
62e76326 2386 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
2387 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
2388 else
2389 storeAppendPrintf(entry, "%s %s", name, list->passwd);
2390
2391 for (w = list->actions; w != NULL; w = w->next) {
2392 storeAppendPrintf(entry, " %s", w->key);
2393 }
2394
2395 storeAppendPrintf(entry, "\n");
2396 list = list->next;
d41de3c1 2397 }
270b86af 2398}
2399
2400static void
613924ee 2401parse_cachemgrpasswd(Mgr::ActionPasswordList ** head)
270b86af 2402{
2403 char *passwd = NULL;
2404 wordlist *actions = NULL;
613924ee
FC
2405 Mgr::ActionPasswordList *p;
2406 Mgr::ActionPasswordList **P;
270b86af 2407 parse_string(&passwd);
2408 parse_wordlist(&actions);
613924ee 2409 p = new Mgr::ActionPasswordList;
22f3fd98 2410 p->passwd = passwd;
2411 p->actions = actions;
62e76326 2412
26aa7e31 2413 for (P = head; *P; P = &(*P)->next) {
62e76326 2414 /*
2415 * See if any of the actions from this line already have a
2416 * password from previous lines. The password checking
2417 * routines in cache_manager.c take the the password from
613924ee 2418 * the first Mgr::ActionPasswordList that contains the
62e76326 2419 * requested action. Thus, we should warn users who might
2420 * think they can have two passwords for the same action.
2421 */
2422 wordlist *w;
2423 wordlist *u;
2424
2425 for (w = (*P)->actions; w; w = w->next) {
2426 for (u = actions; u; u = u->next) {
2427 if (strcmp(w->key, u->key))
2428 continue;
2429
fa84c01d 2430 debugs(0, DBG_CRITICAL, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password");
62e76326 2431 }
2432 }
26aa7e31 2433 }
62e76326 2434
22f3fd98 2435 *P = p;
270b86af 2436}
2437
2438static void
613924ee 2439free_cachemgrpasswd(Mgr::ActionPasswordList ** head)
270b86af 2440{
613924ee 2441 Mgr::ActionPasswordList *p;
62e76326 2442
79d39a72 2443 while ((p = *head) != NULL) {
62e76326 2444 *head = p->next;
2445 xfree(p->passwd);
2446 wordlistDestroy(&p->actions);
2447 xfree(p);
a47b9029 2448 }
270b86af 2449}
2450
8203a132 2451static void
7f0b3324 2452dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var)
270b86af 2453{
6be70545 2454 AclNameList *a;
62e76326 2455
d41de3c1 2456 while (var != NULL) {
62e76326 2457 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
2458
2459 for (a = var->acl_list; a != NULL; a = a->next)
2460 storeAppendPrintf(entry, " %s", a->name);
2461
2462 storeAppendPrintf(entry, "\n");
2463
2464 var = var->next;
d41de3c1 2465 }
270b86af 2466}
2467
2468static void
7f0b3324 2469parse_denyinfo(AclDenyInfoList ** var)
6e40f263 2470{
f1dc9b30 2471 aclParseDenyInfoLine(var);
6e40f263 2472}
403279e0 2473
1273d501 2474void
7f0b3324 2475free_denyinfo(AclDenyInfoList ** list)
3c5557f9 2476{
7f0b3324
FC
2477 AclDenyInfoList *a = NULL;
2478 AclDenyInfoList *a_next = NULL;
6be70545
FC
2479 AclNameList *l = NULL;
2480 AclNameList *l_next = NULL;
62e76326 2481
1273d501 2482 for (a = *list; a; a = a_next) {
62e76326 2483 for (l = a->acl_list; l; l = l_next) {
2484 l_next = l->next;
2485 memFree(l, MEM_ACL_NAME_LIST);
2486 l = NULL;
2487 }
2488
2489 a_next = a->next;
2490 memFree(a, MEM_ACL_DENY_INFO_LIST);
2491 a = NULL;
1273d501 2492 }
62e76326 2493
1273d501 2494 *list = NULL;
270b86af 2495}
2496
2497static void
505e35db 2498parse_peer_access(void)
270b86af 2499{
2500 char *host = NULL;
a3c6762c 2501 CachePeer *p;
62e76326 2502
2eceb328 2503 if (!(host = ConfigParser::NextToken()))
62e76326 2504 self_destruct();
2505
0cdcddb9 2506 if ((p = peerFindByName(host)) == NULL) {
fa84c01d 2507 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
62e76326 2508 return;
0cdcddb9 2509 }
62e76326 2510
6f58d7d7
AR
2511 std::string directive = "peer_access ";
2512 directive += host;
2513 aclParseAccessLine(directive.c_str(), LegacyParser, &p->access);
270b86af 2514}
2515
270b86af 2516static void
2517parse_hostdomain(void)
2518{
2519 char *host = NULL;
2520 char *domain = NULL;
62e76326 2521
2eceb328 2522 if (!(host = ConfigParser::NextToken()))
62e76326 2523 self_destruct();
2524
2eceb328 2525 while ((domain = ConfigParser::NextToken())) {
b802d2cb
FC
2526 CachePeerDomainList *l = NULL;
2527 CachePeerDomainList **L = NULL;
a3c6762c 2528 CachePeer *p;
62e76326 2529
2530 if ((p = peerFindByName(host)) == NULL) {
fa84c01d 2531 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
62e76326 2532 continue;
2533 }
2534
b802d2cb
FC
2535 l = static_cast<CachePeerDomainList *>(xcalloc(1, sizeof(CachePeerDomainList)));
2536 l->do_ping = true;
62e76326 2537
2538 if (*domain == '!') { /* check for !.edu */
b802d2cb 2539 l->do_ping = false;
a38ec4b1 2540 ++domain;
62e76326 2541 }
2542
2543 l->domain = xstrdup(domain);
2544
3d0ac046 2545 for (L = &(p->peer_domain); *L; L = &((*L)->next));
62e76326 2546 *L = l;
f1dc9b30 2547 }
270b86af 2548}
2549
2550static void
2551parse_hostdomaintype(void)
2552{
2553 char *host = NULL;
2554 char *type = NULL;
2555 char *domain = NULL;
62e76326 2556
2eceb328 2557 if (!(host = ConfigParser::NextToken()))
62e76326 2558 self_destruct();
2559
2eceb328 2560 if (!(type = ConfigParser::NextToken()))
62e76326 2561 self_destruct();
2562
2eceb328 2563 while ((domain = ConfigParser::NextToken())) {
5844d003
FC
2564 NeighborTypeDomainList *l = NULL;
2565 NeighborTypeDomainList **L = NULL;
a3c6762c 2566 CachePeer *p;
62e76326 2567
2568 if ((p = peerFindByName(host)) == NULL) {
fa84c01d 2569 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
62e76326 2570 return;
2571 }
2572
5844d003 2573 l = static_cast<NeighborTypeDomainList *>(xcalloc(1, sizeof(NeighborTypeDomainList)));
62e76326 2574 l->type = parseNeighborType(type);
2575 l->domain = xstrdup(domain);
2576
3d0ac046 2577 for (L = &(p->typelist); *L; L = &((*L)->next));
62e76326 2578 *L = l;
f1dc9b30 2579 }
270b86af 2580}
2581
270b86af 2582static void
a7d59104 2583dump_int(StoreEntry * entry, const char *name, int var)
270b86af 2584{
f53b06f9 2585 storeAppendPrintf(entry, "%s %d\n", name, var);
270b86af 2586}
c1c29eb6 2587
94439e4e 2588void
270b86af 2589parse_int(int *var)
2590{
270b86af 2591 int i;
0e4e0e7d 2592 i = GetInteger();
270b86af 2593 *var = i;
2594}
090089c4 2595
0153d498 2596static void
2597free_int(int *var)
2598{
a47b9029 2599 *var = 0;
0153d498 2600}
2601
270b86af 2602static void
a7d59104 2603dump_onoff(StoreEntry * entry, const char *name, int var)
270b86af 2604{
f53b06f9 2605 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
270b86af 2606}
090089c4 2607
d205783b 2608void
270b86af 2609parse_onoff(int *var)
2610{
2eceb328 2611 char *token = ConfigParser::NextToken();
090089c4 2612
270b86af 2613 if (token == NULL)
62e76326 2614 self_destruct();
2615
a37d6070 2616 if (!strcmp(token, "on")) {
62e76326 2617 *var = 1;
a37d6070 2618 } else if (!strcmp(token, "enable")) {
54a063a2
TX
2619 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2620 *var = 1;
a37d6070 2621 } else if (!strcmp(token, "off")) {
62e76326 2622 *var = 0;
a37d6070 2623 } else if (!strcmp(token, "disable")) {
54a063a2
TX
2624 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2625 *var = 0;
2626 } else {
2627 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2628 self_destruct();
2629 }
270b86af 2630}
e90100aa 2631
0153d498 2632#define free_onoff free_int
52d3f198 2633
2634static void
2635dump_tristate(StoreEntry * entry, const char *name, int var)
2636{
2637 const char *state;
2638
2639 if (var > 0)
2640 state = "on";
2641 else if (var < 0)
2642 state = "warn";
2643 else
2644 state = "off";
2645
2646 storeAppendPrintf(entry, "%s %s\n", name, state);
2647}
2648
2649static void
2650parse_tristate(int *var)
2651{
2eceb328 2652 char *token = ConfigParser::NextToken();
52d3f198 2653
2654 if (token == NULL)
2655 self_destruct();
2656
a37d6070 2657 if (!strcmp(token, "on")) {
54a063a2 2658 *var = 1;
a37d6070 2659 } else if (!strcmp(token, "enable")) {
54a063a2 2660 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
52d3f198 2661 *var = 1;
a37d6070 2662 } else if (!strcmp(token, "warn")) {
52d3f198 2663 *var = -1;
a37d6070 2664 } else if (!strcmp(token, "off")) {
52d3f198 2665 *var = 0;
a37d6070 2666 } else if (!strcmp(token, "disable")) {
54a063a2
TX
2667 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2668 *var = 0;
2669 } else {
2670 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2671 self_destruct();
2672 }
52d3f198 2673}
2674
2675#define free_tristate free_int
30a4f2a8 2676
079a8480
AJ
2677void
2678parse_pipelinePrefetch(int *var)
2679{
bde7a8ce 2680 char *token = ConfigParser::PeekAtToken();
079a8480
AJ
2681
2682 if (token == NULL)
2683 self_destruct();
2684
2685 if (!strcmp(token, "on")) {
2686 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2687 *var = 1;
bde7a8ce
CT
2688 //pop the token
2689 (void)ConfigParser::NextToken();
079a8480
AJ
2690 } else if (!strcmp(token, "off")) {
2691 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2692 *var = 0;
bde7a8ce
CT
2693 //pop the token
2694 (void)ConfigParser::NextToken();
2695 } else
079a8480 2696 parse_int(var);
079a8480
AJ
2697}
2698
2699#define free_pipelinePrefetch free_int
2700#define dump_pipelinePrefetch dump_int
2701
270b86af 2702static void
8d9a8184 2703dump_refreshpattern(StoreEntry * entry, const char *name, RefreshPattern * head)
270b86af 2704{
d41de3c1 2705 while (head != NULL) {
0e1d7629 2706 storeAppendPrintf(entry, "%s%s %s %d %d%% %d",
62e76326 2707 name,
2708 head->flags.icase ? " -i" : null_string,
2709 head->pattern,
2710 (int) head->min / 60,
2711 (int) (100.0 * head->pct + 0.5),
2712 (int) head->max / 60);
4c3ef9b2 2713
570d3f75
AJ
2714 if (head->max_stale >= 0)
2715 storeAppendPrintf(entry, " max-stale=%d", head->max_stale);
2716
4c3ef9b2 2717 if (head->flags.refresh_ims)
2718 storeAppendPrintf(entry, " refresh-ims");
2719
3d8b6ba4
AJ
2720 if (head->flags.store_stale)
2721 storeAppendPrintf(entry, " store-stale");
2722
626096be 2723#if USE_HTTP_VIOLATIONS
62e76326 2724
2725 if (head->flags.override_expire)
2726 storeAppendPrintf(entry, " override-expire");
2727
2728 if (head->flags.override_lastmod)
2729 storeAppendPrintf(entry, " override-lastmod");
2730
2731 if (head->flags.reload_into_ims)
2732 storeAppendPrintf(entry, " reload-into-ims");
2733
2734 if (head->flags.ignore_reload)
2735 storeAppendPrintf(entry, " ignore-reload");
2736
38f9c547 2737 if (head->flags.ignore_no_store)
2738 storeAppendPrintf(entry, " ignore-no-store");
2739
4ca08219
AJ
2740 if (head->flags.ignore_must_revalidate)
2741 storeAppendPrintf(entry, " ignore-must-revalidate");
2742
38f9c547 2743 if (head->flags.ignore_private)
2744 storeAppendPrintf(entry, " ignore-private");
2745
2746 if (head->flags.ignore_auth)
2747 storeAppendPrintf(entry, " ignore-auth");
2748
9f60cfdf 2749#endif
62e76326 2750
2751 storeAppendPrintf(entry, "\n");
2752
2753 head = head->next;
d41de3c1 2754 }
270b86af 2755}
090089c4 2756
270b86af 2757static void
8d9a8184 2758parse_refreshpattern(RefreshPattern ** head)
270b86af 2759{
f1dc9b30 2760 char *token;
2761 char *pattern;
2762 time_t min = 0;
c3f6d204 2763 double pct = 0.0;
f1dc9b30 2764 time_t max = 0;
4c3ef9b2 2765 int refresh_ims = 0;
3d8b6ba4 2766 int store_stale = 0;
570d3f75 2767 int max_stale = -1;
3d8b6ba4 2768
626096be 2769#if USE_HTTP_VIOLATIONS
62e76326 2770
1dfa1d81 2771 int override_expire = 0;
2772 int override_lastmod = 0;
cbe3a719 2773 int reload_into_ims = 0;
2774 int ignore_reload = 0;
38f9c547 2775 int ignore_no_store = 0;
4ca08219 2776 int ignore_must_revalidate = 0;
38f9c547 2777 int ignore_private = 0;
2778 int ignore_auth = 0;
9f60cfdf 2779#endif
62e76326 2780
f1dc9b30 2781 int i;
8d9a8184 2782 RefreshPattern *t;
f1dc9b30 2783 regex_t comp;
2784 int errcode;
2785 int flags = REG_EXTENDED | REG_NOSUB;
62e76326 2786
bde7a8ce 2787 if ((token = ConfigParser::RegexPattern()) != NULL) {
2f3c75c3
AJ
2788
2789 if (strcmp(token, "-i") == 0) {
2790 flags |= REG_ICASE;
bde7a8ce 2791 token = ConfigParser::RegexPattern();
2f3c75c3
AJ
2792 } else if (strcmp(token, "+i") == 0) {
2793 flags &= ~REG_ICASE;
bde7a8ce 2794 token = ConfigParser::RegexPattern();
2f3c75c3 2795 }
62e76326 2796
f1dc9b30 2797 }
62e76326 2798
9eeb8e4b 2799 if (token == NULL) {
2f3c75c3 2800 debugs(3, DBG_CRITICAL, "FATAL: refresh_pattern missing the regex pattern parameter");
62e76326 2801 self_destruct();
9eeb8e4b 2802 return;
2803 }
62e76326 2804
f1dc9b30 2805 pattern = xstrdup(token);
62e76326 2806
0e4e0e7d 2807 i = GetInteger(); /* token: min */
62e76326 2808
a632ba71
AJ
2809 /* catch negative and insanely huge values close to 32-bit wrap */
2810 if (i < 0) {
2811 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2812 i = 0;
2813 }
2814 if (i > 60*24*365) {
2815 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2816 i = 60*24*365;
2817 }
2818
f1dc9b30 2819 min = (time_t) (i * 60); /* convert minutes to seconds */
62e76326 2820
54a063a2 2821 i = GetPercentage(); /* token: pct */
62e76326 2822
c3f6d204 2823 pct = (double) i / 100.0;
62e76326 2824
0e4e0e7d 2825 i = GetInteger(); /* token: max */
62e76326 2826
a632ba71
AJ
2827 /* catch negative and insanely huge values close to 32-bit wrap */
2828 if (i < 0) {
2829 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2830 i = 0;
2831 }
2832 if (i > 60*24*365) {
2833 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2834 i = 60*24*365;
2835 }
2836
f1dc9b30 2837 max = (time_t) (i * 60); /* convert minutes to seconds */
62e76326 2838
1dfa1d81 2839 /* Options */
2eceb328 2840 while ((token = ConfigParser::NextToken()) != NULL) {
4c3ef9b2 2841 if (!strcmp(token, "refresh-ims")) {
2842 refresh_ims = 1;
3d8b6ba4
AJ
2843 } else if (!strcmp(token, "store-stale")) {
2844 store_stale = 1;
570d3f75 2845 } else if (!strncmp(token, "max-stale=", 10)) {
54a063a2 2846 max_stale = xatoi(token + 10);
626096be 2847#if USE_HTTP_VIOLATIONS
62e76326 2848
4c3ef9b2 2849 } else if (!strcmp(token, "override-expire"))
62e76326 2850 override_expire = 1;
2851 else if (!strcmp(token, "override-lastmod"))
2852 override_lastmod = 1;
38f9c547 2853 else if (!strcmp(token, "ignore-no-store"))
2854 ignore_no_store = 1;
4ca08219
AJ
2855 else if (!strcmp(token, "ignore-must-revalidate"))
2856 ignore_must_revalidate = 1;
38f9c547 2857 else if (!strcmp(token, "ignore-private"))
2858 ignore_private = 1;
2859 else if (!strcmp(token, "ignore-auth"))
2860 ignore_auth = 1;
62e76326 2861 else if (!strcmp(token, "reload-into-ims")) {
2862 reload_into_ims = 1;
2863 refresh_nocache_hack = 1;
2864 /* tell client_side.c that this is used */
2865 } else if (!strcmp(token, "ignore-reload")) {
2866 ignore_reload = 1;
2867 refresh_nocache_hack = 1;
2868 /* tell client_side.c that this is used */
9f60cfdf 2869#endif
62e76326 2870
7ed5335a
AJ
2871 } else if (!strcmp(token, "ignore-no-cache")) {
2872 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it.");
4c3ef9b2 2873 } else
fa84c01d 2874 debugs(22, DBG_CRITICAL, "refreshAddToList: Unknown option '" << pattern << "': " << token);
1dfa1d81 2875 }
62e76326 2876
f1dc9b30 2877 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
62e76326 2878 char errbuf[256];
2879 regerror(errcode, &comp, errbuf, sizeof errbuf);
fa84c01d
FC
2880 debugs(22, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2881 debugs(22, DBG_CRITICAL, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
eeaa522f 2882 xfree(pattern);
62e76326 2883 return;
f1dc9b30 2884 }
62e76326 2885
c3f6d204 2886 pct = pct < 0.0 ? 0.0 : pct;
f1dc9b30 2887 max = max < 0 ? 0 : max;
8d9a8184 2888 t = static_cast<RefreshPattern *>(xcalloc(1, sizeof(RefreshPattern)));
f1dc9b30 2889 t->pattern = (char *) xstrdup(pattern);
2890 t->compiled_pattern = comp;
2891 t->min = min;
c3f6d204 2892 t->pct = pct;
f1dc9b30 2893 t->max = max;
62e76326 2894
c3f6d204 2895 if (flags & REG_ICASE)
be4d35dc 2896 t->flags.icase = true;
62e76326 2897
4c3ef9b2 2898 if (refresh_ims)
be4d35dc 2899 t->flags.refresh_ims = true;
4c3ef9b2 2900
3d8b6ba4 2901 if (store_stale)
be4d35dc 2902 t->flags.store_stale = true;
3d8b6ba4 2903
570d3f75
AJ
2904 t->max_stale = max_stale;
2905
626096be 2906#if USE_HTTP_VIOLATIONS
62e76326 2907
1dfa1d81 2908 if (override_expire)
be4d35dc 2909 t->flags.override_expire = true;
62e76326 2910
1dfa1d81 2911 if (override_lastmod)
be4d35dc 2912 t->flags.override_lastmod = true;
62e76326 2913
cbe3a719 2914 if (reload_into_ims)
be4d35dc 2915 t->flags.reload_into_ims = true;
62e76326 2916
cbe3a719 2917 if (ignore_reload)
be4d35dc 2918 t->flags.ignore_reload = true;
62e76326 2919
38f9c547 2920 if (ignore_no_store)
be4d35dc 2921 t->flags.ignore_no_store = true;
38f9c547 2922
4ca08219 2923 if (ignore_must_revalidate)
be4d35dc 2924 t->flags.ignore_must_revalidate = true;
4ca08219 2925
38f9c547 2926 if (ignore_private)
be4d35dc 2927 t->flags.ignore_private = true;
38f9c547 2928
2929 if (ignore_auth)
be4d35dc 2930 t->flags.ignore_auth = true;
38f9c547 2931
9f60cfdf 2932#endif
62e76326 2933
f1dc9b30 2934 t->next = NULL;
62e76326 2935
f1dc9b30 2936 while (*head)
62e76326 2937 head = &(*head)->next;
2938
f1dc9b30 2939 *head = t;
62e76326 2940
f1dc9b30 2941 safe_free(pattern);
270b86af 2942}
090089c4 2943
270b86af 2944static void
8d9a8184 2945free_refreshpattern(RefreshPattern ** head)
270b86af 2946{
8d9a8184 2947 RefreshPattern *t;
62e76326 2948
79d39a72 2949 while ((t = *head) != NULL) {
62e76326 2950 *head = t->next;
2951 safe_free(t->pattern);
2952 regfree(&t->compiled_pattern);
2953 safe_free(t);
f1dc9b30 2954 }
c2066637 2955
626096be 2956#if USE_HTTP_VIOLATIONS
c2066637 2957 refresh_nocache_hack = 0;
8970d351 2958
2959#endif
270b86af 2960}
12b9e9b1 2961
270b86af 2962static void
a7d59104 2963dump_string(StoreEntry * entry, const char *name, char *var)
270b86af 2964{
f53b06f9 2965 if (var != NULL)
62e76326 2966 storeAppendPrintf(entry, "%s %s\n", name, var);
270b86af 2967}
98ffb7e4 2968
270b86af 2969static void
0153d498 2970parse_string(char **var)
270b86af 2971{
2eceb328 2972 char *token = ConfigParser::NextToken();
270b86af 2973 safe_free(*var);
62e76326 2974
270b86af 2975 if (token == NULL)
62e76326 2976 self_destruct();
2977
270b86af 2978 *var = xstrdup(token);
2979}
b15e6857 2980
0153d498 2981static void
2982free_string(char **var)
2983{
027acbaf 2984 safe_free(*var);
0153d498 2985}
caebbe00 2986
94439e4e 2987void
f1dc9b30 2988parse_eol(char *volatile *var)
270b86af 2989{
65657c1a
AJ
2990 if (!var) {
2991 self_destruct();
2992 return;
2993 }
2994
2eceb328 2995 unsigned char *token = (unsigned char *) ConfigParser::NextQuotedOrToEol();
270b86af 2996 safe_free(*var);
62e76326 2997
9eeb8e4b 2998 if (!token) {
62e76326 2999 self_destruct();
9eeb8e4b 3000 return;
3001 }
62e76326 3002
e4755e29 3003 while (*token && xisspace(*token))
a38ec4b1 3004 ++token;
62e76326 3005
9eeb8e4b 3006 if (!*token) {
62e76326 3007 self_destruct();
9eeb8e4b 3008 return;
3009 }
62e76326 3010
852751f7 3011 *var = xstrdup((char *) token);
270b86af 3012}
090089c4 3013
52d3f198 3014#define dump_eol dump_string
3015#define free_eol free_string
3016
b11724bb
CT
3017static void
3018parse_TokenOrQuotedString(char **var)
3019{
3020 char *token = ConfigParser::NextQuotedToken();
3021 safe_free(*var);
3022
3023 if (token == NULL)
3024 self_destruct();
3025
3026 *var = xstrdup(token);
3027}
3028
3029#define dump_TokenOrQuotedString dump_string
3030#define free_TokenOrQuotedString free_string
3031
270b86af 3032static void
a7d59104 3033dump_time_t(StoreEntry * entry, const char *name, time_t var)
090089c4 3034{
f53b06f9 3035 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
090089c4 3036}
3037
94439e4e 3038void
a47b9029 3039parse_time_t(time_t * var)
0ffd22bc 3040{
fd0f51c4 3041 time_msec_t tval;
9b741834 3042 parseTimeLine(&tval, T_SECOND_STR, false);
fd0f51c4 3043 *var = static_cast<time_t>(tval/1000);
0ffd22bc 3044}
3045
270b86af 3046static void
a47b9029 3047free_time_t(time_t * var)
270b86af 3048{
a47b9029 3049 *var = 0;
270b86af 3050}
9906e724 3051
fd0f51c4
CT
3052static void
3053dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
3054{
3055 if (var % 1000)
c91ca3ce 3056 storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
fd0f51c4
CT
3057 else
3058 storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
3059}
3060
3061void
3062parse_time_msec(time_msec_t * var)
3063{
9b741834 3064 parseTimeLine(var, T_SECOND_STR, true);
fd0f51c4
CT
3065}
3066
3067static void
3068free_time_msec(time_msec_t * var)
3069{
3070 *var = 0;
3071}
3072
0477a072 3073#if UNUSED_CODE
9906e724 3074static void
a7d59104 3075dump_size_t(StoreEntry * entry, const char *name, size_t var)
1b635117 3076{
f53b06f9 3077 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
1b635117 3078}
0477a072 3079#endif
1b635117 3080
3081static void
a7d59104 3082dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
9906e724 3083{
f53b06f9 3084 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
9906e724 3085}
3086
e210930b
AJ
3087static void
3088dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var)
3089{
3090 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3091}
e210930b 3092
3e62bd58 3093#if UNUSED_CODE
9906e724 3094static void
a7d59104 3095dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
9906e724 3096{
f53b06f9 3097 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
9906e724 3098}
3e62bd58 3099#endif
9906e724 3100
47f6e231 3101static void
3102dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
3103{
c91ca3ce 3104 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
47f6e231 3105}
3106
3107static void
3108dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
3109{
c91ca3ce 3110 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
47f6e231 3111}
3112
0477a072 3113#if UNUSED_CODE
9906e724 3114static void
a47b9029 3115parse_size_t(size_t * var)
1b635117 3116{
1b635117 3117 int i;
0e4e0e7d 3118 i = GetInteger();
1b635117 3119 *var = (size_t) i;
3120}
0477a072 3121#endif
1b635117 3122
3123static void
3124parse_b_size_t(size_t * var)
9906e724 3125{
3126 parseBytesLine(var, B_BYTES_STR);
3127}
3128
e210930b
AJ
3129static void
3130parse_b_ssize_t(ssize_t * var)
3131{
3132 parseBytesLineSigned(var, B_BYTES_STR);
3133}
e210930b 3134
3e62bd58 3135#if UNUSED_CODE
9906e724 3136static void
a47b9029 3137parse_kb_size_t(size_t * var)
9906e724 3138{
3139 parseBytesLine(var, B_KBYTES_STR);
3140}
3e62bd58 3141#endif
9906e724 3142
47f6e231 3143static void
3144parse_b_int64_t(int64_t * var)
3145{
3146 parseBytesLine64(var, B_BYTES_STR);
3147}
3148
3149static void
3150parse_kb_int64_t(int64_t * var)
3151{
3152 parseBytesLine64(var, B_KBYTES_STR);
3153}
3154
9906e724 3155static void
a47b9029 3156free_size_t(size_t * var)
9906e724 3157{
a47b9029 3158 *var = 0;
9906e724 3159}
3160
e210930b
AJ
3161static void
3162free_ssize_t(ssize_t * var)
3163{
3164 *var = 0;
3165}
e210930b 3166
47f6e231 3167static void
3168free_b_int64_t(int64_t * var)
3169{
3170 *var = 0;
3171}
3172
1b635117 3173#define free_b_size_t free_size_t
e210930b 3174#define free_b_ssize_t free_ssize_t
9906e724 3175#define free_kb_size_t free_size_t
3176#define free_mb_size_t free_size_t
3177#define free_gb_size_t free_size_t
47f6e231 3178#define free_kb_int64_t free_b_int64_t
090089c4 3179
8203a132 3180static void
f45dd259 3181dump_u_short(StoreEntry * entry, const char *name, unsigned short var)
090089c4 3182{
f53b06f9 3183 storeAppendPrintf(entry, "%s %d\n", name, var);
270b86af 3184}
090089c4 3185
0153d498 3186static void
f45dd259 3187free_u_short(unsigned short * u)
0153d498 3188{
3189 *u = 0;
3190}
3191
270b86af 3192static void
f45dd259 3193parse_u_short(unsigned short * var)
b67e2c8c 3194{
3195 ConfigParser::ParseUShort(var);
3196}
3197
3198void
f45dd259 3199ConfigParser::ParseUShort(unsigned short *var)
270b86af 3200{
0e656b69 3201 *var = GetShort();
090089c4 3202}
3203
3a69ddf3 3204void
3205ConfigParser::ParseBool(bool *var)
3206{
3207 int i = GetInteger();
3208
3209 if (0 == i)
3210 *var = false;
3211 else if (1 == i)
3212 *var = true;
3213 else
3214 self_destruct();
3215}
3216
270b86af 3217static void
a7d59104 3218dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
270b86af 3219{
270b86af 3220 while (list != NULL) {
62e76326 3221 storeAppendPrintf(entry, "%s %s\n", name, list->key);
3222 list = list->next;
429fdbec 3223 }
429fdbec 3224}
3225
3a69ddf3 3226void
3227ConfigParser::ParseWordList(wordlist ** list)
3228{
3229 parse_wordlist(list);
3230}
3231
94439e4e 3232void
270b86af 3233parse_wordlist(wordlist ** list)
429fdbec 3234{
270b86af 3235 char *token;
bde7a8ce 3236 while ((token = ConfigParser::NextQuotedToken()))
62e76326 3237 wordlistAdd(list, token);
429fdbec 3238}
270b86af 3239
b3d8a9e8 3240#if 0 /* now unused */
f8d9f54a 3241static int
5da06f20 3242check_null_wordlist(wordlist * w)
f8d9f54a 3243{
3244 return w == NULL;
3245}
b3d8a9e8 3246#endif
f8d9f54a 3247
63e9d884 3248static int
c6d5b87b 3249check_null_acl_access(acl_access * a)
63e9d884 3250{
3251 return a == NULL;
3252}
3253
0153d498 3254#define free_wordlist wordlistDestroy
270b86af 3255
d548ee64 3256#define free_uri_whitespace free_int
3257
3258static void
3259parse_uri_whitespace(int *var)
3260{
2eceb328 3261 char *token = ConfigParser::NextToken();
62e76326 3262
d548ee64 3263 if (token == NULL)
62e76326 3264 self_destruct();
3265
a37d6070 3266 if (!strcmp(token, "strip"))
62e76326 3267 *var = URI_WHITESPACE_STRIP;
a37d6070 3268 else if (!strcmp(token, "deny"))
62e76326 3269 *var = URI_WHITESPACE_DENY;
a37d6070 3270 else if (!strcmp(token, "allow"))
62e76326 3271 *var = URI_WHITESPACE_ALLOW;
a37d6070 3272 else if (!strcmp(token, "encode"))
62e76326 3273 *var = URI_WHITESPACE_ENCODE;
a37d6070 3274 else if (!strcmp(token, "chop"))
62e76326 3275 *var = URI_WHITESPACE_CHOP;
54a063a2
TX
3276 else {
3277 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
62e76326 3278 self_destruct();
54a063a2 3279 }
d548ee64 3280}
3281
d548ee64 3282static void
3283dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
3284{
c193c972 3285 const char *s;
62e76326 3286
d548ee64 3287 if (var == URI_WHITESPACE_ALLOW)
62e76326 3288 s = "allow";
d548ee64 3289 else if (var == URI_WHITESPACE_ENCODE)
62e76326 3290 s = "encode";
d548ee64 3291 else if (var == URI_WHITESPACE_CHOP)
62e76326 3292 s = "chop";
7e3ce7b9 3293 else if (var == URI_WHITESPACE_DENY)
62e76326 3294 s = "deny";
7e3ce7b9 3295 else
62e76326 3296 s = "strip";
3297
d548ee64 3298 storeAppendPrintf(entry, "%s %s\n", name, s);
3299}
3300
6a566b9c 3301static void
c1dd71ae 3302free_removalpolicy(RemovalPolicySettings ** settings)
6a566b9c 3303{
3304 if (!*settings)
62e76326 3305 return;
3306
6a566b9c 3307 free_string(&(*settings)->type);
62e76326 3308
6a566b9c 3309 free_wordlist(&(*settings)->args);
62e76326 3310
c8f4eac4 3311 delete *settings;
62e76326 3312
6a566b9c 3313 *settings = NULL;
3314}
3315
3316static void
c1dd71ae 3317parse_removalpolicy(RemovalPolicySettings ** settings)
6a566b9c 3318{
3319 if (*settings)
62e76326 3320 free_removalpolicy(settings);
3321
c8f4eac4 3322 *settings = new RemovalPolicySettings;
62e76326 3323
6a566b9c 3324 parse_string(&(*settings)->type);
62e76326 3325
6a566b9c 3326 parse_wordlist(&(*settings)->args);
3327}
3328
3329static void
c1dd71ae 3330dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
6a566b9c 3331{
3332 wordlist *args;
3333 storeAppendPrintf(entry, "%s %s", name, settings->type);
3334 args = settings->args;
62e76326 3335
6a566b9c 3336 while (args) {
62e76326 3337 storeAppendPrintf(entry, " %s", args->key);
3338 args = args->next;
6a566b9c 3339 }
62e76326 3340
be58afb5 3341 storeAppendPrintf(entry, "\n");
6a566b9c 3342}
c1dd71ae 3343
de0cb3d8
AR
3344inline void
3345free_YesNoNone(YesNoNone *)
57af1e3f 3346{
de0cb3d8 3347 // do nothing: no explicit cleanup is required
57af1e3f
AR
3348}
3349
3350static void
3351parse_YesNoNone(YesNoNone *option)
3352{
3353 int value = 0;
3354 parse_onoff(&value);
3355 option->configure(value > 0);
3356}
3357
3358static void
3359dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
3360{
3361 if (option.configured())
3362 dump_onoff(entry, name, option ? 1 : 0);
3363}
3364
ea21d497
HN
3365static void
3366free_memcachemode(SquidConfig * config)
3367{
3368 return;
3369}
3370
3371static void
3372parse_memcachemode(SquidConfig * config)
3373{
2eceb328 3374 char *token = ConfigParser::NextToken();
ea21d497 3375 if (!token)
e1381638 3376 self_destruct();
ea21d497 3377
10aeba1d 3378 if (strcmp(token, "always") == 0) {
e1381638
AJ
3379 Config.onoff.memory_cache_first = 1;
3380 Config.onoff.memory_cache_disk = 1;
10aeba1d 3381 } else if (strcmp(token, "disk") == 0) {
e1381638
AJ
3382 Config.onoff.memory_cache_first = 0;
3383 Config.onoff.memory_cache_disk = 1;
ea21d497 3384 } else if (strncmp(token, "net", 3) == 0) {
e1381638
AJ
3385 Config.onoff.memory_cache_first = 1;
3386 Config.onoff.memory_cache_disk = 0;
10aeba1d 3387 } else if (strcmp(token, "never") == 0) {
e1381638
AJ
3388 Config.onoff.memory_cache_first = 0;
3389 Config.onoff.memory_cache_disk = 0;
54a063a2
TX
3390 } else {
3391 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
e1381638 3392 self_destruct();
54a063a2 3393 }
ea21d497
HN
3394}
3395
3396static void
3397dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config)
3398{
3399 storeAppendPrintf(entry, "%s ", name);
3400 if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
e1381638 3401 storeAppendPrintf(entry, "always");
ea21d497 3402 else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
e1381638 3403 storeAppendPrintf(entry, "disk");
ea21d497 3404 else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
e1381638 3405 storeAppendPrintf(entry, "network");
ea21d497 3406 else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
e1381638 3407 storeAppendPrintf(entry, "none");
ea21d497
HN
3408 storeAppendPrintf(entry, "\n");
3409}
3410
cca8ba0d 3411#include "cf_parser.cci"
f1dc9b30 3412
3413peer_t
3414parseNeighborType(const char *s)
3415{
a37d6070 3416 if (!strcmp(s, "parent"))
62e76326 3417 return PEER_PARENT;
3418
a37d6070 3419 if (!strcmp(s, "neighbor"))
62e76326 3420 return PEER_SIBLING;
3421
a37d6070 3422 if (!strcmp(s, "neighbour"))
62e76326 3423 return PEER_SIBLING;
3424
a37d6070 3425 if (!strcmp(s, "sibling"))
62e76326 3426 return PEER_SIBLING;
3427
a37d6070 3428 if (!strcmp(s, "multicast"))
62e76326 3429 return PEER_MULTICAST;
3430
fa84c01d 3431 debugs(15, DBG_CRITICAL, "WARNING: Unknown neighbor type: " << s);
62e76326 3432
f1dc9b30 3433 return PEER_SIBLING;
3434}
f150dd4b 3435
0b0cfcf2 3436#if USE_WCCPv2
52f772de 3437static void
b7ac5457 3438parse_IpAddress_list(Ip::Address_list ** head)
52f772de 3439{
3440 char *token;
b7ac5457
AJ
3441 Ip::Address_list *s;
3442 Ip::Address ipa;
62e76326 3443
2eceb328 3444 while ((token = ConfigParser::NextToken())) {
82b7abe3
AJ
3445 if (GetHostWithPort(token, &ipa)) {
3446
3447 while (*head)
3448 head = &(*head)->next;
3449
b7ac5457 3450 s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s)));
82b7abe3
AJ
3451 s->s = ipa;
3452
3453 *head = s;
9d65168e 3454 } else
82b7abe3 3455 self_destruct();
7e3ce7b9 3456 }
3457}
3458
3459static void
b7ac5457 3460dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s)
7e3ce7b9 3461{
cc192b50 3462 char ntoabuf[MAX_IPSTRLEN];
3463
7e3ce7b9 3464 while (s) {
cc192b50 3465 storeAppendPrintf(e, "%s %s\n",
62e76326 3466 n,
4dd643d5 3467 s->s.toStr(ntoabuf,MAX_IPSTRLEN));
62e76326 3468 s = s->next;
7e3ce7b9 3469 }
3470}
3471
3472static void
b7ac5457 3473free_IpAddress_list(Ip::Address_list ** head)
7e3ce7b9 3474{
26ac0430
AJ
3475 if (*head) delete *head;
3476 *head = NULL;
7e3ce7b9 3477}
3478
0b0cfcf2 3479#if CURRENTLY_UNUSED
3480/* This code was previously used by http_port. Left as it really should
3481 * be used by icp_port and htcp_port
3482 */
7e3ce7b9 3483static int
b7ac5457 3484check_null_IpAddress_list(const Ip::Address_list * s)
7e3ce7b9 3485{
3486 return NULL == s;
3487}
62e76326 3488
3f38a55e 3489#endif /* CURRENTLY_UNUSED */
0b0cfcf2 3490#endif /* USE_WCCPv2 */
7e3ce7b9 3491
d193a436 3492static void
fa720bfb 3493parsePortSpecification(const AnyP::PortCfgPointer &s, char *token)
d193a436 3494{
3f38a55e 3495 char *host = NULL;
3f38a55e 3496 unsigned short port = 0;
cc192b50 3497 char *t = NULL;
3498 char *junk = NULL;
62e76326 3499
5529ca8a 3500 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
13adaf1f 3501 s->name = xstrdup(token);
d67acb4e 3502 s->connection_auth_disabled = false;
5529ca8a 3503
1ca54a54 3504 const char *portType = AnyP::UriScheme(s->transport.protocol).c_str();
eb6ac808 3505
cc192b50 3506 if (*token == '[') {
3507 /* [ipv6]:port */
26ac0430
AJ
3508 host = token + 1;
3509 t = strchr(host, ']');
3510 if (!t) {
eb6ac808 3511 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing ']' on IPv6 address: " << token);
26ac0430 3512 self_destruct();
cc192b50 3513 }
a38ec4b1
FC
3514 *t = '\0';
3515 ++t;
26ac0430 3516 if (*t != ':') {
eb6ac808 3517 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port in: " << token);
26ac0430 3518 self_destruct();
cc192b50 3519 }
055421ee 3520 if (!Ip::EnableIpv6) {
eb6ac808 3521 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: IPv6 is not available.");
26ac0430
AJ
3522 self_destruct();
3523 }
055421ee
AJ
3524 port = xatos(t + 1);
3525 } else if ((t = strchr(token, ':'))) {
3526 /* host:port */
3527 /* ipv4:port */
3528 host = token;
3529 *t = '\0';
3530 port = xatos(t + 1);
3531
54a063a2
TX
3532 } else if (strtol(token, &junk, 10) && !*junk) {
3533 port = xatos(token);
eb6ac808 3534 debugs(3, 3, portType << "_port: found Listen on Port: " << port);
055421ee 3535 } else {
eb6ac808 3536 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port: " << token);
055421ee
AJ
3537 self_destruct();
3538 }
62e76326 3539
859741ed 3540 if (port == 0 && host != NULL) {
eb6ac808 3541 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: Port cannot be 0: " << token);
0e656b69 3542 self_destruct();
cc192b50 3543 }
0e656b69 3544
cc192b50 3545 if (NULL == host) {
4dd643d5
AJ
3546 s->s.setAnyAddr();
3547 s->s.port(port);
6df7ad56 3548 if (!Ip::EnableIpv6)
4dd643d5 3549 s->s.setIPv4();
eb6ac808 3550 debugs(3, 3, portType << "_port: found Listen on wildcard address: *:" << s->s.port());
c49d44e1 3551 } else if ( (s->s = host) ) { /* check/parse numeric IPA */
4dd643d5 3552 s->s.port(port);
6df7ad56 3553 if (!Ip::EnableIpv6)
4dd643d5 3554 s->s.setIPv4();
eb6ac808 3555 debugs(3, 3, portType << "_port: Listen on Host/IP: " << host << " --> " << s->s);
26ac0430 3556 } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
62e76326 3557 /* dont use ipcache */
62e76326 3558 s->defaultsite = xstrdup(host);
4dd643d5 3559 s->s.port(port);
6df7ad56 3560 if (!Ip::EnableIpv6)
4dd643d5 3561 s->s.setIPv4();
eb6ac808 3562 debugs(3, 3, portType << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
26ac0430 3563 } else {
eb6ac808 3564 debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: failed to resolve Host/IP: " << host);
62e76326 3565 self_destruct();
cc192b50 3566 }
3f38a55e 3567}
3568
3569static void
fa720bfb 3570parse_port_option(AnyP::PortCfgPointer &s, char *token)
3f38a55e 3571{
c7b1dd5d
AJ
3572 /* modes first */
3573
3574 if (strcmp(token, "accel") == 0) {
151ba0d4 3575 if (s->flags.isIntercepted()) {
c7b1dd5d
AJ
3576 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3577 self_destruct();
3578 }
6a25a046 3579 s->flags.accelSurrogate = true;
86ab7a90 3580 s->vhost = true;
c7b1dd5d 3581 } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
151ba0d4 3582 if (s->flags.accelSurrogate || s->flags.tproxyIntercept) {
c7b1dd5d
AJ
3583 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3584 self_destruct();
3585 }
6a25a046 3586 s->flags.natIntercept = true;
c7b1dd5d
AJ
3587 Ip::Interceptor.StartInterception();
3588 /* Log information regarding the port modes under interception. */
3589 debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
3590 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
c7b1dd5d 3591 } else if (strcmp(token, "tproxy") == 0) {
151ba0d4 3592 if (s->flags.natIntercept || s->flags.accelSurrogate) {
c7b1dd5d
AJ
3593 debugs(3,DBG_CRITICAL, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3594 self_destruct();
3595 }
6a25a046 3596 s->flags.tproxyIntercept = true;
c7b1dd5d
AJ
3597 Ip::Interceptor.StartTransparency();
3598 /* Log information regarding the port modes under transparency. */
0d901ef4 3599 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (TPROXY enabled)");
c7b1dd5d 3600
151ba0d4
AJ
3601 if (s->flags.proxySurrogate) {
3602 debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (proxy-surrogate enabled)");
3603 }
3604
c7b1dd5d
AJ
3605 if (!Ip::Interceptor.ProbeForTproxy(s->s)) {
3606 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3607 self_destruct();
3608 }
3609
00d0ce87 3610 } else if (strcmp(token, "proxy-surrogate") == 0) {
00d0ce87 3611 s->flags.proxySurrogate = true;
151ba0d4 3612 debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (proxy-surrogate enabled)");
00d0ce87 3613
c7b1dd5d 3614 } else if (strncmp(token, "defaultsite=", 12) == 0) {
6a25a046 3615 if (!s->flags.accelSurrogate) {
c7b1dd5d
AJ
3616 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3617 self_destruct();
3618 }
62e76326 3619 safe_free(s->defaultsite);
3620 s->defaultsite = xstrdup(token + 12);
3f38a55e 3621 } else if (strcmp(token, "vhost") == 0) {
6a25a046 3622 if (!s->flags.accelSurrogate) {
cf673853
AJ
3623 debugs(3, DBG_CRITICAL, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3624 }
6a25a046 3625 s->flags.accelSurrogate = true;
86ab7a90 3626 s->vhost = true;
cf673853 3627 } else if (strcmp(token, "no-vhost") == 0) {
6a25a046 3628 if (!s->flags.accelSurrogate) {
cf673853 3629 debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
c7b1dd5d 3630 }
86ab7a90 3631 s->vhost = false;
3f38a55e 3632 } else if (strcmp(token, "vport") == 0) {
6a25a046 3633 if (!s->flags.accelSurrogate) {
c7b1dd5d
AJ
3634 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3635 self_destruct();
3636 }
62e76326 3637 s->vport = -1;
3f38a55e 3638 } else if (strncmp(token, "vport=", 6) == 0) {
6a25a046 3639 if (!s->flags.accelSurrogate) {
c7b1dd5d
AJ
3640 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3641 self_destruct();
3642 }
0e656b69 3643 s->vport = xatos(token + 6);
3f38a55e 3644 } else if (strncmp(token, "protocol=", 9) == 0) {
6a25a046 3645 if (!s->flags.accelSurrogate) {
c7b1dd5d
AJ
3646 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3647 self_destruct();
3648 }
eb6ac808 3649 s->setTransport(token + 9);
7f7bdd96 3650 } else if (strcmp(token, "allow-direct") == 0) {
6a25a046 3651 if (!s->flags.accelSurrogate) {
90fa5816 3652 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
c7b1dd5d
AJ
3653 self_destruct();
3654 }
86ab7a90 3655 s->allow_direct = true;
90fa5816 3656 } else if (strcmp(token, "act-as-origin") == 0) {
6a25a046 3657 if (!s->flags.accelSurrogate) {
90fa5816
AJ
3658 debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3659 } else
86ab7a90 3660 s->actAsOrigin = true;
432bc83c 3661 } else if (strcmp(token, "ignore-cc") == 0) {
626096be 3662#if !USE_HTTP_VIOLATIONS
6a25a046 3663 if (!s->flags.accelSurrogate) {
c3d24490 3664 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: ignore-cc option requires Acceleration mode flag.");
838daf3f
A
3665 self_destruct();
3666 }
432bc83c 3667#endif
86ab7a90 3668 s->ignore_cc = true;
c7b1dd5d
AJ
3669 } else if (strncmp(token, "name=", 5) == 0) {
3670 safe_free(s->name);
3671 s->name = xstrdup(token + 5);
d67acb4e
AJ
3672 } else if (strcmp(token, "no-connection-auth") == 0) {
3673 s->connection_auth_disabled = true;
3674 } else if (strcmp(token, "connection-auth=off") == 0) {
26ac0430 3675 s->connection_auth_disabled = true;
d67acb4e 3676 } else if (strcmp(token, "connection-auth") == 0) {
26ac0430 3677 s->connection_auth_disabled = false;
d67acb4e 3678 } else if (strcmp(token, "connection-auth=on") == 0) {
26ac0430 3679 s->connection_auth_disabled = false;
5529ca8a 3680 } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
a37d6070 3681 if (!strcmp(token + 23, "off"))
5529ca8a 3682 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
a37d6070 3683 else if (!strcmp(token + 23, "transparent"))
5529ca8a 3684 s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
a37d6070 3685 else if (!strcmp(token + 23, "always"))
5529ca8a 3686 s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
3687 else
3688 self_destruct();
cc192b50 3689 } else if (strcmp(token, "ipv4") == 0) {
4dd643d5 3690 if ( !s->s.setIPv4() ) {
055421ee 3691 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s );
cc192b50 3692 self_destruct();
3693 }
26ac0430 3694 } else if (strcmp(token, "tcpkeepalive") == 0) {
86ab7a90 3695 s->tcp_keepalive.enabled = true;
b2130d58 3696 } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
26ac0430 3697 char *t = token + 13;
86ab7a90 3698 s->tcp_keepalive.enabled = true;
e398d16e 3699 s->tcp_keepalive.idle = xatoui(t,',');
26ac0430
AJ
3700 t = strchr(t, ',');
3701 if (t) {
a38ec4b1 3702 ++t;
e398d16e 3703 s->tcp_keepalive.interval = xatoui(t,',');
26ac0430
AJ
3704 t = strchr(t, ',');
3705 }
3706 if (t) {
a38ec4b1 3707 ++t;
54a063a2 3708 s->tcp_keepalive.timeout = xatoui(t);
26ac0430 3709 }
cb4f4424 3710#if USE_OPENSSL
a37d6070 3711 } else if (strcmp(token, "sslBump") == 0) {
3a0c8eb5 3712 debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " <<
9945bf3f 3713 "in http_port. Use 'ssl-bump' instead.");
c3d24490 3714 s->flags.tunnelSslBumping = true;
3a0c8eb5 3715 } else if (strcmp(token, "ssl-bump") == 0) {
c3d24490 3716 s->flags.tunnelSslBumping = true;
154dc884 3717 } else if (strncmp(token, "cert=", 5) == 0) {
3718 safe_free(s->cert);
3719 s->cert = xstrdup(token + 5);
3720 } else if (strncmp(token, "key=", 4) == 0) {
3721 safe_free(s->key);
3722 s->key = xstrdup(token + 4);
3723 } else if (strncmp(token, "version=", 8) == 0) {
3724 s->version = xatoi(token + 8);
154dc884 3725 if (s->version < 1 || s->version > 4)
3726 self_destruct();
3727 } else if (strncmp(token, "options=", 8) == 0) {
3728 safe_free(s->options);
3729 s->options = xstrdup(token + 8);
3730 } else if (strncmp(token, "cipher=", 7) == 0) {
3731 safe_free(s->cipher);
3732 s->cipher = xstrdup(token + 7);
3733 } else if (strncmp(token, "clientca=", 9) == 0) {
3734 safe_free(s->clientca);
3735 s->clientca = xstrdup(token + 9);
3736 } else if (strncmp(token, "cafile=", 7) == 0) {
3737 safe_free(s->cafile);
3738 s->cafile = xstrdup(token + 7);
3739 } else if (strncmp(token, "capath=", 7) == 0) {
3740 safe_free(s->capath);
3741 s->capath = xstrdup(token + 7);
3742 } else if (strncmp(token, "crlfile=", 8) == 0) {
3743 safe_free(s->crlfile);
3744 s->crlfile = xstrdup(token + 8);
3745 } else if (strncmp(token, "dhparams=", 9) == 0) {
3746 safe_free(s->dhfile);
3747 s->dhfile = xstrdup(token + 9);
3748 } else if (strncmp(token, "sslflags=", 9) == 0) {
3749 safe_free(s->sslflags);
3750 s->sslflags = xstrdup(token + 9);
3751 } else if (strncmp(token, "sslcontext=", 11) == 0) {
95d2589c
CT
3752 safe_free(s->sslContextSessionId);
3753 s->sslContextSessionId = xstrdup(token + 11);
3754 } else if (strcmp(token, "generate-host-certificates") == 0) {
3755 s->generateHostCertificates = true;
3756 } else if (strcmp(token, "generate-host-certificates=on") == 0) {
3757 s->generateHostCertificates = true;
3758 } else if (strcmp(token, "generate-host-certificates=off") == 0) {
3759 s->generateHostCertificates = false;
3760 } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) {
3761 parseBytesOptionValue(&s->dynamicCertMemCacheSize, B_BYTES_STR, token + 28);
154dc884 3762#endif
3f38a55e 3763 } else {
54a063a2 3764 debugs(3, DBG_CRITICAL, "FATAL: Unknown http(s)_port option '" << token << "'.");
62e76326 3765 self_destruct();
3f38a55e 3766 }
3767}
3768
3f38a55e 3769void
3770add_http_port(char *portspec)
3771{
fa720bfb 3772 AnyP::PortCfgPointer s = new AnyP::PortCfg();
eb6ac808 3773 s->setTransport("HTTP");
859741ed 3774 parsePortSpecification(s, portspec);
65d448bc 3775 // we may need to merge better if the above returns a list with clones
7e07ced1 3776 assert(s->next == NULL);
fa720bfb
AJ
3777 s->next = HttpPortList;
3778 HttpPortList = s;
3f38a55e 3779}
3780
3781static void
fa720bfb 3782parsePortCfg(AnyP::PortCfgPointer *head, const char *optionName)
d3388e1f
AR
3783{
3784 const char *protocol = NULL;
3785 if (strcmp(optionName, "http_port") == 0 ||
b5944cff 3786 strcmp(optionName, "ascii_port") == 0)
d3388e1f
AR
3787 protocol = "http";
3788 else if (strcmp(optionName, "https_port") == 0)
3789 protocol = "https";
3790 if (!protocol) {
3791 self_destruct();
3792 return;
3793 }
3794
2eceb328 3795 char *token = ConfigParser::NextToken();
62e76326 3796
9eeb8e4b 3797 if (!token) {
62e76326 3798 self_destruct();
9eeb8e4b 3799 return;
3800 }
62e76326 3801
fa720bfb 3802 AnyP::PortCfgPointer s = new AnyP::PortCfg();
eb6ac808 3803 s->setTransport(protocol);
859741ed 3804 parsePortSpecification(s, token);
62e76326 3805
3f38a55e 3806 /* parse options ... */
2eceb328 3807 while ((token = ConfigParser::NextToken())) {
65d448bc 3808 parse_port_option(s, token);
3f38a55e 3809 }
62e76326 3810
6507233b 3811 if (s->transport.protocol == AnyP::PROTO_HTTPS) {
151ba0d4 3812#if USE_OPENSSL
38450a50 3813 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
c3d24490 3814 const bool hijacked = s->flags.isIntercepted();
6a25a046 3815 if (s->flags.tunnelSslBumping && !hijacked) {
38450a50 3816 debugs(3, DBG_CRITICAL, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
03f00a11
CT
3817 self_destruct();
3818 }
6a25a046 3819 if (hijacked && !s->flags.tunnelSslBumping) {
38450a50 3820 debugs(3, DBG_CRITICAL, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
03f00a11
CT
3821 self_destruct();
3822 }
03f00a11 3823#endif
151ba0d4 3824 if (s->transport.protocol == AnyP::PROTO_HTTPS) {
70a16fea 3825 debugs(3,DBG_CRITICAL, "FATAL: https_port: proxy-surrogate option is not supported on HTTPS ports.");
151ba0d4
AJ
3826 self_destruct();
3827 }
3828 }
03f00a11 3829
4dd643d5 3830 if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.isAnyAddr()) {
7e07ced1 3831 // clone the port options from *s to *(s->next)
fa720bfb 3832 s->next = s->clone();
4dd643d5 3833 s->next->s.setIPv4();
1ca54a54 3834 debugs(3, 3, AnyP::UriScheme(s->transport.protocol).c_str() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
7e07ced1 3835 }
7e07ced1 3836
fa720bfb
AJ
3837 while (*head != NULL)
3838 head = &((*head)->next);
62e76326 3839
fa720bfb 3840 *head = s;
3f38a55e 3841}
3842
3843static void
fa720bfb 3844dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s)
3f38a55e 3845{
cc192b50 3846 char buf[MAX_IPSTRLEN];
3847
3848 storeAppendPrintf(e, "%s %s",
62e76326 3849 n,
4dd643d5 3850 s->s.toUrl(buf,MAX_IPSTRLEN));
62e76326 3851
df1b20e4 3852 // MODES and specific sub-options.
6a25a046 3853 if (s->flags.natIntercept)
2ad20b4f 3854 storeAppendPrintf(e, " intercept");
62e76326 3855
6a25a046 3856 else if (s->flags.tproxyIntercept)
c7b1dd5d
AJ
3857 storeAppendPrintf(e, " tproxy");
3858
00d0ce87
AJ
3859 else if (s->flags.proxySurrogate)
3860 storeAppendPrintf(e, " proxy-surrogate");
3861
6a25a046 3862 else if (s->flags.accelSurrogate) {
c7b1dd5d
AJ
3863 storeAppendPrintf(e, " accel");
3864
df1b20e4
AJ
3865 if (s->vhost)
3866 storeAppendPrintf(e, " vhost");
62e76326 3867
df1b20e4
AJ
3868 if (s->vport < 0)
3869 storeAppendPrintf(e, " vport");
3870 else if (s->vport > 0)
3871 storeAppendPrintf(e, " vport=%d", s->vport);
5529ca8a 3872
df1b20e4
AJ
3873 if (s->defaultsite)
3874 storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3875
eb6ac808
AJ
3876 // TODO: compare against prefix of 'n' instead of assuming http_port
3877 if (s->transport.protocol != AnyP::PROTO_HTTP)
1ca54a54 3878 storeAppendPrintf(e, " protocol=%s", AnyP::UriScheme(s->transport.protocol).c_str());
df1b20e4
AJ
3879
3880 if (s->allow_direct)
3881 storeAppendPrintf(e, " allow-direct");
3882
3883 if (s->ignore_cc)
3884 storeAppendPrintf(e, " ignore-cc");
3885
3886 }
3887
3888 // Generic independent options
3889
3890 if (s->name)
3891 storeAppendPrintf(e, " name=%s", s->name);
3892
33e701f3 3893#if USE_HTTP_VIOLATIONS
6a25a046 3894 if (!s->flags.accelSurrogate && s->ignore_cc)
df1b20e4
AJ
3895 storeAppendPrintf(e, " ignore-cc");
3896#endif
c7b1dd5d 3897
d67acb4e
AJ
3898 if (s->connection_auth_disabled)
3899 storeAppendPrintf(e, " connection-auth=off");
3900 else
3901 storeAppendPrintf(e, " connection-auth=on");
3902
5529ca8a 3903 if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3904 const char *pmtu;
3905
3906 if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3907 pmtu = "always";
3908 else
3909 pmtu = "transparent";
3910
3911 storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3912 }
b2130d58 3913
4dd643d5 3914 if (s->s.isAnyAddr() && !s->s.isIPv6())
df1b20e4
AJ
3915 storeAppendPrintf(e, " ipv4");
3916
b2130d58 3917 if (s->tcp_keepalive.enabled) {
26ac0430 3918 if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
68924b6d 3919 storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
26ac0430 3920 } else {
68924b6d 3921 storeAppendPrintf(e, " tcpkeepalive");
26ac0430 3922 }
b2130d58 3923 }
154dc884 3924
cb4f4424 3925#if USE_OPENSSL
6a25a046 3926 if (s->flags.tunnelSslBumping)
df1b20e4 3927 storeAppendPrintf(e, " ssl-bump");
c7b1dd5d 3928
26ac0430
AJ
3929 if (s->cert)
3930 storeAppendPrintf(e, " cert=%s", s->cert);
154dc884 3931
26ac0430
AJ
3932 if (s->key)
3933 storeAppendPrintf(e, " key=%s", s->key);
154dc884 3934
26ac0430
AJ
3935 if (s->version)
3936 storeAppendPrintf(e, " version=%d", s->version);
154dc884 3937
26ac0430
AJ
3938 if (s->options)
3939 storeAppendPrintf(e, " options=%s", s->options);
154dc884 3940
26ac0430
AJ
3941 if (s->cipher)
3942 storeAppendPrintf(e, " cipher=%s", s->cipher);
154dc884 3943
26ac0430
AJ
3944 if (s->cafile)
3945 storeAppendPrintf(e, " cafile=%s", s->cafile);
154dc884 3946
26ac0430
AJ
3947 if (s->capath)
3948 storeAppendPrintf(e, " capath=%s", s->capath);
154dc884 3949
26ac0430
AJ
3950 if (s->crlfile)
3951 storeAppendPrintf(e, " crlfile=%s", s->crlfile);
154dc884 3952
26ac0430
AJ
3953 if (s->dhfile)
3954 storeAppendPrintf(e, " dhparams=%s", s->dhfile);
154dc884 3955
26ac0430
AJ
3956 if (s->sslflags)
3957 storeAppendPrintf(e, " sslflags=%s", s->sslflags);
154dc884 3958
95d2589c
CT
3959 if (s->sslContextSessionId)
3960 storeAppendPrintf(e, " sslcontext=%s", s->sslContextSessionId);
3961
3962 if (s->generateHostCertificates)
3963 storeAppendPrintf(e, " generate-host-certificates");
3964
3965 if (s->dynamicCertMemCacheSize != std::numeric_limits<size_t>::max())
3966 storeAppendPrintf(e, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s->dynamicCertMemCacheSize, B_BYTES_STR);
154dc884 3967#endif
3f38a55e 3968}
62e76326 3969
3f38a55e 3970static void
fa720bfb 3971dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s)
3f38a55e 3972{
fa720bfb
AJ
3973 for (AnyP::PortCfgPointer p = s; p != NULL; p = p->next) {
3974 dump_generic_port(e, n, p);
62e76326 3975 storeAppendPrintf(e, "\n");
3f38a55e 3976 }
3977}
3978
f150dd4b 3979void
3980configFreeMemory(void)
3981{
23ff6968 3982 free_all();
cb4f4424 3983#if USE_OPENSSL
29bf4910
CT
3984 SSL_CTX_free(Config.ssl_client.sslContext);
3985#endif
f150dd4b 3986}
f0b19334 3987
94439e4e 3988void
f0b19334 3989requirePathnameExists(const char *name, const char *path)
3990{
62e76326 3991
f0b19334 3992 struct stat sb;
08577e16 3993 char pathbuf[BUFSIZ];
f0b19334 3994 assert(path != NULL);
62e76326 3995
0b796acd 3996 if (Config.chroot_dir && (geteuid() == 0)) {
62e76326 3997 snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3998 path = pathbuf;
08577e16 3999 }
62e76326 4000
a572d8be 4001 if (stat(path, &sb) < 0) {
a32a190b
AJ
4002 debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL ":"") << "ERROR: " << name << " " << path << ": " << xstrerror());
4003 // keep going to find more issues if we are only checking the config file with "-k parse"
4004 if (opt_parse_cfg_only)
4005 return;
4006 // this is fatal if it is found during startup or reconfigure
a572d8be 4007 if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
4008 fatalf("%s %s: %s", name, path, xstrerror());
a572d8be 4009 }
f0b19334 4010}
d860a1aa 4011
4012char *
4013strtokFile(void)
4014{
d295d770 4015 return ConfigParser::strtokFile();
d860a1aa 4016}
7684c4b1 4017
450e0c10 4018#include "AccessLogEntry.h"
7684c4b1 4019
fb0c2f17
NH
4020/**
4021 * We support several access_log configuration styles:
4022 *
4023 * #1: Deprecated ancient style without an explicit logging module:
4024 * access_log /var/log/access.log
4025 *
4026 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
4027 * access_log none [acl ...]
4028 *
4029 * #3: Configurable logging module without named options:
4030 * Logformat or the first ACL name, whichever comes first, may not contain '='.
4031 * If no explicit logformat name is given, the first ACL name, if any,
4032 * should not be an existing logformat name or it will be treated as such.
4033 * access_log module:place [logformat_name] [acl ...]
4034 *
4035 * #4: Configurable logging module with name=value options such as logformat=x:
4036 * The first ACL name may not contain '='.
4037 * access_log module:place [option ...] [acl ...]
4038 *
4039 */
7684c4b1 4040static void
87ddff6e 4041parse_access_log(CustomLog ** logs)
7684c4b1 4042{
87ddff6e 4043 CustomLog *cl = (CustomLog *)xcalloc(1, sizeof(*cl));
7684c4b1 4044
fb0c2f17
NH
4045 // default buffer size and fatal settings
4046 cl->bufferSize = 8*MAX_URL;
4047 cl->fatal = true;
4048
4049 /* determine configuration style */
4050
2eceb328 4051 const char *filename = ConfigParser::NextToken();
fb0c2f17 4052 if (!filename) {
7684c4b1 4053 self_destruct();
9eeb8e4b 4054 return;
4055 }
7684c4b1 4056
4057 if (strcmp(filename, "none") == 0) {
20efa1c2 4058 cl->type = Log::Format::CLF_NONE;
6f58d7d7 4059 aclParseAclList(LegacyParser, &cl->aclList, filename);
6375a714
AJ
4060 while (*logs)
4061 logs = &(*logs)->next;
4062 *logs = cl;
4063 return;
7684c4b1 4064 }
4065
fb0c2f17
NH
4066 cl->filename = xstrdup(filename);
4067 cl->type = Log::Format::CLF_UNKNOWN;
4068
bde7a8ce 4069 const char *token = ConfigParser::PeekAtToken();
fb0c2f17
NH
4070 if (!token) { // style #1
4071 // no options to deal with
4072 } else if (!strchr(token, '=')) { // style #3
bde7a8ce
CT
4073 // if logformat name is recognized,
4074 // pop the previewed token; Else it must be an ACL name
4075 if (setLogformat(cl, token, false))
4076 (void)ConfigParser::NextToken();
fb0c2f17
NH
4077 } else { // style #4
4078 do {
4079 if (strncasecmp(token, "on-error=", 9) == 0) {
4080 if (strncasecmp(token+9, "die", 3) == 0) {
4081 cl->fatal = true;
4082 } else if (strncasecmp(token+9, "drop", 4) == 0) {
4083 cl->fatal = false;
4084 } else {
4085 debugs(3, DBG_CRITICAL, "Unknown value for on-error '" <<
4086 token << "' expected 'drop' or 'die'");
4087 self_destruct();
4088 }
4089 } else if (strncasecmp(token, "buffer-size=", 12) == 0) {
4090 parseBytesOptionValue(&cl->bufferSize, B_BYTES_STR, token+12);
4091 } else if (strncasecmp(token, "logformat=", 10) == 0) {
4092 setLogformat(cl, token+10, true);
4093 } else if (!strchr(token, '=')) {
bde7a8ce 4094 // Do not pop the token; it must be an ACL name
fb0c2f17
NH
4095 break; // done with name=value options, now to ACLs
4096 } else {
4097 debugs(3, DBG_CRITICAL, "Unknown access_log option " << token);
4098 self_destruct();
4099 }
bde7a8ce
CT
4100 // Pop the token, it was a valid "name=value" option
4101 (void)ConfigParser::NextToken();
4102 // Get next with preview ConfigParser::NextToken call.
4103 } while ((token = ConfigParser::PeekAtToken()) != NULL);
fb0c2f17 4104 }
7684c4b1 4105
fb0c2f17
NH
4106 // set format if it has not been specified explicitly
4107 if (cl->type == Log::Format::CLF_UNKNOWN)
4108 setLogformat(cl, "squid", true);
7684c4b1 4109
0a003ce5 4110 aclParseAclList(LegacyParser, &cl->aclList, cl->filename);
fb0c2f17
NH
4111
4112 while (*logs)
4113 logs = &(*logs)->next;
4114
4115 *logs = cl;
4116}
4117
4118/// sets CustomLog::type and, if needed, CustomLog::lf
4119/// returns false iff there is no named log format
4120static bool
4121setLogformat(CustomLog *cl, const char *logdef_name, const bool dieWhenMissing)
4122{
4123 assert(cl);
4124 assert(logdef_name);
4125
4126 debugs(3, 9, "possible " << cl->filename << " logformat: " << logdef_name);
4127
4128 if (cl->type != Log::Format::CLF_UNKNOWN) {
4129 debugs(3, DBG_CRITICAL, "Second logformat name in one access_log: " <<
4130 logdef_name << " " << cl->type << " ? " << Log::Format::CLF_NONE);
4131 self_destruct();
4132 return false;
4133 }
7684c4b1 4134
4135 /* look for the definition pointer corresponding to this name */
38e16f92 4136 Format::Format *lf = Log::TheConfig.logformats;
7684c4b1 4137
4138 while (lf != NULL) {
bf8fe701 4139 debugs(3, 9, "Comparing against '" << lf->name << "'");
7684c4b1 4140
4141 if (strcmp(lf->name, logdef_name) == 0)
4142 break;
4143
4144 lf = lf->next;
4145 }
4146
4147 if (lf != NULL) {
20efa1c2 4148 cl->type = Log::Format::CLF_CUSTOM;
7684c4b1 4149 cl->logFormat = lf;
4150 } else if (strcmp(logdef_name, "auto") == 0) {
fa84c01d 4151 debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
20efa1c2 4152 cl->type = Log::Format::CLF_SQUID;
7684c4b1 4153 } else if (strcmp(logdef_name, "squid") == 0) {
20efa1c2 4154 cl->type = Log::Format::CLF_SQUID;
7684c4b1 4155 } else if (strcmp(logdef_name, "common") == 0) {
20efa1c2
AJ
4156 cl->type = Log::Format::CLF_COMMON;
4157 } else if (strcmp(logdef_name, "combined") == 0) {
4158 cl->type = Log::Format::CLF_COMBINED;
3ff65596
AR
4159#if ICAP_CLIENT
4160 } else if (strcmp(logdef_name, "icap_squid") == 0) {
20efa1c2 4161 cl->type = Log::Format::CLF_ICAP_SQUID;
3ff65596 4162#endif
20efa1c2
AJ
4163 } else if (strcmp(logdef_name, "useragent") == 0) {
4164 cl->type = Log::Format::CLF_USERAGENT;
4165 } else if (strcmp(logdef_name, "referrer") == 0) {
4166 cl->type = Log::Format::CLF_REFERER;
fb0c2f17 4167 } else if (dieWhenMissing) {
fa84c01d 4168 debugs(3, DBG_CRITICAL, "Log format '" << logdef_name << "' is not defined");
7684c4b1 4169 self_destruct();
fb0c2f17
NH
4170 return false;
4171 } else {
4172 return false;
7684c4b1 4173 }
4174
fb0c2f17 4175 return true;
7684c4b1 4176}
4177
d64bef4c 4178static int
87ddff6e 4179check_null_access_log(CustomLog *customlog_definitions)
d64bef4c 4180{
4181 return customlog_definitions == NULL;
4182}
4183
7684c4b1 4184static void
87ddff6e 4185dump_access_log(StoreEntry * entry, const char *name, CustomLog * logs)
7684c4b1 4186{
87ddff6e 4187 CustomLog *log;
7684c4b1 4188
4189 for (log = logs; log; log = log->next) {
4190 storeAppendPrintf(entry, "%s ", name);
4191
4192 switch (log->type) {
4193
20efa1c2 4194 case Log::Format::CLF_CUSTOM:
7684c4b1 4195 storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name);
4196 break;
4197
20efa1c2 4198 case Log::Format::CLF_NONE:
7684c4b1 4199 storeAppendPrintf(entry, "none");
4200 break;
4201
20efa1c2 4202 case Log::Format::CLF_SQUID:
7684c4b1 4203 storeAppendPrintf(entry, "%s squid", log->filename);
4204 break;
4205
20efa1c2
AJ
4206 case Log::Format::CLF_COMBINED:
4207 storeAppendPrintf(entry, "%s combined", log->filename);
4208 break;
4209
4210 case Log::Format::CLF_COMMON:
4211 storeAppendPrintf(entry, "%s common", log->filename);
7684c4b1 4212 break;
20efa1c2 4213
3ff65596 4214#if ICAP_CLIENT
20efa1c2 4215 case Log::Format::CLF_ICAP_SQUID:
3ff65596
AR
4216 storeAppendPrintf(entry, "%s icap_squid", log->filename);
4217 break;
4218#endif
20efa1c2
AJ
4219 case Log::Format::CLF_USERAGENT:
4220 storeAppendPrintf(entry, "%s useragent", log->filename);
4221 break;
7684c4b1 4222
20efa1c2
AJ
4223 case Log::Format::CLF_REFERER:
4224 storeAppendPrintf(entry, "%s referrer", log->filename);
7684c4b1 4225 break;
4226
20efa1c2 4227 case Log::Format::CLF_UNKNOWN:
7684c4b1 4228 break;
4229 }
4230
4231 if (log->aclList)
4232 dump_acl_list(entry, log->aclList);
4233
4234 storeAppendPrintf(entry, "\n");
4235 }
4236}
4237
7684c4b1 4238static void
87ddff6e 4239free_access_log(CustomLog ** definitions)
7684c4b1 4240{
4241 while (*definitions) {
87ddff6e 4242 CustomLog *log = *definitions;
7684c4b1 4243 *definitions = log->next;
4244
4245 log->logFormat = NULL;
20efa1c2 4246 log->type = Log::Format::CLF_UNKNOWN;
7684c4b1 4247
4248 if (log->aclList)
4249 aclDestroyAclList(&log->aclList);
4250
4251 safe_free(log->filename);
4252
4253 xfree(log);
4254 }
4255}
3a69ddf3 4256
96c2bb61
AR
4257/// parses list of integers form name=N1,N2,N3,...
4258static bool
c8ea3cc0 4259parseNamedIntList(const char *data, const String &name, std::vector<int> &list)
96c2bb61
AR
4260{
4261 if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) {
4262 data += name.size();
4263 if (*data == '=') {
4264 while (true) {
4265 ++data;
4266 int value = 0;
4267 if (!StringToInt(data, value, &data, 10))
4268 break;
4269 list.push_back(value);
4270 if (*data == '\0' || *data != ',')
4271 break;
4272 }
4273 }
4274 }
cff99cec 4275 return data && *data == '\0';
96c2bb61
AR
4276}
4277
4278static void
212af65c
A
4279parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4280{
96c2bb61
AR
4281#if !HAVE_CPU_AFFINITY
4282 debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " <<
4283 "support, do not set 'cpu_affinity_map'");
4284 self_destruct();
4285#endif /* HAVE_CPU_AFFINITY */
4286
4287 if (!*cpuAffinityMap)
4288 *cpuAffinityMap = new CpuAffinityMap;
4289
2eceb328
CT
4290 const char *const pToken = ConfigParser::NextToken();
4291 const char *const cToken = ConfigParser::NextToken();
c8ea3cc0 4292 std::vector<int> processes, cores;
96c2bb61
AR
4293 if (!parseNamedIntList(pToken, "process_numbers", processes)) {
4294 debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " <<
4295 "in 'cpu_affinity_map'");
4296 self_destruct();
4297 } else if (!parseNamedIntList(cToken, "cores", cores)) {
4298 debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " <<
4299 "'cpu_affinity_map'");
4300 self_destruct();
4301 } else if (!(*cpuAffinityMap)->add(processes, cores)) {
4302 debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " <<
4303 "process_numbers and cores lists differ in length or " <<
4304 "contain numbers <= 0");
4305 self_destruct();
4306 }
4307}
4308
4309static void
212af65c
A
4310dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap)
4311{
96c2bb61
AR
4312 if (cpuAffinityMap) {
4313 storeAppendPrintf(entry, "%s process_numbers=", name);
4314 for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4315 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4316 cpuAffinityMap->processes()[i]);
4317 }
4318 storeAppendPrintf(entry, " cores=");
eaed60cc 4319 for (size_t i = 0; i < cpuAffinityMap->cores().size(); ++i) {
96c2bb61
AR
4320 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4321 cpuAffinityMap->cores()[i]);
4322 }
4323 storeAppendPrintf(entry, "\n");
4324 }
4325}
4326
4327static void
212af65c
A
4328free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4329{
96c2bb61
AR
4330 delete *cpuAffinityMap;
4331 *cpuAffinityMap = NULL;
4332}
4333
62c7f90e
AR
4334#if USE_ADAPTATION
4335
4336static void
4337parse_adaptation_service_set_type()
4338{
4339 Adaptation::Config::ParseServiceSet();
4340}
4341
a22e6cd3
AR
4342static void
4343parse_adaptation_service_chain_type()
4344{
4345 Adaptation::Config::ParseServiceChain();
4346}
4347
62c7f90e
AR
4348static void
4349parse_adaptation_access_type()
4350{
4351 Adaptation::Config::ParseAccess(LegacyParser);
4352}
62c7f90e
AR
4353#endif /* USE_ADAPTATION */
4354
3a69ddf3 4355#if ICAP_CLIENT
4356
4357static void
26cc52cb 4358parse_icap_service_type(Adaptation::Icap::Config * cfg)
3a69ddf3 4359{
462e63d3 4360 cfg->parseService();
3a69ddf3 4361}
4362
4363static void
26cc52cb 4364free_icap_service_type(Adaptation::Icap::Config * cfg)
3a69ddf3 4365{
462e63d3 4366 cfg->freeService();
3a69ddf3 4367}
4368
4369static void
26cc52cb 4370dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
3a69ddf3 4371{
462e63d3 4372 cfg.dumpService(entry, name);
3a69ddf3 4373}
4374
4375static void
c939dc70 4376parse_icap_class_type()
3a69ddf3 4377{
fa84c01d 4378 debugs(93, DBG_CRITICAL, "WARNING: 'icap_class' is depricated. " <<
26ac0430 4379 "Use 'adaptation_service_set' instead");
62c7f90e 4380 Adaptation::Config::ParseServiceSet();
3a69ddf3 4381}
4382
3a69ddf3 4383static void
c939dc70 4384parse_icap_access_type()
3a69ddf3 4385{
fa84c01d 4386 debugs(93, DBG_CRITICAL, "WARNING: 'icap_access' is depricated. " <<
26ac0430 4387 "Use 'adaptation_access' instead");
21a26d31 4388 Adaptation::Config::ParseAccess(LegacyParser);
3a69ddf3 4389}
4390
3a69ddf3 4391#endif
21a26d31 4392
21a26d31
AR
4393#if USE_ECAP
4394
4395static void
574b508c 4396parse_ecap_service_type(Adaptation::Ecap::Config * cfg)
21a26d31
AR
4397{
4398 cfg->parseService();
4399}
4400
4401static void
574b508c 4402free_ecap_service_type(Adaptation::Ecap::Config * cfg)
21a26d31
AR
4403{
4404 cfg->freeService();
4405}
4406
4407static void
574b508c 4408dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
21a26d31
AR
4409{
4410 cfg.dumpService(entry, name);
4411}
4412
4413#endif /* USE_ECAP */
8277060a
CT
4414
4415#if ICAP_CLIENT
4416static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4417{
4418 char *token;
4419 time_t d;
4420 time_t m;
4421 cfg->service_failure_limit = GetInteger();
4422
2eceb328 4423 if ((token = ConfigParser::NextToken()) == NULL)
8277060a
CT
4424 return;
4425
4426 if (strcmp(token,"in") != 0) {
fa84c01d 4427 debugs(3, DBG_CRITICAL, "expecting 'in' on'" << config_input_line << "'");
8277060a
CT
4428 self_destruct();
4429 }
4430
2eceb328 4431 if ((token = ConfigParser::NextToken()) == NULL) {
8277060a
CT
4432 self_destruct();
4433 }
4434
4435 d = static_cast<time_t> (xatoi(token));
a459e80a 4436
8277060a
CT
4437 m = static_cast<time_t> (1);
4438
4439 if (0 == d)
4440 (void) 0;
2eceb328 4441 else if ((token = ConfigParser::NextToken()) == NULL) {
fa84c01d 4442 debugs(3, DBG_CRITICAL, "No time-units on '" << config_input_line << "'");
8277060a 4443 self_destruct();
9b741834 4444 } else if ((m = parseTimeUnits(token, false)) == 0)
8277060a
CT
4445 self_destruct();
4446
4447 cfg->oldest_service_failure = (m * d);
4448}
4449
4450static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg)
4451{
4452 storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit);
4453 if (cfg.oldest_service_failure > 0) {
4454 storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure);
4455 }
4456 storeAppendPrintf(entry, "\n");
4457}
4458
4459static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4460{
4461 cfg->oldest_service_failure = 0;
4462 cfg->service_failure_limit = 0;
4463}
aebe6888 4464#endif
8277060a 4465
cb4f4424 4466#if USE_OPENSSL
fb2178bb
CT
4467static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
4468{
4469 char *al;
4470 sslproxy_cert_adapt *ca = (sslproxy_cert_adapt *) xcalloc(1, sizeof(sslproxy_cert_adapt));
2eceb328 4471 if ((al = ConfigParser::NextToken()) == NULL) {
fb2178bb
CT
4472 self_destruct();
4473 return;
4474 }
87f237a9 4475
fb2178bb
CT
4476 const char *param;
4477 if ( char *s = strchr(al, '{')) {
4478 *s = '\0'; // terminate the al string
a38ec4b1 4479 ++s;
fb2178bb
CT
4480 param = s;
4481 s = strchr(s, '}');
4482 if (!s) {
4483 self_destruct();
4484 return;
4485 }
4486 *s = '\0';
87f237a9 4487 } else
fb2178bb
CT
4488 param = NULL;
4489
4490 if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidAfter]) == 0) {
4491 ca->alg = Ssl::algSetValidAfter;
b8889258 4492 ca->param = xstrdup("on");
87f237a9 4493 } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidBefore]) == 0) {
fb2178bb 4494 ca->alg = Ssl::algSetValidBefore;
b8889258 4495 ca->param = xstrdup("on");
87f237a9 4496 } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetCommonName]) == 0) {
fb2178bb
CT
4497 ca->alg = Ssl::algSetCommonName;
4498 if (param) {
5367d845
CT
4499 if (strlen(param) > 64) {
4500 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param << "} : using common name longer than 64 bytes is not supported");
4501 self_destruct();
4502 return;
4503 }
b8889258 4504 ca->param = xstrdup(param);
fb2178bb
CT
4505 }
4506 } else {
4507 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al);
4508 self_destruct();
4509 return;
4510 }
4511
6f58d7d7 4512 aclParseAclList(LegacyParser, &ca->aclList, al);
fb2178bb 4513
87f237a9 4514 while (*cert_adapt)
fb2178bb
CT
4515 cert_adapt = &(*cert_adapt)->next;
4516
4517 *cert_adapt = ca;
4518}
4519
4520static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt)
4521{
4522 for (sslproxy_cert_adapt *ca = cert_adapt; ca != NULL; ca = ca->next) {
4523 storeAppendPrintf(entry, "%s ", name);
4524 storeAppendPrintf(entry, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca->alg), ca->param);
4525 if (ca->aclList)
4526 dump_acl_list(entry, ca->aclList);
4527 storeAppendPrintf(entry, "\n");
4528 }
4529}
4530
4531static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
4532{
87f237a9 4533 while (*cert_adapt) {
fb2178bb
CT
4534 sslproxy_cert_adapt *ca = *cert_adapt;
4535 *cert_adapt = ca->next;
4536 safe_free(ca->param);
4537
4538 if (ca->aclList)
4539 aclDestroyAclList(&ca->aclList);
4540
4541 safe_free(ca);
4542 }
4543}
aebe6888
CT
4544
4545static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign)
4546{
4547 char *al;
4548 sslproxy_cert_sign *cs = (sslproxy_cert_sign *) xcalloc(1, sizeof(sslproxy_cert_sign));
2eceb328 4549 if ((al = ConfigParser::NextToken()) == NULL) {
aebe6888
CT
4550 self_destruct();
4551 return;
4552 }
4553
4554 if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignTrusted]) == 0)
4555 cs->alg = Ssl::algSignTrusted;
4556 else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignUntrusted]) == 0)
4557 cs->alg = Ssl::algSignUntrusted;
4558 else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignSelf]) == 0)
4559 cs->alg = Ssl::algSignSelf;
4560 else {
4561 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al);
4562 self_destruct();
4563 return;
4564 }
4565
6f58d7d7 4566 aclParseAclList(LegacyParser, &cs->aclList, al);
aebe6888 4567
87f237a9 4568 while (*cert_sign)
aebe6888
CT
4569 cert_sign = &(*cert_sign)->next;
4570
4571 *cert_sign = cs;
4572}
4573
4574static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign)
4575{
4576 sslproxy_cert_sign *cs;
4577 for (cs = cert_sign; cs != NULL; cs = cs->next) {
4578 storeAppendPrintf(entry, "%s ", name);
4579 storeAppendPrintf(entry, "%s ", Ssl::certSignAlgorithm(cs->alg));
4580 if (cs->aclList)
4581 dump_acl_list(entry, cs->aclList);
4582 storeAppendPrintf(entry, "\n");
4583 }
4584}
4585
4586static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign)
4587{
87f237a9 4588 while (*cert_sign) {
aebe6888
CT
4589 sslproxy_cert_sign *cs = *cert_sign;
4590 *cert_sign = cs->next;
4591
4592 if (cs->aclList)
4593 aclDestroyAclList(&cs->aclList);
4594
4595 safe_free(cs);
4596 }
4597}
fb2178bb 4598
38450a50
CT
4599class sslBumpCfgRr: public ::RegisteredRunner
4600{
4601public:
4602 static Ssl::BumpMode lastDeprecatedRule;
4603 /* RegisteredRunner API */
21b7990f 4604 virtual void finalizeConfig();
38450a50
CT
4605};
4606
4607Ssl::BumpMode sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
4608
21b7990f 4609RunnerRegistrationEntry(sslBumpCfgRr);
38450a50 4610
21b7990f
AR
4611void
4612sslBumpCfgRr::finalizeConfig()
38450a50
CT
4613{
4614 if (lastDeprecatedRule != Ssl::bumpEnd) {
4615 assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone);
4616 static char buf[1024];
4617 if (lastDeprecatedRule == Ssl::bumpClientFirst) {
4618 strcpy(buf, "ssl_bump deny all");
4619 debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated implicit "
4620 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4621 "must not use implicit rules. Update your ssl_bump rules.");
4622 } else {
4623 strcpy(buf, "ssl_bump allow all");
4624 debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated implicit "
4625 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4626 "inferior to the newer server-first bumping mode. New ssl_bump"
4627 " configurations must not use implicit rules. Update your ssl_bump rules.");
4628 }
4629 parse_line(buf);
4630 }
4631}
4632
caf3666d
AR
4633static void parse_sslproxy_ssl_bump(acl_access **ssl_bump)
4634{
38450a50
CT
4635 typedef const char *BumpCfgStyle;
4636 BumpCfgStyle bcsNone = NULL;
4637 BumpCfgStyle bcsNew = "new client/server-first/none";
4638 BumpCfgStyle bcsOld = "deprecated allow/deny";
4639 static BumpCfgStyle bumpCfgStyleLast = bcsNone;
4640 BumpCfgStyle bumpCfgStyleNow = bcsNone;
caf3666d 4641 char *bm;
2eceb328 4642 if ((bm = ConfigParser::NextToken()) == NULL) {
caf3666d
AR
4643 self_destruct();
4644 return;
4645 }
4646
38450a50
CT
4647 // if this is the first rule proccessed
4648 if (*ssl_bump == NULL) {
4649 bumpCfgStyleLast = bcsNone;
4650 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
4651 }
4652
6f58d7d7 4653 allow_t action = allow_t(ACCESS_ALLOWED);
caf3666d 4654
38450a50 4655 if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpClientFirst]) == 0) {
6f58d7d7 4656 action.kind = Ssl::bumpClientFirst;
38450a50
CT
4657 bumpCfgStyleNow = bcsNew;
4658 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpServerFirst]) == 0) {
6f58d7d7 4659 action.kind = Ssl::bumpServerFirst;
38450a50
CT
4660 bumpCfgStyleNow = bcsNew;
4661 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpNone]) == 0) {
6f58d7d7 4662 action.kind = Ssl::bumpNone;
38450a50
CT
4663 bumpCfgStyleNow = bcsNew;
4664 } else if (strcmp(bm, "allow") == 0) {
4665 debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated "
4666 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4667 "is usually inferior to the newer server-first "
4668 "bumping mode. Update your ssl_bump rules.");
6f58d7d7 4669 action.kind = Ssl::bumpClientFirst;
38450a50
CT
4670 bumpCfgStyleNow = bcsOld;
4671 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpClientFirst;
4672 } else if (strcmp(bm, "deny") == 0) {
4673 debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated "
4674 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4675 "your ssl_bump rules.");
6f58d7d7 4676 action.kind = Ssl::bumpNone;
38450a50
CT
4677 bumpCfgStyleNow = bcsOld;
4678 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpNone;
caf3666d
AR
4679 } else {
4680 debugs(3, DBG_CRITICAL, "FATAL: unknown ssl_bump mode: " << bm);
4681 self_destruct();
4682 return;
4683 }
4684
38450a50 4685 if (bumpCfgStyleLast != bcsNone && bumpCfgStyleNow != bumpCfgStyleLast) {
87f237a9 4686 debugs(3, DBG_CRITICAL, "FATAL: do not mix " << bumpCfgStyleNow << " actions with " <<
38450a50
CT
4687 bumpCfgStyleLast << " actions. Update your ssl_bump rules.");
4688 self_destruct();
4689 return;
4690 }
4691
4692 bumpCfgStyleLast = bumpCfgStyleNow;
4693
8984b8cd 4694 Acl::AndNode *rule = new Acl::AndNode;
6f58d7d7 4695 rule->context("(ssl_bump rule)", config_input_line);
8984b8cd
CT
4696 rule->lineParse();
4697 // empty rule OK
6f58d7d7
AR
4698
4699 assert(ssl_bump);
4700 if (!*ssl_bump) {
4701 *ssl_bump = new Acl::Tree;
4702 (*ssl_bump)->context("(ssl_bump rules)", config_input_line);
4703 }
caf3666d 4704
6f58d7d7 4705 (*ssl_bump)->add(rule, action);
caf3666d
AR
4706}
4707
4708static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump)
4709{
2cb8d372
FC
4710 if (ssl_bump)
4711 dump_SBufList(entry, ssl_bump->treeDump(name, Ssl::BumpModeStr));
caf3666d
AR
4712}
4713
4714static void free_sslproxy_ssl_bump(acl_access **ssl_bump)
4715{
4716 free_acl_access(ssl_bump);
4717}
8277060a
CT
4718
4719#endif
f4698e0b
CT
4720
4721static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers)
4722{
4723 if (!headers)
4724 return;
4725
4726 for (HeaderWithAclList::iterator hwa = headers->begin(); hwa != headers->end(); ++hwa) {
4727 storeAppendPrintf(entry, "%s ", hwa->fieldName.c_str());
4728 storeAppendPrintf(entry, "%s ", hwa->fieldValue.c_str());
4729 if (hwa->aclList)
4730 dump_acl_list(entry, hwa->aclList);
4731 storeAppendPrintf(entry, "\n");
4732 }
4733}
4734
4735static void parse_HeaderWithAclList(HeaderWithAclList **headers)
4736{
4737 char *fn;
4738 if (!*headers) {
4739 *headers = new HeaderWithAclList;
4740 }
2eceb328 4741 if ((fn = ConfigParser::NextToken()) == NULL) {
f4698e0b
CT
4742 self_destruct();
4743 return;
4744 }
4745 HeaderWithAcl hwa;
4746 hwa.fieldName = fn;
4747 hwa.fieldId = httpHeaderIdByNameDef(fn, strlen(fn));
4748 if (hwa.fieldId == HDR_BAD_HDR)
4749 hwa.fieldId = HDR_OTHER;
4750
2eceb328
CT
4751 Format::Format *nlf = new ::Format::Format("hdrWithAcl");
4752 ConfigParser::EnableMacros();
bde7a8ce 4753 String buf = ConfigParser::NextQuotedToken();
2eceb328 4754 ConfigParser::DisableMacros();
f4698e0b 4755 hwa.fieldValue = buf.termedBuf();
2eceb328 4756 hwa.quoted = ConfigParser::LastTokenWasQuoted();
f4698e0b 4757 if (hwa.quoted) {
f4698e0b
CT
4758 if (!nlf->parse(hwa.fieldValue.c_str())) {
4759 self_destruct();
4760 return;
4761 }
4762 hwa.valueFormat = nlf;
2eceb328
CT
4763 } else
4764 delete nlf;
6f58d7d7 4765 aclParseAclList(LegacyParser, &hwa.aclList, (hwa.fieldName + ':' + hwa.fieldValue).c_str());
f4698e0b
CT
4766 (*headers)->push_back(hwa);
4767}
4768
4769static void free_HeaderWithAclList(HeaderWithAclList **header)
4770{
4771 if (!(*header))
4772 return;
4773
4774 for (HeaderWithAclList::iterator hwa = (*header)->begin(); hwa != (*header)->end(); ++hwa) {
4775 if (hwa->aclList)
4776 aclDestroyAclList(&hwa->aclList);
4777
4778 if (hwa->valueFormat) {
4779 delete hwa->valueFormat;
4780 hwa->valueFormat = NULL;
4781 }
4782 }
4783 delete *header;
4784 *header = NULL;
4785}
d7f4a0b7
CT
4786
4787static void parse_note(Notes *notes)
4788{
4789 assert(notes);
4790 notes->parse(LegacyParser);
4791}
4792
4793static void dump_note(StoreEntry *entry, const char *name, Notes &notes)
4794{
4795 notes.dump(entry, name);
4796}
4797
4798static void free_note(Notes *notes)
4799{
4800 notes->clean();
4801}
bde7a8ce 4802
ddf5aa2b
CT
4803static bool FtpEspvDeprecated = false;
4804static void parse_ftp_epsv(acl_access **ftp_epsv)
4805{
4806 allow_t ftpEpsvDeprecatedAction;
4807 bool ftpEpsvIsDeprecatedRule = false;
4808
4809 char *t = ConfigParser::PeekAtToken();
e2849af8 4810 if (!t) {
ddf5aa2b
CT
4811 self_destruct();
4812 return;
4813 }
4814
4815 if (!strcmp(t, "off")) {
4816 (void)ConfigParser::NextToken();
4817 ftpEpsvIsDeprecatedRule = true;
4818 ftpEpsvDeprecatedAction = allow_t(ACCESS_DENIED);
4819 } else if (!strcmp(t, "on")) {
4820 (void)ConfigParser::NextToken();
4821 ftpEpsvIsDeprecatedRule = true;
4822 ftpEpsvDeprecatedAction = allow_t(ACCESS_ALLOWED);
4823 }
4824
4825 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4826 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4827 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4828 // then abort
4829 if ((!ftpEpsvIsDeprecatedRule && FtpEspvDeprecated) ||
e2849af8 4830 (ftpEpsvIsDeprecatedRule && !FtpEspvDeprecated && *ftp_epsv != NULL)) {
ddf5aa2b
CT
4831 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.");
4832 self_destruct();
4833 }
4834
4835 if (ftpEpsvIsDeprecatedRule) {
4836 // overwrite previous ftp_epsv lines
4837 delete *ftp_epsv;
4838 if (ftpEpsvDeprecatedAction == allow_t(ACCESS_DENIED)) {
4839 Acl::AndNode *ftpEpsvRule = new Acl::AndNode;
4840 ftpEpsvRule->context("(ftp_epsv rule)", config_input_line);
4841 ACL *a = ACL::FindByName("all");
4842 if (!a) {
4843 self_destruct();
4844 return;
4845 }
4846 ftpEpsvRule->add(a);
4847 *ftp_epsv = new Acl::Tree;
4848 (*ftp_epsv)->context("(ftp_epsv rules)", config_input_line);
4849 (*ftp_epsv)->add(ftpEpsvRule, ftpEpsvDeprecatedAction);
4850 } else
4851 *ftp_epsv = NULL;
4852 FtpEspvDeprecated = true;
4853 } else {
4854 aclParseAccessLine(cfg_directive, LegacyParser, ftp_epsv);
4855 }
4856}
4857
4858static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv)
4859{
dfad5100
FC
4860 if (ftp_epsv)
4861 dump_SBufList(entry, ftp_epsv->treeDump(name, NULL));
ddf5aa2b
CT
4862}
4863
4864static void free_ftp_epsv(acl_access **ftp_epsv)
4865{
4866 free_acl_access(ftp_epsv);
4867 FtpEspvDeprecated = false;
4868}
4869
bde7a8ce
CT
4870static void
4871parse_configuration_includes_quoted_values(bool *recognizeQuotedValues)
4872{
4873 int val = 0;
4874 parse_onoff(&val);
4875
4876 // If quoted values is set to on then enable new strict mode parsing
4877 if (val) {
4878 ConfigParser::RecognizeQuotedValues = true;
4879 ConfigParser::StrictMode = true;
4880 } else {
4881 ConfigParser::RecognizeQuotedValues = false;
4882 ConfigParser::StrictMode = false;
4883 }
4884}
4885
4886static void
4887dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool recognizeQuotedValues)
4888{
4889 int val = ConfigParser::RecognizeQuotedValues ? 1 : 0;
4890 dump_onoff(entry, name, val);
4891}
4892
4893static void
4894free_configuration_includes_quoted_values(bool *recognizeQuotedValues)
4895{
4896 ConfigParser::RecognizeQuotedValues = false;
4897 ConfigParser::StrictMode = false;
4898}