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