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