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