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