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