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