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