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