cache_cf.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 parse_u_short(unsigned short * var);
165 static void parse_string(char **);
166 static void default_all(void);
167 static void defaults_if_none(void);
168 static void defaults_postscriptum(void);
169 static int parse_line(char *);
170 static void parse_obsolete(const char *);
171 static void parseBytesLine(size_t * bptr, const char *units);
172 static void parseBytesLineSigned(ssize_t * bptr, const char *units);
173 static size_t parseBytesUnits(const char *unit);
174 static void free_all(void);
175 void requirePathnameExists(const char *name, const char *path);
177 #if USE_HTTP_VIOLATIONS
178 static void free_HeaderManglers(HeaderManglers **pm);
179 static void dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
180 static void parse_http_header_access(HeaderManglers **manglers);
181 #define free_http_header_access free_HeaderManglers
182 static void dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
183 static void parse_http_header_replace(HeaderManglers **manglers);
184 #define free_http_header_replace free_HeaderManglers
185 #endif
186 static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers);
187 static void parse_HeaderWithAclList(HeaderWithAclList **header);
188 static void free_HeaderWithAclList(HeaderWithAclList **header);
189 static void parse_note(Notes *);
190 static void dump_note(StoreEntry *, const char *, Notes &);
191 static void free_note(Notes *);
192 static void parse_denyinfo(AclDenyInfoList ** var);
193 static void dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var);
194 static void free_denyinfo(AclDenyInfoList ** var);
195 
196 #if USE_WCCPv2
197 static void parse_IpAddress_list(Ip::Address_list **);
198 static void dump_IpAddress_list(StoreEntry *, const char *, const Ip::Address_list *);
199 static void free_IpAddress_list(Ip::Address_list **);
200 #if CURRENTLY_UNUSED
201 static int check_null_IpAddress_list(const Ip::Address_list *);
202 #endif /* CURRENTLY_UNUSED */
203 #endif /* USE_WCCPv2 */
204 
205 static void parsePortCfg(AnyP::PortCfgPointer *, const char *protocol);
206 #define parse_PortCfg(l) parsePortCfg((l), token)
207 static void dump_PortCfg(StoreEntry *, const char *, const AnyP::PortCfgPointer &);
208 #define free_PortCfg(h) *(h)=NULL
209 
210 #if USE_OPENSSL
211 static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign);
212 static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign);
213 static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign);
214 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt);
215 static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt);
216 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt);
217 static void parse_sslproxy_ssl_bump(acl_access **ssl_bump);
218 static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump);
219 static void free_sslproxy_ssl_bump(acl_access **ssl_bump);
220 #endif /* USE_OPENSSL */
221 
222 static void parse_ftp_epsv(acl_access **ftp_epsv);
223 static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv);
224 static void free_ftp_epsv(acl_access **ftp_epsv);
225 
226 static void parse_b_size_t(size_t * var);
227 static void parse_b_int64_t(int64_t * var);
228 
229 static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
230 static void dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap);
231 static void free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
232 
234 static void dump_UrlHelperTimeout(StoreEntry *, const char *, SquidConfig::UrlHelperTimeout &);
236 
237 static int parseOneConfigFile(const char *file_name, unsigned int depth);
238 
239 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues);
240 static void dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool recognizeQuotedValues);
241 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues);
242 static void parse_on_unsupported_protocol(acl_access **access);
243 static void dump_on_unsupported_protocol(StoreEntry *entry, const char *name, acl_access *access);
244 static void free_on_unsupported_protocol(acl_access **access);
245 static void ParseAclWithAction(acl_access **access, const Acl::Answer &action, const char *desc, ACL *acl = nullptr);
246 
247 /*
248  * LegacyParser is a parser for legacy code that uses the global
249  * approach. This is static so that it is only exposed to cache_cf.
250  * Other modules needing access to a ConfigParser should have it
251  * provided to them in their parserFOO methods.
252  */
253 static ConfigParser LegacyParser = ConfigParser();
254 
255 void
257 {
258  LegacyParser.destruct();
259 }
260 
261 static void
262 SetConfigFilename(char const *file_name, bool is_pipe)
263 {
264  if (is_pipe)
265  cfg_filename = file_name + 1;
266  else
267  cfg_filename = file_name;
268 }
269 
270 static const char*
271 skip_ws(const char* s)
272 {
273  while (xisspace(*s))
274  ++s;
275 
276  return s;
277 }
278 
279 static int
280 parseManyConfigFiles(char* files, int depth)
281 {
282  int error_count = 0;
283  char* saveptr = NULL;
284 #if HAVE_GLOB
285  char *path;
286  glob_t globbuf;
287  int i;
288  memset(&globbuf, 0, sizeof(globbuf));
289  for (path = strwordtok(files, &saveptr); path; path = strwordtok(NULL, &saveptr)) {
290  if (glob(path, globbuf.gl_pathc ? GLOB_APPEND : 0, NULL, &globbuf) != 0) {
291  int xerrno = errno;
292  fatalf("Unable to find configuration file: %s: %s", path, xstrerr(xerrno));
293  }
294  }
295  for (i = 0; i < (int)globbuf.gl_pathc; ++i) {
296  error_count += parseOneConfigFile(globbuf.gl_pathv[i], depth);
297  }
298  globfree(&globbuf);
299 #else
300  char* file = strwordtok(files, &saveptr);
301  while (file != NULL) {
302  error_count += parseOneConfigFile(file, depth);
303  file = strwordtok(NULL, &saveptr);
304  }
305 #endif /* HAVE_GLOB */
306  return error_count;
307 }
308 
309 static void
310 ReplaceSubstr(char*& str, int& len, unsigned substrIdx, unsigned substrLen, const char* newSubstr)
311 {
312  assert(str != NULL);
313  assert(newSubstr != NULL);
314 
315  unsigned newSubstrLen = strlen(newSubstr);
316  if (newSubstrLen > substrLen)
317  str = (char*)realloc(str, len - substrLen + newSubstrLen + 1);
318 
319  // move tail part including zero
320  memmove(str + substrIdx + newSubstrLen, str + substrIdx + substrLen, len - substrIdx - substrLen + 1);
321  // copy new substring in place
322  memcpy(str + substrIdx, newSubstr, newSubstrLen);
323 
324  len = strlen(str);
325 }
326 
327 static void
328 SubstituteMacro(char*& line, int& len, const char* macroName, const char* substStr)
329 {
330  assert(line != NULL);
331  assert(macroName != NULL);
332  assert(substStr != NULL);
333  unsigned macroNameLen = strlen(macroName);
334  while (const char* macroPos = strstr(line, macroName)) // we would replace all occurrences
335  ReplaceSubstr(line, len, macroPos - line, macroNameLen, substStr);
336 }
337 
338 static void
339 ProcessMacros(char*& line, int& len)
340 {
341  SubstituteMacro(line, len, "${service_name}", service_name.c_str());
342  SubstituteMacro(line, len, "${process_name}", TheKidName.c_str());
343  SubstituteMacro(line, len, "${process_number}", xitoa(KidIdentifier));
344 }
345 
346 static void
348 {
349  assert(str != NULL);
350  unsigned i = strlen(str);
351  while ((i > 0) && xisspace(str[i - 1]))
352  --i;
353  str[i] = '\0';
354 }
355 
356 static const char*
357 FindStatement(const char* line, const char* statement)
358 {
359  assert(line != NULL);
360  assert(statement != NULL);
361 
362  const char* str = skip_ws(line);
363  unsigned len = strlen(statement);
364  if (strncmp(str, statement, len) == 0) {
365  str += len;
366  if (*str == '\0')
367  return str;
368  else if (xisspace(*str))
369  return skip_ws(str);
370  }
371 
372  return NULL;
373 }
374 
375 static bool
376 StrToInt(const char* str, long& number)
377 {
378  assert(str != NULL);
379 
380  char* end;
381  number = strtol(str, &end, 0);
382 
383  return (end != str) && (*end == '\0'); // returns true if string contains nothing except number
384 }
385 
386 static bool
387 EvalBoolExpr(const char* expr)
388 {
389  assert(expr != NULL);
390  if (strcmp(expr, "true") == 0) {
391  return true;
392  } else if (strcmp(expr, "false") == 0) {
393  return false;
394  } else if (const char* equation = strchr(expr, '=')) {
395  const char* rvalue = skip_ws(equation + 1);
396  char* lvalue = (char*)xmalloc(equation - expr + 1);
397  xstrncpy(lvalue, expr, equation - expr + 1);
398  trim_trailing_ws(lvalue);
399 
400  long number1;
401  if (!StrToInt(lvalue, number1))
402  fatalf("String is not a integer number: '%s'\n", lvalue);
403  long number2;
404  if (!StrToInt(rvalue, number2))
405  fatalf("String is not a integer number: '%s'\n", rvalue);
406 
407  xfree(lvalue);
408  return number1 == number2;
409  }
410  fatalf("Unable to evaluate expression '%s'\n", expr);
411  return false; // this place cannot be reached
412 }
413 
414 static int
415 parseOneConfigFile(const char *file_name, unsigned int depth)
416 {
417  FILE *fp = NULL;
418  const char *orig_cfg_filename = cfg_filename;
419  const int orig_config_lineno = config_lineno;
420  char *token = NULL;
421  char *tmp_line = NULL;
422  int tmp_line_len = 0;
423  int err_count = 0;
424  int is_pipe = 0;
425 
426  debugs(3, DBG_IMPORTANT, "Processing Configuration File: " << file_name << " (depth " << depth << ")");
427  if (depth > 16) {
428  fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name);
429  return 1;
430  }
431 
432  if (file_name[0] == '!' || file_name[0] == '|') {
433  fp = popen(file_name + 1, "r");
434  is_pipe = 1;
435  } else {
436  fp = fopen(file_name, "r");
437  }
438 
439  if (!fp) {
440  int xerrno = errno;
441  fatalf("Unable to open configuration file: %s: %s", file_name, xstrerr(xerrno));
442  }
443 
444 #if _SQUID_WINDOWS_
445  setmode(fileno(fp), O_TEXT);
446 #endif
447 
448  SetConfigFilename(file_name, bool(is_pipe));
449 
450  memset(config_input_line, '\0', BUFSIZ);
451 
452  config_lineno = 0;
453 
454  std::vector<bool> if_states;
455  while (fgets(config_input_line, BUFSIZ, fp)) {
456  ++config_lineno;
457 
458  if ((token = strchr(config_input_line, '\n')))
459  *token = '\0';
460 
461  if ((token = strchr(config_input_line, '\r')))
462  *token = '\0';
463 
464  // strip any prefix whitespace off the line.
465  const char *p = skip_ws(config_input_line);
466  if (config_input_line != p)
467  memmove(config_input_line, p, strlen(p)+1);
468 
469  if (strncmp(config_input_line, "#line ", 6) == 0) {
470  static char new_file_name[1024];
471  static char *file;
472  static char new_lineno;
473  token = config_input_line + 6;
474  new_lineno = strtol(token, &file, 0) - 1;
475 
476  if (file == token)
477  continue; /* Not a valid #line directive, may be a comment */
478 
479  while (*file && xisspace((unsigned char) *file))
480  ++file;
481 
482  if (*file) {
483  if (*file != '"')
484  continue; /* Not a valid #line directive, may be a comment */
485 
486  xstrncpy(new_file_name, file + 1, sizeof(new_file_name));
487 
488  if ((token = strchr(new_file_name, '"')))
489  *token = '\0';
490 
491  SetConfigFilename(new_file_name, false);
492  }
493 
494  config_lineno = new_lineno;
495  }
496 
497  if (config_input_line[0] == '#')
498  continue;
499 
500  if (config_input_line[0] == '\0')
501  continue;
502 
503  const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line;
504 
505  size_t append_len = strlen(append);
506 
507  tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1);
508 
509  strcpy(tmp_line + tmp_line_len, append);
510 
511  tmp_line_len += append_len;
512 
513  if (tmp_line[tmp_line_len-1] == '\\') {
514  debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'");
515  tmp_line[--tmp_line_len] = '\0';
516  continue;
517  }
518 
519  trim_trailing_ws(tmp_line);
520  ProcessMacros(tmp_line, tmp_line_len);
521  debugs(3, (opt_parse_cfg_only?1:5), "Processing: " << tmp_line);
522 
523  if (const char* expr = FindStatement(tmp_line, "if")) {
524  if_states.push_back(EvalBoolExpr(expr)); // store last if-statement meaning
525  } else if (FindStatement(tmp_line, "endif")) {
526  if (!if_states.empty())
527  if_states.pop_back(); // remove last if-statement meaning
528  else
529  fatalf("'endif' without 'if'\n");
530  } else if (FindStatement(tmp_line, "else")) {
531  if (!if_states.empty())
532  if_states.back() = !if_states.back();
533  else
534  fatalf("'else' without 'if'\n");
535  } else if (if_states.empty() || if_states.back()) { // test last if-statement meaning if present
536  /* Handle includes here */
537  if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) {
538  err_count += parseManyConfigFiles(tmp_line + 8, depth + 1);
539  } else if (!parse_line(tmp_line)) {
540  debugs(3, DBG_CRITICAL, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'");
541  ++err_count;
542  }
543  }
544 
545  safe_free(tmp_line);
546  tmp_line_len = 0;
547 
548  }
549  if (!if_states.empty())
550  fatalf("if-statement without 'endif'\n");
551 
552  if (is_pipe) {
553  int ret = pclose(fp);
554 
555  if (ret != 0)
556  fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret);
557  } else {
558  fclose(fp);
559  }
560 
561  SetConfigFilename(orig_cfg_filename, false);
562  config_lineno = orig_config_lineno;
563 
564  xfree(tmp_line);
565  return err_count;
566 }
567 
568 static
569 int
570 parseConfigFileOrThrow(const char *file_name)
571 {
572  int err_count = 0;
573 
574  debugs(5, 4, HERE);
575 
577 
579  default_all();
580 
581  err_count = parseOneConfigFile(file_name, 0);
582 
584 
586 
587  /*
588  * We must call configDoConfigure() before leave_suid() because
589  * configDoConfigure() is where we turn username strings into
590  * uid values.
591  */
593 
594  if (!Config.chroot_dir) {
595  leave_suid();
598  enter_suid();
599  }
600 
601  if (opt_send_signal == -1) {
602  Mgr::RegisterAction("config",
603  "Current Squid Configuration",
604  dump_config,
605  1, 1);
606  }
607 
608  return err_count;
609 }
610 
611 // TODO: Refactor main.cc to centrally handle (and report) all exceptions.
612 int
613 parseConfigFile(const char *file_name)
614 {
615  try {
616  return parseConfigFileOrThrow(file_name);
617  }
618  catch (const std::exception &ex) {
619  debugs(3, DBG_CRITICAL, "FATAL: bad configuration: " << ex.what());
620  self_destruct();
621  return 1; // not reached
622  }
623 }
624 
625 static void
627 {
628  Config2.clear();
629  /* init memory as early as possible */
630  memConfigure();
631  /* Sanity checks */
632 
633  Config.cacheSwap.n_strands = 0; // no diskers by default
634  if (Config.cacheSwap.swapDirs == NULL) {
635  /* Memory-only cache probably in effect. */
636  /* turn off the cache rebuild delays... */
638  } else if (InDaemonMode()) { // no diskers in non-daemon mode
639  for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
641  if (sd->needsDiskStrand())
643  }
644  }
645 
646  if (Debug::rotateNumber < 0) {
648  }
649 
650 #if SIZEOF_OFF_T <= 4
651  if (Config.Store.maxObjectSize > 0x7FFF0000) {
652  debugs(3, DBG_CRITICAL, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
653  Config.Store.maxObjectSize = 0x7FFF0000;
654  }
655 #endif
656 
657  if (Config.Announce.period > 0) {
658  Config.onoff.announce = 1;
659  } else {
660  Config.Announce.period = 86400 * 365; /* one year */
661  Config.onoff.announce = 0;
662  }
663 
666  else
667  visible_appname_string = (char const *)APP_FULLNAME;
668 
669  if (Config.Program.redirect) {
670  if (Config.redirectChildren.n_max < 1) {
673  }
674  }
675 
676  if (Config.Program.store_id) {
677  if (Config.storeIdChildren.n_max < 1) {
680  }
681  }
682 
683  if (Config.appendDomain)
684  if (*Config.appendDomain != '.')
685  fatal("append_domain must begin with a '.'");
686 
687  if (Config.errHtmlText == NULL)
689 
690 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
691  if (Config.max_filedescriptors > 0) {
692  debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
693  }
694 #elif USE_SELECT || USE_SELECT_WIN32
695  if (Config.max_filedescriptors > FD_SETSIZE) {
696  debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors limited to " << FD_SETSIZE << " by select() algorithm.");
697  }
698 #endif
699 
700  storeConfigure();
701 
702  snprintf(ThisCache, sizeof(ThisCache), "%s (%s)",
703  uniqueHostname(),
705 
706  /*
707  * the extra space is for loop detection in client_side.c -- we search
708  * for substrings in the Via header.
709  */
710  snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)",
711  uniqueHostname(),
713 
714  /* Use visible_hostname as default surrogate_id */
715  if (!Config.Accel.surrogate_id) {
716  const char *t = getMyHostname();
717  Config.Accel.surrogate_id = xstrdup( (t?t:"unset-id") );
718  }
719 
722 
723  if (Config.appendDomain)
725  else
727 
728  if (Config.connect_retries > 10) {
729  debugs(0,DBG_CRITICAL, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
730  Config.connect_retries = 10;
731  }
732 
733  requirePathnameExists("MIME Config Table", Config.mimeTablePathname);
734 #if USE_UNLINKD
735 
736  requirePathnameExists("unlinkd_program", Config.Program.unlinkd);
737 #endif
738  bool logDaemonUsed = false;
739  for (const auto *log = Config.Log.accesslogs; !logDaemonUsed && log; log = log->next)
740  logDaemonUsed = log->usesDaemon();
741 #if ICAP_CLIENT
742  for (const auto *log = Config.Log.icaplogs; !logDaemonUsed && log; log = log->next)
743  logDaemonUsed = log->usesDaemon();
744 #endif
745  if (logDaemonUsed)
746  requirePathnameExists("logfile_daemon", Log::TheConfig.logfile_daemon);
747 
748  if (Config.Program.redirect)
749  requirePathnameExists("redirect_program", Config.Program.redirect->key);
750 
751  if (Config.Program.store_id)
752  requirePathnameExists("store_id_program", Config.Program.store_id->key);
753 
754  requirePathnameExists("Icon Directory", Config.icons.directory);
755 
757  requirePathnameExists("Error Directory", Config.errorDirectory);
758 
759 #if USE_HTTP_VIOLATIONS
760 
761  {
762  const RefreshPattern *R;
763 
764  for (R = Config.Refresh; R; R = R->next) {
765  if (!R->flags.override_expire)
766  continue;
767 
768  debugs(22, DBG_IMPORTANT, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
769 
770  break;
771  }
772 
773  for (R = Config.Refresh; R; R = R->next) {
774  if (!R->flags.override_lastmod)
775  continue;
776 
777  debugs(22, DBG_IMPORTANT, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
778 
779  break;
780  }
781 
782  for (R = Config.Refresh; R; R = R->next) {
783  if (!R->flags.reload_into_ims)
784  continue;
785 
786  debugs(22, DBG_IMPORTANT, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
787 
788  break;
789  }
790 
791  for (R = Config.Refresh; R; R = R->next) {
792  if (!R->flags.ignore_reload)
793  continue;
794 
795  debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
796 
797  break;
798  }
799 
800  for (R = Config.Refresh; R; R = R->next) {
801  if (!R->flags.ignore_no_store)
802  continue;
803 
804  debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
805 
806  break;
807  }
808 
809  for (R = Config.Refresh; R; R = R->next) {
810  if (!R->flags.ignore_private)
811  continue;
812 
813  debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
814 
815  break;
816  }
817  }
818 #endif
819 #if !USE_HTTP_VIOLATIONS
820  Config.onoff.via = 1;
821 #else
822 
823  if (!Config.onoff.via)
824  debugs(22, DBG_IMPORTANT, "WARNING: HTTP requires the use of Via");
825 
826 #endif
827 
828  // we enable runtime PURGE checks if there is at least one PURGE method ACL
829  // TODO: replace with a dedicated "purge" ACL option?
831 
832  if (geteuid() == 0) {
833  if (NULL != Config.effectiveUser) {
834 
835  struct passwd *pwd = getpwnam(Config.effectiveUser);
836 
837  if (NULL == pwd) {
838  /*
839  * Andres Kroonmaa <andre@online.ee>:
840  * Some getpwnam() implementations (Solaris?) require
841  * an available FD < 256 for opening a FILE* to the
842  * passwd file.
843  * DW:
844  * This should be safe at startup, but might still fail
845  * during reconfigure.
846  */
847  fatalf("getpwnam failed to find userid for effective user '%s'",
849  return;
850  }
851 
852  Config2.effectiveUserID = pwd->pw_uid;
853 
854  Config2.effectiveGroupID = pwd->pw_gid;
855 
856 #if HAVE_PUTENV
857  if (pwd->pw_dir && *pwd->pw_dir) {
858  // putenv() leaks by design; avoid leaks when nothing changes
859  static SBuf lastDir;
860  if (lastDir.isEmpty() || lastDir.cmp(pwd->pw_dir) != 0) {
861  lastDir = pwd->pw_dir;
862  int len = strlen(pwd->pw_dir) + 6;
863  char *env_str = (char *)xcalloc(len, 1);
864  snprintf(env_str, len, "HOME=%s", pwd->pw_dir);
865  putenv(env_str);
866  }
867  }
868 #endif
869  }
870  } else {
871  Config2.effectiveUserID = geteuid();
872  Config2.effectiveGroupID = getegid();
873  }
874 
875  if (NULL != Config.effectiveGroup) {
876 
877  struct group *grp = getgrnam(Config.effectiveGroup);
878 
879  if (NULL == grp) {
880  fatalf("getgrnam failed to find groupid for effective group '%s'",
882  return;
883  }
884 
885  Config2.effectiveGroupID = grp->gr_gid;
886  }
887 
888 #if USE_OPENSSL
891 #endif
892 
893  if (Security::ProxyOutgoingConfig.encryptTransport) {
894  debugs(3, DBG_IMPORTANT, "Initializing https:// proxy context");
897 #if USE_OPENSSL
898  fatal("ERROR: Could not initialize https:// proxy context");
899 #else
900  debugs(3, DBG_IMPORTANT, "ERROR: proxying https:// currently still requires --with-openssl");
901 #endif
902  }
903 #if USE_OPENSSL
905 #endif
906  }
907 
908  for (CachePeer *p = Config.peers; p != NULL; p = p->next) {
909 
910  // default value for ssldomain= is the peer host/IP
911  if (p->secure.sslDomain.isEmpty())
912  p->secure.sslDomain = p->host;
913 
914  if (p->secure.encryptTransport) {
915  debugs(3, DBG_IMPORTANT, "Initializing cache_peer " << p->name << " TLS context");
916  p->sslContext = p->secure.createClientContext(true);
917  if (!p->sslContext) {
918  debugs(3, DBG_CRITICAL, "ERROR: Could not initialize cache_peer " << p->name << " TLS context");
919  self_destruct();
920  return;
921  }
922  }
923  }
924 
925  for (AnyP::PortCfgPointer s = HttpPortList; s != NULL; s = s->next) {
926  if (!s->secure.encryptTransport)
927  continue;
928  debugs(3, DBG_IMPORTANT, "Initializing " << AnyP::UriScheme(s->transport.protocol) << "_port " << s->s << " TLS contexts");
929  s->secure.initServerContexts(*s);
930  }
931 
932  // prevent infinite fetch loops in the request parser
933  // due to buffer full but not enough data recived to finish parse
935  fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
936  " Change client_request_buffer_max or request_header_max_size limits.",
938  }
939 
940  /*
941  * Disable client side request pipelining if client_persistent_connections OFF.
942  * Waste of resources queueing any pipelined requests when the first will close the connection.
943  */
945  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: pipeline_prefetch " << Config.pipeline_max_prefetch <<
946  " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
948  }
949 
950 #if USE_AUTH
951  /*
952  * disable client side request pipelining. There is a race with
953  * Negotiate and NTLM when the client sends a second request on an
954  * connection before the authenticate challenge is sent. With
955  * pipelining OFF, the client may fail to authenticate, but squid's
956  * state will be preserved.
957  */
958  if (Config.pipeline_max_prefetch > 0) {
959  Auth::SchemeConfig *nego = Auth::SchemeConfig::Find("Negotiate");
961  if ((nego && nego->active()) || (ntlm && ntlm->active())) {
962  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
964  }
965  }
966 
967  for (auto &authSchemes : Auth::TheConfig.schemeLists) {
968  authSchemes.expand();
969  if (authSchemes.authConfigs.empty()) {
970  debugs(3, DBG_CRITICAL, "auth_schemes: at least one scheme name is required; got: " << authSchemes.rawSchemes);
971  self_destruct();
972  }
973  }
974 #endif
975 }
976 
983 void
984 parse_obsolete(const char *name)
985 {
986  // Directives which have been radically changed rather than removed
987  if (!strcmp(name, "url_rewrite_concurrency")) {
988  int cval;
989  parse_int(&cval);
990  debugs(3, DBG_CRITICAL, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
992  }
993 
994  if (!strcmp(name, "log_access")) {
995  self_destruct();
996  return;
997  }
998 
999  if (!strcmp(name, "log_icap")) {
1000  self_destruct();
1001  return;
1002  }
1003 
1004  if (!strcmp(name, "ignore_ims_on_miss")) {
1005  // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1006  // than the 2.7 directive. We need to parse and invert the configured value.
1007  int temp = 0;
1008  parse_onoff(&temp);
1010  }
1011 
1012  if (!strncmp(name, "sslproxy_", 9)) {
1013  // the replacement directive tls_outgoing_options uses options instead of whole-line input
1014  SBuf tmp;
1015  if (!strcmp(name, "sslproxy_cafile"))
1016  tmp.append("cafile=");
1017  else if (!strcmp(name, "sslproxy_capath"))
1018  tmp.append("capath=");
1019  else if (!strcmp(name, "sslproxy_cipher"))
1020  tmp.append("cipher=");
1021  else if (!strcmp(name, "sslproxy_client_certificate"))
1022  tmp.append("cert=");
1023  else if (!strcmp(name, "sslproxy_client_key"))
1024  tmp.append("key=");
1025  else if (!strcmp(name, "sslproxy_flags"))
1026  tmp.append("flags=");
1027  else if (!strcmp(name, "sslproxy_options"))
1028  tmp.append("options=");
1029  else if (!strcmp(name, "sslproxy_version"))
1030  tmp.append("version=");
1031  else {
1032  debugs(3, DBG_CRITICAL, "ERROR: unknown directive: " << name);
1033  self_destruct();
1034  return;
1035  }
1036 
1037  // add the value as unquoted-string because the old values did not support whitespace
1038  const char *token = ConfigParser::NextQuotedOrToEol();
1039  tmp.append(token, strlen(token));
1041  }
1042 }
1043 
1044 /* Parse a time specification from the config file. Store the
1045  * result in 'tptr', after converting it to 'units' */
1046 static time_msec_t
1047 parseTimeLine(const char *units, bool allowMsec, bool expectMoreArguments = false)
1048 {
1049  time_msec_t u = parseTimeUnits(units, allowMsec);
1050  if (u == 0) {
1051  self_destruct();
1052  return 0;
1053  }
1054 
1055  char *token = ConfigParser::NextToken();
1056  if (!token) {
1057  self_destruct();
1058  return 0;
1059  }
1060 
1061  double d = xatof(token);
1062 
1063  time_msec_t m = u; /* default to 'units' if none specified */
1064 
1065  if (d) {
1066  if ((token = ConfigParser::PeekAtToken()) && (m = parseTimeUnits(token, allowMsec))) {
1067  (void)ConfigParser::NextToken();
1068 
1069  } else if (!expectMoreArguments) {
1070  self_destruct();
1071  return 0;
1072 
1073  } else {
1074  token = NULL; // show default units if dying below
1075  debugs(3, DBG_CRITICAL, "WARNING: No units on '" << config_input_line << "', assuming " << d << " " << units);
1076  }
1077  } else
1078  token = NULL; // show default units if dying below.
1079 
1080  const auto result = static_cast<time_msec_t>(m * d);
1081 
1082  if (static_cast<double>(result) * 2 != m * d * 2) {
1083  debugs(3, DBG_CRITICAL, "FATAL: Invalid value '" <<
1084  d << " " << (token ? token : units) << ": integer overflow (time_msec_t).");
1085  self_destruct();
1086  }
1087  return result;
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 auto action = Acl::Answer(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 Acl::Answer &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 Acl::Answer &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  Tolower(p->host);
2143  p->name = xstrdup(host_str);
2144  p->type = parseNeighborType(token);
2145 
2146  if (p->type == PEER_MULTICAST) {
2147  p->options.no_digest = true;
2148  p->options.no_netdb_exchange = true;
2149  }
2150 
2151  p->http_port = GetTcpService();
2152 
2153  if (!p->http_port) {
2154  delete p;
2155  self_destruct();
2156  return;
2157  }
2158 
2159  p->icp.port = GetUdpService();
2160 
2161  while ((token = ConfigParser::NextToken())) {
2162  if (!strcmp(token, "proxy-only")) {
2163  p->options.proxy_only = true;
2164  } else if (!strcmp(token, "no-query")) {
2165  p->options.no_query = true;
2166  } else if (!strcmp(token, "background-ping")) {
2167  p->options.background_ping = true;
2168  } else if (!strcmp(token, "no-digest")) {
2169  p->options.no_digest = true;
2170  } else if (!strcmp(token, "no-tproxy")) {
2171  p->options.no_tproxy = true;
2172  } else if (!strcmp(token, "multicast-responder")) {
2173  p->options.mcast_responder = true;
2174 #if PEER_MULTICAST_SIBLINGS
2175  } else if (!strcmp(token, "multicast-siblings")) {
2176  p->options.mcast_siblings = true;
2177 #endif
2178  } else if (!strncmp(token, "weight=", 7)) {
2179  p->weight = xatoi(token + 7);
2180  } else if (!strncmp(token, "basetime=", 9)) {
2181  p->basetime = xatoi(token + 9);
2182  } else if (!strcmp(token, "closest-only")) {
2183  p->options.closest_only = true;
2184  } else if (!strncmp(token, "ttl=", 4)) {
2185  p->mcast.ttl = xatoi(token + 4);
2186 
2187  if (p->mcast.ttl < 0)
2188  p->mcast.ttl = 0;
2189 
2190  if (p->mcast.ttl > 128)
2191  p->mcast.ttl = 128;
2192  } else if (!strcmp(token, "default")) {
2193  p->options.default_parent = true;
2194  } else if (!strcmp(token, "round-robin")) {
2195  p->options.roundrobin = true;
2196  } else if (!strcmp(token, "weighted-round-robin")) {
2197  p->options.weighted_roundrobin = true;
2198 #if USE_HTCP
2199  } else if (!strcmp(token, "htcp")) {
2200  p->options.htcp = true;
2201  } else if (!strncmp(token, "htcp=", 5) || !strncmp(token, "htcp-", 5)) {
2202  /* Note: The htcp- form is deprecated, replaced by htcp= */
2203  p->options.htcp = true;
2204  char *tmp = xstrdup(token+5);
2205  char *mode, *nextmode;
2206  for (mode = nextmode = tmp; mode; mode = nextmode) {
2207  nextmode = strchr(mode, ',');
2208  if (nextmode) {
2209  *nextmode = '\0';
2210  ++nextmode;
2211  }
2212  if (!strcmp(mode, "no-clr")) {
2213  if (p->options.htcp_only_clr)
2214  fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2215  p->options.htcp_no_clr = true;
2216  } else if (!strcmp(mode, "no-purge-clr")) {
2217  p->options.htcp_no_purge_clr = true;
2218  } else if (!strcmp(mode, "only-clr")) {
2219  if (p->options.htcp_no_clr)
2220  fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2221  p->options.htcp_only_clr = true;
2222  } else if (!strcmp(mode, "forward-clr")) {
2223  p->options.htcp_forward_clr = true;
2224  } else if (!strcmp(mode, "oldsquid")) {
2225  p->options.htcp_oldsquid = true;
2226  } else {
2227  fatalf("invalid HTCP mode '%s'", mode);
2228  }
2229  }
2230  safe_free(tmp);
2231 #endif
2232  } else if (!strcmp(token, "no-netdb-exchange")) {
2233  p->options.no_netdb_exchange = true;
2234 
2235  } else if (!strcmp(token, "carp")) {
2236  if (p->type != PEER_PARENT)
2237  fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
2238 
2239  p->options.carp = true;
2240  } else if (!strncmp(token, "carp-key=", 9)) {
2241  if (p->options.carp != true)
2242  fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port);
2243  p->options.carp_key.set = true;
2244  char *nextkey=token+strlen("carp-key="), *key=nextkey;
2245  for (; key; key = nextkey) {
2246  nextkey=strchr(key,',');
2247  if (nextkey) ++nextkey; // skip the comma, any
2248  if (0==strncmp(key,"scheme",6)) {
2249  p->options.carp_key.scheme = true;
2250  } else if (0==strncmp(key,"host",4)) {
2251  p->options.carp_key.host = true;
2252  } else if (0==strncmp(key,"port",4)) {
2253  p->options.carp_key.port = true;
2254  } else if (0==strncmp(key,"path",4)) {
2255  p->options.carp_key.path = true;
2256  } else if (0==strncmp(key,"params",6)) {
2257  p->options.carp_key.params = true;
2258  } else {
2259  fatalf("invalid carp-key '%s'",key);
2260  }
2261  }
2262  } else if (!strcmp(token, "userhash")) {
2263 #if USE_AUTH
2264  if (p->type != PEER_PARENT)
2265  fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port);
2266 
2267  p->options.userhash = true;
2268 #else
2269  fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port);
2270 #endif
2271  } else if (!strcmp(token, "sourcehash")) {
2272  if (p->type != PEER_PARENT)
2273  fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port);
2274 
2275  p->options.sourcehash = true;
2276 
2277  } else if (!strcmp(token, "no-delay")) {
2278 #if USE_DELAY_POOLS
2279  p->options.no_delay = true;
2280 #else
2281  debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2282 #endif
2283  } else if (!strncmp(token, "login=", 6)) {
2284  p->login = xstrdup(token + 6);
2285  rfc1738_unescape(p->login);
2286  } else if (!strcmp(token, "auth-no-keytab")) {
2287  p->options.auth_no_keytab = 1;
2288  } else if (!strncmp(token, "connect-timeout=", 16)) {
2289  p->connect_timeout_raw = xatoi(token + 16);
2290  } else if (!strncmp(token, "connect-fail-limit=", 19)) {
2291  p->connect_fail_limit = xatoi(token + 19);
2292 #if USE_CACHE_DIGESTS
2293  } else if (!strncmp(token, "digest-url=", 11)) {
2294  p->digest_url = xstrdup(token + 11);
2295 #endif
2296 
2297  } else if (!strcmp(token, "allow-miss")) {
2298  p->options.allow_miss = true;
2299  } else if (!strncmp(token, "max-conn=", 9)) {
2300  p->max_conn = xatoi(token + 9);
2301  } else if (!strncmp(token, "standby=", 8)) {
2302  p->standby.limit = xatoi(token + 8);
2303  } else if (!strcmp(token, "originserver")) {
2304  p->options.originserver = true;
2305  } else if (!strncmp(token, "name=", 5)) {
2306  safe_free(p->name);
2307 
2308  if (token[5])
2309  p->name = xstrdup(token + 5);
2310  } else if (!strncmp(token, "forceddomain=", 13)) {
2311  safe_free(p->domain);
2312  if (token[13])
2313  p->domain = xstrdup(token + 13);
2314 
2315  } else if (strncmp(token, "ssl", 3) == 0) {
2316 #if !USE_OPENSSL
2317  debugs(0, DBG_CRITICAL, "WARNING: cache_peer option '" << token << "' requires --with-openssl");
2318 #else
2319  p->secure.parse(token+3);
2320 #endif
2321  } else if (strncmp(token, "tls-", 4) == 0) {
2322  p->secure.parse(token+4);
2323  } else if (strncmp(token, "tls", 3) == 0) {
2324  p->secure.parse(token+3);
2325  } else if (strcmp(token, "front-end-https") == 0) {
2326  p->front_end_https = 1;
2327  } else if (strcmp(token, "front-end-https=on") == 0) {
2328  p->front_end_https = 1;
2329  } else if (strcmp(token, "front-end-https=auto") == 0) {
2330  p->front_end_https = 2;
2331  } else if (strcmp(token, "connection-auth=off") == 0) {
2332  p->connection_auth = 0;
2333  } else if (strcmp(token, "connection-auth") == 0) {
2334  p->connection_auth = 1;
2335  } else if (strcmp(token, "connection-auth=on") == 0) {
2336  p->connection_auth = 1;
2337  } else if (strcmp(token, "connection-auth=auto") == 0) {
2338  p->connection_auth = 2;
2339  } else if (token[0] == '#') {
2340  // start of a text comment. stop reading this line.
2341  break;
2342  } else {
2343  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Ignoring unknown cache_peer option '" << token << "'");
2344  }
2345  }
2346 
2347  if (peerFindByName(p->name))
2348  fatalf("ERROR: cache_peer %s specified twice\n", p->name);
2349 
2350  if (p->max_conn > 0 && p->max_conn < p->standby.limit)
2351  fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p->host, p->max_conn, p->standby.limit);
2352 
2353  if (p->weight < 1)
2354  p->weight = 1;
2355 
2356  if (p->connect_fail_limit < 1)
2357  p->connect_fail_limit = 10;
2358 
2359 #if USE_CACHE_DIGESTS
2360  if (!p->options.no_digest)
2361  peerDigestCreate(p);
2362 #endif
2363 
2364  if (p->secure.encryptTransport)
2365  p->secure.parseOptions();
2366 
2367  p->index = ++Config.npeers;
2368 
2369  while (*head != NULL)
2370  head = &(*head)->next;
2371 
2372  *head = p;
2373 
2374  peerClearRRStart();
2375 }
2376 
2377 static void
2379 {
2380  delete *P;
2381  *P = NULL;
2382  Config.npeers = 0;
2383 }
2384 
2385 static void
2386 dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list)
2387 {
2388  while (list) {
2389  if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
2390  storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
2391  else
2392  storeAppendPrintf(entry, "%s %s", name, list->passwd);
2393 
2394  for (auto w : list->actions)
2395  entry->appendf(" " SQUIDSBUFPH, SQUIDSBUFPRINT(w));
2396 
2397  storeAppendPrintf(entry, "\n");
2398  list = list->next;
2399  }
2400 }
2401 
2402 static void
2404 {
2405  char *passwd = nullptr;
2406  parse_string(&passwd);
2407 
2409  p->passwd = passwd;
2410 
2411  while (char *token = ConfigParser::NextQuotedToken())
2412  p->actions.push_back(SBuf(token));
2413 
2415  for (P = head; *P; P = &(*P)->next) {
2416  /*
2417  * See if any of the actions from this line already have a
2418  * password from previous lines. The password checking
2419  * routines in cache_manager.c take the the password from
2420  * the first Mgr::ActionPasswordList that contains the
2421  * requested action. Thus, we should warn users who might
2422  * think they can have two passwords for the same action.
2423  */
2424  for (const auto &w : (*P)->actions) {
2425  for (const auto &u : p->actions) {
2426  if (w != u)
2427  continue;
2428 
2429  debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u << "' (line " << config_lineno << ") already has a password");
2430  }
2431  }
2432  }
2433 
2434  *P = p;
2435 }
2436 
2437 static void
2439 {
2440  delete *head;
2441  *head = nullptr;
2442 }
2443 
2444 static void
2445 dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var)
2446 {
2447  while (var != NULL) {
2448  storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
2449 
2450  for (const auto &aclName: var->acl_list)
2451  storeAppendPrintf(entry, " " SQUIDSBUFPH, SQUIDSBUFPRINT(aclName));
2452 
2453  storeAppendPrintf(entry, "\n");
2454 
2455  var = var->next;
2456  }
2457 }
2458 
2459 static void
2461 {
2462  aclParseDenyInfoLine(var);
2463 }
2464 
2465 void
2467 {
2468  delete *list;
2469  *list = nullptr;
2470 }
2471 
2472 static void
2474 {
2475  char *host = ConfigParser::NextToken();
2476  if (!host) {
2477  self_destruct();
2478  return;
2479  }
2480 
2481  CachePeer *p = peerFindByName(host);
2482  if (!p) {
2483  debugs(15, DBG_CRITICAL, "ERROR: " << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2484  return;
2485  }
2486 
2487  std::string directive = "peer_access ";
2488  directive += host;
2489  aclParseAccessLine(directive.c_str(), LegacyParser, &p->access);
2490 }
2491 
2492 static void
2494 {
2495  char *host = ConfigParser::NextToken();
2496  if (!host) {
2497  self_destruct();
2498  return;
2499  }
2500 
2501  char *type = ConfigParser::NextToken();
2502  if (!type) {
2503  self_destruct();
2504  return;
2505  }
2506 
2507  char *domain = nullptr;
2508  while ((domain = ConfigParser::NextToken())) {
2509  CachePeer *p = peerFindByName(host);
2510  if (!p) {
2511  debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2512  return;
2513  }
2514 
2515  auto *l = static_cast<NeighborTypeDomainList *>(xcalloc(1, sizeof(NeighborTypeDomainList)));
2516  l->type = parseNeighborType(type);
2517  l->domain = xstrdup(domain);
2518 
2519  NeighborTypeDomainList **L = nullptr;
2520  for (L = &(p->typelist); *L; L = &((*L)->next));
2521  *L = l;
2522  }
2523 }
2524 
2525 static void
2526 dump_int(StoreEntry * entry, const char *name, int var)
2527 {
2528  storeAppendPrintf(entry, "%s %d\n", name, var);
2529 }
2530 
2531 void
2532 parse_int(int *var)
2533 {
2534  int i;
2535  i = GetInteger();
2536  *var = i;
2537 }
2538 
2539 static void
2540 free_int(int *var)
2541 {
2542  *var = 0;
2543 }
2544 
2545 static void
2546 dump_int64_t(StoreEntry * entry, const char *name, int64_t var)
2547 {
2548  storeAppendPrintf(entry, "%s %" PRId64 "\n", name, var);
2549 }
2550 
2551 void
2552 parse_int64_t(int64_t *var)
2553 {
2554  int64_t i;
2555  i = GetInteger64();
2556  *var = i;
2557 }
2558 
2559 static void
2560 free_int64_t(int64_t *var)
2561 {
2562  *var = 0;
2563 }
2564 
2565 static void
2566 dump_onoff(StoreEntry * entry, const char *name, int var)
2567 {
2568  storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
2569 }
2570 
2571 void
2572 parse_onoff(int *var)
2573 {
2574  char *token = ConfigParser::NextToken();
2575  if (!token) {
2576  self_destruct();
2577  return;
2578  }
2579 
2580  if (!strcmp(token, "on")) {
2581  *var = 1;
2582  } else if (!strcmp(token, "enable")) {
2583  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2584  *var = 1;
2585  } else if (!strcmp(token, "off")) {
2586  *var = 0;
2587  } else if (!strcmp(token, "disable")) {
2588  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2589  *var = 0;
2590  } else {
2591  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2592  self_destruct();
2593  }
2594 }
2595 
2596 #define free_onoff free_int
2597 
2598 static void
2599 dump_tristate(StoreEntry * entry, const char *name, int var)
2600 {
2601  const char *state;
2602 
2603  if (var > 0)
2604  state = "on";
2605  else if (var < 0)
2606  state = "warn";
2607  else
2608  state = "off";
2609 
2610  storeAppendPrintf(entry, "%s %s\n", name, state);
2611 }
2612 
2613 static void
2615 {
2616  char *token = ConfigParser::NextToken();
2617  if (!token) {
2618  self_destruct();
2619  return;
2620  }
2621 
2622  if (!strcmp(token, "on")) {
2623  *var = 1;
2624  } else if (!strcmp(token, "enable")) {
2625  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2626  *var = 1;
2627  } else if (!strcmp(token, "warn")) {
2628  *var = -1;
2629  } else if (!strcmp(token, "off")) {
2630  *var = 0;
2631  } else if (!strcmp(token, "disable")) {
2632  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2633  *var = 0;
2634  } else {
2635  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2636  self_destruct();
2637  }
2638 }
2639 
2640 #define free_tristate free_int
2641 
2642 void
2644 {
2645  char *token = ConfigParser::PeekAtToken();
2646  if (!token) {
2647  self_destruct();
2648  return;
2649  }
2650 
2651  if (!strcmp(token, "on")) {
2652  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2653  *var = 1;
2654  //pop the token
2655  (void)ConfigParser::NextToken();
2656  } else if (!strcmp(token, "off")) {
2657  debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2658  *var = 0;
2659  //pop the token
2660  (void)ConfigParser::NextToken();
2661  } else
2662  parse_int(var);
2663 }
2664 
2665 #define free_pipelinePrefetch free_int
2666 #define dump_pipelinePrefetch dump_int
2667 
2668 static void
2669 dump_refreshpattern(StoreEntry * entry, const char *name, RefreshPattern * head)
2670 {
2671  while (head != NULL) {
2672  storeAppendPrintf(entry, "%s%s %s %d %d%% %d",
2673  name,
2674  head->pattern.flags&REG_ICASE ? " -i" : null_string,
2675  head->pattern.c_str(),
2676  (int) head->min / 60,
2677  (int) (100.0 * head->pct + 0.5),
2678  (int) head->max / 60);
2679 
2680  if (head->max_stale >= 0)
2681  storeAppendPrintf(entry, " max-stale=%d", head->max_stale);
2682 
2683  if (head->flags.refresh_ims)
2684  storeAppendPrintf(entry, " refresh-ims");
2685 
2686  if (head->flags.store_stale)
2687  storeAppendPrintf(entry, " store-stale");
2688 
2689 #if USE_HTTP_VIOLATIONS
2690 
2691  if (head->flags.override_expire)
2692  storeAppendPrintf(entry, " override-expire");
2693 
2694  if (head->flags.override_lastmod)
2695  storeAppendPrintf(entry, " override-lastmod");
2696 
2697  if (head->flags.reload_into_ims)
2698  storeAppendPrintf(entry, " reload-into-ims");
2699 
2700  if (head->flags.ignore_reload)
2701  storeAppendPrintf(entry, " ignore-reload");
2702 
2703  if (head->flags.ignore_no_store)
2704  storeAppendPrintf(entry, " ignore-no-store");
2705 
2706  if (head->flags.ignore_private)
2707  storeAppendPrintf(entry, " ignore-private");
2708 #endif
2709 
2710  storeAppendPrintf(entry, "\n");
2711 
2712  head = head->next;
2713  }
2714 }
2715 
2716 static void
2718 {
2719  char *token;
2720  char *pattern;
2721  time_t min = 0;
2722  double pct = 0.0;
2723  time_t max = 0;
2724  int refresh_ims = 0;
2725  int store_stale = 0;
2726  int max_stale = -1;
2727 
2728 #if USE_HTTP_VIOLATIONS
2729 
2730  int override_expire = 0;
2731  int override_lastmod = 0;
2732  int reload_into_ims = 0;
2733  int ignore_reload = 0;
2734  int ignore_no_store = 0;
2735  int ignore_private = 0;
2736 #endif
2737 
2738  int i;
2739  RefreshPattern *t;
2740  regex_t comp;
2741  int errcode;
2742  int flags = REG_EXTENDED | REG_NOSUB;
2743 
2744  if ((token = ConfigParser::RegexPattern()) != NULL) {
2745 
2746  if (strcmp(token, "-i") == 0) {
2747  flags |= REG_ICASE;
2748  token = ConfigParser::RegexPattern();
2749  } else if (strcmp(token, "+i") == 0) {
2750  flags &= ~REG_ICASE;
2751  token = ConfigParser::RegexPattern();
2752  }
2753 
2754  }
2755 
2756  if (token == NULL) {
2757  debugs(3, DBG_CRITICAL, "FATAL: refresh_pattern missing the regex pattern parameter");
2758  self_destruct();
2759  return;
2760  }
2761 
2762  pattern = xstrdup(token);
2763 
2764  i = GetInteger(); /* token: min */
2765 
2766  /* catch negative and insanely huge values close to 32-bit wrap */
2767  if (i < 0) {
2768  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2769  i = 0;
2770  }
2771  if (i > 60*24*365) {
2772  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2773  i = 60*24*365;
2774  }
2775 
2776  min = (time_t) (i * 60); /* convert minutes to seconds */
2777 
2778  pct = GetPercentage(false); /* token: pct . with no limit on size */
2779 
2780  i = GetInteger(); /* token: max */
2781 
2782  /* catch negative and insanely huge values close to 32-bit wrap */
2783  if (i < 0) {
2784  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2785  i = 0;
2786  }
2787  if (i > 60*24*365) {
2788  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2789  i = 60*24*365;
2790  }
2791 
2792  max = (time_t) (i * 60); /* convert minutes to seconds */
2793 
2794  /* Options */
2795  while ((token = ConfigParser::NextToken()) != NULL) {
2796  if (!strcmp(token, "refresh-ims")) {
2797  refresh_ims = 1;
2798  } else if (!strcmp(token, "store-stale")) {
2799  store_stale = 1;
2800  } else if (!strncmp(token, "max-stale=", 10)) {
2801  max_stale = xatoi(token + 10);
2802 
2803 #if USE_HTTP_VIOLATIONS
2804 
2805  } else if (!strcmp(token, "override-expire"))
2806  override_expire = 1;
2807  else if (!strcmp(token, "override-lastmod"))
2808  override_lastmod = 1;
2809  else if (!strcmp(token, "ignore-no-store"))
2810  ignore_no_store = 1;
2811  else if (!strcmp(token, "ignore-private"))
2812  ignore_private = 1;
2813  else if (!strcmp(token, "reload-into-ims")) {
2814  reload_into_ims = 1;
2816  /* tell client_side.c that this is used */
2817  } else if (!strcmp(token, "ignore-reload")) {
2818  ignore_reload = 1;
2820  /* tell client_side.c that this is used */
2821 #endif
2822 
2823  } else if (!strcmp(token, "ignore-no-cache") ||
2824  !strcmp(token, "ignore-must-revalidate") ||
2825  !strcmp(token, "ignore-auth")
2826  ) {
2827  debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token << "' is obsolete. Remove it.");
2828  } else
2829  debugs(22, DBG_CRITICAL, "refreshAddToList: Unknown option '" << pattern << "': " << token);
2830  }
2831 
2832  if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
2833  char errbuf[256];
2834  regerror(errcode, &comp, errbuf, sizeof errbuf);
2835  debugs(22, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2836  debugs(22, DBG_CRITICAL, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
2837  xfree(pattern);
2838  return;
2839  }
2840 
2841  pct = pct < 0.0 ? 0.0 : pct;
2842  max = max < 0 ? 0 : max;
2843  t = new RefreshPattern(pattern, flags);
2844  t->pattern.regex = comp;
2845  t->min = min;
2846  t->pct = pct;
2847  t->max = max;
2848 
2849  if (refresh_ims)
2850  t->flags.refresh_ims = true;
2851 
2852  if (store_stale)
2853  t->flags.store_stale = true;
2854 
2855  t->max_stale = max_stale;
2856 
2857 #if USE_HTTP_VIOLATIONS
2858 
2859  if (override_expire)
2860  t->flags.override_expire = true;
2861 
2862  if (override_lastmod)
2863  t->flags.override_lastmod = true;
2864 
2865  if (reload_into_ims)
2866  t->flags.reload_into_ims = true;
2867 
2868  if (ignore_reload)
2869  t->flags.ignore_reload = true;
2870 
2871  if (ignore_no_store)
2872  t->flags.ignore_no_store = true;
2873 
2874  if (ignore_private)
2875  t->flags.ignore_private = true;
2876 #endif
2877 
2878  t->next = NULL;
2879 
2880  while (*head)
2881  head = &(*head)->next;
2882 
2883  *head = t;
2884 
2885  xfree(pattern);
2886 }
2887 
2888 static void
2890 {
2891  delete *head;
2892  *head = nullptr;
2893 
2894 #if USE_HTTP_VIOLATIONS
2896 
2897 #endif
2898 }
2899 
2900 static void
2901 dump_string(StoreEntry * entry, const char *name, char *var)
2902 {
2903  if (var != NULL)
2904  storeAppendPrintf(entry, "%s %s\n", name, var);
2905 }
2906 
2907 static void
2908 parse_string(char **var)
2909 {
2910  safe_free(*var);
2911 
2912  char *token = ConfigParser::NextToken();
2913  if (!token) {
2914  self_destruct();
2915  return;
2916  }
2917 
2918  *var = xstrdup(token);
2919 }
2920 
2921 static void
2922 free_string(char **var)
2923 {
2924  safe_free(*var);
2925 }
2926 
2927 void
2928 parse_eol(char *volatile *var)
2929 {
2930  if (!var) {
2931  self_destruct();
2932  return;
2933  }
2934 
2935  unsigned char *token = (unsigned char *) ConfigParser::NextQuotedOrToEol();
2936  safe_free(*var);
2937 
2938  if (!token) {
2939  self_destruct();
2940  return;
2941  }
2942 
2943  while (*token && xisspace(*token))
2944  ++token;
2945 
2946  if (!*token) {
2947  self_destruct();
2948  return;
2949  }
2950 
2951  *var = xstrdup((char *) token);
2952 }
2953 
2954 #define dump_eol dump_string
2955 #define free_eol free_string
2956 
2957 static void
2959 {
2960  safe_free(*var);
2961 
2962  char *token = ConfigParser::NextQuotedToken();
2963  if (!token) {
2964  self_destruct();
2965  return;
2966  }
2967 
2968  *var = xstrdup(token);
2969 }
2970 
2971 #define dump_TokenOrQuotedString dump_string
2972 #define free_TokenOrQuotedString free_string
2973 
2974 static void
2975 dump_time_t(StoreEntry * entry, const char *name, time_t var)
2976 {
2977  storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
2978 }
2979 
2980 void
2981 parse_time_t(time_t * var)
2982 {
2983  time_msec_t tval = parseTimeLine(T_SECOND_STR, false);
2984  *var = static_cast<time_t>(tval/1000);
2985 }
2986 
2987 static void
2988 free_time_t(time_t * var)
2989 {
2990  *var = 0;
2991 }
2992 
2993 static void
2994 dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
2995 {
2996  if (var % 1000)
2997  storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
2998  else
2999  storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
3000 }
3001 
3002 void
3004 {
3005  *var = parseTimeLine(T_SECOND_STR, true);
3006 }
3007 
3008 static void
3010 {
3011  *var = 0;
3012 }
3013 
3014 #if UNUSED_CODE
3015 static void
3016 dump_size_t(StoreEntry * entry, const char *name, size_t var)
3017 {
3018  storeAppendPrintf(entry, "%s %d\n", name, (int) var);
3019 }
3020 #endif
3021 
3022 static void
3023 dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
3024 {
3025  storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3026 }
3027 
3028 static void
3029 dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var)
3030 {
3031  storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3032 }
3033 
3034 #if UNUSED_CODE
3035 static void
3036 dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
3037 {
3038  storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
3039 }
3040 #endif
3041 
3042 static void
3043 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
3044 {
3045  storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
3046 }
3047 
3048 static void
3049 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
3050 {
3051  storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
3052 }
3053 
3054 #if UNUSED_CODE
3055 static void
3056 parse_size_t(size_t * var)
3057 {
3058  int i;
3059  i = GetInteger();
3060  *var = (size_t) i;
3061 }
3062 #endif
3063 
3064 static void
3065 parse_b_size_t(size_t * var)
3066 {
3068 }
3069 
3070 static void
3071 parse_b_ssize_t(ssize_t * var)
3072 {
3074 }
3075 
3076 #if UNUSED_CODE
3077 static void
3078 parse_kb_size_t(size_t * var)
3079 {
3081 }
3082 #endif
3083 
3084 static void
3085 parse_b_int64_t(int64_t * var)
3086 {
3088 }
3089 
3090 static void
3091 parse_kb_int64_t(int64_t * var)
3092 {
3094 }
3095 
3096 static void
3097 free_size_t(size_t * var)
3098 {
3099  *var = 0;
3100 }
3101 
3102 static void
3103 free_ssize_t(ssize_t * var)
3104 {
3105  *var = 0;
3106 }
3107 
3108 static void
3109 free_b_int64_t(int64_t * var)
3110 {
3111  *var = 0;
3112 }
3113 
3114 #define free_b_size_t free_size_t
3115 #define free_b_ssize_t free_ssize_t
3116 #define free_kb_size_t free_size_t
3117 #define free_mb_size_t free_size_t
3118 #define free_gb_size_t free_size_t
3119 #define free_kb_int64_t free_b_int64_t
3120 
3121 static void
3122 dump_u_short(StoreEntry * entry, const char *name, unsigned short var)
3123 {
3124  storeAppendPrintf(entry, "%s %d\n", name, var);
3125 }
3126 
3127 static void
3128 free_u_short(unsigned short * u)
3129 {
3130  *u = 0;
3131 }
3132 
3133 static void
3134 parse_u_short(unsigned short * var)
3135 {
3137 }
3138 
3139 void
3140 ConfigParser::ParseUShort(unsigned short *var)
3141 {
3142  *var = GetShort();
3143 }
3144 
3145 void
3147 {
3148  int i = GetInteger();
3149 
3150  if (0 == i)
3151  *var = false;
3152  else if (1 == i)
3153  *var = true;
3154  else
3155  self_destruct();
3156 }
3157 
3158 static void
3159 dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
3160 {
3161  while (list != NULL) {
3162  storeAppendPrintf(entry, "%s %s\n", name, list->key);
3163  list = list->next;
3164  }
3165 }
3166 
3167 void
3169 {
3170  parse_wordlist(list);
3171 }
3172 
3173 void
3175 {
3176  char *token;
3177  while ((token = ConfigParser::NextQuotedToken()))
3178  wordlistAdd(list, token);
3179 }
3180 
3181 #if 0 /* now unused */
3182 static int
3183 check_null_wordlist(wordlist * w)
3184 {
3185  return w == NULL;
3186 }
3187 #endif
3188 
3189 static int
3191 {
3192  return a == NULL;
3193 }
3194 
3195 #define free_wordlist wordlistDestroy
3196 
3197 #define free_uri_whitespace free_int
3198 
3199 static void
3201 {
3202  char *token = ConfigParser::NextToken();
3203  if (!token) {
3204  self_destruct();
3205  return;
3206  }
3207 
3208  if (!strcmp(token, "strip"))
3209  *var = URI_WHITESPACE_STRIP;
3210  else if (!strcmp(token, "deny"))
3211  *var = URI_WHITESPACE_DENY;
3212  else if (!strcmp(token, "allow"))
3213  *var = URI_WHITESPACE_ALLOW;
3214  else if (!strcmp(token, "encode"))
3215  *var = URI_WHITESPACE_ENCODE;
3216  else if (!strcmp(token, "chop"))
3217  *var = URI_WHITESPACE_CHOP;
3218  else {
3219  debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3220  self_destruct();
3221  }
3222 }
3223 
3224 static void
3225 dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
3226 {
3227  const char *s;
3228 
3229  if (var == URI_WHITESPACE_ALLOW)
3230  s = "allow";
3231  else if (var == URI_WHITESPACE_ENCODE)
3232  s = "encode";
3233  else if (var == URI_WHITESPACE_CHOP)
3234  s = "chop";
3235  else if (var == URI_WHITESPACE_DENY)
3236  s = "deny";
3237  else
3238  s = "strip";
3239 
3240  storeAppendPrintf(entry, "%s %s\n", name, s);
3241 }
3242 
3243 static void
3245 {
3246  if (!*settings)
3247  return;
3248 
3249  free_string(&(*settings)->type);
3250 
3251  free_wordlist(&(*settings)->args);
3252 
3253  delete *settings;
3254 
3255  *settings = NULL;
3256 }
3257 
3258 static void
3260 {
3261  if (*settings)
3262  free_removalpolicy(settings);
3263 
3264  *settings = new RemovalPolicySettings;
3265 
3266  parse_string(&(*settings)->type);
3267 
3268  parse_wordlist(&(*settings)->args);
3269 }
3270 
3271 static void
3272 dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
3273 {
3274  wordlist *args;
3275  storeAppendPrintf(entry, "%s %s", name, settings->type);
3276  args = settings->args;
3277 
3278  while (args) {
3279  storeAppendPrintf(entry, " %s", args->key);
3280  args = args->next;
3281  }
3282 
3283  storeAppendPrintf(entry, "\n");
3284 }
3285 
3286 inline void
3288 {}
3289 
3290 static void
3292 {
3293  int value = 0;
3294  parse_onoff(&value);
3295  option->configure(value > 0);
3296 }
3297 
3298 static void
3299 dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
3300 {
3301  if (option.configured())
3302  dump_onoff(entry, name, option ? 1 : 0);
3303 }
3304 
3305 static void
3307 {}
3308 
3309 static void
3311 {
3312  char *token = ConfigParser::NextToken();
3313  if (!token) {
3314  self_destruct();
3315  return;
3316  }
3317 
3318  if (strcmp(token, "always") == 0) {
3321  } else if (strcmp(token, "disk") == 0) {
3324  } else if (strncmp(token, "net", 3) == 0) {
3327  } else if (strcmp(token, "never") == 0) {
3330  } else {
3331  debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3332  self_destruct();
3333  }
3334 }
3335 
3336 static void
3337 dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &)
3338 {
3339  storeAppendPrintf(entry, "%s ", name);
3341  storeAppendPrintf(entry, "always");
3343  storeAppendPrintf(entry, "disk");
3345  storeAppendPrintf(entry, "network");
3347  storeAppendPrintf(entry, "none");
3348  storeAppendPrintf(entry, "\n");
3349 }
3350 
3351 #include "cf_parser.cci"
3352 
3353 peer_t
3354 parseNeighborType(const char *s)
3355 {
3356  if (!strcmp(s, "parent"))
3357  return PEER_PARENT;
3358 
3359  if (!strcmp(s, "neighbor"))
3360  return PEER_SIBLING;
3361 
3362  if (!strcmp(s, "neighbour"))
3363  return PEER_SIBLING;
3364 
3365  if (!strcmp(s, "sibling"))
3366  return PEER_SIBLING;
3367 
3368  if (!strcmp(s, "multicast"))
3369  return PEER_MULTICAST;
3370 
3371  debugs(15, DBG_CRITICAL, "WARNING: Unknown neighbor type: " << s);
3372 
3373  return PEER_SIBLING;
3374 }
3375 
3376 #if USE_WCCPv2
3377 static void
3379 {
3380  char *token;
3381  Ip::Address_list *s;
3382  Ip::Address ipa;
3383 
3384  while ((token = ConfigParser::NextToken())) {
3385  if (GetHostWithPort(token, &ipa)) {
3386 
3387  while (*head)
3388  head = &(*head)->next;
3389 
3390  s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s)));
3391  s->s = ipa;
3392 
3393  *head = s;
3394  } else {
3395  self_destruct();
3396  return;
3397  }
3398  }
3399 }
3400 
3401 static void
3402 dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s)
3403 {
3404  char ntoabuf[MAX_IPSTRLEN];
3405 
3406  while (s) {
3407  storeAppendPrintf(e, "%s %s\n",
3408  n,
3409  s->s.toStr(ntoabuf,MAX_IPSTRLEN));
3410  s = s->next;
3411  }
3412 }
3413 
3414 static void
3416 {
3417  if (*head) delete *head;
3418  *head = NULL;
3419 }
3420 
3421 #if CURRENTLY_UNUSED
3422 /* This code was previously used by http_port. Left as it really should
3423  * be used by icp_port and htcp_port
3424  */
3425 static int
3426 check_null_IpAddress_list(const Ip::Address_list * s)
3427 {
3428  return NULL == s;
3429 }
3430 
3431 #endif /* CURRENTLY_UNUSED */
3432 #endif /* USE_WCCPv2 */
3433 
3434 static void
3436 {
3437  char *host = NULL;
3438  unsigned short port = 0;
3439  char *t = NULL;
3440  char *junk = NULL;
3441 
3442  s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3443  s->name = xstrdup(token);
3444  s->connection_auth_disabled = false;
3445 
3446  const SBuf &portType = AnyP::UriScheme(s->transport.protocol).image();
3447 
3448  if (*token == '[') {
3449  /* [ipv6]:port */
3450  host = token + 1;
3451  t = strchr(host, ']');
3452  if (!t) {
3453  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing ']' on IPv6 address: " << token);
3454  self_destruct();
3455  return;
3456  }
3457  *t = '\0';
3458  ++t;
3459  if (*t != ':') {
3460  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port in: " << token);
3461  self_destruct();
3462  return;
3463  }
3464  if (!Ip::EnableIpv6) {
3465  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: IPv6 is not available.");
3466  self_destruct();
3467  return;
3468  }
3469  port = xatos(t + 1);
3470  } else if ((t = strchr(token, ':'))) {
3471  /* host:port */
3472  /* ipv4:port */
3473  host = token;
3474  *t = '\0';
3475  port = xatos(t + 1);
3476 
3477  } else if (strtol(token, &junk, 10) && !*junk) {
3478  port = xatos(token);
3479  debugs(3, 3, portType << "_port: found Listen on Port: " << port);
3480  } else {
3481  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port: " << token);
3482  self_destruct();
3483  return;
3484  }
3485 
3486  if (port == 0 && host != NULL) {
3487  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: Port cannot be 0: " << token);
3488  self_destruct();
3489  return;
3490  }
3491 
3492  if (NULL == host) {
3493  s->s.setAnyAddr();
3494  s->s.port(port);
3495  if (!Ip::EnableIpv6)
3496  s->s.setIPv4();
3497  debugs(3, 3, portType << "_port: found Listen on wildcard address: *:" << s->s.port());
3498  } else if ( (s->s = host) ) { /* check/parse numeric IPA */
3499  s->s.port(port);
3500  if (!Ip::EnableIpv6)
3501  s->s.setIPv4();
3502  debugs(3, 3, portType << "_port: Listen on Host/IP: " << host << " --> " << s->s);
3503  } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
3504  /* do not use ipcache */
3505  s->defaultsite = xstrdup(host);
3506  s->s.port(port);
3507  if (!Ip::EnableIpv6)
3508  s->s.setIPv4();
3509  debugs(3, 3, portType << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
3510  } else {
3511  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: failed to resolve Host/IP: " << host);
3512  self_destruct();
3513  }
3514 }
3515 
3519 static AnyP::ProtocolVersion
3521 {
3522  // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3523  // and RFC 2616 requires us to upgrade 1.0 to 1.1
3524  if (value.cmp("HTTP") == 0 || value.cmp("HTTP/1.1") == 0)
3525  return Http::ProtocolVersion(1,1);
3526 
3527  if (value.cmp("HTTPS") == 0 || value.cmp("HTTPS/1.1") == 0)
3529 
3530  if (value.cmp("FTP") == 0)
3531  return Ftp::ProtocolVersion();
3532 
3533  fatalf("%s directive does not support protocol=" SQUIDSBUFPH "\n", cfg_directive, SQUIDSBUFPRINT(value));
3534  return AnyP::ProtocolVersion(); // not reached
3535 }
3536 
3537 static void
3539 {
3540  /* modes first */
3541 
3542  if (strcmp(token, "accel") == 0) {
3543  if (s->flags.isIntercepted()) {
3544  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3545  self_destruct();
3546  return;
3547  }
3548  s->flags.accelSurrogate = true;
3549  s->vhost = true;
3550  } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
3551  if (s->flags.accelSurrogate || s->flags.tproxyIntercept) {
3552  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3553  self_destruct();
3554  return;
3555  }
3556  s->flags.natIntercept = true;
3558  /* Log information regarding the port modes under interception. */
3559  debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
3560  debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
3561  } else if (strcmp(token, "tproxy") == 0) {
3562  if (s->flags.natIntercept || s->flags.accelSurrogate) {
3563  debugs(3,DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3564  self_destruct();
3565  return;
3566  }
3567  s->flags.tproxyIntercept = true;
3569  /* Log information regarding the port modes under transparency. */
3570  debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (TPROXY enabled)");
3571 
3572  if (s->flags.proxySurrogate) {
3573  debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)");
3574  }
3575 
3576  if (!Ip::Interceptor.ProbeForTproxy(s->s)) {
3577  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY support in the system does not work.");
3578  self_destruct();
3579  return;
3580  }
3581 
3582  } else if (strcmp(token, "require-proxy-header") == 0) {
3583  s->flags.proxySurrogate = true;
3584  if (s->flags.tproxyIntercept) {
3585  // receiving is still permitted, so we do not unset the TPROXY flag
3586  // spoofing access control override takes care of the spoof disable later
3587  debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)");
3588  }
3589 
3590  } else if (strncmp(token, "defaultsite=", 12) == 0) {
3591  if (!s->flags.accelSurrogate) {
3592  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": defaultsite option requires Acceleration mode flag.");
3593  self_destruct();
3594  return;
3595  }
3596  safe_free(s->defaultsite);
3597  s->defaultsite = xstrdup(token + 12);
3598  } else if (strcmp(token, "vhost") == 0) {
3599  if (!s->flags.accelSurrogate) {
3600  debugs(3, DBG_CRITICAL, "WARNING: " << cfg_directive << ": vhost option is deprecated. Use 'accel' mode flag instead.");
3601  }
3602  s->flags.accelSurrogate = true;
3603  s->vhost = true;
3604  } else if (strcmp(token, "no-vhost") == 0) {
3605  if (!s->flags.accelSurrogate) {
3606  debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": no-vhost option requires Acceleration mode flag.");
3607  }
3608  s->vhost = false;
3609  } else if (strcmp(token, "vport") == 0) {
3610  if (!s->flags.accelSurrogate) {
3611  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag.");
3612  self_destruct();
3613  return;
3614  }
3615  s->vport = -1;
3616  } else if (strncmp(token, "vport=", 6) == 0) {
3617  if (!s->flags.accelSurrogate) {
3618  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag.");
3619  self_destruct();
3620  return;
3621  }
3622  s->vport = xatos(token + 6);
3623  } else if (strncmp(token, "protocol=", 9) == 0) {
3624  if (!s->flags.accelSurrogate) {
3625  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": protocol option requires Acceleration mode flag.");
3626  self_destruct();
3627  return;
3628  }
3629  s->transport = parsePortProtocol(ToUpper(SBuf(token + 9)));
3630  } else if (strcmp(token, "allow-direct") == 0) {
3631  if (!s->flags.accelSurrogate) {
3632  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": allow-direct option requires Acceleration mode flag.");
3633  self_destruct();
3634  return;
3635  }
3636  s->allow_direct = true;
3637  } else if (strcmp(token, "act-as-origin") == 0) {
3638  if (!s->flags.accelSurrogate) {
3639  debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": act-as-origin option requires Acceleration mode flag.");
3640  } else
3641  s->actAsOrigin = true;
3642  } else if (strcmp(token, "ignore-cc") == 0) {
3643 #if !USE_HTTP_VIOLATIONS
3644  if (!s->flags.accelSurrogate) {
3645  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": ignore-cc option requires Acceleration mode flag.");
3646  self_destruct();
3647  return;
3648  }
3649 #endif
3650  s->ignore_cc = true;
3651  } else if (strncmp(token, "name=", 5) == 0) {
3652  safe_free(s->name);
3653  s->name = xstrdup(token + 5);
3654  } else if (strcmp(token, "no-connection-auth") == 0) {
3655  s->connection_auth_disabled = true;
3656  } else if (strcmp(token, "connection-auth=off") == 0) {
3657  s->connection_auth_disabled = true;
3658  } else if (strcmp(token, "connection-auth") == 0) {
3659  s->connection_auth_disabled = false;
3660  } else if (strcmp(token, "connection-auth=on") == 0) {
3661  s->connection_auth_disabled = false;
3662  } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
3663  if (!strcmp(token + 23, "off"))
3664  s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3665  else if (!strcmp(token + 23, "transparent"))
3666  s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
3667  else if (!strcmp(token + 23, "always"))
3668  s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
3669  else {
3670  self_destruct();
3671  return;
3672  }
3673  } else if (strcmp(token, "ipv4") == 0) {
3674  if ( !s->s.setIPv4() ) {
3675  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": IPv6 addresses cannot be used as IPv4-Only. " << s->s );
3676  self_destruct();
3677  return;
3678  }
3679  } else if (strcmp(token, "tcpkeepalive") == 0) {
3680  s->tcp_keepalive.enabled = true;
3681  } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
3682  char *t = token + 13;
3683  s->tcp_keepalive.enabled = true;
3684  s->tcp_keepalive.idle = xatoui(t,',');
3685  t = strchr(t, ',');
3686  if (t) {
3687  ++t;
3688  s->tcp_keepalive.interval = xatoui(t,',');
3689  t = strchr(t, ',');
3690  }
3691  if (t) {
3692  ++t;
3693  s->tcp_keepalive.timeout = xatoui(t);
3694  }
3695 #if USE_OPENSSL
3696  } else if (strcmp(token, "sslBump") == 0) {
3697  debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token << "' is deprecated " <<
3698  "in " << cfg_directive << ". Use 'ssl-bump' instead.");
3699  s->flags.tunnelSslBumping = true;
3700  } else if (strcmp(token, "ssl-bump") == 0) {
3701  s->flags.tunnelSslBumping = true;
3702  } else if (strncmp(token, "cert=", 5) == 0) {
3703  s->secure.parse(token);
3704  } else if (strncmp(token, "key=", 4) == 0) {
3705  s->secure.parse(token);
3706  } else if (strncmp(token, "version=", 8) == 0) {
3707  debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token << "' is deprecated " <<
3708  "in " << cfg_directive << ". Use 'options=' instead.");
3709  s->secure.parse(token);
3710  } else if (strncmp(token, "options=", 8) == 0) {
3711  s->secure.parse(token);
3712  } else if (strncmp(token, "cipher=", 7) == 0) {
3713  s->secure.parse(token);
3714  } else if (strncmp(token, "clientca=", 9) == 0) {
3715  s->secure.parse(token);
3716  } else if (strncmp(token, "cafile=", 7) == 0) {
3717  debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token << "' is deprecated " <<
3718  "in " << cfg_directive << ". Use 'tls-cafile=' instead.");
3719  s->secure.parse(token);
3720  } else if (strncmp(token, "capath=", 7) == 0) {
3721  s->secure.parse(token);
3722  } else if (strncmp(token, "crlfile=", 8) == 0) {
3723  s->secure.parse(token);
3724  } else if (strncmp(token, "dhparams=", 9) == 0) {
3725  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: '" << token << "' is deprecated " <<
3726  "in " << cfg_directive << ". Use 'tls-dh=' instead.");
3727  s->secure.parse(token);
3728  } else if (strncmp(token, "sslflags=", 9) == 0) {
3729  // NP: deprecation warnings output by secure.parse() when relevant
3730  s->secure.parse(token+3);
3731  } else if (strncmp(token, "sslcontext=", 11) == 0) {
3732  // NP: deprecation warnings output by secure.parse() when relevant
3733  s->secure.parse(token+3);
3734  } else if (strncmp(token, "generate-host-certificates", 26) == 0) {
3735  s->secure.parse(token);
3736 #endif
3737  } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) {
3738  s->secure.parse(token);
3739  } else if (strncmp(token, "tls-", 4) == 0) {
3740  s->secure.parse(token+4);
3741  } else if (strcmp(token, "ftp-track-dirs") == 0) {
3742  s->ftp_track_dirs = true;
3743  } else {
3744  debugs(3, DBG_CRITICAL, "FATAL: Unknown " << cfg_directive << " option '" << token << "'.");
3745  self_destruct();
3746  }
3747 }
3748 
3749 void
3750 add_http_port(char *portspec)
3751 {
3753  s->transport = parsePortProtocol(SBuf("HTTP"));
3754  parsePortSpecification(s, portspec);
3755  // we may need to merge better if the above returns a list with clones
3756  assert(s->next == NULL);
3757  s->next = HttpPortList;
3758  HttpPortList = s;
3759 }
3760 
3761 static void
3762 parsePortCfg(AnyP::PortCfgPointer *head, const char *optionName)
3763 {
3764  SBuf protoName;
3765  if (strcmp(optionName, "http_port") == 0 ||
3766  strcmp(optionName, "ascii_port") == 0)
3767  protoName = "HTTP";
3768  else if (strcmp(optionName, "https_port") == 0)
3769  protoName = "HTTPS";
3770  else if (strcmp(optionName, "ftp_port") == 0)
3771  protoName = "FTP";
3772  if (protoName.isEmpty()) {
3773  self_destruct();
3774  return;
3775  }
3776 
3777  char *token = ConfigParser::NextToken();
3778 
3779  if (!token) {
3780  self_destruct();
3781  return;
3782  }
3783 
3785  s->transport = parsePortProtocol(protoName); // default; protocol=... overwrites
3786  parsePortSpecification(s, token);
3787 
3788  /* parse options ... */
3789  while ((token = ConfigParser::NextToken())) {
3790  parse_port_option(s, token);
3791  }
3792 
3793  s->secure.syncCaFiles();
3794 
3795  if (s->transport.protocol == AnyP::PROTO_HTTPS) {
3796  s->secure.encryptTransport = true;
3797 #if USE_OPENSSL
3798  /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3799  const bool hijacked = s->flags.isIntercepted();
3800  if (s->flags.tunnelSslBumping && !hijacked) {
3801  debugs(3, DBG_CRITICAL, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3802  self_destruct();
3803  return;
3804  }
3805  if (hijacked && !s->flags.tunnelSslBumping) {
3806  debugs(3, DBG_CRITICAL, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3807  self_destruct();
3808  return;
3809  }
3810 #endif
3811  if (s->flags.proxySurrogate) {
3812  debugs(3,DBG_CRITICAL, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3813  self_destruct();
3814  return;
3815  }
3816  } else if (protoName.cmp("FTP") == 0) {
3817  /* ftp_port does not support ssl-bump */
3818  if (s->flags.tunnelSslBumping) {
3819  debugs(3, DBG_CRITICAL, "FATAL: ssl-bump is not supported for ftp_port.");
3820  self_destruct();
3821  return;
3822  }
3823  if (s->flags.proxySurrogate) {
3824  // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3825  debugs(3,DBG_CRITICAL, "FATAL: require-proxy-header option is not supported on ftp_port.");
3826  self_destruct();
3827  return;
3828  }
3829  }
3830 
3831  if (s->secure.encryptTransport) {
3832  if (s->secure.certs.empty()) {
3833  debugs(3, DBG_CRITICAL, "FATAL: " << AnyP::UriScheme(s->transport.protocol) << "_port requires a cert= parameter");
3834  self_destruct();
3835  return;
3836  }
3837  s->secure.parseOptions();
3838  }
3839 
3840  // *_port line should now be fully valid so we can clone it if necessary
3841  if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.isAnyAddr()) {
3842  // clone the port options from *s to *(s->next)
3843  s->next = s->clone();
3844  s->next->s.setIPv4();
3845  debugs(3, 3, AnyP::UriScheme(s->transport.protocol).image() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
3846  }
3847 
3848  while (*head != NULL)
3849  head = &((*head)->next);
3850 
3851  *head = s;
3852 }
3853 
3854 static void
3856 {
3857  char buf[MAX_IPSTRLEN];
3858 
3859  storeAppendPrintf(e, "%s %s",
3860  n,
3861  s->s.toUrl(buf,MAX_IPSTRLEN));
3862 
3863  // MODES and specific sub-options.
3864  if (s->flags.natIntercept)
3865  storeAppendPrintf(e, " intercept");
3866 
3867  else if (s->flags.tproxyIntercept)
3868  storeAppendPrintf(e, " tproxy");
3869 
3870  else if (s->flags.proxySurrogate)
3871  storeAppendPrintf(e, " require-proxy-header");
3872 
3873  else if (s->flags.accelSurrogate) {
3874  storeAppendPrintf(e, " accel");
3875 
3876  if (s->vhost)
3877  storeAppendPrintf(e, " vhost");
3878 
3879  if (s->vport < 0)
3880  storeAppendPrintf(e, " vport");
3881  else if (s->vport > 0)
3882  storeAppendPrintf(e, " vport=%d", s->vport);
3883 
3884  if (s->defaultsite)
3885  storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3886 
3887  // TODO: compare against prefix of 'n' instead of assuming http_port
3888  if (s->transport.protocol != AnyP::PROTO_HTTP)
3889  storeAppendPrintf(e, " protocol=%s", AnyP::ProtocolType_str[s->transport.protocol]);
3890 
3891  if (s->allow_direct)
3892  storeAppendPrintf(e, " allow-direct");
3893 
3894  if (s->ignore_cc)
3895  storeAppendPrintf(e, " ignore-cc");
3896 
3897  }
3898 
3899  // Generic independent options
3900 
3901  if (s->name)
3902  storeAppendPrintf(e, " name=%s", s->name);
3903 
3904 #if USE_HTTP_VIOLATIONS
3905  if (!s->flags.accelSurrogate && s->ignore_cc)
3906  storeAppendPrintf(e, " ignore-cc");
3907 #endif
3908 
3909  if (s->connection_auth_disabled)
3910  storeAppendPrintf(e, " connection-auth=off");
3911  else
3912  storeAppendPrintf(e, " connection-auth=on");
3913 
3914  if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3915  const char *pmtu;
3916 
3917  if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3918  pmtu = "always";
3919  else
3920  pmtu = "transparent";
3921 
3922  storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3923  }
3924 
3925  if (s->s.isAnyAddr() && !s->s.isIPv6())
3926  storeAppendPrintf(e, " ipv4");
3927 
3928  if (s->tcp_keepalive.enabled) {
3929  if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
3930  storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
3931  } else {
3932  storeAppendPrintf(e, " tcpkeepalive");
3933  }
3934  }
3935 
3936 #if USE_OPENSSL
3937  if (s->flags.tunnelSslBumping)
3938  storeAppendPrintf(e, " ssl-bump");
3939 #endif
3940 
3941  s->secure.dumpCfg(e, "tls-");
3942 }
3943 
3944 static void
3945 dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s)
3946 {
3947  for (AnyP::PortCfgPointer p = s; p != NULL; p = p->next) {
3948  dump_generic_port(e, n, p);
3949  storeAppendPrintf(e, "\n");
3950  }
3951 }
3952 
3953 void
3955 {
3956  free_all();
3957  Config.ssl_client.sslContext.reset();
3958 #if USE_OPENSSL
3960 #endif
3961 }
3962 
3963 void
3964 requirePathnameExists(const char *name, const char *path)
3965 {
3966 
3967  struct stat sb;
3968  char pathbuf[BUFSIZ];
3969  assert(path != NULL);
3970 
3971  if (Config.chroot_dir && (geteuid() == 0)) {
3972  snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3973  path = pathbuf;
3974  }
3975 
3976  if (stat(path, &sb) < 0) {
3977  int xerrno = errno;
3978  debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL: ":"ERROR: ") << name << " " << path << ": " << xstrerr(xerrno));
3979  // keep going to find more issues if we are only checking the config file with "-k parse"
3980  if (opt_parse_cfg_only)
3981  return;
3982  // this is fatal if it is found during startup or reconfigure
3983  if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
3984  fatalf("%s %s: %s", name, path, xstrerr(xerrno));
3985  }
3986 }
3987 
3988 #include "AccessLogEntry.h"
3989 
4010 static void
4012 {
4013  const char *filename = ConfigParser::NextToken();
4014  if (!filename) {
4015  self_destruct();
4016  return;
4017  }
4018 
4019  CustomLog *cl = (CustomLog *)xcalloc(1, sizeof(*cl));
4020 
4021  cl->filename = xstrdup(filename);
4022  // default buffer size and fatal settings
4023  cl->bufferSize = 8*MAX_URL;
4024  cl->fatal = true;
4025 
4026  if (strcmp(filename, "none") == 0) {
4028  aclParseAclList(LegacyParser, &cl->aclList, filename);
4029  while (*logs)
4030  logs = &(*logs)->next;
4031  *logs = cl;
4032  return;
4033  }
4034 
4036  cl->rotateCount = -1; // default: use global logfile_rotate setting.
4037 
4038  const char *token = ConfigParser::PeekAtToken();
4039  if (!token) { // style #1
4040  // no options to deal with
4041  } else if (!strchr(token, '=')) { // style #3
4042  // if logformat name is recognized,
4043  // pop the previewed token; Else it must be an ACL name
4044  if (setLogformat(cl, token, false))
4045  (void)ConfigParser::NextToken();
4046  } else { // style #4
4047  do {
4048  if (strncasecmp(token, "on-error=", 9) == 0) {
4049  if (strncasecmp(token+9, "die", 3) == 0) {
4050  cl->fatal = true;
4051  } else if (strncasecmp(token+9, "drop", 4) == 0) {
4052  cl->fatal = false;
4053  } else {
4054  debugs(3, DBG_CRITICAL, "Unknown value for on-error '" <<
4055  token << "' expected 'drop' or 'die'");
4056  xfree(cl->filename);
4057  xfree(cl);
4058  self_destruct();
4059  return;
4060  }
4061  } else if (strncasecmp(token, "buffer-size=", 12) == 0) {
4062  parseBytesOptionValue(&cl->bufferSize, B_BYTES_STR, token+12);
4063  } else if (strncasecmp(token, "rotate=", 7) == 0) {
4064  cl->rotateCount = xatoi(token + 7);
4065  } else if (strncasecmp(token, "logformat=", 10) == 0) {
4066  setLogformat(cl, token+10, true);
4067  } else if (!strchr(token, '=')) {
4068  // Do not pop the token; it must be an ACL name
4069  break; // done with name=value options, now to ACLs
4070  } else {
4071  debugs(3, DBG_CRITICAL, "Unknown access_log option " << token);
4072  xfree(cl->filename);
4073  xfree(cl);
4074  self_destruct();
4075  return;
4076  }
4077  // Pop the token, it was a valid "name=value" option
4078  (void)ConfigParser::NextToken();
4079  // Get next with preview ConfigParser::NextToken call.
4080  } while ((token = ConfigParser::PeekAtToken()) != NULL);
4081  }
4082 
4083  // set format if it has not been specified explicitly
4084  if (cl->type == Log::Format::CLF_UNKNOWN)
4085  setLogformat(cl, "squid", true);
4086 
4087  aclParseAclList(LegacyParser, &cl->aclList, cl->filename);
4088 
4089  while (*logs)
4090  logs = &(*logs)->next;
4091 
4092  *logs = cl;
4093 }
4094 
4097 static bool
4098 setLogformat(CustomLog *cl, const char *logdef_name, const bool dieWhenMissing)
4099 {
4100  assert(cl);
4101  assert(logdef_name);
4102 
4103  debugs(3, 9, "possible " << cl->filename << " logformat: " << logdef_name);
4104 
4105  if (cl->type != Log::Format::CLF_UNKNOWN) {
4106  debugs(3, DBG_CRITICAL, "FATAL: Second logformat name in one access_log: " <<
4107  logdef_name << " " << cl->type << " ? " << Log::Format::CLF_NONE);
4108  self_destruct();
4109  return false;
4110  }
4111 
4112  /* look for the definition pointer corresponding to this name */
4114 
4115  while (lf != NULL) {
4116  debugs(3, 9, "Comparing against '" << lf->name << "'");
4117 
4118  if (strcmp(lf->name, logdef_name) == 0)
4119  break;
4120 
4121  lf = lf->next;
4122  }
4123 
4124  if (lf != NULL) {
4126  cl->logFormat = lf;
4127  } else if (strcmp(logdef_name, "auto") == 0) {
4128  debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4130  } else if (strcmp(logdef_name, "squid") == 0) {
4132  } else if (strcmp(logdef_name, "common") == 0) {
4134  } else if (strcmp(logdef_name, "combined") == 0) {
4136 #if ICAP_CLIENT
4137  } else if (strcmp(logdef_name, "icap_squid") == 0) {
4139 #endif
4140  } else if (strcmp(logdef_name, "useragent") == 0) {
4142  } else if (strcmp(logdef_name, "referrer") == 0) {
4144  } else if (dieWhenMissing) {
4145  debugs(3, DBG_CRITICAL, "FATAL: Log format '" << logdef_name << "' is not defined");
4146  self_destruct();
4147  return false;
4148  } else {
4149  return false;
4150  }
4151 
4152  return true;
4153 }
4154 
4155 static int
4156 check_null_access_log(CustomLog *customlog_definitions)
4157 {
4158  return customlog_definitions == NULL;
4159 }
4160 
4161 static void
4162 dump_access_log(StoreEntry * entry, const char *name, CustomLog * logs)
4163 {
4164  CustomLog *log;
4165 
4166  for (log = logs; log; log = log->next) {
4167  storeAppendPrintf(entry, "%s ", name);
4168 
4169  switch (log->type) {
4170 
4172  storeAppendPrintf(entry, "%s logformat=%s", log->filename, log->logFormat->name);
4173  break;
4174 
4175  case Log::Format::CLF_NONE:
4176  storeAppendPrintf(entry, "logformat=none");
4177  break;
4178 
4180  // this is the default, no need to add to the dump
4181  //storeAppendPrintf(entry, "%s logformat=squid", log->filename);
4182  break;
4183 
4185  storeAppendPrintf(entry, "%s logformat=combined", log->filename);
4186  break;
4187 
4189  storeAppendPrintf(entry, "%s logformat=common", log->filename);
4190  break;
4191 
4192 #if ICAP_CLIENT
4194  storeAppendPrintf(entry, "%s logformat=icap_squid", log->filename);
4195  break;
4196 #endif
4198  storeAppendPrintf(entry, "%s logformat=useragent", log->filename);
4199  break;
4200 
4202  storeAppendPrintf(entry, "%s logformat=referrer", log->filename);
4203  break;
4204 
4206  break;
4207  }
4208 
4209  // default is on-error=die
4210  if (!log->fatal)
4211  storeAppendPrintf(entry, " on-error=drop");
4212 
4213  // default: 64KB
4214  if (log->bufferSize != 64*1024)
4215  storeAppendPrintf(entry, " buffer-size=%" PRIuSIZE, log->bufferSize);
4216 
4217  if (log->rotateCount >= 0)
4218  storeAppendPrintf(entry, " rotate=%d", log->rotateCount);
4219 
4220  if (log->aclList)
4221  dump_acl_list(entry, log->aclList);
4222 
4223  storeAppendPrintf(entry, "\n");
4224  }
4225 }
4226 
4227 static void
4229 {
4230  while (*definitions) {
4231  CustomLog *log = *definitions;
4232  *definitions = log->next;
4233 
4234  log->logFormat = NULL;
4236 
4237  if (log->aclList)
4238  aclDestroyAclList(&log->aclList);
4239 
4240  safe_free(log->filename);
4241 
4242  xfree(log);
4243  }
4244 }
4245 
4246 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4247 static bool
4249 parseNamedIntList(const char *data, const String &name, std::vector<int> &list)
4250 {
4251  if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) {
4252  data += name.size();
4253  if (*data == '=') {
4254  while (true) {
4255  ++data;
4256  int value = 0;
4257  if (!StringToInt(data, value, &data, 10))
4258  break;
4259  list.push_back(value);
4260  if (*data == '\0' || *data != ',')
4261  break;
4262  }
4263  }
4264  }
4265  return data && *data == '\0';
4266 }
4267 #endif
4268 
4269 static void
4270 parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4271 {
4272 #if !HAVE_CPU_AFFINITY
4273  debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " <<
4274  "support, do not set 'cpu_affinity_map'");
4275  self_destruct();
4276 
4277 #else /* HAVE_CPU_AFFINITY */
4278  if (!*cpuAffinityMap)
4279  *cpuAffinityMap = new CpuAffinityMap;
4280 
4281  const char *const pToken = ConfigParser::NextToken();
4282  const char *const cToken = ConfigParser::NextToken();
4283  std::vector<int> processes, cores;
4284  if (!parseNamedIntList(pToken, "process_numbers", processes)) {
4285  debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " <<
4286  "in 'cpu_affinity_map'");
4287  self_destruct();
4288  } else if (!parseNamedIntList(cToken, "cores", cores)) {
4289  debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " <<
4290  "'cpu_affinity_map'");
4291  self_destruct();
4292  } else if (!(*cpuAffinityMap)->add(processes, cores)) {
4293  debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " <<
4294  "process_numbers and cores lists differ in length or " <<
4295  "contain numbers <= 0");
4296  self_destruct();
4297  }
4298 #endif
4299 }
4300 
4301 static void
4302 dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap)
4303 {
4304  if (cpuAffinityMap) {
4305  storeAppendPrintf(entry, "%s process_numbers=", name);
4306  for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4307  storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4308  cpuAffinityMap->processes()[i]);
4309  }
4310  storeAppendPrintf(entry, " cores=");
4311  for (size_t i = 0; i < cpuAffinityMap->cores().size(); ++i) {
4312  storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4313  cpuAffinityMap->cores()[i]);
4314  }
4315  storeAppendPrintf(entry, "\n");
4316  }
4317 }
4318 
4319 static void
4320 free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4321 {
4322  delete *cpuAffinityMap;
4323  *cpuAffinityMap = NULL;
4324 }
4325 
4326 #if USE_ADAPTATION
4327 
4328 static void
4330 {
4332 }
4333 
4334 static void
4336 {
4338 }
4339 
4340 static void
4342 {
4343  Adaptation::Config::ParseAccess(LegacyParser);
4344 }
4345 #endif /* USE_ADAPTATION */
4346 
4347 #if ICAP_CLIENT
4348 
4349 static void
4351 {
4352  cfg->parseService();
4353 }
4354 
4355 static void
4357 {
4358  cfg->freeService();
4359 }
4360 
4361 static void
4362 dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
4363 {
4364  cfg.dumpService(entry, name);
4365 }
4366 
4367 static void
4369 {
4370  debugs(93, DBG_CRITICAL, "WARNING: 'icap_class' is deprecated. " <<
4371  "Use 'adaptation_service_set' instead");
4373 }
4374 
4375 static void
4377 {
4378  debugs(93, DBG_CRITICAL, "WARNING: 'icap_access' is deprecated. " <<
4379  "Use 'adaptation_access' instead");
4380  Adaptation::Config::ParseAccess(LegacyParser);
4381 }
4382 
4383 #endif
4384 
4385 #if USE_ECAP
4386 
4387 static void
4389 {
4390  cfg->parseService();
4391 }
4392 
4393 static void
4395 {
4396  cfg->freeService();
4397 }
4398 
4399 static void
4400 dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
4401 {
4402  cfg.dumpService(entry, name);
4403 }
4404 
4405 #endif /* USE_ECAP */
4406 
4407 #if ICAP_CLIENT
4409 {
4410  char *token;
4411  time_t d;
4412  time_t m;
4414 
4415  if ((token = ConfigParser::NextToken()) == NULL)
4416  return;
4417 
4418  if (strcmp(token,"in") != 0) {
4419  debugs(3, DBG_CRITICAL, "expecting 'in' on'" << config_input_line << "'");
4420  self_destruct();
4421  return;
4422  }
4423 
4424  if ((token = ConfigParser::NextToken()) == NULL) {
4425  self_destruct();
4426  return;
4427  }
4428 
4429  d = static_cast<time_t> (xatoi(token));
4430 
4431  m = static_cast<time_t> (1);
4432 
4433  if (0 == d)
4434  (void) 0;
4435  else if ((token = ConfigParser::NextToken()) == NULL) {
4436  debugs(3, DBG_CRITICAL, "No time-units on '" << config_input_line << "'");
4437  self_destruct();
4438  return;
4439  } else if ((m = parseTimeUnits(token, false)) == 0) {
4440  self_destruct();
4441  return;
4442  }
4443 
4444  cfg->oldest_service_failure = (m * d);
4445 }
4446 
4447 static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg)
4448 {
4449  storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit);
4450  if (cfg.oldest_service_failure > 0) {
4451  storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure);
4452  }
4453  storeAppendPrintf(entry, "\n");
4454 }
4455 
4457 {
4458  cfg->oldest_service_failure = 0;
4459  cfg->service_failure_limit = 0;
4460 }
4461 #endif
4462 
4463 #if USE_OPENSSL
4465 {
4466  char *al;
4468  if ((al = ConfigParser::NextToken()) == NULL) {
4469  xfree(ca);
4470  self_destruct();
4471  return;
4472  }
4473 
4474  const char *param;
4475  if ( char *s = strchr(al, '{')) {
4476  *s = '\0'; // terminate the al string
4477  ++s;
4478  param = s;
4479  s = strchr(s, '}');
4480  if (!s) {
4481  xfree(ca);
4482  self_destruct();
4483  return;
4484  }
4485  *s = '\0';
4486  } else
4487  param = NULL;
4488 
4489  if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidAfter]) == 0) {
4490  ca->alg = Ssl::algSetValidAfter;
4491  ca->param = xstrdup("on");
4492  } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidBefore]) == 0) {
4494  ca->param = xstrdup("on");
4495  } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetCommonName]) == 0) {
4496  ca->alg = Ssl::algSetCommonName;
4497  if (param) {
4498  if (strlen(param) > 64) {
4499  debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param << "} : using common name longer than 64 bytes is not supported");
4500  xfree(ca);
4501  self_destruct();
4502  return;
4503  }
4504  ca->param = xstrdup(param);
4505  }
4506  } else {
4507  debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al);
4508  xfree(ca);
4509  self_destruct();
4510  return;
4511  }
4512 
4513  aclParseAclList(LegacyParser, &ca->aclList, al);
4514 
4515  while (*cert_adapt)
4516  cert_adapt = &(*cert_adapt)->next;
4517 
4518  *cert_adapt = ca;
4519 }
4520 
4521 static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt)
4522 {
4523  for (sslproxy_cert_adapt *ca = cert_adapt; ca != NULL; ca = ca->next) {
4524  storeAppendPrintf(entry, "%s ", name);
4525  storeAppendPrintf(entry, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca->alg), ca->param);
4526  if (ca->aclList)
4527  dump_acl_list(entry, ca->aclList);
4528  storeAppendPrintf(entry, "\n");
4529  }
4530 }
4531 
4533 {
4534  while (*cert_adapt) {
4535  sslproxy_cert_adapt *ca = *cert_adapt;
4536  *cert_adapt = ca->next;
4537  safe_free(ca->param);
4538 
4539  if (ca->aclList)
4540  aclDestroyAclList(&ca->aclList);
4541 
4542  safe_free(ca);
4543  }
4544 }
4545 
4547 {
4548  char *al;
4550  if ((al = ConfigParser::NextToken()) == NULL) {
4551  xfree(cs);
4552  self_destruct();
4553  return;
4554  }
4555 
4556  if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignTrusted]) == 0)
4557  cs->alg = Ssl::algSignTrusted;
4558  else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignUntrusted]) == 0)
4559  cs->alg = Ssl::algSignUntrusted;
4560  else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignSelf]) == 0)
4561  cs->alg = Ssl::algSignSelf;
4562  else {
4563  debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al);
4564  xfree(cs);
4565  self_destruct();
4566  return;
4567  }
4568 
4569  aclParseAclList(LegacyParser, &cs->aclList, al);
4570 
4571  while (*cert_sign)
4572  cert_sign = &(*cert_sign)->next;
4573 
4574  *cert_sign = cs;
4575 }
4576 
4577 static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign)
4578 {
4579  sslproxy_cert_sign *cs;
4580  for (cs = cert_sign; cs != NULL; cs = cs->next) {
4581  storeAppendPrintf(entry, "%s ", name);
4582  storeAppendPrintf(entry, "%s ", Ssl::certSignAlgorithm(cs->alg));
4583  if (cs->aclList)
4584  dump_acl_list(entry, cs->aclList);
4585  storeAppendPrintf(entry, "\n");
4586  }
4587 }
4588 
4590 {
4591  while (*cert_sign) {
4592  sslproxy_cert_sign *cs = *cert_sign;
4593  *cert_sign = cs->next;
4594 
4595  if (cs->aclList)
4596  aclDestroyAclList(&cs->aclList);
4597 
4598  safe_free(cs);
4599  }
4600 }
4601 
4603 {
4604 public:
4606  /* RegisteredRunner API */
4607  virtual void finalizeConfig();
4608 };
4609 
4611 
4613 
4614 void
4616 {
4617  if (lastDeprecatedRule != Ssl::bumpEnd) {
4618  assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone);
4619  static char buf[1024];
4620  if (lastDeprecatedRule == Ssl::bumpClientFirst) {
4621  strcpy(buf, "ssl_bump deny all");
4622  debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated implicit "
4623  "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4624  "must not use implicit rules. Update your ssl_bump rules.");
4625  } else {
4626  strcpy(buf, "ssl_bump allow all");
4627  debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated implicit "
4628  "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4629  "inferior to the newer server-first bumping mode. New ssl_bump"
4630  " configurations must not use implicit rules. Update your ssl_bump rules.");
4631  }
4632  parse_line(buf);
4633  }
4634 }
4635 
4636 static void parse_sslproxy_ssl_bump(acl_access **ssl_bump)
4637 {
4638  typedef const char *BumpCfgStyle;
4639  BumpCfgStyle bcsNone = NULL;
4640  BumpCfgStyle bcsNew = "new client/server-first/none";
4641  BumpCfgStyle bcsOld = "deprecated allow/deny";
4642  static BumpCfgStyle bumpCfgStyleLast = bcsNone;
4643  BumpCfgStyle bumpCfgStyleNow = bcsNone;
4644  char *bm;
4645  if ((bm = ConfigParser::NextToken()) == NULL) {
4646  self_destruct();
4647  return;
4648  }
4649 
4650  // if this is the first rule proccessed
4651  if (*ssl_bump == NULL) {
4652  bumpCfgStyleLast = bcsNone;
4654  }
4655 
4657 
4658  if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpClientFirst]) == 0) {
4660  bumpCfgStyleNow = bcsNew;
4661  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpServerFirst]) == 0) {
4663  bumpCfgStyleNow = bcsNew;
4664  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpPeek]) == 0) {
4665  action.kind = Ssl::bumpPeek;
4666  bumpCfgStyleNow = bcsNew;
4667  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpStare]) == 0) {
4668  action.kind = Ssl::bumpStare;
4669  bumpCfgStyleNow = bcsNew;
4670  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpSplice]) == 0) {
4671  action.kind = Ssl::bumpSplice;
4672  bumpCfgStyleNow = bcsNew;
4673  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpBump]) == 0) {
4674  action.kind = Ssl::bumpBump;
4675  bumpCfgStyleNow = bcsNew;
4676  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpTerminate]) == 0) {
4677  action.kind = Ssl::bumpTerminate;
4678  bumpCfgStyleNow = bcsNew;
4679  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpNone]) == 0) {
4680  action.kind = Ssl::bumpNone;
4681  bumpCfgStyleNow = bcsNew;
4682  } else if (strcmp(bm, "allow") == 0) {
4683  debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated "
4684  "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4685  "is usually inferior to the newer server-first "
4686  "bumping mode. Update your ssl_bump rules.");
4688  bumpCfgStyleNow = bcsOld;
4690  } else if (strcmp(bm, "deny") == 0) {
4691  debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated "
4692  "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4693  "your ssl_bump rules.");
4694  action.kind = Ssl::bumpNone;
4695  bumpCfgStyleNow = bcsOld;
4697  } else {
4698  debugs(3, DBG_CRITICAL, "FATAL: unknown ssl_bump mode: " << bm);
4699  self_destruct();
4700  return;
4701  }
4702 
4703  if (bumpCfgStyleLast != bcsNone && bumpCfgStyleNow != bumpCfgStyleLast) {
4704  debugs(3, DBG_CRITICAL, "FATAL: do not mix " << bumpCfgStyleNow << " actions with " <<
4705  bumpCfgStyleLast << " actions. Update your ssl_bump rules.");
4706  self_destruct();
4707  return;
4708  }
4709 
4710  bumpCfgStyleLast = bumpCfgStyleNow;
4711 
4712  // empty rule OK
4713  ParseAclWithAction(ssl_bump, action, "ssl_bump");
4714 }
4715 
4716 static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump)
4717 {
4718  if (ssl_bump)
4719  dump_SBufList(entry, ssl_bump->treeDump(name, [](const Acl::Answer &action) {
4720  return Ssl::BumpModeStr.at(action.kind);
4721  }));
4722 }
4723 
4724 static void free_sslproxy_ssl_bump(acl_access **ssl_bump)
4725 {
4726  free_acl_access(ssl_bump);
4727 }
4728 
4729 #endif
4730 
4731 static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers)
4732 {
4733  if (!headers)
4734  return;
4735 
4736  for (HeaderWithAclList::iterator hwa = headers->begin(); hwa != headers->end(); ++hwa) {
4737  storeAppendPrintf(entry, "%s %s %s", name, hwa->fieldName.c_str(), hwa->fieldValue.c_str());
4738  if (hwa->aclList)
4739  dump_acl_list(entry, hwa->aclList);
4740  storeAppendPrintf(entry, "\n");
4741  }
4742 }
4743 
4745 {
4746  char *fn;
4747  if (!*headers) {
4748  *headers = new HeaderWithAclList;
4749  }
4750  if ((fn = ConfigParser::NextToken()) == NULL) {
4751  self_destruct();
4752  return;
4753  }
4754  HeaderWithAcl hwa;
4755  hwa.fieldName = fn;
4757  if (hwa.fieldId == Http::HdrType::BAD_HDR)
4759 
4760  Format::Format *nlf = new ::Format::Format("hdrWithAcl");
4764  hwa.fieldValue = buf.termedBuf();
4766  if (hwa.quoted) {
4767  if (!nlf->parse(hwa.fieldValue.c_str())) {
4768  self_destruct();
4769  return;
4770  }
4771  hwa.valueFormat = nlf;
4772  } else
4773  delete nlf;
4774  aclParseAclList(LegacyParser, &hwa.aclList, (hwa.fieldName + ':' + hwa.fieldValue).c_str());
4775  (*headers)->push_back(hwa);
4776 }
4777 
4779 {
4780  if (!(*header))
4781  return;
4782 
4783  for (HeaderWithAclList::iterator hwa = (*header)->begin(); hwa != (*header)->end(); ++hwa) {
4784  if (hwa->aclList)
4785  aclDestroyAclList(&hwa->aclList);
4786 
4787  if (hwa->valueFormat) {
4788  delete hwa->valueFormat;
4789  hwa->valueFormat = NULL;
4790  }
4791  }
4792  delete *header;
4793  *header = NULL;
4794 }
4795 
4796 static void parse_note(Notes *notes)
4797 {
4798  assert(notes);
4799  notes->parse(LegacyParser);
4800 }
4801 
4802 static void dump_note(StoreEntry *entry, const char *name, Notes &notes)
4803 {
4804  notes.dump(entry, name);
4805 }
4806 
4807 static void free_note(Notes *notes)
4808 {
4809  notes->clean();
4810 }
4811 
4812 static bool FtpEspvDeprecated = false;
4813 static void parse_ftp_epsv(acl_access **ftp_epsv)
4814 {
4815  Acl::Answer ftpEpsvDeprecatedAction;
4816  bool ftpEpsvIsDeprecatedRule = false;
4817 
4818  char *t = ConfigParser::PeekAtToken();
4819  if (!t) {
4820  self_destruct();
4821  return;
4822  }
4823 
4824  if (!strcmp(t, "off")) {
4825  (void)ConfigParser::NextToken();
4826  ftpEpsvIsDeprecatedRule = true;
4827  ftpEpsvDeprecatedAction = Acl::Answer(ACCESS_DENIED);
4828  } else if (!strcmp(t, "on")) {
4829  (void)ConfigParser::NextToken();
4830  ftpEpsvIsDeprecatedRule = true;
4831  ftpEpsvDeprecatedAction = Acl::Answer(ACCESS_ALLOWED);
4832  }
4833 
4834  // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4835  // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4836  // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4837  // then abort
4838  if ((!ftpEpsvIsDeprecatedRule && FtpEspvDeprecated) ||
4839  (ftpEpsvIsDeprecatedRule && !FtpEspvDeprecated && *ftp_epsv != NULL)) {
4840  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.");
4841  self_destruct();
4842  return;
4843  }
4844 
4845  if (ftpEpsvIsDeprecatedRule) {
4846  // overwrite previous ftp_epsv lines
4847  delete *ftp_epsv;
4848  *ftp_epsv = nullptr;
4849 
4850  if (ftpEpsvDeprecatedAction == Acl::Answer(ACCESS_DENIED)) {
4851  if (ACL *a = ACL::FindByName("all"))
4852  ParseAclWithAction(ftp_epsv, ftpEpsvDeprecatedAction, "ftp_epsv", a);
4853  else {
4854  self_destruct();
4855  return;
4856  }
4857  }
4858  FtpEspvDeprecated = true;
4859  } else {
4860  aclParseAccessLine(cfg_directive, LegacyParser, ftp_epsv);
4861  }
4862 }
4863 
4864 static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv)
4865 {
4866  if (ftp_epsv)
4867  dump_SBufList(entry, ftp_epsv->treeDump(name, Acl::AllowOrDeny));
4868 }
4869 
4870 static void free_ftp_epsv(acl_access **ftp_epsv)
4871 {
4872  free_acl_access(ftp_epsv);
4873  FtpEspvDeprecated = false;
4874 }
4875 
4876 static void
4878 {
4879  const auto tval = parseTimeLine(T_SECOND_STR, false, true);
4880  Config.Timeout.urlRewrite = static_cast<time_t>(tval/1000);
4881 
4882  char *key, *value;
4883  while(ConfigParser::NextKvPair(key, value)) {
4884  if (strcasecmp(key, "on_timeout") == 0) {
4885  if (strcasecmp(value, "bypass") == 0)
4886  config->action = toutActBypass;
4887  else if (strcasecmp(value, "fail") == 0)
4888  config->action = toutActFail;
4889  else if (strcasecmp(value, "retry") == 0)
4890  config->action = toutActRetry;
4891  else if (strcasecmp(value, "use_configured_response") == 0) {
4893  } else {
4894  debugs(3, DBG_CRITICAL, "FATAL: unsupported \"on_timeout\" action: " << value);
4895  self_destruct();
4896  return;
4897  }
4898  } else if (strcasecmp(key, "response") == 0) {
4899  config->response = xstrdup(value);
4900  } else {
4901  debugs(3, DBG_CRITICAL, "FATAL: unsupported option " << key);
4902  self_destruct();
4903  return;
4904  }
4905  }
4906 
4907  if (config->action == toutActUseConfiguredResponse && !config->response) {
4908  debugs(3, DBG_CRITICAL, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4909  self_destruct();
4910  }
4911 
4912  if (config->action != toutActUseConfiguredResponse && config->response) {
4913  debugs(3, DBG_CRITICAL, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4914  self_destruct();
4915  }
4916 }
4917 
4918 static void
4920 {
4921  const char *onTimedOutActions[] = {"bypass", "fail", "retry", "use_configured_response"};
4922  assert(config.action >= 0 && config.action <= toutActUseConfiguredResponse);
4923 
4924  dump_time_t(entry, name, Config.Timeout.urlRewrite);
4925  storeAppendPrintf(entry, " on_timeout=%s", onTimedOutActions[config.action]);
4926 
4927  if (config.response)
4928  storeAppendPrintf(entry, " response=\"%s\"", config.response);
4929 
4930  storeAppendPrintf(entry, "\n");
4931 }
4932 
4933 static void
4935 {
4937  config->action = 0;
4938  safe_free(config->response);
4939 }
4940 
4941 static void
4943 {
4944  int val = 0;
4945  parse_onoff(&val);
4946 
4947  // If quoted values is set to on then enable new strict mode parsing
4948  if (val) {
4950  ConfigParser::StrictMode = true;
4951  } else {
4953  ConfigParser::StrictMode = false;
4954  }
4955 }
4956 
4957 static void
4958 dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool)
4959 {
4960  int val = ConfigParser::RecognizeQuotedValues ? 1 : 0;
4961  dump_onoff(entry, name, val);
4962 }
4963 
4964 static void
4966 {
4968  ConfigParser::StrictMode = false;
4969 }
4970 
4971 static void
4973 {
4974  char *tm;
4975  if ((tm = ConfigParser::NextToken()) == NULL) {
4976  self_destruct();
4977  return;
4978  }
4979 
4981  if (strcmp(tm, "tunnel") == 0)
4982  action.kind = 1;
4983  else if (strcmp(tm, "respond") == 0)
4984  action.kind = 2;
4985  else {
4986  debugs(3, DBG_CRITICAL, "FATAL: unknown on_unsupported_protocol mode: " << tm);
4987  self_destruct();
4988  return;
4989  }
4990 
4991  // empty rule OK
4992  ParseAclWithAction(access, action, "on_unsupported_protocol");
4993 }
4994 
4995 static void
4996 dump_on_unsupported_protocol(StoreEntry *entry, const char *name, acl_access *access)
4997 {
4998  static const std::vector<const char *> onErrorTunnelMode = {
4999  "none",
5000  "tunnel",
5001  "respond"
5002  };
5003  if (access) {
5004  SBufList lines = access->treeDump(name, [](const Acl::Answer &action) {
5005  return onErrorTunnelMode.at(action.kind);
5006  });
5007  dump_SBufList(entry, lines);
5008  }
5009 }
5010 
5011 static void
5013 {
5014  free_acl_access(access);
5015 }
5016 
static void free_b_int64_t(int64_t *var)
Definition: cache_cf.cc:3109
#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:4394
bool mcast_responder
Definition: CachePeer.h:86
char const * rawBuf() const
Definition: SquidString.h:85
struct CachePeer::icp_ icp
unsigned short port
Definition: CachePeer.h:63
static void ParseBool(bool *var)
Definition: cache_cf.cc:3146
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:2908
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:4098
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:3310
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:280
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
static time_msec_t parseTimeLine(const char *units, bool allowMsec, bool expectMoreArguments=false)
Definition: cache_cf.cc:1047
SBuf TheKidName
current Squid process name (e.g., "squid-coord")
Definition: Kids.cc:19
static void parse_delay_pool_rates(DelayConfig *cfg)
Definition: cache_cf.cc:1672
int regcomp(regex_t *preg, const char *pattern, int cflags)
Definition: GnuRegex.c:4120
#define assert(EX)
Definition: assert.h:17
bool mcast_siblings
Definition: CachePeer.h:117
static void dump_access_log(StoreEntry *entry, const char *name, CustomLog *definitions)
Definition: cache_cf.cc:4162
char * chroot_dir
Definition: SquidConfig.h:480
struct SquidConfig::@122 ssl_client
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:2922
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:4341
char * foreignIntermediateCertsPath
Definition: SquidConfig.h:515
static int parseConfigFileOrThrow(const char *file_name)
Definition: cache_cf.cc:570
static bool FtpEspvDeprecated
Definition: cache_cf.cc:4812
static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
Definition: cache_cf.cc:4270
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
void StartTransparency()
Definition: Intercept.h:61
static void dump_int(StoreEntry *entry, const char *name, int var)
Definition: cache_cf.cc:2526
static unsigned short GetService(const char *proto)
Definition: cache_cf.cc:2086
void parse_time_t(time_t *var)
Definition: cache_cf.cc:2981
static void dump_onoff(StoreEntry *entry, const char *name, int var)
Definition: cache_cf.cc:2566
static void parse_YesNoNone(YesNoNone *option)
Definition: cache_cf.cc:3291
static void defaults_postscriptum(void)
static void free_time_msec(time_msec_t *var)
Definition: cache_cf.cc:3009
int cache_miss_revalidate
Definition: SquidConfig.h:322
SBuf image() const
Definition: UriScheme.h:50
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:4807
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:125
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:4156
void parse_eol(char *volatile *var)
Definition: cache_cf.cc:2928
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:4716
int type
Definition: errorpage.cc:152
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:92
static std::vector< StoreFileSystem * > const & FileSystems()
static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
Definition: cache_cf.cc:4532
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:310
virtual void append(char const *, int)
Appends a c-string to existing packed data.
Definition: store.cc:829
const char * null_string
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
char const * type() const
Definition: Disk.cc:230
static void parse_HeaderWithAclList(HeaderWithAclList **header)
Definition: cache_cf.cc:4744
::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:3065
char * effectiveUser
Definition: SquidConfig.h:189
void self_destruct(void)
Definition: cache_cf.cc:256
static void dump_kb_int64_t(StoreEntry *entry, const char *name, int64_t var)
Definition: cache_cf.cc:3049
struct SquidConfig::@105 Announce
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:2958
CachePeer * peers
Definition: SquidConfig.h:247
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:3003
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:3855
struct SquidConfig::@102 Log
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:3299
#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:3140
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:124
bool htcp_oldsquid
Definition: CachePeer.h:90
void parse_pipelinePrefetch(int *var)
Definition: cache_cf.cc:2643
bool encryptTransport
whether transport encryption (TLS/SSL) is to be used on connections to the peer
Definition: PeerOptions.h:144
static void free_ssize_t(ssize_t *var)
Definition: cache_cf.cc:3103
#define safe_free(x)
Definition: xalloc.h:73
void wordlistDestroy(wordlist **list)
destroy a wordlist
Definition: wordlist.cc:16
Address_list * next
Definition: Address.h:367
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:1160
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
static void parse_u_short(unsigned short *var)
Definition: cache_cf.cc:3134
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:2988
char * mimeTablePathname
Definition: SquidConfig.h:219
static void free_delay_pool_count(DelayConfig *cfg)
Definition: cache_cf.cc:1648
char * key
Definition: wordlist.h:33
bool isEmpty() const
Definition: SBuf.h:420
struct RefreshPattern::@94 flags
char * appendDomain
Definition: SquidConfig.h:215
static void free_IpAddress_list(Ip::Address_list **)
Definition: cache_cf.cc:3415
static void parse_delay_pool_count(DelayConfig *cfg)
Definition: cache_cf.cc:1660
void parse_onoff(int *var)
Definition: cache_cf.cc:2572
struct SquidConfig::@104 Accel
const char * CertAdaptAlgorithmStr[]
Definition: gadgets.cc:202
RegexPattern pattern
#define xisspace(x)
Definition: xis.h:17
static char * PeekAtToken()
#define DBG_CRITICAL
Definition: Debug.h:45
std::vector< Auth::SchemeConfig * > ConfigVector
Definition: forward.h:23
char * p
Definition: membanger.c:43
void OBJH(StoreEntry *)
Definition: forward.h:44
wordlist * redirect
Definition: SquidConfig.h:194
representation of a neighbor_type_domain configuration directive. A POD
#define DBG_PARSE_NOTE(x)
Definition: Debug.h:50
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured
Definition: PortCfg.cc:21
Format::Format * valueFormat
compiled HTTP header field value (no macros)
static const char *const B_MBYTES_STR
Definition: cache_cf.cc:150