]> git.ipfire.org Git - thirdparty/squid.git/blob - src/cache_cf.cc
Author: Mark Nottingham <mnot@pobox.com>
[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 #if USE_CACHE_DIGESTS
1781
1782 } else if (!strncasecmp(token, "digest-url=", 11)) {
1783 p->digest_url = xstrdup(token + 11);
1784 #endif
1785
1786 } else if (!strcasecmp(token, "allow-miss")) {
1787 p->options.allow_miss = 1;
1788 } else if (!strncasecmp(token, "max-conn=", 9)) {
1789 p->max_conn = xatoi(token + 9);
1790 } else if (!strcasecmp(token, "originserver")) {
1791 p->options.originserver = 1;
1792 } else if (!strncasecmp(token, "name=", 5)) {
1793 safe_free(p->name);
1794
1795 if (token[5])
1796 p->name = xstrdup(token + 5);
1797 } else if (!strncasecmp(token, "forceddomain=", 13)) {
1798 safe_free(p->domain);
1799
1800 if (token[13])
1801 p->domain = xstrdup(token + 13);
1802
1803 #if USE_SSL
1804
1805 } else if (strcmp(token, "ssl") == 0) {
1806 p->use_ssl = 1;
1807 } else if (strncmp(token, "sslcert=", 8) == 0) {
1808 safe_free(p->sslcert);
1809 p->sslcert = xstrdup(token + 8);
1810 } else if (strncmp(token, "sslkey=", 7) == 0) {
1811 safe_free(p->sslkey);
1812 p->sslkey = xstrdup(token + 7);
1813 } else if (strncmp(token, "sslversion=", 11) == 0) {
1814 p->sslversion = atoi(token + 11);
1815 } else if (strncmp(token, "ssloptions=", 11) == 0) {
1816 safe_free(p->ssloptions);
1817 p->ssloptions = xstrdup(token + 11);
1818 } else if (strncmp(token, "sslcipher=", 10) == 0) {
1819 safe_free(p->sslcipher);
1820 p->sslcipher = xstrdup(token + 10);
1821 } else if (strncmp(token, "sslcafile=", 10) == 0) {
1822 safe_free(p->sslcafile);
1823 p->sslcafile = xstrdup(token + 10);
1824 } else if (strncmp(token, "sslcapath=", 10) == 0) {
1825 safe_free(p->sslcapath);
1826 p->sslcapath = xstrdup(token + 10);
1827 } else if (strncmp(token, "sslcrlfile=", 11) == 0) {
1828 safe_free(p->sslcrlfile);
1829 p->sslcapath = xstrdup(token + 10);
1830 } else if (strncmp(token, "sslflags=", 9) == 0) {
1831 safe_free(p->sslflags);
1832 p->sslflags = xstrdup(token + 9);
1833 } else if (strncmp(token, "ssldomain=", 10) == 0) {
1834 safe_free(p->ssldomain);
1835 p->ssldomain = xstrdup(token + 10);
1836 #endif
1837
1838 } else if (strcmp(token, "front-end-https") == 0) {
1839 p->front_end_https = 1;
1840 } else if (strcmp(token, "front-end-https=on") == 0) {
1841 p->front_end_https = 1;
1842 } else if (strcmp(token, "front-end-https=auto") == 0) {
1843 p->front_end_https = 2;
1844 } else if (strcmp(token, "connection-auth=off") == 0) {
1845 p->connection_auth = 0;
1846 } else if (strcmp(token, "connection-auth") == 0) {
1847 p->connection_auth = 1;
1848 } else if (strcmp(token, "connection-auth=on") == 0) {
1849 p->connection_auth = 1;
1850 } else if (strcmp(token, "connection-auth=auto") == 0) {
1851 p->connection_auth = 2;
1852 } else {
1853 debugs(3, 0, "parse_peer: token='" << token << "'");
1854 self_destruct();
1855 }
1856 }
1857
1858 if (peerFindByName(p->name))
1859 fatalf("ERROR: cache_peer %s specified twice\n", p->name);
1860
1861 if (p->weight < 1)
1862 p->weight = 1;
1863
1864 p->icp.version = ICP_VERSION_CURRENT;
1865
1866 p->test_fd = -1;
1867
1868 #if USE_CACHE_DIGESTS
1869
1870 if (!p->options.no_digest) {
1871 /* XXX This looks odd.. who has the original pointer
1872 * then?
1873 */
1874 PeerDigest *pd = peerDigestCreate(p);
1875 p->digest = cbdataReference(pd);
1876 }
1877
1878 #endif
1879
1880 p->index = ++Config.npeers;
1881
1882 while (*head != NULL)
1883 head = &(*head)->next;
1884
1885 *head = p;
1886
1887 peerClearRRStart();
1888 }
1889
1890 static void
1891 free_peer(peer ** P)
1892 {
1893 peer *p;
1894
1895 while ((p = *P) != NULL) {
1896 *P = p->next;
1897 #if USE_CACHE_DIGESTS
1898
1899 cbdataReferenceDone(p->digest);
1900 #endif
1901
1902 cbdataFree(p);
1903 }
1904
1905 Config.npeers = 0;
1906 }
1907
1908 static void
1909 dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list)
1910 {
1911 wordlist *w;
1912
1913 while (list != NULL) {
1914 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
1915 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
1916 else
1917 storeAppendPrintf(entry, "%s %s", name, list->passwd);
1918
1919 for (w = list->actions; w != NULL; w = w->next) {
1920 storeAppendPrintf(entry, " %s", w->key);
1921 }
1922
1923 storeAppendPrintf(entry, "\n");
1924 list = list->next;
1925 }
1926 }
1927
1928 static void
1929 parse_cachemgrpasswd(cachemgr_passwd ** head)
1930 {
1931 char *passwd = NULL;
1932 wordlist *actions = NULL;
1933 cachemgr_passwd *p;
1934 cachemgr_passwd **P;
1935 parse_string(&passwd);
1936 parse_wordlist(&actions);
1937 p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd)));
1938 p->passwd = passwd;
1939 p->actions = actions;
1940
1941 for (P = head; *P; P = &(*P)->next) {
1942 /*
1943 * See if any of the actions from this line already have a
1944 * password from previous lines. The password checking
1945 * routines in cache_manager.c take the the password from
1946 * the first cachemgr_passwd struct that contains the
1947 * requested action. Thus, we should warn users who might
1948 * think they can have two passwords for the same action.
1949 */
1950 wordlist *w;
1951 wordlist *u;
1952
1953 for (w = (*P)->actions; w; w = w->next) {
1954 for (u = actions; u; u = u->next) {
1955 if (strcmp(w->key, u->key))
1956 continue;
1957
1958 debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password");
1959 }
1960 }
1961 }
1962
1963 *P = p;
1964 }
1965
1966 static void
1967 free_cachemgrpasswd(cachemgr_passwd ** head)
1968 {
1969 cachemgr_passwd *p;
1970
1971 while ((p = *head) != NULL) {
1972 *head = p->next;
1973 xfree(p->passwd);
1974 wordlistDestroy(&p->actions);
1975 xfree(p);
1976 }
1977 }
1978
1979 static void
1980 dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var)
1981 {
1982 acl_name_list *a;
1983
1984 while (var != NULL) {
1985 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
1986
1987 for (a = var->acl_list; a != NULL; a = a->next)
1988 storeAppendPrintf(entry, " %s", a->name);
1989
1990 storeAppendPrintf(entry, "\n");
1991
1992 var = var->next;
1993 }
1994 }
1995
1996 static void
1997 parse_denyinfo(acl_deny_info_list ** var)
1998 {
1999 aclParseDenyInfoLine(var);
2000 }
2001
2002 void
2003 free_denyinfo(acl_deny_info_list ** list)
2004 {
2005 acl_deny_info_list *a = NULL;
2006 acl_deny_info_list *a_next = NULL;
2007 acl_name_list *l = NULL;
2008 acl_name_list *l_next = NULL;
2009
2010 for (a = *list; a; a = a_next) {
2011 for (l = a->acl_list; l; l = l_next) {
2012 l_next = l->next;
2013 memFree(l, MEM_ACL_NAME_LIST);
2014 l = NULL;
2015 }
2016
2017 a_next = a->next;
2018 memFree(a, MEM_ACL_DENY_INFO_LIST);
2019 a = NULL;
2020 }
2021
2022 *list = NULL;
2023 }
2024
2025 static void
2026 parse_peer_access(void)
2027 {
2028 char *host = NULL;
2029 peer *p;
2030
2031 if (!(host = strtok(NULL, w_space)))
2032 self_destruct();
2033
2034 if ((p = peerFindByName(host)) == NULL) {
2035 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2036 return;
2037 }
2038
2039 aclParseAccessLine(LegacyParser, &p->access);
2040 }
2041
2042 static void
2043 parse_hostdomain(void)
2044 {
2045 char *host = NULL;
2046 char *domain = NULL;
2047
2048 if (!(host = strtok(NULL, w_space)))
2049 self_destruct();
2050
2051 while ((domain = strtok(NULL, list_sep))) {
2052 domain_ping *l = NULL;
2053 domain_ping **L = NULL;
2054 peer *p;
2055
2056 if ((p = peerFindByName(host)) == NULL) {
2057 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2058 continue;
2059 }
2060
2061 l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping)));
2062 l->do_ping = 1;
2063
2064 if (*domain == '!') { /* check for !.edu */
2065 l->do_ping = 0;
2066 domain++;
2067 }
2068
2069 l->domain = xstrdup(domain);
2070
2071 for (L = &(p->peer_domain); *L; L = &((*L)->next));
2072 *L = l;
2073 }
2074 }
2075
2076 static void
2077 parse_hostdomaintype(void)
2078 {
2079 char *host = NULL;
2080 char *type = NULL;
2081 char *domain = NULL;
2082
2083 if (!(host = strtok(NULL, w_space)))
2084 self_destruct();
2085
2086 if (!(type = strtok(NULL, w_space)))
2087 self_destruct();
2088
2089 while ((domain = strtok(NULL, list_sep))) {
2090 domain_type *l = NULL;
2091 domain_type **L = NULL;
2092 peer *p;
2093
2094 if ((p = peerFindByName(host)) == NULL) {
2095 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2096 return;
2097 }
2098
2099 l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type)));
2100 l->type = parseNeighborType(type);
2101 l->domain = xstrdup(domain);
2102
2103 for (L = &(p->typelist); *L; L = &((*L)->next));
2104 *L = l;
2105 }
2106 }
2107
2108 static void
2109 dump_int(StoreEntry * entry, const char *name, int var)
2110 {
2111 storeAppendPrintf(entry, "%s %d\n", name, var);
2112 }
2113
2114 void
2115 parse_int(int *var)
2116 {
2117 int i;
2118 i = GetInteger();
2119 *var = i;
2120 }
2121
2122 static void
2123 free_int(int *var)
2124 {
2125 *var = 0;
2126 }
2127
2128 static void
2129 dump_onoff(StoreEntry * entry, const char *name, int var)
2130 {
2131 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
2132 }
2133
2134 void
2135 parse_onoff(int *var)
2136 {
2137 char *token = strtok(NULL, w_space);
2138
2139 if (token == NULL)
2140 self_destruct();
2141
2142 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
2143 *var = 1;
2144 else
2145 *var = 0;
2146 }
2147
2148 #define free_onoff free_int
2149
2150 static void
2151 dump_tristate(StoreEntry * entry, const char *name, int var)
2152 {
2153 const char *state;
2154
2155 if (var > 0)
2156 state = "on";
2157 else if (var < 0)
2158 state = "warn";
2159 else
2160 state = "off";
2161
2162 storeAppendPrintf(entry, "%s %s\n", name, state);
2163 }
2164
2165 static void
2166 parse_tristate(int *var)
2167 {
2168 char *token = strtok(NULL, w_space);
2169
2170 if (token == NULL)
2171 self_destruct();
2172
2173 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
2174 *var = 1;
2175 else if (!strcasecmp(token, "warn"))
2176 *var = -1;
2177 else
2178 *var = 0;
2179 }
2180
2181 #define free_tristate free_int
2182
2183 static void
2184 dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head)
2185 {
2186 while (head != NULL) {
2187 storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n",
2188 name,
2189 head->flags.icase ? " -i" : null_string,
2190 head->pattern,
2191 (int) head->min / 60,
2192 (int) (100.0 * head->pct + 0.5),
2193 (int) head->max / 60);
2194
2195 if (head->flags.refresh_ims)
2196 storeAppendPrintf(entry, " refresh-ims");
2197
2198 #if HTTP_VIOLATIONS
2199
2200 if (head->flags.override_expire)
2201 storeAppendPrintf(entry, " override-expire");
2202
2203 if (head->flags.override_lastmod)
2204 storeAppendPrintf(entry, " override-lastmod");
2205
2206 if (head->flags.reload_into_ims)
2207 storeAppendPrintf(entry, " reload-into-ims");
2208
2209 if (head->flags.ignore_reload)
2210 storeAppendPrintf(entry, " ignore-reload");
2211
2212 if (head->flags.ignore_no_cache)
2213 storeAppendPrintf(entry, " ignore-no-cache");
2214
2215 if (head->flags.ignore_no_store)
2216 storeAppendPrintf(entry, " ignore-no-store");
2217
2218 if (head->flags.ignore_must_revalidate)
2219 storeAppendPrintf(entry, " ignore-must-revalidate");
2220
2221 if (head->flags.ignore_private)
2222 storeAppendPrintf(entry, " ignore-private");
2223
2224 if (head->flags.ignore_auth)
2225 storeAppendPrintf(entry, " ignore-auth");
2226
2227 #endif
2228
2229 storeAppendPrintf(entry, "\n");
2230
2231 head = head->next;
2232 }
2233 }
2234
2235 static void
2236 parse_refreshpattern(refresh_t ** head)
2237 {
2238 char *token;
2239 char *pattern;
2240 time_t min = 0;
2241 double pct = 0.0;
2242 time_t max = 0;
2243 int refresh_ims = 0;
2244 #if HTTP_VIOLATIONS
2245
2246 int override_expire = 0;
2247 int override_lastmod = 0;
2248 int reload_into_ims = 0;
2249 int ignore_reload = 0;
2250 int ignore_no_cache = 0;
2251 int ignore_no_store = 0;
2252 int ignore_must_revalidate = 0;
2253 int ignore_private = 0;
2254 int ignore_auth = 0;
2255 #endif
2256
2257 int i;
2258 refresh_t *t;
2259 regex_t comp;
2260 int errcode;
2261 int flags = REG_EXTENDED | REG_NOSUB;
2262
2263 if ((token = strtok(NULL, w_space)) == NULL) {
2264 self_destruct();
2265 return;
2266 }
2267
2268 if (strcmp(token, "-i") == 0) {
2269 flags |= REG_ICASE;
2270 token = strtok(NULL, w_space);
2271 } else if (strcmp(token, "+i") == 0) {
2272 flags &= ~REG_ICASE;
2273 token = strtok(NULL, w_space);
2274 }
2275
2276 if (token == NULL) {
2277 self_destruct();
2278 return;
2279 }
2280
2281 pattern = xstrdup(token);
2282
2283 i = GetInteger(); /* token: min */
2284
2285 min = (time_t) (i * 60); /* convert minutes to seconds */
2286
2287 i = GetInteger(); /* token: pct */
2288
2289 pct = (double) i / 100.0;
2290
2291 i = GetInteger(); /* token: max */
2292
2293 max = (time_t) (i * 60); /* convert minutes to seconds */
2294
2295 /* Options */
2296 while ((token = strtok(NULL, w_space)) != NULL) {
2297 if (!strcmp(token, "refresh-ims")) {
2298 refresh_ims = 1;
2299 #if HTTP_VIOLATIONS
2300
2301 } else if (!strcmp(token, "override-expire"))
2302 override_expire = 1;
2303 else if (!strcmp(token, "override-lastmod"))
2304 override_lastmod = 1;
2305 else if (!strcmp(token, "ignore-no-cache"))
2306 ignore_no_cache = 1;
2307 else if (!strcmp(token, "ignore-no-store"))
2308 ignore_no_store = 1;
2309 else if (!strcmp(token, "ignore-must-revalidate"))
2310 ignore_must_revalidate = 1;
2311 else if (!strcmp(token, "ignore-private"))
2312 ignore_private = 1;
2313 else if (!strcmp(token, "ignore-auth"))
2314 ignore_auth = 1;
2315 else if (!strcmp(token, "reload-into-ims")) {
2316 reload_into_ims = 1;
2317 refresh_nocache_hack = 1;
2318 /* tell client_side.c that this is used */
2319 } else if (!strcmp(token, "ignore-reload")) {
2320 ignore_reload = 1;
2321 refresh_nocache_hack = 1;
2322 /* tell client_side.c that this is used */
2323 #endif
2324
2325 } else
2326 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern << "': " << token);
2327 }
2328
2329 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
2330 char errbuf[256];
2331 regerror(errcode, &comp, errbuf, sizeof errbuf);
2332 debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2333 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
2334 return;
2335 }
2336
2337 pct = pct < 0.0 ? 0.0 : pct;
2338 max = max < 0 ? 0 : max;
2339 t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t)));
2340 t->pattern = (char *) xstrdup(pattern);
2341 t->compiled_pattern = comp;
2342 t->min = min;
2343 t->pct = pct;
2344 t->max = max;
2345
2346 if (flags & REG_ICASE)
2347 t->flags.icase = 1;
2348
2349 if (refresh_ims)
2350 t->flags.refresh_ims = 1;
2351
2352 #if HTTP_VIOLATIONS
2353
2354 if (override_expire)
2355 t->flags.override_expire = 1;
2356
2357 if (override_lastmod)
2358 t->flags.override_lastmod = 1;
2359
2360 if (reload_into_ims)
2361 t->flags.reload_into_ims = 1;
2362
2363 if (ignore_reload)
2364 t->flags.ignore_reload = 1;
2365
2366 if (ignore_no_cache)
2367 t->flags.ignore_no_cache = 1;
2368
2369 if (ignore_no_store)
2370 t->flags.ignore_no_store = 1;
2371
2372 if (ignore_must_revalidate)
2373 t->flags.ignore_must_revalidate = 1;
2374
2375 if (ignore_private)
2376 t->flags.ignore_private = 1;
2377
2378 if (ignore_auth)
2379 t->flags.ignore_auth = 1;
2380
2381 #endif
2382
2383 t->next = NULL;
2384
2385 while (*head)
2386 head = &(*head)->next;
2387
2388 *head = t;
2389
2390 safe_free(pattern);
2391 }
2392
2393 static void
2394 free_refreshpattern(refresh_t ** head)
2395 {
2396 refresh_t *t;
2397
2398 while ((t = *head) != NULL) {
2399 *head = t->next;
2400 safe_free(t->pattern);
2401 regfree(&t->compiled_pattern);
2402 safe_free(t);
2403 }
2404
2405 #if HTTP_VIOLATIONS
2406 refresh_nocache_hack = 0;
2407
2408 #endif
2409 }
2410
2411 static void
2412 dump_string(StoreEntry * entry, const char *name, char *var)
2413 {
2414 if (var != NULL)
2415 storeAppendPrintf(entry, "%s %s\n", name, var);
2416 }
2417
2418 static void
2419 parse_string(char **var)
2420 {
2421 char *token = strtok(NULL, w_space);
2422 safe_free(*var);
2423
2424 if (token == NULL)
2425 self_destruct();
2426
2427 *var = xstrdup(token);
2428 }
2429
2430 void
2431 ConfigParser::ParseString(char **var)
2432 {
2433 parse_string(var);
2434 }
2435
2436 void
2437 ConfigParser::ParseString(String *var)
2438 {
2439 char *token = strtok(NULL, w_space);
2440
2441 if (token == NULL)
2442 self_destruct();
2443
2444 var->reset(token);
2445 }
2446
2447 static void
2448 free_string(char **var)
2449 {
2450 safe_free(*var);
2451 }
2452
2453 void
2454 parse_eol(char *volatile *var)
2455 {
2456 unsigned char *token = (unsigned char *) strtok(NULL, null_string);
2457 safe_free(*var);
2458
2459 if (!token) {
2460 self_destruct();
2461 return;
2462 }
2463
2464 while (*token && xisspace(*token))
2465 token++;
2466
2467 if (!*token) {
2468 self_destruct();
2469 return;
2470 }
2471
2472 *var = xstrdup((char *) token);
2473 }
2474
2475 #define dump_eol dump_string
2476 #define free_eol free_string
2477
2478 static void
2479 dump_time_t(StoreEntry * entry, const char *name, time_t var)
2480 {
2481 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
2482 }
2483
2484 void
2485 parse_time_t(time_t * var)
2486 {
2487 parseTimeLine(var, T_SECOND_STR);
2488 }
2489
2490 static void
2491 free_time_t(time_t * var)
2492 {
2493 *var = 0;
2494 }
2495
2496 static void
2497 dump_size_t(StoreEntry * entry, const char *name, size_t var)
2498 {
2499 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
2500 }
2501
2502 static void
2503 dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
2504 {
2505 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
2506 }
2507
2508 #if UNUSED_CODE
2509 static void
2510 dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
2511 {
2512 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
2513 }
2514 #endif
2515
2516 static void
2517 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
2518 {
2519 storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR);
2520 }
2521
2522 static void
2523 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
2524 {
2525 storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR);
2526 }
2527
2528 static void
2529 parse_size_t(size_t * var)
2530 {
2531 int i;
2532 i = GetInteger();
2533 *var = (size_t) i;
2534 }
2535
2536 static void
2537 parse_b_size_t(size_t * var)
2538 {
2539 parseBytesLine(var, B_BYTES_STR);
2540 }
2541
2542 #if UNUSED_CODE
2543 static void
2544 parse_kb_size_t(size_t * var)
2545 {
2546 parseBytesLine(var, B_KBYTES_STR);
2547 }
2548 #endif
2549
2550 static void
2551 parse_b_int64_t(int64_t * var)
2552 {
2553 parseBytesLine64(var, B_BYTES_STR);
2554 }
2555
2556 static void
2557 parse_kb_int64_t(int64_t * var)
2558 {
2559 parseBytesLine64(var, B_KBYTES_STR);
2560 }
2561
2562 static void
2563 free_size_t(size_t * var)
2564 {
2565 *var = 0;
2566 }
2567
2568 static void
2569 free_b_int64_t(int64_t * var)
2570 {
2571 *var = 0;
2572 }
2573
2574 #define free_b_size_t free_size_t
2575 #define free_kb_size_t free_size_t
2576 #define free_mb_size_t free_size_t
2577 #define free_gb_size_t free_size_t
2578 #define free_kb_int64_t free_b_int64_t
2579
2580 static void
2581 dump_ushort(StoreEntry * entry, const char *name, u_short var)
2582 {
2583 storeAppendPrintf(entry, "%s %d\n", name, var);
2584 }
2585
2586 static void
2587 free_ushort(u_short * u)
2588 {
2589 *u = 0;
2590 }
2591
2592 static void
2593 parse_ushort(u_short * var)
2594 {
2595 ConfigParser::ParseUShort(var);
2596 }
2597
2598 void
2599 ConfigParser::ParseUShort(u_short *var)
2600 {
2601 *var = GetShort();
2602 }
2603
2604 void
2605 ConfigParser::ParseBool(bool *var)
2606 {
2607 int i = GetInteger();
2608
2609 if (0 == i)
2610 *var = false;
2611 else if (1 == i)
2612 *var = true;
2613 else
2614 self_destruct();
2615 }
2616
2617 static void
2618 dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
2619 {
2620 while (list != NULL) {
2621 storeAppendPrintf(entry, "%s %s\n", name, list->key);
2622 list = list->next;
2623 }
2624 }
2625
2626 void
2627 ConfigParser::ParseWordList(wordlist ** list)
2628 {
2629 parse_wordlist(list);
2630 }
2631
2632 void
2633 parse_wordlist(wordlist ** list)
2634 {
2635 char *token;
2636 char *t = strtok(NULL, "");
2637
2638 while ((token = strwordtok(NULL, &t)))
2639 wordlistAdd(list, token);
2640 }
2641
2642 #if 0 /* now unused */
2643 static int
2644 check_null_wordlist(wordlist * w)
2645 {
2646 return w == NULL;
2647 }
2648 #endif
2649
2650 static int
2651 check_null_acl_access(acl_access * a)
2652 {
2653 return a == NULL;
2654 }
2655
2656 #define free_wordlist wordlistDestroy
2657
2658 #define free_uri_whitespace free_int
2659
2660 static void
2661 parse_uri_whitespace(int *var)
2662 {
2663 char *token = strtok(NULL, w_space);
2664
2665 if (token == NULL)
2666 self_destruct();
2667
2668 if (!strcasecmp(token, "strip"))
2669 *var = URI_WHITESPACE_STRIP;
2670 else if (!strcasecmp(token, "deny"))
2671 *var = URI_WHITESPACE_DENY;
2672 else if (!strcasecmp(token, "allow"))
2673 *var = URI_WHITESPACE_ALLOW;
2674 else if (!strcasecmp(token, "encode"))
2675 *var = URI_WHITESPACE_ENCODE;
2676 else if (!strcasecmp(token, "chop"))
2677 *var = URI_WHITESPACE_CHOP;
2678 else
2679 self_destruct();
2680 }
2681
2682 static void
2683 dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
2684 {
2685 const char *s;
2686
2687 if (var == URI_WHITESPACE_ALLOW)
2688 s = "allow";
2689 else if (var == URI_WHITESPACE_ENCODE)
2690 s = "encode";
2691 else if (var == URI_WHITESPACE_CHOP)
2692 s = "chop";
2693 else if (var == URI_WHITESPACE_DENY)
2694 s = "deny";
2695 else
2696 s = "strip";
2697
2698 storeAppendPrintf(entry, "%s %s\n", name, s);
2699 }
2700
2701 static void
2702 free_removalpolicy(RemovalPolicySettings ** settings)
2703 {
2704 if (!*settings)
2705 return;
2706
2707 free_string(&(*settings)->type);
2708
2709 free_wordlist(&(*settings)->args);
2710
2711 delete *settings;
2712
2713 *settings = NULL;
2714 }
2715
2716 static void
2717 parse_removalpolicy(RemovalPolicySettings ** settings)
2718 {
2719 if (*settings)
2720 free_removalpolicy(settings);
2721
2722 *settings = new RemovalPolicySettings;
2723
2724 parse_string(&(*settings)->type);
2725
2726 parse_wordlist(&(*settings)->args);
2727 }
2728
2729 static void
2730 dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
2731 {
2732 wordlist *args;
2733 storeAppendPrintf(entry, "%s %s", name, settings->type);
2734 args = settings->args;
2735
2736 while (args) {
2737 storeAppendPrintf(entry, " %s", args->key);
2738 args = args->next;
2739 }
2740
2741 storeAppendPrintf(entry, "\n");
2742 }
2743
2744 #include "cf_parser.h"
2745
2746 peer_t
2747 parseNeighborType(const char *s)
2748 {
2749 if (!strcasecmp(s, "parent"))
2750 return PEER_PARENT;
2751
2752 if (!strcasecmp(s, "neighbor"))
2753 return PEER_SIBLING;
2754
2755 if (!strcasecmp(s, "neighbour"))
2756 return PEER_SIBLING;
2757
2758 if (!strcasecmp(s, "sibling"))
2759 return PEER_SIBLING;
2760
2761 if (!strcasecmp(s, "multicast"))
2762 return PEER_MULTICAST;
2763
2764 debugs(15, 0, "WARNING: Unknown neighbor type: " << s);
2765
2766 return PEER_SIBLING;
2767 }
2768
2769 #if USE_WCCPv2
2770 void
2771 parse_IpAddress_list_token(IpAddress_list ** head, char *token)
2772 {
2773 char *t;
2774 char *host;
2775 char *tmp;
2776
2777 IpAddress ipa;
2778 unsigned short port;
2779 IpAddress_list *s;
2780
2781 host = NULL;
2782 port = 0;
2783
2784 #if USE_IPV6
2785 if (*token == '[') {
2786 /* [host]:port */
2787 host = token + 1;
2788 t = strchr(host, ']');
2789 if (!t)
2790 self_destruct();
2791 *t++ = '\0';
2792 if (*t != ':')
2793 self_destruct();
2794 port = xatos(t + 1);
2795 } else
2796 #endif
2797 if ((t = strchr(token, ':'))) {
2798 /* host:port */
2799 host = token;
2800 *t = '\0';
2801 port = xatos(t + 1);
2802
2803 if (0 == port)
2804 self_destruct();
2805 } else if ((port = strtol(token, &tmp, 10)), !*tmp) {
2806 /* port */
2807 } else {
2808 host = token;
2809 port = 0;
2810 }
2811
2812 if (NULL == host)
2813 ipa.SetAnyAddr();
2814 else if ( ipa.GetHostByName(host) ) /* dont use ipcache. Accept either FQDN or IPA. */
2815 (void) 0;
2816 else
2817 self_destruct();
2818
2819 /* port MUST be set after the IPA lookup/conversion is perofrmed. */
2820 ipa.SetPort(port);
2821
2822 while (*head)
2823 head = &(*head)->next;
2824
2825 s = static_cast<IpAddress_list *>(xcalloc(1, sizeof(*s)));
2826 s->s = ipa;
2827
2828 *head = s;
2829 }
2830
2831 static void
2832 parse_IpAddress_list(IpAddress_list ** head)
2833 {
2834 char *token;
2835
2836 while ((token = strtok(NULL, w_space))) {
2837 parse_IpAddress_list_token(head, token);
2838 }
2839 }
2840
2841 static void
2842 dump_IpAddress_list(StoreEntry * e, const char *n, const IpAddress_list * s)
2843 {
2844 char ntoabuf[MAX_IPSTRLEN];
2845
2846 while (s) {
2847 storeAppendPrintf(e, "%s %s\n",
2848 n,
2849 s->s.NtoA(ntoabuf,MAX_IPSTRLEN));
2850 s = s->next;
2851 }
2852 }
2853
2854 static void
2855 free_IpAddress_list(IpAddress_list ** head)
2856 {
2857 if (*head) delete *head;
2858 *head = NULL;
2859 }
2860
2861 #if CURRENTLY_UNUSED
2862 /* This code was previously used by http_port. Left as it really should
2863 * be used by icp_port and htcp_port
2864 */
2865 static int
2866 check_null_IpAddress_list(const IpAddress_list * s)
2867 {
2868 return NULL == s;
2869 }
2870
2871 #endif /* CURRENTLY_UNUSED */
2872 #endif /* USE_WCCPv2 */
2873
2874 CBDATA_CLASS_INIT(http_port_list);
2875
2876 static void
2877 parse_http_port_specification(http_port_list * s, char *token)
2878 {
2879 char *host = NULL;
2880 unsigned short port = 0;
2881 char *t = NULL;
2882 char *junk = NULL;
2883
2884 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
2885 s->name = xstrdup(token);
2886 s->connection_auth_disabled = false;
2887
2888 #if USE_IPV6
2889 if (*token == '[') {
2890 /* [ipv6]:port */
2891 host = token + 1;
2892 t = strchr(host, ']');
2893 if (!t) {
2894 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token);
2895 self_destruct();
2896 }
2897 *t++ = '\0';
2898 if (*t != ':') {
2899 debugs(3, 0, "http(s)_port: missing Port in: " << token);
2900 self_destruct();
2901 }
2902 port = xatos(t + 1);
2903 } else
2904 #endif
2905 if ((t = strchr(token, ':'))) {
2906 /* host:port */
2907 /* ipv4:port */
2908 host = token;
2909 *t = '\0';
2910 port = xatos(t + 1);
2911
2912 } else if ((port = strtol(token, &junk, 10)), !*junk) {
2913 /* port */
2914 debugs(3, 3, "http(s)_port: found Listen on Port: " << port);
2915 } else {
2916 debugs(3, 0, "http(s)_port: missing Port: " << token);
2917 self_destruct();
2918 }
2919
2920 if (port == 0) {
2921 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token);
2922 self_destruct();
2923 }
2924
2925 if (NULL == host) {
2926 s->s.SetAnyAddr();
2927 s->s.SetPort(port);
2928 debugs(3, 3, "http(s)_port: found Listen on wildcard address: " << s->s);
2929 } else if ( s->s = host ) { /* check/parse numeric IPA */
2930 s->s.SetPort(port);
2931 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host << " --> " << s->s);
2932 } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
2933 /* dont use ipcache */
2934 s->defaultsite = xstrdup(host);
2935 s->s.SetPort(port);
2936 debugs(3, 3, "http(s)_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
2937 } else {
2938 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host);
2939 self_destruct();
2940 }
2941 }
2942
2943 static void
2944 parse_http_port_option(http_port_list * s, char *token)
2945 {
2946 if (strncmp(token, "defaultsite=", 12) == 0) {
2947 safe_free(s->defaultsite);
2948 s->defaultsite = xstrdup(token + 12);
2949 s->accel = 1;
2950 } else if (strncmp(token, "name=", 5) == 0) {
2951 safe_free(s->name);
2952 s->name = xstrdup(token + 5);
2953 } else if (strcmp(token, "vhost") == 0) {
2954 s->vhost = 1;
2955 s->accel = 1;
2956 } else if (strcmp(token, "vport") == 0) {
2957 s->vport = -1;
2958 s->accel = 1;
2959 } else if (strncmp(token, "vport=", 6) == 0) {
2960 s->vport = xatos(token + 6);
2961 s->accel = 1;
2962 } else if (strncmp(token, "protocol=", 9) == 0) {
2963 s->protocol = xstrdup(token + 9);
2964 s->accel = 1;
2965 } else if (strcmp(token, "accel") == 0) {
2966 s->accel = 1;
2967 } else if (strcmp(token, "no-connection-auth") == 0) {
2968 s->connection_auth_disabled = true;
2969 } else if (strcmp(token, "connection-auth=off") == 0) {
2970 s->connection_auth_disabled = true;
2971 } else if (strcmp(token, "connection-auth") == 0) {
2972 s->connection_auth_disabled = false;
2973 } else if (strcmp(token, "connection-auth=on") == 0) {
2974 s->connection_auth_disabled = false;
2975 } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
2976 if (!strcasecmp(token + 23, "off"))
2977 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
2978 else if (!strcasecmp(token + 23, "transparent"))
2979 s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
2980 else if (!strcasecmp(token + 23, "always"))
2981 s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
2982 else
2983 self_destruct();
2984
2985 } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
2986 s->intercepted = 1;
2987 IpInterceptor.StartInterception();
2988 /* Log information regarding the port modes under interception. */
2989 debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
2990 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
2991
2992 #if USE_IPV6
2993 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
2994 debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)");
2995 if ( !s->s.SetIPv4() ) {
2996 debugs(3, DBG_CRITICAL, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s->s );
2997 self_destruct();
2998 }
2999 #endif
3000 } else if (strcmp(token, "tproxy") == 0) {
3001 if (s->intercepted || s->accel) {
3002 debugs(3,DBG_CRITICAL, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3003 self_destruct();
3004 }
3005 s->spoof_client_ip = 1;
3006 IpInterceptor.StartTransparency();
3007 /* Log information regarding the port modes under transparency. */
3008 debugs(3, DBG_IMPORTANT, "Starting IP Spoofing on port " << s->s);
3009 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (Ip spoofing enabled)");
3010
3011 #if USE_IPV6
3012 /* INET6: until target TPROXY is known to work on IPv6 SOCKET, force wildcard to IPv4 */
3013 debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)");
3014 if ( s->s.IsIPv6() && !s->s.SetIPv4() ) {
3015 debugs(3, DBG_CRITICAL, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s->s );
3016 self_destruct();
3017 }
3018 #endif
3019
3020 } else if (strcmp(token, "ipv4") == 0) {
3021 #if USE_IPV6
3022 if ( !s->s.SetIPv4() ) {
3023 debugs(3, 0, "http(s)_port: IPv6 addresses cannot be used a IPv4-Only." << s->s );
3024 self_destruct();
3025 }
3026 #endif
3027 } else if (strcmp(token, "tcpkeepalive") == 0) {
3028 s->tcp_keepalive.enabled = 1;
3029 } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
3030 char *t = token + 13;
3031 s->tcp_keepalive.enabled = 1;
3032 s->tcp_keepalive.idle = atoi(t);
3033 t = strchr(t, ',');
3034 if (t) {
3035 t++;
3036 s->tcp_keepalive.interval = atoi(t);
3037 t = strchr(t, ',');
3038 }
3039 if (t) {
3040 t++;
3041 s->tcp_keepalive.timeout = atoi(t);
3042 t = strchr(t, ',');
3043 }
3044 #if USE_SSL
3045 } else if (strncmp(token, "cert=", 5) == 0) {
3046 safe_free(s->cert);
3047 s->cert = xstrdup(token + 5);
3048 } else if (strncmp(token, "key=", 4) == 0) {
3049 safe_free(s->key);
3050 s->key = xstrdup(token + 4);
3051 } else if (strncmp(token, "version=", 8) == 0) {
3052 s->version = xatoi(token + 8);
3053
3054 if (s->version < 1 || s->version > 4)
3055 self_destruct();
3056 } else if (strncmp(token, "options=", 8) == 0) {
3057 safe_free(s->options);
3058 s->options = xstrdup(token + 8);
3059 } else if (strncmp(token, "cipher=", 7) == 0) {
3060 safe_free(s->cipher);
3061 s->cipher = xstrdup(token + 7);
3062 } else if (strncmp(token, "clientca=", 9) == 0) {
3063 safe_free(s->clientca);
3064 s->clientca = xstrdup(token + 9);
3065 } else if (strncmp(token, "cafile=", 7) == 0) {
3066 safe_free(s->cafile);
3067 s->cafile = xstrdup(token + 7);
3068 } else if (strncmp(token, "capath=", 7) == 0) {
3069 safe_free(s->capath);
3070 s->capath = xstrdup(token + 7);
3071 } else if (strncmp(token, "crlfile=", 8) == 0) {
3072 safe_free(s->crlfile);
3073 s->crlfile = xstrdup(token + 8);
3074 } else if (strncmp(token, "dhparams=", 9) == 0) {
3075 safe_free(s->dhfile);
3076 s->dhfile = xstrdup(token + 9);
3077 } else if (strncmp(token, "sslflags=", 9) == 0) {
3078 safe_free(s->sslflags);
3079 s->sslflags = xstrdup(token + 9);
3080 } else if (strncmp(token, "sslcontext=", 11) == 0) {
3081 safe_free(s->sslcontext);
3082 s->sslcontext = xstrdup(token + 11);
3083 } else if (strcmp(token, "sslBump") == 0) {
3084 s->sslBump = 1; // accelerated when bumped, otherwise not
3085 #endif
3086 } else {
3087 self_destruct();
3088 }
3089
3090 if ( s->spoof_client_ip && (s->intercepted || s->accel) ) {
3091 debugs(3,DBG_CRITICAL, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3092 self_destruct();
3093 }
3094 }
3095
3096 static http_port_list *
3097 create_http_port(char *portspec)
3098 {
3099 http_port_list *s = new http_port_list("http");
3100 parse_http_port_specification(s, portspec);
3101 return s;
3102 }
3103
3104 void
3105 add_http_port(char *portspec)
3106 {
3107 http_port_list *s = create_http_port(portspec);
3108 s->next = Config.Sockaddr.http;
3109 Config.Sockaddr.http = s;
3110 }
3111
3112 static void
3113 parse_http_port_list(http_port_list ** head)
3114 {
3115 char *token = strtok(NULL, w_space);
3116
3117 if (!token) {
3118 self_destruct();
3119 return;
3120 }
3121
3122 http_port_list *s = create_http_port(token);
3123
3124 /* parse options ... */
3125 while ((token = strtok(NULL, w_space))) {
3126 parse_http_port_option(s, token);
3127 }
3128
3129 while (*head)
3130 head = &(*head)->next;
3131
3132 *head = s;
3133 }
3134
3135 static void
3136 dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s)
3137 {
3138 char buf[MAX_IPSTRLEN];
3139
3140 storeAppendPrintf(e, "%s %s",
3141 n,
3142 s->s.ToURL(buf,MAX_IPSTRLEN));
3143
3144 if (s->defaultsite)
3145 storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3146
3147 if (s->intercepted)
3148 storeAppendPrintf(e, " intercept");
3149
3150 if (s->vhost)
3151 storeAppendPrintf(e, " vhost");
3152
3153 if (s->vport)
3154 storeAppendPrintf(e, " vport");
3155
3156 if (s->connection_auth_disabled)
3157 storeAppendPrintf(e, " connection-auth=off");
3158 else
3159 storeAppendPrintf(e, " connection-auth=on");
3160
3161 if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3162 const char *pmtu;
3163
3164 if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3165 pmtu = "always";
3166 else
3167 pmtu = "transparent";
3168
3169 storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3170 }
3171
3172 if (s->tcp_keepalive.enabled) {
3173 if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
3174 storeAppendPrintf(e, " tcp_keepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
3175 } else {
3176 storeAppendPrintf(e, " tcp_keepalive");
3177 }
3178 }
3179
3180 #if USE_SSL
3181 if (s->cert)
3182 storeAppendPrintf(e, " cert=%s", s->cert);
3183
3184 if (s->key)
3185 storeAppendPrintf(e, " key=%s", s->key);
3186
3187 if (s->version)
3188 storeAppendPrintf(e, " version=%d", s->version);
3189
3190 if (s->options)
3191 storeAppendPrintf(e, " options=%s", s->options);
3192
3193 if (s->cipher)
3194 storeAppendPrintf(e, " cipher=%s", s->cipher);
3195
3196 if (s->cafile)
3197 storeAppendPrintf(e, " cafile=%s", s->cafile);
3198
3199 if (s->capath)
3200 storeAppendPrintf(e, " capath=%s", s->capath);
3201
3202 if (s->crlfile)
3203 storeAppendPrintf(e, " crlfile=%s", s->crlfile);
3204
3205 if (s->dhfile)
3206 storeAppendPrintf(e, " dhparams=%s", s->dhfile);
3207
3208 if (s->sslflags)
3209 storeAppendPrintf(e, " sslflags=%s", s->sslflags);
3210
3211 if (s->sslcontext)
3212 storeAppendPrintf(e, " sslcontext=%s", s->sslcontext);
3213
3214 if (s->sslBump)
3215 storeAppendPrintf(e, " sslBump");
3216 #endif
3217 }
3218
3219 static void
3220 dump_http_port_list(StoreEntry * e, const char *n, const http_port_list * s)
3221 {
3222 while (s) {
3223 dump_generic_http_port(e, n, s);
3224 storeAppendPrintf(e, "\n");
3225 s = s->next;
3226 }
3227 }
3228
3229 static void
3230 free_http_port_list(http_port_list ** head)
3231 {
3232 http_port_list *s;
3233
3234 while ((s = *head) != NULL) {
3235 *head = s->next;
3236 delete s;
3237 }
3238 }
3239
3240 #if USE_SSL
3241
3242 // TODO: merge better with parse_http_port_list
3243 static void
3244 parse_https_port_list(https_port_list ** head)
3245 {
3246 char *token;
3247 https_port_list *s;
3248
3249 token = strtok(NULL, w_space);
3250
3251 if (!token)
3252 self_destruct();
3253
3254 s = new https_port_list;
3255 parse_http_port_specification(&s->http, token);
3256
3257 /* parse options ... */
3258 while ((token = strtok(NULL, w_space))) {
3259 parse_http_port_option(s, token);
3260 }
3261
3262 while (*head) {
3263 http_port_list ** headTmp = &(*head)->http.next;
3264 head = (https_port_list **)headTmp;
3265 }
3266
3267 *head = s;
3268 }
3269
3270 static void
3271 dump_https_port_list(StoreEntry * e, const char *n, const https_port_list * s)
3272 {
3273 dump_http_port_list(e, n, s);
3274 }
3275
3276 static void
3277 free_https_port_list(https_port_list ** head)
3278 {
3279 free_http_port_list((http_port_list**)head);
3280 }
3281
3282 #if 0
3283 static int
3284 check_null_https_port_list(const https_port_list * s)
3285 {
3286 return NULL == s;
3287 }
3288
3289 #endif
3290
3291 #endif /* USE_SSL */
3292
3293 void
3294 configFreeMemory(void)
3295 {
3296 free_all();
3297 }
3298
3299 void
3300 requirePathnameExists(const char *name, const char *path)
3301 {
3302
3303 struct stat sb;
3304 char pathbuf[BUFSIZ];
3305 assert(path != NULL);
3306
3307 if (Config.chroot_dir && (geteuid() == 0)) {
3308 snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3309 path = pathbuf;
3310 }
3311
3312 if (stat(path, &sb) < 0) {
3313 if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
3314 fatalf("%s %s: %s", name, path, xstrerror());
3315 else
3316 fprintf(stderr, "WARNING: %s %s: %s\n", name, path, xstrerror());
3317 }
3318 }
3319
3320 char *
3321 strtokFile(void)
3322 {
3323 return ConfigParser::strtokFile();
3324 }
3325
3326 #include "AccessLogEntry.h"
3327 /* TODO: split out parsing somehow ...*/
3328 static void
3329 parse_logformat(logformat ** logformat_definitions)
3330 {
3331 logformat *nlf;
3332 char *name, *def;
3333
3334 if ((name = strtok(NULL, w_space)) == NULL)
3335 self_destruct();
3336
3337 if ((def = strtok(NULL, "\r\n")) == NULL) {
3338 self_destruct();
3339 return;
3340 }
3341
3342 debugs(3, 2, "Logformat for '" << name << "' is '" << def << "'");
3343
3344 nlf = (logformat *)xcalloc(1, sizeof(logformat));
3345
3346 nlf->name = xstrdup(name);
3347
3348 if (!accessLogParseLogFormat(&nlf->format, def)) {
3349 self_destruct();
3350 return;
3351 }
3352
3353 nlf->next = *logformat_definitions;
3354
3355 *logformat_definitions = nlf;
3356 }
3357
3358 static void
3359 parse_access_log(customlog ** logs)
3360 {
3361 const char *filename, *logdef_name;
3362 customlog *cl;
3363 logformat *lf;
3364
3365 cl = (customlog *)xcalloc(1, sizeof(*cl));
3366
3367 if ((filename = strtok(NULL, w_space)) == NULL) {
3368 self_destruct();
3369 return;
3370 }
3371
3372 if (strcmp(filename, "none") == 0) {
3373 cl->type = CLF_NONE;
3374 goto done;
3375 }
3376
3377 if ((logdef_name = strtok(NULL, w_space)) == NULL)
3378 logdef_name = "auto";
3379
3380 debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'");
3381
3382 cl->filename = xstrdup(filename);
3383
3384 /* look for the definition pointer corresponding to this name */
3385 lf = Config.Log.logformats;
3386
3387 while (lf != NULL) {
3388 debugs(3, 9, "Comparing against '" << lf->name << "'");
3389
3390 if (strcmp(lf->name, logdef_name) == 0)
3391 break;
3392
3393 lf = lf->next;
3394 }
3395
3396 if (lf != NULL) {
3397 cl->type = CLF_CUSTOM;
3398 cl->logFormat = lf;
3399 } else if (strcmp(logdef_name, "auto") == 0) {
3400 cl->type = CLF_AUTO;
3401 } else if (strcmp(logdef_name, "squid") == 0) {
3402 cl->type = CLF_SQUID;
3403 } else if (strcmp(logdef_name, "common") == 0) {
3404 cl->type = CLF_COMMON;
3405 } else {
3406 debugs(3, 0, "Log format '" << logdef_name << "' is not defined");
3407 self_destruct();
3408 return;
3409 }
3410
3411 done:
3412 aclParseAclList(LegacyParser, &cl->aclList);
3413
3414 while (*logs)
3415 logs = &(*logs)->next;
3416
3417 *logs = cl;
3418 }
3419
3420 static int
3421 check_null_access_log(customlog *customlog_definitions)
3422 {
3423 return customlog_definitions == NULL;
3424 }
3425
3426 static void
3427 dump_logformat(StoreEntry * entry, const char *name, logformat * definitions)
3428 {
3429 accessLogDumpLogFormat(entry, name, definitions);
3430 }
3431
3432 static void
3433 dump_access_log(StoreEntry * entry, const char *name, customlog * logs)
3434 {
3435 customlog *log;
3436
3437 for (log = logs; log; log = log->next) {
3438 storeAppendPrintf(entry, "%s ", name);
3439
3440 switch (log->type) {
3441
3442 case CLF_CUSTOM:
3443 storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name);
3444 break;
3445
3446 case CLF_NONE:
3447 storeAppendPrintf(entry, "none");
3448 break;
3449
3450 case CLF_SQUID:
3451 storeAppendPrintf(entry, "%s squid", log->filename);
3452 break;
3453
3454 case CLF_COMMON:
3455 storeAppendPrintf(entry, "%s squid", log->filename);
3456 break;
3457
3458 case CLF_AUTO:
3459
3460 if (log->aclList)
3461 storeAppendPrintf(entry, "%s auto", log->filename);
3462 else
3463 storeAppendPrintf(entry, "%s", log->filename);
3464
3465 break;
3466
3467 case CLF_UNKNOWN:
3468 break;
3469 }
3470
3471 if (log->aclList)
3472 dump_acl_list(entry, log->aclList);
3473
3474 storeAppendPrintf(entry, "\n");
3475 }
3476 }
3477
3478 static void
3479 free_logformat(logformat ** definitions)
3480 {
3481 while (*definitions) {
3482 logformat *format = *definitions;
3483 *definitions = format->next;
3484 safe_free(format->name);
3485 accessLogFreeLogFormat(&format->format);
3486 xfree(format);
3487 }
3488 }
3489
3490 static void
3491 free_access_log(customlog ** definitions)
3492 {
3493 while (*definitions) {
3494 customlog *log = *definitions;
3495 *definitions = log->next;
3496
3497 log->logFormat = NULL;
3498 log->type = CLF_UNKNOWN;
3499
3500 if (log->aclList)
3501 aclDestroyAclList(&log->aclList);
3502
3503 safe_free(log->filename);
3504
3505 xfree(log);
3506 }
3507 }
3508
3509 #if USE_ADAPTATION
3510
3511 static void
3512 parse_adaptation_service_set_type()
3513 {
3514 Adaptation::Config::ParseServiceSet();
3515 }
3516
3517 static void
3518 parse_adaptation_access_type()
3519 {
3520 Adaptation::Config::ParseAccess(LegacyParser);
3521 }
3522
3523 #endif /* USE_ADAPTATION */
3524
3525
3526 #if ICAP_CLIENT
3527
3528 static void
3529 parse_icap_service_type(Adaptation::Icap::Config * cfg)
3530 {
3531 cfg->parseService();
3532 }
3533
3534 static void
3535 free_icap_service_type(Adaptation::Icap::Config * cfg)
3536 {
3537 cfg->freeService();
3538 }
3539
3540 static void
3541 dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
3542 {
3543 cfg.dumpService(entry, name);
3544 }
3545
3546 static void
3547 parse_icap_class_type()
3548 {
3549 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3550 "Use 'adaptation_service_set' instead");
3551 Adaptation::Config::ParseServiceSet();
3552 }
3553
3554 static void
3555 parse_icap_access_type()
3556 {
3557 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3558 "Use 'adaptation_access' instead");
3559 Adaptation::Config::ParseAccess(LegacyParser);
3560 }
3561
3562 #endif
3563
3564
3565 #if USE_ECAP
3566
3567 static void
3568 parse_ecap_service_type(Adaptation::Ecap::Config * cfg)
3569 {
3570 cfg->parseService();
3571 }
3572
3573 static void
3574 free_ecap_service_type(Adaptation::Ecap::Config * cfg)
3575 {
3576 cfg->freeService();
3577 }
3578
3579 static void
3580 dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
3581 {
3582 cfg.dumpService(entry, name);
3583 }
3584
3585 #endif /* USE_ECAP */