]>
Commit | Line | Data |
---|---|---|
30a4f2a8 | 1 | /* |
262a0e14 | 2 | * $Id$ |
30a4f2a8 | 3 | * |
b510f3a1 | 4 | * DEBUG: section 03 Configuration File Parsing |
30a4f2a8 | 5 | * AUTHOR: Harvest Derived |
6 | * | |
2b6662ba | 7 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 8 | * ---------------------------------------------------------- |
30a4f2a8 | 9 | * |
2b6662ba | 10 | * Squid is the result of efforts by numerous individuals from |
11 | * the Internet community; see the CONTRIBUTORS file for full | |
12 | * details. Many organizations have provided support for Squid's | |
13 | * development; see the SPONSORS file for full details. Squid is | |
14 | * Copyrighted (C) 2001 by the Regents of the University of | |
15 | * California; see the COPYRIGHT file for full details. Squid | |
16 | * incorporates software developed and/or copyrighted by other | |
17 | * sources; see the CREDITS file for full details. | |
30a4f2a8 | 18 | * |
19 | * This program is free software; you can redistribute it and/or modify | |
20 | * it under the terms of the GNU General Public License as published by | |
21 | * the Free Software Foundation; either version 2 of the License, or | |
22 | * (at your option) any later version. | |
26ac0430 | 23 | * |
30a4f2a8 | 24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 | * GNU General Public License for more details. | |
26ac0430 | 28 | * |
30a4f2a8 | 29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program; if not, write to the Free Software | |
cbdec147 | 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 32 | * |
30a4f2a8 | 33 | */ |
cf5fd929 | 34 | |
44a47c6e | 35 | #include "squid.h" |
82b7abe3 AJ |
36 | |
37 | #include "acl/Acl.h" | |
38 | #include "acl/Gadgets.h" | |
39 | #include "acl/MethodData.h" | |
40 | #if USE_ADAPTATION | |
41 | #include "adaptation/Config.h" | |
42 | #endif | |
43 | #if ICAP_CLIENT | |
44 | #include "adaptation/icap/Config.h" | |
45 | #endif | |
46 | #if USE_ECAP | |
47 | #include "adaptation/ecap/Config.h" | |
48 | #endif | |
2d2b0bb7 AR |
49 | #include "auth/Config.h" |
50 | #include "auth/Scheme.h" | |
62ee09ca | 51 | #include "CacheManager.h" |
a80a77cf | 52 | #include "ConfigParser.h" |
82b7abe3 AJ |
53 | #include "eui/Config.h" |
54 | #if USE_SQUID_ESI | |
55 | #include "esi/Parser.h" | |
56 | #endif | |
57 | #include "HttpRequestMethod.h" | |
58 | #include "ident/Config.h" | |
96d89ea0 | 59 | #include "ip/Intercept.h" |
b7ac5457 | 60 | #include "ip/QosConfig.h" |
055421ee | 61 | #include "ip/tools.h" |
82b7abe3 AJ |
62 | #include "log/Config.h" |
63 | #include "MemBuf.h" | |
c8f4eac4 | 64 | #include "Parsing.h" |
82b7abe3 | 65 | #include "ProtoPort.h" |
1fa9b1a7 | 66 | #include "rfc1738.h" |
82b7abe3 AJ |
67 | #if SQUID_SNMP |
68 | #include "snmp.h" | |
69 | #endif | |
70 | #include "Store.h" | |
71 | #include "StoreFileSystem.h" | |
72 | #include "SwapDir.h" | |
d295d770 | 73 | #include "wordlist.h" |
40daaeb8 | 74 | #include "ipc/Kids.h" |
04f87469 | 75 | |
52303a3d | 76 | #if HAVE_GLOB_H |
592a09dc | 77 | #include <glob.h> |
52303a3d | 78 | #endif |
1df370e3 | 79 | |
62c7f90e | 80 | #if USE_ADAPTATION |
62c7f90e | 81 | static void parse_adaptation_service_set_type(); |
a22e6cd3 | 82 | static void parse_adaptation_service_chain_type(); |
62c7f90e | 83 | static void parse_adaptation_access_type(); |
62c7f90e AR |
84 | #endif |
85 | ||
3a69ddf3 | 86 | #if ICAP_CLIENT |
26cc52cb AR |
87 | static void parse_icap_service_type(Adaptation::Icap::Config *); |
88 | static void dump_icap_service_type(StoreEntry *, const char *, const Adaptation::Icap::Config &); | |
89 | static void free_icap_service_type(Adaptation::Icap::Config *); | |
c939dc70 AR |
90 | static void parse_icap_class_type(); |
91 | static void parse_icap_access_type(); | |
8277060a CT |
92 | |
93 | static void parse_icap_service_failure_limit(Adaptation::Icap::Config *); | |
94 | static void dump_icap_service_failure_limit(StoreEntry *, const char *, const Adaptation::Icap::Config &); | |
95 | static void free_icap_service_failure_limit(Adaptation::Icap::Config *); | |
3a69ddf3 | 96 | #endif |
97 | ||
21a26d31 | 98 | #if USE_ECAP |
574b508c AR |
99 | static void parse_ecap_service_type(Adaptation::Ecap::Config *); |
100 | static void dump_ecap_service_type(StoreEntry *, const char *, const Adaptation::Ecap::Config &); | |
101 | static void free_ecap_service_type(Adaptation::Ecap::Config *); | |
21a26d31 AR |
102 | #endif |
103 | ||
f5691f9c | 104 | CBDATA_TYPE(peer); |
105 | ||
8813e606 | 106 | static const char *const T_SECOND_STR = "second"; |
107 | static const char *const T_MINUTE_STR = "minute"; | |
108 | static const char *const T_HOUR_STR = "hour"; | |
109 | static const char *const T_DAY_STR = "day"; | |
110 | static const char *const T_WEEK_STR = "week"; | |
111 | static const char *const T_FORTNIGHT_STR = "fortnight"; | |
112 | static const char *const T_MONTH_STR = "month"; | |
113 | static const char *const T_YEAR_STR = "year"; | |
114 | static const char *const T_DECADE_STR = "decade"; | |
aa0a0c7c | 115 | |
9906e724 | 116 | static const char *const B_BYTES_STR = "bytes"; |
117 | static const char *const B_KBYTES_STR = "KB"; | |
118 | static const char *const B_MBYTES_STR = "MB"; | |
119 | static const char *const B_GBYTES_STR = "GB"; | |
120 | ||
4db43fab | 121 | static const char *const list_sep = ", \t\n\r"; |
b0e7d2d5 | 122 | |
7684c4b1 | 123 | static void parse_logformat(logformat ** logformat_definitions); |
124 | static void parse_access_log(customlog ** customlog_definitions); | |
d64bef4c | 125 | static int check_null_access_log(customlog *customlog_definitions); |
126 | ||
7684c4b1 | 127 | static void dump_logformat(StoreEntry * entry, const char *name, logformat * definitions); |
128 | static void dump_access_log(StoreEntry * entry, const char *name, customlog * definitions); | |
129 | static void free_logformat(logformat ** definitions); | |
130 | static void free_access_log(customlog ** definitions); | |
131 | ||
cd748f27 | 132 | static void update_maxobjsize(void); |
f5b8bbc4 | 133 | static void configDoConfigure(void); |
134 | static void parse_refreshpattern(refresh_t **); | |
135 | static int parseTimeUnits(const char *unit); | |
136 | static void parseTimeLine(time_t * tptr, const char *units); | |
59715b38 | 137 | static void parse_ushort(u_short * var); |
f5b8bbc4 | 138 | static void parse_string(char **); |
f5b8bbc4 | 139 | static void default_all(void); |
140 | static void defaults_if_none(void); | |
141 | static int parse_line(char *); | |
142 | static void parseBytesLine(size_t * bptr, const char *units); | |
143 | static size_t parseBytesUnits(const char *unit); | |
f5b8bbc4 | 144 | static void free_all(void); |
94439e4e | 145 | void requirePathnameExists(const char *name, const char *path); |
ed7f5615 | 146 | static OBJH dump_config; |
626096be | 147 | #if USE_HTTP_VIOLATIONS |
6bccf575 | 148 | static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]); |
149 | static void parse_http_header_access(header_mangler header[]); | |
150 | static void free_http_header_access(header_mangler header[]); | |
151 | static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]); | |
152 | static void parse_http_header_replace(header_mangler * header); | |
153 | static void free_http_header_replace(header_mangler * header); | |
9e8b2f1c | 154 | #endif |
6bccf575 | 155 | static void parse_denyinfo(acl_deny_info_list ** var); |
156 | static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var); | |
157 | static void free_denyinfo(acl_deny_info_list ** var); | |
e1a88700 | 158 | |
0b0cfcf2 | 159 | #if USE_WCCPv2 |
b7ac5457 AJ |
160 | static void parse_IpAddress_list(Ip::Address_list **); |
161 | static void dump_IpAddress_list(StoreEntry *, const char *, const Ip::Address_list *); | |
162 | static void free_IpAddress_list(Ip::Address_list **); | |
0b0cfcf2 | 163 | #if CURRENTLY_UNUSED |
b7ac5457 | 164 | static int check_null_IpAddress_list(const Ip::Address_list *); |
3f38a55e | 165 | #endif /* CURRENTLY_UNUSED */ |
e1a88700 | 166 | #endif /* USE_WCCPv2 */ |
167 | ||
3f38a55e | 168 | static void parse_http_port_list(http_port_list **); |
169 | static void dump_http_port_list(StoreEntry *, const char *, const http_port_list *); | |
170 | static void free_http_port_list(http_port_list **); | |
e1a88700 | 171 | |
d193a436 | 172 | #if USE_SSL |
173 | static void parse_https_port_list(https_port_list **); | |
174 | static void dump_https_port_list(StoreEntry *, const char *, const https_port_list *); | |
175 | static void free_https_port_list(https_port_list **); | |
176 | #if 0 | |
177 | static int check_null_https_port_list(const https_port_list *); | |
178 | #endif | |
179 | #endif /* USE_SSL */ | |
e1a88700 | 180 | |
ef1955a5 | 181 | static void parse_b_size_t(size_t * var); |
47f6e231 | 182 | static void parse_b_int64_t(int64_t * var); |
270b86af | 183 | |
cfcb6b30 | 184 | static int parseOneConfigFile(const char *file_name, unsigned int depth); |
185 | ||
a385afc3 | 186 | /* |
187 | * LegacyParser is a parser for legacy code that uses the global | |
188 | * approach. This is static so that it is only exposed to cache_cf. | |
189 | * Other modules needing access to a ConfigParser should have it | |
190 | * provided to them in their parserFOO methods. | |
191 | */ | |
192 | static ConfigParser LegacyParser = ConfigParser(); | |
a9f20260 | 193 | |
0e4e0e7d | 194 | void |
0673c0ba | 195 | self_destruct(void) |
090089c4 | 196 | { |
a9f20260 | 197 | LegacyParser.destruct(); |
6b8e7481 | 198 | } |
199 | ||
cd748f27 | 200 | static void |
201 | update_maxobjsize(void) | |
202 | { | |
203 | int i; | |
47f6e231 | 204 | int64_t ms = -1; |
cd748f27 | 205 | |
206 | for (i = 0; i < Config.cacheSwap.n_configured; i++) { | |
c8f4eac4 | 207 | assert (Config.cacheSwap.swapDirs[i].getRaw()); |
62e76326 | 208 | |
c8f4eac4 | 209 | if (dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())-> |
210 | max_objsize > ms) | |
211 | ms = dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->max_objsize; | |
cd748f27 | 212 | } |
213 | store_maxobjsize = ms; | |
214 | } | |
215 | ||
76b9daa5 | 216 | static void |
217 | SetConfigFilename(char const *file_name, bool is_pipe) | |
218 | { | |
219 | cfg_filename = file_name; | |
220 | ||
221 | char const *token; | |
222 | ||
223 | if (is_pipe) | |
224 | cfg_filename = file_name + 1; | |
225 | else if ((token = strrchr(cfg_filename, '/'))) | |
226 | cfg_filename = token + 1; | |
227 | } | |
228 | ||
130bff33 | 229 | static const char* |
230 | skip_ws(const char* s) | |
231 | { | |
232 | while (xisspace(*s)) | |
233 | ++s; | |
234 | ||
235 | return s; | |
236 | } | |
237 | ||
cfcb6b30 | 238 | static int |
239 | parseManyConfigFiles(char* files, int depth) | |
240 | { | |
241 | int error_count = 0; | |
d7ac36b9 | 242 | char* saveptr = NULL; |
52303a3d | 243 | #if HAVE_GLOB |
592a09dc | 244 | char *path; |
245 | glob_t globbuf; | |
246 | int i; | |
247 | memset(&globbuf, 0, sizeof(globbuf)); | |
248 | for (path = strwordtok(files, &saveptr); path; path = strwordtok(NULL, &saveptr)) { | |
26ac0430 AJ |
249 | if (glob(path, globbuf.gl_pathc ? GLOB_APPEND : 0, NULL, &globbuf) != 0) { |
250 | fatalf("Unable to find configuration file: %s: %s", | |
251 | path, xstrerror()); | |
252 | } | |
253 | } | |
592a09dc | 254 | for (i = 0; i < (int)globbuf.gl_pathc; i++) { |
26ac0430 | 255 | error_count += parseOneConfigFile(globbuf.gl_pathv[i], depth); |
cfcb6b30 | 256 | } |
592a09dc | 257 | globfree(&globbuf); |
52303a3d | 258 | #else |
259 | char* file = strwordtok(files, &saveptr); | |
260 | while (file != NULL) { | |
26ac0430 AJ |
261 | error_count += parseOneConfigFile(file, depth); |
262 | file = strwordtok(NULL, &saveptr); | |
52303a3d | 263 | } |
264 | #endif /* HAVE_GLOB */ | |
cfcb6b30 | 265 | return error_count; |
266 | } | |
267 | ||
d4a3e179 AR |
268 | static void |
269 | ReplaceSubstr(char*& str, int& len, unsigned substrIdx, unsigned substrLen, const char* newSubstr) | |
270 | { | |
271 | assert(str != NULL); | |
272 | assert(newSubstr != NULL); | |
273 | ||
274 | unsigned newSubstrLen = strlen(newSubstr); | |
275 | if (newSubstrLen > substrLen) | |
276 | str = (char*)realloc(str, len - substrLen + newSubstrLen + 1); | |
277 | ||
278 | // move tail part including zero | |
279 | memmove(str + substrIdx + newSubstrLen, str + substrIdx + substrLen, len - substrIdx - substrLen + 1); | |
280 | // copy new substring in place | |
281 | memcpy(str + substrIdx, newSubstr, newSubstrLen); | |
282 | ||
283 | len = strlen(str); | |
284 | } | |
285 | ||
286 | static void | |
287 | SubstituteMacro(char*& line, int& len, const char* macroName, const char* substStr) | |
288 | { | |
289 | assert(line != NULL); | |
290 | assert(macroName != NULL); | |
291 | assert(substStr != NULL); | |
292 | unsigned macroNameLen = strlen(macroName); | |
293 | while (const char* macroPos = strstr(line, macroName)) // we would replace all occurrences | |
294 | ReplaceSubstr(line, len, macroPos - line, macroNameLen, substStr); | |
295 | } | |
296 | ||
297 | static void | |
298 | ProcessMacros(char*& line, int& len) | |
299 | { | |
9de6c973 | 300 | SubstituteMacro(line, len, "${process_name}", TheKidName); |
d4a3e179 AR |
301 | SubstituteMacro(line, len, "${process_number}", xitoa(KidIdentifier)); |
302 | } | |
303 | ||
a7ea9b13 AR |
304 | static void |
305 | trim_trailing_ws(char* str) | |
306 | { | |
307 | assert(str != NULL); | |
308 | unsigned i = strlen(str); | |
309 | while ((i > 0) && xisspace(str[i - 1])) | |
310 | --i; | |
311 | str[i] = '\0'; | |
312 | } | |
313 | ||
314 | static const char* | |
315 | FindStatement(const char* line, const char* statement) | |
316 | { | |
317 | assert(line != NULL); | |
318 | assert(statement != NULL); | |
319 | ||
320 | const char* str = skip_ws(line); | |
321 | unsigned len = strlen(statement); | |
322 | if (strncmp(str, statement, len) == 0) { | |
323 | str += len; | |
324 | if (*str == '\0') | |
325 | return str; | |
326 | else if (xisspace(*str)) | |
327 | return skip_ws(str); | |
328 | } | |
329 | ||
330 | return NULL; | |
331 | } | |
332 | ||
333 | static bool | |
334 | StrToInt(const char* str, long& number) | |
335 | { | |
336 | assert(str != NULL); | |
337 | ||
338 | char* end; | |
339 | number = strtol(str, &end, 0); | |
340 | ||
341 | return (end != str) && (*end == '\0'); // returns true if string contains nothing except number | |
342 | } | |
343 | ||
344 | static bool | |
345 | EvalBoolExpr(const char* expr) | |
346 | { | |
347 | assert(expr != NULL); | |
348 | if (strcmp(expr, "true") == 0) { | |
349 | return true; | |
350 | } else if (strcmp(expr, "false") == 0) { | |
351 | return false; | |
352 | } else if (const char* equation = strchr(expr, '=')) { | |
353 | const char* rvalue = skip_ws(equation + 1); | |
354 | char* lvalue = (char*)xmalloc(equation - expr + 1); | |
355 | xstrncpy(lvalue, expr, equation - expr + 1); | |
356 | trim_trailing_ws(lvalue); | |
357 | ||
358 | long number1; | |
359 | if (!StrToInt(lvalue, number1)) | |
360 | fatalf("String is not a integer number: '%s'\n", lvalue); | |
361 | long number2; | |
362 | if (!StrToInt(rvalue, number2)) | |
363 | fatalf("String is not a integer number: '%s'\n", rvalue); | |
364 | ||
365 | xfree(lvalue); | |
366 | return number1 == number2; | |
367 | } | |
368 | fatalf("Unable to evaluate expression '%s'\n", expr); | |
369 | return false; // this place cannot be reached | |
370 | } | |
371 | ||
cfcb6b30 | 372 | static int |
373 | parseOneConfigFile(const char *file_name, unsigned int depth) | |
2546fcb3 | 374 | { |
270b86af | 375 | FILE *fp = NULL; |
cfcb6b30 | 376 | const char *orig_cfg_filename = cfg_filename; |
377 | const int orig_config_lineno = config_lineno; | |
270b86af | 378 | char *token = NULL; |
81c161d0 | 379 | char *tmp_line = NULL; |
380 | int tmp_line_len = 0; | |
e13ee7ad | 381 | int err_count = 0; |
1741cbad | 382 | int is_pipe = 0; |
cfcb6b30 | 383 | |
384 | debugs(3, 1, "Processing Configuration File: " << file_name << " (depth " << depth << ")"); | |
385 | if (depth > 16) { | |
386 | fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name); | |
387 | return 1; | |
388 | } | |
62e76326 | 389 | |
1741cbad | 390 | if (file_name[0] == '!' || file_name[0] == '|') { |
62e76326 | 391 | fp = popen(file_name + 1, "r"); |
392 | is_pipe = 1; | |
1741cbad | 393 | } else { |
62e76326 | 394 | fp = fopen(file_name, "r"); |
1741cbad | 395 | } |
62e76326 | 396 | |
1741cbad | 397 | if (fp == NULL) |
cfcb6b30 | 398 | fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror()); |
62e76326 | 399 | |
ec4daaa5 | 400 | #ifdef _SQUID_WIN32_ |
62e76326 | 401 | |
c4aefe96 | 402 | setmode(fileno(fp), O_TEXT); |
62e76326 | 403 | |
c4aefe96 | 404 | #endif |
62e76326 | 405 | |
76b9daa5 | 406 | SetConfigFilename(file_name, bool(is_pipe)); |
62e76326 | 407 | |
270b86af | 408 | memset(config_input_line, '\0', BUFSIZ); |
62e76326 | 409 | |
270b86af | 410 | config_lineno = 0; |
62e76326 | 411 | |
a7ea9b13 | 412 | Vector<bool> if_states; |
270b86af | 413 | while (fgets(config_input_line, BUFSIZ, fp)) { |
62e76326 | 414 | config_lineno++; |
415 | ||
416 | if ((token = strchr(config_input_line, '\n'))) | |
417 | *token = '\0'; | |
418 | ||
d866e2ad | 419 | if ((token = strchr(config_input_line, '\r'))) |
420 | *token = '\0'; | |
421 | ||
62e76326 | 422 | if (strncmp(config_input_line, "#line ", 6) == 0) { |
423 | static char new_file_name[1024]; | |
424 | static char *file; | |
425 | static char new_lineno; | |
426 | token = config_input_line + 6; | |
427 | new_lineno = strtol(token, &file, 0) - 1; | |
428 | ||
429 | if (file == token) | |
430 | continue; /* Not a valid #line directive, may be a comment */ | |
431 | ||
e4755e29 | 432 | while (*file && xisspace((unsigned char) *file)) |
62e76326 | 433 | file++; |
434 | ||
435 | if (*file) { | |
436 | if (*file != '"') | |
437 | continue; /* Not a valid #line directive, may be a comment */ | |
438 | ||
439 | xstrncpy(new_file_name, file + 1, sizeof(new_file_name)); | |
440 | ||
441 | if ((token = strchr(new_file_name, '"'))) | |
442 | *token = '\0'; | |
443 | ||
444 | cfg_filename = new_file_name; | |
62e76326 | 445 | } |
446 | ||
447 | config_lineno = new_lineno; | |
448 | } | |
449 | ||
450 | if (config_input_line[0] == '#') | |
451 | continue; | |
452 | ||
453 | if (config_input_line[0] == '\0') | |
454 | continue; | |
455 | ||
130bff33 | 456 | const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line; |
457 | ||
458 | size_t append_len = strlen(append); | |
62e76326 | 459 | |
130bff33 | 460 | tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1); |
81c161d0 | 461 | |
130bff33 | 462 | strcpy(tmp_line + tmp_line_len, append); |
81c161d0 | 463 | |
130bff33 | 464 | tmp_line_len += append_len; |
81c161d0 | 465 | |
466 | if (tmp_line[tmp_line_len-1] == '\\') { | |
bf8fe701 | 467 | debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'"); |
81c161d0 | 468 | tmp_line[--tmp_line_len] = '\0'; |
469 | continue; | |
470 | } | |
471 | ||
a7ea9b13 | 472 | trim_trailing_ws(tmp_line); |
d4a3e179 | 473 | ProcessMacros(tmp_line, tmp_line_len); |
bf8fe701 | 474 | debugs(3, 5, "Processing: '" << tmp_line << "'"); |
62e76326 | 475 | |
a7ea9b13 AR |
476 | if (const char* expr = FindStatement(tmp_line, "if")) { |
477 | if_states.push_back(EvalBoolExpr(expr)); // store last if-statement meaning | |
478 | } else if (FindStatement(tmp_line, "endif")) { | |
479 | if (!if_states.empty()) | |
480 | if_states.pop_back(); // remove last if-statement meaning | |
481 | else | |
482 | fatalf("'endif' without 'if'\n"); | |
483 | } else if (FindStatement(tmp_line, "else")) { | |
484 | if (!if_states.empty()) | |
485 | if_states.back() = !if_states.back(); | |
486 | else | |
487 | fatalf("'else' without 'if'\n"); | |
488 | } else if (if_states.empty() || if_states.back()) { // test last if-statement meaning if present | |
489 | /* Handle includes here */ | |
490 | if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) { | |
491 | err_count += parseManyConfigFiles(tmp_line + 8, depth + 1); | |
492 | } else if (!parse_line(tmp_line)) { | |
493 | debugs(3, 0, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'"); | |
494 | err_count++; | |
495 | } | |
26ac0430 | 496 | } |
62e76326 | 497 | |
498 | safe_free(tmp_line); | |
81c161d0 | 499 | tmp_line_len = 0; |
500 | ||
270b86af | 501 | } |
a7ea9b13 AR |
502 | if (!if_states.empty()) |
503 | fatalf("if-statement without 'endif'\n"); | |
62e76326 | 504 | |
1741cbad | 505 | if (is_pipe) { |
62e76326 | 506 | int ret = pclose(fp); |
507 | ||
508 | if (ret != 0) | |
509 | fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret); | |
1741cbad | 510 | } else { |
62e76326 | 511 | fclose(fp); |
1741cbad | 512 | } |
62e76326 | 513 | |
cfcb6b30 | 514 | cfg_filename = orig_cfg_filename; |
515 | config_lineno = orig_config_lineno; | |
516 | ||
517 | return err_count; | |
518 | } | |
519 | ||
520 | int | |
dd9b1081 | 521 | parseConfigFile(const char *file_name) |
cfcb6b30 | 522 | { |
523 | int err_count = 0; | |
dd9b1081 | 524 | CacheManager *manager=CacheManager::GetInstance(); |
cfcb6b30 | 525 | |
5817ee13 AJ |
526 | debugs(5, 4, HERE); |
527 | ||
cfcb6b30 | 528 | configFreeMemory(); |
529 | ||
5491c11e | 530 | ACLMethodData::ThePurgeCount = 0; |
cfcb6b30 | 531 | default_all(); |
532 | ||
533 | err_count = parseOneConfigFile(file_name, 0); | |
534 | ||
f0b19334 | 535 | defaults_if_none(); |
f9ad0106 | 536 | |
9c46ca97 | 537 | /* |
538 | * We must call configDoConfigure() before leave_suid() because | |
539 | * configDoConfigure() is where we turn username strings into | |
540 | * uid values. | |
541 | */ | |
542 | configDoConfigure(); | |
543 | ||
f9ad0106 | 544 | if (!Config.chroot_dir) { |
545 | leave_suid(); | |
c642c141 | 546 | setUmask(Config.umask); |
62493678 | 547 | _db_init(Debug::cache_log, Debug::debugOptions); |
f9ad0106 | 548 | enter_suid(); |
549 | } | |
550 | ||
478c4f2f | 551 | if (opt_send_signal == -1) { |
dd9b1081 | 552 | manager->registerAction("config", |
26ac0430 AJ |
553 | "Current Squid Configuration", |
554 | dump_config, | |
555 | 1, 1); | |
478c4f2f | 556 | } |
557 | ||
e13ee7ad | 558 | return err_count; |
f0b19334 | 559 | } |
270b86af | 560 | |
cfcb6b30 | 561 | |
f0b19334 | 562 | static void |
563 | configDoConfigure(void) | |
564 | { | |
f0b19334 | 565 | memset(&Config2, '\0', sizeof(SquidConfig2)); |
7021844c | 566 | /* init memory as early as possible */ |
567 | memConfigure(); | |
270b86af | 568 | /* Sanity checks */ |
62e76326 | 569 | |
7895fa18 AJ |
570 | if (Config.cacheSwap.swapDirs == NULL) { |
571 | /* Memory-only cache probably in effect. */ | |
572 | /* turn off the cache rebuild delays... */ | |
573 | StoreController::store_dirs_rebuilding = 0; | |
574 | } | |
575 | ||
47df1aa7 AJ |
576 | if (Debug::rotateNumber < 0) { |
577 | Debug::rotateNumber = Config.Log.rotateNumber; | |
578 | } | |
579 | ||
5aecb102 | 580 | #if SIZEOF_OFF_T <= 4 |
581 | if (Config.Store.maxObjectSize > 0x7FFF0000) { | |
26ac0430 AJ |
582 | debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB"); |
583 | Config.Store.maxObjectSize = 0x7FFF0000; | |
5aecb102 | 584 | } |
585 | #endif | |
c8f4eac4 | 586 | if (0 == Store::Root().maxSize()) |
62e76326 | 587 | /* people might want a zero-sized cache on purpose */ |
588 | (void) 0; | |
c8f4eac4 | 589 | else if (Store::Root().maxSize() < (Config.memMaxSize >> 10)) |
590 | /* This is bogus. folk with NULL caches will want this */ | |
bf8fe701 | 591 | debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!"); |
62e76326 | 592 | |
84f42bac | 593 | if (Config.Announce.period > 0) { |
62e76326 | 594 | Config.onoff.announce = 1; |
84f42bac | 595 | } else if (Config.Announce.period < 1) { |
62e76326 | 596 | Config.Announce.period = 86400 * 365; /* one year */ |
597 | Config.onoff.announce = 0; | |
270b86af | 598 | } |
62e76326 | 599 | |
d3caee79 | 600 | if (Config.onoff.httpd_suppress_version_string) |
601 | visible_appname_string = (char *)appname_string; | |
602 | else | |
7dbca7a4 | 603 | visible_appname_string = (char const *)APP_FULLNAME; |
d3caee79 | 604 | |
6b53c392 | 605 | #if USE_DNSSERVERS |
d3caee79 | 606 | |
48d54e4d | 607 | if (Config.dnsChildren.n_max < 1) |
62e76326 | 608 | fatal("No dnsservers allocated"); |
609 | ||
efd900cb | 610 | #endif |
62e76326 | 611 | |
270b86af | 612 | if (Config.Program.redirect) { |
48d54e4d AJ |
613 | if (Config.redirectChildren.n_max < 1) { |
614 | Config.redirectChildren.n_max = 0; | |
62e76326 | 615 | wordlistDestroy(&Config.Program.redirect); |
616 | } | |
fea2e6e0 | 617 | } |
62e76326 | 618 | |
f1dc9b30 | 619 | if (Config.appendDomain) |
62e76326 | 620 | if (*Config.appendDomain != '.') |
621 | fatal("append_domain must begin with a '.'"); | |
622 | ||
270b86af | 623 | if (Config.errHtmlText == NULL) |
62e76326 | 624 | Config.errHtmlText = xstrdup(null_string); |
625 | ||
270b86af | 626 | storeConfigure(); |
62e76326 | 627 | |
52f772de | 628 | snprintf(ThisCache, sizeof(ThisCache), "%s (%s)", |
62e76326 | 629 | uniqueHostname(), |
d3caee79 | 630 | visible_appname_string); |
fbdba7c4 | 631 | |
38a6c74e | 632 | /* |
633 | * the extra space is for loop detection in client_side.c -- we search | |
634 | * for substrings in the Via header. | |
635 | */ | |
52f772de | 636 | snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)", |
62e76326 | 637 | uniqueHostname(), |
d3caee79 | 638 | visible_appname_string); |
62e76326 | 639 | |
b2b40d8c AJ |
640 | /* Use visible_hostname as default surrogate_id */ |
641 | if (!Config.Accel.surrogate_id) { | |
642 | const char *t = getMyHostname(); | |
643 | Config.Accel.surrogate_id = xstrdup( (t?t:"unset-id") ); | |
644 | } | |
645 | ||
270b86af | 646 | if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) |
62e76326 | 647 | Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; |
648 | ||
270b86af | 649 | if (Config.appendDomain) |
62e76326 | 650 | Config.appendDomainLen = strlen(Config.appendDomain); |
270b86af | 651 | else |
62e76326 | 652 | Config.appendDomainLen = 0; |
653 | ||
22c653cd | 654 | if (Config.retry.maxtries > 10) |
62e76326 | 655 | fatal("maximum_single_addr_tries cannot be larger than 10"); |
656 | ||
22c653cd | 657 | if (Config.retry.maxtries < 1) { |
bf8fe701 | 658 | debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1"); |
62e76326 | 659 | Config.retry.maxtries = 1; |
5210854d | 660 | } |
62e76326 | 661 | |
f0b19334 | 662 | requirePathnameExists("MIME Config Table", Config.mimeTablePathname); |
6b53c392 | 663 | #if USE_DNSSERVERS |
62e76326 | 664 | |
f0b19334 | 665 | requirePathnameExists("cache_dns_program", Config.Program.dnsserver); |
efd900cb | 666 | #endif |
a3d0a19d | 667 | #if USE_UNLINKD |
62e76326 | 668 | |
f0b19334 | 669 | requirePathnameExists("unlinkd_program", Config.Program.unlinkd); |
a3d0a19d | 670 | #endif |
82b7abe3 | 671 | requirePathnameExists("logfile_daemon", Log::TheConfig.logfile_daemon); |
f0b19334 | 672 | if (Config.Program.redirect) |
62e76326 | 673 | requirePathnameExists("redirect_program", Config.Program.redirect->key); |
674 | ||
f0b19334 | 675 | requirePathnameExists("Icon Directory", Config.icons.directory); |
62e76326 | 676 | |
26ac0430 | 677 | if (Config.errorDirectory) |
43000484 | 678 | requirePathnameExists("Error Directory", Config.errorDirectory); |
62e76326 | 679 | |
626096be | 680 | #if USE_HTTP_VIOLATIONS |
62e76326 | 681 | |
9f60cfdf | 682 | { |
62e76326 | 683 | const refresh_t *R; |
684 | ||
26ac0430 | 685 | for (R = Config.Refresh; R; R = R->next) { |
62e76326 | 686 | if (!R->flags.override_expire) |
687 | continue; | |
688 | ||
bf8fe701 | 689 | debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP"); |
62e76326 | 690 | |
691 | break; | |
692 | } | |
693 | ||
26ac0430 | 694 | for (R = Config.Refresh; R; R = R->next) { |
62e76326 | 695 | if (!R->flags.override_lastmod) |
696 | continue; | |
697 | ||
bf8fe701 | 698 | debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP"); |
62e76326 | 699 | |
700 | break; | |
701 | } | |
702 | ||
26ac0430 | 703 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 704 | if (!R->flags.reload_into_ims) |
705 | continue; | |
706 | ||
bf8fe701 | 707 | debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 708 | |
709 | break; | |
710 | } | |
711 | ||
26ac0430 | 712 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 713 | if (!R->flags.ignore_reload) |
714 | continue; | |
715 | ||
bf8fe701 | 716 | debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 717 | |
718 | break; | |
719 | } | |
720 | ||
26ac0430 | 721 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 722 | if (!R->flags.ignore_no_cache) |
723 | continue; | |
724 | ||
bf8fe701 | 725 | debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 726 | |
727 | break; | |
728 | } | |
729 | ||
26ac0430 | 730 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 731 | if (!R->flags.ignore_no_store) |
732 | continue; | |
733 | ||
bf8fe701 | 734 | debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 735 | |
736 | break; | |
737 | } | |
738 | ||
4ca08219 | 739 | for (R = Config.Refresh; R; R = R->next) { |
04f7fd38 AJ |
740 | if (!R->flags.ignore_must_revalidate) |
741 | continue; | |
742 | debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP"); | |
743 | break; | |
4ca08219 AJ |
744 | } |
745 | ||
26ac0430 | 746 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 747 | if (!R->flags.ignore_private) |
748 | continue; | |
749 | ||
bf8fe701 | 750 | debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 751 | |
752 | break; | |
753 | } | |
754 | ||
26ac0430 | 755 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 756 | if (!R->flags.ignore_auth) |
757 | continue; | |
758 | ||
bf8fe701 | 759 | debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 760 | |
761 | break; | |
762 | } | |
763 | ||
9f60cfdf | 764 | } |
c2f5c744 | 765 | #endif |
626096be | 766 | #if !USE_HTTP_VIOLATIONS |
c2f5c744 | 767 | Config.onoff.via = 1; |
768 | #else | |
62e76326 | 769 | |
c2f5c744 | 770 | if (!Config.onoff.via) |
bf8fe701 | 771 | debugs(22, 1, "WARNING: HTTP requires the use of Via"); |
62e76326 | 772 | |
9f60cfdf | 773 | #endif |
62e76326 | 774 | |
5491c11e AR |
775 | // we enable runtime PURGE checks if there is at least one PURGE method ACL |
776 | // TODO: replace with a dedicated "purge" ACL option? | |
3d9019c7 | 777 | Config2.onoff.enable_purge = (ACLMethodData::ThePurgeCount > 0); |
62e76326 | 778 | |
4f56514c | 779 | Config2.onoff.mangle_request_headers = httpReqHdrManglersConfigured(); |
5967c0bf | 780 | |
8749fa47 | 781 | if (geteuid() == 0) { |
62e76326 | 782 | if (NULL != Config.effectiveUser) { |
783 | ||
784 | struct passwd *pwd = getpwnam(Config.effectiveUser); | |
785 | ||
5ad8d199 | 786 | if (NULL == pwd) { |
62e76326 | 787 | /* |
788 | * Andres Kroonmaa <andre@online.ee>: | |
789 | * Some getpwnam() implementations (Solaris?) require | |
790 | * an available FD < 256 for opening a FILE* to the | |
791 | * passwd file. | |
792 | * DW: | |
793 | * This should be safe at startup, but might still fail | |
794 | * during reconfigure. | |
795 | */ | |
796 | fatalf("getpwnam failed to find userid for effective user '%s'", | |
797 | Config.effectiveUser); | |
5ad8d199 | 798 | return; |
799 | } | |
62e76326 | 800 | |
801 | Config2.effectiveUserID = pwd->pw_uid; | |
802 | ||
803 | Config2.effectiveGroupID = pwd->pw_gid; | |
08ac5ea7 | 804 | |
cff61cb8 | 805 | #if HAVE_PUTENV |
806 | ||
807 | if (pwd->pw_dir && *pwd->pw_dir) { | |
808 | int len; | |
809 | char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1); | |
810 | snprintf(env_str, len, "HOME=%s", pwd->pw_dir); | |
811 | putenv(env_str); | |
812 | } | |
813 | ||
814 | #endif | |
815 | ||
62e76326 | 816 | } |
8749fa47 | 817 | } else { |
62e76326 | 818 | Config2.effectiveUserID = geteuid(); |
819 | Config2.effectiveGroupID = getegid(); | |
d20b1cd0 | 820 | } |
62e76326 | 821 | |
d20b1cd0 | 822 | if (NULL != Config.effectiveGroup) { |
62e76326 | 823 | |
824 | struct group *grp = getgrnam(Config.effectiveGroup); | |
825 | ||
5ad8d199 | 826 | if (NULL == grp) { |
62e76326 | 827 | fatalf("getgrnam failed to find groupid for effective group '%s'", |
828 | Config.effectiveGroup); | |
5ad8d199 | 829 | return; |
830 | } | |
62e76326 | 831 | |
832 | Config2.effectiveGroupID = grp->gr_gid; | |
d20b1cd0 | 833 | } |
62e76326 | 834 | |
985c86bc | 835 | HttpRequestMethod::Configure(Config); |
a7ad6e4e | 836 | #if USE_SSL |
62e76326 | 837 | |
bf8fe701 | 838 | debugs(3, 1, "Initializing https proxy context"); |
f9ad0106 | 839 | |
a82a4fe4 | 840 | 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); |
f9ad0106 | 841 | |
842 | { | |
843 | ||
844 | peer *p; | |
845 | ||
846 | for (p = Config.peers; p != NULL; p = p->next) { | |
847 | if (p->use_ssl) { | |
bf8fe701 | 848 | debugs(3, 1, "Initializing cache_peer " << p->name << " SSL context"); |
a82a4fe4 | 849 | p->sslContext = sslCreateClientContext(p->sslcert, p->sslkey, p->sslversion, p->sslcipher, p->ssloptions, p->sslflags, p->sslcafile, p->sslcapath, p->sslcrlfile); |
f9ad0106 | 850 | } |
851 | } | |
852 | } | |
853 | ||
154dc884 | 854 | { |
855 | ||
856 | http_port_list *s; | |
857 | ||
858 | for (s = Config.Sockaddr.http; s != NULL; s = (http_port_list *) s->next) { | |
859 | if (!s->cert && !s->key) | |
860 | continue; | |
861 | ||
862 | debugs(3, 1, "Initializing http_port " << s->http.s << " SSL context"); | |
863 | ||
864 | s->sslContext = sslCreateServerContext(s->cert, s->key, s->version, s->cipher, s->options, s->sslflags, s->clientca, s->cafile, s->capath, s->crlfile, s->dhfile, s->sslcontext); | |
865 | } | |
866 | } | |
867 | ||
f9ad0106 | 868 | { |
869 | ||
870 | https_port_list *s; | |
871 | ||
b844522c | 872 | for (s = Config.Sockaddr.https; s != NULL; s = (https_port_list *) s->http.next) { |
cc192b50 | 873 | debugs(3, 1, "Initializing https_port " << s->http.s << " SSL context"); |
bf8fe701 | 874 | |
a82a4fe4 | 875 | s->sslContext = sslCreateServerContext(s->cert, s->key, s->version, s->cipher, s->options, s->sslflags, s->clientca, s->cafile, s->capath, s->crlfile, s->dhfile, s->sslcontext); |
f9ad0106 | 876 | } |
877 | } | |
878 | ||
a7ad6e4e | 879 | #endif |
090089c4 | 880 | } |
881 | ||
270b86af | 882 | /* Parse a time specification from the config file. Store the |
f1dc9b30 | 883 | * result in 'tptr', after converting it to 'units' */ |
8203a132 | 884 | static void |
a47b9029 | 885 | parseTimeLine(time_t * tptr, const char *units) |
090089c4 | 886 | { |
887 | char *token; | |
270b86af | 888 | double d; |
f1dc9b30 | 889 | time_t m; |
890 | time_t u; | |
62e76326 | 891 | |
270b86af | 892 | if ((u = parseTimeUnits(units)) == 0) |
62e76326 | 893 | self_destruct(); |
894 | ||
270b86af | 895 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 896 | self_destruct(); |
897 | ||
5c20d6fa | 898 | d = xatof(token); |
62e76326 | 899 | |
270b86af | 900 | m = u; /* default to 'units' if none specified */ |
62e76326 | 901 | |
10738561 | 902 | if (0 == d) |
62e76326 | 903 | (void) 0; |
10738561 | 904 | else if ((token = strtok(NULL, w_space)) == NULL) |
26ac0430 AJ |
905 | debugs(3, 0, "WARNING: No units on '" << |
906 | config_input_line << "', assuming " << | |
907 | d << " " << units ); | |
9e975e4e | 908 | else if ((m = parseTimeUnits(token)) == 0) |
62e76326 | 909 | self_destruct(); |
910 | ||
e6ccf245 | 911 | *tptr = static_cast<time_t> (m * d / u); |
090089c4 | 912 | } |
913 | ||
270b86af | 914 | static int |
915 | parseTimeUnits(const char *unit) | |
916 | { | |
917 | if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR))) | |
62e76326 | 918 | return 1; |
919 | ||
270b86af | 920 | if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR))) |
62e76326 | 921 | return 60; |
922 | ||
270b86af | 923 | if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR))) |
62e76326 | 924 | return 3600; |
925 | ||
270b86af | 926 | if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR))) |
62e76326 | 927 | return 86400; |
928 | ||
270b86af | 929 | if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR))) |
62e76326 | 930 | return 86400 * 7; |
931 | ||
270b86af | 932 | if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR))) |
62e76326 | 933 | return 86400 * 14; |
934 | ||
270b86af | 935 | if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR))) |
62e76326 | 936 | return 86400 * 30; |
937 | ||
270b86af | 938 | if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR))) |
62e76326 | 939 | return static_cast<int>(86400 * 365.2522); |
940 | ||
270b86af | 941 | if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR))) |
62e76326 | 942 | return static_cast<int>(86400 * 365.2522 * 10); |
943 | ||
bf8fe701 | 944 | debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit << "'"); |
62e76326 | 945 | |
270b86af | 946 | return 0; |
947 | } | |
948 | ||
47f6e231 | 949 | static void |
950 | parseBytesLine64(int64_t * bptr, const char *units) | |
951 | { | |
952 | char *token; | |
953 | double d; | |
954 | int64_t m; | |
955 | int64_t u; | |
956 | ||
9eeb8e4b | 957 | if ((u = parseBytesUnits(units)) == 0) { |
47f6e231 | 958 | self_destruct(); |
9eeb8e4b | 959 | return; |
960 | } | |
47f6e231 | 961 | |
9eeb8e4b | 962 | if ((token = strtok(NULL, w_space)) == NULL) { |
47f6e231 | 963 | self_destruct(); |
9eeb8e4b | 964 | return; |
965 | } | |
47f6e231 | 966 | |
967 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { | |
bc41416d | 968 | *bptr = -1; |
47f6e231 | 969 | return; |
970 | } | |
971 | ||
972 | d = xatof(token); | |
973 | ||
974 | m = u; /* default to 'units' if none specified */ | |
975 | ||
976 | if (0.0 == d) | |
977 | (void) 0; | |
978 | else if ((token = strtok(NULL, w_space)) == NULL) | |
26ac0430 AJ |
979 | debugs(3, 0, "WARNING: No units on '" << |
980 | config_input_line << "', assuming " << | |
981 | d << " " << units ); | |
9eeb8e4b | 982 | else if ((m = parseBytesUnits(token)) == 0) { |
47f6e231 | 983 | self_destruct(); |
9eeb8e4b | 984 | return; |
985 | } | |
47f6e231 | 986 | |
987 | *bptr = static_cast<int64_t>(m * d / u); | |
988 | ||
989 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
990 | self_destruct(); | |
991 | } | |
992 | ||
993 | ||
9906e724 | 994 | static void |
9e975e4e | 995 | parseBytesLine(size_t * bptr, const char *units) |
9906e724 | 996 | { |
997 | char *token; | |
998 | double d; | |
47f6e231 | 999 | int m; |
1000 | int u; | |
62e76326 | 1001 | |
9eeb8e4b | 1002 | if ((u = parseBytesUnits(units)) == 0) { |
62e76326 | 1003 | self_destruct(); |
9eeb8e4b | 1004 | return; |
1005 | } | |
62e76326 | 1006 | |
9eeb8e4b | 1007 | if ((token = strtok(NULL, w_space)) == NULL) { |
62e76326 | 1008 | self_destruct(); |
9eeb8e4b | 1009 | return; |
1010 | } | |
62e76326 | 1011 | |
f8ecd7d7 | 1012 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { |
b2d729e6 | 1013 | *bptr = static_cast<size_t>(-1); |
ef1955a5 | 1014 | return; |
1015 | } | |
1016 | ||
5c20d6fa | 1017 | d = xatof(token); |
62e76326 | 1018 | |
9906e724 | 1019 | m = u; /* default to 'units' if none specified */ |
62e76326 | 1020 | |
343f47a3 | 1021 | if (0.0 == d) |
62e76326 | 1022 | (void) 0; |
4860dc1b | 1023 | else if ((token = strtok(NULL, w_space)) == NULL) |
26ac0430 AJ |
1024 | debugs(3, 0, "WARNING: No units on '" << |
1025 | config_input_line << "', assuming " << | |
1026 | d << " " << units ); | |
9eeb8e4b | 1027 | else if ((m = parseBytesUnits(token)) == 0) { |
62e76326 | 1028 | self_destruct(); |
9eeb8e4b | 1029 | return; |
1030 | } | |
62e76326 | 1031 | |
e6ccf245 | 1032 | *bptr = static_cast<size_t>(m * d / u); |
347ae7c4 | 1033 | |
a69d485c | 1034 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) |
347ae7c4 | 1035 | self_destruct(); |
9906e724 | 1036 | } |
1037 | ||
1038 | static size_t | |
1039 | parseBytesUnits(const char *unit) | |
1040 | { | |
1041 | if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) | |
62e76326 | 1042 | return 1; |
1043 | ||
9906e724 | 1044 | if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) |
62e76326 | 1045 | return 1 << 10; |
1046 | ||
9906e724 | 1047 | if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) |
62e76326 | 1048 | return 1 << 20; |
1049 | ||
9906e724 | 1050 | if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) |
62e76326 | 1051 | return 1 << 30; |
1052 | ||
fa37412f | 1053 | debugs(3, DBG_CRITICAL, "WARNING: Unknown bytes unit '" << unit << "'"); |
62e76326 | 1054 | |
9906e724 | 1055 | return 0; |
1056 | } | |
1057 | ||
270b86af | 1058 | /***************************************************************************** |
1059 | * Max | |
1060 | *****************************************************************************/ | |
1061 | ||
8203a132 | 1062 | static void |
97427e90 | 1063 | dump_acl(StoreEntry * entry, const char *name, ACL * ae) |
090089c4 | 1064 | { |
56b63fa1 | 1065 | wordlist *w; |
1066 | wordlist *v; | |
62e76326 | 1067 | |
9ef28b60 | 1068 | while (ae != NULL) { |
bf8fe701 | 1069 | debugs(3, 3, "dump_acl: " << name << " " << ae->name); |
62e76326 | 1070 | storeAppendPrintf(entry, "%s %s %s ", |
1071 | name, | |
1072 | ae->name, | |
1073 | ae->typeString()); | |
6bf4f823 | 1074 | v = w = ae->dump(); |
62e76326 | 1075 | |
1076 | while (v != NULL) { | |
bf8fe701 | 1077 | debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key); |
62e76326 | 1078 | storeAppendPrintf(entry, "%s ", v->key); |
1079 | v = v->next; | |
1080 | } | |
1081 | ||
1082 | storeAppendPrintf(entry, "\n"); | |
1083 | wordlistDestroy(&w); | |
1084 | ae = ae->next; | |
56b63fa1 | 1085 | } |
090089c4 | 1086 | } |
1087 | ||
8203a132 | 1088 | static void |
97427e90 | 1089 | parse_acl(ACL ** ae) |
090089c4 | 1090 | { |
a9f20260 | 1091 | ACL::ParseAclLine(LegacyParser, ae); |
f1dc9b30 | 1092 | } |
1093 | ||
1094 | static void | |
97427e90 | 1095 | free_acl(ACL ** ae) |
f1dc9b30 | 1096 | { |
9ef28b60 | 1097 | aclDestroyAcls(ae); |
090089c4 | 1098 | } |
1099 | ||
8203a132 | 1100 | static void |
76cd39d7 | 1101 | dump_acl_list(StoreEntry * entry, ACLList * head) |
30a4f2a8 | 1102 | { |
76cd39d7 | 1103 | ACLList *l; |
62e76326 | 1104 | |
d6827718 | 1105 | for (l = head; l; l = l->next) { |
62e76326 | 1106 | storeAppendPrintf(entry, " %s%s", |
1107 | l->op ? null_string : "!", | |
1108 | l->_acl->name); | |
d6827718 | 1109 | } |
1110 | } | |
1111 | ||
b67e2c8c | 1112 | void |
d6827718 | 1113 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
1114 | { | |
1115 | acl_access *l; | |
62e76326 | 1116 | |
d6827718 | 1117 | for (l = head; l; l = l->next) { |
62e76326 | 1118 | storeAppendPrintf(entry, "%s %s", |
1119 | name, | |
1120 | l->allow ? "Allow" : "Deny"); | |
1121 | dump_acl_list(entry, l->aclList); | |
1122 | storeAppendPrintf(entry, "\n"); | |
56b63fa1 | 1123 | } |
30a4f2a8 | 1124 | } |
090089c4 | 1125 | |
8203a132 | 1126 | static void |
16300b58 | 1127 | parse_acl_access(acl_access ** head) |
090089c4 | 1128 | { |
a9f20260 | 1129 | aclParseAccessLine(LegacyParser, head); |
090089c4 | 1130 | } |
1131 | ||
0153d498 | 1132 | static void |
16300b58 | 1133 | free_acl_access(acl_access ** head) |
0153d498 | 1134 | { |
a47b9029 | 1135 | aclDestroyAccessList(head); |
0153d498 | 1136 | } |
1137 | ||
8203a132 | 1138 | static void |
b7ac5457 | 1139 | dump_address(StoreEntry * entry, const char *name, Ip::Address &addr) |
270b86af | 1140 | { |
cc192b50 | 1141 | char buf[MAX_IPSTRLEN]; |
1142 | storeAppendPrintf(entry, "%s %s\n", name, addr.NtoA(buf,MAX_IPSTRLEN) ); | |
270b86af | 1143 | } |
1144 | ||
1145 | static void | |
b7ac5457 | 1146 | parse_address(Ip::Address *addr) |
090089c4 | 1147 | { |
270b86af | 1148 | char *token = strtok(NULL, w_space); |
1149 | ||
9eeb8e4b | 1150 | if (!token) { |
62e76326 | 1151 | self_destruct(); |
9eeb8e4b | 1152 | return; |
1153 | } | |
62e76326 | 1154 | |
26ac0430 | 1155 | if (!strcmp(token,"any_addr")) { |
cc192b50 | 1156 | addr->SetAnyAddr(); |
26ac0430 AJ |
1157 | (void) 0; |
1158 | } else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) ) { | |
cc192b50 | 1159 | addr->SetNoAddr(); |
26ac0430 AJ |
1160 | (void) 0; |
1161 | } else | |
cc192b50 | 1162 | *addr = token; |
090089c4 | 1163 | } |
1164 | ||
0153d498 | 1165 | static void |
b7ac5457 | 1166 | free_address(Ip::Address *addr) |
0153d498 | 1167 | { |
cc192b50 | 1168 | addr->SetEmpty(); |
0153d498 | 1169 | } |
1170 | ||
d6827718 | 1171 | CBDATA_TYPE(acl_address); |
1172 | ||
1173 | static void | |
1174 | dump_acl_address(StoreEntry * entry, const char *name, acl_address * head) | |
1175 | { | |
cc192b50 | 1176 | char buf[MAX_IPSTRLEN]; |
d6827718 | 1177 | acl_address *l; |
62e76326 | 1178 | |
d6827718 | 1179 | for (l = head; l; l = l->next) { |
cc192b50 | 1180 | if (!l->addr.IsAnyAddr()) |
1181 | storeAppendPrintf(entry, "%s %s", name, l->addr.NtoA(buf,MAX_IPSTRLEN)); | |
62e76326 | 1182 | else |
1183 | storeAppendPrintf(entry, "%s autoselect", name); | |
1184 | ||
1185 | dump_acl_list(entry, l->aclList); | |
1186 | ||
1187 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1188 | } |
1189 | } | |
1190 | ||
1191 | static void | |
1192 | freed_acl_address(void *data) | |
1193 | { | |
e6ccf245 | 1194 | acl_address *l = static_cast<acl_address *>(data); |
29b8d8d6 | 1195 | aclDestroyAclList(&l->aclList); |
d6827718 | 1196 | } |
1197 | ||
1198 | static void | |
1199 | parse_acl_address(acl_address ** head) | |
1200 | { | |
1201 | acl_address *l; | |
1202 | acl_address **tail = head; /* sane name below */ | |
1203 | CBDATA_INIT_TYPE_FREECB(acl_address, freed_acl_address); | |
1204 | l = cbdataAlloc(acl_address); | |
1205 | parse_address(&l->addr); | |
a9f20260 | 1206 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1207 | |
d6827718 | 1208 | while (*tail) |
62e76326 | 1209 | tail = &(*tail)->next; |
1210 | ||
d6827718 | 1211 | *tail = l; |
1212 | } | |
1213 | ||
1214 | static void | |
1215 | free_acl_address(acl_address ** head) | |
1216 | { | |
1217 | while (*head) { | |
62e76326 | 1218 | acl_address *l = *head; |
1219 | *head = l->next; | |
1220 | cbdataFree(l); | |
d6827718 | 1221 | } |
1222 | } | |
1223 | ||
1224 | CBDATA_TYPE(acl_tos); | |
1225 | ||
1226 | static void | |
1227 | dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head) | |
1228 | { | |
1229 | acl_tos *l; | |
62e76326 | 1230 | |
d6827718 | 1231 | for (l = head; l; l = l->next) { |
62e76326 | 1232 | if (l->tos > 0) |
1233 | storeAppendPrintf(entry, "%s 0x%02X", name, l->tos); | |
1234 | else | |
1235 | storeAppendPrintf(entry, "%s none", name); | |
1236 | ||
1237 | dump_acl_list(entry, l->aclList); | |
1238 | ||
1239 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1240 | } |
1241 | } | |
1242 | ||
1243 | static void | |
1244 | freed_acl_tos(void *data) | |
1245 | { | |
e6ccf245 | 1246 | acl_tos *l = static_cast<acl_tos *>(data); |
29b8d8d6 | 1247 | aclDestroyAclList(&l->aclList); |
d6827718 | 1248 | } |
1249 | ||
1250 | static void | |
1251 | parse_acl_tos(acl_tos ** head) | |
1252 | { | |
1253 | acl_tos *l; | |
1254 | acl_tos **tail = head; /* sane name below */ | |
1255 | int tos; | |
1256 | char junk; | |
1257 | char *token = strtok(NULL, w_space); | |
62e76326 | 1258 | |
9eeb8e4b | 1259 | if (!token) { |
62e76326 | 1260 | self_destruct(); |
9eeb8e4b | 1261 | return; |
1262 | } | |
62e76326 | 1263 | |
9eeb8e4b | 1264 | if (sscanf(token, "0x%x%c", &tos, &junk) != 1) { |
62e76326 | 1265 | self_destruct(); |
9eeb8e4b | 1266 | return; |
1267 | } | |
62e76326 | 1268 | |
9eeb8e4b | 1269 | if (tos < 0 || tos > 255) { |
62e76326 | 1270 | self_destruct(); |
9eeb8e4b | 1271 | return; |
1272 | } | |
62e76326 | 1273 | |
d6827718 | 1274 | CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos); |
62e76326 | 1275 | |
d6827718 | 1276 | l = cbdataAlloc(acl_tos); |
62e76326 | 1277 | |
d6827718 | 1278 | l->tos = tos; |
62e76326 | 1279 | |
a9f20260 | 1280 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1281 | |
d6827718 | 1282 | while (*tail) |
62e76326 | 1283 | tail = &(*tail)->next; |
1284 | ||
d6827718 | 1285 | *tail = l; |
1286 | } | |
1287 | ||
1288 | static void | |
1289 | free_acl_tos(acl_tos ** head) | |
1290 | { | |
1291 | while (*head) { | |
62e76326 | 1292 | acl_tos *l = *head; |
1293 | *head = l->next; | |
1294 | l->next = NULL; | |
1295 | cbdataFree(l); | |
d6827718 | 1296 | } |
1297 | } | |
1298 | ||
ef1955a5 | 1299 | CBDATA_TYPE(acl_size_t); |
1300 | ||
1301 | static void | |
1302 | dump_acl_b_size_t(StoreEntry * entry, const char *name, acl_size_t * head) | |
1303 | { | |
1304 | acl_size_t *l; | |
1305 | ||
1306 | for (l = head; l; l = l->next) { | |
ed013b6c | 1307 | if (l->size != -1) |
ef1955a5 | 1308 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR); |
1309 | else | |
1310 | storeAppendPrintf(entry, "%s none", name); | |
1311 | ||
1312 | dump_acl_list(entry, l->aclList); | |
1313 | ||
1314 | storeAppendPrintf(entry, "\n"); | |
1315 | } | |
1316 | } | |
1317 | ||
1318 | static void | |
1319 | freed_acl_b_size_t(void *data) | |
1320 | { | |
1321 | acl_size_t *l = static_cast<acl_size_t *>(data); | |
1322 | aclDestroyAclList(&l->aclList); | |
1323 | } | |
1324 | ||
1325 | static void | |
1326 | parse_acl_b_size_t(acl_size_t ** head) | |
1327 | { | |
1328 | acl_size_t *l; | |
1329 | acl_size_t **tail = head; /* sane name below */ | |
1330 | ||
1331 | CBDATA_INIT_TYPE_FREECB(acl_size_t, freed_acl_b_size_t); | |
1332 | ||
1333 | l = cbdataAlloc(acl_size_t); | |
1334 | ||
47f6e231 | 1335 | parse_b_int64_t(&l->size); |
ef1955a5 | 1336 | |
a9f20260 | 1337 | aclParseAclList(LegacyParser, &l->aclList); |
ef1955a5 | 1338 | |
1339 | while (*tail) | |
1340 | tail = &(*tail)->next; | |
1341 | ||
1342 | *tail = l; | |
1343 | } | |
1344 | ||
1345 | static void | |
1346 | free_acl_b_size_t(acl_size_t ** head) | |
1347 | { | |
1348 | while (*head) { | |
1349 | acl_size_t *l = *head; | |
1350 | *head = l->next; | |
1351 | l->next = NULL; | |
1352 | cbdataFree(l); | |
1353 | } | |
1354 | } | |
1355 | ||
59715b38 | 1356 | #if DELAY_POOLS |
1357 | ||
b67e2c8c | 1358 | #include "DelayPools.h" |
1359 | #include "DelayConfig.h" | |
59715b38 | 1360 | /* do nothing - free_delay_pool_count is the magic free function. |
1361 | * this is why delay_pool_count isn't just marked TYPE: ushort | |
1362 | */ | |
1363 | #define free_delay_pool_class(X) | |
1364 | #define free_delay_pool_access(X) | |
1365 | #define free_delay_pool_rates(X) | |
1366 | #define dump_delay_pool_class(X, Y, Z) | |
1367 | #define dump_delay_pool_access(X, Y, Z) | |
1368 | #define dump_delay_pool_rates(X, Y, Z) | |
1369 | ||
1370 | static void | |
b67e2c8c | 1371 | free_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1372 | { |
b67e2c8c | 1373 | cfg->freePoolCount(); |
59715b38 | 1374 | } |
1375 | ||
1376 | static void | |
b67e2c8c | 1377 | dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg) |
59715b38 | 1378 | { |
b67e2c8c | 1379 | cfg.dumpPoolCount (entry, name); |
59715b38 | 1380 | } |
1381 | ||
1382 | static void | |
b67e2c8c | 1383 | parse_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1384 | { |
b67e2c8c | 1385 | cfg->parsePoolCount(); |
59715b38 | 1386 | } |
1387 | ||
1388 | static void | |
b67e2c8c | 1389 | parse_delay_pool_class(DelayConfig * cfg) |
59715b38 | 1390 | { |
b67e2c8c | 1391 | cfg->parsePoolClass(); |
59715b38 | 1392 | } |
1393 | ||
1394 | static void | |
b67e2c8c | 1395 | parse_delay_pool_rates(DelayConfig * cfg) |
59715b38 | 1396 | { |
b67e2c8c | 1397 | cfg->parsePoolRates(); |
59715b38 | 1398 | } |
1399 | ||
1400 | static void | |
b67e2c8c | 1401 | parse_delay_pool_access(DelayConfig * cfg) |
59715b38 | 1402 | { |
a9f20260 | 1403 | cfg->parsePoolAccess(LegacyParser); |
59715b38 | 1404 | } |
62e76326 | 1405 | |
59715b38 | 1406 | #endif |
1407 | ||
626096be | 1408 | #if USE_HTTP_VIOLATIONS |
97474590 | 1409 | static void |
6bccf575 | 1410 | dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]) |
e3dd531e | 1411 | { |
efd900cb | 1412 | int i; |
62e76326 | 1413 | |
6bccf575 | 1414 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1415 | if (header[i].access_list != NULL) { |
1416 | storeAppendPrintf(entry, "%s ", name); | |
1417 | dump_acl_access(entry, httpHeaderNameById(i), | |
1418 | header[i].access_list); | |
1419 | } | |
efd900cb | 1420 | } |
97474590 | 1421 | } |
e3dd531e | 1422 | |
97474590 | 1423 | static void |
6bccf575 | 1424 | parse_http_header_access(header_mangler header[]) |
97474590 | 1425 | { |
6bccf575 | 1426 | int id, i; |
97474590 | 1427 | char *t = NULL; |
62e76326 | 1428 | |
97474590 | 1429 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1430 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1431 | debugs(3, 0, "parse_http_header_access: missing header name."); | |
62e76326 | 1432 | return; |
97474590 | 1433 | } |
62e76326 | 1434 | |
6bccf575 | 1435 | /* Now lookup index of header. */ |
1436 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1437 | |
6bccf575 | 1438 | if (strcmp(t, "All") == 0) |
62e76326 | 1439 | id = HDR_ENUM_END; |
6bccf575 | 1440 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1441 | id = HDR_OTHER; |
6bccf575 | 1442 | else if (id == -1) { |
bf8fe701 | 1443 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1444 | debugs(3, 0, "parse_http_header_access: unknown header name '" << t << "'"); | |
62e76326 | 1445 | return; |
97474590 | 1446 | } |
62e76326 | 1447 | |
6bccf575 | 1448 | if (id != HDR_ENUM_END) { |
62e76326 | 1449 | parse_acl_access(&header[id].access_list); |
6bccf575 | 1450 | } else { |
62e76326 | 1451 | char *next_string = t + strlen(t) - 1; |
1452 | *next_string = 'A'; | |
1453 | *(next_string + 1) = ' '; | |
1454 | ||
1455 | for (i = 0; i < HDR_ENUM_END; i++) { | |
1456 | char *new_string = xstrdup(next_string); | |
1457 | strtok(new_string, w_space); | |
1458 | parse_acl_access(&header[i].access_list); | |
1459 | safe_free(new_string); | |
1460 | } | |
97474590 | 1461 | } |
6bccf575 | 1462 | } |
1463 | ||
1464 | static void | |
1465 | free_http_header_access(header_mangler header[]) | |
1466 | { | |
1467 | int i; | |
62e76326 | 1468 | |
6bccf575 | 1469 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1470 | free_acl_access(&header[i].access_list); |
6bccf575 | 1471 | } |
1472 | } | |
1473 | ||
1474 | static void | |
1475 | dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler | |
62e76326 | 1476 | header[]) |
6bccf575 | 1477 | { |
1478 | int i; | |
62e76326 | 1479 | |
6bccf575 | 1480 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1481 | if (NULL == header[i].replacement) |
1482 | continue; | |
1483 | ||
1484 | storeAppendPrintf(entry, "%s %s %s\n", name, httpHeaderNameById(i), | |
1485 | header[i].replacement); | |
97474590 | 1486 | } |
1487 | } | |
e3dd531e | 1488 | |
97474590 | 1489 | static void |
6bccf575 | 1490 | parse_http_header_replace(header_mangler header[]) |
e3dd531e | 1491 | { |
6bccf575 | 1492 | int id, i; |
1493 | char *t = NULL; | |
62e76326 | 1494 | |
6bccf575 | 1495 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1496 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1497 | debugs(3, 0, "parse_http_header_replace: missing header name."); | |
62e76326 | 1498 | return; |
6bccf575 | 1499 | } |
62e76326 | 1500 | |
6bccf575 | 1501 | /* Now lookup index of header. */ |
1502 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1503 | |
6bccf575 | 1504 | if (strcmp(t, "All") == 0) |
62e76326 | 1505 | id = HDR_ENUM_END; |
6bccf575 | 1506 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1507 | id = HDR_OTHER; |
6bccf575 | 1508 | else if (id == -1) { |
bf8fe701 | 1509 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1510 | debugs(3, 0, "parse_http_header_replace: unknown header name " << t << "."); | |
1511 | ||
62e76326 | 1512 | return; |
6bccf575 | 1513 | } |
62e76326 | 1514 | |
6bccf575 | 1515 | if (id != HDR_ENUM_END) { |
62e76326 | 1516 | if (header[id].replacement != NULL) |
1517 | safe_free(header[id].replacement); | |
1518 | ||
1519 | header[id].replacement = xstrdup(t + strlen(t) + 1); | |
6bccf575 | 1520 | } else { |
62e76326 | 1521 | for (i = 0; i < HDR_ENUM_END; i++) { |
1522 | if (header[i].replacement != NULL) | |
1523 | safe_free(header[i].replacement); | |
1524 | ||
1525 | header[i].replacement = xstrdup(t + strlen(t) + 1); | |
1526 | } | |
6bccf575 | 1527 | } |
1528 | } | |
1529 | ||
1530 | static void | |
1531 | free_http_header_replace(header_mangler header[]) | |
1532 | { | |
1533 | int i; | |
62e76326 | 1534 | |
6bccf575 | 1535 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1536 | if (header[i].replacement != NULL) |
1537 | safe_free(header[i].replacement); | |
6bccf575 | 1538 | } |
97474590 | 1539 | } |
62e76326 | 1540 | |
9e8b2f1c | 1541 | #endif |
97474590 | 1542 | |
e90100aa | 1543 | static void |
e1f7507e | 1544 | dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap) |
e90100aa | 1545 | { |
f53b06f9 | 1546 | SwapDir *s; |
1547 | int i; | |
d3b3ab85 | 1548 | assert (entry); |
62e76326 | 1549 | |
a7d59104 | 1550 | for (i = 0; i < swap.n_configured; i++) { |
c8f4eac4 | 1551 | s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw()); |
26ac0430 | 1552 | if (!s) continue; |
59b2d47f | 1553 | storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path); |
62e76326 | 1554 | s->dump(*entry); |
62e76326 | 1555 | storeAppendPrintf(entry, "\n"); |
f53b06f9 | 1556 | } |
1557 | } | |
1558 | ||
53ad48e6 | 1559 | static int |
1560 | check_null_string(char *s) | |
1561 | { | |
1562 | return s == NULL; | |
1563 | } | |
1564 | ||
94439e4e | 1565 | static void |
5817ee13 | 1566 | parse_authparam(Auth::authConfig * config) |
94439e4e | 1567 | { |
1568 | char *type_str; | |
1569 | char *param_str; | |
94439e4e | 1570 | |
1571 | if ((type_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1572 | self_destruct(); |
94439e4e | 1573 | |
1574 | if ((param_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1575 | self_destruct(); |
94439e4e | 1576 | |
5817ee13 AJ |
1577 | /* find a configuration for the scheme in the currently parsed configs... */ |
1578 | AuthConfig *schemeCfg = AuthConfig::Find(type_str); | |
62e76326 | 1579 | |
5817ee13 AJ |
1580 | if (schemeCfg == NULL) { |
1581 | /* Create a configuration based on the scheme info */ | |
1582 | AuthScheme::Pointer theScheme = AuthScheme::Find(type_str); | |
f5691f9c | 1583 | |
5817ee13 AJ |
1584 | if (theScheme == NULL) { |
1585 | debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'."); | |
1586 | self_destruct(); | |
62e76326 | 1587 | } |
94439e4e | 1588 | |
f5691f9c | 1589 | config->push_back(theScheme->createConfig()); |
5817ee13 AJ |
1590 | schemeCfg = AuthConfig::Find(type_str); |
1591 | if (schemeCfg == NULL) { | |
1592 | debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'."); | |
1593 | self_destruct(); | |
1594 | } | |
94439e4e | 1595 | } |
62e76326 | 1596 | |
5817ee13 | 1597 | schemeCfg->parse(schemeCfg, config->size(), param_str); |
94439e4e | 1598 | } |
1599 | ||
1600 | static void | |
5817ee13 | 1601 | free_authparam(Auth::authConfig * cfg) |
94439e4e | 1602 | { |
5817ee13 AJ |
1603 | /* Wipe the Auth globals and Detach/Destruct component config + state. */ |
1604 | cfg->clean(); | |
62e76326 | 1605 | |
5817ee13 | 1606 | /* remove our pointers to the probably-dead sub-configs */ |
f5691f9c | 1607 | while (cfg->size()) { |
5817ee13 AJ |
1608 | cfg->pop_back(); |
1609 | } | |
1610 | ||
1611 | /* on reconfigure initialize new auth schemes for the new config. */ | |
ec5858ff | 1612 | if (reconfiguring) { |
5817ee13 | 1613 | InitAuthSchemes(); |
94439e4e | 1614 | } |
94439e4e | 1615 | } |
1616 | ||
1617 | static void | |
1618 | dump_authparam(StoreEntry * entry, const char *name, authConfig cfg) | |
1619 | { | |
f5691f9c | 1620 | for (authConfig::iterator i = cfg.begin(); i != cfg.end(); ++i) |
1621 | (*i)->dump(entry, name, (*i)); | |
94439e4e | 1622 | } |
1623 | ||
59b2d47f | 1624 | /* TODO: just return the object, the # is irrelevant */ |
cd748f27 | 1625 | static int |
1626 | find_fstype(char *type) | |
1627 | { | |
59b2d47f | 1628 | for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i) |
1629 | if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0) | |
1630 | return (int)i; | |
62e76326 | 1631 | |
cd748f27 | 1632 | return (-1); |
1633 | } | |
1634 | ||
0e4e0e7d | 1635 | static void |
e1f7507e | 1636 | parse_cachedir(SquidConfig::_cacheSwap * swap) |
0e4e0e7d | 1637 | { |
1638 | char *type_str; | |
cd748f27 | 1639 | char *path_str; |
c8f4eac4 | 1640 | RefCount<SwapDir> sd; |
cd748f27 | 1641 | int i; |
1642 | int fs; | |
cd748f27 | 1643 | |
0e4e0e7d | 1644 | if ((type_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1645 | self_destruct(); |
cd748f27 | 1646 | |
cd748f27 | 1647 | if ((path_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1648 | self_destruct(); |
cd748f27 | 1649 | |
c9e2e0e8 | 1650 | fs = find_fstype(type_str); |
1651 | ||
1652 | if (fs < 0) | |
1653 | self_destruct(); | |
1654 | ||
1655 | /* reconfigure existing dir */ | |
cd748f27 | 1656 | |
1657 | for (i = 0; i < swap->n_configured; i++) { | |
c8f4eac4 | 1658 | assert (swap->swapDirs[i].getRaw()); |
62e76326 | 1659 | |
2c9e9cba | 1660 | if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) { |
c9e2e0e8 | 1661 | /* this is specific to on-fs Stores. The right |
26ac0430 | 1662 | * way to handle this is probably to have a mapping |
c9e2e0e8 | 1663 | * from paths to stores, and have on-fs stores |
1664 | * register with that, and lookip in that in their | |
1665 | * own setup logic. RBC 20041225. TODO. | |
1666 | */ | |
c8f4eac4 | 1667 | |
1668 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw()); | |
1669 | ||
c9e2e0e8 | 1670 | if (sd->type() != StoreFileSystem::FileSystems().items[fs]->type()) { |
bf8fe701 | 1671 | debugs(3, 0, "ERROR: Can't change type of existing cache_dir " << |
1672 | sd->type() << " " << sd->path << " to " << type_str << ". Restart required"); | |
c9e2e0e8 | 1673 | return; |
1674 | } | |
1675 | ||
62e76326 | 1676 | sd->reconfigure (i, path_str); |
c8f4eac4 | 1677 | |
62e76326 | 1678 | update_maxobjsize(); |
c8f4eac4 | 1679 | |
62e76326 | 1680 | return; |
1681 | } | |
cd748f27 | 1682 | } |
1683 | ||
c9e2e0e8 | 1684 | /* new cache_dir */ |
af6a12ee | 1685 | if (swap->n_configured > 63) { |
2c9e9cba AJ |
1686 | /* 7 bits, signed */ |
1687 | debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle."); | |
1688 | debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many."); | |
1689 | self_destruct(); | |
1690 | return; | |
1691 | } | |
dc986280 | 1692 | |
cd748f27 | 1693 | allocate_new_swapdir(swap); |
c9e2e0e8 | 1694 | |
59b2d47f | 1695 | swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir(); |
c9e2e0e8 | 1696 | |
c8f4eac4 | 1697 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw()); |
c9e2e0e8 | 1698 | |
8e8d4f30 | 1699 | /* parse the FS parameters and options */ |
d3b3ab85 | 1700 | sd->parse(swap->n_configured, path_str); |
c9e2e0e8 | 1701 | |
d3b3ab85 | 1702 | ++swap->n_configured; |
c9e2e0e8 | 1703 | |
cd748f27 | 1704 | /* Update the max object size */ |
1705 | update_maxobjsize(); | |
752c3b27 | 1706 | } |
1707 | ||
2d72d4fd | 1708 | static const char * |
505e35db | 1709 | peer_type_str(const peer_t type) |
1710 | { | |
1f140227 | 1711 | const char * result; |
1712 | ||
0cdcddb9 | 1713 | switch (type) { |
62e76326 | 1714 | |
505e35db | 1715 | case PEER_PARENT: |
1f140227 | 1716 | result = "parent"; |
62e76326 | 1717 | break; |
1718 | ||
505e35db | 1719 | case PEER_SIBLING: |
1f140227 | 1720 | result = "sibling"; |
62e76326 | 1721 | break; |
1722 | ||
505e35db | 1723 | case PEER_MULTICAST: |
1f140227 | 1724 | result = "multicast"; |
62e76326 | 1725 | break; |
1726 | ||
505e35db | 1727 | default: |
1f140227 | 1728 | result = "unknown"; |
62e76326 | 1729 | break; |
505e35db | 1730 | } |
1f140227 | 1731 | |
1732 | return result; | |
505e35db | 1733 | } |
1734 | ||
f1dc9b30 | 1735 | static void |
a7d59104 | 1736 | dump_peer(StoreEntry * entry, const char *name, peer * p) |
98ffb7e4 | 1737 | { |
505e35db | 1738 | domain_ping *d; |
505e35db | 1739 | domain_type *t; |
1740 | LOCAL_ARRAY(char, xname, 128); | |
62e76326 | 1741 | |
d41de3c1 | 1742 | while (p != NULL) { |
4bc48d15 | 1743 | storeAppendPrintf(entry, "%s %s %s %d %d name=%s", |
62e76326 | 1744 | name, |
1745 | p->host, | |
1746 | neighborTypeStr(p), | |
1747 | p->http_port, | |
4bc48d15 AJ |
1748 | p->icp.port, |
1749 | p->name); | |
62e76326 | 1750 | dump_peer_options(entry, p); |
1751 | ||
1752 | for (d = p->peer_domain; d; d = d->next) { | |
1753 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", | |
1754 | p->host, | |
1755 | d->do_ping ? null_string : "!", | |
1756 | d->domain); | |
1757 | } | |
1758 | ||
1759 | if (p->access) { | |
1760 | snprintf(xname, 128, "cache_peer_access %s", p->name); | |
1761 | dump_acl_access(entry, xname, p->access); | |
1762 | } | |
1763 | ||
1764 | for (t = p->typelist; t; t = t->next) { | |
1765 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
1766 | p->host, | |
1767 | peer_type_str(t->type), | |
1768 | t->domain); | |
1769 | } | |
1770 | ||
1771 | p = p->next; | |
d41de3c1 | 1772 | } |
98ffb7e4 | 1773 | } |
1774 | ||
86ae97bb AJ |
1775 | /** |
1776 | * utility function to prevent getservbyname() being called with a numeric value | |
1777 | * on Windows at least it returns garage results. | |
1778 | */ | |
1779 | static bool | |
1780 | isUnsignedNumeric(const char *str, size_t len) | |
1781 | { | |
1782 | if (len < 1) return false; | |
1783 | ||
1784 | for (; len >0 && *str; str++, len--) { | |
1785 | if (! isdigit(*str)) | |
1786 | return false; | |
1787 | } | |
1788 | return true; | |
1789 | } | |
1790 | ||
609fac72 | 1791 | /** |
1792 | \param proto 'tcp' or 'udp' for protocol | |
1793 | \returns Port the named service is supposed to be listening on. | |
1794 | */ | |
1795 | static u_short | |
1796 | GetService(const char *proto) | |
1797 | { | |
1798 | struct servent *port = NULL; | |
1799 | /** Parses a port number or service name from the squid.conf */ | |
1800 | char *token = strtok(NULL, w_space); | |
1801 | if (token == NULL) { | |
26ac0430 AJ |
1802 | self_destruct(); |
1803 | return 0; /* NEVER REACHED */ | |
609fac72 | 1804 | } |
1805 | /** Returns either the service port number from /etc/services */ | |
e1381638 | 1806 | if ( !isUnsignedNumeric(token, strlen(token)) ) |
86ae97bb | 1807 | port = getservbyname(token, proto); |
609fac72 | 1808 | if (port != NULL) { |
1809 | return ntohs((u_short)port->s_port); | |
1810 | } | |
1811 | /** Or a numeric translation of the config text. */ | |
1812 | return xatos(token); | |
1813 | } | |
1814 | ||
1815 | /** | |
1816 | \returns Port the named TCP service is supposed to be listening on. | |
1817 | \copydoc GetService(const char *proto) | |
1818 | */ | |
1819 | inline u_short | |
1820 | GetTcpService(void) | |
1821 | { | |
1822 | return GetService("tcp"); | |
1823 | } | |
1824 | ||
1825 | /** | |
1826 | \returns Port the named UDP service is supposed to be listening on. | |
1827 | \copydoc GetService(const char *proto) | |
1828 | */ | |
1829 | inline u_short | |
1830 | GetUdpService(void) | |
1831 | { | |
1832 | return GetService("udp"); | |
1833 | } | |
1834 | ||
8203a132 | 1835 | static void |
40a1495e | 1836 | parse_peer(peer ** head) |
7813c6d5 | 1837 | { |
270b86af | 1838 | char *token = NULL; |
40a1495e | 1839 | peer *p; |
f5691f9c | 1840 | CBDATA_INIT_TYPE_FREECB(peer, peerDestroy); |
72711e31 | 1841 | p = cbdataAlloc(peer); |
40a1495e | 1842 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 1843 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 1844 | p->weight = 1; |
d1b63fc8 | 1845 | p->basetime = 0; |
dc835977 | 1846 | p->stats.logged_state = PEER_ALIVE; |
62e76326 | 1847 | |
e481c2dc | 1848 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 1849 | self_destruct(); |
1850 | ||
40a1495e | 1851 | p->host = xstrdup(token); |
26ac0430 | 1852 | |
be753325 | 1853 | p->name = xstrdup(token); |
62e76326 | 1854 | |
e481c2dc | 1855 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 1856 | self_destruct(); |
1857 | ||
40a1495e | 1858 | p->type = parseNeighborType(token); |
62e76326 | 1859 | |
0d5a2006 | 1860 | if (p->type == PEER_MULTICAST) { |
1861 | p->options.no_digest = 1; | |
1862 | p->options.no_netdb_exchange = 1; | |
1863 | } | |
1864 | ||
609fac72 | 1865 | p->http_port = GetTcpService(); |
62e76326 | 1866 | |
0e656b69 | 1867 | if (!p->http_port) |
1868 | self_destruct(); | |
62e76326 | 1869 | |
609fac72 | 1870 | p->icp.port = GetUdpService(); |
d67acb4e | 1871 | p->connection_auth = 2; /* auto */ |
62e76326 | 1872 | |
270b86af | 1873 | while ((token = strtok(NULL, w_space))) { |
62e76326 | 1874 | if (!strcasecmp(token, "proxy-only")) { |
1875 | p->options.proxy_only = 1; | |
1876 | } else if (!strcasecmp(token, "no-query")) { | |
1877 | p->options.no_query = 1; | |
1878 | } else if (!strcasecmp(token, "background-ping")) { | |
1879 | p->options.background_ping = 1; | |
1880 | } else if (!strcasecmp(token, "no-digest")) { | |
1881 | p->options.no_digest = 1; | |
b0758e04 AJ |
1882 | } else if (!strcasecmp(token, "no-tproxy")) { |
1883 | p->options.no_tproxy = 1; | |
62e76326 | 1884 | } else if (!strcasecmp(token, "multicast-responder")) { |
1885 | p->options.mcast_responder = 1; | |
8a368316 | 1886 | #if PEER_MULTICAST_SIBLINGS |
79ddb8e2 | 1887 | } else if (!strcasecmp(token, "multicast-siblings")) { |
8a368316 AJ |
1888 | p->options.mcast_siblings = 1; |
1889 | #endif | |
62e76326 | 1890 | } else if (!strncasecmp(token, "weight=", 7)) { |
1891 | p->weight = xatoi(token + 7); | |
1892 | } else if (!strncasecmp(token, "basetime=", 9)) { | |
1893 | p->basetime = xatoi(token + 9); | |
1894 | } else if (!strcasecmp(token, "closest-only")) { | |
1895 | p->options.closest_only = 1; | |
1896 | } else if (!strncasecmp(token, "ttl=", 4)) { | |
1897 | p->mcast.ttl = xatoi(token + 4); | |
1898 | ||
1899 | if (p->mcast.ttl < 0) | |
1900 | p->mcast.ttl = 0; | |
1901 | ||
1902 | if (p->mcast.ttl > 128) | |
1903 | p->mcast.ttl = 128; | |
1904 | } else if (!strcasecmp(token, "default")) { | |
1905 | p->options.default_parent = 1; | |
1906 | } else if (!strcasecmp(token, "round-robin")) { | |
1907 | p->options.roundrobin = 1; | |
1908 | } else if (!strcasecmp(token, "weighted-round-robin")) { | |
1909 | p->options.weighted_roundrobin = 1; | |
dc9d133b | 1910 | #if USE_HTCP |
62e76326 | 1911 | |
1912 | } else if (!strcasecmp(token, "htcp")) { | |
1913 | p->options.htcp = 1; | |
527ee50d | 1914 | } else if (!strcasecmp(token, "htcp-oldsquid")) { |
1915 | p->options.htcp = 1; | |
1916 | p->options.htcp_oldsquid = 1; | |
4f4fa815 BR |
1917 | } else if (!strcasecmp(token, "htcp-no-clr")) { |
1918 | if (p->options.htcp_only_clr) | |
26ac0430 | 1919 | fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously"); |
4f4fa815 BR |
1920 | p->options.htcp = 1; |
1921 | p->options.htcp_no_clr = 1; | |
1922 | } else if (!strcasecmp(token, "htcp-no-purge-clr")) { | |
1923 | p->options.htcp = 1; | |
1924 | p->options.htcp_no_purge_clr = 1; | |
1925 | } else if (!strcasecmp(token, "htcp-only-clr")) { | |
1926 | if (p->options.htcp_no_clr) | |
26ac0430 | 1927 | fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously"); |
4f4fa815 BR |
1928 | p->options.htcp = 1; |
1929 | p->options.htcp_only_clr = 1; | |
1930 | } else if (!strcasecmp(token, "htcp-forward-clr")) { | |
1931 | p->options.htcp = 1; | |
1932 | p->options.htcp_forward_clr = 1; | |
dc9d133b | 1933 | #endif |
62e76326 | 1934 | |
1935 | } else if (!strcasecmp(token, "no-netdb-exchange")) { | |
1936 | p->options.no_netdb_exchange = 1; | |
62e76326 | 1937 | |
1938 | } else if (!strcasecmp(token, "carp")) { | |
1939 | if (p->type != PEER_PARENT) | |
1940 | fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port); | |
1941 | ||
1942 | p->options.carp = 1; | |
1943 | ||
f7e1d9ce HN |
1944 | } else if (!strcasecmp(token, "userhash")) { |
1945 | if (p->type != PEER_PARENT) | |
1946 | fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port); | |
1947 | ||
1948 | p->options.userhash = 1; | |
1949 | ||
1950 | } else if (!strcasecmp(token, "sourcehash")) { | |
1951 | if (p->type != PEER_PARENT) | |
1952 | fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port); | |
1953 | ||
1954 | p->options.sourcehash = 1; | |
1955 | ||
95e36d02 | 1956 | #if DELAY_POOLS |
62e76326 | 1957 | |
1958 | } else if (!strcasecmp(token, "no-delay")) { | |
1959 | p->options.no_delay = 1; | |
afd88fbe | 1960 | #endif |
62e76326 | 1961 | |
1962 | } else if (!strncasecmp(token, "login=", 6)) { | |
1963 | p->login = xstrdup(token + 6); | |
1964 | rfc1738_unescape(p->login); | |
1965 | } else if (!strncasecmp(token, "connect-timeout=", 16)) { | |
1966 | p->connect_timeout = xatoi(token + 16); | |
ff9970cc AJ |
1967 | } else if (!strncasecmp(token, "connect-fail-limit=", 19)) { |
1968 | p->connect_fail_limit = xatoi(token + 19); | |
7e3ce7b9 | 1969 | #if USE_CACHE_DIGESTS |
62e76326 | 1970 | } else if (!strncasecmp(token, "digest-url=", 11)) { |
1971 | p->digest_url = xstrdup(token + 11); | |
7e3ce7b9 | 1972 | #endif |
62e76326 | 1973 | |
1974 | } else if (!strcasecmp(token, "allow-miss")) { | |
1975 | p->options.allow_miss = 1; | |
1976 | } else if (!strncasecmp(token, "max-conn=", 9)) { | |
1977 | p->max_conn = xatoi(token + 9); | |
1978 | } else if (!strcasecmp(token, "originserver")) { | |
1979 | p->options.originserver = 1; | |
1980 | } else if (!strncasecmp(token, "name=", 5)) { | |
1981 | safe_free(p->name); | |
1982 | ||
1983 | if (token[5]) | |
1984 | p->name = xstrdup(token + 5); | |
1985 | } else if (!strncasecmp(token, "forceddomain=", 13)) { | |
1986 | safe_free(p->domain); | |
1987 | ||
1988 | if (token[13]) | |
1989 | p->domain = xstrdup(token + 13); | |
1990 | ||
a7ad6e4e | 1991 | #if USE_SSL |
62e76326 | 1992 | |
1993 | } else if (strcmp(token, "ssl") == 0) { | |
1994 | p->use_ssl = 1; | |
1995 | } else if (strncmp(token, "sslcert=", 8) == 0) { | |
1996 | safe_free(p->sslcert); | |
1997 | p->sslcert = xstrdup(token + 8); | |
1998 | } else if (strncmp(token, "sslkey=", 7) == 0) { | |
1999 | safe_free(p->sslkey); | |
2000 | p->sslkey = xstrdup(token + 7); | |
2001 | } else if (strncmp(token, "sslversion=", 11) == 0) { | |
2002 | p->sslversion = atoi(token + 11); | |
2003 | } else if (strncmp(token, "ssloptions=", 11) == 0) { | |
2004 | safe_free(p->ssloptions); | |
2005 | p->ssloptions = xstrdup(token + 11); | |
2006 | } else if (strncmp(token, "sslcipher=", 10) == 0) { | |
2007 | safe_free(p->sslcipher); | |
2008 | p->sslcipher = xstrdup(token + 10); | |
2009 | } else if (strncmp(token, "sslcafile=", 10) == 0) { | |
2010 | safe_free(p->sslcafile); | |
a82a4fe4 | 2011 | p->sslcafile = xstrdup(token + 10); |
62e76326 | 2012 | } else if (strncmp(token, "sslcapath=", 10) == 0) { |
2013 | safe_free(p->sslcapath); | |
a82a4fe4 | 2014 | p->sslcapath = xstrdup(token + 10); |
2015 | } else if (strncmp(token, "sslcrlfile=", 11) == 0) { | |
2016 | safe_free(p->sslcrlfile); | |
2017 | p->sslcapath = xstrdup(token + 10); | |
62e76326 | 2018 | } else if (strncmp(token, "sslflags=", 9) == 0) { |
2019 | safe_free(p->sslflags); | |
2020 | p->sslflags = xstrdup(token + 9); | |
2021 | } else if (strncmp(token, "ssldomain=", 10) == 0) { | |
2022 | safe_free(p->ssldomain); | |
2023 | p->ssldomain = xstrdup(token + 10); | |
a7ad6e4e | 2024 | #endif |
62e76326 | 2025 | |
2026 | } else if (strcmp(token, "front-end-https") == 0) { | |
2027 | p->front_end_https = 1; | |
2028 | } else if (strcmp(token, "front-end-https=on") == 0) { | |
2029 | p->front_end_https = 1; | |
2030 | } else if (strcmp(token, "front-end-https=auto") == 0) { | |
2031 | p->front_end_https = 2; | |
26ac0430 | 2032 | } else if (strcmp(token, "connection-auth=off") == 0) { |
d67acb4e AJ |
2033 | p->connection_auth = 0; |
2034 | } else if (strcmp(token, "connection-auth") == 0) { | |
2035 | p->connection_auth = 1; | |
2036 | } else if (strcmp(token, "connection-auth=on") == 0) { | |
2037 | p->connection_auth = 1; | |
2038 | } else if (strcmp(token, "connection-auth=auto") == 0) { | |
2039 | p->connection_auth = 2; | |
62e76326 | 2040 | } else { |
bf8fe701 | 2041 | debugs(3, 0, "parse_peer: token='" << token << "'"); |
62e76326 | 2042 | self_destruct(); |
2043 | } | |
270b86af | 2044 | } |
62e76326 | 2045 | |
be753325 | 2046 | if (peerFindByName(p->name)) |
62e76326 | 2047 | fatalf("ERROR: cache_peer %s specified twice\n", p->name); |
2048 | ||
40a1495e | 2049 | if (p->weight < 1) |
62e76326 | 2050 | p->weight = 1; |
2051 | ||
ff9970cc | 2052 | if (p->connect_fail_limit < 1) |
a4d889e0 | 2053 | p->connect_fail_limit = 10; |
ff9970cc | 2054 | |
399cabec | 2055 | p->icp.version = ICP_VERSION_CURRENT; |
62e76326 | 2056 | |
eb406bb7 | 2057 | p->test_fd = -1; |
62e76326 | 2058 | |
e13ee7ad | 2059 | #if USE_CACHE_DIGESTS |
62e76326 | 2060 | |
e13ee7ad | 2061 | if (!p->options.no_digest) { |
62e76326 | 2062 | /* XXX This looks odd.. who has the original pointer |
2063 | * then? | |
2064 | */ | |
2065 | PeerDigest *pd = peerDigestCreate(p); | |
2066 | p->digest = cbdataReference(pd); | |
8a6218c6 | 2067 | } |
62e76326 | 2068 | |
e13ee7ad | 2069 | #endif |
cc192b50 | 2070 | |
2071 | p->index = ++Config.npeers; | |
2072 | ||
0153d498 | 2073 | while (*head != NULL) |
62e76326 | 2074 | head = &(*head)->next; |
2075 | ||
0153d498 | 2076 | *head = p; |
62e76326 | 2077 | |
32a47e3e | 2078 | peerClearRRStart(); |
0153d498 | 2079 | } |
2080 | ||
2081 | static void | |
40a1495e | 2082 | free_peer(peer ** P) |
0153d498 | 2083 | { |
40a1495e | 2084 | peer *p; |
62e76326 | 2085 | |
79d39a72 | 2086 | while ((p = *P) != NULL) { |
62e76326 | 2087 | *P = p->next; |
3855c318 | 2088 | #if USE_CACHE_DIGESTS |
62e76326 | 2089 | |
2090 | cbdataReferenceDone(p->digest); | |
3855c318 | 2091 | #endif |
62e76326 | 2092 | |
2093 | cbdataFree(p); | |
a47b9029 | 2094 | } |
62e76326 | 2095 | |
987c67d1 | 2096 | Config.npeers = 0; |
270b86af | 2097 | } |
2098 | ||
2099 | static void | |
a7d59104 | 2100 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) |
270b86af | 2101 | { |
d41de3c1 | 2102 | wordlist *w; |
62e76326 | 2103 | |
d41de3c1 | 2104 | while (list != NULL) { |
62e76326 | 2105 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
2106 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
2107 | else | |
2108 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
2109 | ||
2110 | for (w = list->actions; w != NULL; w = w->next) { | |
2111 | storeAppendPrintf(entry, " %s", w->key); | |
2112 | } | |
2113 | ||
2114 | storeAppendPrintf(entry, "\n"); | |
2115 | list = list->next; | |
d41de3c1 | 2116 | } |
270b86af | 2117 | } |
2118 | ||
2119 | static void | |
a47b9029 | 2120 | parse_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 2121 | { |
2122 | char *passwd = NULL; | |
2123 | wordlist *actions = NULL; | |
22f3fd98 | 2124 | cachemgr_passwd *p; |
2125 | cachemgr_passwd **P; | |
270b86af | 2126 | parse_string(&passwd); |
2127 | parse_wordlist(&actions); | |
e6ccf245 | 2128 | p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd))); |
22f3fd98 | 2129 | p->passwd = passwd; |
2130 | p->actions = actions; | |
62e76326 | 2131 | |
26aa7e31 | 2132 | for (P = head; *P; P = &(*P)->next) { |
62e76326 | 2133 | /* |
2134 | * See if any of the actions from this line already have a | |
2135 | * password from previous lines. The password checking | |
2136 | * routines in cache_manager.c take the the password from | |
2137 | * the first cachemgr_passwd struct that contains the | |
2138 | * requested action. Thus, we should warn users who might | |
2139 | * think they can have two passwords for the same action. | |
2140 | */ | |
2141 | wordlist *w; | |
2142 | wordlist *u; | |
2143 | ||
2144 | for (w = (*P)->actions; w; w = w->next) { | |
2145 | for (u = actions; u; u = u->next) { | |
2146 | if (strcmp(w->key, u->key)) | |
2147 | continue; | |
2148 | ||
bf8fe701 | 2149 | debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password"); |
62e76326 | 2150 | } |
2151 | } | |
26aa7e31 | 2152 | } |
62e76326 | 2153 | |
22f3fd98 | 2154 | *P = p; |
270b86af | 2155 | } |
2156 | ||
2157 | static void | |
a47b9029 | 2158 | free_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 2159 | { |
a47b9029 | 2160 | cachemgr_passwd *p; |
62e76326 | 2161 | |
79d39a72 | 2162 | while ((p = *head) != NULL) { |
62e76326 | 2163 | *head = p->next; |
2164 | xfree(p->passwd); | |
2165 | wordlistDestroy(&p->actions); | |
2166 | xfree(p); | |
a47b9029 | 2167 | } |
270b86af | 2168 | } |
2169 | ||
8203a132 | 2170 | static void |
16300b58 | 2171 | dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) |
270b86af | 2172 | { |
d41de3c1 | 2173 | acl_name_list *a; |
62e76326 | 2174 | |
d41de3c1 | 2175 | while (var != NULL) { |
62e76326 | 2176 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
2177 | ||
2178 | for (a = var->acl_list; a != NULL; a = a->next) | |
2179 | storeAppendPrintf(entry, " %s", a->name); | |
2180 | ||
2181 | storeAppendPrintf(entry, "\n"); | |
2182 | ||
2183 | var = var->next; | |
d41de3c1 | 2184 | } |
270b86af | 2185 | } |
2186 | ||
2187 | static void | |
16300b58 | 2188 | parse_denyinfo(acl_deny_info_list ** var) |
6e40f263 | 2189 | { |
f1dc9b30 | 2190 | aclParseDenyInfoLine(var); |
6e40f263 | 2191 | } |
403279e0 | 2192 | |
1273d501 | 2193 | void |
a47b9029 | 2194 | free_denyinfo(acl_deny_info_list ** list) |
3c5557f9 | 2195 | { |
56b63fa1 | 2196 | acl_deny_info_list *a = NULL; |
2197 | acl_deny_info_list *a_next = NULL; | |
2198 | acl_name_list *l = NULL; | |
2199 | acl_name_list *l_next = NULL; | |
62e76326 | 2200 | |
1273d501 | 2201 | for (a = *list; a; a = a_next) { |
62e76326 | 2202 | for (l = a->acl_list; l; l = l_next) { |
2203 | l_next = l->next; | |
2204 | memFree(l, MEM_ACL_NAME_LIST); | |
2205 | l = NULL; | |
2206 | } | |
2207 | ||
2208 | a_next = a->next; | |
2209 | memFree(a, MEM_ACL_DENY_INFO_LIST); | |
2210 | a = NULL; | |
1273d501 | 2211 | } |
62e76326 | 2212 | |
1273d501 | 2213 | *list = NULL; |
270b86af | 2214 | } |
2215 | ||
2216 | static void | |
505e35db | 2217 | parse_peer_access(void) |
270b86af | 2218 | { |
2219 | char *host = NULL; | |
505e35db | 2220 | peer *p; |
62e76326 | 2221 | |
270b86af | 2222 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2223 | self_destruct(); |
2224 | ||
0cdcddb9 | 2225 | if ((p = peerFindByName(host)) == NULL) { |
bf8fe701 | 2226 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2227 | return; |
0cdcddb9 | 2228 | } |
62e76326 | 2229 | |
a9f20260 | 2230 | aclParseAccessLine(LegacyParser, &p->access); |
270b86af | 2231 | } |
2232 | ||
270b86af | 2233 | static void |
2234 | parse_hostdomain(void) | |
2235 | { | |
2236 | char *host = NULL; | |
2237 | char *domain = NULL; | |
62e76326 | 2238 | |
270b86af | 2239 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2240 | self_destruct(); |
2241 | ||
f1dc9b30 | 2242 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 2243 | domain_ping *l = NULL; |
2244 | domain_ping **L = NULL; | |
2245 | peer *p; | |
2246 | ||
2247 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 2248 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2249 | continue; |
2250 | } | |
2251 | ||
2252 | l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping))); | |
2253 | l->do_ping = 1; | |
2254 | ||
2255 | if (*domain == '!') { /* check for !.edu */ | |
2256 | l->do_ping = 0; | |
2257 | domain++; | |
2258 | } | |
2259 | ||
2260 | l->domain = xstrdup(domain); | |
2261 | ||
3d0ac046 | 2262 | for (L = &(p->peer_domain); *L; L = &((*L)->next)); |
62e76326 | 2263 | *L = l; |
f1dc9b30 | 2264 | } |
270b86af | 2265 | } |
2266 | ||
2267 | static void | |
2268 | parse_hostdomaintype(void) | |
2269 | { | |
2270 | char *host = NULL; | |
2271 | char *type = NULL; | |
2272 | char *domain = NULL; | |
62e76326 | 2273 | |
270b86af | 2274 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2275 | self_destruct(); |
2276 | ||
270b86af | 2277 | if (!(type = strtok(NULL, w_space))) |
62e76326 | 2278 | self_destruct(); |
2279 | ||
f1dc9b30 | 2280 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 2281 | domain_type *l = NULL; |
2282 | domain_type **L = NULL; | |
2283 | peer *p; | |
2284 | ||
2285 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 2286 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2287 | return; |
2288 | } | |
2289 | ||
2290 | l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type))); | |
2291 | l->type = parseNeighborType(type); | |
2292 | l->domain = xstrdup(domain); | |
2293 | ||
3d0ac046 | 2294 | for (L = &(p->typelist); *L; L = &((*L)->next)); |
62e76326 | 2295 | *L = l; |
f1dc9b30 | 2296 | } |
270b86af | 2297 | } |
2298 | ||
270b86af | 2299 | static void |
a7d59104 | 2300 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 2301 | { |
f53b06f9 | 2302 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2303 | } |
c1c29eb6 | 2304 | |
94439e4e | 2305 | void |
270b86af | 2306 | parse_int(int *var) |
2307 | { | |
270b86af | 2308 | int i; |
0e4e0e7d | 2309 | i = GetInteger(); |
270b86af | 2310 | *var = i; |
2311 | } | |
090089c4 | 2312 | |
0153d498 | 2313 | static void |
2314 | free_int(int *var) | |
2315 | { | |
a47b9029 | 2316 | *var = 0; |
0153d498 | 2317 | } |
2318 | ||
270b86af | 2319 | static void |
a7d59104 | 2320 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 2321 | { |
f53b06f9 | 2322 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 2323 | } |
090089c4 | 2324 | |
d205783b | 2325 | void |
270b86af | 2326 | parse_onoff(int *var) |
2327 | { | |
2328 | char *token = strtok(NULL, w_space); | |
090089c4 | 2329 | |
270b86af | 2330 | if (token == NULL) |
62e76326 | 2331 | self_destruct(); |
2332 | ||
270b86af | 2333 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) |
62e76326 | 2334 | *var = 1; |
270b86af | 2335 | else |
62e76326 | 2336 | *var = 0; |
270b86af | 2337 | } |
e90100aa | 2338 | |
0153d498 | 2339 | #define free_onoff free_int |
52d3f198 | 2340 | |
2341 | static void | |
2342 | dump_tristate(StoreEntry * entry, const char *name, int var) | |
2343 | { | |
2344 | const char *state; | |
2345 | ||
2346 | if (var > 0) | |
2347 | state = "on"; | |
2348 | else if (var < 0) | |
2349 | state = "warn"; | |
2350 | else | |
2351 | state = "off"; | |
2352 | ||
2353 | storeAppendPrintf(entry, "%s %s\n", name, state); | |
2354 | } | |
2355 | ||
2356 | static void | |
2357 | parse_tristate(int *var) | |
2358 | { | |
2359 | char *token = strtok(NULL, w_space); | |
2360 | ||
2361 | if (token == NULL) | |
2362 | self_destruct(); | |
2363 | ||
2364 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) | |
2365 | *var = 1; | |
2366 | else if (!strcasecmp(token, "warn")) | |
2367 | *var = -1; | |
2368 | else | |
2369 | *var = 0; | |
2370 | } | |
2371 | ||
2372 | #define free_tristate free_int | |
30a4f2a8 | 2373 | |
270b86af | 2374 | static void |
a7d59104 | 2375 | dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) |
270b86af | 2376 | { |
d41de3c1 | 2377 | while (head != NULL) { |
0e1d7629 | 2378 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d", |
62e76326 | 2379 | name, |
2380 | head->flags.icase ? " -i" : null_string, | |
2381 | head->pattern, | |
2382 | (int) head->min / 60, | |
2383 | (int) (100.0 * head->pct + 0.5), | |
2384 | (int) head->max / 60); | |
4c3ef9b2 | 2385 | |
2386 | if (head->flags.refresh_ims) | |
2387 | storeAppendPrintf(entry, " refresh-ims"); | |
2388 | ||
3d8b6ba4 AJ |
2389 | if (head->flags.store_stale) |
2390 | storeAppendPrintf(entry, " store-stale"); | |
2391 | ||
626096be | 2392 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2393 | |
2394 | if (head->flags.override_expire) | |
2395 | storeAppendPrintf(entry, " override-expire"); | |
2396 | ||
2397 | if (head->flags.override_lastmod) | |
2398 | storeAppendPrintf(entry, " override-lastmod"); | |
2399 | ||
2400 | if (head->flags.reload_into_ims) | |
2401 | storeAppendPrintf(entry, " reload-into-ims"); | |
2402 | ||
2403 | if (head->flags.ignore_reload) | |
2404 | storeAppendPrintf(entry, " ignore-reload"); | |
2405 | ||
38f9c547 | 2406 | if (head->flags.ignore_no_cache) |
2407 | storeAppendPrintf(entry, " ignore-no-cache"); | |
2408 | ||
2409 | if (head->flags.ignore_no_store) | |
2410 | storeAppendPrintf(entry, " ignore-no-store"); | |
2411 | ||
4ca08219 AJ |
2412 | if (head->flags.ignore_must_revalidate) |
2413 | storeAppendPrintf(entry, " ignore-must-revalidate"); | |
2414 | ||
38f9c547 | 2415 | if (head->flags.ignore_private) |
2416 | storeAppendPrintf(entry, " ignore-private"); | |
2417 | ||
2418 | if (head->flags.ignore_auth) | |
2419 | storeAppendPrintf(entry, " ignore-auth"); | |
2420 | ||
9f60cfdf | 2421 | #endif |
62e76326 | 2422 | |
2423 | storeAppendPrintf(entry, "\n"); | |
2424 | ||
2425 | head = head->next; | |
d41de3c1 | 2426 | } |
270b86af | 2427 | } |
090089c4 | 2428 | |
270b86af | 2429 | static void |
f1dc9b30 | 2430 | parse_refreshpattern(refresh_t ** head) |
270b86af | 2431 | { |
f1dc9b30 | 2432 | char *token; |
2433 | char *pattern; | |
2434 | time_t min = 0; | |
c3f6d204 | 2435 | double pct = 0.0; |
f1dc9b30 | 2436 | time_t max = 0; |
4c3ef9b2 | 2437 | int refresh_ims = 0; |
3d8b6ba4 AJ |
2438 | int store_stale = 0; |
2439 | ||
626096be | 2440 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2441 | |
1dfa1d81 | 2442 | int override_expire = 0; |
2443 | int override_lastmod = 0; | |
cbe3a719 | 2444 | int reload_into_ims = 0; |
2445 | int ignore_reload = 0; | |
38f9c547 | 2446 | int ignore_no_cache = 0; |
2447 | int ignore_no_store = 0; | |
4ca08219 | 2448 | int ignore_must_revalidate = 0; |
38f9c547 | 2449 | int ignore_private = 0; |
2450 | int ignore_auth = 0; | |
9f60cfdf | 2451 | #endif |
62e76326 | 2452 | |
f1dc9b30 | 2453 | int i; |
2454 | refresh_t *t; | |
2455 | regex_t comp; | |
2456 | int errcode; | |
2457 | int flags = REG_EXTENDED | REG_NOSUB; | |
62e76326 | 2458 | |
9eeb8e4b | 2459 | if ((token = strtok(NULL, w_space)) == NULL) { |
62e76326 | 2460 | self_destruct(); |
9eeb8e4b | 2461 | return; |
2462 | } | |
62e76326 | 2463 | |
f1dc9b30 | 2464 | if (strcmp(token, "-i") == 0) { |
62e76326 | 2465 | flags |= REG_ICASE; |
2466 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2467 | } else if (strcmp(token, "+i") == 0) { |
62e76326 | 2468 | flags &= ~REG_ICASE; |
2469 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2470 | } |
62e76326 | 2471 | |
9eeb8e4b | 2472 | if (token == NULL) { |
62e76326 | 2473 | self_destruct(); |
9eeb8e4b | 2474 | return; |
2475 | } | |
62e76326 | 2476 | |
f1dc9b30 | 2477 | pattern = xstrdup(token); |
62e76326 | 2478 | |
0e4e0e7d | 2479 | i = GetInteger(); /* token: min */ |
62e76326 | 2480 | |
a632ba71 AJ |
2481 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2482 | if (i < 0) { | |
2483 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero."); | |
2484 | i = 0; | |
2485 | } | |
2486 | if (i > 60*24*365) { | |
2487 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year."); | |
2488 | i = 60*24*365; | |
2489 | } | |
2490 | ||
f1dc9b30 | 2491 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2492 | |
0e4e0e7d | 2493 | i = GetInteger(); /* token: pct */ |
62e76326 | 2494 | |
c3f6d204 | 2495 | pct = (double) i / 100.0; |
62e76326 | 2496 | |
0e4e0e7d | 2497 | i = GetInteger(); /* token: max */ |
62e76326 | 2498 | |
a632ba71 AJ |
2499 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2500 | if (i < 0) { | |
2501 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero."); | |
2502 | i = 0; | |
2503 | } | |
2504 | if (i > 60*24*365) { | |
2505 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year."); | |
2506 | i = 60*24*365; | |
2507 | } | |
2508 | ||
f1dc9b30 | 2509 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2510 | |
1dfa1d81 | 2511 | /* Options */ |
2512 | while ((token = strtok(NULL, w_space)) != NULL) { | |
4c3ef9b2 | 2513 | if (!strcmp(token, "refresh-ims")) { |
2514 | refresh_ims = 1; | |
3d8b6ba4 AJ |
2515 | } else if (!strcmp(token, "store-stale")) { |
2516 | store_stale = 1; | |
626096be | 2517 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2518 | |
4c3ef9b2 | 2519 | } else if (!strcmp(token, "override-expire")) |
62e76326 | 2520 | override_expire = 1; |
2521 | else if (!strcmp(token, "override-lastmod")) | |
2522 | override_lastmod = 1; | |
38f9c547 | 2523 | else if (!strcmp(token, "ignore-no-cache")) |
2524 | ignore_no_cache = 1; | |
2525 | else if (!strcmp(token, "ignore-no-store")) | |
2526 | ignore_no_store = 1; | |
4ca08219 AJ |
2527 | else if (!strcmp(token, "ignore-must-revalidate")) |
2528 | ignore_must_revalidate = 1; | |
38f9c547 | 2529 | else if (!strcmp(token, "ignore-private")) |
2530 | ignore_private = 1; | |
2531 | else if (!strcmp(token, "ignore-auth")) | |
2532 | ignore_auth = 1; | |
62e76326 | 2533 | else if (!strcmp(token, "reload-into-ims")) { |
2534 | reload_into_ims = 1; | |
2535 | refresh_nocache_hack = 1; | |
2536 | /* tell client_side.c that this is used */ | |
2537 | } else if (!strcmp(token, "ignore-reload")) { | |
2538 | ignore_reload = 1; | |
2539 | refresh_nocache_hack = 1; | |
2540 | /* tell client_side.c that this is used */ | |
9f60cfdf | 2541 | #endif |
62e76326 | 2542 | |
4c3ef9b2 | 2543 | } else |
26ac0430 | 2544 | debugs(22, 0, "redreshAddToList: Unknown option '" << pattern << "': " << token); |
1dfa1d81 | 2545 | } |
62e76326 | 2546 | |
f1dc9b30 | 2547 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
62e76326 | 2548 | char errbuf[256]; |
2549 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
bf8fe701 | 2550 | debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
2551 | debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf); | |
62e76326 | 2552 | return; |
f1dc9b30 | 2553 | } |
62e76326 | 2554 | |
c3f6d204 | 2555 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 2556 | max = max < 0 ? 0 : max; |
e6ccf245 | 2557 | t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t))); |
f1dc9b30 | 2558 | t->pattern = (char *) xstrdup(pattern); |
2559 | t->compiled_pattern = comp; | |
2560 | t->min = min; | |
c3f6d204 | 2561 | t->pct = pct; |
f1dc9b30 | 2562 | t->max = max; |
62e76326 | 2563 | |
c3f6d204 | 2564 | if (flags & REG_ICASE) |
62e76326 | 2565 | t->flags.icase = 1; |
2566 | ||
4c3ef9b2 | 2567 | if (refresh_ims) |
2568 | t->flags.refresh_ims = 1; | |
2569 | ||
3d8b6ba4 AJ |
2570 | if (store_stale) |
2571 | t->flags.store_stale = 1; | |
2572 | ||
626096be | 2573 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2574 | |
1dfa1d81 | 2575 | if (override_expire) |
62e76326 | 2576 | t->flags.override_expire = 1; |
2577 | ||
1dfa1d81 | 2578 | if (override_lastmod) |
62e76326 | 2579 | t->flags.override_lastmod = 1; |
2580 | ||
cbe3a719 | 2581 | if (reload_into_ims) |
62e76326 | 2582 | t->flags.reload_into_ims = 1; |
2583 | ||
cbe3a719 | 2584 | if (ignore_reload) |
62e76326 | 2585 | t->flags.ignore_reload = 1; |
2586 | ||
38f9c547 | 2587 | if (ignore_no_cache) |
2588 | t->flags.ignore_no_cache = 1; | |
2589 | ||
2590 | if (ignore_no_store) | |
2591 | t->flags.ignore_no_store = 1; | |
2592 | ||
4ca08219 AJ |
2593 | if (ignore_must_revalidate) |
2594 | t->flags.ignore_must_revalidate = 1; | |
2595 | ||
38f9c547 | 2596 | if (ignore_private) |
2597 | t->flags.ignore_private = 1; | |
2598 | ||
2599 | if (ignore_auth) | |
2600 | t->flags.ignore_auth = 1; | |
2601 | ||
9f60cfdf | 2602 | #endif |
62e76326 | 2603 | |
f1dc9b30 | 2604 | t->next = NULL; |
62e76326 | 2605 | |
f1dc9b30 | 2606 | while (*head) |
62e76326 | 2607 | head = &(*head)->next; |
2608 | ||
f1dc9b30 | 2609 | *head = t; |
62e76326 | 2610 | |
f1dc9b30 | 2611 | safe_free(pattern); |
270b86af | 2612 | } |
090089c4 | 2613 | |
270b86af | 2614 | static void |
a47b9029 | 2615 | free_refreshpattern(refresh_t ** head) |
270b86af | 2616 | { |
f1dc9b30 | 2617 | refresh_t *t; |
62e76326 | 2618 | |
79d39a72 | 2619 | while ((t = *head) != NULL) { |
62e76326 | 2620 | *head = t->next; |
2621 | safe_free(t->pattern); | |
2622 | regfree(&t->compiled_pattern); | |
2623 | safe_free(t); | |
f1dc9b30 | 2624 | } |
c2066637 | 2625 | |
626096be | 2626 | #if USE_HTTP_VIOLATIONS |
c2066637 | 2627 | refresh_nocache_hack = 0; |
8970d351 | 2628 | |
2629 | #endif | |
270b86af | 2630 | } |
12b9e9b1 | 2631 | |
270b86af | 2632 | static void |
a7d59104 | 2633 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 2634 | { |
f53b06f9 | 2635 | if (var != NULL) |
62e76326 | 2636 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 2637 | } |
98ffb7e4 | 2638 | |
270b86af | 2639 | static void |
0153d498 | 2640 | parse_string(char **var) |
270b86af | 2641 | { |
2642 | char *token = strtok(NULL, w_space); | |
270b86af | 2643 | safe_free(*var); |
62e76326 | 2644 | |
270b86af | 2645 | if (token == NULL) |
62e76326 | 2646 | self_destruct(); |
2647 | ||
270b86af | 2648 | *var = xstrdup(token); |
2649 | } | |
b15e6857 | 2650 | |
3a69ddf3 | 2651 | void |
2652 | ConfigParser::ParseString(char **var) | |
2653 | { | |
2654 | parse_string(var); | |
2655 | } | |
2656 | ||
2657 | void | |
30abd221 | 2658 | ConfigParser::ParseString(String *var) |
3a69ddf3 | 2659 | { |
2660 | char *token = strtok(NULL, w_space); | |
2661 | ||
2662 | if (token == NULL) | |
2663 | self_destruct(); | |
2664 | ||
30abd221 | 2665 | var->reset(token); |
3a69ddf3 | 2666 | } |
2667 | ||
0153d498 | 2668 | static void |
2669 | free_string(char **var) | |
2670 | { | |
027acbaf | 2671 | safe_free(*var); |
0153d498 | 2672 | } |
caebbe00 | 2673 | |
94439e4e | 2674 | void |
f1dc9b30 | 2675 | parse_eol(char *volatile *var) |
270b86af | 2676 | { |
852751f7 | 2677 | unsigned char *token = (unsigned char *) strtok(NULL, null_string); |
270b86af | 2678 | safe_free(*var); |
62e76326 | 2679 | |
9eeb8e4b | 2680 | if (!token) { |
62e76326 | 2681 | self_destruct(); |
9eeb8e4b | 2682 | return; |
2683 | } | |
62e76326 | 2684 | |
e4755e29 | 2685 | while (*token && xisspace(*token)) |
62e76326 | 2686 | token++; |
2687 | ||
9eeb8e4b | 2688 | if (!*token) { |
62e76326 | 2689 | self_destruct(); |
9eeb8e4b | 2690 | return; |
2691 | } | |
62e76326 | 2692 | |
852751f7 | 2693 | *var = xstrdup((char *) token); |
270b86af | 2694 | } |
090089c4 | 2695 | |
52d3f198 | 2696 | #define dump_eol dump_string |
2697 | #define free_eol free_string | |
2698 | ||
270b86af | 2699 | static void |
a7d59104 | 2700 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 2701 | { |
f53b06f9 | 2702 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 2703 | } |
2704 | ||
94439e4e | 2705 | void |
a47b9029 | 2706 | parse_time_t(time_t * var) |
0ffd22bc | 2707 | { |
f1dc9b30 | 2708 | parseTimeLine(var, T_SECOND_STR); |
0ffd22bc | 2709 | } |
2710 | ||
270b86af | 2711 | static void |
a47b9029 | 2712 | free_time_t(time_t * var) |
270b86af | 2713 | { |
a47b9029 | 2714 | *var = 0; |
270b86af | 2715 | } |
9906e724 | 2716 | |
0477a072 | 2717 | #if UNUSED_CODE |
9906e724 | 2718 | static void |
a7d59104 | 2719 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 2720 | { |
f53b06f9 | 2721 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 2722 | } |
0477a072 | 2723 | #endif |
1b635117 | 2724 | |
2725 | static void | |
a7d59104 | 2726 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 2727 | { |
f53b06f9 | 2728 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 2729 | } |
2730 | ||
3e62bd58 | 2731 | #if UNUSED_CODE |
9906e724 | 2732 | static void |
a7d59104 | 2733 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 2734 | { |
f53b06f9 | 2735 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 2736 | } |
3e62bd58 | 2737 | #endif |
9906e724 | 2738 | |
47f6e231 | 2739 | static void |
2740 | dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
2741 | { | |
2742 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR); | |
2743 | } | |
2744 | ||
2745 | static void | |
2746 | dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
2747 | { | |
2748 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR); | |
2749 | } | |
2750 | ||
0477a072 | 2751 | #if UNUSED_CODE |
9906e724 | 2752 | static void |
a47b9029 | 2753 | parse_size_t(size_t * var) |
1b635117 | 2754 | { |
1b635117 | 2755 | int i; |
0e4e0e7d | 2756 | i = GetInteger(); |
1b635117 | 2757 | *var = (size_t) i; |
2758 | } | |
0477a072 | 2759 | #endif |
1b635117 | 2760 | |
2761 | static void | |
2762 | parse_b_size_t(size_t * var) | |
9906e724 | 2763 | { |
2764 | parseBytesLine(var, B_BYTES_STR); | |
2765 | } | |
2766 | ||
3e62bd58 | 2767 | #if UNUSED_CODE |
9906e724 | 2768 | static void |
a47b9029 | 2769 | parse_kb_size_t(size_t * var) |
9906e724 | 2770 | { |
2771 | parseBytesLine(var, B_KBYTES_STR); | |
2772 | } | |
3e62bd58 | 2773 | #endif |
9906e724 | 2774 | |
47f6e231 | 2775 | static void |
2776 | parse_b_int64_t(int64_t * var) | |
2777 | { | |
2778 | parseBytesLine64(var, B_BYTES_STR); | |
2779 | } | |
2780 | ||
2781 | static void | |
2782 | parse_kb_int64_t(int64_t * var) | |
2783 | { | |
2784 | parseBytesLine64(var, B_KBYTES_STR); | |
2785 | } | |
2786 | ||
9906e724 | 2787 | static void |
a47b9029 | 2788 | free_size_t(size_t * var) |
9906e724 | 2789 | { |
a47b9029 | 2790 | *var = 0; |
9906e724 | 2791 | } |
2792 | ||
47f6e231 | 2793 | static void |
2794 | free_b_int64_t(int64_t * var) | |
2795 | { | |
2796 | *var = 0; | |
2797 | } | |
2798 | ||
1b635117 | 2799 | #define free_b_size_t free_size_t |
9906e724 | 2800 | #define free_kb_size_t free_size_t |
2801 | #define free_mb_size_t free_size_t | |
2802 | #define free_gb_size_t free_size_t | |
47f6e231 | 2803 | #define free_kb_int64_t free_b_int64_t |
090089c4 | 2804 | |
8203a132 | 2805 | static void |
a7d59104 | 2806 | dump_ushort(StoreEntry * entry, const char *name, u_short var) |
090089c4 | 2807 | { |
f53b06f9 | 2808 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2809 | } |
090089c4 | 2810 | |
0153d498 | 2811 | static void |
a47b9029 | 2812 | free_ushort(u_short * u) |
0153d498 | 2813 | { |
2814 | *u = 0; | |
2815 | } | |
2816 | ||
270b86af | 2817 | static void |
2818 | parse_ushort(u_short * var) | |
b67e2c8c | 2819 | { |
2820 | ConfigParser::ParseUShort(var); | |
2821 | } | |
2822 | ||
2823 | void | |
2824 | ConfigParser::ParseUShort(u_short *var) | |
270b86af | 2825 | { |
0e656b69 | 2826 | *var = GetShort(); |
090089c4 | 2827 | } |
2828 | ||
3a69ddf3 | 2829 | void |
2830 | ConfigParser::ParseBool(bool *var) | |
2831 | { | |
2832 | int i = GetInteger(); | |
2833 | ||
2834 | if (0 == i) | |
2835 | *var = false; | |
2836 | else if (1 == i) | |
2837 | *var = true; | |
2838 | else | |
2839 | self_destruct(); | |
2840 | } | |
2841 | ||
270b86af | 2842 | static void |
a7d59104 | 2843 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 2844 | { |
270b86af | 2845 | while (list != NULL) { |
62e76326 | 2846 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
2847 | list = list->next; | |
429fdbec | 2848 | } |
429fdbec | 2849 | } |
2850 | ||
3a69ddf3 | 2851 | void |
2852 | ConfigParser::ParseWordList(wordlist ** list) | |
2853 | { | |
2854 | parse_wordlist(list); | |
2855 | } | |
2856 | ||
94439e4e | 2857 | void |
270b86af | 2858 | parse_wordlist(wordlist ** list) |
429fdbec | 2859 | { |
270b86af | 2860 | char *token; |
a3c6890f | 2861 | char *t = strtok(NULL, ""); |
62e76326 | 2862 | |
a3c6890f | 2863 | while ((token = strwordtok(NULL, &t))) |
62e76326 | 2864 | wordlistAdd(list, token); |
429fdbec | 2865 | } |
270b86af | 2866 | |
b3d8a9e8 | 2867 | #if 0 /* now unused */ |
f8d9f54a | 2868 | static int |
5da06f20 | 2869 | check_null_wordlist(wordlist * w) |
f8d9f54a | 2870 | { |
2871 | return w == NULL; | |
2872 | } | |
b3d8a9e8 | 2873 | #endif |
f8d9f54a | 2874 | |
63e9d884 | 2875 | static int |
c6d5b87b | 2876 | check_null_acl_access(acl_access * a) |
63e9d884 | 2877 | { |
2878 | return a == NULL; | |
2879 | } | |
2880 | ||
0153d498 | 2881 | #define free_wordlist wordlistDestroy |
270b86af | 2882 | |
d548ee64 | 2883 | #define free_uri_whitespace free_int |
2884 | ||
2885 | static void | |
2886 | parse_uri_whitespace(int *var) | |
2887 | { | |
2888 | char *token = strtok(NULL, w_space); | |
62e76326 | 2889 | |
d548ee64 | 2890 | if (token == NULL) |
62e76326 | 2891 | self_destruct(); |
2892 | ||
7e3ce7b9 | 2893 | if (!strcasecmp(token, "strip")) |
62e76326 | 2894 | *var = URI_WHITESPACE_STRIP; |
7e3ce7b9 | 2895 | else if (!strcasecmp(token, "deny")) |
62e76326 | 2896 | *var = URI_WHITESPACE_DENY; |
d548ee64 | 2897 | else if (!strcasecmp(token, "allow")) |
62e76326 | 2898 | *var = URI_WHITESPACE_ALLOW; |
d548ee64 | 2899 | else if (!strcasecmp(token, "encode")) |
62e76326 | 2900 | *var = URI_WHITESPACE_ENCODE; |
d548ee64 | 2901 | else if (!strcasecmp(token, "chop")) |
62e76326 | 2902 | *var = URI_WHITESPACE_CHOP; |
d548ee64 | 2903 | else |
62e76326 | 2904 | self_destruct(); |
d548ee64 | 2905 | } |
2906 | ||
d548ee64 | 2907 | static void |
2908 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
2909 | { | |
c193c972 | 2910 | const char *s; |
62e76326 | 2911 | |
d548ee64 | 2912 | if (var == URI_WHITESPACE_ALLOW) |
62e76326 | 2913 | s = "allow"; |
d548ee64 | 2914 | else if (var == URI_WHITESPACE_ENCODE) |
62e76326 | 2915 | s = "encode"; |
d548ee64 | 2916 | else if (var == URI_WHITESPACE_CHOP) |
62e76326 | 2917 | s = "chop"; |
7e3ce7b9 | 2918 | else if (var == URI_WHITESPACE_DENY) |
62e76326 | 2919 | s = "deny"; |
7e3ce7b9 | 2920 | else |
62e76326 | 2921 | s = "strip"; |
2922 | ||
d548ee64 | 2923 | storeAppendPrintf(entry, "%s %s\n", name, s); |
2924 | } | |
2925 | ||
6a566b9c | 2926 | static void |
c1dd71ae | 2927 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 2928 | { |
2929 | if (!*settings) | |
62e76326 | 2930 | return; |
2931 | ||
6a566b9c | 2932 | free_string(&(*settings)->type); |
62e76326 | 2933 | |
6a566b9c | 2934 | free_wordlist(&(*settings)->args); |
62e76326 | 2935 | |
c8f4eac4 | 2936 | delete *settings; |
62e76326 | 2937 | |
6a566b9c | 2938 | *settings = NULL; |
2939 | } | |
2940 | ||
2941 | static void | |
c1dd71ae | 2942 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 2943 | { |
2944 | if (*settings) | |
62e76326 | 2945 | free_removalpolicy(settings); |
2946 | ||
c8f4eac4 | 2947 | *settings = new RemovalPolicySettings; |
62e76326 | 2948 | |
6a566b9c | 2949 | parse_string(&(*settings)->type); |
62e76326 | 2950 | |
6a566b9c | 2951 | parse_wordlist(&(*settings)->args); |
2952 | } | |
2953 | ||
2954 | static void | |
c1dd71ae | 2955 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 2956 | { |
2957 | wordlist *args; | |
2958 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
2959 | args = settings->args; | |
62e76326 | 2960 | |
6a566b9c | 2961 | while (args) { |
62e76326 | 2962 | storeAppendPrintf(entry, " %s", args->key); |
2963 | args = args->next; | |
6a566b9c | 2964 | } |
62e76326 | 2965 | |
be58afb5 | 2966 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 2967 | } |
c1dd71ae | 2968 | |
ea21d497 HN |
2969 | static void |
2970 | free_memcachemode(SquidConfig * config) | |
2971 | { | |
2972 | return; | |
2973 | } | |
2974 | ||
2975 | static void | |
2976 | parse_memcachemode(SquidConfig * config) | |
2977 | { | |
2978 | char *token = strtok(NULL, w_space); | |
2979 | if (!token) | |
e1381638 | 2980 | self_destruct(); |
ea21d497 | 2981 | |
10aeba1d | 2982 | if (strcmp(token, "always") == 0) { |
e1381638 AJ |
2983 | Config.onoff.memory_cache_first = 1; |
2984 | Config.onoff.memory_cache_disk = 1; | |
10aeba1d | 2985 | } else if (strcmp(token, "disk") == 0) { |
e1381638 AJ |
2986 | Config.onoff.memory_cache_first = 0; |
2987 | Config.onoff.memory_cache_disk = 1; | |
ea21d497 | 2988 | } else if (strncmp(token, "net", 3) == 0) { |
e1381638 AJ |
2989 | Config.onoff.memory_cache_first = 1; |
2990 | Config.onoff.memory_cache_disk = 0; | |
10aeba1d | 2991 | } else if (strcmp(token, "never") == 0) { |
e1381638 AJ |
2992 | Config.onoff.memory_cache_first = 0; |
2993 | Config.onoff.memory_cache_disk = 0; | |
ea21d497 | 2994 | } else |
e1381638 | 2995 | self_destruct(); |
ea21d497 HN |
2996 | } |
2997 | ||
2998 | static void | |
2999 | dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config) | |
3000 | { | |
3001 | storeAppendPrintf(entry, "%s ", name); | |
3002 | if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) | |
e1381638 | 3003 | storeAppendPrintf(entry, "always"); |
ea21d497 | 3004 | else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) |
e1381638 | 3005 | storeAppendPrintf(entry, "disk"); |
ea21d497 | 3006 | else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3007 | storeAppendPrintf(entry, "network"); |
ea21d497 | 3008 | else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3009 | storeAppendPrintf(entry, "none"); |
ea21d497 HN |
3010 | storeAppendPrintf(entry, "\n"); |
3011 | } | |
3012 | ||
cca8ba0d | 3013 | #include "cf_parser.cci" |
f1dc9b30 | 3014 | |
3015 | peer_t | |
3016 | parseNeighborType(const char *s) | |
3017 | { | |
3018 | if (!strcasecmp(s, "parent")) | |
62e76326 | 3019 | return PEER_PARENT; |
3020 | ||
f1dc9b30 | 3021 | if (!strcasecmp(s, "neighbor")) |
62e76326 | 3022 | return PEER_SIBLING; |
3023 | ||
f1dc9b30 | 3024 | if (!strcasecmp(s, "neighbour")) |
62e76326 | 3025 | return PEER_SIBLING; |
3026 | ||
f1dc9b30 | 3027 | if (!strcasecmp(s, "sibling")) |
62e76326 | 3028 | return PEER_SIBLING; |
3029 | ||
f1dc9b30 | 3030 | if (!strcasecmp(s, "multicast")) |
62e76326 | 3031 | return PEER_MULTICAST; |
3032 | ||
bf8fe701 | 3033 | debugs(15, 0, "WARNING: Unknown neighbor type: " << s); |
62e76326 | 3034 | |
f1dc9b30 | 3035 | return PEER_SIBLING; |
3036 | } | |
f150dd4b | 3037 | |
0b0cfcf2 | 3038 | #if USE_WCCPv2 |
52f772de | 3039 | static void |
b7ac5457 | 3040 | parse_IpAddress_list(Ip::Address_list ** head) |
52f772de | 3041 | { |
3042 | char *token; | |
b7ac5457 AJ |
3043 | Ip::Address_list *s; |
3044 | Ip::Address ipa; | |
62e76326 | 3045 | |
52f772de | 3046 | while ((token = strtok(NULL, w_space))) { |
82b7abe3 AJ |
3047 | if (GetHostWithPort(token, &ipa)) { |
3048 | ||
3049 | while (*head) | |
3050 | head = &(*head)->next; | |
3051 | ||
b7ac5457 | 3052 | s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s))); |
82b7abe3 AJ |
3053 | s->s = ipa; |
3054 | ||
3055 | *head = s; | |
9d65168e | 3056 | } else |
82b7abe3 | 3057 | self_destruct(); |
7e3ce7b9 | 3058 | } |
3059 | } | |
3060 | ||
3061 | static void | |
b7ac5457 | 3062 | dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s) |
7e3ce7b9 | 3063 | { |
cc192b50 | 3064 | char ntoabuf[MAX_IPSTRLEN]; |
3065 | ||
7e3ce7b9 | 3066 | while (s) { |
cc192b50 | 3067 | storeAppendPrintf(e, "%s %s\n", |
62e76326 | 3068 | n, |
cc192b50 | 3069 | s->s.NtoA(ntoabuf,MAX_IPSTRLEN)); |
62e76326 | 3070 | s = s->next; |
7e3ce7b9 | 3071 | } |
3072 | } | |
3073 | ||
3074 | static void | |
b7ac5457 | 3075 | free_IpAddress_list(Ip::Address_list ** head) |
7e3ce7b9 | 3076 | { |
26ac0430 AJ |
3077 | if (*head) delete *head; |
3078 | *head = NULL; | |
7e3ce7b9 | 3079 | } |
3080 | ||
0b0cfcf2 | 3081 | #if CURRENTLY_UNUSED |
3082 | /* This code was previously used by http_port. Left as it really should | |
3083 | * be used by icp_port and htcp_port | |
3084 | */ | |
7e3ce7b9 | 3085 | static int |
b7ac5457 | 3086 | check_null_IpAddress_list(const Ip::Address_list * s) |
7e3ce7b9 | 3087 | { |
3088 | return NULL == s; | |
3089 | } | |
62e76326 | 3090 | |
3f38a55e | 3091 | #endif /* CURRENTLY_UNUSED */ |
0b0cfcf2 | 3092 | #endif /* USE_WCCPv2 */ |
7e3ce7b9 | 3093 | |
154dc884 | 3094 | CBDATA_CLASS_INIT(http_port_list); |
3095 | ||
d193a436 | 3096 | static void |
3f38a55e | 3097 | parse_http_port_specification(http_port_list * s, char *token) |
d193a436 | 3098 | { |
3f38a55e | 3099 | char *host = NULL; |
3f38a55e | 3100 | unsigned short port = 0; |
cc192b50 | 3101 | char *t = NULL; |
3102 | char *junk = NULL; | |
62e76326 | 3103 | |
5529ca8a | 3104 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; |
13adaf1f | 3105 | s->name = xstrdup(token); |
d67acb4e | 3106 | s->connection_auth_disabled = false; |
5529ca8a | 3107 | |
cc192b50 | 3108 | if (*token == '[') { |
3109 | /* [ipv6]:port */ | |
26ac0430 AJ |
3110 | host = token + 1; |
3111 | t = strchr(host, ']'); | |
3112 | if (!t) { | |
cc192b50 | 3113 | debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token); |
26ac0430 | 3114 | self_destruct(); |
cc192b50 | 3115 | } |
26ac0430 AJ |
3116 | *t++ = '\0'; |
3117 | if (*t != ':') { | |
cc192b50 | 3118 | debugs(3, 0, "http(s)_port: missing Port in: " << token); |
26ac0430 | 3119 | self_destruct(); |
cc192b50 | 3120 | } |
055421ee AJ |
3121 | if (!Ip::EnableIpv6) { |
3122 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 is not available."); | |
26ac0430 AJ |
3123 | self_destruct(); |
3124 | } | |
055421ee AJ |
3125 | port = xatos(t + 1); |
3126 | } else if ((t = strchr(token, ':'))) { | |
3127 | /* host:port */ | |
3128 | /* ipv4:port */ | |
3129 | host = token; | |
3130 | *t = '\0'; | |
3131 | port = xatos(t + 1); | |
3132 | ||
3133 | } else if ((port = strtol(token, &junk, 10)), !*junk) { | |
3134 | /* port */ | |
3135 | debugs(3, 3, "http(s)_port: found Listen on Port: " << port); | |
3136 | } else { | |
3137 | debugs(3, 0, "http(s)_port: missing Port: " << token); | |
3138 | self_destruct(); | |
3139 | } | |
62e76326 | 3140 | |
cc192b50 | 3141 | if (port == 0) { |
3142 | debugs(3, 0, "http(s)_port: Port cannot be 0: " << token); | |
0e656b69 | 3143 | self_destruct(); |
cc192b50 | 3144 | } |
0e656b69 | 3145 | |
cc192b50 | 3146 | if (NULL == host) { |
3147 | s->s.SetAnyAddr(); | |
3148 | s->s.SetPort(port); | |
6df7ad56 AJ |
3149 | if (!Ip::EnableIpv6) |
3150 | s->s.SetIPv4(); | |
7e07ced1 | 3151 | debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s->s.GetPort() ); |
26ac0430 | 3152 | } else if ( s->s = host ) { /* check/parse numeric IPA */ |
cc192b50 | 3153 | s->s.SetPort(port); |
6df7ad56 AJ |
3154 | if (!Ip::EnableIpv6) |
3155 | s->s.SetIPv4(); | |
cc192b50 | 3156 | debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host << " --> " << s->s); |
26ac0430 | 3157 | } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */ |
62e76326 | 3158 | /* dont use ipcache */ |
62e76326 | 3159 | s->defaultsite = xstrdup(host); |
cc192b50 | 3160 | s->s.SetPort(port); |
6df7ad56 AJ |
3161 | if (!Ip::EnableIpv6) |
3162 | s->s.SetIPv4(); | |
cc192b50 | 3163 | debugs(3, 3, "http(s)_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s); |
26ac0430 | 3164 | } else { |
cc192b50 | 3165 | debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host); |
62e76326 | 3166 | self_destruct(); |
cc192b50 | 3167 | } |
3f38a55e | 3168 | } |
3169 | ||
3170 | static void | |
3171 | parse_http_port_option(http_port_list * s, char *token) | |
3172 | { | |
c7b1dd5d AJ |
3173 | /* modes first */ |
3174 | ||
3175 | if (strcmp(token, "accel") == 0) { | |
3176 | if (s->intercepted || s->spoof_client_ip) { | |
3177 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes."); | |
3178 | self_destruct(); | |
3179 | } | |
3180 | s->accel = 1; | |
3181 | } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) { | |
3182 | if (s->accel || s->spoof_client_ip) { | |
3183 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes."); | |
3184 | self_destruct(); | |
3185 | } | |
3186 | s->intercepted = 1; | |
3187 | Ip::Interceptor.StartInterception(); | |
3188 | /* Log information regarding the port modes under interception. */ | |
3189 | debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s); | |
3190 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)"); | |
3191 | ||
c7b1dd5d | 3192 | /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */ |
055421ee AJ |
3193 | if (Ip::EnableIpv6) |
3194 | debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)"); | |
c7b1dd5d AJ |
3195 | if ( !s->s.SetIPv4() ) { |
3196 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s->s ); | |
3197 | self_destruct(); | |
3198 | } | |
c7b1dd5d AJ |
3199 | } else if (strcmp(token, "tproxy") == 0) { |
3200 | if (s->intercepted || s->accel) { | |
3201 | debugs(3,DBG_CRITICAL, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes."); | |
3202 | self_destruct(); | |
3203 | } | |
3204 | s->spoof_client_ip = 1; | |
3205 | Ip::Interceptor.StartTransparency(); | |
3206 | /* Log information regarding the port modes under transparency. */ | |
3207 | debugs(3, DBG_IMPORTANT, "Starting IP Spoofing on port " << s->s); | |
3208 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (IP spoofing enabled)"); | |
3209 | ||
3210 | if (!Ip::Interceptor.ProbeForTproxy(s->s)) { | |
3211 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: TPROXY support in the system does not work."); | |
3212 | self_destruct(); | |
3213 | } | |
3214 | ||
3215 | } else if (strncmp(token, "defaultsite=", 12) == 0) { | |
3216 | if (!s->accel) { | |
3217 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag."); | |
3218 | self_destruct(); | |
3219 | } | |
62e76326 | 3220 | safe_free(s->defaultsite); |
3221 | s->defaultsite = xstrdup(token + 12); | |
3f38a55e | 3222 | } else if (strcmp(token, "vhost") == 0) { |
c7b1dd5d AJ |
3223 | if (!s->accel) { |
3224 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vhost option requires Acceleration mode flag."); | |
3225 | self_destruct(); | |
3226 | } | |
62e76326 | 3227 | s->vhost = 1; |
3f38a55e | 3228 | } else if (strcmp(token, "vport") == 0) { |
c7b1dd5d AJ |
3229 | if (!s->accel) { |
3230 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3231 | self_destruct(); | |
3232 | } | |
62e76326 | 3233 | s->vport = -1; |
3f38a55e | 3234 | } else if (strncmp(token, "vport=", 6) == 0) { |
c7b1dd5d AJ |
3235 | if (!s->accel) { |
3236 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3237 | self_destruct(); | |
3238 | } | |
0e656b69 | 3239 | s->vport = xatos(token + 6); |
3f38a55e | 3240 | } else if (strncmp(token, "protocol=", 9) == 0) { |
c7b1dd5d AJ |
3241 | if (!s->accel) { |
3242 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag."); | |
3243 | self_destruct(); | |
3244 | } | |
62e76326 | 3245 | s->protocol = xstrdup(token + 9); |
7f7bdd96 | 3246 | } else if (strcmp(token, "allow-direct") == 0) { |
c7b1dd5d AJ |
3247 | if (!s->accel) { |
3248 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3249 | self_destruct(); | |
3250 | } | |
7f7bdd96 | 3251 | s->allow_direct = 1; |
432bc83c | 3252 | } else if (strcmp(token, "ignore-cc") == 0) { |
626096be | 3253 | #if !USE_HTTP_VIOLATIONS |
838daf3f | 3254 | if (!s->accel) { |
c7b1dd5d | 3255 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag."); |
838daf3f A |
3256 | self_destruct(); |
3257 | } | |
432bc83c | 3258 | #endif |
c7b1dd5d AJ |
3259 | s->ignore_cc = 1; |
3260 | } else if (strncmp(token, "name=", 5) == 0) { | |
3261 | safe_free(s->name); | |
3262 | s->name = xstrdup(token + 5); | |
d67acb4e AJ |
3263 | } else if (strcmp(token, "no-connection-auth") == 0) { |
3264 | s->connection_auth_disabled = true; | |
3265 | } else if (strcmp(token, "connection-auth=off") == 0) { | |
26ac0430 | 3266 | s->connection_auth_disabled = true; |
d67acb4e | 3267 | } else if (strcmp(token, "connection-auth") == 0) { |
26ac0430 | 3268 | s->connection_auth_disabled = false; |
d67acb4e | 3269 | } else if (strcmp(token, "connection-auth=on") == 0) { |
26ac0430 | 3270 | s->connection_auth_disabled = false; |
5529ca8a | 3271 | } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) { |
3272 | if (!strcasecmp(token + 23, "off")) | |
3273 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; | |
3274 | else if (!strcasecmp(token + 23, "transparent")) | |
3275 | s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT; | |
3276 | else if (!strcasecmp(token + 23, "always")) | |
3277 | s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS; | |
3278 | else | |
3279 | self_destruct(); | |
cc192b50 | 3280 | } else if (strcmp(token, "ipv4") == 0) { |
26ac0430 | 3281 | if ( !s->s.SetIPv4() ) { |
055421ee | 3282 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s ); |
cc192b50 | 3283 | self_destruct(); |
3284 | } | |
26ac0430 AJ |
3285 | } else if (strcmp(token, "tcpkeepalive") == 0) { |
3286 | s->tcp_keepalive.enabled = 1; | |
b2130d58 | 3287 | } else if (strncmp(token, "tcpkeepalive=", 13) == 0) { |
26ac0430 AJ |
3288 | char *t = token + 13; |
3289 | s->tcp_keepalive.enabled = 1; | |
3290 | s->tcp_keepalive.idle = atoi(t); | |
3291 | t = strchr(t, ','); | |
3292 | if (t) { | |
3293 | t++; | |
3294 | s->tcp_keepalive.interval = atoi(t); | |
3295 | t = strchr(t, ','); | |
3296 | } | |
3297 | if (t) { | |
3298 | t++; | |
3299 | s->tcp_keepalive.timeout = atoi(t); | |
3300 | t = strchr(t, ','); | |
3301 | } | |
154dc884 | 3302 | #if USE_SSL |
3a0c8eb5 AR |
3303 | } else if (strcasecmp(token, "sslBump") == 0) { |
3304 | debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " << | |
9945bf3f | 3305 | "in http_port. Use 'ssl-bump' instead."); |
3a0c8eb5 AR |
3306 | s->sslBump = 1; // accelerated when bumped, otherwise not |
3307 | } else if (strcmp(token, "ssl-bump") == 0) { | |
c7b1dd5d | 3308 | s->sslBump = 1; // accelerated when bumped, otherwise not |
154dc884 | 3309 | } else if (strncmp(token, "cert=", 5) == 0) { |
3310 | safe_free(s->cert); | |
3311 | s->cert = xstrdup(token + 5); | |
3312 | } else if (strncmp(token, "key=", 4) == 0) { | |
3313 | safe_free(s->key); | |
3314 | s->key = xstrdup(token + 4); | |
3315 | } else if (strncmp(token, "version=", 8) == 0) { | |
3316 | s->version = xatoi(token + 8); | |
154dc884 | 3317 | if (s->version < 1 || s->version > 4) |
3318 | self_destruct(); | |
3319 | } else if (strncmp(token, "options=", 8) == 0) { | |
3320 | safe_free(s->options); | |
3321 | s->options = xstrdup(token + 8); | |
3322 | } else if (strncmp(token, "cipher=", 7) == 0) { | |
3323 | safe_free(s->cipher); | |
3324 | s->cipher = xstrdup(token + 7); | |
3325 | } else if (strncmp(token, "clientca=", 9) == 0) { | |
3326 | safe_free(s->clientca); | |
3327 | s->clientca = xstrdup(token + 9); | |
3328 | } else if (strncmp(token, "cafile=", 7) == 0) { | |
3329 | safe_free(s->cafile); | |
3330 | s->cafile = xstrdup(token + 7); | |
3331 | } else if (strncmp(token, "capath=", 7) == 0) { | |
3332 | safe_free(s->capath); | |
3333 | s->capath = xstrdup(token + 7); | |
3334 | } else if (strncmp(token, "crlfile=", 8) == 0) { | |
3335 | safe_free(s->crlfile); | |
3336 | s->crlfile = xstrdup(token + 8); | |
3337 | } else if (strncmp(token, "dhparams=", 9) == 0) { | |
3338 | safe_free(s->dhfile); | |
3339 | s->dhfile = xstrdup(token + 9); | |
3340 | } else if (strncmp(token, "sslflags=", 9) == 0) { | |
3341 | safe_free(s->sslflags); | |
3342 | s->sslflags = xstrdup(token + 9); | |
3343 | } else if (strncmp(token, "sslcontext=", 11) == 0) { | |
3344 | safe_free(s->sslcontext); | |
3345 | s->sslcontext = xstrdup(token + 11); | |
154dc884 | 3346 | #endif |
3f38a55e | 3347 | } else { |
62e76326 | 3348 | self_destruct(); |
3f38a55e | 3349 | } |
3350 | } | |
3351 | ||
3f38a55e | 3352 | static http_port_list * |
3353 | create_http_port(char *portspec) | |
3354 | { | |
154dc884 | 3355 | http_port_list *s = new http_port_list("http"); |
3f38a55e | 3356 | parse_http_port_specification(s, portspec); |
3357 | return s; | |
3358 | } | |
3359 | ||
3360 | void | |
3361 | add_http_port(char *portspec) | |
3362 | { | |
3363 | http_port_list *s = create_http_port(portspec); | |
7e07ced1 AJ |
3364 | // we may need to merge better of the above returns a list with clones |
3365 | assert(s->next == NULL); | |
3f38a55e | 3366 | s->next = Config.Sockaddr.http; |
3367 | Config.Sockaddr.http = s; | |
3368 | } | |
3369 | ||
7e07ced1 AJ |
3370 | http_port_list * |
3371 | clone_http_port_list(http_port_list *a) | |
3372 | { | |
3373 | http_port_list *b = new http_port_list(a->protocol); | |
3374 | ||
3375 | b->s = a->s; | |
3376 | if (a->name) | |
3377 | b->name = xstrdup(a->name); | |
3378 | if (a->defaultsite) | |
3379 | b->defaultsite = xstrdup(a->defaultsite); | |
3380 | ||
3381 | b->intercepted = a->intercepted; | |
3382 | b->spoof_client_ip = a->spoof_client_ip; | |
3383 | b->accel = a->accel; | |
3384 | b->allow_direct = a->allow_direct; | |
3385 | b->vhost = a->vhost; | |
3386 | b->sslBump = a->sslBump; | |
3387 | b->vport = a->vport; | |
3388 | b->connection_auth_disabled = a->connection_auth_disabled; | |
3389 | b->disable_pmtu_discovery = a->disable_pmtu_discovery; | |
3390 | ||
3391 | memcpy( &(b->tcp_keepalive), &(a->tcp_keepalive), sizeof(a->tcp_keepalive)); | |
3392 | ||
3393 | #if 0 | |
3394 | // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings | |
3395 | ||
3396 | #if USE_SSL | |
3397 | // XXX: temporary hack to ease move of SSL options to http_port | |
3398 | http_port_list &http; | |
3399 | ||
3400 | char *cert; | |
3401 | char *key; | |
3402 | int version; | |
3403 | char *cipher; | |
3404 | char *options; | |
3405 | char *clientca; | |
3406 | char *cafile; | |
3407 | char *capath; | |
3408 | char *crlfile; | |
3409 | char *dhfile; | |
3410 | char *sslflags; | |
3411 | char *sslcontext; | |
3412 | SSL_CTX *sslContext; | |
3413 | #endif | |
3414 | ||
3415 | #endif /*0*/ | |
3416 | ||
3417 | return b; | |
3418 | } | |
7e07ced1 | 3419 | |
3f38a55e | 3420 | static void |
3421 | parse_http_port_list(http_port_list ** head) | |
3422 | { | |
3423 | char *token = strtok(NULL, w_space); | |
62e76326 | 3424 | |
9eeb8e4b | 3425 | if (!token) { |
62e76326 | 3426 | self_destruct(); |
9eeb8e4b | 3427 | return; |
3428 | } | |
62e76326 | 3429 | |
3f38a55e | 3430 | http_port_list *s = create_http_port(token); |
62e76326 | 3431 | |
3f38a55e | 3432 | /* parse options ... */ |
3433 | while ((token = strtok(NULL, w_space))) { | |
62e76326 | 3434 | parse_http_port_option(s, token); |
3f38a55e | 3435 | } |
62e76326 | 3436 | |
055421ee | 3437 | if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.IsAnyAddr()) { |
7e07ced1 AJ |
3438 | // clone the port options from *s to *(s->next) |
3439 | s->next = clone_http_port_list(s); | |
3440 | s->next->s.SetIPv4(); | |
3441 | debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); | |
3442 | } | |
7e07ced1 | 3443 | |
3f38a55e | 3444 | while (*head) |
62e76326 | 3445 | head = &(*head)->next; |
3446 | ||
3f38a55e | 3447 | *head = s; |
3448 | } | |
3449 | ||
3450 | static void | |
3451 | dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s) | |
3452 | { | |
cc192b50 | 3453 | char buf[MAX_IPSTRLEN]; |
3454 | ||
3455 | storeAppendPrintf(e, "%s %s", | |
62e76326 | 3456 | n, |
cc192b50 | 3457 | s->s.ToURL(buf,MAX_IPSTRLEN)); |
62e76326 | 3458 | |
2ad20b4f AJ |
3459 | if (s->intercepted) |
3460 | storeAppendPrintf(e, " intercept"); | |
62e76326 | 3461 | |
c7b1dd5d AJ |
3462 | if (s->spoof_client_ip) |
3463 | storeAppendPrintf(e, " tproxy"); | |
3464 | ||
3465 | if (s->accel) | |
3466 | storeAppendPrintf(e, " accel"); | |
3467 | ||
3f38a55e | 3468 | if (s->vhost) |
62e76326 | 3469 | storeAppendPrintf(e, " vhost"); |
3470 | ||
3f38a55e | 3471 | if (s->vport) |
62e76326 | 3472 | storeAppendPrintf(e, " vport"); |
5529ca8a | 3473 | |
c7b1dd5d AJ |
3474 | if (s->defaultsite) |
3475 | storeAppendPrintf(e, " defaultsite=%s", s->defaultsite); | |
3476 | ||
d67acb4e AJ |
3477 | if (s->connection_auth_disabled) |
3478 | storeAppendPrintf(e, " connection-auth=off"); | |
3479 | else | |
3480 | storeAppendPrintf(e, " connection-auth=on"); | |
3481 | ||
5529ca8a | 3482 | if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) { |
3483 | const char *pmtu; | |
3484 | ||
3485 | if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS) | |
3486 | pmtu = "always"; | |
3487 | else | |
3488 | pmtu = "transparent"; | |
3489 | ||
3490 | storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu); | |
3491 | } | |
b2130d58 | 3492 | |
3493 | if (s->tcp_keepalive.enabled) { | |
26ac0430 | 3494 | if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) { |
68924b6d | 3495 | storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout); |
26ac0430 | 3496 | } else { |
68924b6d | 3497 | storeAppendPrintf(e, " tcpkeepalive"); |
26ac0430 | 3498 | } |
b2130d58 | 3499 | } |
154dc884 | 3500 | |
3501 | #if USE_SSL | |
c7b1dd5d AJ |
3502 | if (s->sslBump) |
3503 | storeAppendPrintf(e, " sslBump"); | |
3504 | ||
26ac0430 AJ |
3505 | if (s->cert) |
3506 | storeAppendPrintf(e, " cert=%s", s->cert); | |
154dc884 | 3507 | |
26ac0430 AJ |
3508 | if (s->key) |
3509 | storeAppendPrintf(e, " key=%s", s->key); | |
154dc884 | 3510 | |
26ac0430 AJ |
3511 | if (s->version) |
3512 | storeAppendPrintf(e, " version=%d", s->version); | |
154dc884 | 3513 | |
26ac0430 AJ |
3514 | if (s->options) |
3515 | storeAppendPrintf(e, " options=%s", s->options); | |
154dc884 | 3516 | |
26ac0430 AJ |
3517 | if (s->cipher) |
3518 | storeAppendPrintf(e, " cipher=%s", s->cipher); | |
154dc884 | 3519 | |
26ac0430 AJ |
3520 | if (s->cafile) |
3521 | storeAppendPrintf(e, " cafile=%s", s->cafile); | |
154dc884 | 3522 | |
26ac0430 AJ |
3523 | if (s->capath) |
3524 | storeAppendPrintf(e, " capath=%s", s->capath); | |
154dc884 | 3525 | |
26ac0430 AJ |
3526 | if (s->crlfile) |
3527 | storeAppendPrintf(e, " crlfile=%s", s->crlfile); | |
154dc884 | 3528 | |
26ac0430 AJ |
3529 | if (s->dhfile) |
3530 | storeAppendPrintf(e, " dhparams=%s", s->dhfile); | |
154dc884 | 3531 | |
26ac0430 AJ |
3532 | if (s->sslflags) |
3533 | storeAppendPrintf(e, " sslflags=%s", s->sslflags); | |
154dc884 | 3534 | |
26ac0430 AJ |
3535 | if (s->sslcontext) |
3536 | storeAppendPrintf(e, " sslcontext=%s", s->sslcontext); | |
154dc884 | 3537 | #endif |
3f38a55e | 3538 | } |
62e76326 | 3539 | |
3f38a55e | 3540 | static void |
3541 | dump_http_port_list(StoreEntry * e, const char *n, const http_port_list * s) | |
3542 | { | |
3543 | while (s) { | |
62e76326 | 3544 | dump_generic_http_port(e, n, s); |
3545 | storeAppendPrintf(e, "\n"); | |
3546 | s = s->next; | |
3f38a55e | 3547 | } |
3548 | } | |
3549 | ||
3550 | static void | |
3551 | free_http_port_list(http_port_list ** head) | |
3552 | { | |
3553 | http_port_list *s; | |
62e76326 | 3554 | |
3f38a55e | 3555 | while ((s = *head) != NULL) { |
62e76326 | 3556 | *head = s->next; |
154dc884 | 3557 | delete s; |
3f38a55e | 3558 | } |
3559 | } | |
3560 | ||
3f38a55e | 3561 | #if USE_SSL |
3f38a55e | 3562 | |
154dc884 | 3563 | // TODO: merge better with parse_http_port_list |
3f38a55e | 3564 | static void |
3565 | parse_https_port_list(https_port_list ** head) | |
3566 | { | |
3f38a55e | 3567 | char *token; |
3568 | https_port_list *s; | |
154dc884 | 3569 | |
3f38a55e | 3570 | token = strtok(NULL, w_space); |
62e76326 | 3571 | |
3f38a55e | 3572 | if (!token) |
62e76326 | 3573 | self_destruct(); |
3574 | ||
154dc884 | 3575 | s = new https_port_list; |
3f38a55e | 3576 | parse_http_port_specification(&s->http, token); |
62e76326 | 3577 | |
d193a436 | 3578 | /* parse options ... */ |
3579 | while ((token = strtok(NULL, w_space))) { | |
154dc884 | 3580 | parse_http_port_option(s, token); |
d193a436 | 3581 | } |
62e76326 | 3582 | |
8abf232c | 3583 | while (*head) { |
3584 | http_port_list ** headTmp = &(*head)->http.next; | |
3585 | head = (https_port_list **)headTmp; | |
3586 | } | |
62e76326 | 3587 | |
d193a436 | 3588 | *head = s; |
3589 | } | |
3590 | ||
3591 | static void | |
3592 | dump_https_port_list(StoreEntry * e, const char *n, const https_port_list * s) | |
3593 | { | |
154dc884 | 3594 | dump_http_port_list(e, n, s); |
d193a436 | 3595 | } |
3596 | ||
3597 | static void | |
3598 | free_https_port_list(https_port_list ** head) | |
3599 | { | |
154dc884 | 3600 | free_http_port_list((http_port_list**)head); |
d193a436 | 3601 | } |
3602 | ||
3603 | #if 0 | |
3604 | static int | |
3605 | check_null_https_port_list(const https_port_list * s) | |
3606 | { | |
3607 | return NULL == s; | |
3608 | } | |
62e76326 | 3609 | |
d193a436 | 3610 | #endif |
3611 | ||
3612 | #endif /* USE_SSL */ | |
3613 | ||
f150dd4b | 3614 | void |
3615 | configFreeMemory(void) | |
3616 | { | |
23ff6968 | 3617 | free_all(); |
f150dd4b | 3618 | } |
f0b19334 | 3619 | |
94439e4e | 3620 | void |
f0b19334 | 3621 | requirePathnameExists(const char *name, const char *path) |
3622 | { | |
62e76326 | 3623 | |
f0b19334 | 3624 | struct stat sb; |
08577e16 | 3625 | char pathbuf[BUFSIZ]; |
f0b19334 | 3626 | assert(path != NULL); |
62e76326 | 3627 | |
0b796acd | 3628 | if (Config.chroot_dir && (geteuid() == 0)) { |
62e76326 | 3629 | snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path); |
3630 | path = pathbuf; | |
08577e16 | 3631 | } |
62e76326 | 3632 | |
a572d8be | 3633 | if (stat(path, &sb) < 0) { |
3634 | if (opt_send_signal == -1 || opt_send_signal == SIGHUP) | |
3635 | fatalf("%s %s: %s", name, path, xstrerror()); | |
3636 | else | |
3637 | fprintf(stderr, "WARNING: %s %s: %s\n", name, path, xstrerror()); | |
3638 | } | |
f0b19334 | 3639 | } |
d860a1aa | 3640 | |
3641 | char * | |
3642 | strtokFile(void) | |
3643 | { | |
d295d770 | 3644 | return ConfigParser::strtokFile(); |
d860a1aa | 3645 | } |
7684c4b1 | 3646 | |
450e0c10 | 3647 | #include "AccessLogEntry.h" |
3648 | /* TODO: split out parsing somehow ...*/ | |
7684c4b1 | 3649 | static void |
3650 | parse_logformat(logformat ** logformat_definitions) | |
3651 | { | |
3652 | logformat *nlf; | |
3653 | char *name, *def; | |
3654 | ||
3655 | if ((name = strtok(NULL, w_space)) == NULL) | |
3656 | self_destruct(); | |
3657 | ||
9eeb8e4b | 3658 | if ((def = strtok(NULL, "\r\n")) == NULL) { |
7684c4b1 | 3659 | self_destruct(); |
9eeb8e4b | 3660 | return; |
3661 | } | |
7684c4b1 | 3662 | |
bf8fe701 | 3663 | debugs(3, 2, "Logformat for '" << name << "' is '" << def << "'"); |
7684c4b1 | 3664 | |
3665 | nlf = (logformat *)xcalloc(1, sizeof(logformat)); | |
3666 | ||
3667 | nlf->name = xstrdup(name); | |
3668 | ||
9eeb8e4b | 3669 | if (!accessLogParseLogFormat(&nlf->format, def)) { |
7684c4b1 | 3670 | self_destruct(); |
9eeb8e4b | 3671 | return; |
3672 | } | |
7684c4b1 | 3673 | |
3674 | nlf->next = *logformat_definitions; | |
3675 | ||
3676 | *logformat_definitions = nlf; | |
3677 | } | |
3678 | ||
3679 | static void | |
3680 | parse_access_log(customlog ** logs) | |
3681 | { | |
3682 | const char *filename, *logdef_name; | |
3683 | customlog *cl; | |
3684 | logformat *lf; | |
3685 | ||
3686 | cl = (customlog *)xcalloc(1, sizeof(*cl)); | |
3687 | ||
9eeb8e4b | 3688 | if ((filename = strtok(NULL, w_space)) == NULL) { |
7684c4b1 | 3689 | self_destruct(); |
9eeb8e4b | 3690 | return; |
3691 | } | |
7684c4b1 | 3692 | |
3693 | if (strcmp(filename, "none") == 0) { | |
3694 | cl->type = CLF_NONE; | |
3695 | goto done; | |
3696 | } | |
3697 | ||
3698 | if ((logdef_name = strtok(NULL, w_space)) == NULL) | |
3699 | logdef_name = "auto"; | |
3700 | ||
bf8fe701 | 3701 | debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'"); |
7684c4b1 | 3702 | |
3703 | cl->filename = xstrdup(filename); | |
3704 | ||
3705 | /* look for the definition pointer corresponding to this name */ | |
3706 | lf = Config.Log.logformats; | |
3707 | ||
3708 | while (lf != NULL) { | |
bf8fe701 | 3709 | debugs(3, 9, "Comparing against '" << lf->name << "'"); |
7684c4b1 | 3710 | |
3711 | if (strcmp(lf->name, logdef_name) == 0) | |
3712 | break; | |
3713 | ||
3714 | lf = lf->next; | |
3715 | } | |
3716 | ||
3717 | if (lf != NULL) { | |
3718 | cl->type = CLF_CUSTOM; | |
3719 | cl->logFormat = lf; | |
3720 | } else if (strcmp(logdef_name, "auto") == 0) { | |
3721 | cl->type = CLF_AUTO; | |
3722 | } else if (strcmp(logdef_name, "squid") == 0) { | |
3723 | cl->type = CLF_SQUID; | |
3724 | } else if (strcmp(logdef_name, "common") == 0) { | |
3725 | cl->type = CLF_COMMON; | |
3ff65596 AR |
3726 | #if ICAP_CLIENT |
3727 | } else if (strcmp(logdef_name, "icap_squid") == 0) { | |
3728 | cl->type = CLF_ICAP_SQUID; | |
3729 | #endif | |
7684c4b1 | 3730 | } else { |
bf8fe701 | 3731 | debugs(3, 0, "Log format '" << logdef_name << "' is not defined"); |
7684c4b1 | 3732 | self_destruct(); |
9eeb8e4b | 3733 | return; |
7684c4b1 | 3734 | } |
3735 | ||
3736 | done: | |
a9f20260 | 3737 | aclParseAclList(LegacyParser, &cl->aclList); |
7684c4b1 | 3738 | |
3739 | while (*logs) | |
3740 | logs = &(*logs)->next; | |
3741 | ||
3742 | *logs = cl; | |
3743 | } | |
3744 | ||
d64bef4c | 3745 | static int |
3746 | check_null_access_log(customlog *customlog_definitions) | |
3747 | { | |
3748 | return customlog_definitions == NULL; | |
3749 | } | |
3750 | ||
7684c4b1 | 3751 | static void |
3752 | dump_logformat(StoreEntry * entry, const char *name, logformat * definitions) | |
3753 | { | |
3754 | accessLogDumpLogFormat(entry, name, definitions); | |
3755 | } | |
3756 | ||
3757 | static void | |
3758 | dump_access_log(StoreEntry * entry, const char *name, customlog * logs) | |
3759 | { | |
3760 | customlog *log; | |
3761 | ||
3762 | for (log = logs; log; log = log->next) { | |
3763 | storeAppendPrintf(entry, "%s ", name); | |
3764 | ||
3765 | switch (log->type) { | |
3766 | ||
3767 | case CLF_CUSTOM: | |
3768 | storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name); | |
3769 | break; | |
3770 | ||
3771 | case CLF_NONE: | |
3772 | storeAppendPrintf(entry, "none"); | |
3773 | break; | |
3774 | ||
3775 | case CLF_SQUID: | |
3776 | storeAppendPrintf(entry, "%s squid", log->filename); | |
3777 | break; | |
3778 | ||
3779 | case CLF_COMMON: | |
3780 | storeAppendPrintf(entry, "%s squid", log->filename); | |
3781 | break; | |
3ff65596 AR |
3782 | #if ICAP_CLIENT |
3783 | case CLF_ICAP_SQUID: | |
3784 | storeAppendPrintf(entry, "%s icap_squid", log->filename); | |
3785 | break; | |
3786 | #endif | |
7684c4b1 | 3787 | case CLF_AUTO: |
3788 | ||
3789 | if (log->aclList) | |
3790 | storeAppendPrintf(entry, "%s auto", log->filename); | |
3791 | else | |
3792 | storeAppendPrintf(entry, "%s", log->filename); | |
3793 | ||
3794 | break; | |
3795 | ||
3796 | case CLF_UNKNOWN: | |
3797 | break; | |
3798 | } | |
3799 | ||
3800 | if (log->aclList) | |
3801 | dump_acl_list(entry, log->aclList); | |
3802 | ||
3803 | storeAppendPrintf(entry, "\n"); | |
3804 | } | |
3805 | } | |
3806 | ||
3807 | static void | |
3808 | free_logformat(logformat ** definitions) | |
3809 | { | |
3810 | while (*definitions) { | |
3811 | logformat *format = *definitions; | |
3812 | *definitions = format->next; | |
61831b4a | 3813 | safe_free(format->name); |
7684c4b1 | 3814 | accessLogFreeLogFormat(&format->format); |
3815 | xfree(format); | |
3816 | } | |
3817 | } | |
3818 | ||
3819 | static void | |
3820 | free_access_log(customlog ** definitions) | |
3821 | { | |
3822 | while (*definitions) { | |
3823 | customlog *log = *definitions; | |
3824 | *definitions = log->next; | |
3825 | ||
3826 | log->logFormat = NULL; | |
3827 | log->type = CLF_UNKNOWN; | |
3828 | ||
3829 | if (log->aclList) | |
3830 | aclDestroyAclList(&log->aclList); | |
3831 | ||
3832 | safe_free(log->filename); | |
3833 | ||
3834 | xfree(log); | |
3835 | } | |
3836 | } | |
3a69ddf3 | 3837 | |
62c7f90e AR |
3838 | #if USE_ADAPTATION |
3839 | ||
3840 | static void | |
3841 | parse_adaptation_service_set_type() | |
3842 | { | |
3843 | Adaptation::Config::ParseServiceSet(); | |
3844 | } | |
3845 | ||
a22e6cd3 AR |
3846 | static void |
3847 | parse_adaptation_service_chain_type() | |
3848 | { | |
3849 | Adaptation::Config::ParseServiceChain(); | |
3850 | } | |
3851 | ||
62c7f90e AR |
3852 | static void |
3853 | parse_adaptation_access_type() | |
3854 | { | |
3855 | Adaptation::Config::ParseAccess(LegacyParser); | |
3856 | } | |
3857 | ||
62c7f90e AR |
3858 | #endif /* USE_ADAPTATION */ |
3859 | ||
3860 | ||
3a69ddf3 | 3861 | #if ICAP_CLIENT |
3862 | ||
3863 | static void | |
26cc52cb | 3864 | parse_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 3865 | { |
462e63d3 | 3866 | cfg->parseService(); |
3a69ddf3 | 3867 | } |
3868 | ||
3869 | static void | |
26cc52cb | 3870 | free_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 3871 | { |
462e63d3 | 3872 | cfg->freeService(); |
3a69ddf3 | 3873 | } |
3874 | ||
3875 | static void | |
26cc52cb | 3876 | dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg) |
3a69ddf3 | 3877 | { |
462e63d3 | 3878 | cfg.dumpService(entry, name); |
3a69ddf3 | 3879 | } |
3880 | ||
3881 | static void | |
c939dc70 | 3882 | parse_icap_class_type() |
3a69ddf3 | 3883 | { |
62c7f90e | 3884 | debugs(93, 0, "WARNING: 'icap_class' is depricated. " << |
26ac0430 | 3885 | "Use 'adaptation_service_set' instead"); |
62c7f90e | 3886 | Adaptation::Config::ParseServiceSet(); |
3a69ddf3 | 3887 | } |
3888 | ||
3a69ddf3 | 3889 | static void |
c939dc70 | 3890 | parse_icap_access_type() |
3a69ddf3 | 3891 | { |
62c7f90e | 3892 | debugs(93, 0, "WARNING: 'icap_access' is depricated. " << |
26ac0430 | 3893 | "Use 'adaptation_access' instead"); |
21a26d31 | 3894 | Adaptation::Config::ParseAccess(LegacyParser); |
3a69ddf3 | 3895 | } |
3896 | ||
3a69ddf3 | 3897 | #endif |
21a26d31 AR |
3898 | |
3899 | ||
3900 | #if USE_ECAP | |
3901 | ||
3902 | static void | |
574b508c | 3903 | parse_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
3904 | { |
3905 | cfg->parseService(); | |
3906 | } | |
3907 | ||
3908 | static void | |
574b508c | 3909 | free_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
3910 | { |
3911 | cfg->freeService(); | |
3912 | } | |
3913 | ||
3914 | static void | |
574b508c | 3915 | dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg) |
21a26d31 AR |
3916 | { |
3917 | cfg.dumpService(entry, name); | |
3918 | } | |
3919 | ||
3920 | #endif /* USE_ECAP */ | |
8277060a CT |
3921 | |
3922 | #if ICAP_CLIENT | |
3923 | static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
3924 | { | |
3925 | char *token; | |
3926 | time_t d; | |
3927 | time_t m; | |
3928 | cfg->service_failure_limit = GetInteger(); | |
3929 | ||
3930 | if ((token = strtok(NULL, w_space)) == NULL) | |
3931 | return; | |
3932 | ||
3933 | if (strcmp(token,"in") != 0) { | |
3934 | debugs(3, 0, "expecting 'in' on'" << config_input_line << "'"); | |
3935 | self_destruct(); | |
3936 | } | |
3937 | ||
3938 | if ((token = strtok(NULL, w_space)) == NULL) { | |
3939 | self_destruct(); | |
3940 | } | |
3941 | ||
3942 | d = static_cast<time_t> (xatoi(token)); | |
a459e80a | 3943 | |
8277060a CT |
3944 | m = static_cast<time_t> (1); |
3945 | ||
3946 | if (0 == d) | |
3947 | (void) 0; | |
3948 | else if ((token = strtok(NULL, w_space)) == NULL) { | |
3949 | debugs(3, 0, "No time-units on '" << config_input_line << "'"); | |
3950 | self_destruct(); | |
a459e80a | 3951 | } else if ((m = parseTimeUnits(token)) == 0) |
8277060a CT |
3952 | self_destruct(); |
3953 | ||
3954 | cfg->oldest_service_failure = (m * d); | |
3955 | } | |
3956 | ||
3957 | static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg) | |
3958 | { | |
3959 | storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit); | |
3960 | if (cfg.oldest_service_failure > 0) { | |
3961 | storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure); | |
3962 | } | |
3963 | storeAppendPrintf(entry, "\n"); | |
3964 | } | |
3965 | ||
3966 | static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
3967 | { | |
3968 | cfg->oldest_service_failure = 0; | |
3969 | cfg->service_failure_limit = 0; | |
3970 | } | |
3971 | ||
3972 | #endif |