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