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