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