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