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