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