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