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