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