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