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