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