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