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