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