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