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

 

Introduction

Documentation

Support

Miscellaneous