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