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