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