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 allow_t &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 allow_t action = allow_t(ACCESS_ALLOWED, Auth::TheConfig.schemeLists.size() - 1);
1888  ParseAclWithAction(authSchemes, action, "auth_schemes");
1889 }
1890 
1891 static void
1893 {
1894  Auth::TheConfig.schemeLists.clear();
1895  free_acl_access(authSchemes);
1896 }
1897 
1898 static void
1899 dump_AuthSchemes(StoreEntry *entry, const char *name, acl_access *authSchemes)
1900 {
1901  if (authSchemes)
1902  dump_SBufList(entry, authSchemes->treeDump(name, [](const allow_t &action) {
1903  return Auth::TheConfig.schemeLists.at(action.kind).rawSchemes;
1904  }));
1905 }
1906 
1907 #endif /* USE_AUTH */
1908 
1909 static void
1910 ParseAclWithAction(acl_access **access, const allow_t &action, const char *desc, ACL *acl)
1911 {
1912  assert(access);
1913  SBuf name;
1914  if (!*access) {
1915  *access = new Acl::Tree;
1916  name.Printf("(%s rules)", desc);
1917  (*access)->context(name.c_str(), config_input_line);
1918  }
1919  Acl::AndNode *rule = new Acl::AndNode;
1920  name.Printf("(%s rule)", desc);
1921  rule->context(name.c_str(), config_input_line);
1922  acl ? rule->add(acl) : rule->lineParse();
1923  (*access)->add(rule, action);
1924 }
1925 
1926 /* TODO: just return the object, the # is irrelevant */
1927 static int
1929 {
1930  for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i)
1931  if (strcasecmp(type, StoreFileSystem::FileSystems().at(i)->type()) == 0)
1932  return (int)i;
1933 
1934  return (-1);
1935 }
1936 
1937 static void
1939 {
1940  char *type_str = ConfigParser::NextToken();
1941  if (!type_str) {
1942  self_destruct();
1943  return;
1944  }
1945 
1946  char *path_str = ConfigParser::NextToken();
1947  if (!path_str) {
1948  self_destruct();
1949  return;
1950  }
1951 
1952  int fs = find_fstype(type_str);
1953  if (fs < 0) {
1954  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: This proxy does not support the '" << type_str << "' cache type. Ignoring.");
1955  return;
1956  }
1957 
1958  /* reconfigure existing dir */
1959 
1960  RefCount<SwapDir> sd;
1961  for (int i = 0; i < swap->n_configured; ++i) {
1962  assert (swap->swapDirs[i].getRaw());
1963 
1964  if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) {
1965  /* this is specific to on-fs Stores. The right
1966  * way to handle this is probably to have a mapping
1967  * from paths to stores, and have on-fs stores
1968  * register with that, and lookip in that in their
1969  * own setup logic. RBC 20041225. TODO.
1970  */
1971 
1972  sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw());
1973 
1974  if (strcmp(sd->type(), StoreFileSystem::FileSystems().at(fs)->type()) != 0) {
1975  debugs(3, DBG_CRITICAL, "ERROR: Can't change type of existing cache_dir " <<
1976  sd->type() << " " << sd->path << " to " << type_str << ". Restart required");
1977  return;
1978  }
1979 
1980  sd->reconfigure();
1981  return;
1982  }
1983  }
1984 
1985  /* new cache_dir */
1986  if (swap->n_configured > 63) {
1987  /* 7 bits, signed */
1988  debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1989  debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many.");
1990  self_destruct();
1991  return;
1992  }
1993 
1994  allocate_new_swapdir(swap);
1995 
1996  swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().at(fs)->createSwapDir();
1997 
1998  sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw());
1999 
2000  /* parse the FS parameters and options */
2001  sd->parse(swap->n_configured, path_str);
2002 
2003  ++swap->n_configured;
2004 }
2005 
2006 static const char *
2008 {
2009  const char * result;
2010 
2011  switch (type) {
2012 
2013  case PEER_PARENT:
2014  result = "parent";
2015  break;
2016 
2017  case PEER_SIBLING:
2018  result = "sibling";
2019  break;
2020 
2021  case PEER_MULTICAST:
2022  result = "multicast";
2023  break;
2024 
2025  default:
2026  result = "unknown";
2027  break;
2028  }
2029 
2030  return result;
2031 }
2032 
2033 static void
2034 dump_peer(StoreEntry * entry, const char *name, CachePeer * p)
2035 {
2037  LOCAL_ARRAY(char, xname, 128);
2038 
2039  while (p != NULL) {
2040  storeAppendPrintf(entry, "%s %s %s %d %d name=%s",
2041  name,
2042  p->host,
2043  neighborTypeStr(p),
2044  p->http_port,
2045  p->icp.port,
2046  p->name);
2047  dump_peer_options(entry, p);
2048 
2049  if (p->access) {
2050  snprintf(xname, 128, "cache_peer_access %s", p->name);
2051  dump_acl_access(entry, xname, p->access);
2052  }
2053 
2054  for (t = p->typelist; t; t = t->next) {
2055  storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
2056  p->host,
2057  peer_type_str(t->type),
2058  t->domain);
2059  }
2060 
2061  p = p->next;
2062  }
2063 }
2064 
2069 static bool
2070 isUnsignedNumeric(const char *str, size_t len)
2071 {
2072  if (len < 1) return false;
2073 
2074  for (; len >0 && *str; ++str, --len) {
2075  if (! isdigit(*str))
2076  return false;
2077  }
2078  return true;
2079 }
2080 
2085 static unsigned short
2086 GetService(const char *proto)
2087 {
2088  struct servent *port = NULL;
2090  char *token = ConfigParser::NextToken();
2091  if (token == NULL) {
2092  self_destruct();
2093  return 0; /* NEVER REACHED */
2094  }
2096  if ( !isUnsignedNumeric(token, strlen(token)) )
2097  port = getservbyname(token, proto);
2098  if (port != NULL) {
2099  return ntohs((unsigned short)port->s_port);
2100  }
2102  return xatos(token);
2103 }
2104 
2109 inline unsigned short
2111 {
2112  return GetService("tcp");
2113 }
2114 
2119 inline unsigned short
2121 {
2122  return GetService("udp");
2123 }
2124 
2125 static void
2127 {
2128  char *host_str = ConfigParser::NextToken();
2129  if (!host_str) {
2130  self_destruct();
2131  return;
2132  }
2133 
2134  char *token = ConfigParser::NextToken();
2135  if (!token) {
2136  self_destruct();
2137  return;
2138  }
2139 
2140  CachePeer *p = new CachePeer;
2141  p->host = xstrdup(host_str);
2142  p->name = xstrdup(host_str);
2143  p->type = parseNeighborType(token);
2144 
2145  if (p->type == PEER_MULTICAST) {
2146  p->options.no_digest = true;
2147  p->options.no_netdb_exchange = true;
2148  }
2149 
2150  p->http_port = GetTcpService();
2151 
2152  if (!p->http_port) {
2153  delete p;
2154  self_destruct();
2155  return;
2156  }
2157 
2158  p->icp.port = GetUdpService();
2159 
2160  while ((token = ConfigParser::NextToken())) {
2161  if (!strcmp(token, "proxy-only")) {
2162  p->options.proxy_only = true;
2163  } else if (!strcmp(token, "no-query")) {
2164  p->options.no_query = true;
2165  } else if (!strcmp(token, "background-ping")) {
2166  p->options.background_ping = true;
2167  } else if (!strcmp(token, "no-digest")) {
2168  p->options.no_digest = true;
2169  } else if (!strcmp(token, "no-tproxy")) {
2170  p->options.no_tproxy = true;
2171  } else if (!strcmp(token, "multicast-responder")) {
2172  p->options.mcast_responder = true;
2173 #if PEER_MULTICAST_SIBLINGS
2174  } else if (!strcmp(token, "multicast-siblings")) {
2175  p->options.mcast_siblings = true;
2176 #endif
2177  } else if (!strncmp(token, "weight=", 7)) {
2178  p->weight = xatoi(token + 7);
2179  } else if (!strncmp(token, "basetime=", 9)) {
2180  p->basetime = xatoi(token + 9);
2181  } else if (!strcmp(token, "closest-only")) {
2182  p->options.closest_only = true;
2183  } else if (!strncmp(token, "ttl=", 4)) {
2184  p->mcast.ttl = xatoi(token + 4);
2185 
2186  if (p->mcast.ttl < 0)
2187  p->mcast.ttl = 0;
2188 
2189  if (p->mcast.ttl > 128)
2190  p->mcast.ttl = 128;
2191  } else if (!strcmp(token, "default")) {
2192  p->options.default_parent = true;
2193  } else if (!strcmp(token, "round-robin")) {
2194  p->options.roundrobin = true;
2195  } else if (!strcmp(token, "weighted-round-robin")) {
2196  p->options.weighted_roundrobin = true;
2197 #if USE_HTCP
2198  } else if (!strcmp(token, "htcp")) {
2199  p->options.htcp = true;
2200  } else if (!strncmp(token, "htcp=", 5) || !strncmp(token, "htcp-", 5)) {
2201  /* Note: The htcp- form is deprecated, replaced by htcp= */
2202  p->options.htcp = true;
2203  char *tmp = xstrdup(token+5);
2204  char *mode, *nextmode;
2205  for (mode = nextmode = tmp; mode; mode = nextmode) {
2206  nextmode = strchr(mode, ',');
2207  if (nextmode) {
2208  *nextmode = '\0';
2209  ++nextmode;
2210  }
2211  if (!strcmp(mode, "no-clr")) {
2212  if (p->options.htcp_only_clr)
2213  fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2214  p->options.htcp_no_clr = true;
2215  } else if (!strcmp(mode, "no-purge-clr")) {
2216  p->options.htcp_no_purge_clr = true;
2217  } else if (!strcmp(mode, "only-clr")) {
2218  if (p->options.htcp_no_clr)
2219  fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2220  p->options.htcp_only_clr = true;
2221  } else if (!strcmp(mode, "forward-clr")) {
2222  p->options.htcp_forward_clr = true;
2223  } else if (!strcmp(mode, "oldsquid")) {
2224  p->options.htcp_oldsquid = true;
2225  } else {
2226  fatalf("invalid HTCP mode '%s'", mode);
2227  }
2228  }
2229  safe_free(tmp);
2230 #endif
2231  } else if (!strcmp(token, "no-netdb-exchange")) {
2232  p->options.no_netdb_exchange = true;
2233 
2234  } else if (!strcmp(token, "carp")) {
2235  if (p->type != PEER_PARENT)
2236  fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
2237 
2238  p->options.carp = true;
2239  } else if (!strncmp(token, "carp-key=", 9)) {
2240  if (p->options.carp != true)
2241  fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port);
2242  p->options.carp_key.set = true;
2243  char *nextkey=token+strlen("carp-key="), *key=nextkey;
2244  for (; key; key = nextkey) {
2245  nextkey=strchr(key,',');
2246  if (nextkey) ++nextkey; // skip the comma, any
2247  if (0==strncmp(key,"scheme",6)) {
2248  p->options.carp_key.scheme = true;
2249  } else if (0==strncmp(key,"host",4)) {
2250  p->options.carp_key.host = true;
2251  } else if (0==strncmp(key,"port",4)) {
2252  p->options.carp_key.port = true;
2253  } else if (0==strncmp(key,"path",4)) {
2254  p->options.carp_key.path = true;
2255  } else if (0==strncmp(key,"params",6)) {
2256  p->options.carp_key.params = true;
2257  } else {
2258  fatalf("invalid carp-key '%s'",key);
2259  }
2260  }
2261  } else if (!strcmp(token, "userhash")) {
2262 #if USE_AUTH
2263  if (p->type != PEER_PARENT)
2264  fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port);
2265 
2266  p->options.userhash = true;
2267 #else
2268  fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port);
2269 #endif
2270  } else if (!strcmp(token, "sourcehash")) {
2271  if (p->type != PEER_PARENT)
2272  fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port);
2273 
2274  p->options.sourcehash = true;
2275 
2276  } else if (!strcmp(token, "no-delay")) {
2277 #if USE_DELAY_POOLS
2278  p->options.no_delay = true;
2279 #else
2280  debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2281 #endif
2282  } else if (!strncmp(token, "login=", 6)) {
2283  p->login = xstrdup(token + 6);
2284  rfc1738_unescape(p->login);
2285  } else if (!strcmp(token, "auth-no-keytab")) {
2286  p->options.auth_no_keytab = 1;
2287  } else if (!strncmp(token, "connect-timeout=", 16)) {
2288  p->connect_timeout_raw = xatoi(token + 16);
2289  } else if (!strncmp(token, "connect-fail-limit=", 19)) {
2290  p->connect_fail_limit = xatoi(token + 19);
2291 #if USE_CACHE_DIGESTS
2292  } else if (!strncmp(token, "digest-url=", 11)) {
2293  p->digest_url = xstrdup(token + 11);
2294 #endif
2295 
2296  } else if (!strcmp(token, "allow-miss")) {
2297  p->options.allow_miss = true;
2298  } else if (!strncmp(token, "max-conn=", 9)) {
2299  p->max_conn = xatoi(token + 9);
2300  } else if (!strncmp(token, "standby=", 8)) {
2301  p->standby.limit = xatoi(token + 8);
2302  } else if (!strcmp(token, "originserver")) {
2303  p->options.originserver = true;
2304  } else if (!strncmp(token, "name=", 5)) {
2305  safe_free(p->name);
2306 
2307  if (token[5])
2308  p->name = xstrdup(token + 5);
2309  } else if (!strncmp(token, "forceddomain=", 13)) {
2310  safe_free(p->domain);
2311  if (token[13])
2312  p->domain = xstrdup(token + 13);
2313 
2314  } else if (strncmp(token, "ssl", 3) == 0) {
2315 #if !USE_OPENSSL
2316  debugs(0, DBG_CRITICAL, "WARNING: cache_peer option '" << token << "' requires --with-openssl");
2317 #else
2318  p->secure.parse(token+3);
2319 #endif
2320  } else if (strncmp(token, "tls-", 4) == 0) {
2321  p->secure.parse(token+4);
2322  } else if (strncmp(token, "tls", 3) == 0) {
2323  p->secure.parse(token+3);
2324  } else if (strcmp(token, "front-end-https") == 0) {
2325  p->front_end_https = 1;
2326  } else if (strcmp(token, "front-end-https=on") == 0) {
2327  p->front_end_https = 1;
2328  } else if (strcmp(token, "front-end-https=auto") == 0) {
2329  p->front_end_https = 2;
2330  } else if (strcmp(token, "connection-auth=off") == 0) {
2331  p->connection_auth = 0;
2332  } else if (strcmp(token, "connection-auth") == 0) {
2333  p->connection_auth = 1;
2334  } else if (strcmp(token, "connection-auth=on") == 0) {
2335  p->connection_auth = 1;
2336  } else if (strcmp(token, "connection-auth=auto") == 0) {
2337  p->connection_auth = 2;
2338  } else if (token[0] == '#') {
2339  // start of a text comment. stop reading this line.
2340  break;
2341  } else {
2342  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Ignoring unknown cache_peer option '" << token << "'");
2343  }
2344  }
2345 
2346  if (peerFindByName(p->name))
2347  fatalf("ERROR: cache_peer %s specified twice\n", p->name);
2348 
2349  if (p->max_conn > 0 && p->max_conn < p->standby.limit)
2350  fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p->host, p->max_conn, p->standby.limit);
2351 
2352  if (p->weight < 1)
2353  p->weight = 1;
2354 
2355  if (p->connect_fail_limit < 1)
2356  p->connect_fail_limit = 10;
2357 
2358 #if USE_CACHE_DIGESTS
2359  if (!p->options.no_digest)
2360  peerDigestCreate(p);
2361 #endif
2362 
2363  p->index = ++Config.npeers;
2364 
2365  while (*head != NULL)
2366  head = &(*head)->next;
2367 
2368  *head = p;
2369 
2370  peerClearRRStart();
2371 }
2372 
2373 static void
2375 {
2376  delete *P;
2377  *P = NULL;
2378  Config.npeers = 0;
2379 }
2380 
2381 static void
2382 dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list)
2383 {
2384  while (list) {
2385  if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
2386  storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
2387  else
2388  storeAppendPrintf(entry, "%s %s", name, list->passwd);
2389 
2390  for (auto w : list->actions)
2391  entry->appendf(" " SQUIDSBUFPH, SQUIDSBUFPRINT(w));
2392 
2393  storeAppendPrintf(entry, "\n");
2394  list = list->next;
2395  }
2396 }
2397 
2398 static void
2400 {
2401  char *passwd = nullptr;
2402  parse_string(&passwd);
2403 
2405  p->passwd = passwd;
2406 
2407  while (char *token = ConfigParser::NextQuotedToken())
2408  p->actions.push_back(SBuf(token));
2409 
2411  for (P = head; *P; P = &(*P)->next) {
2412  /*
2413  * See if any of the actions from this line already have a
2414  * password from previous lines. The password checking
2415  * routines in cache_manager.c take the the password from
2416  * the first Mgr::ActionPasswordList that contains the
2417  * requested action. Thus, we should warn users who might
2418  * think they can have two passwords for the same action.
2419  */
2420  for (const auto &w : (*P)->actions) {
2421  for (const auto &u : p->actions) {
2422  if (w != u)
2423  continue;
2424 
2425  debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u << "' (line " << config_lineno << ") already has a password");
2426  }
2427  }
2428  }
2429 
2430  *P = p;
2431 }
2432 
2433 static void
2435 {
2436  delete *head;
2437  *head = nullptr;
2438 }
2439 
2440 static void
2441 dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var)
2442 {
2443  while (var != NULL) {
2444  storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
2445 
2446  for (const auto &aclName: var->acl_list)
2447  storeAppendPrintf(entry, " " SQUIDSBUFPH, SQUIDSBUFPRINT(aclName));
2448 
2449  storeAppendPrintf(entry, "\n");
2450 
2451  var = var->next;
2452  }
2453 }
2454 
2455 static void
2457 {
2458  aclParseDenyInfoLine(var);
2459 }
2460 
2461 void
2463 {
2464  delete *list;
2465  *list = nullptr;
2466 }
2467 
2468 static void
2470 {
2471  char *host = ConfigParser::NextToken();
2472  if (!host) {
2473  self_destruct();
2474  return;
2475  }
2476 
2477  CachePeer *p = peerFindByName(host);
2478  if (!p) {
2479  debugs(15, DBG_CRITICAL, "ERROR: " << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2480  return;
2481  }
2482 
2483  std::string directive = "peer_access ";
2484  directive += host;
2485  aclParseAccessLine(directive.c_str(), LegacyParser, &p->access);
2486 }
2487 
2488 static void
2490 {
2491  char *host = ConfigParser::NextToken();
2492  if (!host) {
2493  self_destruct();
2494  return;
2495  }
2496 
2497  char *type = ConfigParser::NextToken();
2498  if (!type) {
2499  self_destruct();
2500  return;
2501  }
2502 
2503  char *domain = nullptr;
2504  while ((domain = ConfigParser::NextToken())) {
2505  CachePeer *p = peerFindByName(host);
2506  if (!p) {
2507  debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2508  return;
2509  }
2510 
2511  auto *l = static_cast<NeighborTypeDomainList *>(xcalloc(1, sizeof(NeighborTypeDomainList)));
2512  l->type = parseNeighborType(type);
2513  l->domain = xstrdup(domain);
2514 
2515  NeighborTypeDomainList **L = nullptr;
2516  for (L = &(p->typelist); *L; L = &((*L)->next));
2517  *L = l;
2518  }
2519 }
2520 
2521 static void
2522 dump_int(StoreEntry * entry, const char *name, int var)
2523 {
2524  storeAppendPrintf(entry, "%s %d\n", name, var);
2525 }
2526 
2527 void
2528 parse_int(int *var)
2529 {
2530  int i;
2531  i = GetInteger();
2532  *var = i;
2533 }
2534 
2535 static void
2536 free_int(int *var)
2537 {
2538  *var = 0;
2539 }
2540 
2541 static void
2542 dump_int64_t(StoreEntry * entry, const char *name, int64_t var)
2543 {
2544  storeAppendPrintf(entry, "%s %" PRId64 "\n", name, var);
2545 }
2546 
2547 void
2548 parse_int64_t(int64_t *var)
2549 {
2550  int64_t i;
2551  i = GetInteger64();
2552  *var = i;
2553 }
2554 
2555 static void
2556 free_int64_t(int64_t *var)
2557 {
2558  *var = 0;
2559 }
2560 
2561 static void
2562 dump_onoff(StoreEntry * entry, const char *name, int var)
2563 {
2564  storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
2565 }
2566 
2567 void
2568 parse_onoff(int *var)
2569 {
2570  char *token = ConfigParser::NextToken();
2571  if (!token) {
2572  self_destruct();
2573  return;
2574  }
2575 
2576  if (!strcmp(token, "on")) {
2577  *var = 1;
2578  } else if (!strcmp(token, "enable")) {
2579  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2580  *var = 1;
2581  } else if (!strcmp(token, "off")) {
2582  *var = 0;
2583  } else if (!strcmp(token, "disable")) {
2584  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2585  *var = 0;
2586  } else {
2587  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2588  self_destruct();
2589  }
2590 }
2591 
2592 #define free_onoff free_int
2593 
2594 static void
2595 dump_tristate(StoreEntry * entry, const char *name, int var)
2596 {
2597  const char *state;
2598 
2599  if (var > 0)
2600  state = "on";
2601  else if (var < 0)
2602  state = "warn";
2603  else
2604  state = "off";
2605 
2606  storeAppendPrintf(entry, "%s %s\n", name, state);
2607 }
2608 
2609 static void
2611 {
2612  char *token = ConfigParser::NextToken();
2613  if (!token) {
2614  self_destruct();
2615  return;
2616  }
2617 
2618  if (!strcmp(token, "on")) {
2619  *var = 1;
2620  } else if (!strcmp(token, "enable")) {
2621  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2622  *var = 1;
2623  } else if (!strcmp(token, "warn")) {
2624  *var = -1;
2625  } else if (!strcmp(token, "off")) {
2626  *var = 0;
2627  } else if (!strcmp(token, "disable")) {
2628  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2629  *var = 0;
2630  } else {
2631  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2632  self_destruct();
2633  }
2634 }
2635 
2636 #define free_tristate free_int
2637 
2638 void
2640 {
2641  char *token = ConfigParser::PeekAtToken();
2642  if (!token) {
2643  self_destruct();
2644  return;
2645  }
2646 
2647  if (!strcmp(token, "on")) {
2648  debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2649  *var = 1;
2650  //pop the token
2651  (void)ConfigParser::NextToken();
2652  } else if (!strcmp(token, "off")) {
2653  debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2654  *var = 0;
2655  //pop the token
2656  (void)ConfigParser::NextToken();
2657  } else
2658  parse_int(var);
2659 }
2660 
2661 #define free_pipelinePrefetch free_int
2662 #define dump_pipelinePrefetch dump_int
2663 
2664 static void
2665 dump_refreshpattern(StoreEntry * entry, const char *name, RefreshPattern * head)
2666 {
2667  while (head != NULL) {
2668  storeAppendPrintf(entry, "%s%s %s %d %d%% %d",
2669  name,
2670  head->pattern.flags&REG_ICASE ? " -i" : null_string,
2671  head->pattern.c_str(),
2672  (int) head->min / 60,
2673  (int) (100.0 * head->pct + 0.5),
2674  (int) head->max / 60);
2675 
2676  if (head->max_stale >= 0)
2677  storeAppendPrintf(entry, " max-stale=%d", head->max_stale);
2678 
2679  if (head->flags.refresh_ims)
2680  storeAppendPrintf(entry, " refresh-ims");
2681 
2682  if (head->flags.store_stale)
2683  storeAppendPrintf(entry, " store-stale");
2684 
2685 #if USE_HTTP_VIOLATIONS
2686 
2687  if (head->flags.override_expire)
2688  storeAppendPrintf(entry, " override-expire");
2689 
2690  if (head->flags.override_lastmod)
2691  storeAppendPrintf(entry, " override-lastmod");
2692 
2693  if (head->flags.reload_into_ims)
2694  storeAppendPrintf(entry, " reload-into-ims");
2695 
2696  if (head->flags.ignore_reload)
2697  storeAppendPrintf(entry, " ignore-reload");
2698 
2699  if (head->flags.ignore_no_store)
2700  storeAppendPrintf(entry, " ignore-no-store");
2701 
2702  if (head->flags.ignore_private)
2703  storeAppendPrintf(entry, " ignore-private");
2704 #endif
2705 
2706  storeAppendPrintf(entry, "\n");
2707 
2708  head = head->next;
2709  }
2710 }
2711 
2712 static void
2714 {
2715  char *token;
2716  char *pattern;
2717  time_t min = 0;
2718  double pct = 0.0;
2719  time_t max = 0;
2720  int refresh_ims = 0;
2721  int store_stale = 0;
2722  int max_stale = -1;
2723 
2724 #if USE_HTTP_VIOLATIONS
2725 
2726  int override_expire = 0;
2727  int override_lastmod = 0;
2728  int reload_into_ims = 0;
2729  int ignore_reload = 0;
2730  int ignore_no_store = 0;
2731  int ignore_private = 0;
2732 #endif
2733 
2734  int i;
2735  RefreshPattern *t;
2736  regex_t comp;
2737  int errcode;
2738  int flags = REG_EXTENDED | REG_NOSUB;
2739 
2740  if ((token = ConfigParser::RegexPattern()) != NULL) {
2741 
2742  if (strcmp(token, "-i") == 0) {
2743  flags |= REG_ICASE;
2744  token = ConfigParser::RegexPattern();
2745  } else if (strcmp(token, "+i") == 0) {
2746  flags &= ~REG_ICASE;
2747  token = ConfigParser::RegexPattern();
2748  }
2749 
2750  }
2751 
2752  if (token == NULL) {
2753  debugs(3, DBG_CRITICAL, "FATAL: refresh_pattern missing the regex pattern parameter");
2754  self_destruct();
2755  return;
2756  }
2757 
2758  pattern = xstrdup(token);
2759 
2760  i = GetInteger(); /* token: min */
2761 
2762  /* catch negative and insanely huge values close to 32-bit wrap */
2763  if (i < 0) {
2764  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2765  i = 0;
2766  }
2767  if (i > 60*24*365) {
2768  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2769  i = 60*24*365;
2770  }
2771 
2772  min = (time_t) (i * 60); /* convert minutes to seconds */
2773 
2774  pct = GetPercentage(false); /* token: pct . with no limit on size */
2775 
2776  i = GetInteger(); /* token: max */
2777 
2778  /* catch negative and insanely huge values close to 32-bit wrap */
2779  if (i < 0) {
2780  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2781  i = 0;
2782  }
2783  if (i > 60*24*365) {
2784  debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2785  i = 60*24*365;
2786  }
2787 
2788  max = (time_t) (i * 60); /* convert minutes to seconds */
2789 
2790  /* Options */
2791  while ((token = ConfigParser::NextToken()) != NULL) {
2792  if (!strcmp(token, "refresh-ims")) {
2793  refresh_ims = 1;
2794  } else if (!strcmp(token, "store-stale")) {
2795  store_stale = 1;
2796  } else if (!strncmp(token, "max-stale=", 10)) {
2797  max_stale = xatoi(token + 10);
2798 
2799 #if USE_HTTP_VIOLATIONS
2800 
2801  } else if (!strcmp(token, "override-expire"))
2802  override_expire = 1;
2803  else if (!strcmp(token, "override-lastmod"))
2804  override_lastmod = 1;
2805  else if (!strcmp(token, "ignore-no-store"))
2806  ignore_no_store = 1;
2807  else if (!strcmp(token, "ignore-private"))
2808  ignore_private = 1;
2809  else if (!strcmp(token, "reload-into-ims")) {
2810  reload_into_ims = 1;
2812  /* tell client_side.c that this is used */
2813  } else if (!strcmp(token, "ignore-reload")) {
2814  ignore_reload = 1;
2816  /* tell client_side.c that this is used */
2817 #endif
2818 
2819  } else if (!strcmp(token, "ignore-no-cache") ||
2820  !strcmp(token, "ignore-must-revalidate") ||
2821  !strcmp(token, "ignore-auth")
2822  ) {
2823  debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token << "' is obsolete. Remove it.");
2824  } else
2825  debugs(22, DBG_CRITICAL, "refreshAddToList: Unknown option '" << pattern << "': " << token);
2826  }
2827 
2828  if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
2829  char errbuf[256];
2830  regerror(errcode, &comp, errbuf, sizeof errbuf);
2831  debugs(22, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2832  debugs(22, DBG_CRITICAL, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
2833  xfree(pattern);
2834  return;
2835  }
2836 
2837  pct = pct < 0.0 ? 0.0 : pct;
2838  max = max < 0 ? 0 : max;
2839  t = new RefreshPattern(pattern, flags);
2840  t->pattern.regex = comp;
2841  t->min = min;
2842  t->pct = pct;
2843  t->max = max;
2844 
2845  if (refresh_ims)
2846  t->flags.refresh_ims = true;
2847 
2848  if (store_stale)
2849  t->flags.store_stale = true;
2850 
2851  t->max_stale = max_stale;
2852 
2853 #if USE_HTTP_VIOLATIONS
2854 
2855  if (override_expire)
2856  t->flags.override_expire = true;
2857 
2858  if (override_lastmod)
2859  t->flags.override_lastmod = true;
2860 
2861  if (reload_into_ims)
2862  t->flags.reload_into_ims = true;
2863 
2864  if (ignore_reload)
2865  t->flags.ignore_reload = true;
2866 
2867  if (ignore_no_store)
2868  t->flags.ignore_no_store = true;
2869 
2870  if (ignore_private)
2871  t->flags.ignore_private = true;
2872 #endif
2873 
2874  t->next = NULL;
2875 
2876  while (*head)
2877  head = &(*head)->next;
2878 
2879  *head = t;
2880 
2881  xfree(pattern);
2882 }
2883 
2884 static void
2886 {
2887  delete *head;
2888  *head = nullptr;
2889 
2890 #if USE_HTTP_VIOLATIONS
2892 
2893 #endif
2894 }
2895 
2896 static void
2897 dump_string(StoreEntry * entry, const char *name, char *var)
2898 {
2899  if (var != NULL)
2900  storeAppendPrintf(entry, "%s %s\n", name, var);
2901 }
2902 
2903 static void
2904 parse_string(char **var)
2905 {
2906  safe_free(*var);
2907 
2908  char *token = ConfigParser::NextToken();
2909  if (!token) {
2910  self_destruct();
2911  return;
2912  }
2913 
2914  *var = xstrdup(token);
2915 }
2916 
2917 static void
2918 free_string(char **var)
2919 {
2920  safe_free(*var);
2921 }
2922 
2923 void
2924 parse_eol(char *volatile *var)
2925 {
2926  if (!var) {
2927  self_destruct();
2928  return;
2929  }
2930 
2931  unsigned char *token = (unsigned char *) ConfigParser::NextQuotedOrToEol();
2932  safe_free(*var);
2933 
2934  if (!token) {
2935  self_destruct();
2936  return;
2937  }
2938 
2939  while (*token && xisspace(*token))
2940  ++token;
2941 
2942  if (!*token) {
2943  self_destruct();
2944  return;
2945  }
2946 
2947  *var = xstrdup((char *) token);
2948 }
2949 
2950 #define dump_eol dump_string
2951 #define free_eol free_string
2952 
2953 static void
2955 {
2956  safe_free(*var);
2957 
2958  char *token = ConfigParser::NextQuotedToken();
2959  if (!token) {
2960  self_destruct();
2961  return;
2962  }
2963 
2964  *var = xstrdup(token);
2965 }
2966 
2967 #define dump_TokenOrQuotedString dump_string
2968 #define free_TokenOrQuotedString free_string
2969 
2970 static void
2971 dump_time_t(StoreEntry * entry, const char *name, time_t var)
2972 {
2973  storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
2974 }
2975 
2976 void
2977 parse_time_t(time_t * var)
2978 {
2979  time_msec_t tval = parseTimeLine(T_SECOND_STR, false);
2980  *var = static_cast<time_t>(tval/1000);
2981 }
2982 
2983 static void
2984 free_time_t(time_t * var)
2985 {
2986  *var = 0;
2987 }
2988 
2989 static void
2990 dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
2991 {
2992  if (var % 1000)
2993  storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
2994  else
2995  storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
2996 }
2997 
2998 void
3000 {
3001  *var = parseTimeLine(T_SECOND_STR, true);
3002 }
3003 
3004 static void
3006 {
3007  *var = 0;
3008 }
3009 
3010 #if UNUSED_CODE
3011 static void
3012 dump_size_t(StoreEntry * entry, const char *name, size_t var)
3013 {
3014  storeAppendPrintf(entry, "%s %d\n", name, (int) var);
3015 }
3016 #endif
3017 
3018 static void
3019 dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
3020 {
3021  storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3022 }
3023 
3024 static void
3025 dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var)
3026 {
3027  storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3028 }
3029 
3030 #if UNUSED_CODE
3031 static void
3032 dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
3033 {
3034  storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
3035 }
3036 #endif
3037 
3038 static void
3039 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
3040 {
3041  storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
3042 }
3043 
3044 static void
3045 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
3046 {
3047  storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
3048 }
3049 
3050 #if UNUSED_CODE
3051 static void
3052 parse_size_t(size_t * var)
3053 {
3054  int i;
3055  i = GetInteger();
3056  *var = (size_t) i;
3057 }
3058 #endif
3059 
3060 static void
3061 parse_b_size_t(size_t * var)
3062 {
3064 }
3065 
3066 static void
3067 parse_b_ssize_t(ssize_t * var)
3068 {
3070 }
3071 
3072 #if UNUSED_CODE
3073 static void
3074 parse_kb_size_t(size_t * var)
3075 {
3077 }
3078 #endif
3079 
3080 static void
3081 parse_b_int64_t(int64_t * var)
3082 {
3084 }
3085 
3086 static void
3087 parse_kb_int64_t(int64_t * var)
3088 {
3090 }
3091 
3092 static void
3093 free_size_t(size_t * var)
3094 {
3095  *var = 0;
3096 }
3097 
3098 static void
3099 free_ssize_t(ssize_t * var)
3100 {
3101  *var = 0;
3102 }
3103 
3104 static void
3105 free_b_int64_t(int64_t * var)
3106 {
3107  *var = 0;
3108 }
3109 
3110 #define free_b_size_t free_size_t
3111 #define free_b_ssize_t free_ssize_t
3112 #define free_kb_size_t free_size_t
3113 #define free_mb_size_t free_size_t
3114 #define free_gb_size_t free_size_t
3115 #define free_kb_int64_t free_b_int64_t
3116 
3117 static void
3118 dump_u_short(StoreEntry * entry, const char *name, unsigned short var)
3119 {
3120  storeAppendPrintf(entry, "%s %d\n", name, var);
3121 }
3122 
3123 static void
3124 free_u_short(unsigned short * u)
3125 {
3126  *u = 0;
3127 }
3128 
3129 static void
3130 parse_u_short(unsigned short * var)
3131 {
3133 }
3134 
3135 void
3136 ConfigParser::ParseUShort(unsigned short *var)
3137 {
3138  *var = GetShort();
3139 }
3140 
3141 void
3143 {
3144  int i = GetInteger();
3145 
3146  if (0 == i)
3147  *var = false;
3148  else if (1 == i)
3149  *var = true;
3150  else
3151  self_destruct();
3152 }
3153 
3154 static void
3155 dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
3156 {
3157  while (list != NULL) {
3158  storeAppendPrintf(entry, "%s %s\n", name, list->key);
3159  list = list->next;
3160  }
3161 }
3162 
3163 void
3165 {
3166  parse_wordlist(list);
3167 }
3168 
3169 void
3171 {
3172  char *token;
3173  while ((token = ConfigParser::NextQuotedToken()))
3174  wordlistAdd(list, token);
3175 }
3176 
3177 #if 0 /* now unused */
3178 static int
3179 check_null_wordlist(wordlist * w)
3180 {
3181  return w == NULL;
3182 }
3183 #endif
3184 
3185 static int
3187 {
3188  return a == NULL;
3189 }
3190 
3191 #define free_wordlist wordlistDestroy
3192 
3193 #define free_uri_whitespace free_int
3194 
3195 static void
3197 {
3198  char *token = ConfigParser::NextToken();
3199  if (!token) {
3200  self_destruct();
3201  return;
3202  }
3203 
3204  if (!strcmp(token, "strip"))
3205  *var = URI_WHITESPACE_STRIP;
3206  else if (!strcmp(token, "deny"))
3207  *var = URI_WHITESPACE_DENY;
3208  else if (!strcmp(token, "allow"))
3209  *var = URI_WHITESPACE_ALLOW;
3210  else if (!strcmp(token, "encode"))
3211  *var = URI_WHITESPACE_ENCODE;
3212  else if (!strcmp(token, "chop"))
3213  *var = URI_WHITESPACE_CHOP;
3214  else {
3215  debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3216  self_destruct();
3217  }
3218 }
3219 
3220 static void
3221 dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
3222 {
3223  const char *s;
3224 
3225  if (var == URI_WHITESPACE_ALLOW)
3226  s = "allow";
3227  else if (var == URI_WHITESPACE_ENCODE)
3228  s = "encode";
3229  else if (var == URI_WHITESPACE_CHOP)
3230  s = "chop";
3231  else if (var == URI_WHITESPACE_DENY)
3232  s = "deny";
3233  else
3234  s = "strip";
3235 
3236  storeAppendPrintf(entry, "%s %s\n", name, s);
3237 }
3238 
3239 static void
3241 {
3242  if (!*settings)
3243  return;
3244 
3245  free_string(&(*settings)->type);
3246 
3247  free_wordlist(&(*settings)->args);
3248 
3249  delete *settings;
3250 
3251  *settings = NULL;
3252 }
3253 
3254 static void
3256 {
3257  if (*settings)
3258  free_removalpolicy(settings);
3259 
3260  *settings = new RemovalPolicySettings;
3261 
3262  parse_string(&(*settings)->type);
3263 
3264  parse_wordlist(&(*settings)->args);
3265 }
3266 
3267 static void
3268 dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
3269 {
3270  wordlist *args;
3271  storeAppendPrintf(entry, "%s %s", name, settings->type);
3272  args = settings->args;
3273 
3274  while (args) {
3275  storeAppendPrintf(entry, " %s", args->key);
3276  args = args->next;
3277  }
3278 
3279  storeAppendPrintf(entry, "\n");
3280 }
3281 
3282 inline void
3284 {}
3285 
3286 static void
3288 {
3289  int value = 0;
3290  parse_onoff(&value);
3291  option->configure(value > 0);
3292 }
3293 
3294 static void
3295 dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
3296 {
3297  if (option.configured())
3298  dump_onoff(entry, name, option ? 1 : 0);
3299 }
3300 
3301 static void
3303 {}
3304 
3305 static void
3307 {
3308  char *token = ConfigParser::NextToken();
3309  if (!token) {
3310  self_destruct();
3311  return;
3312  }
3313 
3314  if (strcmp(token, "always") == 0) {
3317  } else if (strcmp(token, "disk") == 0) {
3320  } else if (strncmp(token, "net", 3) == 0) {
3323  } else if (strcmp(token, "never") == 0) {
3326  } else {
3327  debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3328  self_destruct();
3329  }
3330 }
3331 
3332 static void
3333 dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &)
3334 {
3335  storeAppendPrintf(entry, "%s ", name);
3337  storeAppendPrintf(entry, "always");
3339  storeAppendPrintf(entry, "disk");
3341  storeAppendPrintf(entry, "network");
3343  storeAppendPrintf(entry, "none");
3344  storeAppendPrintf(entry, "\n");
3345 }
3346 
3347 #include "cf_parser.cci"
3348 
3349 peer_t
3350 parseNeighborType(const char *s)
3351 {
3352  if (!strcmp(s, "parent"))
3353  return PEER_PARENT;
3354 
3355  if (!strcmp(s, "neighbor"))
3356  return PEER_SIBLING;
3357 
3358  if (!strcmp(s, "neighbour"))
3359  return PEER_SIBLING;
3360 
3361  if (!strcmp(s, "sibling"))
3362  return PEER_SIBLING;
3363 
3364  if (!strcmp(s, "multicast"))
3365  return PEER_MULTICAST;
3366 
3367  debugs(15, DBG_CRITICAL, "WARNING: Unknown neighbor type: " << s);
3368 
3369  return PEER_SIBLING;
3370 }
3371 
3372 #if USE_WCCPv2
3373 static void
3375 {
3376  char *token;
3377  Ip::Address_list *s;
3378  Ip::Address ipa;
3379 
3380  while ((token = ConfigParser::NextToken())) {
3381  if (GetHostWithPort(token, &ipa)) {
3382 
3383  while (*head)
3384  head = &(*head)->next;
3385 
3386  s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s)));
3387  s->s = ipa;
3388 
3389  *head = s;
3390  } else {
3391  self_destruct();
3392  return;
3393  }
3394  }
3395 }
3396 
3397 static void
3398 dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s)
3399 {
3400  char ntoabuf[MAX_IPSTRLEN];
3401 
3402  while (s) {
3403  storeAppendPrintf(e, "%s %s\n",
3404  n,
3405  s->s.toStr(ntoabuf,MAX_IPSTRLEN));
3406  s = s->next;
3407  }
3408 }
3409 
3410 static void
3412 {
3413  if (*head) delete *head;
3414  *head = NULL;
3415 }
3416 
3417 #if CURRENTLY_UNUSED
3418 /* This code was previously used by http_port. Left as it really should
3419  * be used by icp_port and htcp_port
3420  */
3421 static int
3422 check_null_IpAddress_list(const Ip::Address_list * s)
3423 {
3424  return NULL == s;
3425 }
3426 
3427 #endif /* CURRENTLY_UNUSED */
3428 #endif /* USE_WCCPv2 */
3429 
3430 static void
3432 {
3433  char *host = NULL;
3434  unsigned short port = 0;
3435  char *t = NULL;
3436  char *junk = NULL;
3437 
3438  s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3439  s->name = xstrdup(token);
3440  s->connection_auth_disabled = false;
3441 
3442  const SBuf &portType = AnyP::UriScheme(s->transport.protocol).image();
3443 
3444  if (*token == '[') {
3445  /* [ipv6]:port */
3446  host = token + 1;
3447  t = strchr(host, ']');
3448  if (!t) {
3449  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing ']' on IPv6 address: " << token);
3450  self_destruct();
3451  return;
3452  }
3453  *t = '\0';
3454  ++t;
3455  if (*t != ':') {
3456  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port in: " << token);
3457  self_destruct();
3458  return;
3459  }
3460  if (!Ip::EnableIpv6) {
3461  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: IPv6 is not available.");
3462  self_destruct();
3463  return;
3464  }
3465  port = xatos(t + 1);
3466  } else if ((t = strchr(token, ':'))) {
3467  /* host:port */
3468  /* ipv4:port */
3469  host = token;
3470  *t = '\0';
3471  port = xatos(t + 1);
3472 
3473  } else if (strtol(token, &junk, 10) && !*junk) {
3474  port = xatos(token);
3475  debugs(3, 3, portType << "_port: found Listen on Port: " << port);
3476  } else {
3477  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port: " << token);
3478  self_destruct();
3479  return;
3480  }
3481 
3482  if (port == 0 && host != NULL) {
3483  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: Port cannot be 0: " << token);
3484  self_destruct();
3485  return;
3486  }
3487 
3488  if (NULL == host) {
3489  s->s.setAnyAddr();
3490  s->s.port(port);
3491  if (!Ip::EnableIpv6)
3492  s->s.setIPv4();
3493  debugs(3, 3, portType << "_port: found Listen on wildcard address: *:" << s->s.port());
3494  } else if ( (s->s = host) ) { /* check/parse numeric IPA */
3495  s->s.port(port);
3496  if (!Ip::EnableIpv6)
3497  s->s.setIPv4();
3498  debugs(3, 3, portType << "_port: Listen on Host/IP: " << host << " --> " << s->s);
3499  } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
3500  /* do not use ipcache */
3501  s->defaultsite = xstrdup(host);
3502  s->s.port(port);
3503  if (!Ip::EnableIpv6)
3504  s->s.setIPv4();
3505  debugs(3, 3, portType << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
3506  } else {
3507  debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: failed to resolve Host/IP: " << host);
3508  self_destruct();
3509  }
3510 }
3511 
3515 static AnyP::ProtocolVersion
3517 {
3518  // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3519  // and RFC 2616 requires us to upgrade 1.0 to 1.1
3520  if (value.cmp("HTTP") == 0 || value.cmp("HTTP/1.1") == 0)
3521  return Http::ProtocolVersion(1,1);
3522 
3523  if (value.cmp("HTTPS") == 0 || value.cmp("HTTPS/1.1") == 0)
3525 
3526  if (value.cmp("FTP") == 0)
3527  return Ftp::ProtocolVersion();
3528 
3529  fatalf("%s directive does not support protocol=" SQUIDSBUFPH "\n", cfg_directive, SQUIDSBUFPRINT(value));
3530  return AnyP::ProtocolVersion(); // not reached
3531 }
3532 
3533 static void
3535 {
3536  /* modes first */
3537 
3538  if (strcmp(token, "accel") == 0) {
3539  if (s->flags.isIntercepted()) {
3540  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3541  self_destruct();
3542  return;
3543  }
3544  s->flags.accelSurrogate = true;
3545  s->vhost = true;
3546  } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
3547  if (s->flags.accelSurrogate || s->flags.tproxyIntercept) {
3548  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3549  self_destruct();
3550  return;
3551  }
3552  s->flags.natIntercept = true;
3554  /* Log information regarding the port modes under interception. */
3555  debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
3556  debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
3557  } else if (strcmp(token, "tproxy") == 0) {
3558  if (s->flags.natIntercept || s->flags.accelSurrogate) {
3559  debugs(3,DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3560  self_destruct();
3561  return;
3562  }
3563  s->flags.tproxyIntercept = true;
3565  /* Log information regarding the port modes under transparency. */
3566  debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (TPROXY enabled)");
3567 
3568  if (s->flags.proxySurrogate) {
3569  debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)");
3570  }
3571 
3572  if (!Ip::Interceptor.ProbeForTproxy(s->s)) {
3573  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY support in the system does not work.");
3574  self_destruct();
3575  return;
3576  }
3577 
3578  } else if (strcmp(token, "require-proxy-header") == 0) {
3579  s->flags.proxySurrogate = true;
3580  if (s->flags.tproxyIntercept) {
3581  // receiving is still permitted, so we do not unset the TPROXY flag
3582  // spoofing access control override takes care of the spoof disable later
3583  debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)");
3584  }
3585 
3586  } else if (strncmp(token, "defaultsite=", 12) == 0) {
3587  if (!s->flags.accelSurrogate) {
3588  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": defaultsite option requires Acceleration mode flag.");
3589  self_destruct();
3590  return;
3591  }
3592  safe_free(s->defaultsite);
3593  s->defaultsite = xstrdup(token + 12);
3594  } else if (strcmp(token, "vhost") == 0) {
3595  if (!s->flags.accelSurrogate) {
3596  debugs(3, DBG_CRITICAL, "WARNING: " << cfg_directive << ": vhost option is deprecated. Use 'accel' mode flag instead.");
3597  }
3598  s->flags.accelSurrogate = true;
3599  s->vhost = true;
3600  } else if (strcmp(token, "no-vhost") == 0) {
3601  if (!s->flags.accelSurrogate) {
3602  debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": no-vhost option requires Acceleration mode flag.");
3603  }
3604  s->vhost = false;
3605  } else if (strcmp(token, "vport") == 0) {
3606  if (!s->flags.accelSurrogate) {
3607  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag.");
3608  self_destruct();
3609  return;
3610  }
3611  s->vport = -1;
3612  } else if (strncmp(token, "vport=", 6) == 0) {
3613  if (!s->flags.accelSurrogate) {
3614  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag.");
3615  self_destruct();
3616  return;
3617  }
3618  s->vport = xatos(token + 6);
3619  } else if (strncmp(token, "protocol=", 9) == 0) {
3620  if (!s->flags.accelSurrogate) {
3621  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": protocol option requires Acceleration mode flag.");
3622  self_destruct();
3623  return;
3624  }
3625  s->transport = parsePortProtocol(ToUpper(SBuf(token + 9)));
3626  } else if (strcmp(token, "allow-direct") == 0) {
3627  if (!s->flags.accelSurrogate) {
3628  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": allow-direct option requires Acceleration mode flag.");
3629  self_destruct();
3630  return;
3631  }
3632  s->allow_direct = true;
3633  } else if (strcmp(token, "act-as-origin") == 0) {
3634  if (!s->flags.accelSurrogate) {
3635  debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": act-as-origin option requires Acceleration mode flag.");
3636  } else
3637  s->actAsOrigin = true;
3638  } else if (strcmp(token, "ignore-cc") == 0) {
3639 #if !USE_HTTP_VIOLATIONS
3640  if (!s->flags.accelSurrogate) {
3641  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": ignore-cc option requires Acceleration mode flag.");
3642  self_destruct();
3643  return;
3644  }
3645 #endif
3646  s->ignore_cc = true;
3647  } else if (strncmp(token, "name=", 5) == 0) {
3648  safe_free(s->name);
3649  s->name = xstrdup(token + 5);
3650  } else if (strcmp(token, "no-connection-auth") == 0) {
3651  s->connection_auth_disabled = true;
3652  } else if (strcmp(token, "connection-auth=off") == 0) {
3653  s->connection_auth_disabled = true;
3654  } else if (strcmp(token, "connection-auth") == 0) {
3655  s->connection_auth_disabled = false;
3656  } else if (strcmp(token, "connection-auth=on") == 0) {
3657  s->connection_auth_disabled = false;
3658  } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
3659  if (!strcmp(token + 23, "off"))
3660  s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3661  else if (!strcmp(token + 23, "transparent"))
3662  s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
3663  else if (!strcmp(token + 23, "always"))
3664  s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
3665  else {
3666  self_destruct();
3667  return;
3668  }
3669  } else if (strcmp(token, "ipv4") == 0) {
3670  if ( !s->s.setIPv4() ) {
3671  debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": IPv6 addresses cannot be used as IPv4-Only. " << s->s );
3672  self_destruct();
3673  return;
3674  }
3675  } else if (strcmp(token, "tcpkeepalive") == 0) {
3676  s->tcp_keepalive.enabled = true;
3677  } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
3678  char *t = token + 13;
3679  s->tcp_keepalive.enabled = true;
3680  s->tcp_keepalive.idle = xatoui(t,',');
3681  t = strchr(t, ',');
3682  if (t) {
3683  ++t;
3684  s->tcp_keepalive.interval = xatoui(t,',');
3685  t = strchr(t, ',');
3686  }
3687  if (t) {
3688  ++t;
3689  s->tcp_keepalive.timeout = xatoui(t);
3690  }
3691 #if USE_OPENSSL
3692  } else if (strcmp(token, "sslBump") == 0) {
3693  debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token << "' is deprecated " <<
3694  "in " << cfg_directive << ". Use 'ssl-bump' instead.");
3695  s->flags.tunnelSslBumping = true;
3696  } else if (strcmp(token, "ssl-bump") == 0) {
3697  s->flags.tunnelSslBumping = true;
3698  } else if (strncmp(token, "cert=", 5) == 0) {
3699  s->secure.parse(token);
3700  } else if (strncmp(token, "key=", 4) == 0) {
3701  s->secure.parse(token);
3702  } else if (strncmp(token, "version=", 8) == 0) {
3703  debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token << "' is deprecated " <<
3704  "in " << cfg_directive << ". Use 'options=' instead.");
3705  s->secure.parse(token);
3706  } else if (strncmp(token, "options=", 8) == 0) {
3707  s->secure.parse(token);
3708  } else if (strncmp(token, "cipher=", 7) == 0) {
3709  s->secure.parse(token);
3710  } else if (strncmp(token, "clientca=", 9) == 0) {
3711  s->secure.parse(token);
3712  } else if (strncmp(token, "cafile=", 7) == 0) {
3713  debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token << "' is deprecated " <<
3714  "in " << cfg_directive << ". Use 'tls-cafile=' instead.");
3715  s->secure.parse(token);
3716  } else if (strncmp(token, "capath=", 7) == 0) {
3717  s->secure.parse(token);
3718  } else if (strncmp(token, "crlfile=", 8) == 0) {
3719  s->secure.parse(token);
3720  } else if (strncmp(token, "dhparams=", 9) == 0) {
3721  debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: '" << token << "' is deprecated " <<
3722  "in " << cfg_directive << ". Use 'tls-dh=' instead.");
3723  s->secure.parse(token);
3724  } else if (strncmp(token, "sslflags=", 9) == 0) {
3725  // NP: deprecation warnings output by secure.parse() when relevant
3726  s->secure.parse(token+3);
3727  } else if (strncmp(token, "sslcontext=", 11) == 0) {
3728  // NP: deprecation warnings output by secure.parse() when relevant
3729  s->secure.parse(token+3);
3730  } else if (strncmp(token, "generate-host-certificates", 26) == 0) {
3731  s->secure.parse(token);
3732 #endif
3733  } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) {
3734  s->secure.parse(token);
3735  } else if (strncmp(token, "tls-", 4) == 0) {
3736  s->secure.parse(token+4);
3737  } else if (strcmp(token, "ftp-track-dirs") == 0) {
3738  s->ftp_track_dirs = true;
3739  } else {
3740  debugs(3, DBG_CRITICAL, "FATAL: Unknown " << cfg_directive << " option '" << token << "'.");
3741  self_destruct();
3742  }
3743 }
3744 
3745 void
3746 add_http_port(char *portspec)
3747 {
3749  s->transport = parsePortProtocol(SBuf("HTTP"));
3750  parsePortSpecification(s, portspec);
3751  // we may need to merge better if the above returns a list with clones
3752  assert(s->next == NULL);
3753  s->next = HttpPortList;
3754  HttpPortList = s;
3755 }
3756 
3757 static void
3758 parsePortCfg(AnyP::PortCfgPointer *head, const char *optionName)
3759 {
3760  SBuf protoName;
3761  if (strcmp(optionName, "http_port") == 0 ||
3762  strcmp(optionName, "ascii_port") == 0)
3763  protoName = "HTTP";
3764  else if (strcmp(optionName, "https_port") == 0)
3765  protoName = "HTTPS";
3766  else if (strcmp(optionName, "ftp_port") == 0)
3767  protoName = "FTP";
3768  if (protoName.isEmpty()) {
3769  self_destruct();
3770  return;
3771  }
3772 
3773  char *token = ConfigParser::NextToken();
3774 
3775  if (!token) {
3776  self_destruct();
3777  return;
3778  }
3779 
3781  s->transport = parsePortProtocol(protoName); // default; protocol=... overwrites
3782  parsePortSpecification(s, token);
3783 
3784  /* parse options ... */
3785  while ((token = ConfigParser::NextToken())) {
3786  parse_port_option(s, token);
3787  }
3788 
3789  s->secure.syncCaFiles();
3790 
3791  if (s->transport.protocol == AnyP::PROTO_HTTPS) {
3792  s->secure.encryptTransport = true;
3793 #if USE_OPENSSL
3794  /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3795  const bool hijacked = s->flags.isIntercepted();
3796  if (s->flags.tunnelSslBumping && !hijacked) {
3797  debugs(3, DBG_CRITICAL, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3798  self_destruct();
3799  return;
3800  }
3801  if (hijacked && !s->flags.tunnelSslBumping) {
3802  debugs(3, DBG_CRITICAL, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3803  self_destruct();
3804  return;
3805  }
3806 #endif
3807  if (s->flags.proxySurrogate) {
3808  debugs(3,DBG_CRITICAL, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3809  self_destruct();
3810  return;
3811  }
3812  } else if (protoName.cmp("FTP") == 0) {
3813  /* ftp_port does not support ssl-bump */
3814  if (s->flags.tunnelSslBumping) {
3815  debugs(3, DBG_CRITICAL, "FATAL: ssl-bump is not supported for ftp_port.");
3816  self_destruct();
3817  return;
3818  }
3819  if (s->flags.proxySurrogate) {
3820  // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3821  debugs(3,DBG_CRITICAL, "FATAL: require-proxy-header option is not supported on ftp_port.");
3822  self_destruct();
3823  return;
3824  }
3825  }
3826 
3827  if (s->secure.encryptTransport) {
3828  if (s->secure.certs.empty()) {
3829  debugs(3, DBG_CRITICAL, "FATAL: " << AnyP::UriScheme(s->transport.protocol) << "_port requires a cert= parameter");
3830  self_destruct();
3831  return;
3832  }
3833  }
3834 
3835  // *_port line should now be fully valid so we can clone it if necessary
3836  if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.isAnyAddr()) {
3837  // clone the port options from *s to *(s->next)
3838  s->next = s->clone();
3839  s->next->s.setIPv4();
3840  debugs(3, 3, AnyP::UriScheme(s->transport.protocol).image() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
3841  }
3842 
3843  while (*head != NULL)
3844  head = &((*head)->next);
3845 
3846  *head = s;
3847 }
3848 
3849 static void
3851 {
3852  char buf[MAX_IPSTRLEN];
3853 
3854  storeAppendPrintf(e, "%s %s",
3855  n,
3856  s->s.toUrl(buf,MAX_IPSTRLEN));
3857 
3858  // MODES and specific sub-options.
3859  if (s->flags.natIntercept)
3860  storeAppendPrintf(e, " intercept");
3861 
3862  else if (s->flags.tproxyIntercept)
3863  storeAppendPrintf(e, " tproxy");
3864 
3865  else if (s->flags.proxySurrogate)
3866  storeAppendPrintf(e, " require-proxy-header");
3867 
3868  else if (s->flags.accelSurrogate) {
3869  storeAppendPrintf(e, " accel");
3870 
3871  if (s->vhost)
3872  storeAppendPrintf(e, " vhost");
3873 
3874  if (s->vport < 0)
3875  storeAppendPrintf(e, " vport");
3876  else if (s->vport > 0)
3877  storeAppendPrintf(e, " vport=%d", s->vport);
3878 
3879  if (s->defaultsite)
3880  storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3881 
3882  // TODO: compare against prefix of 'n' instead of assuming http_port
3883  if (s->transport.protocol != AnyP::PROTO_HTTP)
3884  storeAppendPrintf(e, " protocol=%s", AnyP::ProtocolType_str[s->transport.protocol]);
3885 
3886  if (s->allow_direct)
3887  storeAppendPrintf(e, " allow-direct");
3888 
3889  if (s->ignore_cc)
3890  storeAppendPrintf(e, " ignore-cc");
3891 
3892  }
3893 
3894  // Generic independent options
3895 
3896  if (s->name)
3897  storeAppendPrintf(e, " name=%s", s->name);
3898 
3899 #if USE_HTTP_VIOLATIONS
3900  if (!s->flags.accelSurrogate && s->ignore_cc)
3901  storeAppendPrintf(e, " ignore-cc");
3902 #endif
3903 
3904  if (s->connection_auth_disabled)
3905  storeAppendPrintf(e, " connection-auth=off");
3906  else
3907  storeAppendPrintf(e, " connection-auth=on");
3908 
3909  if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3910  const char *pmtu;
3911 
3912  if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3913  pmtu = "always";
3914  else
3915  pmtu = "transparent";
3916 
3917  storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3918  }
3919 
3920  if (s->s.isAnyAddr() && !s->s.isIPv6())
3921  storeAppendPrintf(e, " ipv4");
3922 
3923  if (s->tcp_keepalive.enabled) {
3924  if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
3925  storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
3926  } else {
3927  storeAppendPrintf(e, " tcpkeepalive");
3928  }
3929  }
3930 
3931 #if USE_OPENSSL
3932  if (s->flags.tunnelSslBumping)
3933  storeAppendPrintf(e, " ssl-bump");
3934 #endif
3935 
3936  s->secure.dumpCfg(e, "tls-");
3937 }
3938 
3939 static void
3940 dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s)
3941 {
3942  for (AnyP::PortCfgPointer p = s; p != NULL; p = p->next) {
3943  dump_generic_port(e, n, p);
3944  storeAppendPrintf(e, "\n");
3945  }
3946 }
3947 
3948 void
3950 {
3951  free_all();
3952  Config.ssl_client.sslContext.reset();
3953 #if USE_OPENSSL
3955 #endif
3956 }
3957 
3958 void
3959 requirePathnameExists(const char *name, const char *path)
3960 {
3961 
3962  struct stat sb;
3963  char pathbuf[BUFSIZ];
3964  assert(path != NULL);
3965 
3966  if (Config.chroot_dir && (geteuid() == 0)) {
3967  snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3968  path = pathbuf;
3969  }
3970 
3971  if (stat(path, &sb) < 0) {
3972  int xerrno = errno;
3973  debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL: ":"ERROR: ") << name << " " << path << ": " << xstrerr(xerrno));
3974  // keep going to find more issues if we are only checking the config file with "-k parse"
3975  if (opt_parse_cfg_only)
3976  return;
3977  // this is fatal if it is found during startup or reconfigure
3978  if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
3979  fatalf("%s %s: %s", name, path, xstrerr(xerrno));
3980  }
3981 }
3982 
3983 #include "AccessLogEntry.h"
3984 
4005 static void
4007 {
4008  const char *filename = ConfigParser::NextToken();
4009  if (!filename) {
4010  self_destruct();
4011  return;
4012  }
4013 
4014  CustomLog *cl = (CustomLog *)xcalloc(1, sizeof(*cl));
4015 
4016  cl->filename = xstrdup(filename);
4017  // default buffer size and fatal settings
4018  cl->bufferSize = 8*MAX_URL;
4019  cl->fatal = true;
4020 
4021  if (strcmp(filename, "none") == 0) {
4023  aclParseAclList(LegacyParser, &cl->aclList, filename);
4024  while (*logs)
4025  logs = &(*logs)->next;
4026  *logs = cl;
4027  return;
4028  }
4029 
4031  cl->rotateCount = -1; // default: use global logfile_rotate setting.
4032 
4033  const char *token = ConfigParser::PeekAtToken();
4034  if (!token) { // style #1
4035  // no options to deal with
4036  } else if (!strchr(token, '=')) { // style #3
4037  // if logformat name is recognized,
4038  // pop the previewed token; Else it must be an ACL name
4039  if (setLogformat(cl, token, false))
4040  (void)ConfigParser::NextToken();
4041  } else { // style #4
4042  do {
4043  if (strncasecmp(token, "on-error=", 9) == 0) {
4044  if (strncasecmp(token+9, "die", 3) == 0) {
4045  cl->fatal = true;
4046  } else if (strncasecmp(token+9, "drop", 4) == 0) {
4047  cl->fatal = false;
4048  } else {
4049  debugs(3, DBG_CRITICAL, "Unknown value for on-error '" <<
4050  token << "' expected 'drop' or 'die'");
4051  xfree(cl->filename);
4052  xfree(cl);
4053  self_destruct();
4054  return;
4055  }
4056  } else if (strncasecmp(token, "buffer-size=", 12) == 0) {
4057  parseBytesOptionValue(&cl->bufferSize, B_BYTES_STR, token+12);
4058  } else if (strncasecmp(token, "rotate=", 7) == 0) {
4059  cl->rotateCount = xatoi(token + 7);
4060  } else if (strncasecmp(token, "logformat=", 10) == 0) {
4061  setLogformat(cl, token+10, true);
4062  } else if (!strchr(token, '=')) {
4063  // Do not pop the token; it must be an ACL name
4064  break; // done with name=value options, now to ACLs
4065  } else {
4066  debugs(3, DBG_CRITICAL, "Unknown access_log option " << token);
4067  xfree(cl->filename);
4068  xfree(cl);
4069  self_destruct();
4070  return;
4071  }
4072  // Pop the token, it was a valid "name=value" option
4073  (void)ConfigParser::NextToken();
4074  // Get next with preview ConfigParser::NextToken call.
4075  } while ((token = ConfigParser::PeekAtToken()) != NULL);
4076  }
4077 
4078  // set format if it has not been specified explicitly
4079  if (cl->type == Log::Format::CLF_UNKNOWN)
4080  setLogformat(cl, "squid", true);
4081 
4082  aclParseAclList(LegacyParser, &cl->aclList, cl->filename);
4083 
4084  while (*logs)
4085  logs = &(*logs)->next;
4086 
4087  *logs = cl;
4088 }
4089 
4092 static bool
4093 setLogformat(CustomLog *cl, const char *logdef_name, const bool dieWhenMissing)
4094 {
4095  assert(cl);
4096  assert(logdef_name);
4097 
4098  debugs(3, 9, "possible " << cl->filename << " logformat: " << logdef_name);
4099 
4100  if (cl->type != Log::Format::CLF_UNKNOWN) {
4101  debugs(3, DBG_CRITICAL, "FATAL: Second logformat name in one access_log: " <<
4102  logdef_name << " " << cl->type << " ? " << Log::Format::CLF_NONE);
4103  self_destruct();
4104  return false;
4105  }
4106 
4107  /* look for the definition pointer corresponding to this name */
4109 
4110  while (lf != NULL) {
4111  debugs(3, 9, "Comparing against '" << lf->name << "'");
4112 
4113  if (strcmp(lf->name, logdef_name) == 0)
4114  break;
4115 
4116  lf = lf->next;
4117  }
4118 
4119  if (lf != NULL) {
4121  cl->logFormat = lf;
4122  } else if (strcmp(logdef_name, "auto") == 0) {
4123  debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4125  } else if (strcmp(logdef_name, "squid") == 0) {
4127  } else if (strcmp(logdef_name, "common") == 0) {
4129  } else if (strcmp(logdef_name, "combined") == 0) {
4131 #if ICAP_CLIENT
4132  } else if (strcmp(logdef_name, "icap_squid") == 0) {
4134 #endif
4135  } else if (strcmp(logdef_name, "useragent") == 0) {
4137  } else if (strcmp(logdef_name, "referrer") == 0) {
4139  } else if (dieWhenMissing) {
4140  debugs(3, DBG_CRITICAL, "FATAL: Log format '" << logdef_name << "' is not defined");
4141  self_destruct();
4142  return false;
4143  } else {
4144  return false;
4145  }
4146 
4147  return true;
4148 }
4149 
4150 static int
4151 check_null_access_log(CustomLog *customlog_definitions)
4152 {
4153  return customlog_definitions == NULL;
4154 }
4155 
4156 static void
4157 dump_access_log(StoreEntry * entry, const char *name, CustomLog * logs)
4158 {
4159  CustomLog *log;
4160 
4161  for (log = logs; log; log = log->next) {
4162  storeAppendPrintf(entry, "%s ", name);
4163 
4164  switch (log->type) {
4165 
4167  storeAppendPrintf(entry, "%s logformat=%s", log->filename, log->logFormat->name);
4168  break;
4169 
4170  case Log::Format::CLF_NONE:
4171  storeAppendPrintf(entry, "logformat=none");
4172  break;
4173 
4175  // this is the default, no need to add to the dump
4176  //storeAppendPrintf(entry, "%s logformat=squid", log->filename);
4177  break;
4178 
4180  storeAppendPrintf(entry, "%s logformat=combined", log->filename);
4181  break;
4182 
4184  storeAppendPrintf(entry, "%s logformat=common", log->filename);
4185  break;
4186 
4187 #if ICAP_CLIENT
4189  storeAppendPrintf(entry, "%s logformat=icap_squid", log->filename);
4190  break;
4191 #endif
4193  storeAppendPrintf(entry, "%s logformat=useragent", log->filename);
4194  break;
4195 
4197  storeAppendPrintf(entry, "%s logformat=referrer", log->filename);
4198  break;
4199 
4201  break;
4202  }
4203 
4204  // default is on-error=die
4205  if (!log->fatal)
4206  storeAppendPrintf(entry, " on-error=drop");
4207 
4208  // default: 64KB
4209  if (log->bufferSize != 64*1024)
4210  storeAppendPrintf(entry, " buffer-size=%" PRIuSIZE, log->bufferSize);
4211 
4212  if (log->rotateCount >= 0)
4213  storeAppendPrintf(entry, " rotate=%d", log->rotateCount);
4214 
4215  if (log->aclList)
4216  dump_acl_list(entry, log->aclList);
4217 
4218  storeAppendPrintf(entry, "\n");
4219  }
4220 }
4221 
4222 static void
4224 {
4225  while (*definitions) {
4226  CustomLog *log = *definitions;
4227  *definitions = log->next;
4228 
4229  log->logFormat = NULL;
4231 
4232  if (log->aclList)
4233  aclDestroyAclList(&log->aclList);
4234 
4235  safe_free(log->filename);
4236 
4237  xfree(log);
4238  }
4239 }
4240 
4241 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4242 static bool
4244 parseNamedIntList(const char *data, const String &name, std::vector<int> &list)
4245 {
4246  if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) {
4247  data += name.size();
4248  if (*data == '=') {
4249  while (true) {
4250  ++data;
4251  int value = 0;
4252  if (!StringToInt(data, value, &data, 10))
4253  break;
4254  list.push_back(value);
4255  if (*data == '\0' || *data != ',')
4256  break;
4257  }
4258  }
4259  }
4260  return data && *data == '\0';
4261 }
4262 #endif
4263 
4264 static void
4265 parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4266 {
4267 #if !HAVE_CPU_AFFINITY
4268  debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " <<
4269  "support, do not set 'cpu_affinity_map'");
4270  self_destruct();
4271 
4272 #else /* HAVE_CPU_AFFINITY */
4273  if (!*cpuAffinityMap)
4274  *cpuAffinityMap = new CpuAffinityMap;
4275 
4276  const char *const pToken = ConfigParser::NextToken();
4277  const char *const cToken = ConfigParser::NextToken();
4278  std::vector<int> processes, cores;
4279  if (!parseNamedIntList(pToken, "process_numbers", processes)) {
4280  debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " <<
4281  "in 'cpu_affinity_map'");
4282  self_destruct();
4283  } else if (!parseNamedIntList(cToken, "cores", cores)) {
4284  debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " <<
4285  "'cpu_affinity_map'");
4286  self_destruct();
4287  } else if (!(*cpuAffinityMap)->add(processes, cores)) {
4288  debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " <<
4289  "process_numbers and cores lists differ in length or " <<
4290  "contain numbers <= 0");
4291  self_destruct();
4292  }
4293 #endif
4294 }
4295 
4296 static void
4297 dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap)
4298 {
4299  if (cpuAffinityMap) {
4300  storeAppendPrintf(entry, "%s process_numbers=", name);
4301  for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4302  storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4303  cpuAffinityMap->processes()[i]);
4304  }
4305  storeAppendPrintf(entry, " cores=");
4306  for (size_t i = 0; i < cpuAffinityMap->cores().size(); ++i) {
4307  storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4308  cpuAffinityMap->cores()[i]);
4309  }
4310  storeAppendPrintf(entry, "\n");
4311  }
4312 }
4313 
4314 static void
4315 free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4316 {
4317  delete *cpuAffinityMap;
4318  *cpuAffinityMap = NULL;
4319 }
4320 
4321 #if USE_ADAPTATION
4322 
4323 static void
4325 {
4327 }
4328 
4329 static void
4331 {
4333 }
4334 
4335 static void
4337 {
4338  Adaptation::Config::ParseAccess(LegacyParser);
4339 }
4340 #endif /* USE_ADAPTATION */
4341 
4342 #if ICAP_CLIENT
4343 
4344 static void
4346 {
4347  cfg->parseService();
4348 }
4349 
4350 static void
4352 {
4353  cfg->freeService();
4354 }
4355 
4356 static void
4357 dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
4358 {
4359  cfg.dumpService(entry, name);
4360 }
4361 
4362 static void
4364 {
4365  debugs(93, DBG_CRITICAL, "WARNING: 'icap_class' is deprecated. " <<
4366  "Use 'adaptation_service_set' instead");
4368 }
4369 
4370 static void
4372 {
4373  debugs(93, DBG_CRITICAL, "WARNING: 'icap_access' is deprecated. " <<
4374  "Use 'adaptation_access' instead");
4375  Adaptation::Config::ParseAccess(LegacyParser);
4376 }
4377 
4378 #endif
4379 
4380 #if USE_ECAP
4381 
4382 static void
4384 {
4385  cfg->parseService();
4386 }
4387 
4388 static void
4390 {
4391  cfg->freeService();
4392 }
4393 
4394 static void
4395 dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
4396 {
4397  cfg.dumpService(entry, name);
4398 }
4399 
4400 #endif /* USE_ECAP */
4401 
4402 #if ICAP_CLIENT
4404 {
4405  char *token;
4406  time_t d;
4407  time_t m;
4409 
4410  if ((token = ConfigParser::NextToken()) == NULL)
4411  return;
4412 
4413  if (strcmp(token,"in") != 0) {
4414  debugs(3, DBG_CRITICAL, "expecting 'in' on'" << config_input_line << "'");
4415  self_destruct();
4416  return;
4417  }
4418 
4419  if ((token = ConfigParser::NextToken()) == NULL) {
4420  self_destruct();
4421  return;
4422  }
4423 
4424  d = static_cast<time_t> (xatoi(token));
4425 
4426  m = static_cast<time_t> (1);
4427 
4428  if (0 == d)
4429  (void) 0;
4430  else if ((token = ConfigParser::NextToken()) == NULL) {
4431  debugs(3, DBG_CRITICAL, "No time-units on '" << config_input_line << "'");
4432  self_destruct();
4433  return;
4434  } else if ((m = parseTimeUnits(token, false)) == 0) {
4435  self_destruct();
4436  return;
4437  }
4438 
4439  cfg->oldest_service_failure = (m * d);
4440 }
4441 
4442 static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg)
4443 {
4444  storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit);
4445  if (cfg.oldest_service_failure > 0) {
4446  storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure);
4447  }
4448  storeAppendPrintf(entry, "\n");
4449 }
4450 
4452 {
4453  cfg->oldest_service_failure = 0;
4454  cfg->service_failure_limit = 0;
4455 }
4456 #endif
4457 
4458 #if USE_OPENSSL
4460 {
4461  char *al;
4463  if ((al = ConfigParser::NextToken()) == NULL) {
4464  xfree(ca);
4465  self_destruct();
4466  return;
4467  }
4468 
4469  const char *param;
4470  if ( char *s = strchr(al, '{')) {
4471  *s = '\0'; // terminate the al string
4472  ++s;
4473  param = s;
4474  s = strchr(s, '}');
4475  if (!s) {
4476  xfree(ca);
4477  self_destruct();
4478  return;
4479  }
4480  *s = '\0';
4481  } else
4482  param = NULL;
4483 
4484  if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidAfter]) == 0) {
4485  ca->alg = Ssl::algSetValidAfter;
4486  ca->param = xstrdup("on");
4487  } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidBefore]) == 0) {
4489  ca->param = xstrdup("on");
4490  } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetCommonName]) == 0) {
4491  ca->alg = Ssl::algSetCommonName;
4492  if (param) {
4493  if (strlen(param) > 64) {
4494  debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param << "} : using common name longer than 64 bytes is not supported");
4495  xfree(ca);
4496  self_destruct();
4497  return;
4498  }
4499  ca->param = xstrdup(param);
4500  }
4501  } else {
4502  debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al);
4503  xfree(ca);
4504  self_destruct();
4505  return;
4506  }
4507 
4508  aclParseAclList(LegacyParser, &ca->aclList, al);
4509 
4510  while (*cert_adapt)
4511  cert_adapt = &(*cert_adapt)->next;
4512 
4513  *cert_adapt = ca;
4514 }
4515 
4516 static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt)
4517 {
4518  for (sslproxy_cert_adapt *ca = cert_adapt; ca != NULL; ca = ca->next) {
4519  storeAppendPrintf(entry, "%s ", name);
4520  storeAppendPrintf(entry, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca->alg), ca->param);
4521  if (ca->aclList)
4522  dump_acl_list(entry, ca->aclList);
4523  storeAppendPrintf(entry, "\n");
4524  }
4525 }
4526 
4528 {
4529  while (*cert_adapt) {
4530  sslproxy_cert_adapt *ca = *cert_adapt;
4531  *cert_adapt = ca->next;
4532  safe_free(ca->param);
4533 
4534  if (ca->aclList)
4535  aclDestroyAclList(&ca->aclList);
4536 
4537  safe_free(ca);
4538  }
4539 }
4540 
4542 {
4543  char *al;
4545  if ((al = ConfigParser::NextToken()) == NULL) {
4546  xfree(cs);
4547  self_destruct();
4548  return;
4549  }
4550 
4551  if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignTrusted]) == 0)
4552  cs->alg = Ssl::algSignTrusted;
4553  else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignUntrusted]) == 0)
4554  cs->alg = Ssl::algSignUntrusted;
4555  else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignSelf]) == 0)
4556  cs->alg = Ssl::algSignSelf;
4557  else {
4558  debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al);
4559  xfree(cs);
4560  self_destruct();
4561  return;
4562  }
4563 
4564  aclParseAclList(LegacyParser, &cs->aclList, al);
4565 
4566  while (*cert_sign)
4567  cert_sign = &(*cert_sign)->next;
4568 
4569  *cert_sign = cs;
4570 }
4571 
4572 static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign)
4573 {
4574  sslproxy_cert_sign *cs;
4575  for (cs = cert_sign; cs != NULL; cs = cs->next) {
4576  storeAppendPrintf(entry, "%s ", name);
4577  storeAppendPrintf(entry, "%s ", Ssl::certSignAlgorithm(cs->alg));
4578  if (cs->aclList)
4579  dump_acl_list(entry, cs->aclList);
4580  storeAppendPrintf(entry, "\n");
4581  }
4582 }
4583 
4585 {
4586  while (*cert_sign) {
4587  sslproxy_cert_sign *cs = *cert_sign;
4588  *cert_sign = cs->next;
4589 
4590  if (cs->aclList)
4591  aclDestroyAclList(&cs->aclList);
4592 
4593  safe_free(cs);
4594  }
4595 }
4596 
4598 {
4599 public:
4601  /* RegisteredRunner API */
4602  virtual void finalizeConfig();
4603 };
4604 
4606 
4608 
4609 void
4611 {
4612  if (lastDeprecatedRule != Ssl::bumpEnd) {
4613  assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone);
4614  static char buf[1024];
4615  if (lastDeprecatedRule == Ssl::bumpClientFirst) {
4616  strcpy(buf, "ssl_bump deny all");
4617  debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated implicit "
4618  "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4619  "must not use implicit rules. Update your ssl_bump rules.");
4620  } else {
4621  strcpy(buf, "ssl_bump allow all");
4622  debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated implicit "
4623  "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4624  "inferior to the newer server-first bumping mode. New ssl_bump"
4625  " configurations must not use implicit rules. Update your ssl_bump rules.");
4626  }
4627  parse_line(buf);
4628  }
4629 }
4630 
4631 static void parse_sslproxy_ssl_bump(acl_access **ssl_bump)
4632 {
4633  typedef const char *BumpCfgStyle;
4634  BumpCfgStyle bcsNone = NULL;
4635  BumpCfgStyle bcsNew = "new client/server-first/none";
4636  BumpCfgStyle bcsOld = "deprecated allow/deny";
4637  static BumpCfgStyle bumpCfgStyleLast = bcsNone;
4638  BumpCfgStyle bumpCfgStyleNow = bcsNone;
4639  char *bm;
4640  if ((bm = ConfigParser::NextToken()) == NULL) {
4641  self_destruct();
4642  return;
4643  }
4644 
4645  // if this is the first rule proccessed
4646  if (*ssl_bump == NULL) {
4647  bumpCfgStyleLast = bcsNone;
4649  }
4650 
4652 
4653  if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpClientFirst]) == 0) {
4654  action.kind = Ssl::bumpClientFirst;
4655  bumpCfgStyleNow = bcsNew;
4656  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpServerFirst]) == 0) {
4657  action.kind = Ssl::bumpServerFirst;
4658  bumpCfgStyleNow = bcsNew;
4659  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpPeek]) == 0) {
4660  action.kind = Ssl::bumpPeek;
4661  bumpCfgStyleNow = bcsNew;
4662  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpStare]) == 0) {
4663  action.kind = Ssl::bumpStare;
4664  bumpCfgStyleNow = bcsNew;
4665  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpSplice]) == 0) {
4666  action.kind = Ssl::bumpSplice;
4667  bumpCfgStyleNow = bcsNew;
4668  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpBump]) == 0) {
4669  action.kind = Ssl::bumpBump;
4670  bumpCfgStyleNow = bcsNew;
4671  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpTerminate]) == 0) {
4672  action.kind = Ssl::bumpTerminate;
4673  bumpCfgStyleNow = bcsNew;
4674  } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpNone]) == 0) {
4675  action.kind = Ssl::bumpNone;
4676  bumpCfgStyleNow = bcsNew;
4677  } else if (strcmp(bm, "allow") == 0) {
4678  debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated "
4679  "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4680  "is usually inferior to the newer server-first "
4681  "bumping mode. Update your ssl_bump rules.");
4682  action.kind = Ssl::bumpClientFirst;
4683  bumpCfgStyleNow = bcsOld;
4685  } else if (strcmp(bm, "deny") == 0) {
4686  debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated "
4687  "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4688  "your ssl_bump rules.");
4689  action.kind = Ssl::bumpNone;
4690  bumpCfgStyleNow = bcsOld;
4692  } else {
4693  debugs(3, DBG_CRITICAL, "FATAL: unknown ssl_bump mode: " << bm);
4694  self_destruct();
4695  return;
4696  }
4697 
4698  if (bumpCfgStyleLast != bcsNone && bumpCfgStyleNow != bumpCfgStyleLast) {
4699  debugs(3, DBG_CRITICAL, "FATAL: do not mix " << bumpCfgStyleNow << " actions with " <<
4700  bumpCfgStyleLast << " actions. Update your ssl_bump rules.");
4701  self_destruct();
4702  return;
4703  }
4704 
4705  bumpCfgStyleLast = bumpCfgStyleNow;
4706 
4707  // empty rule OK
4708  ParseAclWithAction(ssl_bump, action, "ssl_bump");
4709 }
4710 
4711 static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump)
4712 {
4713  if (ssl_bump)
4714  dump_SBufList(entry, ssl_bump->treeDump(name, [](const allow_t &action) {
4715  return Ssl::BumpModeStr.at(action.kind);
4716  }));
4717 }
4718 
4719 static void free_sslproxy_ssl_bump(acl_access **ssl_bump)
4720 {
4721  free_acl_access(ssl_bump);
4722 }
4723 
4724 #endif
4725 
4726 static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers)
4727 {
4728  if (!headers)
4729  return;
4730 
4731  for (HeaderWithAclList::iterator hwa = headers->begin(); hwa != headers->end(); ++hwa) {
4732  storeAppendPrintf(entry, "%s %s %s", name, hwa->fieldName.c_str(), hwa->fieldValue.c_str());
4733  if (hwa->aclList)
4734  dump_acl_list(entry, hwa->aclList);
4735  storeAppendPrintf(entry, "\n");
4736  }
4737 }
4738 
4740 {
4741  char *fn;
4742  if (!*headers) {
4743  *headers = new HeaderWithAclList;
4744  }
4745  if ((fn = ConfigParser::NextToken()) == NULL) {
4746  self_destruct();
4747  return;
4748  }
4749  HeaderWithAcl hwa;
4750  hwa.fieldName = fn;
4752  if (hwa.fieldId == Http::HdrType::BAD_HDR)
4754 
4755  Format::Format *nlf = new ::Format::Format("hdrWithAcl");
4759  hwa.fieldValue = buf.termedBuf();
4761  if (hwa.quoted) {
4762  if (!nlf->parse(hwa.fieldValue.c_str())) {
4763  self_destruct();
4764  return;
4765  }
4766  hwa.valueFormat = nlf;
4767  } else
4768  delete nlf;
4769  aclParseAclList(LegacyParser, &hwa.aclList, (hwa.fieldName + ':' + hwa.fieldValue).c_str());
4770  (*headers)->push_back(hwa);
4771 }
4772 
4774 {
4775  if (!(*header))
4776  return;
4777 
4778  for (HeaderWithAclList::iterator hwa = (*header)->begin(); hwa != (*header)->end(); ++hwa) {
4779  if (hwa->aclList)
4780  aclDestroyAclList(&hwa->aclList);
4781 
4782  if (hwa->valueFormat) {
4783  delete hwa->valueFormat;
4784  hwa->valueFormat = NULL;
4785  }
4786  }
4787  delete *header;
4788  *header = NULL;
4789 }
4790 
4791 static void parse_note(Notes *notes)
4792 {
4793  assert(notes);
4794  notes->parse(LegacyParser);
4795 }
4796 
4797 static void dump_note(StoreEntry *entry, const char *name, Notes &notes)
4798 {
4799  notes.dump(entry, name);
4800 }
4801 
4802 static void free_note(Notes *notes)
4803 {
4804  notes->clean();
4805 }
4806 
4807 static bool FtpEspvDeprecated = false;
4808 static void parse_ftp_epsv(acl_access **ftp_epsv)
4809 {
4810  allow_t ftpEpsvDeprecatedAction;
4811  bool ftpEpsvIsDeprecatedRule = false;
4812 
4813  char *t = ConfigParser::PeekAtToken();
4814  if (!t) {
4815  self_destruct();
4816  return;
4817  }
4818 
4819  if (!strcmp(t, "off")) {
4820  (void)ConfigParser::NextToken();
4821  ftpEpsvIsDeprecatedRule = true;
4822  ftpEpsvDeprecatedAction = allow_t(ACCESS_DENIED);
4823  } else if (!strcmp(t, "on")) {
4824  (void)ConfigParser::NextToken();
4825  ftpEpsvIsDeprecatedRule = true;
4826  ftpEpsvDeprecatedAction = allow_t(ACCESS_ALLOWED);
4827  }
4828 
4829  // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4830  // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4831  // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4832  // then abort
4833  if ((!ftpEpsvIsDeprecatedRule && FtpEspvDeprecated) ||
4834  (ftpEpsvIsDeprecatedRule && !FtpEspvDeprecated && *ftp_epsv != NULL)) {
4835  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.");
4836  self_destruct();
4837  return;
4838  }
4839 
4840  if (ftpEpsvIsDeprecatedRule) {
4841  // overwrite previous ftp_epsv lines
4842  delete *ftp_epsv;
4843  *ftp_epsv = nullptr;
4844 
4845  if (ftpEpsvDeprecatedAction == allow_t(ACCESS_DENIED)) {
4846  if (ACL *a = ACL::FindByName("all"))
4847  ParseAclWithAction(ftp_epsv, ftpEpsvDeprecatedAction, "ftp_epsv", a);
4848  else {
4849  self_destruct();
4850  return;
4851  }
4852  }
4853  FtpEspvDeprecated = true;
4854  } else {
4855  aclParseAccessLine(cfg_directive, LegacyParser, ftp_epsv);
4856  }
4857 }
4858 
4859 static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv)
4860 {
4861  if (ftp_epsv)
4862  dump_SBufList(entry, ftp_epsv->treeDump(name, Acl::AllowOrDeny));
4863 }
4864 
4865 static void free_ftp_epsv(acl_access **ftp_epsv)
4866 {
4867  free_acl_access(ftp_epsv);
4868  FtpEspvDeprecated = false;
4869 }
4870 
4871 static void
4873 {
4874  const auto tval = parseTimeLine(T_SECOND_STR, false, true);
4875  Config.Timeout.urlRewrite = static_cast<time_t>(tval/1000);
4876 
4877  char *key, *value;
4878  while(ConfigParser::NextKvPair(key, value)) {
4879  if (strcasecmp(key, "on_timeout") == 0) {
4880  if (strcasecmp(value, "bypass") == 0)
4881  config->action = toutActBypass;
4882  else if (strcasecmp(value, "fail") == 0)
4883  config->action = toutActFail;
4884  else if (strcasecmp(value, "retry") == 0)
4885  config->action = toutActRetry;
4886  else if (strcasecmp(value, "use_configured_response") == 0) {
4888  } else {
4889  debugs(3, DBG_CRITICAL, "FATAL: unsupported \"on_timeout\" action: " << value);
4890  self_destruct();
4891  return;
4892  }
4893  } else if (strcasecmp(key, "response") == 0) {
4894  config->response = xstrdup(value);
4895  } else {
4896  debugs(3, DBG_CRITICAL, "FATAL: unsupported option " << key);
4897  self_destruct();
4898  return;
4899  }
4900  }
4901 
4902  if (config->action == toutActUseConfiguredResponse && !config->response) {
4903  debugs(3, DBG_CRITICAL, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4904  self_destruct();
4905  }
4906 
4907  if (config->action != toutActUseConfiguredResponse && config->response) {
4908  debugs(3, DBG_CRITICAL, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4909  self_destruct();
4910  }
4911 }
4912 
4913 static void
4915 {
4916  const char *onTimedOutActions[] = {"bypass", "fail", "retry", "use_configured_response"};
4917  assert(config.action >= 0 && config.action <= toutActUseConfiguredResponse);
4918 
4919  dump_time_t(entry, name, Config.Timeout.urlRewrite);
4920  storeAppendPrintf(entry, " on_timeout=%s", onTimedOutActions[config.action]);
4921 
4922  if (config.response)
4923  storeAppendPrintf(entry, " response=\"%s\"", config.response);
4924 
4925  storeAppendPrintf(entry, "\n");
4926 }
4927 
4928 static void
4930 {
4932  config->action = 0;
4933  safe_free(config->response);
4934 }
4935 
4936 static void
4938 {
4939  int val = 0;
4940  parse_onoff(&val);
4941 
4942  // If quoted values is set to on then enable new strict mode parsing
4943  if (val) {
4945  ConfigParser::StrictMode = true;
4946  } else {
4948  ConfigParser::StrictMode = false;
4949  }
4950 }
4951 
4952 static void
4953 dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool)
4954 {
4955  int val = ConfigParser::RecognizeQuotedValues ? 1 : 0;
4956  dump_onoff(entry, name, val);
4957 }
4958 
4959 static void
4961 {
4963  ConfigParser::StrictMode = false;
4964 }
4965 
4966 static void
4968 {
4969  char *tm;
4970  if ((tm = ConfigParser::NextToken()) == NULL) {
4971  self_destruct();
4972  return;
4973  }
4974 
4976  if (strcmp(tm, "tunnel") == 0)
4977  action.kind = 1;
4978  else if (strcmp(tm, "respond") == 0)
4979  action.kind = 2;
4980  else {
4981  debugs(3, DBG_CRITICAL, "FATAL: unknown on_unsupported_protocol mode: " << tm);
4982  self_destruct();
4983  return;
4984  }
4985 
4986  // empty rule OK
4987  ParseAclWithAction(access, action, "on_unsupported_protocol");
4988 }
4989 
4990 static void
4991 dump_on_unsupported_protocol(StoreEntry *entry, const char *name, acl_access *access)
4992 {
4993  static const std::vector<const char *> onErrorTunnelMode = {
4994  "none",
4995  "tunnel",
4996  "respond"
4997  };
4998  if (access) {
4999  SBufList lines = access->treeDump(name, [](const allow_t &action) {
5000  return onErrorTunnelMode.at(action.kind);
5001  });
5002  dump_SBufList(entry, lines);
5003  }
5004 }
5005 
5006 static void
5008 {
5009  free_acl_access(access);
5010 }
5011 
static void free_b_int64_t(int64_t *var)
Definition: cache_cf.cc:3105
#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:4389
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:3142
static size_t parseBytesUnits(const char *unit)
Definition: cache_cf.cc:1307
int xatoi(const char *token)
Definition: Parsing.cc:43
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
static void parse_string(char **)
Definition: cache_cf.cc:2904
int GetInteger(void)
Definition: Parsing.cc:142
char * login
Definition: CachePeer.h:171
static void free_authparam(Auth::ConfigVector *cfg)
Definition: cache_cf.cc:1859
representation of a custom log directive.
Definition: CustomLog.h:22
static bool setLogformat(CustomLog *cl, const char *name, const bool dieWhenMissing)
Definition: cache_cf.cc:4093
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:3306
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
static void ParseAclWithAction(acl_access **access, const allow_t &action, const char *desc, ACL *acl=nullptr)
Definition: cache_cf.cc:1910
bool mcast_siblings
Definition: CachePeer.h:117
static void dump_access_log(StoreEntry *entry, const char *name, CustomLog *definitions)
Definition: cache_cf.cc:4157
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:2918
bool htcp_no_clr
Definition: CachePeer.h:91
const char * wordlistAdd(wordlist **list, const char *key)
Definition: wordlist.cc:25
static void parse_adaptation_access_type()
Definition: cache_cf.cc:4336
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:4807
static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
Definition: cache_cf.cc:4265
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:2522
static unsigned short GetService(const char *proto)
Definition: cache_cf.cc:2086
void parse_time_t(time_t *var)
Definition: cache_cf.cc:2977
static void dump_onoff(StoreEntry *entry, const char *name, int var)
Definition: cache_cf.cc:2562
static void parse_YesNoNone(YesNoNone *option)
Definition: cache_cf.cc:3287
static void defaults_postscriptum(void)
static void free_time_msec(time_msec_t *var)
Definition: cache_cf.cc:3005
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:4802
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:4151
void parse_eol(char *volatile *var)
Definition: cache_cf.cc:2924
CachePeer * next
Definition: CachePeer.h:150
const char * appname_string
static void parse_acl_access(acl_access **head)
Definition: cache_cf.cc:1405
static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump)
Definition: cache_cf.cc:4711
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:4527
Definition: Acl.h:113
std::string fieldValue
HTTP header field value, possibly with macros.
Definition: SBuf.h:86
char * domain
Forced domain.
Definition: CachePeer.h:184
void setReplacement(const char *name, const char *replacementValue)
updates mangler for the named header with a replacement value
static void ReplaceSubstr(char *&str, int &len, unsigned substrIdx, unsigned substrLen, const char *newSubstr)
Definition: cache_cf.cc: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:4739
::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:3061
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:3045
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:2954
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:2999
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:3850
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:3295
#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:3136
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:2639
static void free_ssize_t(ssize_t *var)
Definition: cache_cf.cc:3099
#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:3130
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:2984
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:3411
static void parse_delay_pool_count(DelayConfig *cfg)
Definition: cache_cf.cc:1660
void parse_onoff(int *var)
Definition: cache_cf.cc:2568
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
list of address-based ACLs.
Definition: Address.h:19
int64_t maxObjectSize
Definition: SquidConfig.h:266