]> git.ipfire.org Git - thirdparty/squid.git/blob - src/cache_cf.cc
Turn flags in CachePeer class into proper bool type.
[thirdparty/squid.git] / src / cache_cf.cc
1 /*
2 * DEBUG: section 03 Configuration File Parsing
3 * AUTHOR: Harvest Derived
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33 #include "squid.h"
34 #include "acl/Acl.h"
35 #include "acl/AclAddress.h"
36 #include "acl/AclDenyInfoList.h"
37 #include "acl/AclNameList.h"
38 #include "acl/AclSizeLimit.h"
39 #include "acl/Gadgets.h"
40 #include "acl/MethodData.h"
41 #include "anyp/PortCfg.h"
42 #include "AuthReg.h"
43 #include "base/RunnersRegistry.h"
44 #include "mgr/ActionPasswordList.h"
45 #include "CachePeer.h"
46 #include "CachePeerDomainList.h"
47 #include "cache_cf.h"
48 #include "ConfigParser.h"
49 #include "CpuAffinityMap.h"
50 #include "DiskIO/DiskIOModule.h"
51 #include "eui/Config.h"
52 #include "ExternalACL.h"
53 #include "format/Format.h"
54 #include "globals.h"
55 #include "HttpHeaderTools.h"
56 #include "HttpRequestMethod.h"
57 #include "ident/Config.h"
58 #include "ip/Intercept.h"
59 #include "ip/QosConfig.h"
60 #include "ip/tools.h"
61 #include "ipc/Kids.h"
62 #include "log/Config.h"
63 #include "log/CustomLog.h"
64 #include "Mem.h"
65 #include "MemBuf.h"
66 #include "mgr/Registration.h"
67 #include "NeighborTypeDomainList.h"
68 #include "Parsing.h"
69 #include "PeerDigest.h"
70 #include "RefreshPattern.h"
71 #include "rfc1738.h"
72 #include "SquidConfig.h"
73 #include "SquidString.h"
74 #include "ssl/ProxyCerts.h"
75 #include "Store.h"
76 #include "StoreFileSystem.h"
77 #include "SwapDir.h"
78 #include "wordlist.h"
79 #include "neighbors.h"
80 #include "tools.h"
81 /* wccp2 has its own conditional definitions */
82 #include "wccp2.h"
83 #if USE_ADAPTATION
84 #include "adaptation/Config.h"
85 #endif
86 #if ICAP_CLIENT
87 #include "adaptation/icap/Config.h"
88 #endif
89 #if USE_ECAP
90 #include "adaptation/ecap/Config.h"
91 #endif
92 #if USE_SSL
93 #include "ssl/support.h"
94 #include "ssl/Config.h"
95 #endif
96 #if USE_AUTH
97 #include "auth/Config.h"
98 #include "auth/Scheme.h"
99 #endif
100 #if USE_SQUID_ESI
101 #include "esi/Parser.h"
102 #endif
103 #if SQUID_SNMP
104 #include "snmp.h"
105 #endif
106
107 #if HAVE_GLOB_H
108 #include <glob.h>
109 #endif
110 #if HAVE_LIMITS_H
111 #include <limits>
112 #endif
113 #if HAVE_LIST
114 #include <list>
115 #endif
116 #if HAVE_SYS_TYPES_H
117 #include <sys/types.h>
118 #endif
119 #if HAVE_PWD_H
120 #include <pwd.h>
121 #endif
122 #if HAVE_GRP_H
123 #include <grp.h>
124 #endif
125 #if HAVE_SYS_STAT_H
126 #include <sys/stat.h>
127 #endif
128
129 #if USE_SSL
130 #include "ssl/gadgets.h"
131 #endif
132
133 #if USE_ADAPTATION
134 static void parse_adaptation_service_set_type();
135 static void parse_adaptation_service_chain_type();
136 static void parse_adaptation_access_type();
137 #endif
138
139 #if ICAP_CLIENT
140 static void parse_icap_service_type(Adaptation::Icap::Config *);
141 static void dump_icap_service_type(StoreEntry *, const char *, const Adaptation::Icap::Config &);
142 static void free_icap_service_type(Adaptation::Icap::Config *);
143 static void parse_icap_class_type();
144 static void parse_icap_access_type();
145
146 static void parse_icap_service_failure_limit(Adaptation::Icap::Config *);
147 static void dump_icap_service_failure_limit(StoreEntry *, const char *, const Adaptation::Icap::Config &);
148 static void free_icap_service_failure_limit(Adaptation::Icap::Config *);
149 #endif
150
151 #if USE_ECAP
152 static void parse_ecap_service_type(Adaptation::Ecap::Config *);
153 static void dump_ecap_service_type(StoreEntry *, const char *, const Adaptation::Ecap::Config &);
154 static void free_ecap_service_type(Adaptation::Ecap::Config *);
155 #endif
156
157 static peer_t parseNeighborType(const char *s);
158
159 CBDATA_TYPE(CachePeer);
160
161 static const char *const T_MILLISECOND_STR = "millisecond";
162 static const char *const T_SECOND_STR = "second";
163 static const char *const T_MINUTE_STR = "minute";
164 static const char *const T_HOUR_STR = "hour";
165 static const char *const T_DAY_STR = "day";
166 static const char *const T_WEEK_STR = "week";
167 static const char *const T_FORTNIGHT_STR = "fortnight";
168 static const char *const T_MONTH_STR = "month";
169 static const char *const T_YEAR_STR = "year";
170 static const char *const T_DECADE_STR = "decade";
171
172 static const char *const B_BYTES_STR = "bytes";
173 static const char *const B_KBYTES_STR = "KB";
174 static const char *const B_MBYTES_STR = "MB";
175 static const char *const B_GBYTES_STR = "GB";
176
177 static const char *const list_sep = ", \t\n\r";
178
179 static void parse_access_log(CustomLog ** customlog_definitions);
180 static int check_null_access_log(CustomLog *customlog_definitions);
181 static void dump_access_log(StoreEntry * entry, const char *name, CustomLog * definitions);
182 static void free_access_log(CustomLog ** definitions);
183
184 static void update_maxobjsize(void);
185 static void configDoConfigure(void);
186 static void parse_refreshpattern(RefreshPattern **);
187 static uint64_t parseTimeUnits(const char *unit, bool allowMsec);
188 static void parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec);
189 static void parse_u_short(unsigned short * var);
190 static void parse_string(char **);
191 static void default_all(void);
192 static void defaults_if_none(void);
193 static void defaults_postscriptum(void);
194 static int parse_line(char *);
195 static void parse_obsolete(const char *);
196 static void parseBytesLine(size_t * bptr, const char *units);
197 #if USE_SSL
198 static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value);
199 #endif
200 #if !USE_DNSHELPER
201 static void parseBytesLineSigned(ssize_t * bptr, const char *units);
202 #endif
203 static size_t parseBytesUnits(const char *unit);
204 static void free_all(void);
205 void requirePathnameExists(const char *name, const char *path);
206 static OBJH dump_config;
207 #if USE_HTTP_VIOLATIONS
208 static void free_HeaderManglers(HeaderManglers **pm);
209 static void dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
210 static void parse_http_header_access(HeaderManglers **manglers);
211 #define free_http_header_access free_HeaderManglers
212 static void dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
213 static void parse_http_header_replace(HeaderManglers **manglers);
214 #define free_http_header_replace free_HeaderManglers
215 #endif
216 static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers);
217 static void parse_HeaderWithAclList(HeaderWithAclList **header);
218 static void free_HeaderWithAclList(HeaderWithAclList **header);
219 static void parse_note(Notes *);
220 static void dump_note(StoreEntry *, const char *, Notes &);
221 static void free_note(Notes *);
222 static void parse_denyinfo(AclDenyInfoList ** var);
223 static void dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var);
224 static void free_denyinfo(AclDenyInfoList ** var);
225
226 #if USE_WCCPv2
227 static void parse_IpAddress_list(Ip::Address_list **);
228 static void dump_IpAddress_list(StoreEntry *, const char *, const Ip::Address_list *);
229 static void free_IpAddress_list(Ip::Address_list **);
230 #if CURRENTLY_UNUSED
231 static int check_null_IpAddress_list(const Ip::Address_list *);
232 #endif /* CURRENTLY_UNUSED */
233 #endif /* USE_WCCPv2 */
234
235 static void parsePortCfg(AnyP::PortCfg **, const char *protocol);
236 #define parse_PortCfg(l) parsePortCfg((l), token)
237 static void dump_PortCfg(StoreEntry *, const char *, const AnyP::PortCfg *);
238 static void free_PortCfg(AnyP::PortCfg **);
239
240 #if USE_SSL
241 static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign);
242 static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign);
243 static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign);
244 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt);
245 static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt);
246 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt);
247 static void parse_sslproxy_ssl_bump(acl_access **ssl_bump);
248 static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump);
249 static void free_sslproxy_ssl_bump(acl_access **ssl_bump);
250 #endif /* USE_SSL */
251
252 static void parse_b_size_t(size_t * var);
253 static void parse_b_int64_t(int64_t * var);
254
255 static bool parseNamedIntList(const char *data, const String &name, Vector<int> &list);
256
257 static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
258 static void dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap);
259 static void free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
260
261 static int parseOneConfigFile(const char *file_name, unsigned int depth);
262
263 /*
264 * LegacyParser is a parser for legacy code that uses the global
265 * approach. This is static so that it is only exposed to cache_cf.
266 * Other modules needing access to a ConfigParser should have it
267 * provided to them in their parserFOO methods.
268 */
269 static ConfigParser LegacyParser = ConfigParser();
270
271 void
272 self_destruct(void)
273 {
274 LegacyParser.destruct();
275 }
276
277 static void
278 update_maxobjsize(void)
279 {
280 int i;
281 int64_t ms = -1;
282
283 for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
284 assert (Config.cacheSwap.swapDirs[i].getRaw());
285
286 if (dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->
287 max_objsize > ms)
288 ms = dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->max_objsize;
289 }
290 store_maxobjsize = ms;
291 }
292
293 static void
294 SetConfigFilename(char const *file_name, bool is_pipe)
295 {
296 cfg_filename = file_name;
297
298 char const *token;
299
300 if (is_pipe)
301 cfg_filename = file_name + 1;
302 else if ((token = strrchr(cfg_filename, '/')))
303 cfg_filename = token + 1;
304 }
305
306 static const char*
307 skip_ws(const char* s)
308 {
309 while (xisspace(*s))
310 ++s;
311
312 return s;
313 }
314
315 static int
316 parseManyConfigFiles(char* files, int depth)
317 {
318 int error_count = 0;
319 char* saveptr = NULL;
320 #if HAVE_GLOB
321 char *path;
322 glob_t globbuf;
323 int i;
324 memset(&globbuf, 0, sizeof(globbuf));
325 for (path = strwordtok(files, &saveptr); path; path = strwordtok(NULL, &saveptr)) {
326 if (glob(path, globbuf.gl_pathc ? GLOB_APPEND : 0, NULL, &globbuf) != 0) {
327 fatalf("Unable to find configuration file: %s: %s",
328 path, xstrerror());
329 }
330 }
331 for (i = 0; i < (int)globbuf.gl_pathc; ++i) {
332 error_count += parseOneConfigFile(globbuf.gl_pathv[i], depth);
333 }
334 globfree(&globbuf);
335 #else
336 char* file = strwordtok(files, &saveptr);
337 while (file != NULL) {
338 error_count += parseOneConfigFile(file, depth);
339 file = strwordtok(NULL, &saveptr);
340 }
341 #endif /* HAVE_GLOB */
342 return error_count;
343 }
344
345 static void
346 ReplaceSubstr(char*& str, int& len, unsigned substrIdx, unsigned substrLen, const char* newSubstr)
347 {
348 assert(str != NULL);
349 assert(newSubstr != NULL);
350
351 unsigned newSubstrLen = strlen(newSubstr);
352 if (newSubstrLen > substrLen)
353 str = (char*)realloc(str, len - substrLen + newSubstrLen + 1);
354
355 // move tail part including zero
356 memmove(str + substrIdx + newSubstrLen, str + substrIdx + substrLen, len - substrIdx - substrLen + 1);
357 // copy new substring in place
358 memcpy(str + substrIdx, newSubstr, newSubstrLen);
359
360 len = strlen(str);
361 }
362
363 static void
364 SubstituteMacro(char*& line, int& len, const char* macroName, const char* substStr)
365 {
366 assert(line != NULL);
367 assert(macroName != NULL);
368 assert(substStr != NULL);
369 unsigned macroNameLen = strlen(macroName);
370 while (const char* macroPos = strstr(line, macroName)) // we would replace all occurrences
371 ReplaceSubstr(line, len, macroPos - line, macroNameLen, substStr);
372 }
373
374 static void
375 ProcessMacros(char*& line, int& len)
376 {
377 SubstituteMacro(line, len, "${process_name}", TheKidName);
378 SubstituteMacro(line, len, "${process_number}", xitoa(KidIdentifier));
379 }
380
381 static void
382 trim_trailing_ws(char* str)
383 {
384 assert(str != NULL);
385 unsigned i = strlen(str);
386 while ((i > 0) && xisspace(str[i - 1]))
387 --i;
388 str[i] = '\0';
389 }
390
391 static const char*
392 FindStatement(const char* line, const char* statement)
393 {
394 assert(line != NULL);
395 assert(statement != NULL);
396
397 const char* str = skip_ws(line);
398 unsigned len = strlen(statement);
399 if (strncmp(str, statement, len) == 0) {
400 str += len;
401 if (*str == '\0')
402 return str;
403 else if (xisspace(*str))
404 return skip_ws(str);
405 }
406
407 return NULL;
408 }
409
410 static bool
411 StrToInt(const char* str, long& number)
412 {
413 assert(str != NULL);
414
415 char* end;
416 number = strtol(str, &end, 0);
417
418 return (end != str) && (*end == '\0'); // returns true if string contains nothing except number
419 }
420
421 static bool
422 EvalBoolExpr(const char* expr)
423 {
424 assert(expr != NULL);
425 if (strcmp(expr, "true") == 0) {
426 return true;
427 } else if (strcmp(expr, "false") == 0) {
428 return false;
429 } else if (const char* equation = strchr(expr, '=')) {
430 const char* rvalue = skip_ws(equation + 1);
431 char* lvalue = (char*)xmalloc(equation - expr + 1);
432 xstrncpy(lvalue, expr, equation - expr + 1);
433 trim_trailing_ws(lvalue);
434
435 long number1;
436 if (!StrToInt(lvalue, number1))
437 fatalf("String is not a integer number: '%s'\n", lvalue);
438 long number2;
439 if (!StrToInt(rvalue, number2))
440 fatalf("String is not a integer number: '%s'\n", rvalue);
441
442 xfree(lvalue);
443 return number1 == number2;
444 }
445 fatalf("Unable to evaluate expression '%s'\n", expr);
446 return false; // this place cannot be reached
447 }
448
449 static int
450 parseOneConfigFile(const char *file_name, unsigned int depth)
451 {
452 FILE *fp = NULL;
453 const char *orig_cfg_filename = cfg_filename;
454 const int orig_config_lineno = config_lineno;
455 char *token = NULL;
456 char *tmp_line = NULL;
457 int tmp_line_len = 0;
458 int err_count = 0;
459 int is_pipe = 0;
460
461 debugs(3, DBG_IMPORTANT, "Processing Configuration File: " << file_name << " (depth " << depth << ")");
462 if (depth > 16) {
463 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name);
464 return 1;
465 }
466
467 if (file_name[0] == '!' || file_name[0] == '|') {
468 fp = popen(file_name + 1, "r");
469 is_pipe = 1;
470 } else {
471 fp = fopen(file_name, "r");
472 }
473
474 if (fp == NULL)
475 fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror());
476
477 #if _SQUID_WINDOWS_
478 setmode(fileno(fp), O_TEXT);
479 #endif
480
481 SetConfigFilename(file_name, bool(is_pipe));
482
483 memset(config_input_line, '\0', BUFSIZ);
484
485 config_lineno = 0;
486
487 Vector<bool> if_states;
488 while (fgets(config_input_line, BUFSIZ, fp)) {
489 ++config_lineno;
490
491 if ((token = strchr(config_input_line, '\n')))
492 *token = '\0';
493
494 if ((token = strchr(config_input_line, '\r')))
495 *token = '\0';
496
497 // strip any prefix whitespace off the line.
498 const char *p = skip_ws(config_input_line);
499 if (config_input_line != p)
500 memmove(config_input_line, p, strlen(p)+1);
501
502 if (strncmp(config_input_line, "#line ", 6) == 0) {
503 static char new_file_name[1024];
504 static char *file;
505 static char new_lineno;
506 token = config_input_line + 6;
507 new_lineno = strtol(token, &file, 0) - 1;
508
509 if (file == token)
510 continue; /* Not a valid #line directive, may be a comment */
511
512 while (*file && xisspace((unsigned char) *file))
513 ++file;
514
515 if (*file) {
516 if (*file != '"')
517 continue; /* Not a valid #line directive, may be a comment */
518
519 xstrncpy(new_file_name, file + 1, sizeof(new_file_name));
520
521 if ((token = strchr(new_file_name, '"')))
522 *token = '\0';
523
524 cfg_filename = new_file_name;
525 }
526
527 config_lineno = new_lineno;
528 }
529
530 if (config_input_line[0] == '#')
531 continue;
532
533 if (config_input_line[0] == '\0')
534 continue;
535
536 const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line;
537
538 size_t append_len = strlen(append);
539
540 tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1);
541
542 strcpy(tmp_line + tmp_line_len, append);
543
544 tmp_line_len += append_len;
545
546 if (tmp_line[tmp_line_len-1] == '\\') {
547 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'");
548 tmp_line[--tmp_line_len] = '\0';
549 continue;
550 }
551
552 trim_trailing_ws(tmp_line);
553 ProcessMacros(tmp_line, tmp_line_len);
554 debugs(3, (opt_parse_cfg_only?1:5), "Processing: " << tmp_line);
555
556 if (const char* expr = FindStatement(tmp_line, "if")) {
557 if_states.push_back(EvalBoolExpr(expr)); // store last if-statement meaning
558 } else if (FindStatement(tmp_line, "endif")) {
559 if (!if_states.empty())
560 if_states.pop_back(); // remove last if-statement meaning
561 else
562 fatalf("'endif' without 'if'\n");
563 } else if (FindStatement(tmp_line, "else")) {
564 if (!if_states.empty())
565 if_states.back() = !if_states.back();
566 else
567 fatalf("'else' without 'if'\n");
568 } else if (if_states.empty() || if_states.back()) { // test last if-statement meaning if present
569 /* Handle includes here */
570 if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) {
571 err_count += parseManyConfigFiles(tmp_line + 8, depth + 1);
572 } else if (!parse_line(tmp_line)) {
573 debugs(3, DBG_CRITICAL, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'");
574 ++err_count;
575 }
576 }
577
578 safe_free(tmp_line);
579 tmp_line_len = 0;
580
581 }
582 if (!if_states.empty())
583 fatalf("if-statement without 'endif'\n");
584
585 if (is_pipe) {
586 int ret = pclose(fp);
587
588 if (ret != 0)
589 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret);
590 } else {
591 fclose(fp);
592 }
593
594 cfg_filename = orig_cfg_filename;
595 config_lineno = orig_config_lineno;
596
597 xfree(tmp_line);
598 return err_count;
599 }
600
601 int
602 parseConfigFile(const char *file_name)
603 {
604 int err_count = 0;
605
606 debugs(5, 4, HERE);
607
608 configFreeMemory();
609
610 ACLMethodData::ThePurgeCount = 0;
611 default_all();
612
613 err_count = parseOneConfigFile(file_name, 0);
614
615 defaults_if_none();
616
617 defaults_postscriptum();
618
619 /*
620 * We must call configDoConfigure() before leave_suid() because
621 * configDoConfigure() is where we turn username strings into
622 * uid values.
623 */
624 configDoConfigure();
625
626 if (!Config.chroot_dir) {
627 leave_suid();
628 setUmask(Config.umask);
629 _db_init(Debug::cache_log, Debug::debugOptions);
630 enter_suid();
631 }
632
633 if (opt_send_signal == -1) {
634 Mgr::RegisterAction("config",
635 "Current Squid Configuration",
636 dump_config,
637 1, 1);
638 }
639
640 return err_count;
641 }
642
643 static void
644 configDoConfigure(void)
645 {
646 memset(&Config2, '\0', sizeof(SquidConfig2));
647 /* init memory as early as possible */
648 memConfigure();
649 /* Sanity checks */
650
651 if (Config.cacheSwap.swapDirs == NULL) {
652 /* Memory-only cache probably in effect. */
653 /* turn off the cache rebuild delays... */
654 StoreController::store_dirs_rebuilding = 0;
655 } else if (InDaemonMode()) { // no diskers in non-daemon mode
656 for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
657 const RefCount<SwapDir> sd = Config.cacheSwap.swapDirs[i];
658 if (sd->needsDiskStrand())
659 sd->disker = Config.workers + (++Config.cacheSwap.n_strands);
660 }
661 }
662
663 if (Debug::rotateNumber < 0) {
664 Debug::rotateNumber = Config.Log.rotateNumber;
665 }
666
667 #if SIZEOF_OFF_T <= 4
668 if (Config.Store.maxObjectSize > 0x7FFF0000) {
669 debugs(3, DBG_CRITICAL, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
670 Config.Store.maxObjectSize = 0x7FFF0000;
671 }
672 #endif
673 if (0 == Store::Root().maxSize())
674 /* people might want a zero-sized cache on purpose */
675 (void) 0;
676 else if (Store::Root().maxSize() < Config.memMaxSize)
677 /* This is bogus. folk with NULL caches will want this */
678 debugs(3, DBG_CRITICAL, "WARNING cache_mem is larger than total disk cache space!");
679
680 if (Config.Announce.period > 0) {
681 Config.onoff.announce = 1;
682 } else if (Config.Announce.period < 1) {
683 Config.Announce.period = 86400 * 365; /* one year */
684 Config.onoff.announce = 0;
685 }
686
687 if (Config.onoff.httpd_suppress_version_string)
688 visible_appname_string = (char *)appname_string;
689 else
690 visible_appname_string = (char const *)APP_FULLNAME;
691
692 #if USE_DNSHELPER
693 if (Config.dnsChildren.n_max < 1)
694 fatal("No DNS helpers allocated");
695 #endif
696
697 if (Config.Program.redirect) {
698 if (Config.redirectChildren.n_max < 1) {
699 Config.redirectChildren.n_max = 0;
700 wordlistDestroy(&Config.Program.redirect);
701 }
702 }
703
704 if (Config.appendDomain)
705 if (*Config.appendDomain != '.')
706 fatal("append_domain must begin with a '.'");
707
708 if (Config.errHtmlText == NULL)
709 Config.errHtmlText = xstrdup(null_string);
710
711 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
712 if (Config.max_filedescriptors > 0) {
713 debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
714 }
715 #elif USE_SELECT || USE_SELECT_WIN32
716 if (Config.max_filedescriptors > FD_SETSIZE) {
717 debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors limited to " << FD_SETSIZE << " by select() algorithm.");
718 }
719 #endif
720
721 storeConfigure();
722
723 snprintf(ThisCache, sizeof(ThisCache), "%s (%s)",
724 uniqueHostname(),
725 visible_appname_string);
726
727 /*
728 * the extra space is for loop detection in client_side.c -- we search
729 * for substrings in the Via header.
730 */
731 snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)",
732 uniqueHostname(),
733 visible_appname_string);
734
735 /* Use visible_hostname as default surrogate_id */
736 if (!Config.Accel.surrogate_id) {
737 const char *t = getMyHostname();
738 Config.Accel.surrogate_id = xstrdup( (t?t:"unset-id") );
739 }
740
741 if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
742 Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
743
744 if (Config.appendDomain)
745 Config.appendDomainLen = strlen(Config.appendDomain);
746 else
747 Config.appendDomainLen = 0;
748
749 if (Config.connect_retries > 10) {
750 debugs(0,DBG_CRITICAL, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
751 Config.connect_retries = 10;
752 }
753
754 requirePathnameExists("MIME Config Table", Config.mimeTablePathname);
755 #if USE_DNSHELPER
756 requirePathnameExists("cache_dns_program", Config.Program.dnsserver);
757 #endif
758 #if USE_UNLINKD
759
760 requirePathnameExists("unlinkd_program", Config.Program.unlinkd);
761 #endif
762 requirePathnameExists("logfile_daemon", Log::TheConfig.logfile_daemon);
763 if (Config.Program.redirect)
764 requirePathnameExists("redirect_program", Config.Program.redirect->key);
765
766 requirePathnameExists("Icon Directory", Config.icons.directory);
767
768 if (Config.errorDirectory)
769 requirePathnameExists("Error Directory", Config.errorDirectory);
770
771 #if USE_HTTP_VIOLATIONS
772
773 {
774 const RefreshPattern *R;
775
776 for (R = Config.Refresh; R; R = R->next) {
777 if (!R->flags.override_expire)
778 continue;
779
780 debugs(22, DBG_IMPORTANT, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
781
782 break;
783 }
784
785 for (R = Config.Refresh; R; R = R->next) {
786 if (!R->flags.override_lastmod)
787 continue;
788
789 debugs(22, DBG_IMPORTANT, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
790
791 break;
792 }
793
794 for (R = Config.Refresh; R; R = R->next) {
795 if (!R->flags.reload_into_ims)
796 continue;
797
798 debugs(22, DBG_IMPORTANT, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
799
800 break;
801 }
802
803 for (R = Config.Refresh; R; R = R->next) {
804 if (!R->flags.ignore_reload)
805 continue;
806
807 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
808
809 break;
810 }
811
812 for (R = Config.Refresh; R; R = R->next) {
813 if (!R->flags.ignore_no_store)
814 continue;
815
816 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
817
818 break;
819 }
820
821 for (R = Config.Refresh; R; R = R->next) {
822 if (!R->flags.ignore_must_revalidate)
823 continue;
824 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
825 break;
826 }
827
828 for (R = Config.Refresh; R; R = R->next) {
829 if (!R->flags.ignore_private)
830 continue;
831
832 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
833
834 break;
835 }
836
837 for (R = Config.Refresh; R; R = R->next) {
838 if (!R->flags.ignore_auth)
839 continue;
840
841 debugs(22, DBG_IMPORTANT, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
842
843 break;
844 }
845
846 }
847 #endif
848 #if !USE_HTTP_VIOLATIONS
849 Config.onoff.via = 1;
850 #else
851
852 if (!Config.onoff.via)
853 debugs(22, DBG_IMPORTANT, "WARNING: HTTP requires the use of Via");
854
855 #endif
856
857 // we enable runtime PURGE checks if there is at least one PURGE method ACL
858 // TODO: replace with a dedicated "purge" ACL option?
859 Config2.onoff.enable_purge = (ACLMethodData::ThePurgeCount > 0);
860
861 Config2.onoff.mangle_request_headers = (Config.request_header_access != NULL);
862
863 if (geteuid() == 0) {
864 if (NULL != Config.effectiveUser) {
865
866 struct passwd *pwd = getpwnam(Config.effectiveUser);
867
868 if (NULL == pwd) {
869 /*
870 * Andres Kroonmaa <andre@online.ee>:
871 * Some getpwnam() implementations (Solaris?) require
872 * an available FD < 256 for opening a FILE* to the
873 * passwd file.
874 * DW:
875 * This should be safe at startup, but might still fail
876 * during reconfigure.
877 */
878 fatalf("getpwnam failed to find userid for effective user '%s'",
879 Config.effectiveUser);
880 return;
881 }
882
883 Config2.effectiveUserID = pwd->pw_uid;
884
885 Config2.effectiveGroupID = pwd->pw_gid;
886
887 #if HAVE_PUTENV
888
889 if (pwd->pw_dir && *pwd->pw_dir) {
890 int len;
891 char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1);
892 snprintf(env_str, len, "HOME=%s", pwd->pw_dir);
893 putenv(env_str);
894 }
895
896 #endif
897
898 }
899 } else {
900 Config2.effectiveUserID = geteuid();
901 Config2.effectiveGroupID = getegid();
902 }
903
904 if (NULL != Config.effectiveGroup) {
905
906 struct group *grp = getgrnam(Config.effectiveGroup);
907
908 if (NULL == grp) {
909 fatalf("getgrnam failed to find groupid for effective group '%s'",
910 Config.effectiveGroup);
911 return;
912 }
913
914 Config2.effectiveGroupID = grp->gr_gid;
915 }
916
917 #if USE_SSL
918
919 debugs(3, DBG_IMPORTANT, "Initializing https proxy context");
920
921 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);
922
923 for (CachePeer *p = Config.peers; p != NULL; p = p->next) {
924 if (p->use_ssl) {
925 debugs(3, DBG_IMPORTANT, "Initializing cache_peer " << p->name << " SSL context");
926 p->sslContext = sslCreateClientContext(p->sslcert, p->sslkey, p->sslversion, p->sslcipher, p->ssloptions, p->sslflags, p->sslcafile, p->sslcapath, p->sslcrlfile);
927 }
928 }
929
930 for (AnyP::PortCfg *s = Config.Sockaddr.http; s != NULL; s = s->next) {
931 if (!s->sslBump)
932 continue;
933
934 debugs(3, DBG_IMPORTANT, "Initializing http_port " << s->s << " SSL context");
935 s->configureSslServerContext();
936 }
937
938 for (AnyP::PortCfg *s = Config.Sockaddr.https; s != NULL; s = s->next) {
939 debugs(3, DBG_IMPORTANT, "Initializing https_port " << s->s << " SSL context");
940 s->configureSslServerContext();
941 }
942
943 #endif
944
945 // prevent infinite fetch loops in the request parser
946 // due to buffer full but not enough data recived to finish parse
947 if (Config.maxRequestBufferSize <= Config.maxRequestHeaderSize) {
948 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
949 " Change client_request_buffer_max or request_header_max_size limits.",
950 (uint32_t)Config.maxRequestBufferSize, (uint32_t)Config.maxRequestHeaderSize);
951 }
952
953 #if USE_AUTH
954 /*
955 * disable client side request pipelining. There is a race with
956 * Negotiate and NTLM when the client sends a second request on an
957 * connection before the authenticate challenge is sent. With
958 * pipelining OFF, the client may fail to authenticate, but squid's
959 * state will be preserved.
960 */
961 if (Config.onoff.pipeline_prefetch) {
962 Auth::Config *nego = Auth::Config::Find("Negotiate");
963 Auth::Config *ntlm = Auth::Config::Find("NTLM");
964 if ((nego && nego->active()) || (ntlm && ntlm->active())) {
965 debugs(3, DBG_IMPORTANT, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
966 Config.onoff.pipeline_prefetch = 0;
967 }
968 }
969 #endif
970 }
971
972 /** Parse a line containing an obsolete directive.
973 * To upgrade it where possible instead of just "Bungled config" for
974 * directives which cannot be marked as simply aliases of the some name.
975 * For example if the parameter order and content has changed.
976 * Or if the directive has been completely removed.
977 */
978 void
979 parse_obsolete(const char *name)
980 {
981 // Directives which have been radically changed rather than removed
982 if (!strcmp(name, "url_rewrite_concurrency")) {
983 int cval;
984 parse_int(&cval);
985 debugs(3, DBG_CRITICAL, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
986 Config.redirectChildren.concurrency = cval;
987 }
988 }
989
990 /* Parse a time specification from the config file. Store the
991 * result in 'tptr', after converting it to 'units' */
992 static void
993 parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec)
994 {
995 char *token;
996 double d;
997 time_msec_t m;
998 time_msec_t u;
999
1000 if ((u = parseTimeUnits(units, allowMsec)) == 0)
1001 self_destruct();
1002
1003 if ((token = strtok(NULL, w_space)) == NULL)
1004 self_destruct();
1005
1006 d = xatof(token);
1007
1008 m = u; /* default to 'units' if none specified */
1009
1010 if (0 == d)
1011 (void) 0;
1012 else if ((token = strtok(NULL, w_space)) == NULL)
1013 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
1014 config_input_line << "', assuming " <<
1015 d << " " << units );
1016 else if ((m = parseTimeUnits(token, allowMsec)) == 0)
1017 self_destruct();
1018
1019 *tptr = static_cast<time_msec_t>(m * d);
1020
1021 if (static_cast<double>(*tptr) * 2 != m * d * 2) {
1022 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1023 d << " " << token << ": integer overflow (time_msec_t).");
1024 self_destruct();
1025 }
1026 }
1027
1028 static uint64_t
1029 parseTimeUnits(const char *unit, bool allowMsec)
1030 {
1031 if (allowMsec && !strncasecmp(unit, T_MILLISECOND_STR, strlen(T_MILLISECOND_STR)))
1032 return 1;
1033
1034 if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR)))
1035 return 1000;
1036
1037 if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR)))
1038 return 60 * 1000;
1039
1040 if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR)))
1041 return 3600 * 1000;
1042
1043 if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR)))
1044 return 86400 * 1000;
1045
1046 if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR)))
1047 return 86400 * 7 * 1000;
1048
1049 if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR)))
1050 return 86400 * 14 * 1000;
1051
1052 if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR)))
1053 return static_cast<uint64_t>(86400) * 30 * 1000;
1054
1055 if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR)))
1056 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1057
1058 if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR)))
1059 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1060
1061 debugs(3, DBG_IMPORTANT, "parseTimeUnits: unknown time unit '" << unit << "'");
1062
1063 return 0;
1064 }
1065
1066 static void
1067 parseBytesLine64(int64_t * bptr, const char *units)
1068 {
1069 char *token;
1070 double d;
1071 int64_t m;
1072 int64_t u;
1073
1074 if ((u = parseBytesUnits(units)) == 0) {
1075 self_destruct();
1076 return;
1077 }
1078
1079 if ((token = strtok(NULL, w_space)) == NULL) {
1080 self_destruct();
1081 return;
1082 }
1083
1084 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
1085 *bptr = -1;
1086 return;
1087 }
1088
1089 d = xatof(token);
1090
1091 m = u; /* default to 'units' if none specified */
1092
1093 if (0.0 == d)
1094 (void) 0;
1095 else if ((token = strtok(NULL, w_space)) == NULL)
1096 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
1097 config_input_line << "', assuming " <<
1098 d << " " << units );
1099 else if ((m = parseBytesUnits(token)) == 0) {
1100 self_destruct();
1101 return;
1102 }
1103
1104 *bptr = static_cast<int64_t>(m * d / u);
1105
1106 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2) {
1107 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1108 d << " " << token << ": integer overflow (int64_t).");
1109 self_destruct();
1110 }
1111 }
1112
1113 static void
1114 parseBytesLine(size_t * bptr, const char *units)
1115 {
1116 char *token;
1117 double d;
1118 int m;
1119 int u;
1120
1121 if ((u = parseBytesUnits(units)) == 0) {
1122 self_destruct();
1123 return;
1124 }
1125
1126 if ((token = strtok(NULL, w_space)) == NULL) {
1127 self_destruct();
1128 return;
1129 }
1130
1131 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
1132 *bptr = static_cast<size_t>(-1);
1133 return;
1134 }
1135
1136 d = xatof(token);
1137
1138 m = u; /* default to 'units' if none specified */
1139
1140 if (0.0 == d)
1141 (void) 0;
1142 else if ((token = strtok(NULL, w_space)) == NULL)
1143 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
1144 config_input_line << "', assuming " <<
1145 d << " " << units );
1146 else if ((m = parseBytesUnits(token)) == 0) {
1147 self_destruct();
1148 return;
1149 }
1150
1151 *bptr = static_cast<size_t>(m * d / u);
1152
1153 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2) {
1154 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1155 d << " " << token << ": integer overflow (size_t).");
1156 self_destruct();
1157 }
1158 }
1159
1160 #if !USE_DNSHELPER
1161 static void
1162 parseBytesLineSigned(ssize_t * bptr, const char *units)
1163 {
1164 char *token;
1165 double d;
1166 int m;
1167 int u;
1168
1169 if ((u = parseBytesUnits(units)) == 0) {
1170 self_destruct();
1171 return;
1172 }
1173
1174 if ((token = strtok(NULL, w_space)) == NULL) {
1175 self_destruct();
1176 return;
1177 }
1178
1179 if (strcmp(token, "none") == 0 || token[0] == '-' /* -N */) {
1180 *bptr = -1;
1181 return;
1182 }
1183
1184 d = xatof(token);
1185
1186 m = u; /* default to 'units' if none specified */
1187
1188 if (0.0 == d)
1189 (void) 0;
1190 else if ((token = strtok(NULL, w_space)) == NULL)
1191 debugs(3, DBG_CRITICAL, "WARNING: No units on '" <<
1192 config_input_line << "', assuming " <<
1193 d << " " << units );
1194 else if ((m = parseBytesUnits(token)) == 0) {
1195 self_destruct();
1196 return;
1197 }
1198
1199 *bptr = static_cast<ssize_t>(m * d / u);
1200
1201 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2) {
1202 debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" <<
1203 d << " " << token << ": integer overflow (ssize_t).");
1204 self_destruct();
1205 }
1206 }
1207 #endif
1208
1209 #if USE_SSL
1210 /**
1211 * Parse bytes from a string.
1212 * Similar to the parseBytesLine function but parses the string value instead of
1213 * the current token value.
1214 */
1215 static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value)
1216 {
1217 int u;
1218 if ((u = parseBytesUnits(units)) == 0) {
1219 self_destruct();
1220 return;
1221 }
1222
1223 // Find number from string beginning.
1224 char const * number_begin = value;
1225 char const * number_end = value;
1226
1227 while ((*number_end >= '0' && *number_end <= '9')) {
1228 ++number_end;
1229 }
1230
1231 String number;
1232 number.limitInit(number_begin, number_end - number_begin);
1233
1234 int d = xatoi(number.termedBuf());
1235 int m;
1236 if ((m = parseBytesUnits(number_end)) == 0) {
1237 self_destruct();
1238 return;
1239 }
1240
1241 *bptr = static_cast<size_t>(m * d / u);
1242 if (static_cast<double>(*bptr) * 2 != (m * d / u) * 2)
1243 self_destruct();
1244 }
1245 #endif
1246
1247 static size_t
1248 parseBytesUnits(const char *unit)
1249 {
1250 if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR)))
1251 return 1;
1252
1253 if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR)))
1254 return 1 << 10;
1255
1256 if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR)))
1257 return 1 << 20;
1258
1259 if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR)))
1260 return 1 << 30;
1261
1262 debugs(3, DBG_CRITICAL, "WARNING: Unknown bytes unit '" << unit << "'");
1263
1264 return 0;
1265 }
1266
1267 /*****************************************************************************
1268 * Max
1269 *****************************************************************************/
1270
1271 static void
1272 dump_acl(StoreEntry * entry, const char *name, ACL * ae)
1273 {
1274 wordlist *w;
1275 wordlist *v;
1276
1277 while (ae != NULL) {
1278 debugs(3, 3, "dump_acl: " << name << " " << ae->name);
1279 storeAppendPrintf(entry, "%s %s %s ",
1280 name,
1281 ae->name,
1282 ae->typeString());
1283 v = w = ae->dump();
1284
1285 while (v != NULL) {
1286 debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key);
1287 storeAppendPrintf(entry, "%s ", v->key);
1288 v = v->next;
1289 }
1290
1291 storeAppendPrintf(entry, "\n");
1292 wordlistDestroy(&w);
1293 ae = ae->next;
1294 }
1295 }
1296
1297 static void
1298 parse_acl(ACL ** ae)
1299 {
1300 ACL::ParseAclLine(LegacyParser, ae);
1301 }
1302
1303 static void
1304 free_acl(ACL ** ae)
1305 {
1306 aclDestroyAcls(ae);
1307 }
1308
1309 void
1310 dump_acl_list(StoreEntry * entry, ACLList * head)
1311 {
1312 ACLList *l;
1313
1314 for (l = head; l; l = l->next) {
1315 storeAppendPrintf(entry, " %s%s",
1316 l->op ? null_string : "!",
1317 l->_acl->name);
1318 }
1319 }
1320
1321 void
1322 dump_acl_access(StoreEntry * entry, const char *name, acl_access * head)
1323 {
1324 acl_access *l;
1325
1326 for (l = head; l; l = l->next) {
1327 storeAppendPrintf(entry, "%s %s",
1328 name,
1329 l->allow ? "Allow" : "Deny");
1330 dump_acl_list(entry, l->aclList);
1331 storeAppendPrintf(entry, "\n");
1332 }
1333 }
1334
1335 static void
1336 parse_acl_access(acl_access ** head)
1337 {
1338 aclParseAccessLine(LegacyParser, head);
1339 }
1340
1341 static void
1342 free_acl_access(acl_access ** head)
1343 {
1344 aclDestroyAccessList(head);
1345 }
1346
1347 static void
1348 dump_address(StoreEntry * entry, const char *name, Ip::Address &addr)
1349 {
1350 char buf[MAX_IPSTRLEN];
1351 storeAppendPrintf(entry, "%s %s\n", name, addr.NtoA(buf,MAX_IPSTRLEN) );
1352 }
1353
1354 static void
1355 parse_address(Ip::Address *addr)
1356 {
1357 char *token = strtok(NULL, w_space);
1358
1359 if (!token) {
1360 self_destruct();
1361 return;
1362 }
1363
1364 if (!strcmp(token,"any_addr"))
1365 addr->SetAnyAddr();
1366 else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) )
1367 addr->SetNoAddr();
1368 else if ( (*addr = token) ) // try parse numeric/IPA
1369 (void) 0;
1370 else
1371 addr->GetHostByName(token); // dont use ipcache
1372 }
1373
1374 static void
1375 free_address(Ip::Address *addr)
1376 {
1377 addr->SetEmpty();
1378 }
1379
1380 CBDATA_TYPE(AclAddress);
1381
1382 static void
1383 dump_acl_address(StoreEntry * entry, const char *name, AclAddress * head)
1384 {
1385 char buf[MAX_IPSTRLEN];
1386 AclAddress *l;
1387
1388 for (l = head; l; l = l->next) {
1389 if (!l->addr.IsAnyAddr())
1390 storeAppendPrintf(entry, "%s %s", name, l->addr.NtoA(buf,MAX_IPSTRLEN));
1391 else
1392 storeAppendPrintf(entry, "%s autoselect", name);
1393
1394 dump_acl_list(entry, l->aclList);
1395
1396 storeAppendPrintf(entry, "\n");
1397 }
1398 }
1399
1400 static void
1401 freed_acl_address(void *data)
1402 {
1403 AclAddress *l = static_cast<AclAddress *>(data);
1404 aclDestroyAclList(&l->aclList);
1405 }
1406
1407 static void
1408 parse_acl_address(AclAddress ** head)
1409 {
1410 AclAddress *l;
1411 AclAddress **tail = head; /* sane name below */
1412 CBDATA_INIT_TYPE_FREECB(AclAddress, freed_acl_address);
1413 l = cbdataAlloc(AclAddress);
1414 parse_address(&l->addr);
1415 aclParseAclList(LegacyParser, &l->aclList);
1416
1417 while (*tail)
1418 tail = &(*tail)->next;
1419
1420 *tail = l;
1421 }
1422
1423 static void
1424 free_acl_address(AclAddress ** head)
1425 {
1426 while (*head) {
1427 AclAddress *l = *head;
1428 *head = l->next;
1429 cbdataFree(l);
1430 }
1431 }
1432
1433 CBDATA_TYPE(acl_tos);
1434
1435 static void
1436 dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head)
1437 {
1438 acl_tos *l;
1439
1440 for (l = head; l; l = l->next) {
1441 if (l->tos > 0)
1442 storeAppendPrintf(entry, "%s 0x%02X", name, l->tos);
1443 else
1444 storeAppendPrintf(entry, "%s none", name);
1445
1446 dump_acl_list(entry, l->aclList);
1447
1448 storeAppendPrintf(entry, "\n");
1449 }
1450 }
1451
1452 static void
1453 freed_acl_tos(void *data)
1454 {
1455 acl_tos *l = static_cast<acl_tos *>(data);
1456 aclDestroyAclList(&l->aclList);
1457 }
1458
1459 static void
1460 parse_acl_tos(acl_tos ** head)
1461 {
1462 acl_tos *l;
1463 acl_tos **tail = head; /* sane name below */
1464 unsigned int tos; /* Initially uint for strtoui. Casted to tos_t before return */
1465 char *token = strtok(NULL, w_space);
1466
1467 if (!token) {
1468 self_destruct();
1469 return;
1470 }
1471
1472 if (!xstrtoui(token, NULL, &tos, 0, std::numeric_limits<tos_t>::max())) {
1473 self_destruct();
1474 return;
1475 }
1476
1477 CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos);
1478
1479 l = cbdataAlloc(acl_tos);
1480
1481 l->tos = (tos_t)tos;
1482
1483 aclParseAclList(LegacyParser, &l->aclList);
1484
1485 while (*tail)
1486 tail = &(*tail)->next;
1487
1488 *tail = l;
1489 }
1490
1491 static void
1492 free_acl_tos(acl_tos ** head)
1493 {
1494 while (*head) {
1495 acl_tos *l = *head;
1496 *head = l->next;
1497 l->next = NULL;
1498 cbdataFree(l);
1499 }
1500 }
1501
1502 #if SO_MARK && USE_LIBCAP
1503
1504 CBDATA_TYPE(acl_nfmark);
1505
1506 static void
1507 dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head)
1508 {
1509 acl_nfmark *l;
1510
1511 for (l = head; l; l = l->next) {
1512 if (l->nfmark > 0)
1513 storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark);
1514 else
1515 storeAppendPrintf(entry, "%s none", name);
1516
1517 dump_acl_list(entry, l->aclList);
1518
1519 storeAppendPrintf(entry, "\n");
1520 }
1521 }
1522
1523 static void
1524 freed_acl_nfmark(void *data)
1525 {
1526 acl_nfmark *l = static_cast<acl_nfmark *>(data);
1527 aclDestroyAclList(&l->aclList);
1528 }
1529
1530 static void
1531 parse_acl_nfmark(acl_nfmark ** head)
1532 {
1533 acl_nfmark *l;
1534 acl_nfmark **tail = head; /* sane name below */
1535 nfmark_t mark;
1536 char *token = strtok(NULL, w_space);
1537
1538 if (!token) {
1539 self_destruct();
1540 return;
1541 }
1542
1543 if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) {
1544 self_destruct();
1545 return;
1546 }
1547
1548 CBDATA_INIT_TYPE_FREECB(acl_nfmark, freed_acl_nfmark);
1549
1550 l = cbdataAlloc(acl_nfmark);
1551
1552 l->nfmark = mark;
1553
1554 aclParseAclList(LegacyParser, &l->aclList);
1555
1556 while (*tail)
1557 tail = &(*tail)->next;
1558
1559 *tail = l;
1560 }
1561
1562 static void
1563 free_acl_nfmark(acl_nfmark ** head)
1564 {
1565 while (*head) {
1566 acl_nfmark *l = *head;
1567 *head = l->next;
1568 l->next = NULL;
1569 cbdataFree(l);
1570 }
1571 }
1572 #endif /* SO_MARK */
1573
1574 CBDATA_TYPE(AclSizeLimit);
1575
1576 static void
1577 dump_acl_b_size_t(StoreEntry * entry, const char *name, AclSizeLimit * head)
1578 {
1579 AclSizeLimit *l;
1580
1581 for (l = head; l; l = l->next) {
1582 if (l->size != -1)
1583 storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR);
1584 else
1585 storeAppendPrintf(entry, "%s none", name);
1586
1587 dump_acl_list(entry, l->aclList);
1588
1589 storeAppendPrintf(entry, "\n");
1590 }
1591 }
1592
1593 static void
1594 freed_acl_b_size_t(void *data)
1595 {
1596 AclSizeLimit *l = static_cast<AclSizeLimit *>(data);
1597 aclDestroyAclList(&l->aclList);
1598 }
1599
1600 static void
1601 parse_acl_b_size_t(AclSizeLimit ** head)
1602 {
1603 AclSizeLimit *l;
1604 AclSizeLimit **tail = head; /* sane name below */
1605
1606 CBDATA_INIT_TYPE_FREECB(AclSizeLimit, freed_acl_b_size_t);
1607
1608 l = cbdataAlloc(AclSizeLimit);
1609
1610 parse_b_int64_t(&l->size);
1611
1612 aclParseAclList(LegacyParser, &l->aclList);
1613
1614 while (*tail)
1615 tail = &(*tail)->next;
1616
1617 *tail = l;
1618 }
1619
1620 static void
1621 free_acl_b_size_t(AclSizeLimit ** head)
1622 {
1623 while (*head) {
1624 AclSizeLimit *l = *head;
1625 *head = l->next;
1626 l->next = NULL;
1627 cbdataFree(l);
1628 }
1629 }
1630
1631 #if USE_DELAY_POOLS
1632
1633 #include "DelayPools.h"
1634 #include "DelayConfig.h"
1635 /* do nothing - free_delay_pool_count is the magic free function.
1636 * this is why delay_pool_count isn't just marked TYPE: u_short
1637 */
1638 #define free_delay_pool_class(X)
1639 #define free_delay_pool_access(X)
1640 #define free_delay_pool_rates(X)
1641 #define dump_delay_pool_class(X, Y, Z)
1642 #define dump_delay_pool_access(X, Y, Z)
1643 #define dump_delay_pool_rates(X, Y, Z)
1644
1645 static void
1646 free_delay_pool_count(DelayConfig * cfg)
1647 {
1648 cfg->freePoolCount();
1649 }
1650
1651 static void
1652 dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg)
1653 {
1654 cfg.dumpPoolCount (entry, name);
1655 }
1656
1657 static void
1658 parse_delay_pool_count(DelayConfig * cfg)
1659 {
1660 cfg->parsePoolCount();
1661 }
1662
1663 static void
1664 parse_delay_pool_class(DelayConfig * cfg)
1665 {
1666 cfg->parsePoolClass();
1667 }
1668
1669 static void
1670 parse_delay_pool_rates(DelayConfig * cfg)
1671 {
1672 cfg->parsePoolRates();
1673 }
1674
1675 static void
1676 parse_delay_pool_access(DelayConfig * cfg)
1677 {
1678 cfg->parsePoolAccess(LegacyParser);
1679 }
1680
1681 #endif
1682
1683 #if USE_DELAY_POOLS
1684 #include "ClientDelayConfig.h"
1685 /* do nothing - free_client_delay_pool_count is the magic free function.
1686 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1687 */
1688
1689 #define free_client_delay_pool_access(X)
1690 #define free_client_delay_pool_rates(X)
1691 #define dump_client_delay_pool_access(X, Y, Z)
1692 #define dump_client_delay_pool_rates(X, Y, Z)
1693
1694 static void
1695 free_client_delay_pool_count(ClientDelayConfig * cfg)
1696 {
1697 cfg->freePoolCount();
1698 }
1699
1700 static void
1701 dump_client_delay_pool_count(StoreEntry * entry, const char *name, ClientDelayConfig &cfg)
1702 {
1703 cfg.dumpPoolCount (entry, name);
1704 }
1705
1706 static void
1707 parse_client_delay_pool_count(ClientDelayConfig * cfg)
1708 {
1709 cfg->parsePoolCount();
1710 }
1711
1712 static void
1713 parse_client_delay_pool_rates(ClientDelayConfig * cfg)
1714 {
1715 cfg->parsePoolRates();
1716 }
1717
1718 static void
1719 parse_client_delay_pool_access(ClientDelayConfig * cfg)
1720 {
1721 cfg->parsePoolAccess(LegacyParser);
1722 }
1723 #endif
1724
1725 #if USE_HTTP_VIOLATIONS
1726 static void
1727 dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
1728 {
1729 if (manglers)
1730 manglers->dumpAccess(entry, name);
1731 }
1732
1733 static void
1734 parse_http_header_access(HeaderManglers **pm)
1735 {
1736 char *t = NULL;
1737
1738 if ((t = strtok(NULL, w_space)) == NULL) {
1739 debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1740 debugs(3, DBG_CRITICAL, "parse_http_header_access: missing header name.");
1741 return;
1742 }
1743
1744 if (!*pm)
1745 *pm = new HeaderManglers;
1746 HeaderManglers *manglers = *pm;
1747 headerMangler *mangler = manglers->track(t);
1748 assert(mangler);
1749 parse_acl_access(&mangler->access_list);
1750 }
1751
1752 static void
1753 free_HeaderManglers(HeaderManglers **pm)
1754 {
1755 // we delete the entire http_header_* mangler configuration at once
1756 if (const HeaderManglers *manglers = *pm) {
1757 delete manglers;
1758 *pm = NULL;
1759 }
1760 }
1761
1762 static void
1763 dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
1764 {
1765 if (manglers)
1766 manglers->dumpReplacement(entry, name);
1767 }
1768
1769 static void
1770 parse_http_header_replace(HeaderManglers **pm)
1771 {
1772 char *t = NULL;
1773
1774 if ((t = strtok(NULL, w_space)) == NULL) {
1775 debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1776 debugs(3, DBG_CRITICAL, "parse_http_header_replace: missing header name.");
1777 return;
1778 }
1779
1780 const char *value = t + strlen(t) + 1;
1781
1782 if (!*pm)
1783 *pm = new HeaderManglers;
1784 HeaderManglers *manglers = *pm;
1785 manglers->setReplacement(t, value);
1786 }
1787
1788 #endif
1789
1790 static void
1791 dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap)
1792 {
1793 SwapDir *s;
1794 int i;
1795 assert (entry);
1796
1797 for (i = 0; i < swap.n_configured; ++i) {
1798 s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw());
1799 if (!s) continue;
1800 storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path);
1801 s->dump(*entry);
1802 storeAppendPrintf(entry, "\n");
1803 }
1804 }
1805
1806 static int
1807 check_null_string(char *s)
1808 {
1809 return s == NULL;
1810 }
1811
1812 #if USE_AUTH
1813 static void
1814 parse_authparam(Auth::ConfigVector * config)
1815 {
1816 char *type_str;
1817 char *param_str;
1818
1819 if ((type_str = strtok(NULL, w_space)) == NULL)
1820 self_destruct();
1821
1822 if ((param_str = strtok(NULL, w_space)) == NULL)
1823 self_destruct();
1824
1825 /* find a configuration for the scheme in the currently parsed configs... */
1826 Auth::Config *schemeCfg = Auth::Config::Find(type_str);
1827
1828 if (schemeCfg == NULL) {
1829 /* Create a configuration based on the scheme info */
1830 Auth::Scheme::Pointer theScheme = Auth::Scheme::Find(type_str);
1831
1832 if (theScheme == NULL) {
1833 debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'.");
1834 self_destruct();
1835 }
1836
1837 config->push_back(theScheme->createConfig());
1838 schemeCfg = Auth::Config::Find(type_str);
1839 if (schemeCfg == NULL) {
1840 debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'.");
1841 self_destruct();
1842 }
1843 }
1844
1845 schemeCfg->parse(schemeCfg, config->size(), param_str);
1846 }
1847
1848 static void
1849 free_authparam(Auth::ConfigVector * cfg)
1850 {
1851 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1852 cfg->clean();
1853
1854 /* remove our pointers to the probably-dead sub-configs */
1855 while (cfg->size()) {
1856 cfg->pop_back();
1857 }
1858
1859 /* on reconfigure initialize new auth schemes for the new config. */
1860 if (reconfiguring) {
1861 Auth::Init();
1862 }
1863 }
1864
1865 static void
1866 dump_authparam(StoreEntry * entry, const char *name, Auth::ConfigVector cfg)
1867 {
1868 for (Auth::ConfigVector::iterator i = cfg.begin(); i != cfg.end(); ++i)
1869 (*i)->dump(entry, name, (*i));
1870 }
1871 #endif /* USE_AUTH */
1872
1873 /* TODO: just return the object, the # is irrelevant */
1874 static int
1875 find_fstype(char *type)
1876 {
1877 for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i)
1878 if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0)
1879 return (int)i;
1880
1881 return (-1);
1882 }
1883
1884 static void
1885 parse_cachedir(SquidConfig::_cacheSwap * swap)
1886 {
1887 char *type_str;
1888 char *path_str;
1889 RefCount<SwapDir> sd;
1890 int i;
1891 int fs;
1892
1893 if ((type_str = strtok(NULL, w_space)) == NULL)
1894 self_destruct();
1895
1896 if ((path_str = strtok(NULL, w_space)) == NULL)
1897 self_destruct();
1898
1899 fs = find_fstype(type_str);
1900
1901 if (fs < 0)
1902 self_destruct();
1903
1904 /* reconfigure existing dir */
1905
1906 for (i = 0; i < swap->n_configured; ++i) {
1907 assert (swap->swapDirs[i].getRaw());
1908
1909 if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) {
1910 /* this is specific to on-fs Stores. The right
1911 * way to handle this is probably to have a mapping
1912 * from paths to stores, and have on-fs stores
1913 * register with that, and lookip in that in their
1914 * own setup logic. RBC 20041225. TODO.
1915 */
1916
1917 sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw());
1918
1919 if (strcmp(sd->type(), StoreFileSystem::FileSystems().items[fs]->type()) != 0) {
1920 debugs(3, DBG_CRITICAL, "ERROR: Can't change type of existing cache_dir " <<
1921 sd->type() << " " << sd->path << " to " << type_str << ". Restart required");
1922 return;
1923 }
1924
1925 sd->reconfigure();
1926
1927 update_maxobjsize();
1928
1929 return;
1930 }
1931 }
1932
1933 /* new cache_dir */
1934 if (swap->n_configured > 63) {
1935 /* 7 bits, signed */
1936 debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1937 debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many.");
1938 self_destruct();
1939 return;
1940 }
1941
1942 allocate_new_swapdir(swap);
1943
1944 swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir();
1945
1946 sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw());
1947
1948 /* parse the FS parameters and options */
1949 sd->parse(swap->n_configured, path_str);
1950
1951 ++swap->n_configured;
1952
1953 /* Update the max object size */
1954 update_maxobjsize();
1955 }
1956
1957 static const char *
1958 peer_type_str(const peer_t type)
1959 {
1960 const char * result;
1961
1962 switch (type) {
1963
1964 case PEER_PARENT:
1965 result = "parent";
1966 break;
1967
1968 case PEER_SIBLING:
1969 result = "sibling";
1970 break;
1971
1972 case PEER_MULTICAST:
1973 result = "multicast";
1974 break;
1975
1976 default:
1977 result = "unknown";
1978 break;
1979 }
1980
1981 return result;
1982 }
1983
1984 static void
1985 dump_peer(StoreEntry * entry, const char *name, CachePeer * p)
1986 {
1987 CachePeerDomainList *d;
1988 NeighborTypeDomainList *t;
1989 LOCAL_ARRAY(char, xname, 128);
1990
1991 while (p != NULL) {
1992 storeAppendPrintf(entry, "%s %s %s %d %d name=%s",
1993 name,
1994 p->host,
1995 neighborTypeStr(p),
1996 p->http_port,
1997 p->icp.port,
1998 p->name);
1999 dump_peer_options(entry, p);
2000
2001 for (d = p->peer_domain; d; d = d->next) {
2002 storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n",
2003 p->host,
2004 d->do_ping ? null_string : "!",
2005 d->domain);
2006 }
2007
2008 if (p->access) {
2009 snprintf(xname, 128, "cache_peer_access %s", p->name);
2010 dump_acl_access(entry, xname, p->access);
2011 }
2012
2013 for (t = p->typelist; t; t = t->next) {
2014 storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
2015 p->host,
2016 peer_type_str(t->type),
2017 t->domain);
2018 }
2019
2020 p = p->next;
2021 }
2022 }
2023
2024 /**
2025 * utility function to prevent getservbyname() being called with a numeric value
2026 * on Windows at least it returns garage results.
2027 */
2028 static bool
2029 isUnsignedNumeric(const char *str, size_t len)
2030 {
2031 if (len < 1) return false;
2032
2033 for (; len >0 && *str; ++str, --len) {
2034 if (! isdigit(*str))
2035 return false;
2036 }
2037 return true;
2038 }
2039
2040 /**
2041 \param proto 'tcp' or 'udp' for protocol
2042 \returns Port the named service is supposed to be listening on.
2043 */
2044 static unsigned short
2045 GetService(const char *proto)
2046 {
2047 struct servent *port = NULL;
2048 /** Parses a port number or service name from the squid.conf */
2049 char *token = strtok(NULL, w_space);
2050 if (token == NULL) {
2051 self_destruct();
2052 return 0; /* NEVER REACHED */
2053 }
2054 /** Returns either the service port number from /etc/services */
2055 if ( !isUnsignedNumeric(token, strlen(token)) )
2056 port = getservbyname(token, proto);
2057 if (port != NULL) {
2058 return ntohs((unsigned short)port->s_port);
2059 }
2060 /** Or a numeric translation of the config text. */
2061 return xatos(token);
2062 }
2063
2064 /**
2065 \returns Port the named TCP service is supposed to be listening on.
2066 \copydoc GetService(const char *proto)
2067 */
2068 inline unsigned short
2069 GetTcpService(void)
2070 {
2071 return GetService("tcp");
2072 }
2073
2074 /**
2075 \returns Port the named UDP service is supposed to be listening on.
2076 \copydoc GetService(const char *proto)
2077 */
2078 inline unsigned short
2079 GetUdpService(void)
2080 {
2081 return GetService("udp");
2082 }
2083
2084 static void
2085 parse_peer(CachePeer ** head)
2086 {
2087 char *token = NULL;
2088 CachePeer *p;
2089 CBDATA_INIT_TYPE_FREECB(CachePeer, peerDestroy);
2090 p = cbdataAlloc(CachePeer);
2091 p->http_port = CACHE_HTTP_PORT;
2092 p->icp.port = CACHE_ICP_PORT;
2093 p->weight = 1;
2094 p->basetime = 0;
2095 p->stats.logged_state = PEER_ALIVE;
2096
2097 if ((token = strtok(NULL, w_space)) == NULL)
2098 self_destruct();
2099
2100 p->host = xstrdup(token);
2101
2102 p->name = xstrdup(token);
2103
2104 if ((token = strtok(NULL, w_space)) == NULL)
2105 self_destruct();
2106
2107 p->type = parseNeighborType(token);
2108
2109 if (p->type == PEER_MULTICAST) {
2110 p->options.no_digest = true;
2111 p->options.no_netdb_exchange = true;
2112 }
2113
2114 p->http_port = GetTcpService();
2115
2116 if (!p->http_port)
2117 self_destruct();
2118
2119 p->icp.port = GetUdpService();
2120 p->connection_auth = 2; /* auto */
2121
2122 while ((token = strtok(NULL, w_space))) {
2123 if (!strcasecmp(token, "proxy-only")) {
2124 p->options.proxy_only = true;
2125 } else if (!strcasecmp(token, "no-query")) {
2126 p->options.no_query = true;
2127 } else if (!strcasecmp(token, "background-ping")) {
2128 p->options.background_ping = true;
2129 } else if (!strcasecmp(token, "no-digest")) {
2130 p->options.no_digest = true;
2131 } else if (!strcasecmp(token, "no-tproxy")) {
2132 p->options.no_tproxy = true;
2133 } else if (!strcasecmp(token, "multicast-responder")) {
2134 p->options.mcast_responder = true;
2135 #if PEER_MULTICAST_SIBLINGS
2136 } else if (!strcasecmp(token, "multicast-siblings")) {
2137 p->options.mcast_siblings = true;
2138 #endif
2139 } else if (!strncasecmp(token, "weight=", 7)) {
2140 p->weight = xatoi(token + 7);
2141 } else if (!strncasecmp(token, "basetime=", 9)) {
2142 p->basetime = xatoi(token + 9);
2143 } else if (!strcasecmp(token, "closest-only")) {
2144 p->options.closest_only = true;
2145 } else if (!strncasecmp(token, "ttl=", 4)) {
2146 p->mcast.ttl = xatoi(token + 4);
2147
2148 if (p->mcast.ttl < 0)
2149 p->mcast.ttl = 0;
2150
2151 if (p->mcast.ttl > 128)
2152 p->mcast.ttl = 128;
2153 } else if (!strcasecmp(token, "default")) {
2154 p->options.default_parent = true;
2155 } else if (!strcasecmp(token, "round-robin")) {
2156 p->options.roundrobin = true;
2157 } else if (!strcasecmp(token, "weighted-round-robin")) {
2158 p->options.weighted_roundrobin = true;
2159 #if USE_HTCP
2160 } else if (!strcasecmp(token, "htcp")) {
2161 p->options.htcp = true;
2162 } else if (!strncasecmp(token, "htcp=", 5) || !strncasecmp(token, "htcp-", 5)) {
2163 /* Note: The htcp- form is deprecated, replaced by htcp= */
2164 p->options.htcp = true;
2165 char *tmp = xstrdup(token+5);
2166 char *mode, *nextmode;
2167 for (mode = nextmode = tmp; mode; mode = nextmode) {
2168 nextmode = strchr(mode, ',');
2169 if (nextmode) {
2170 *nextmode = '\0';
2171 ++nextmode;
2172 }
2173 if (!strcasecmp(mode, "no-clr")) {
2174 if (p->options.htcp_only_clr)
2175 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2176 p->options.htcp_no_clr = true;
2177 } else if (!strcasecmp(mode, "no-purge-clr")) {
2178 p->options.htcp_no_purge_clr = true;
2179 } else if (!strcasecmp(mode, "only-clr")) {
2180 if (p->options.htcp_no_clr)
2181 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2182 p->options.htcp_only_clr = true;
2183 } else if (!strcasecmp(mode, "forward-clr")) {
2184 p->options.htcp_forward_clr = true;
2185 } else if (!strcasecmp(mode, "oldsquid")) {
2186 p->options.htcp_oldsquid = true;
2187 } else {
2188 fatalf("invalid HTCP mode '%s'", mode);
2189 }
2190 }
2191 safe_free(tmp);
2192 #endif
2193 } else if (!strcasecmp(token, "no-netdb-exchange")) {
2194 p->options.no_netdb_exchange = true;
2195
2196 } else if (!strcasecmp(token, "carp")) {
2197 if (p->type != PEER_PARENT)
2198 fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
2199
2200 p->options.carp = true;
2201 } else if (!strncasecmp(token, "carp-key=", 9)) {
2202 if (p->options.carp != true)
2203 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port);
2204 p->options.carp_key.set = true;
2205 char *nextkey=token+strlen("carp-key="), *key=nextkey;
2206 for (; key; key = nextkey) {
2207 nextkey=strchr(key,',');
2208 if (nextkey) ++nextkey; // skip the comma, any
2209 if (0==strncasecmp(key,"scheme",6)) {
2210 p->options.carp_key.scheme = true;
2211 } else if (0==strncasecmp(key,"host",4)) {
2212 p->options.carp_key.host = true;
2213 } else if (0==strncasecmp(key,"port",4)) {
2214 p->options.carp_key.port = true;
2215 } else if (0==strncasecmp(key,"path",4)) {
2216 p->options.carp_key.path = true;
2217 } else if (0==strncasecmp(key,"params",6)) {
2218 p->options.carp_key.params = true;
2219 } else {
2220 fatalf("invalid carp-key '%s'",key);
2221 }
2222 }
2223 } else if (!strcasecmp(token, "userhash")) {
2224 #if USE_AUTH
2225 if (p->type != PEER_PARENT)
2226 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port);
2227
2228 p->options.userhash = true;
2229 #else
2230 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port);
2231 #endif
2232 } else if (!strcasecmp(token, "sourcehash")) {
2233 if (p->type != PEER_PARENT)
2234 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port);
2235
2236 p->options.sourcehash = true;
2237
2238 } else if (!strcasecmp(token, "no-delay")) {
2239 #if USE_DELAY_POOLS
2240 p->options.no_delay = true;
2241 #else
2242 debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2243 #endif
2244 } else if (!strncasecmp(token, "login=", 6)) {
2245 p->login = xstrdup(token + 6);
2246 rfc1738_unescape(p->login);
2247 } else if (!strncasecmp(token, "connect-timeout=", 16)) {
2248 p->connect_timeout = xatoi(token + 16);
2249 } else if (!strncasecmp(token, "connect-fail-limit=", 19)) {
2250 p->connect_fail_limit = xatoi(token + 19);
2251 #if USE_CACHE_DIGESTS
2252 } else if (!strncasecmp(token, "digest-url=", 11)) {
2253 p->digest_url = xstrdup(token + 11);
2254 #endif
2255
2256 } else if (!strcasecmp(token, "allow-miss")) {
2257 p->options.allow_miss = true;
2258 } else if (!strncasecmp(token, "max-conn=", 9)) {
2259 p->max_conn = xatoi(token + 9);
2260 } else if (!strcasecmp(token, "originserver")) {
2261 p->options.originserver = true;
2262 } else if (!strncasecmp(token, "name=", 5)) {
2263 safe_free(p->name);
2264
2265 if (token[5])
2266 p->name = xstrdup(token + 5);
2267 } else if (!strncasecmp(token, "forceddomain=", 13)) {
2268 safe_free(p->domain);
2269
2270 if (token[13])
2271 p->domain = xstrdup(token + 13);
2272
2273 #if USE_SSL
2274
2275 } else if (strcmp(token, "ssl") == 0) {
2276 p->use_ssl = 1;
2277 } else if (strncmp(token, "sslcert=", 8) == 0) {
2278 safe_free(p->sslcert);
2279 p->sslcert = xstrdup(token + 8);
2280 } else if (strncmp(token, "sslkey=", 7) == 0) {
2281 safe_free(p->sslkey);
2282 p->sslkey = xstrdup(token + 7);
2283 } else if (strncmp(token, "sslversion=", 11) == 0) {
2284 p->sslversion = xatoi(token + 11);
2285 } else if (strncmp(token, "ssloptions=", 11) == 0) {
2286 safe_free(p->ssloptions);
2287 p->ssloptions = xstrdup(token + 11);
2288 } else if (strncmp(token, "sslcipher=", 10) == 0) {
2289 safe_free(p->sslcipher);
2290 p->sslcipher = xstrdup(token + 10);
2291 } else if (strncmp(token, "sslcafile=", 10) == 0) {
2292 safe_free(p->sslcafile);
2293 p->sslcafile = xstrdup(token + 10);
2294 } else if (strncmp(token, "sslcapath=", 10) == 0) {
2295 safe_free(p->sslcapath);
2296 p->sslcapath = xstrdup(token + 10);
2297 } else if (strncmp(token, "sslcrlfile=", 11) == 0) {
2298 safe_free(p->sslcrlfile);
2299 p->sslcrlfile = xstrdup(token + 11);
2300 } else if (strncmp(token, "sslflags=", 9) == 0) {
2301 safe_free(p->sslflags);
2302 p->sslflags = xstrdup(token + 9);
2303 } else if (strncmp(token, "ssldomain=", 10) == 0) {
2304 safe_free(p->ssldomain);
2305 p->ssldomain = xstrdup(token + 10);
2306 #endif
2307
2308 } else if (strcmp(token, "front-end-https") == 0) {
2309 p->front_end_https = 1;
2310 } else if (strcmp(token, "front-end-https=on") == 0) {
2311 p->front_end_https = 1;
2312 } else if (strcmp(token, "front-end-https=auto") == 0) {
2313 p->front_end_https = 2;
2314 } else if (strcmp(token, "connection-auth=off") == 0) {
2315 p->connection_auth = 0;
2316 } else if (strcmp(token, "connection-auth") == 0) {
2317 p->connection_auth = 1;
2318 } else if (strcmp(token, "connection-auth=on") == 0) {
2319 p->connection_auth = 1;
2320 } else if (strcmp(token, "connection-auth=auto") == 0) {
2321 p->connection_auth = 2;
2322 } else {
2323 debugs(3, DBG_CRITICAL, "parse_peer: token='" << token << "'");
2324 self_destruct();
2325 }
2326 }
2327
2328 if (peerFindByName(p->name))
2329 fatalf("ERROR: cache_peer %s specified twice\n", p->name);
2330
2331 if (p->weight < 1)
2332 p->weight = 1;
2333
2334 if (p->connect_fail_limit < 1)
2335 p->connect_fail_limit = 10;
2336
2337 p->icp.version = ICP_VERSION_CURRENT;
2338
2339 p->testing_now = false;
2340
2341 #if USE_CACHE_DIGESTS
2342
2343 if (!p->options.no_digest) {
2344 /* XXX This looks odd.. who has the original pointer
2345 * then?
2346 */
2347 PeerDigest *pd = peerDigestCreate(p);
2348 p->digest = cbdataReference(pd);
2349 }
2350
2351 #endif
2352
2353 p->index = ++Config.npeers;
2354
2355 while (*head != NULL)
2356 head = &(*head)->next;
2357
2358 *head = p;
2359
2360 peerClearRRStart();
2361 }
2362
2363 static void
2364 free_peer(CachePeer ** P)
2365 {
2366 CachePeer *p;
2367
2368 while ((p = *P) != NULL) {
2369 *P = p->next;
2370 #if USE_CACHE_DIGESTS
2371
2372 cbdataReferenceDone(p->digest);
2373 #endif
2374
2375 cbdataFree(p);
2376 }
2377
2378 Config.npeers = 0;
2379 }
2380
2381 static void
2382 dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list)
2383 {
2384 wordlist *w;
2385
2386 while (list != NULL) {
2387 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
2388 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
2389 else
2390 storeAppendPrintf(entry, "%s %s", name, list->passwd);
2391
2392 for (w = list->actions; w != NULL; w = w->next) {
2393 storeAppendPrintf(entry, " %s", w->key);
2394 }
2395
2396 storeAppendPrintf(entry, "\n");
2397 list = list->next;
2398 }
2399 }
2400
2401 static void
2402 parse_cachemgrpasswd(Mgr::ActionPasswordList ** head)
2403 {
2404 char *passwd = NULL;
2405 wordlist *actions = NULL;
2406 Mgr::ActionPasswordList *p;
2407 Mgr::ActionPasswordList **P;
2408 parse_string(&passwd);
2409 parse_wordlist(&actions);
2410 p = new Mgr::ActionPasswordList;
2411 p->passwd = passwd;
2412 p->actions = actions;
2413
2414 for (P = head; *P; P = &(*P)->next) {
2415 /*
2416 * See if any of the actions from this line already have a
2417 * password from previous lines. The password checking
2418 * routines in cache_manager.c take the the password from
2419 * the first Mgr::ActionPasswordList that contains the
2420 * requested action. Thus, we should warn users who might
2421 * think they can have two passwords for the same action.
2422 */
2423 wordlist *w;
2424 wordlist *u;
2425
2426 for (w = (*P)->actions; w; w = w->next) {
2427 for (u = actions; u; u = u->next) {
2428 if (strcmp(w->key, u->key))
2429 continue;
2430
2431 debugs(0, DBG_CRITICAL, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password");
2432 }
2433 }
2434 }
2435
2436 *P = p;
2437 }
2438
2439 static void
2440 free_cachemgrpasswd(Mgr::ActionPasswordList ** head)
2441 {
2442 Mgr::ActionPasswordList *p;
2443
2444 while ((p = *head) != NULL) {
2445 *head = p->next;
2446 xfree(p->passwd);
2447 wordlistDestroy(&p->actions);
2448 xfree(p);
2449 }
2450 }
2451
2452 static void
2453 dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var)
2454 {
2455 AclNameList *a;
2456
2457 while (var != NULL) {
2458 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
2459
2460 for (a = var->acl_list; a != NULL; a = a->next)
2461 storeAppendPrintf(entry, " %s", a->name);
2462
2463 storeAppendPrintf(entry, "\n");
2464
2465 var = var->next;
2466 }
2467 }
2468
2469 static void
2470 parse_denyinfo(AclDenyInfoList ** var)
2471 {
2472 aclParseDenyInfoLine(var);
2473 }
2474
2475 void
2476 free_denyinfo(AclDenyInfoList ** list)
2477 {
2478 AclDenyInfoList *a = NULL;
2479 AclDenyInfoList *a_next = NULL;
2480 AclNameList *l = NULL;
2481 AclNameList *l_next = NULL;
2482
2483 for (a = *list; a; a = a_next) {
2484 for (l = a->acl_list; l; l = l_next) {
2485 l_next = l->next;
2486 memFree(l, MEM_ACL_NAME_LIST);
2487 l = NULL;
2488 }
2489
2490 a_next = a->next;
2491 memFree(a, MEM_ACL_DENY_INFO_LIST);
2492 a = NULL;
2493 }
2494
2495 *list = NULL;
2496 }
2497
2498 static void
2499 parse_peer_access(void)
2500 {
2501 char *host = NULL;
2502 CachePeer *p;
2503
2504 if (!(host = strtok(NULL, w_space)))
2505 self_destruct();
2506
2507 if ((p = peerFindByName(host)) == NULL) {
2508 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2509 return;
2510 }
2511
2512 aclParseAccessLine(LegacyParser, &p->access);
2513 }
2514
2515 static void
2516 parse_hostdomain(void)
2517 {
2518 char *host = NULL;
2519 char *domain = NULL;
2520
2521 if (!(host = strtok(NULL, w_space)))
2522 self_destruct();
2523
2524 while ((domain = strtok(NULL, list_sep))) {
2525 CachePeerDomainList *l = NULL;
2526 CachePeerDomainList **L = NULL;
2527 CachePeer *p;
2528
2529 if ((p = peerFindByName(host)) == NULL) {
2530 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2531 continue;
2532 }
2533
2534 l = static_cast<CachePeerDomainList *>(xcalloc(1, sizeof(CachePeerDomainList)));
2535 l->do_ping = true;
2536
2537 if (*domain == '!') { /* check for !.edu */
2538 l->do_ping = false;
2539 ++domain;
2540 }
2541
2542 l->domain = xstrdup(domain);
2543
2544 for (L = &(p->peer_domain); *L; L = &((*L)->next));
2545 *L = l;
2546 }
2547 }
2548
2549 static void
2550 parse_hostdomaintype(void)
2551 {
2552 char *host = NULL;
2553 char *type = NULL;
2554 char *domain = NULL;
2555
2556 if (!(host = strtok(NULL, w_space)))
2557 self_destruct();
2558
2559 if (!(type = strtok(NULL, w_space)))
2560 self_destruct();
2561
2562 while ((domain = strtok(NULL, list_sep))) {
2563 NeighborTypeDomainList *l = NULL;
2564 NeighborTypeDomainList **L = NULL;
2565 CachePeer *p;
2566
2567 if ((p = peerFindByName(host)) == NULL) {
2568 debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2569 return;
2570 }
2571
2572 l = static_cast<NeighborTypeDomainList *>(xcalloc(1, sizeof(NeighborTypeDomainList)));
2573 l->type = parseNeighborType(type);
2574 l->domain = xstrdup(domain);
2575
2576 for (L = &(p->typelist); *L; L = &((*L)->next));
2577 *L = l;
2578 }
2579 }
2580
2581 static void
2582 dump_int(StoreEntry * entry, const char *name, int var)
2583 {
2584 storeAppendPrintf(entry, "%s %d\n", name, var);
2585 }
2586
2587 void
2588 parse_int(int *var)
2589 {
2590 int i;
2591 i = GetInteger();
2592 *var = i;
2593 }
2594
2595 static void
2596 free_int(int *var)
2597 {
2598 *var = 0;
2599 }
2600
2601 static void
2602 dump_onoff(StoreEntry * entry, const char *name, int var)
2603 {
2604 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
2605 }
2606
2607 void
2608 parse_onoff(int *var)
2609 {
2610 char *token = strtok(NULL, w_space);
2611
2612 if (token == NULL)
2613 self_destruct();
2614
2615 if (!strcasecmp(token, "on")) {
2616 *var = 1;
2617 } else if (!strcasecmp(token, "enable")) {
2618 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2619 *var = 1;
2620 } else if (!strcasecmp(token, "off")) {
2621 *var = 0;
2622 } else if (!strcasecmp(token, "disable")) {
2623 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2624 *var = 0;
2625 } else {
2626 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2627 self_destruct();
2628 }
2629 }
2630
2631 #define free_onoff free_int
2632
2633 static void
2634 dump_tristate(StoreEntry * entry, const char *name, int var)
2635 {
2636 const char *state;
2637
2638 if (var > 0)
2639 state = "on";
2640 else if (var < 0)
2641 state = "warn";
2642 else
2643 state = "off";
2644
2645 storeAppendPrintf(entry, "%s %s\n", name, state);
2646 }
2647
2648 static void
2649 parse_tristate(int *var)
2650 {
2651 char *token = strtok(NULL, w_space);
2652
2653 if (token == NULL)
2654 self_destruct();
2655
2656 if (!strcasecmp(token, "on")) {
2657 *var = 1;
2658 } else if (!strcasecmp(token, "enable")) {
2659 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2660 *var = 1;
2661 } else if (!strcasecmp(token, "warn")) {
2662 *var = -1;
2663 } else if (!strcasecmp(token, "off")) {
2664 *var = 0;
2665 } else if (!strcasecmp(token, "disable")) {
2666 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2667 *var = 0;
2668 } else {
2669 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2670 self_destruct();
2671 }
2672 }
2673
2674 #define free_tristate free_int
2675
2676 static void
2677 dump_refreshpattern(StoreEntry * entry, const char *name, RefreshPattern * head)
2678 {
2679 while (head != NULL) {
2680 storeAppendPrintf(entry, "%s%s %s %d %d%% %d",
2681 name,
2682 head->flags.icase ? " -i" : null_string,
2683 head->pattern,
2684 (int) head->min / 60,
2685 (int) (100.0 * head->pct + 0.5),
2686 (int) head->max / 60);
2687
2688 if (head->max_stale >= 0)
2689 storeAppendPrintf(entry, " max-stale=%d", head->max_stale);
2690
2691 if (head->flags.refresh_ims)
2692 storeAppendPrintf(entry, " refresh-ims");
2693
2694 if (head->flags.store_stale)
2695 storeAppendPrintf(entry, " store-stale");
2696
2697 #if USE_HTTP_VIOLATIONS
2698
2699 if (head->flags.override_expire)
2700 storeAppendPrintf(entry, " override-expire");
2701
2702 if (head->flags.override_lastmod)
2703 storeAppendPrintf(entry, " override-lastmod");
2704
2705 if (head->flags.reload_into_ims)
2706 storeAppendPrintf(entry, " reload-into-ims");
2707
2708 if (head->flags.ignore_reload)
2709 storeAppendPrintf(entry, " ignore-reload");
2710
2711 if (head->flags.ignore_no_store)
2712 storeAppendPrintf(entry, " ignore-no-store");
2713
2714 if (head->flags.ignore_must_revalidate)
2715 storeAppendPrintf(entry, " ignore-must-revalidate");
2716
2717 if (head->flags.ignore_private)
2718 storeAppendPrintf(entry, " ignore-private");
2719
2720 if (head->flags.ignore_auth)
2721 storeAppendPrintf(entry, " ignore-auth");
2722
2723 #endif
2724
2725 storeAppendPrintf(entry, "\n");
2726
2727 head = head->next;
2728 }
2729 }
2730
2731 static void
2732 parse_refreshpattern(RefreshPattern ** head)
2733 {
2734 char *token;
2735 char *pattern;
2736 time_t min = 0;
2737 double pct = 0.0;
2738 time_t max = 0;
2739 int refresh_ims = 0;
2740 int store_stale = 0;
2741 int max_stale = -1;
2742
2743 #if USE_HTTP_VIOLATIONS
2744
2745 int override_expire = 0;
2746 int override_lastmod = 0;
2747 int reload_into_ims = 0;
2748 int ignore_reload = 0;
2749 int ignore_no_store = 0;
2750 int ignore_must_revalidate = 0;
2751 int ignore_private = 0;
2752 int ignore_auth = 0;
2753 #endif
2754
2755 int i;
2756 RefreshPattern *t;
2757 regex_t comp;
2758 int errcode;
2759 int flags = REG_EXTENDED | REG_NOSUB;
2760
2761 if ((token = strtok(NULL, w_space)) == NULL) {
2762 self_destruct();
2763 return;
2764 }
2765
2766 if (strcmp(token, "-i") == 0) {
2767 flags |= REG_ICASE;
2768 token = strtok(NULL, w_space);
2769 } else if (strcmp(token, "+i") == 0) {
2770 flags &= ~REG_ICASE;
2771 token = strtok(NULL, w_space);
2772 }
2773
2774 if (token == NULL) {
2775 self_destruct();
2776 return;
2777 }
2778
2779 pattern = xstrdup(token);
2780
2781 i = GetInteger(); /* token: min */
2782
2783 /* catch negative and insanely huge values close to 32-bit wrap */
2784 if (i < 0) {
2785 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2786 i = 0;
2787 }
2788 if (i > 60*24*365) {
2789 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2790 i = 60*24*365;
2791 }
2792
2793 min = (time_t) (i * 60); /* convert minutes to seconds */
2794
2795 i = GetPercentage(); /* token: pct */
2796
2797 pct = (double) i / 100.0;
2798
2799 i = GetInteger(); /* token: max */
2800
2801 /* catch negative and insanely huge values close to 32-bit wrap */
2802 if (i < 0) {
2803 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2804 i = 0;
2805 }
2806 if (i > 60*24*365) {
2807 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2808 i = 60*24*365;
2809 }
2810
2811 max = (time_t) (i * 60); /* convert minutes to seconds */
2812
2813 /* Options */
2814 while ((token = strtok(NULL, w_space)) != NULL) {
2815 if (!strcmp(token, "refresh-ims")) {
2816 refresh_ims = 1;
2817 } else if (!strcmp(token, "store-stale")) {
2818 store_stale = 1;
2819 } else if (!strncmp(token, "max-stale=", 10)) {
2820 max_stale = xatoi(token + 10);
2821 #if USE_HTTP_VIOLATIONS
2822
2823 } else if (!strcmp(token, "override-expire"))
2824 override_expire = 1;
2825 else if (!strcmp(token, "override-lastmod"))
2826 override_lastmod = 1;
2827 else if (!strcmp(token, "ignore-no-store"))
2828 ignore_no_store = 1;
2829 else if (!strcmp(token, "ignore-must-revalidate"))
2830 ignore_must_revalidate = 1;
2831 else if (!strcmp(token, "ignore-private"))
2832 ignore_private = 1;
2833 else if (!strcmp(token, "ignore-auth"))
2834 ignore_auth = 1;
2835 else if (!strcmp(token, "reload-into-ims")) {
2836 reload_into_ims = 1;
2837 refresh_nocache_hack = 1;
2838 /* tell client_side.c that this is used */
2839 } else if (!strcmp(token, "ignore-reload")) {
2840 ignore_reload = 1;
2841 refresh_nocache_hack = 1;
2842 /* tell client_side.c that this is used */
2843 #endif
2844
2845 } else if (!strcmp(token, "ignore-no-cache")) {
2846 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it.");
2847 } else
2848 debugs(22, DBG_CRITICAL, "refreshAddToList: Unknown option '" << pattern << "': " << token);
2849 }
2850
2851 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
2852 char errbuf[256];
2853 regerror(errcode, &comp, errbuf, sizeof errbuf);
2854 debugs(22, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2855 debugs(22, DBG_CRITICAL, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
2856 return;
2857 }
2858
2859 pct = pct < 0.0 ? 0.0 : pct;
2860 max = max < 0 ? 0 : max;
2861 t = static_cast<RefreshPattern *>(xcalloc(1, sizeof(RefreshPattern)));
2862 t->pattern = (char *) xstrdup(pattern);
2863 t->compiled_pattern = comp;
2864 t->min = min;
2865 t->pct = pct;
2866 t->max = max;
2867
2868 if (flags & REG_ICASE)
2869 t->flags.icase = 1;
2870
2871 if (refresh_ims)
2872 t->flags.refresh_ims = 1;
2873
2874 if (store_stale)
2875 t->flags.store_stale = 1;
2876
2877 t->max_stale = max_stale;
2878
2879 #if USE_HTTP_VIOLATIONS
2880
2881 if (override_expire)
2882 t->flags.override_expire = 1;
2883
2884 if (override_lastmod)
2885 t->flags.override_lastmod = 1;
2886
2887 if (reload_into_ims)
2888 t->flags.reload_into_ims = 1;
2889
2890 if (ignore_reload)
2891 t->flags.ignore_reload = 1;
2892
2893 if (ignore_no_store)
2894 t->flags.ignore_no_store = 1;
2895
2896 if (ignore_must_revalidate)
2897 t->flags.ignore_must_revalidate = 1;
2898
2899 if (ignore_private)
2900 t->flags.ignore_private = 1;
2901
2902 if (ignore_auth)
2903 t->flags.ignore_auth = 1;
2904
2905 #endif
2906
2907 t->next = NULL;
2908
2909 while (*head)
2910 head = &(*head)->next;
2911
2912 *head = t;
2913
2914 safe_free(pattern);
2915 }
2916
2917 static void
2918 free_refreshpattern(RefreshPattern ** head)
2919 {
2920 RefreshPattern *t;
2921
2922 while ((t = *head) != NULL) {
2923 *head = t->next;
2924 safe_free(t->pattern);
2925 regfree(&t->compiled_pattern);
2926 safe_free(t);
2927 }
2928
2929 #if USE_HTTP_VIOLATIONS
2930 refresh_nocache_hack = 0;
2931
2932 #endif
2933 }
2934
2935 static void
2936 dump_string(StoreEntry * entry, const char *name, char *var)
2937 {
2938 if (var != NULL)
2939 storeAppendPrintf(entry, "%s %s\n", name, var);
2940 }
2941
2942 static void
2943 parse_string(char **var)
2944 {
2945 char *token = strtok(NULL, w_space);
2946 safe_free(*var);
2947
2948 if (token == NULL)
2949 self_destruct();
2950
2951 *var = xstrdup(token);
2952 }
2953
2954 void
2955 ConfigParser::ParseString(char **var)
2956 {
2957 parse_string(var);
2958 }
2959
2960 void
2961 ConfigParser::ParseString(String *var)
2962 {
2963 char *token = strtok(NULL, w_space);
2964
2965 if (token == NULL)
2966 self_destruct();
2967
2968 var->reset(token);
2969 }
2970
2971 static void
2972 free_string(char **var)
2973 {
2974 safe_free(*var);
2975 }
2976
2977 void
2978 parse_eol(char *volatile *var)
2979 {
2980 if (!var) {
2981 self_destruct();
2982 return;
2983 }
2984
2985 unsigned char *token = (unsigned char *) strtok(NULL, null_string);
2986 safe_free(*var);
2987
2988 if (!token) {
2989 self_destruct();
2990 return;
2991 }
2992
2993 while (*token && xisspace(*token))
2994 ++token;
2995
2996 if (!*token) {
2997 self_destruct();
2998 return;
2999 }
3000
3001 *var = xstrdup((char *) token);
3002 }
3003
3004 #define dump_eol dump_string
3005 #define free_eol free_string
3006
3007 static void
3008 dump_time_t(StoreEntry * entry, const char *name, time_t var)
3009 {
3010 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
3011 }
3012
3013 void
3014 parse_time_t(time_t * var)
3015 {
3016 time_msec_t tval;
3017 parseTimeLine(&tval, T_SECOND_STR, false);
3018 *var = static_cast<time_t>(tval/1000);
3019 }
3020
3021 static void
3022 free_time_t(time_t * var)
3023 {
3024 *var = 0;
3025 }
3026
3027 #if !USE_DNSHELPER
3028 static void
3029 dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
3030 {
3031 if (var % 1000)
3032 storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
3033 else
3034 storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
3035 }
3036
3037 void
3038 parse_time_msec(time_msec_t * var)
3039 {
3040 parseTimeLine(var, T_SECOND_STR, true);
3041 }
3042
3043 static void
3044 free_time_msec(time_msec_t * var)
3045 {
3046 *var = 0;
3047 }
3048 #endif
3049
3050 #if UNUSED_CODE
3051 static void
3052 dump_size_t(StoreEntry * entry, const char *name, size_t var)
3053 {
3054 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
3055 }
3056 #endif
3057
3058 static void
3059 dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
3060 {
3061 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3062 }
3063
3064 #if !USE_DNSHELPER
3065 static void
3066 dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var)
3067 {
3068 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3069 }
3070 #endif
3071
3072 #if UNUSED_CODE
3073 static void
3074 dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
3075 {
3076 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
3077 }
3078 #endif
3079
3080 static void
3081 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
3082 {
3083 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
3084 }
3085
3086 static void
3087 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
3088 {
3089 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
3090 }
3091
3092 #if UNUSED_CODE
3093 static void
3094 parse_size_t(size_t * var)
3095 {
3096 int i;
3097 i = GetInteger();
3098 *var = (size_t) i;
3099 }
3100 #endif
3101
3102 static void
3103 parse_b_size_t(size_t * var)
3104 {
3105 parseBytesLine(var, B_BYTES_STR);
3106 }
3107
3108 #if !USE_DNSHELPER
3109 static void
3110 parse_b_ssize_t(ssize_t * var)
3111 {
3112 parseBytesLineSigned(var, B_BYTES_STR);
3113 }
3114 #endif
3115
3116 #if UNUSED_CODE
3117 static void
3118 parse_kb_size_t(size_t * var)
3119 {
3120 parseBytesLine(var, B_KBYTES_STR);
3121 }
3122 #endif
3123
3124 static void
3125 parse_b_int64_t(int64_t * var)
3126 {
3127 parseBytesLine64(var, B_BYTES_STR);
3128 }
3129
3130 static void
3131 parse_kb_int64_t(int64_t * var)
3132 {
3133 parseBytesLine64(var, B_KBYTES_STR);
3134 }
3135
3136 static void
3137 free_size_t(size_t * var)
3138 {
3139 *var = 0;
3140 }
3141
3142 #if !USE_DNSHELPER
3143 static void
3144 free_ssize_t(ssize_t * var)
3145 {
3146 *var = 0;
3147 }
3148 #endif
3149
3150 static void
3151 free_b_int64_t(int64_t * var)
3152 {
3153 *var = 0;
3154 }
3155
3156 #define free_b_size_t free_size_t
3157 #define free_b_ssize_t free_ssize_t
3158 #define free_kb_size_t free_size_t
3159 #define free_mb_size_t free_size_t
3160 #define free_gb_size_t free_size_t
3161 #define free_kb_int64_t free_b_int64_t
3162
3163 static void
3164 dump_u_short(StoreEntry * entry, const char *name, unsigned short var)
3165 {
3166 storeAppendPrintf(entry, "%s %d\n", name, var);
3167 }
3168
3169 static void
3170 free_u_short(unsigned short * u)
3171 {
3172 *u = 0;
3173 }
3174
3175 static void
3176 parse_u_short(unsigned short * var)
3177 {
3178 ConfigParser::ParseUShort(var);
3179 }
3180
3181 void
3182 ConfigParser::ParseUShort(unsigned short *var)
3183 {
3184 *var = GetShort();
3185 }
3186
3187 void
3188 ConfigParser::ParseBool(bool *var)
3189 {
3190 int i = GetInteger();
3191
3192 if (0 == i)
3193 *var = false;
3194 else if (1 == i)
3195 *var = true;
3196 else
3197 self_destruct();
3198 }
3199
3200 static void
3201 dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
3202 {
3203 while (list != NULL) {
3204 storeAppendPrintf(entry, "%s %s\n", name, list->key);
3205 list = list->next;
3206 }
3207 }
3208
3209 void
3210 ConfigParser::ParseWordList(wordlist ** list)
3211 {
3212 parse_wordlist(list);
3213 }
3214
3215 void
3216 parse_wordlist(wordlist ** list)
3217 {
3218 char *token;
3219 char *t = strtok(NULL, "");
3220
3221 while ((token = strwordtok(NULL, &t)))
3222 wordlistAdd(list, token);
3223 }
3224
3225 #if 0 /* now unused */
3226 static int
3227 check_null_wordlist(wordlist * w)
3228 {
3229 return w == NULL;
3230 }
3231 #endif
3232
3233 static int
3234 check_null_acl_access(acl_access * a)
3235 {
3236 return a == NULL;
3237 }
3238
3239 #define free_wordlist wordlistDestroy
3240
3241 #define free_uri_whitespace free_int
3242
3243 static void
3244 parse_uri_whitespace(int *var)
3245 {
3246 char *token = strtok(NULL, w_space);
3247
3248 if (token == NULL)
3249 self_destruct();
3250
3251 if (!strcasecmp(token, "strip"))
3252 *var = URI_WHITESPACE_STRIP;
3253 else if (!strcasecmp(token, "deny"))
3254 *var = URI_WHITESPACE_DENY;
3255 else if (!strcasecmp(token, "allow"))
3256 *var = URI_WHITESPACE_ALLOW;
3257 else if (!strcasecmp(token, "encode"))
3258 *var = URI_WHITESPACE_ENCODE;
3259 else if (!strcasecmp(token, "chop"))
3260 *var = URI_WHITESPACE_CHOP;
3261 else {
3262 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3263 self_destruct();
3264 }
3265 }
3266
3267 static void
3268 dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
3269 {
3270 const char *s;
3271
3272 if (var == URI_WHITESPACE_ALLOW)
3273 s = "allow";
3274 else if (var == URI_WHITESPACE_ENCODE)
3275 s = "encode";
3276 else if (var == URI_WHITESPACE_CHOP)
3277 s = "chop";
3278 else if (var == URI_WHITESPACE_DENY)
3279 s = "deny";
3280 else
3281 s = "strip";
3282
3283 storeAppendPrintf(entry, "%s %s\n", name, s);
3284 }
3285
3286 static void
3287 free_removalpolicy(RemovalPolicySettings ** settings)
3288 {
3289 if (!*settings)
3290 return;
3291
3292 free_string(&(*settings)->type);
3293
3294 free_wordlist(&(*settings)->args);
3295
3296 delete *settings;
3297
3298 *settings = NULL;
3299 }
3300
3301 static void
3302 parse_removalpolicy(RemovalPolicySettings ** settings)
3303 {
3304 if (*settings)
3305 free_removalpolicy(settings);
3306
3307 *settings = new RemovalPolicySettings;
3308
3309 parse_string(&(*settings)->type);
3310
3311 parse_wordlist(&(*settings)->args);
3312 }
3313
3314 static void
3315 dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
3316 {
3317 wordlist *args;
3318 storeAppendPrintf(entry, "%s %s", name, settings->type);
3319 args = settings->args;
3320
3321 while (args) {
3322 storeAppendPrintf(entry, " %s", args->key);
3323 args = args->next;
3324 }
3325
3326 storeAppendPrintf(entry, "\n");
3327 }
3328
3329 inline void
3330 free_YesNoNone(YesNoNone *)
3331 {
3332 // do nothing: no explicit cleanup is required
3333 }
3334
3335 static void
3336 parse_YesNoNone(YesNoNone *option)
3337 {
3338 int value = 0;
3339 parse_onoff(&value);
3340 option->configure(value > 0);
3341 }
3342
3343 static void
3344 dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
3345 {
3346 if (option.configured())
3347 dump_onoff(entry, name, option ? 1 : 0);
3348 }
3349
3350 static void
3351 free_memcachemode(SquidConfig * config)
3352 {
3353 return;
3354 }
3355
3356 static void
3357 parse_memcachemode(SquidConfig * config)
3358 {
3359 char *token = strtok(NULL, w_space);
3360 if (!token)
3361 self_destruct();
3362
3363 if (strcmp(token, "always") == 0) {
3364 Config.onoff.memory_cache_first = 1;
3365 Config.onoff.memory_cache_disk = 1;
3366 } else if (strcmp(token, "disk") == 0) {
3367 Config.onoff.memory_cache_first = 0;
3368 Config.onoff.memory_cache_disk = 1;
3369 } else if (strncmp(token, "net", 3) == 0) {
3370 Config.onoff.memory_cache_first = 1;
3371 Config.onoff.memory_cache_disk = 0;
3372 } else if (strcmp(token, "never") == 0) {
3373 Config.onoff.memory_cache_first = 0;
3374 Config.onoff.memory_cache_disk = 0;
3375 } else {
3376 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3377 self_destruct();
3378 }
3379 }
3380
3381 static void
3382 dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config)
3383 {
3384 storeAppendPrintf(entry, "%s ", name);
3385 if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
3386 storeAppendPrintf(entry, "always");
3387 else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
3388 storeAppendPrintf(entry, "disk");
3389 else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
3390 storeAppendPrintf(entry, "network");
3391 else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
3392 storeAppendPrintf(entry, "none");
3393 storeAppendPrintf(entry, "\n");
3394 }
3395
3396 #include "cf_parser.cci"
3397
3398 peer_t
3399 parseNeighborType(const char *s)
3400 {
3401 if (!strcasecmp(s, "parent"))
3402 return PEER_PARENT;
3403
3404 if (!strcasecmp(s, "neighbor"))
3405 return PEER_SIBLING;
3406
3407 if (!strcasecmp(s, "neighbour"))
3408 return PEER_SIBLING;
3409
3410 if (!strcasecmp(s, "sibling"))
3411 return PEER_SIBLING;
3412
3413 if (!strcasecmp(s, "multicast"))
3414 return PEER_MULTICAST;
3415
3416 debugs(15, DBG_CRITICAL, "WARNING: Unknown neighbor type: " << s);
3417
3418 return PEER_SIBLING;
3419 }
3420
3421 #if USE_WCCPv2
3422 static void
3423 parse_IpAddress_list(Ip::Address_list ** head)
3424 {
3425 char *token;
3426 Ip::Address_list *s;
3427 Ip::Address ipa;
3428
3429 while ((token = strtok(NULL, w_space))) {
3430 if (GetHostWithPort(token, &ipa)) {
3431
3432 while (*head)
3433 head = &(*head)->next;
3434
3435 s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s)));
3436 s->s = ipa;
3437
3438 *head = s;
3439 } else
3440 self_destruct();
3441 }
3442 }
3443
3444 static void
3445 dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s)
3446 {
3447 char ntoabuf[MAX_IPSTRLEN];
3448
3449 while (s) {
3450 storeAppendPrintf(e, "%s %s\n",
3451 n,
3452 s->s.NtoA(ntoabuf,MAX_IPSTRLEN));
3453 s = s->next;
3454 }
3455 }
3456
3457 static void
3458 free_IpAddress_list(Ip::Address_list ** head)
3459 {
3460 if (*head) delete *head;
3461 *head = NULL;
3462 }
3463
3464 #if CURRENTLY_UNUSED
3465 /* This code was previously used by http_port. Left as it really should
3466 * be used by icp_port and htcp_port
3467 */
3468 static int
3469 check_null_IpAddress_list(const Ip::Address_list * s)
3470 {
3471 return NULL == s;
3472 }
3473
3474 #endif /* CURRENTLY_UNUSED */
3475 #endif /* USE_WCCPv2 */
3476
3477 static void
3478 parsePortSpecification(AnyP::PortCfg * s, char *token)
3479 {
3480 char *host = NULL;
3481 unsigned short port = 0;
3482 char *t = NULL;
3483 char *junk = NULL;
3484
3485 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3486 s->name = xstrdup(token);
3487 s->connection_auth_disabled = false;
3488
3489 if (*token == '[') {
3490 /* [ipv6]:port */
3491 host = token + 1;
3492 t = strchr(host, ']');
3493 if (!t) {
3494 debugs(3, DBG_CRITICAL, s->protocol << "_port: missing ']' on IPv6 address: " << token);
3495 self_destruct();
3496 }
3497 *t = '\0';
3498 ++t;
3499 if (*t != ':') {
3500 debugs(3, DBG_CRITICAL, s->protocol << "_port: missing Port in: " << token);
3501 self_destruct();
3502 }
3503 if (!Ip::EnableIpv6) {
3504 debugs(3, DBG_CRITICAL, "FATAL: " << s->protocol << "_port: IPv6 is not available.");
3505 self_destruct();
3506 }
3507 port = xatos(t + 1);
3508 } else if ((t = strchr(token, ':'))) {
3509 /* host:port */
3510 /* ipv4:port */
3511 host = token;
3512 *t = '\0';
3513 port = xatos(t + 1);
3514
3515 } else if (strtol(token, &junk, 10) && !*junk) {
3516 port = xatos(token);
3517 debugs(3, 3, s->protocol << "_port: found Listen on Port: " << port);
3518 } else {
3519 debugs(3, DBG_CRITICAL, s->protocol << "_port: missing Port: " << token);
3520 self_destruct();
3521 }
3522
3523 if (port == 0 && host != NULL) {
3524 debugs(3, DBG_CRITICAL, s->protocol << "_port: Port cannot be 0: " << token);
3525 self_destruct();
3526 }
3527
3528 if (NULL == host) {
3529 s->s.SetAnyAddr();
3530 s->s.SetPort(port);
3531 if (!Ip::EnableIpv6)
3532 s->s.SetIPv4();
3533 debugs(3, 3, s->protocol << "_port: found Listen on wildcard address: *:" << s->s.GetPort() );
3534 } else if ( (s->s = host) ) { /* check/parse numeric IPA */
3535 s->s.SetPort(port);
3536 if (!Ip::EnableIpv6)
3537 s->s.SetIPv4();
3538 debugs(3, 3, s->protocol << "_port: Listen on Host/IP: " << host << " --> " << s->s);
3539 } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
3540 /* dont use ipcache */
3541 s->defaultsite = xstrdup(host);
3542 s->s.SetPort(port);
3543 if (!Ip::EnableIpv6)
3544 s->s.SetIPv4();
3545 debugs(3, 3, s->protocol << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
3546 } else {
3547 debugs(3, DBG_CRITICAL, s->protocol << "_port: failed to resolve Host/IP: " << host);
3548 self_destruct();
3549 }
3550 }
3551
3552 static void
3553 parse_port_option(AnyP::PortCfg * s, char *token)
3554 {
3555 /* modes first */
3556
3557 if (strcmp(token, "accel") == 0) {
3558 if (s->intercepted || s->spoof_client_ip) {
3559 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3560 self_destruct();
3561 }
3562 s->accel = s->vhost = 1;
3563 } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
3564 if (s->accel || s->spoof_client_ip) {
3565 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3566 self_destruct();
3567 }
3568 s->intercepted = 1;
3569 Ip::Interceptor.StartInterception();
3570 /* Log information regarding the port modes under interception. */
3571 debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
3572 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
3573
3574 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3575 if (Ip::EnableIpv6)
3576 debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)");
3577 if ( !s->s.SetIPv4() ) {
3578 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s->s );
3579 self_destruct();
3580 }
3581 } else if (strcmp(token, "tproxy") == 0) {
3582 if (s->intercepted || s->accel) {
3583 debugs(3,DBG_CRITICAL, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3584 self_destruct();
3585 }
3586 s->spoof_client_ip = 1;
3587 Ip::Interceptor.StartTransparency();
3588 /* Log information regarding the port modes under transparency. */
3589 debugs(3, DBG_IMPORTANT, "Starting IP Spoofing on port " << s->s);
3590 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (IP spoofing enabled)");
3591
3592 if (!Ip::Interceptor.ProbeForTproxy(s->s)) {
3593 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3594 self_destruct();
3595 }
3596
3597 } else if (strncmp(token, "defaultsite=", 12) == 0) {
3598 if (!s->accel) {
3599 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3600 self_destruct();
3601 }
3602 safe_free(s->defaultsite);
3603 s->defaultsite = xstrdup(token + 12);
3604 } else if (strcmp(token, "vhost") == 0) {
3605 if (!s->accel) {
3606 debugs(3, DBG_CRITICAL, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3607 }
3608 s->accel = s->vhost = 1;
3609 } else if (strcmp(token, "no-vhost") == 0) {
3610 if (!s->accel) {
3611 debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3612 }
3613 s->vhost = 0;
3614 } else if (strcmp(token, "vport") == 0) {
3615 if (!s->accel) {
3616 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3617 self_destruct();
3618 }
3619 s->vport = -1;
3620 } else if (strncmp(token, "vport=", 6) == 0) {
3621 if (!s->accel) {
3622 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3623 self_destruct();
3624 }
3625 s->vport = xatos(token + 6);
3626 } else if (strncmp(token, "protocol=", 9) == 0) {
3627 if (!s->accel) {
3628 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3629 self_destruct();
3630 }
3631 s->protocol = xstrdup(token + 9);
3632 } else if (strcmp(token, "allow-direct") == 0) {
3633 if (!s->accel) {
3634 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3635 self_destruct();
3636 }
3637 s->allow_direct = 1;
3638 } else if (strcmp(token, "act-as-origin") == 0) {
3639 if (!s->accel) {
3640 debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3641 } else
3642 s->actAsOrigin = 1;
3643 } else if (strcmp(token, "ignore-cc") == 0) {
3644 #if !USE_HTTP_VIOLATIONS
3645 if (!s->accel) {
3646 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3647 self_destruct();
3648 }
3649 #endif
3650 s->ignore_cc = 1;
3651 } else if (strncmp(token, "name=", 5) == 0) {
3652 safe_free(s->name);
3653 s->name = xstrdup(token + 5);
3654 } else if (strcmp(token, "no-connection-auth") == 0) {
3655 s->connection_auth_disabled = true;
3656 } else if (strcmp(token, "connection-auth=off") == 0) {
3657 s->connection_auth_disabled = true;
3658 } else if (strcmp(token, "connection-auth") == 0) {
3659 s->connection_auth_disabled = false;
3660 } else if (strcmp(token, "connection-auth=on") == 0) {
3661 s->connection_auth_disabled = false;
3662 } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
3663 if (!strcasecmp(token + 23, "off"))
3664 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3665 else if (!strcasecmp(token + 23, "transparent"))
3666 s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
3667 else if (!strcasecmp(token + 23, "always"))
3668 s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
3669 else
3670 self_destruct();
3671 } else if (strcmp(token, "ipv4") == 0) {
3672 if ( !s->s.SetIPv4() ) {
3673 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s );
3674 self_destruct();
3675 }
3676 } else if (strcmp(token, "tcpkeepalive") == 0) {
3677 s->tcp_keepalive.enabled = 1;
3678 } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
3679 char *t = token + 13;
3680 s->tcp_keepalive.enabled = 1;
3681 s->tcp_keepalive.idle = xatoui(t);
3682 t = strchr(t, ',');
3683 if (t) {
3684 ++t;
3685 s->tcp_keepalive.interval = xatoui(t);
3686 t = strchr(t, ',');
3687 }
3688 if (t) {
3689 ++t;
3690 s->tcp_keepalive.timeout = xatoui(t);
3691 // t = strchr(t, ','); // not really needed, left in as documentation
3692 }
3693 #if USE_SSL
3694 } else if (strcasecmp(token, "sslBump") == 0) {
3695 debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " <<
3696 "in http_port. Use 'ssl-bump' instead.");
3697 s->sslBump = 1; // accelerated when bumped, otherwise not
3698 } else if (strcmp(token, "ssl-bump") == 0) {
3699 s->sslBump = 1; // accelerated when bumped, otherwise not
3700 } else if (strncmp(token, "cert=", 5) == 0) {
3701 safe_free(s->cert);
3702 s->cert = xstrdup(token + 5);
3703 } else if (strncmp(token, "key=", 4) == 0) {
3704 safe_free(s->key);
3705 s->key = xstrdup(token + 4);
3706 } else if (strncmp(token, "version=", 8) == 0) {
3707 s->version = xatoi(token + 8);
3708 if (s->version < 1 || s->version > 4)
3709 self_destruct();
3710 } else if (strncmp(token, "options=", 8) == 0) {
3711 safe_free(s->options);
3712 s->options = xstrdup(token + 8);
3713 } else if (strncmp(token, "cipher=", 7) == 0) {
3714 safe_free(s->cipher);
3715 s->cipher = xstrdup(token + 7);
3716 } else if (strncmp(token, "clientca=", 9) == 0) {
3717 safe_free(s->clientca);
3718 s->clientca = xstrdup(token + 9);
3719 } else if (strncmp(token, "cafile=", 7) == 0) {
3720 safe_free(s->cafile);
3721 s->cafile = xstrdup(token + 7);
3722 } else if (strncmp(token, "capath=", 7) == 0) {
3723 safe_free(s->capath);
3724 s->capath = xstrdup(token + 7);
3725 } else if (strncmp(token, "crlfile=", 8) == 0) {
3726 safe_free(s->crlfile);
3727 s->crlfile = xstrdup(token + 8);
3728 } else if (strncmp(token, "dhparams=", 9) == 0) {
3729 safe_free(s->dhfile);
3730 s->dhfile = xstrdup(token + 9);
3731 } else if (strncmp(token, "sslflags=", 9) == 0) {
3732 safe_free(s->sslflags);
3733 s->sslflags = xstrdup(token + 9);
3734 } else if (strncmp(token, "sslcontext=", 11) == 0) {
3735 safe_free(s->sslContextSessionId);
3736 s->sslContextSessionId = xstrdup(token + 11);
3737 } else if (strcmp(token, "generate-host-certificates") == 0) {
3738 s->generateHostCertificates = true;
3739 } else if (strcmp(token, "generate-host-certificates=on") == 0) {
3740 s->generateHostCertificates = true;
3741 } else if (strcmp(token, "generate-host-certificates=off") == 0) {
3742 s->generateHostCertificates = false;
3743 } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) {
3744 parseBytesOptionValue(&s->dynamicCertMemCacheSize, B_BYTES_STR, token + 28);
3745 #endif
3746 } else {
3747 debugs(3, DBG_CRITICAL, "FATAL: Unknown http(s)_port option '" << token << "'.");
3748 self_destruct();
3749 }
3750 }
3751
3752 void
3753 add_http_port(char *portspec)
3754 {
3755 AnyP::PortCfg *s = new AnyP::PortCfg("http_port");
3756 parsePortSpecification(s, portspec);
3757 // we may need to merge better if the above returns a list with clones
3758 assert(s->next == NULL);
3759 s->next = cbdataReference(Config.Sockaddr.http);
3760 cbdataReferenceDone(Config.Sockaddr.http);
3761 Config.Sockaddr.http = cbdataReference(s);
3762 }
3763
3764 static void
3765 parsePortCfg(AnyP::PortCfg ** head, const char *optionName)
3766 {
3767 const char *protocol = NULL;
3768 if (strcmp(optionName, "http_port") == 0 ||
3769 strcmp(optionName, "ascii_port") == 0)
3770 protocol = "http";
3771 else if (strcmp(optionName, "https_port") == 0)
3772 protocol = "https";
3773 if (!protocol) {
3774 self_destruct();
3775 return;
3776 }
3777
3778 char *token = strtok(NULL, w_space);
3779
3780 if (!token) {
3781 self_destruct();
3782 return;
3783 }
3784
3785 AnyP::PortCfg *s = new AnyP::PortCfg(protocol);
3786 parsePortSpecification(s, token);
3787
3788 /* parse options ... */
3789 while ((token = strtok(NULL, w_space))) {
3790 parse_port_option(s, token);
3791 }
3792
3793 #if USE_SSL
3794 if (strcasecmp(protocol, "https") == 0) {
3795 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3796 const bool hijacked = s->spoof_client_ip || s->intercepted;
3797 if (s->sslBump && !hijacked) {
3798 debugs(3, DBG_CRITICAL, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3799 self_destruct();
3800 }
3801 if (hijacked && !s->sslBump) {
3802 debugs(3, DBG_CRITICAL, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3803 self_destruct();
3804 }
3805 }
3806 #endif
3807
3808 if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.IsAnyAddr()) {
3809 // clone the port options from *s to *(s->next)
3810 s->next = cbdataReference(s->clone());
3811 s->next->s.SetIPv4();
3812 debugs(3, 3, protocol << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
3813 }
3814
3815 while (*head)
3816 head = &(*head)->next;
3817
3818 *head = cbdataReference(s);
3819 }
3820
3821 static void
3822 dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfg * s)
3823 {
3824 char buf[MAX_IPSTRLEN];
3825
3826 storeAppendPrintf(e, "%s %s",
3827 n,
3828 s->s.ToURL(buf,MAX_IPSTRLEN));
3829
3830 // MODES and specific sub-options.
3831 if (s->intercepted)
3832 storeAppendPrintf(e, " intercept");
3833
3834 else if (s->spoof_client_ip)
3835 storeAppendPrintf(e, " tproxy");
3836
3837 else if (s->accel) {
3838 storeAppendPrintf(e, " accel");
3839
3840 if (s->vhost)
3841 storeAppendPrintf(e, " vhost");
3842
3843 if (s->vport < 0)
3844 storeAppendPrintf(e, " vport");
3845 else if (s->vport > 0)
3846 storeAppendPrintf(e, " vport=%d", s->vport);
3847
3848 if (s->defaultsite)
3849 storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3850
3851 if (s->protocol && strcmp(s->protocol,"http") != 0)
3852 storeAppendPrintf(e, " protocol=%s", s->protocol);
3853
3854 if (s->allow_direct)
3855 storeAppendPrintf(e, " allow-direct");
3856
3857 if (s->ignore_cc)
3858 storeAppendPrintf(e, " ignore-cc");
3859
3860 }
3861
3862 // Generic independent options
3863
3864 if (s->name)
3865 storeAppendPrintf(e, " name=%s", s->name);
3866
3867 #if USE_HTTP_VIOLATIONS
3868 if (!s->accel && s->ignore_cc)
3869 storeAppendPrintf(e, " ignore-cc");
3870 #endif
3871
3872 if (s->connection_auth_disabled)
3873 storeAppendPrintf(e, " connection-auth=off");
3874 else
3875 storeAppendPrintf(e, " connection-auth=on");
3876
3877 if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3878 const char *pmtu;
3879
3880 if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3881 pmtu = "always";
3882 else
3883 pmtu = "transparent";
3884
3885 storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3886 }
3887
3888 if (s->s.IsAnyAddr() && !s->s.IsIPv6())
3889 storeAppendPrintf(e, " ipv4");
3890
3891 if (s->tcp_keepalive.enabled) {
3892 if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
3893 storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
3894 } else {
3895 storeAppendPrintf(e, " tcpkeepalive");
3896 }
3897 }
3898
3899 #if USE_SSL
3900 if (s->sslBump)
3901 storeAppendPrintf(e, " ssl-bump");
3902
3903 if (s->cert)
3904 storeAppendPrintf(e, " cert=%s", s->cert);
3905
3906 if (s->key)
3907 storeAppendPrintf(e, " key=%s", s->key);
3908
3909 if (s->version)
3910 storeAppendPrintf(e, " version=%d", s->version);
3911
3912 if (s->options)
3913 storeAppendPrintf(e, " options=%s", s->options);
3914
3915 if (s->cipher)
3916 storeAppendPrintf(e, " cipher=%s", s->cipher);
3917
3918 if (s->cafile)
3919 storeAppendPrintf(e, " cafile=%s", s->cafile);
3920
3921 if (s->capath)
3922 storeAppendPrintf(e, " capath=%s", s->capath);
3923
3924 if (s->crlfile)
3925 storeAppendPrintf(e, " crlfile=%s", s->crlfile);
3926
3927 if (s->dhfile)
3928 storeAppendPrintf(e, " dhparams=%s", s->dhfile);
3929
3930 if (s->sslflags)
3931 storeAppendPrintf(e, " sslflags=%s", s->sslflags);
3932
3933 if (s->sslContextSessionId)
3934 storeAppendPrintf(e, " sslcontext=%s", s->sslContextSessionId);
3935
3936 if (s->generateHostCertificates)
3937 storeAppendPrintf(e, " generate-host-certificates");
3938
3939 if (s->dynamicCertMemCacheSize != std::numeric_limits<size_t>::max())
3940 storeAppendPrintf(e, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s->dynamicCertMemCacheSize, B_BYTES_STR);
3941 #endif
3942 }
3943
3944 static void
3945 dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfg * s)
3946 {
3947 while (s) {
3948 dump_generic_port(e, n, s);
3949 storeAppendPrintf(e, "\n");
3950 s = s->next;
3951 }
3952 }
3953
3954 static void
3955 free_PortCfg(AnyP::PortCfg ** head)
3956 {
3957 AnyP::PortCfg *s;
3958
3959 while ((s = *head) != NULL) {
3960 *head = s->next;
3961 cbdataReferenceDone(s);
3962 }
3963 }
3964
3965 void
3966 configFreeMemory(void)
3967 {
3968 free_all();
3969 #if USE_SSL
3970 SSL_CTX_free(Config.ssl_client.sslContext);
3971 #endif
3972 }
3973
3974 void
3975 requirePathnameExists(const char *name, const char *path)
3976 {
3977
3978 struct stat sb;
3979 char pathbuf[BUFSIZ];
3980 assert(path != NULL);
3981
3982 if (Config.chroot_dir && (geteuid() == 0)) {
3983 snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3984 path = pathbuf;
3985 }
3986
3987 if (stat(path, &sb) < 0) {
3988 debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL ":"") << "ERROR: " << name << " " << path << ": " << xstrerror());
3989 // keep going to find more issues if we are only checking the config file with "-k parse"
3990 if (opt_parse_cfg_only)
3991 return;
3992 // this is fatal if it is found during startup or reconfigure
3993 if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
3994 fatalf("%s %s: %s", name, path, xstrerror());
3995 }
3996 }
3997
3998 char *
3999 strtokFile(void)
4000 {
4001 return ConfigParser::strtokFile();
4002 }
4003
4004 #include "AccessLogEntry.h"
4005
4006 static void
4007 parse_access_log(CustomLog ** logs)
4008 {
4009 const char *filename, *logdef_name;
4010
4011 CustomLog *cl = (CustomLog *)xcalloc(1, sizeof(*cl));
4012
4013 if ((filename = strtok(NULL, w_space)) == NULL) {
4014 self_destruct();
4015 return;
4016 }
4017
4018 if (strcmp(filename, "none") == 0) {
4019 cl->type = Log::Format::CLF_NONE;
4020 aclParseAclList(LegacyParser, &cl->aclList);
4021 while (*logs)
4022 logs = &(*logs)->next;
4023 *logs = cl;
4024 return;
4025 }
4026
4027 if ((logdef_name = strtok(NULL, w_space)) == NULL)
4028 logdef_name = "squid";
4029
4030 debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'");
4031
4032 cl->filename = xstrdup(filename);
4033
4034 /* look for the definition pointer corresponding to this name */
4035 Format::Format *lf = Log::TheConfig.logformats;
4036
4037 while (lf != NULL) {
4038 debugs(3, 9, "Comparing against '" << lf->name << "'");
4039
4040 if (strcmp(lf->name, logdef_name) == 0)
4041 break;
4042
4043 lf = lf->next;
4044 }
4045
4046 if (lf != NULL) {
4047 cl->type = Log::Format::CLF_CUSTOM;
4048 cl->logFormat = lf;
4049 } else if (strcmp(logdef_name, "auto") == 0) {
4050 debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4051 cl->type = Log::Format::CLF_SQUID;
4052 } else if (strcmp(logdef_name, "squid") == 0) {
4053 cl->type = Log::Format::CLF_SQUID;
4054 } else if (strcmp(logdef_name, "common") == 0) {
4055 cl->type = Log::Format::CLF_COMMON;
4056 } else if (strcmp(logdef_name, "combined") == 0) {
4057 cl->type = Log::Format::CLF_COMBINED;
4058 #if ICAP_CLIENT
4059 } else if (strcmp(logdef_name, "icap_squid") == 0) {
4060 cl->type = Log::Format::CLF_ICAP_SQUID;
4061 #endif
4062 } else if (strcmp(logdef_name, "useragent") == 0) {
4063 cl->type = Log::Format::CLF_USERAGENT;
4064 } else if (strcmp(logdef_name, "referrer") == 0) {
4065 cl->type = Log::Format::CLF_REFERER;
4066 } else {
4067 debugs(3, DBG_CRITICAL, "Log format '" << logdef_name << "' is not defined");
4068 self_destruct();
4069 return;
4070 }
4071
4072 aclParseAclList(LegacyParser, &cl->aclList);
4073
4074 while (*logs)
4075 logs = &(*logs)->next;
4076
4077 *logs = cl;
4078 }
4079
4080 static int
4081 check_null_access_log(CustomLog *customlog_definitions)
4082 {
4083 return customlog_definitions == NULL;
4084 }
4085
4086 static void
4087 dump_access_log(StoreEntry * entry, const char *name, CustomLog * logs)
4088 {
4089 CustomLog *log;
4090
4091 for (log = logs; log; log = log->next) {
4092 storeAppendPrintf(entry, "%s ", name);
4093
4094 switch (log->type) {
4095
4096 case Log::Format::CLF_CUSTOM:
4097 storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name);
4098 break;
4099
4100 case Log::Format::CLF_NONE:
4101 storeAppendPrintf(entry, "none");
4102 break;
4103
4104 case Log::Format::CLF_SQUID:
4105 storeAppendPrintf(entry, "%s squid", log->filename);
4106 break;
4107
4108 case Log::Format::CLF_COMBINED:
4109 storeAppendPrintf(entry, "%s combined", log->filename);
4110 break;
4111
4112 case Log::Format::CLF_COMMON:
4113 storeAppendPrintf(entry, "%s common", log->filename);
4114 break;
4115
4116 #if ICAP_CLIENT
4117 case Log::Format::CLF_ICAP_SQUID:
4118 storeAppendPrintf(entry, "%s icap_squid", log->filename);
4119 break;
4120 #endif
4121 case Log::Format::CLF_USERAGENT:
4122 storeAppendPrintf(entry, "%s useragent", log->filename);
4123 break;
4124
4125 case Log::Format::CLF_REFERER:
4126 storeAppendPrintf(entry, "%s referrer", log->filename);
4127 break;
4128
4129 case Log::Format::CLF_UNKNOWN:
4130 break;
4131 }
4132
4133 if (log->aclList)
4134 dump_acl_list(entry, log->aclList);
4135
4136 storeAppendPrintf(entry, "\n");
4137 }
4138 }
4139
4140 static void
4141 free_access_log(CustomLog ** definitions)
4142 {
4143 while (*definitions) {
4144 CustomLog *log = *definitions;
4145 *definitions = log->next;
4146
4147 log->logFormat = NULL;
4148 log->type = Log::Format::CLF_UNKNOWN;
4149
4150 if (log->aclList)
4151 aclDestroyAclList(&log->aclList);
4152
4153 safe_free(log->filename);
4154
4155 xfree(log);
4156 }
4157 }
4158
4159 /// parses list of integers form name=N1,N2,N3,...
4160 static bool
4161 parseNamedIntList(const char *data, const String &name, Vector<int> &list)
4162 {
4163 if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) {
4164 data += name.size();
4165 if (*data == '=') {
4166 while (true) {
4167 ++data;
4168 int value = 0;
4169 if (!StringToInt(data, value, &data, 10))
4170 break;
4171 list.push_back(value);
4172 if (*data == '\0' || *data != ',')
4173 break;
4174 }
4175 }
4176 }
4177 return data && *data == '\0';
4178 }
4179
4180 static void
4181 parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4182 {
4183 #if !HAVE_CPU_AFFINITY
4184 debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " <<
4185 "support, do not set 'cpu_affinity_map'");
4186 self_destruct();
4187 #endif /* HAVE_CPU_AFFINITY */
4188
4189 if (!*cpuAffinityMap)
4190 *cpuAffinityMap = new CpuAffinityMap;
4191
4192 const char *const pToken = strtok(NULL, w_space);
4193 const char *const cToken = strtok(NULL, w_space);
4194 Vector<int> processes, cores;
4195 if (!parseNamedIntList(pToken, "process_numbers", processes)) {
4196 debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " <<
4197 "in 'cpu_affinity_map'");
4198 self_destruct();
4199 } else if (!parseNamedIntList(cToken, "cores", cores)) {
4200 debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " <<
4201 "'cpu_affinity_map'");
4202 self_destruct();
4203 } else if (!(*cpuAffinityMap)->add(processes, cores)) {
4204 debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " <<
4205 "process_numbers and cores lists differ in length or " <<
4206 "contain numbers <= 0");
4207 self_destruct();
4208 }
4209 }
4210
4211 static void
4212 dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap)
4213 {
4214 if (cpuAffinityMap) {
4215 storeAppendPrintf(entry, "%s process_numbers=", name);
4216 for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4217 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4218 cpuAffinityMap->processes()[i]);
4219 }
4220 storeAppendPrintf(entry, " cores=");
4221 for (size_t i = 0; i < cpuAffinityMap->cores().size(); ++i) {
4222 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4223 cpuAffinityMap->cores()[i]);
4224 }
4225 storeAppendPrintf(entry, "\n");
4226 }
4227 }
4228
4229 static void
4230 free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4231 {
4232 delete *cpuAffinityMap;
4233 *cpuAffinityMap = NULL;
4234 }
4235
4236 #if USE_ADAPTATION
4237
4238 static void
4239 parse_adaptation_service_set_type()
4240 {
4241 Adaptation::Config::ParseServiceSet();
4242 }
4243
4244 static void
4245 parse_adaptation_service_chain_type()
4246 {
4247 Adaptation::Config::ParseServiceChain();
4248 }
4249
4250 static void
4251 parse_adaptation_access_type()
4252 {
4253 Adaptation::Config::ParseAccess(LegacyParser);
4254 }
4255 #endif /* USE_ADAPTATION */
4256
4257 #if ICAP_CLIENT
4258
4259 static void
4260 parse_icap_service_type(Adaptation::Icap::Config * cfg)
4261 {
4262 cfg->parseService();
4263 }
4264
4265 static void
4266 free_icap_service_type(Adaptation::Icap::Config * cfg)
4267 {
4268 cfg->freeService();
4269 }
4270
4271 static void
4272 dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
4273 {
4274 cfg.dumpService(entry, name);
4275 }
4276
4277 static void
4278 parse_icap_class_type()
4279 {
4280 debugs(93, DBG_CRITICAL, "WARNING: 'icap_class' is depricated. " <<
4281 "Use 'adaptation_service_set' instead");
4282 Adaptation::Config::ParseServiceSet();
4283 }
4284
4285 static void
4286 parse_icap_access_type()
4287 {
4288 debugs(93, DBG_CRITICAL, "WARNING: 'icap_access' is depricated. " <<
4289 "Use 'adaptation_access' instead");
4290 Adaptation::Config::ParseAccess(LegacyParser);
4291 }
4292
4293 #endif
4294
4295 #if USE_ECAP
4296
4297 static void
4298 parse_ecap_service_type(Adaptation::Ecap::Config * cfg)
4299 {
4300 cfg->parseService();
4301 }
4302
4303 static void
4304 free_ecap_service_type(Adaptation::Ecap::Config * cfg)
4305 {
4306 cfg->freeService();
4307 }
4308
4309 static void
4310 dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
4311 {
4312 cfg.dumpService(entry, name);
4313 }
4314
4315 #endif /* USE_ECAP */
4316
4317 #if ICAP_CLIENT
4318 static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4319 {
4320 char *token;
4321 time_t d;
4322 time_t m;
4323 cfg->service_failure_limit = GetInteger();
4324
4325 if ((token = strtok(NULL, w_space)) == NULL)
4326 return;
4327
4328 if (strcmp(token,"in") != 0) {
4329 debugs(3, DBG_CRITICAL, "expecting 'in' on'" << config_input_line << "'");
4330 self_destruct();
4331 }
4332
4333 if ((token = strtok(NULL, w_space)) == NULL) {
4334 self_destruct();
4335 }
4336
4337 d = static_cast<time_t> (xatoi(token));
4338
4339 m = static_cast<time_t> (1);
4340
4341 if (0 == d)
4342 (void) 0;
4343 else if ((token = strtok(NULL, w_space)) == NULL) {
4344 debugs(3, DBG_CRITICAL, "No time-units on '" << config_input_line << "'");
4345 self_destruct();
4346 } else if ((m = parseTimeUnits(token, false)) == 0)
4347 self_destruct();
4348
4349 cfg->oldest_service_failure = (m * d);
4350 }
4351
4352 static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg)
4353 {
4354 storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit);
4355 if (cfg.oldest_service_failure > 0) {
4356 storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure);
4357 }
4358 storeAppendPrintf(entry, "\n");
4359 }
4360
4361 static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4362 {
4363 cfg->oldest_service_failure = 0;
4364 cfg->service_failure_limit = 0;
4365 }
4366 #endif
4367
4368 #if USE_SSL
4369 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
4370 {
4371 char *al;
4372 sslproxy_cert_adapt *ca = (sslproxy_cert_adapt *) xcalloc(1, sizeof(sslproxy_cert_adapt));
4373 if ((al = strtok(NULL, w_space)) == NULL) {
4374 self_destruct();
4375 return;
4376 }
4377
4378 const char *param;
4379 if ( char *s = strchr(al, '{')) {
4380 *s = '\0'; // terminate the al string
4381 ++s;
4382 param = s;
4383 s = strchr(s, '}');
4384 if (!s) {
4385 self_destruct();
4386 return;
4387 }
4388 *s = '\0';
4389 } else
4390 param = NULL;
4391
4392 if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidAfter]) == 0) {
4393 ca->alg = Ssl::algSetValidAfter;
4394 ca->param = strdup("on");
4395 } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidBefore]) == 0) {
4396 ca->alg = Ssl::algSetValidBefore;
4397 ca->param = strdup("on");
4398 } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetCommonName]) == 0) {
4399 ca->alg = Ssl::algSetCommonName;
4400 if (param) {
4401 if (strlen(param) > 64) {
4402 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param << "} : using common name longer than 64 bytes is not supported");
4403 self_destruct();
4404 return;
4405 }
4406 ca->param = strdup(param);
4407 }
4408 } else {
4409 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al);
4410 self_destruct();
4411 return;
4412 }
4413
4414 aclParseAclList(LegacyParser, &ca->aclList);
4415
4416 while (*cert_adapt)
4417 cert_adapt = &(*cert_adapt)->next;
4418
4419 *cert_adapt = ca;
4420 }
4421
4422 static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt)
4423 {
4424 for (sslproxy_cert_adapt *ca = cert_adapt; ca != NULL; ca = ca->next) {
4425 storeAppendPrintf(entry, "%s ", name);
4426 storeAppendPrintf(entry, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca->alg), ca->param);
4427 if (ca->aclList)
4428 dump_acl_list(entry, ca->aclList);
4429 storeAppendPrintf(entry, "\n");
4430 }
4431 }
4432
4433 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt)
4434 {
4435 while (*cert_adapt) {
4436 sslproxy_cert_adapt *ca = *cert_adapt;
4437 *cert_adapt = ca->next;
4438 safe_free(ca->param);
4439
4440 if (ca->aclList)
4441 aclDestroyAclList(&ca->aclList);
4442
4443 safe_free(ca);
4444 }
4445 }
4446
4447 static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign)
4448 {
4449 char *al;
4450 sslproxy_cert_sign *cs = (sslproxy_cert_sign *) xcalloc(1, sizeof(sslproxy_cert_sign));
4451 if ((al = strtok(NULL, w_space)) == NULL) {
4452 self_destruct();
4453 return;
4454 }
4455
4456 if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignTrusted]) == 0)
4457 cs->alg = Ssl::algSignTrusted;
4458 else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignUntrusted]) == 0)
4459 cs->alg = Ssl::algSignUntrusted;
4460 else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignSelf]) == 0)
4461 cs->alg = Ssl::algSignSelf;
4462 else {
4463 debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al);
4464 self_destruct();
4465 return;
4466 }
4467
4468 aclParseAclList(LegacyParser, &cs->aclList);
4469
4470 while (*cert_sign)
4471 cert_sign = &(*cert_sign)->next;
4472
4473 *cert_sign = cs;
4474 }
4475
4476 static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign)
4477 {
4478 sslproxy_cert_sign *cs;
4479 for (cs = cert_sign; cs != NULL; cs = cs->next) {
4480 storeAppendPrintf(entry, "%s ", name);
4481 storeAppendPrintf(entry, "%s ", Ssl::certSignAlgorithm(cs->alg));
4482 if (cs->aclList)
4483 dump_acl_list(entry, cs->aclList);
4484 storeAppendPrintf(entry, "\n");
4485 }
4486 }
4487
4488 static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign)
4489 {
4490 while (*cert_sign) {
4491 sslproxy_cert_sign *cs = *cert_sign;
4492 *cert_sign = cs->next;
4493
4494 if (cs->aclList)
4495 aclDestroyAclList(&cs->aclList);
4496
4497 safe_free(cs);
4498 }
4499 }
4500
4501 class sslBumpCfgRr: public ::RegisteredRunner
4502 {
4503 public:
4504 static Ssl::BumpMode lastDeprecatedRule;
4505 /* RegisteredRunner API */
4506 virtual void run(const RunnerRegistry &);
4507 };
4508
4509 Ssl::BumpMode sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
4510
4511 RunnerRegistrationEntry(rrFinalizeConfig, sslBumpCfgRr);
4512
4513 void sslBumpCfgRr::run(const RunnerRegistry &r)
4514 {
4515 if (lastDeprecatedRule != Ssl::bumpEnd) {
4516 assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone);
4517 static char buf[1024];
4518 if (lastDeprecatedRule == Ssl::bumpClientFirst) {
4519 strcpy(buf, "ssl_bump deny all");
4520 debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated implicit "
4521 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4522 "must not use implicit rules. Update your ssl_bump rules.");
4523 } else {
4524 strcpy(buf, "ssl_bump allow all");
4525 debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated implicit "
4526 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4527 "inferior to the newer server-first bumping mode. New ssl_bump"
4528 " configurations must not use implicit rules. Update your ssl_bump rules.");
4529 }
4530 parse_line(buf);
4531 }
4532 }
4533
4534 static void parse_sslproxy_ssl_bump(acl_access **ssl_bump)
4535 {
4536 typedef const char *BumpCfgStyle;
4537 BumpCfgStyle bcsNone = NULL;
4538 BumpCfgStyle bcsNew = "new client/server-first/none";
4539 BumpCfgStyle bcsOld = "deprecated allow/deny";
4540 static BumpCfgStyle bumpCfgStyleLast = bcsNone;
4541 BumpCfgStyle bumpCfgStyleNow = bcsNone;
4542 char *bm;
4543 if ((bm = strtok(NULL, w_space)) == NULL) {
4544 self_destruct();
4545 return;
4546 }
4547
4548 // if this is the first rule proccessed
4549 if (*ssl_bump == NULL) {
4550 bumpCfgStyleLast = bcsNone;
4551 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
4552 }
4553
4554 acl_access *A = new acl_access;
4555 A->allow = allow_t(ACCESS_ALLOWED);
4556
4557 if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpClientFirst]) == 0) {
4558 A->allow.kind = Ssl::bumpClientFirst;
4559 bumpCfgStyleNow = bcsNew;
4560 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpServerFirst]) == 0) {
4561 A->allow.kind = Ssl::bumpServerFirst;
4562 bumpCfgStyleNow = bcsNew;
4563 } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpNone]) == 0) {
4564 A->allow.kind = Ssl::bumpNone;
4565 bumpCfgStyleNow = bcsNew;
4566 } else if (strcmp(bm, "allow") == 0) {
4567 debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated "
4568 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4569 "is usually inferior to the newer server-first "
4570 "bumping mode. Update your ssl_bump rules.");
4571 A->allow.kind = Ssl::bumpClientFirst;
4572 bumpCfgStyleNow = bcsOld;
4573 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpClientFirst;
4574 } else if (strcmp(bm, "deny") == 0) {
4575 debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated "
4576 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4577 "your ssl_bump rules.");
4578 A->allow.kind = Ssl::bumpNone;
4579 bumpCfgStyleNow = bcsOld;
4580 sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpNone;
4581 } else {
4582 debugs(3, DBG_CRITICAL, "FATAL: unknown ssl_bump mode: " << bm);
4583 self_destruct();
4584 return;
4585 }
4586
4587 if (bumpCfgStyleLast != bcsNone && bumpCfgStyleNow != bumpCfgStyleLast) {
4588 debugs(3, DBG_CRITICAL, "FATAL: do not mix " << bumpCfgStyleNow << " actions with " <<
4589 bumpCfgStyleLast << " actions. Update your ssl_bump rules.");
4590 self_destruct();
4591 return;
4592 }
4593
4594 bumpCfgStyleLast = bumpCfgStyleNow;
4595
4596 aclParseAclList(LegacyParser, &A->aclList);
4597
4598 acl_access *B, **T;
4599 for (B = *ssl_bump, T = ssl_bump; B; T = &B->next, B = B->next);
4600 *T = A;
4601 }
4602
4603 static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump)
4604 {
4605 acl_access *sb;
4606 for (sb = ssl_bump; sb != NULL; sb = sb->next) {
4607 storeAppendPrintf(entry, "%s ", name);
4608 storeAppendPrintf(entry, "%s ", Ssl::bumpMode(sb->allow.kind));
4609 if (sb->aclList)
4610 dump_acl_list(entry, sb->aclList);
4611 storeAppendPrintf(entry, "\n");
4612 }
4613 }
4614
4615 static void free_sslproxy_ssl_bump(acl_access **ssl_bump)
4616 {
4617 free_acl_access(ssl_bump);
4618 }
4619
4620 #endif
4621
4622 static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers)
4623 {
4624 if (!headers)
4625 return;
4626
4627 for (HeaderWithAclList::iterator hwa = headers->begin(); hwa != headers->end(); ++hwa) {
4628 storeAppendPrintf(entry, "%s ", hwa->fieldName.c_str());
4629 storeAppendPrintf(entry, "%s ", hwa->fieldValue.c_str());
4630 if (hwa->aclList)
4631 dump_acl_list(entry, hwa->aclList);
4632 storeAppendPrintf(entry, "\n");
4633 }
4634 }
4635
4636 static void parse_HeaderWithAclList(HeaderWithAclList **headers)
4637 {
4638 char *fn;
4639 if (!*headers) {
4640 *headers = new HeaderWithAclList;
4641 }
4642 if ((fn = strtok(NULL, w_space)) == NULL) {
4643 self_destruct();
4644 return;
4645 }
4646 HeaderWithAcl hwa;
4647 hwa.fieldName = fn;
4648 hwa.fieldId = httpHeaderIdByNameDef(fn, strlen(fn));
4649 if (hwa.fieldId == HDR_BAD_HDR)
4650 hwa.fieldId = HDR_OTHER;
4651
4652 String buf;
4653 bool wasQuoted;
4654 ConfigParser::ParseQuotedString(&buf, &wasQuoted);
4655 hwa.fieldValue = buf.termedBuf();
4656 hwa.quoted = wasQuoted;
4657 if (hwa.quoted) {
4658 Format::Format *nlf = new ::Format::Format("hdrWithAcl");
4659 if (!nlf->parse(hwa.fieldValue.c_str())) {
4660 self_destruct();
4661 return;
4662 }
4663 hwa.valueFormat = nlf;
4664 }
4665 aclParseAclList(LegacyParser, &hwa.aclList);
4666 (*headers)->push_back(hwa);
4667 }
4668
4669 static void free_HeaderWithAclList(HeaderWithAclList **header)
4670 {
4671 if (!(*header))
4672 return;
4673
4674 for (HeaderWithAclList::iterator hwa = (*header)->begin(); hwa != (*header)->end(); ++hwa) {
4675 if (hwa->aclList)
4676 aclDestroyAclList(&hwa->aclList);
4677
4678 if (hwa->valueFormat) {
4679 delete hwa->valueFormat;
4680 hwa->valueFormat = NULL;
4681 }
4682 }
4683 delete *header;
4684 *header = NULL;
4685 }
4686
4687 static void parse_note(Notes *notes)
4688 {
4689 assert(notes);
4690 notes->parse(LegacyParser);
4691 }
4692
4693 static void dump_note(StoreEntry *entry, const char *name, Notes &notes)
4694 {
4695 notes.dump(entry, name);
4696 }
4697
4698 static void free_note(Notes *notes)
4699 {
4700 notes->clean();
4701 }