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