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