]>
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 | ||
32fd6d8a CT |
240 | static void parse_url_rewrite_timeout(SquidConfig *); |
241 | static void dump_url_rewrite_timeout(StoreEntry *, const char *, SquidConfig &); | |
242 | static void free_url_rewrite_timeout(SquidConfig *); | |
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) | |
478 | continue; /* Not a valid #line directive, may be a comment */ | |
479 | ||
e4755e29 | 480 | while (*file && xisspace((unsigned char) *file)) |
a38ec4b1 | 481 | ++file; |
62e76326 | 482 | |
483 | if (*file) { | |
484 | if (*file != '"') | |
485 | continue; /* Not a valid #line directive, may be a comment */ | |
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 { |
62e76326 | 646 | Config.Announce.period = 86400 * 365; /* one year */ |
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 | |
270b86af | 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 | ||
1090 | m = u; /* default to 'units' if none specified */ | |
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 | |
9906e724 | 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 | ||
1184 | m = u; /* default to 'units' if none specified */ | |
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 | } | |
6f58d7d7 | 1269 | } |
62e76326 | 1270 | |
6f58d7d7 AR |
1271 | static void |
1272 | dump_acl(StoreEntry * entry, const char *name, ACL * ae) | |
1273 | { | |
9ef28b60 | 1274 | while (ae != NULL) { |
bf8fe701 | 1275 | debugs(3, 3, "dump_acl: " << name << " " << ae->name); |
33810b1d | 1276 | storeAppendPrintf(entry, "%s %s %s %s ", |
62e76326 | 1277 | name, |
1278 | ae->name, | |
33810b1d CT |
1279 | ae->typeString(), |
1280 | ae->flags.flagsStr()); | |
dfad5100 | 1281 | dump_SBufList(entry, ae->dump()); |
62e76326 | 1282 | ae = ae->next; |
56b63fa1 | 1283 | } |
090089c4 | 1284 | } |
1285 | ||
8203a132 | 1286 | static void |
97427e90 | 1287 | parse_acl(ACL ** ae) |
090089c4 | 1288 | { |
a9f20260 | 1289 | ACL::ParseAclLine(LegacyParser, ae); |
f1dc9b30 | 1290 | } |
1291 | ||
1292 | static void | |
97427e90 | 1293 | free_acl(ACL ** ae) |
f1dc9b30 | 1294 | { |
9ef28b60 | 1295 | aclDestroyAcls(ae); |
090089c4 | 1296 | } |
1297 | ||
425de4c8 | 1298 | void |
76cd39d7 | 1299 | dump_acl_list(StoreEntry * entry, ACLList * head) |
30a4f2a8 | 1300 | { |
dfad5100 | 1301 | dump_SBufList(entry, head->dump()); |
d6827718 | 1302 | } |
1303 | ||
b67e2c8c | 1304 | void |
d6827718 | 1305 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
1306 | { | |
dfad5100 | 1307 | if (head) |
fbe0f952 | 1308 | dump_SBufList(entry, head->treeDump(name,NULL)); |
30a4f2a8 | 1309 | } |
090089c4 | 1310 | |
8203a132 | 1311 | static void |
16300b58 | 1312 | parse_acl_access(acl_access ** head) |
090089c4 | 1313 | { |
6f58d7d7 AR |
1314 | aclParseAccessLine(cfg_directive, LegacyParser, head); |
1315 | } | |
1316 | ||
0153d498 | 1317 | static void |
16300b58 | 1318 | free_acl_access(acl_access ** head) |
0153d498 | 1319 | { |
a47b9029 | 1320 | aclDestroyAccessList(head); |
0153d498 | 1321 | } |
1322 | ||
8203a132 | 1323 | static void |
b7ac5457 | 1324 | dump_address(StoreEntry * entry, const char *name, Ip::Address &addr) |
270b86af | 1325 | { |
cc192b50 | 1326 | char buf[MAX_IPSTRLEN]; |
4dd643d5 | 1327 | storeAppendPrintf(entry, "%s %s\n", name, addr.toStr(buf,MAX_IPSTRLEN) ); |
270b86af | 1328 | } |
1329 | ||
1330 | static void | |
b7ac5457 | 1331 | parse_address(Ip::Address *addr) |
090089c4 | 1332 | { |
2eceb328 | 1333 | char *token = ConfigParser::NextToken(); |
270b86af | 1334 | |
9eeb8e4b | 1335 | if (!token) { |
62e76326 | 1336 | self_destruct(); |
9eeb8e4b | 1337 | return; |
1338 | } | |
62e76326 | 1339 | |
9f2665ee | 1340 | if (!strcmp(token,"any_addr")) |
4dd643d5 | 1341 | addr->setAnyAddr(); |
9f2665ee | 1342 | else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) ) |
4dd643d5 | 1343 | addr->setNoAddr(); |
9f2665ee | 1344 | else if ( (*addr = token) ) // try parse numeric/IPA |
26ac0430 | 1345 | (void) 0; |
36a83790 AJ |
1346 | else if (addr->GetHostByName(token)) // dont use ipcache |
1347 | (void) 0; | |
1348 | else { // not an IP and not a hostname | |
1349 | debugs(3, DBG_CRITICAL, "FATAL: invalid IP address or domain name '" << token << "'"); | |
1350 | self_destruct(); | |
1351 | } | |
090089c4 | 1352 | } |
1353 | ||
0153d498 | 1354 | static void |
b7ac5457 | 1355 | free_address(Ip::Address *addr) |
0153d498 | 1356 | { |
4dd643d5 | 1357 | addr->setEmpty(); |
0153d498 | 1358 | } |
1359 | ||
0dc8ffa5 | 1360 | CBDATA_TYPE(AclAddress); |
d6827718 | 1361 | |
1362 | static void | |
0dc8ffa5 | 1363 | dump_acl_address(StoreEntry * entry, const char *name, AclAddress * head) |
d6827718 | 1364 | { |
cc192b50 | 1365 | char buf[MAX_IPSTRLEN]; |
0dc8ffa5 | 1366 | AclAddress *l; |
62e76326 | 1367 | |
d6827718 | 1368 | for (l = head; l; l = l->next) { |
4dd643d5 AJ |
1369 | if (!l->addr.isAnyAddr()) |
1370 | storeAppendPrintf(entry, "%s %s", name, l->addr.toStr(buf,MAX_IPSTRLEN)); | |
62e76326 | 1371 | else |
1372 | storeAppendPrintf(entry, "%s autoselect", name); | |
1373 | ||
1374 | dump_acl_list(entry, l->aclList); | |
1375 | ||
1376 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1377 | } |
1378 | } | |
1379 | ||
1380 | static void | |
1381 | freed_acl_address(void *data) | |
1382 | { | |
0dc8ffa5 | 1383 | AclAddress *l = static_cast<AclAddress *>(data); |
29b8d8d6 | 1384 | aclDestroyAclList(&l->aclList); |
d6827718 | 1385 | } |
1386 | ||
1387 | static void | |
0dc8ffa5 | 1388 | parse_acl_address(AclAddress ** head) |
d6827718 | 1389 | { |
0dc8ffa5 FC |
1390 | AclAddress *l; |
1391 | AclAddress **tail = head; /* sane name below */ | |
1392 | CBDATA_INIT_TYPE_FREECB(AclAddress, freed_acl_address); | |
1393 | l = cbdataAlloc(AclAddress); | |
d6827718 | 1394 | parse_address(&l->addr); |
6f58d7d7 | 1395 | aclParseAclList(LegacyParser, &l->aclList, l->addr); |
62e76326 | 1396 | |
d6827718 | 1397 | while (*tail) |
62e76326 | 1398 | tail = &(*tail)->next; |
1399 | ||
d6827718 | 1400 | *tail = l; |
1401 | } | |
1402 | ||
1403 | static void | |
0dc8ffa5 | 1404 | free_acl_address(AclAddress ** head) |
d6827718 | 1405 | { |
1406 | while (*head) { | |
0dc8ffa5 | 1407 | AclAddress *l = *head; |
62e76326 | 1408 | *head = l->next; |
1409 | cbdataFree(l); | |
d6827718 | 1410 | } |
1411 | } | |
1412 | ||
1413 | CBDATA_TYPE(acl_tos); | |
1414 | ||
1415 | static void | |
1416 | dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head) | |
1417 | { | |
1418 | acl_tos *l; | |
62e76326 | 1419 | |
d6827718 | 1420 | for (l = head; l; l = l->next) { |
62e76326 | 1421 | if (l->tos > 0) |
1422 | storeAppendPrintf(entry, "%s 0x%02X", name, l->tos); | |
1423 | else | |
1424 | storeAppendPrintf(entry, "%s none", name); | |
1425 | ||
1426 | dump_acl_list(entry, l->aclList); | |
1427 | ||
1428 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1429 | } |
1430 | } | |
1431 | ||
1432 | static void | |
1433 | freed_acl_tos(void *data) | |
1434 | { | |
e6ccf245 | 1435 | acl_tos *l = static_cast<acl_tos *>(data); |
29b8d8d6 | 1436 | aclDestroyAclList(&l->aclList); |
d6827718 | 1437 | } |
1438 | ||
1439 | static void | |
1440 | parse_acl_tos(acl_tos ** head) | |
1441 | { | |
1442 | acl_tos *l; | |
1443 | acl_tos **tail = head; /* sane name below */ | |
425de4c8 | 1444 | unsigned int tos; /* Initially uint for strtoui. Casted to tos_t before return */ |
2eceb328 | 1445 | char *token = ConfigParser::NextToken(); |
62e76326 | 1446 | |
9eeb8e4b | 1447 | if (!token) { |
62e76326 | 1448 | self_destruct(); |
9eeb8e4b | 1449 | return; |
1450 | } | |
62e76326 | 1451 | |
425de4c8 | 1452 | if (!xstrtoui(token, NULL, &tos, 0, std::numeric_limits<tos_t>::max())) { |
62e76326 | 1453 | self_destruct(); |
9eeb8e4b | 1454 | return; |
1455 | } | |
62e76326 | 1456 | |
c6f168c1 CT |
1457 | const unsigned int chTos = tos & 0xFC; |
1458 | if (chTos != tos) { | |
1459 | debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: Tos value '" << tos << "' adjusted to '" << chTos << "'"); | |
1460 | tos = chTos; | |
1461 | } | |
1462 | ||
d6827718 | 1463 | CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos); |
62e76326 | 1464 | |
d6827718 | 1465 | l = cbdataAlloc(acl_tos); |
62e76326 | 1466 | |
425de4c8 | 1467 | l->tos = (tos_t)tos; |
62e76326 | 1468 | |
6f58d7d7 | 1469 | aclParseAclList(LegacyParser, &l->aclList, token); |
62e76326 | 1470 | |
d6827718 | 1471 | while (*tail) |
62e76326 | 1472 | tail = &(*tail)->next; |
1473 | ||
d6827718 | 1474 | *tail = l; |
1475 | } | |
1476 | ||
1477 | static void | |
1478 | free_acl_tos(acl_tos ** head) | |
1479 | { | |
1480 | while (*head) { | |
62e76326 | 1481 | acl_tos *l = *head; |
1482 | *head = l->next; | |
1483 | l->next = NULL; | |
1484 | cbdataFree(l); | |
d6827718 | 1485 | } |
1486 | } | |
1487 | ||
11e8cfe3 | 1488 | #if SO_MARK && USE_LIBCAP |
f4f6c2e0 | 1489 | |
425de4c8 AJ |
1490 | CBDATA_TYPE(acl_nfmark); |
1491 | ||
1492 | static void | |
1493 | dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head) | |
1494 | { | |
1495 | acl_nfmark *l; | |
1496 | ||
1497 | for (l = head; l; l = l->next) { | |
1498 | if (l->nfmark > 0) | |
1499 | storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark); | |
1500 | else | |
1501 | storeAppendPrintf(entry, "%s none", name); | |
1502 | ||
1503 | dump_acl_list(entry, l->aclList); | |
1504 | ||
1505 | storeAppendPrintf(entry, "\n"); | |
1506 | } | |
1507 | } | |
1508 | ||
1509 | static void | |
1510 | freed_acl_nfmark(void *data) | |
1511 | { | |
1512 | acl_nfmark *l = static_cast<acl_nfmark *>(data); | |
1513 | aclDestroyAclList(&l->aclList); | |
1514 | } | |
1515 | ||
1516 | static void | |
1517 | parse_acl_nfmark(acl_nfmark ** head) | |
1518 | { | |
1519 | acl_nfmark *l; | |
1520 | acl_nfmark **tail = head; /* sane name below */ | |
1521 | nfmark_t mark; | |
2eceb328 | 1522 | char *token = ConfigParser::NextToken(); |
425de4c8 AJ |
1523 | |
1524 | if (!token) { | |
1525 | self_destruct(); | |
1526 | return; | |
1527 | } | |
1528 | ||
1529 | if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) { | |
1530 | self_destruct(); | |
1531 | return; | |
1532 | } | |
1533 | ||
1534 | CBDATA_INIT_TYPE_FREECB(acl_nfmark, freed_acl_nfmark); | |
1535 | ||
1536 | l = cbdataAlloc(acl_nfmark); | |
1537 | ||
1538 | l->nfmark = mark; | |
1539 | ||
6f58d7d7 | 1540 | aclParseAclList(LegacyParser, &l->aclList, token); |
425de4c8 AJ |
1541 | |
1542 | while (*tail) | |
1543 | tail = &(*tail)->next; | |
1544 | ||
1545 | *tail = l; | |
1546 | } | |
1547 | ||
1548 | static void | |
1549 | free_acl_nfmark(acl_nfmark ** head) | |
1550 | { | |
1551 | while (*head) { | |
1552 | acl_nfmark *l = *head; | |
1553 | *head = l->next; | |
1554 | l->next = NULL; | |
1555 | cbdataFree(l); | |
1556 | } | |
1557 | } | |
f4f6c2e0 | 1558 | #endif /* SO_MARK */ |
425de4c8 | 1559 | |
1328cfb7 | 1560 | CBDATA_TYPE(AclSizeLimit); |
ef1955a5 | 1561 | |
1562 | static void | |
1328cfb7 | 1563 | dump_acl_b_size_t(StoreEntry * entry, const char *name, AclSizeLimit * head) |
ef1955a5 | 1564 | { |
1328cfb7 | 1565 | AclSizeLimit *l; |
ef1955a5 | 1566 | |
1567 | for (l = head; l; l = l->next) { | |
ed013b6c | 1568 | if (l->size != -1) |
ef1955a5 | 1569 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR); |
1570 | else | |
1571 | storeAppendPrintf(entry, "%s none", name); | |
1572 | ||
1573 | dump_acl_list(entry, l->aclList); | |
1574 | ||
1575 | storeAppendPrintf(entry, "\n"); | |
1576 | } | |
1577 | } | |
1578 | ||
1579 | static void | |
1580 | freed_acl_b_size_t(void *data) | |
1581 | { | |
1328cfb7 | 1582 | AclSizeLimit *l = static_cast<AclSizeLimit *>(data); |
ef1955a5 | 1583 | aclDestroyAclList(&l->aclList); |
1584 | } | |
1585 | ||
1586 | static void | |
1328cfb7 | 1587 | parse_acl_b_size_t(AclSizeLimit ** head) |
ef1955a5 | 1588 | { |
1328cfb7 FC |
1589 | AclSizeLimit *l; |
1590 | AclSizeLimit **tail = head; /* sane name below */ | |
ef1955a5 | 1591 | |
1328cfb7 | 1592 | CBDATA_INIT_TYPE_FREECB(AclSizeLimit, freed_acl_b_size_t); |
ef1955a5 | 1593 | |
1328cfb7 | 1594 | l = cbdataAlloc(AclSizeLimit); |
ef1955a5 | 1595 | |
47f6e231 | 1596 | parse_b_int64_t(&l->size); |
ef1955a5 | 1597 | |
6f58d7d7 | 1598 | aclParseAclList(LegacyParser, &l->aclList, l->size); |
ef1955a5 | 1599 | |
1600 | while (*tail) | |
1601 | tail = &(*tail)->next; | |
1602 | ||
1603 | *tail = l; | |
1604 | } | |
1605 | ||
1606 | static void | |
1328cfb7 | 1607 | free_acl_b_size_t(AclSizeLimit ** head) |
ef1955a5 | 1608 | { |
1609 | while (*head) { | |
1328cfb7 | 1610 | AclSizeLimit *l = *head; |
ef1955a5 | 1611 | *head = l->next; |
1612 | l->next = NULL; | |
1613 | cbdataFree(l); | |
1614 | } | |
1615 | } | |
1616 | ||
9a0a18de | 1617 | #if USE_DELAY_POOLS |
59715b38 | 1618 | |
b67e2c8c | 1619 | #include "DelayConfig.h" |
602d9612 | 1620 | #include "DelayPools.h" |
59715b38 | 1621 | /* do nothing - free_delay_pool_count is the magic free function. |
ae870270 | 1622 | * this is why delay_pool_count isn't just marked TYPE: u_short |
59715b38 | 1623 | */ |
1624 | #define free_delay_pool_class(X) | |
1625 | #define free_delay_pool_access(X) | |
1626 | #define free_delay_pool_rates(X) | |
1627 | #define dump_delay_pool_class(X, Y, Z) | |
1628 | #define dump_delay_pool_access(X, Y, Z) | |
1629 | #define dump_delay_pool_rates(X, Y, Z) | |
1630 | ||
1631 | static void | |
b67e2c8c | 1632 | free_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1633 | { |
b67e2c8c | 1634 | cfg->freePoolCount(); |
59715b38 | 1635 | } |
1636 | ||
1637 | static void | |
b67e2c8c | 1638 | dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg) |
59715b38 | 1639 | { |
b67e2c8c | 1640 | cfg.dumpPoolCount (entry, name); |
59715b38 | 1641 | } |
1642 | ||
1643 | static void | |
b67e2c8c | 1644 | parse_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1645 | { |
b67e2c8c | 1646 | cfg->parsePoolCount(); |
59715b38 | 1647 | } |
1648 | ||
1649 | static void | |
b67e2c8c | 1650 | parse_delay_pool_class(DelayConfig * cfg) |
59715b38 | 1651 | { |
b67e2c8c | 1652 | cfg->parsePoolClass(); |
59715b38 | 1653 | } |
1654 | ||
1655 | static void | |
b67e2c8c | 1656 | parse_delay_pool_rates(DelayConfig * cfg) |
59715b38 | 1657 | { |
b67e2c8c | 1658 | cfg->parsePoolRates(); |
59715b38 | 1659 | } |
1660 | ||
1661 | static void | |
b67e2c8c | 1662 | parse_delay_pool_access(DelayConfig * cfg) |
59715b38 | 1663 | { |
a9f20260 | 1664 | cfg->parsePoolAccess(LegacyParser); |
59715b38 | 1665 | } |
62e76326 | 1666 | |
59715b38 | 1667 | #endif |
1668 | ||
9a0a18de | 1669 | #if USE_DELAY_POOLS |
b4cd430a CT |
1670 | #include "ClientDelayConfig.h" |
1671 | /* do nothing - free_client_delay_pool_count is the magic free function. | |
ae870270 | 1672 | * this is why client_delay_pool_count isn't just marked TYPE: u_short |
b4cd430a CT |
1673 | */ |
1674 | ||
1675 | #define free_client_delay_pool_access(X) | |
1676 | #define free_client_delay_pool_rates(X) | |
1677 | #define dump_client_delay_pool_access(X, Y, Z) | |
1678 | #define dump_client_delay_pool_rates(X, Y, Z) | |
1679 | ||
1680 | static void | |
1681 | free_client_delay_pool_count(ClientDelayConfig * cfg) | |
1682 | { | |
1683 | cfg->freePoolCount(); | |
1684 | } | |
1685 | ||
1686 | static void | |
1687 | dump_client_delay_pool_count(StoreEntry * entry, const char *name, ClientDelayConfig &cfg) | |
1688 | { | |
1689 | cfg.dumpPoolCount (entry, name); | |
1690 | } | |
1691 | ||
1692 | static void | |
1693 | parse_client_delay_pool_count(ClientDelayConfig * cfg) | |
1694 | { | |
1695 | cfg->parsePoolCount(); | |
1696 | } | |
1697 | ||
1698 | static void | |
1699 | parse_client_delay_pool_rates(ClientDelayConfig * cfg) | |
1700 | { | |
1701 | cfg->parsePoolRates(); | |
1702 | } | |
1703 | ||
1704 | static void | |
1705 | parse_client_delay_pool_access(ClientDelayConfig * cfg) | |
1706 | { | |
1707 | cfg->parsePoolAccess(LegacyParser); | |
1708 | } | |
1709 | #endif | |
1710 | ||
626096be | 1711 | #if USE_HTTP_VIOLATIONS |
97474590 | 1712 | static void |
3b07476b | 1713 | dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers) |
e3dd531e | 1714 | { |
3b07476b CT |
1715 | if (manglers) |
1716 | manglers->dumpAccess(entry, name); | |
97474590 | 1717 | } |
e3dd531e | 1718 | |
97474590 | 1719 | static void |
3b07476b | 1720 | parse_http_header_access(HeaderManglers **pm) |
97474590 | 1721 | { |
97474590 | 1722 | char *t = NULL; |
62e76326 | 1723 | |
2eceb328 | 1724 | if ((t = ConfigParser::NextToken()) == NULL) { |
fa84c01d FC |
1725 | debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1726 | debugs(3, DBG_CRITICAL, "parse_http_header_access: missing header name."); | |
62e76326 | 1727 | return; |
97474590 | 1728 | } |
62e76326 | 1729 | |
3b07476b CT |
1730 | if (!*pm) |
1731 | *pm = new HeaderManglers; | |
1732 | HeaderManglers *manglers = *pm; | |
001d55dc | 1733 | headerMangler *mangler = manglers->track(t); |
3b07476b | 1734 | assert(mangler); |
6f58d7d7 AR |
1735 | |
1736 | std::string directive = "http_header_access "; | |
1737 | directive += t; | |
2450353f | 1738 | aclParseAccessLine(directive.c_str(), LegacyParser, &mangler->access_list); |
6bccf575 | 1739 | } |
1740 | ||
1741 | static void | |
3b07476b | 1742 | free_HeaderManglers(HeaderManglers **pm) |
6bccf575 | 1743 | { |
3b07476b CT |
1744 | // we delete the entire http_header_* mangler configuration at once |
1745 | if (const HeaderManglers *manglers = *pm) { | |
1746 | delete manglers; | |
1747 | *pm = NULL; | |
6bccf575 | 1748 | } |
1749 | } | |
1750 | ||
1751 | static void | |
3b07476b | 1752 | dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers) |
6bccf575 | 1753 | { |
3b07476b CT |
1754 | if (manglers) |
1755 | manglers->dumpReplacement(entry, name); | |
97474590 | 1756 | } |
e3dd531e | 1757 | |
97474590 | 1758 | static void |
3b07476b | 1759 | parse_http_header_replace(HeaderManglers **pm) |
e3dd531e | 1760 | { |
6bccf575 | 1761 | char *t = NULL; |
62e76326 | 1762 | |
2eceb328 | 1763 | if ((t = ConfigParser::NextToken()) == NULL) { |
fa84c01d FC |
1764 | debugs(3, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1765 | debugs(3, DBG_CRITICAL, "parse_http_header_replace: missing header name."); | |
62e76326 | 1766 | return; |
6bccf575 | 1767 | } |
62e76326 | 1768 | |
bde7a8ce | 1769 | const char *value = ConfigParser::NextQuotedOrToEol(); |
62e76326 | 1770 | |
3b07476b CT |
1771 | if (!*pm) |
1772 | *pm = new HeaderManglers; | |
1773 | HeaderManglers *manglers = *pm; | |
1774 | manglers->setReplacement(t, value); | |
97474590 | 1775 | } |
62e76326 | 1776 | |
9e8b2f1c | 1777 | #endif |
97474590 | 1778 | |
e90100aa | 1779 | static void |
e1f7507e | 1780 | dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap) |
e90100aa | 1781 | { |
f53b06f9 | 1782 | SwapDir *s; |
1783 | int i; | |
d3b3ab85 | 1784 | assert (entry); |
62e76326 | 1785 | |
a38ec4b1 | 1786 | for (i = 0; i < swap.n_configured; ++i) { |
c8f4eac4 | 1787 | s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw()); |
26ac0430 | 1788 | if (!s) continue; |
59b2d47f | 1789 | storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path); |
62e76326 | 1790 | s->dump(*entry); |
62e76326 | 1791 | storeAppendPrintf(entry, "\n"); |
f53b06f9 | 1792 | } |
1793 | } | |
1794 | ||
53ad48e6 | 1795 | static int |
1796 | check_null_string(char *s) | |
1797 | { | |
1798 | return s == NULL; | |
1799 | } | |
1800 | ||
2f1431ea | 1801 | #if USE_AUTH |
94439e4e | 1802 | static void |
9f3d2b2e | 1803 | parse_authparam(Auth::ConfigVector * config) |
94439e4e | 1804 | { |
1805 | char *type_str; | |
1806 | char *param_str; | |
94439e4e | 1807 | |
2eceb328 | 1808 | if ((type_str = ConfigParser::NextToken()) == NULL) |
62e76326 | 1809 | self_destruct(); |
94439e4e | 1810 | |
2eceb328 | 1811 | if ((param_str = ConfigParser::NextToken()) == NULL) |
62e76326 | 1812 | self_destruct(); |
94439e4e | 1813 | |
5817ee13 | 1814 | /* find a configuration for the scheme in the currently parsed configs... */ |
9f3d2b2e | 1815 | Auth::Config *schemeCfg = Auth::Config::Find(type_str); |
62e76326 | 1816 | |
5817ee13 AJ |
1817 | if (schemeCfg == NULL) { |
1818 | /* Create a configuration based on the scheme info */ | |
c6cf8dee | 1819 | Auth::Scheme::Pointer theScheme = Auth::Scheme::Find(type_str); |
f5691f9c | 1820 | |
5817ee13 AJ |
1821 | if (theScheme == NULL) { |
1822 | debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'."); | |
1823 | self_destruct(); | |
62e76326 | 1824 | } |
94439e4e | 1825 | |
f5691f9c | 1826 | config->push_back(theScheme->createConfig()); |
9f3d2b2e | 1827 | schemeCfg = Auth::Config::Find(type_str); |
5817ee13 AJ |
1828 | if (schemeCfg == NULL) { |
1829 | debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'."); | |
1830 | self_destruct(); | |
1831 | } | |
94439e4e | 1832 | } |
62e76326 | 1833 | |
5817ee13 | 1834 | schemeCfg->parse(schemeCfg, config->size(), param_str); |
94439e4e | 1835 | } |
1836 | ||
1837 | static void | |
9f3d2b2e | 1838 | free_authparam(Auth::ConfigVector * cfg) |
94439e4e | 1839 | { |
5817ee13 | 1840 | /* Wipe the Auth globals and Detach/Destruct component config + state. */ |
c33a88ca | 1841 | cfg->clear(); |
5817ee13 AJ |
1842 | |
1843 | /* on reconfigure initialize new auth schemes for the new config. */ | |
ec5858ff | 1844 | if (reconfiguring) { |
ccd8a22a | 1845 | Auth::Init(); |
94439e4e | 1846 | } |
94439e4e | 1847 | } |
1848 | ||
1849 | static void | |
9f3d2b2e | 1850 | dump_authparam(StoreEntry * entry, const char *name, Auth::ConfigVector cfg) |
94439e4e | 1851 | { |
9f3d2b2e | 1852 | for (Auth::ConfigVector::iterator i = cfg.begin(); i != cfg.end(); ++i) |
f5691f9c | 1853 | (*i)->dump(entry, name, (*i)); |
94439e4e | 1854 | } |
2f1431ea | 1855 | #endif /* USE_AUTH */ |
94439e4e | 1856 | |
59b2d47f | 1857 | /* TODO: just return the object, the # is irrelevant */ |
cd748f27 | 1858 | static int |
1859 | find_fstype(char *type) | |
1860 | { | |
59b2d47f | 1861 | for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i) |
4c9eadc2 | 1862 | if (strcasecmp(type, StoreFileSystem::FileSystems().at(i)->type()) == 0) |
59b2d47f | 1863 | return (int)i; |
62e76326 | 1864 | |
cd748f27 | 1865 | return (-1); |
1866 | } | |
1867 | ||
0e4e0e7d | 1868 | static void |
e1f7507e | 1869 | parse_cachedir(SquidConfig::_cacheSwap * swap) |
0e4e0e7d | 1870 | { |
1871 | char *type_str; | |
cd748f27 | 1872 | char *path_str; |
c8f4eac4 | 1873 | RefCount<SwapDir> sd; |
cd748f27 | 1874 | int i; |
1875 | int fs; | |
cd748f27 | 1876 | |
2eceb328 | 1877 | if ((type_str = ConfigParser::NextToken()) == NULL) |
62e76326 | 1878 | self_destruct(); |
cd748f27 | 1879 | |
2eceb328 | 1880 | if ((path_str = ConfigParser::NextToken()) == NULL) |
62e76326 | 1881 | self_destruct(); |
cd748f27 | 1882 | |
c9e2e0e8 | 1883 | fs = find_fstype(type_str); |
1884 | ||
d1a37072 AJ |
1885 | if (fs < 0) { |
1886 | debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: This proxy does not support the '" << type_str << "' cache type. Ignoring."); | |
1887 | return; | |
1888 | } | |
c9e2e0e8 | 1889 | |
1890 | /* reconfigure existing dir */ | |
cd748f27 | 1891 | |
a38ec4b1 | 1892 | for (i = 0; i < swap->n_configured; ++i) { |
c8f4eac4 | 1893 | assert (swap->swapDirs[i].getRaw()); |
62e76326 | 1894 | |
2c9e9cba | 1895 | if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) { |
c9e2e0e8 | 1896 | /* this is specific to on-fs Stores. The right |
26ac0430 | 1897 | * way to handle this is probably to have a mapping |
c9e2e0e8 | 1898 | * from paths to stores, and have on-fs stores |
1899 | * register with that, and lookip in that in their | |
1900 | * own setup logic. RBC 20041225. TODO. | |
1901 | */ | |
c8f4eac4 | 1902 | |
1903 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw()); | |
1904 | ||
4c9eadc2 | 1905 | if (strcmp(sd->type(), StoreFileSystem::FileSystems().at(fs)->type()) != 0) { |
fa84c01d | 1906 | debugs(3, DBG_CRITICAL, "ERROR: Can't change type of existing cache_dir " << |
bf8fe701 | 1907 | sd->type() << " " << sd->path << " to " << type_str << ". Restart required"); |
c9e2e0e8 | 1908 | return; |
1909 | } | |
1910 | ||
afa75e4b | 1911 | sd->reconfigure(); |
62e76326 | 1912 | return; |
1913 | } | |
cd748f27 | 1914 | } |
1915 | ||
c9e2e0e8 | 1916 | /* new cache_dir */ |
af6a12ee | 1917 | if (swap->n_configured > 63) { |
2c9e9cba AJ |
1918 | /* 7 bits, signed */ |
1919 | debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle."); | |
1920 | debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many."); | |
1921 | self_destruct(); | |
1922 | return; | |
1923 | } | |
dc986280 | 1924 | |
cd748f27 | 1925 | allocate_new_swapdir(swap); |
c9e2e0e8 | 1926 | |
4c9eadc2 | 1927 | swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().at(fs)->createSwapDir(); |
c9e2e0e8 | 1928 | |
c8f4eac4 | 1929 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw()); |
c9e2e0e8 | 1930 | |
8e8d4f30 | 1931 | /* parse the FS parameters and options */ |
d3b3ab85 | 1932 | sd->parse(swap->n_configured, path_str); |
c9e2e0e8 | 1933 | |
d3b3ab85 | 1934 | ++swap->n_configured; |
752c3b27 | 1935 | } |
1936 | ||
2d72d4fd | 1937 | static const char * |
505e35db | 1938 | peer_type_str(const peer_t type) |
1939 | { | |
1f140227 | 1940 | const char * result; |
1941 | ||
0cdcddb9 | 1942 | switch (type) { |
62e76326 | 1943 | |
505e35db | 1944 | case PEER_PARENT: |
1f140227 | 1945 | result = "parent"; |
62e76326 | 1946 | break; |
1947 | ||
505e35db | 1948 | case PEER_SIBLING: |
1f140227 | 1949 | result = "sibling"; |
62e76326 | 1950 | break; |
1951 | ||
505e35db | 1952 | case PEER_MULTICAST: |
1f140227 | 1953 | result = "multicast"; |
62e76326 | 1954 | break; |
1955 | ||
505e35db | 1956 | default: |
1f140227 | 1957 | result = "unknown"; |
62e76326 | 1958 | break; |
505e35db | 1959 | } |
1f140227 | 1960 | |
1961 | return result; | |
505e35db | 1962 | } |
1963 | ||
f1dc9b30 | 1964 | static void |
a3c6762c | 1965 | dump_peer(StoreEntry * entry, const char *name, CachePeer * p) |
98ffb7e4 | 1966 | { |
b802d2cb | 1967 | CachePeerDomainList *d; |
5844d003 | 1968 | NeighborTypeDomainList *t; |
505e35db | 1969 | LOCAL_ARRAY(char, xname, 128); |
62e76326 | 1970 | |
d41de3c1 | 1971 | while (p != NULL) { |
4bc48d15 | 1972 | storeAppendPrintf(entry, "%s %s %s %d %d name=%s", |
62e76326 | 1973 | name, |
1974 | p->host, | |
1975 | neighborTypeStr(p), | |
1976 | p->http_port, | |
4bc48d15 AJ |
1977 | p->icp.port, |
1978 | p->name); | |
62e76326 | 1979 | dump_peer_options(entry, p); |
1980 | ||
1981 | for (d = p->peer_domain; d; d = d->next) { | |
1982 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", | |
1983 | p->host, | |
1984 | d->do_ping ? null_string : "!", | |
1985 | d->domain); | |
1986 | } | |
1987 | ||
1988 | if (p->access) { | |
1989 | snprintf(xname, 128, "cache_peer_access %s", p->name); | |
1990 | dump_acl_access(entry, xname, p->access); | |
1991 | } | |
1992 | ||
1993 | for (t = p->typelist; t; t = t->next) { | |
1994 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
1995 | p->host, | |
1996 | peer_type_str(t->type), | |
1997 | t->domain); | |
1998 | } | |
1999 | ||
2000 | p = p->next; | |
d41de3c1 | 2001 | } |
98ffb7e4 | 2002 | } |
2003 | ||
86ae97bb AJ |
2004 | /** |
2005 | * utility function to prevent getservbyname() being called with a numeric value | |
2006 | * on Windows at least it returns garage results. | |
2007 | */ | |
2008 | static bool | |
2009 | isUnsignedNumeric(const char *str, size_t len) | |
2010 | { | |
2011 | if (len < 1) return false; | |
2012 | ||
5e263176 | 2013 | for (; len >0 && *str; ++str, --len) { |
86ae97bb AJ |
2014 | if (! isdigit(*str)) |
2015 | return false; | |
2016 | } | |
2017 | return true; | |
2018 | } | |
2019 | ||
609fac72 | 2020 | /** |
2021 | \param proto 'tcp' or 'udp' for protocol | |
2022 | \returns Port the named service is supposed to be listening on. | |
2023 | */ | |
f45dd259 | 2024 | static unsigned short |
609fac72 | 2025 | GetService(const char *proto) |
2026 | { | |
2027 | struct servent *port = NULL; | |
2028 | /** Parses a port number or service name from the squid.conf */ | |
2eceb328 | 2029 | char *token = ConfigParser::NextToken(); |
609fac72 | 2030 | if (token == NULL) { |
26ac0430 AJ |
2031 | self_destruct(); |
2032 | return 0; /* NEVER REACHED */ | |
609fac72 | 2033 | } |
2034 | /** Returns either the service port number from /etc/services */ | |
e1381638 | 2035 | if ( !isUnsignedNumeric(token, strlen(token)) ) |
86ae97bb | 2036 | port = getservbyname(token, proto); |
609fac72 | 2037 | if (port != NULL) { |
f45dd259 | 2038 | return ntohs((unsigned short)port->s_port); |
609fac72 | 2039 | } |
2040 | /** Or a numeric translation of the config text. */ | |
2041 | return xatos(token); | |
2042 | } | |
2043 | ||
2044 | /** | |
2045 | \returns Port the named TCP service is supposed to be listening on. | |
2046 | \copydoc GetService(const char *proto) | |
2047 | */ | |
f45dd259 | 2048 | inline unsigned short |
609fac72 | 2049 | GetTcpService(void) |
2050 | { | |
2051 | return GetService("tcp"); | |
2052 | } | |
2053 | ||
2054 | /** | |
2055 | \returns Port the named UDP service is supposed to be listening on. | |
2056 | \copydoc GetService(const char *proto) | |
2057 | */ | |
f45dd259 | 2058 | inline unsigned short |
609fac72 | 2059 | GetUdpService(void) |
2060 | { | |
2061 | return GetService("udp"); | |
2062 | } | |
2063 | ||
8203a132 | 2064 | static void |
a3c6762c | 2065 | parse_peer(CachePeer ** head) |
7813c6d5 | 2066 | { |
270b86af | 2067 | char *token = NULL; |
a3c6762c FC |
2068 | CachePeer *p; |
2069 | CBDATA_INIT_TYPE_FREECB(CachePeer, peerDestroy); | |
2070 | p = cbdataAlloc(CachePeer); | |
40a1495e | 2071 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 2072 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 2073 | p->weight = 1; |
d1b63fc8 | 2074 | p->basetime = 0; |
dc835977 | 2075 | p->stats.logged_state = PEER_ALIVE; |
62e76326 | 2076 | |
2eceb328 | 2077 | if ((token = ConfigParser::NextToken()) == NULL) |
62e76326 | 2078 | self_destruct(); |
2079 | ||
40a1495e | 2080 | p->host = xstrdup(token); |
26ac0430 | 2081 | |
be753325 | 2082 | p->name = xstrdup(token); |
62e76326 | 2083 | |
2eceb328 | 2084 | if ((token = ConfigParser::NextToken()) == NULL) |
62e76326 | 2085 | self_destruct(); |
2086 | ||
40a1495e | 2087 | p->type = parseNeighborType(token); |
62e76326 | 2088 | |
0d5a2006 | 2089 | if (p->type == PEER_MULTICAST) { |
ccdf4138 FC |
2090 | p->options.no_digest = true; |
2091 | p->options.no_netdb_exchange = true; | |
0d5a2006 | 2092 | } |
2093 | ||
609fac72 | 2094 | p->http_port = GetTcpService(); |
62e76326 | 2095 | |
0e656b69 | 2096 | if (!p->http_port) |
2097 | self_destruct(); | |
62e76326 | 2098 | |
609fac72 | 2099 | p->icp.port = GetUdpService(); |
d67acb4e | 2100 | p->connection_auth = 2; /* auto */ |
62e76326 | 2101 | |
2eceb328 | 2102 | while ((token = ConfigParser::NextToken())) { |
a37d6070 | 2103 | if (!strcmp(token, "proxy-only")) { |
ccdf4138 | 2104 | p->options.proxy_only = true; |
a37d6070 | 2105 | } else if (!strcmp(token, "no-query")) { |
ccdf4138 | 2106 | p->options.no_query = true; |
a37d6070 | 2107 | } else if (!strcmp(token, "background-ping")) { |
ccdf4138 | 2108 | p->options.background_ping = true; |
a37d6070 | 2109 | } else if (!strcmp(token, "no-digest")) { |
ccdf4138 | 2110 | p->options.no_digest = true; |
a37d6070 | 2111 | } else if (!strcmp(token, "no-tproxy")) { |
ccdf4138 | 2112 | p->options.no_tproxy = true; |
a37d6070 | 2113 | } else if (!strcmp(token, "multicast-responder")) { |
ccdf4138 | 2114 | p->options.mcast_responder = true; |
8a368316 | 2115 | #if PEER_MULTICAST_SIBLINGS |
a37d6070 | 2116 | } else if (!strcmp(token, "multicast-siblings")) { |
ccdf4138 | 2117 | p->options.mcast_siblings = true; |
8a368316 | 2118 | #endif |
a37d6070 | 2119 | } else if (!strncmp(token, "weight=", 7)) { |
62e76326 | 2120 | p->weight = xatoi(token + 7); |
a37d6070 | 2121 | } else if (!strncmp(token, "basetime=", 9)) { |
62e76326 | 2122 | p->basetime = xatoi(token + 9); |
a37d6070 | 2123 | } else if (!strcmp(token, "closest-only")) { |
ccdf4138 | 2124 | p->options.closest_only = true; |
a37d6070 | 2125 | } else if (!strncmp(token, "ttl=", 4)) { |
62e76326 | 2126 | p->mcast.ttl = xatoi(token + 4); |
2127 | ||
2128 | if (p->mcast.ttl < 0) | |
2129 | p->mcast.ttl = 0; | |
2130 | ||
2131 | if (p->mcast.ttl > 128) | |
2132 | p->mcast.ttl = 128; | |
a37d6070 | 2133 | } else if (!strcmp(token, "default")) { |
ccdf4138 | 2134 | p->options.default_parent = true; |
a37d6070 | 2135 | } else if (!strcmp(token, "round-robin")) { |
ccdf4138 | 2136 | p->options.roundrobin = true; |
a37d6070 | 2137 | } else if (!strcmp(token, "weighted-round-robin")) { |
ccdf4138 | 2138 | p->options.weighted_roundrobin = true; |
dc9d133b | 2139 | #if USE_HTCP |
a37d6070 | 2140 | } else if (!strcmp(token, "htcp")) { |
ccdf4138 | 2141 | p->options.htcp = true; |
a37d6070 | 2142 | } else if (!strncmp(token, "htcp=", 5) || !strncmp(token, "htcp-", 5)) { |
18191440 | 2143 | /* Note: The htcp- form is deprecated, replaced by htcp= */ |
ccdf4138 | 2144 | p->options.htcp = true; |
18191440 AJ |
2145 | char *tmp = xstrdup(token+5); |
2146 | char *mode, *nextmode; | |
2147 | for (mode = nextmode = tmp; mode; mode = nextmode) { | |
2148 | nextmode = strchr(mode, ','); | |
a38ec4b1 FC |
2149 | if (nextmode) { |
2150 | *nextmode = '\0'; | |
2151 | ++nextmode; | |
2152 | } | |
a37d6070 | 2153 | if (!strcmp(mode, "no-clr")) { |
18191440 AJ |
2154 | if (p->options.htcp_only_clr) |
2155 | fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously"); | |
ccdf4138 | 2156 | p->options.htcp_no_clr = true; |
a37d6070 | 2157 | } else if (!strcmp(mode, "no-purge-clr")) { |
ccdf4138 | 2158 | p->options.htcp_no_purge_clr = true; |
a37d6070 | 2159 | } else if (!strcmp(mode, "only-clr")) { |
18191440 AJ |
2160 | if (p->options.htcp_no_clr) |
2161 | fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously"); | |
ccdf4138 | 2162 | p->options.htcp_only_clr = true; |
a37d6070 | 2163 | } else if (!strcmp(mode, "forward-clr")) { |
ccdf4138 | 2164 | p->options.htcp_forward_clr = true; |
a37d6070 | 2165 | } else if (!strcmp(mode, "oldsquid")) { |
ccdf4138 | 2166 | p->options.htcp_oldsquid = true; |
18191440 AJ |
2167 | } else { |
2168 | fatalf("invalid HTCP mode '%s'", mode); | |
2169 | } | |
2170 | } | |
2171 | safe_free(tmp); | |
dc9d133b | 2172 | #endif |
a37d6070 | 2173 | } else if (!strcmp(token, "no-netdb-exchange")) { |
ccdf4138 | 2174 | p->options.no_netdb_exchange = true; |
62e76326 | 2175 | |
a37d6070 | 2176 | } else if (!strcmp(token, "carp")) { |
62e76326 | 2177 | if (p->type != PEER_PARENT) |
2178 | fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port); | |
2179 | ||
ccdf4138 | 2180 | p->options.carp = true; |
a37d6070 | 2181 | } else if (!strncmp(token, "carp-key=", 9)) { |
ccdf4138 | 2182 | if (p->options.carp != true) |
de03b596 | 2183 | fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port); |
ccdf4138 | 2184 | p->options.carp_key.set = true; |
de03b596 FC |
2185 | char *nextkey=token+strlen("carp-key="), *key=nextkey; |
2186 | for (; key; key = nextkey) { | |
96f6f33b A |
2187 | nextkey=strchr(key,','); |
2188 | if (nextkey) ++nextkey; // skip the comma, any | |
a37d6070 | 2189 | if (0==strncmp(key,"scheme",6)) { |
ccdf4138 | 2190 | p->options.carp_key.scheme = true; |
a37d6070 | 2191 | } else if (0==strncmp(key,"host",4)) { |
ccdf4138 | 2192 | p->options.carp_key.host = true; |
a37d6070 | 2193 | } else if (0==strncmp(key,"port",4)) { |
ccdf4138 | 2194 | p->options.carp_key.port = true; |
a37d6070 | 2195 | } else if (0==strncmp(key,"path",4)) { |
ccdf4138 | 2196 | p->options.carp_key.path = true; |
a37d6070 | 2197 | } else if (0==strncmp(key,"params",6)) { |
ccdf4138 | 2198 | p->options.carp_key.params = true; |
96f6f33b A |
2199 | } else { |
2200 | fatalf("invalid carp-key '%s'",key); | |
2201 | } | |
de03b596 | 2202 | } |
a37d6070 | 2203 | } else if (!strcmp(token, "userhash")) { |
2f1431ea | 2204 | #if USE_AUTH |
f7e1d9ce HN |
2205 | if (p->type != PEER_PARENT) |
2206 | fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port); | |
2207 | ||
ccdf4138 | 2208 | p->options.userhash = true; |
2f1431ea AJ |
2209 | #else |
2210 | fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port); | |
2211 | #endif | |
a37d6070 | 2212 | } else if (!strcmp(token, "sourcehash")) { |
f7e1d9ce HN |
2213 | if (p->type != PEER_PARENT) |
2214 | fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port); | |
2215 | ||
ccdf4138 | 2216 | p->options.sourcehash = true; |
f7e1d9ce | 2217 | |
a37d6070 | 2218 | } else if (!strcmp(token, "no-delay")) { |
9a0a18de | 2219 | #if USE_DELAY_POOLS |
ccdf4138 | 2220 | p->options.no_delay = true; |
9a0a18de AJ |
2221 | #else |
2222 | debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools"); | |
afd88fbe | 2223 | #endif |
a37d6070 | 2224 | } else if (!strncmp(token, "login=", 6)) { |
62e76326 | 2225 | p->login = xstrdup(token + 6); |
2226 | rfc1738_unescape(p->login); | |
a37d6070 | 2227 | } else if (!strncmp(token, "connect-timeout=", 16)) { |
62e76326 | 2228 | p->connect_timeout = xatoi(token + 16); |
a37d6070 | 2229 | } else if (!strncmp(token, "connect-fail-limit=", 19)) { |
ff9970cc | 2230 | p->connect_fail_limit = xatoi(token + 19); |
7e3ce7b9 | 2231 | #if USE_CACHE_DIGESTS |
a37d6070 | 2232 | } else if (!strncmp(token, "digest-url=", 11)) { |
62e76326 | 2233 | p->digest_url = xstrdup(token + 11); |
7e3ce7b9 | 2234 | #endif |
62e76326 | 2235 | |
a37d6070 | 2236 | } else if (!strcmp(token, "allow-miss")) { |
ccdf4138 | 2237 | p->options.allow_miss = true; |
a37d6070 | 2238 | } else if (!strncmp(token, "max-conn=", 9)) { |
62e76326 | 2239 | p->max_conn = xatoi(token + 9); |
e8dca475 CT |
2240 | } else if (!strncmp(token, "standby=", 8)) { |
2241 | p->standby.limit = xatoi(token + 8); | |
a37d6070 | 2242 | } else if (!strcmp(token, "originserver")) { |
ccdf4138 | 2243 | p->options.originserver = true; |
a37d6070 | 2244 | } else if (!strncmp(token, "name=", 5)) { |
62e76326 | 2245 | safe_free(p->name); |
2246 | ||
2247 | if (token[5]) | |
2248 | p->name = xstrdup(token + 5); | |
a37d6070 | 2249 | } else if (!strncmp(token, "forceddomain=", 13)) { |
62e76326 | 2250 | safe_free(p->domain); |
2251 | ||
2252 | if (token[13]) | |
2253 | p->domain = xstrdup(token + 13); | |
2254 | ||
cb4f4424 | 2255 | #if USE_OPENSSL |
62e76326 | 2256 | |
2257 | } else if (strcmp(token, "ssl") == 0) { | |
2258 | p->use_ssl = 1; | |
2259 | } else if (strncmp(token, "sslcert=", 8) == 0) { | |
2260 | safe_free(p->sslcert); | |
2261 | p->sslcert = xstrdup(token + 8); | |
2262 | } else if (strncmp(token, "sslkey=", 7) == 0) { | |
2263 | safe_free(p->sslkey); | |
2264 | p->sslkey = xstrdup(token + 7); | |
2265 | } else if (strncmp(token, "sslversion=", 11) == 0) { | |
54a063a2 | 2266 | p->sslversion = xatoi(token + 11); |
62e76326 | 2267 | } else if (strncmp(token, "ssloptions=", 11) == 0) { |
2268 | safe_free(p->ssloptions); | |
2269 | p->ssloptions = xstrdup(token + 11); | |
2270 | } else if (strncmp(token, "sslcipher=", 10) == 0) { | |
2271 | safe_free(p->sslcipher); | |
2272 | p->sslcipher = xstrdup(token + 10); | |
2273 | } else if (strncmp(token, "sslcafile=", 10) == 0) { | |
2274 | safe_free(p->sslcafile); | |
a82a4fe4 | 2275 | p->sslcafile = xstrdup(token + 10); |
62e76326 | 2276 | } else if (strncmp(token, "sslcapath=", 10) == 0) { |
2277 | safe_free(p->sslcapath); | |
a82a4fe4 | 2278 | p->sslcapath = xstrdup(token + 10); |
2279 | } else if (strncmp(token, "sslcrlfile=", 11) == 0) { | |
2280 | safe_free(p->sslcrlfile); | |
eaed60cc | 2281 | p->sslcrlfile = xstrdup(token + 11); |
62e76326 | 2282 | } else if (strncmp(token, "sslflags=", 9) == 0) { |
2283 | safe_free(p->sslflags); | |
2284 | p->sslflags = xstrdup(token + 9); | |
2285 | } else if (strncmp(token, "ssldomain=", 10) == 0) { | |
2286 | safe_free(p->ssldomain); | |
2287 | p->ssldomain = xstrdup(token + 10); | |
a7ad6e4e | 2288 | #endif |
62e76326 | 2289 | |
2290 | } else if (strcmp(token, "front-end-https") == 0) { | |
2291 | p->front_end_https = 1; | |
2292 | } else if (strcmp(token, "front-end-https=on") == 0) { | |
2293 | p->front_end_https = 1; | |
2294 | } else if (strcmp(token, "front-end-https=auto") == 0) { | |
2295 | p->front_end_https = 2; | |
26ac0430 | 2296 | } else if (strcmp(token, "connection-auth=off") == 0) { |
d67acb4e AJ |
2297 | p->connection_auth = 0; |
2298 | } else if (strcmp(token, "connection-auth") == 0) { | |
2299 | p->connection_auth = 1; | |
2300 | } else if (strcmp(token, "connection-auth=on") == 0) { | |
2301 | p->connection_auth = 1; | |
2302 | } else if (strcmp(token, "connection-auth=auto") == 0) { | |
2303 | p->connection_auth = 2; | |
9d22bac3 AJ |
2304 | } else if (token[0] == '#') { |
2305 | // start of a text comment. stop reading this line. | |
2306 | break; | |
62e76326 | 2307 | } else { |
9d22bac3 | 2308 | debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Ignoring unknown cache_peer option '" << token << "'"); |
62e76326 | 2309 | } |
270b86af | 2310 | } |
62e76326 | 2311 | |
be753325 | 2312 | if (peerFindByName(p->name)) |
62e76326 | 2313 | fatalf("ERROR: cache_peer %s specified twice\n", p->name); |
2314 | ||
e8dca475 CT |
2315 | if (p->max_conn > 0 && p->max_conn < p->standby.limit) |
2316 | fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p->host, p->max_conn, p->standby.limit); | |
2317 | ||
40a1495e | 2318 | if (p->weight < 1) |
62e76326 | 2319 | p->weight = 1; |
2320 | ||
ff9970cc | 2321 | if (p->connect_fail_limit < 1) |
a4d889e0 | 2322 | p->connect_fail_limit = 10; |
ff9970cc | 2323 | |
399cabec | 2324 | p->icp.version = ICP_VERSION_CURRENT; |
62e76326 | 2325 | |
cfd66529 | 2326 | p->testing_now = false; |
62e76326 | 2327 | |
e13ee7ad | 2328 | #if USE_CACHE_DIGESTS |
62e76326 | 2329 | |
e13ee7ad | 2330 | if (!p->options.no_digest) { |
62e76326 | 2331 | /* XXX This looks odd.. who has the original pointer |
2332 | * then? | |
2333 | */ | |
2334 | PeerDigest *pd = peerDigestCreate(p); | |
2335 | p->digest = cbdataReference(pd); | |
8a6218c6 | 2336 | } |
62e76326 | 2337 | |
e13ee7ad | 2338 | #endif |
cc192b50 | 2339 | |
2340 | p->index = ++Config.npeers; | |
2341 | ||
0153d498 | 2342 | while (*head != NULL) |
62e76326 | 2343 | head = &(*head)->next; |
2344 | ||
0153d498 | 2345 | *head = p; |
62e76326 | 2346 | |
32a47e3e | 2347 | peerClearRRStart(); |
0153d498 | 2348 | } |
2349 | ||
2350 | static void | |
a3c6762c | 2351 | free_peer(CachePeer ** P) |
0153d498 | 2352 | { |
a3c6762c | 2353 | CachePeer *p; |
62e76326 | 2354 | |
79d39a72 | 2355 | while ((p = *P) != NULL) { |
62e76326 | 2356 | *P = p->next; |
3855c318 | 2357 | #if USE_CACHE_DIGESTS |
62e76326 | 2358 | |
2359 | cbdataReferenceDone(p->digest); | |
3855c318 | 2360 | #endif |
62e76326 | 2361 | |
e8dca475 CT |
2362 | // the mgr job will notice that its owner is gone and stop |
2363 | PeerPoolMgr::Checkpoint(p->standby.mgr, "peer gone"); | |
2364 | delete p->standby.pool; | |
62e76326 | 2365 | cbdataFree(p); |
a47b9029 | 2366 | } |
62e76326 | 2367 | |
987c67d1 | 2368 | Config.npeers = 0; |
270b86af | 2369 | } |
2370 | ||
2371 | static void | |
613924ee | 2372 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, Mgr::ActionPasswordList * list) |
270b86af | 2373 | { |
d41de3c1 | 2374 | wordlist *w; |
62e76326 | 2375 | |
d41de3c1 | 2376 | while (list != NULL) { |
62e76326 | 2377 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
2378 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
2379 | else | |
2380 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
2381 | ||
2382 | for (w = list->actions; w != NULL; w = w->next) { | |
2383 | storeAppendPrintf(entry, " %s", w->key); | |
2384 | } | |
2385 | ||
2386 | storeAppendPrintf(entry, "\n"); | |
2387 | list = list->next; | |
d41de3c1 | 2388 | } |
270b86af | 2389 | } |
2390 | ||
2391 | static void | |
613924ee | 2392 | parse_cachemgrpasswd(Mgr::ActionPasswordList ** head) |
270b86af | 2393 | { |
2394 | char *passwd = NULL; | |
2395 | wordlist *actions = NULL; | |
613924ee FC |
2396 | Mgr::ActionPasswordList *p; |
2397 | Mgr::ActionPasswordList **P; | |
270b86af | 2398 | parse_string(&passwd); |
2399 | parse_wordlist(&actions); | |
613924ee | 2400 | p = new Mgr::ActionPasswordList; |
22f3fd98 | 2401 | p->passwd = passwd; |
2402 | p->actions = actions; | |
62e76326 | 2403 | |
26aa7e31 | 2404 | for (P = head; *P; P = &(*P)->next) { |
62e76326 | 2405 | /* |
2406 | * See if any of the actions from this line already have a | |
2407 | * password from previous lines. The password checking | |
2408 | * routines in cache_manager.c take the the password from | |
613924ee | 2409 | * the first Mgr::ActionPasswordList that contains the |
62e76326 | 2410 | * requested action. Thus, we should warn users who might |
2411 | * think they can have two passwords for the same action. | |
2412 | */ | |
2413 | wordlist *w; | |
2414 | wordlist *u; | |
2415 | ||
2416 | for (w = (*P)->actions; w; w = w->next) { | |
2417 | for (u = actions; u; u = u->next) { | |
2418 | if (strcmp(w->key, u->key)) | |
2419 | continue; | |
2420 | ||
fa84c01d | 2421 | debugs(0, DBG_CRITICAL, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password"); |
62e76326 | 2422 | } |
2423 | } | |
26aa7e31 | 2424 | } |
62e76326 | 2425 | |
22f3fd98 | 2426 | *P = p; |
270b86af | 2427 | } |
2428 | ||
2429 | static void | |
613924ee | 2430 | free_cachemgrpasswd(Mgr::ActionPasswordList ** head) |
270b86af | 2431 | { |
613924ee | 2432 | Mgr::ActionPasswordList *p; |
62e76326 | 2433 | |
79d39a72 | 2434 | while ((p = *head) != NULL) { |
62e76326 | 2435 | *head = p->next; |
2436 | xfree(p->passwd); | |
2437 | wordlistDestroy(&p->actions); | |
2438 | xfree(p); | |
a47b9029 | 2439 | } |
270b86af | 2440 | } |
2441 | ||
8203a132 | 2442 | static void |
7f0b3324 | 2443 | dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var) |
270b86af | 2444 | { |
6be70545 | 2445 | AclNameList *a; |
62e76326 | 2446 | |
d41de3c1 | 2447 | while (var != NULL) { |
62e76326 | 2448 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
2449 | ||
2450 | for (a = var->acl_list; a != NULL; a = a->next) | |
2451 | storeAppendPrintf(entry, " %s", a->name); | |
2452 | ||
2453 | storeAppendPrintf(entry, "\n"); | |
2454 | ||
2455 | var = var->next; | |
d41de3c1 | 2456 | } |
270b86af | 2457 | } |
2458 | ||
2459 | static void | |
7f0b3324 | 2460 | parse_denyinfo(AclDenyInfoList ** var) |
6e40f263 | 2461 | { |
f1dc9b30 | 2462 | aclParseDenyInfoLine(var); |
6e40f263 | 2463 | } |
403279e0 | 2464 | |
1273d501 | 2465 | void |
7f0b3324 | 2466 | free_denyinfo(AclDenyInfoList ** list) |
3c5557f9 | 2467 | { |
7f0b3324 FC |
2468 | AclDenyInfoList *a = NULL; |
2469 | AclDenyInfoList *a_next = NULL; | |
6be70545 FC |
2470 | AclNameList *l = NULL; |
2471 | AclNameList *l_next = NULL; | |
62e76326 | 2472 | |
1273d501 | 2473 | for (a = *list; a; a = a_next) { |
62e76326 | 2474 | for (l = a->acl_list; l; l = l_next) { |
2475 | l_next = l->next; | |
2476 | memFree(l, MEM_ACL_NAME_LIST); | |
2477 | l = NULL; | |
2478 | } | |
2479 | ||
2480 | a_next = a->next; | |
2481 | memFree(a, MEM_ACL_DENY_INFO_LIST); | |
2482 | a = NULL; | |
1273d501 | 2483 | } |
62e76326 | 2484 | |
1273d501 | 2485 | *list = NULL; |
270b86af | 2486 | } |
2487 | ||
2488 | static void | |
505e35db | 2489 | parse_peer_access(void) |
270b86af | 2490 | { |
2491 | char *host = NULL; | |
a3c6762c | 2492 | CachePeer *p; |
62e76326 | 2493 | |
2eceb328 | 2494 | if (!(host = ConfigParser::NextToken())) |
62e76326 | 2495 | self_destruct(); |
2496 | ||
0cdcddb9 | 2497 | if ((p = peerFindByName(host)) == NULL) { |
fa84c01d | 2498 | debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2499 | return; |
0cdcddb9 | 2500 | } |
62e76326 | 2501 | |
6f58d7d7 AR |
2502 | std::string directive = "peer_access "; |
2503 | directive += host; | |
2504 | aclParseAccessLine(directive.c_str(), LegacyParser, &p->access); | |
270b86af | 2505 | } |
2506 | ||
270b86af | 2507 | static void |
2508 | parse_hostdomain(void) | |
2509 | { | |
2510 | char *host = NULL; | |
2511 | char *domain = NULL; | |
62e76326 | 2512 | |
2eceb328 | 2513 | if (!(host = ConfigParser::NextToken())) |
62e76326 | 2514 | self_destruct(); |
2515 | ||
2eceb328 | 2516 | while ((domain = ConfigParser::NextToken())) { |
b802d2cb FC |
2517 | CachePeerDomainList *l = NULL; |
2518 | CachePeerDomainList **L = NULL; | |
a3c6762c | 2519 | CachePeer *p; |
62e76326 | 2520 | |
2521 | if ((p = peerFindByName(host)) == NULL) { | |
fa84c01d | 2522 | debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2523 | continue; |
2524 | } | |
2525 | ||
b802d2cb FC |
2526 | l = static_cast<CachePeerDomainList *>(xcalloc(1, sizeof(CachePeerDomainList))); |
2527 | l->do_ping = true; | |
62e76326 | 2528 | |
2529 | if (*domain == '!') { /* check for !.edu */ | |
b802d2cb | 2530 | l->do_ping = false; |
a38ec4b1 | 2531 | ++domain; |
62e76326 | 2532 | } |
2533 | ||
2534 | l->domain = xstrdup(domain); | |
2535 | ||
3d0ac046 | 2536 | for (L = &(p->peer_domain); *L; L = &((*L)->next)); |
62e76326 | 2537 | *L = l; |
f1dc9b30 | 2538 | } |
270b86af | 2539 | } |
2540 | ||
2541 | static void | |
2542 | parse_hostdomaintype(void) | |
2543 | { | |
2544 | char *host = NULL; | |
2545 | char *type = NULL; | |
2546 | char *domain = NULL; | |
62e76326 | 2547 | |
2eceb328 | 2548 | if (!(host = ConfigParser::NextToken())) |
62e76326 | 2549 | self_destruct(); |
2550 | ||
2eceb328 | 2551 | if (!(type = ConfigParser::NextToken())) |
62e76326 | 2552 | self_destruct(); |
2553 | ||
2eceb328 | 2554 | while ((domain = ConfigParser::NextToken())) { |
5844d003 FC |
2555 | NeighborTypeDomainList *l = NULL; |
2556 | NeighborTypeDomainList **L = NULL; | |
a3c6762c | 2557 | CachePeer *p; |
62e76326 | 2558 | |
2559 | if ((p = peerFindByName(host)) == NULL) { | |
fa84c01d | 2560 | debugs(15, DBG_CRITICAL, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2561 | return; |
2562 | } | |
2563 | ||
5844d003 | 2564 | l = static_cast<NeighborTypeDomainList *>(xcalloc(1, sizeof(NeighborTypeDomainList))); |
62e76326 | 2565 | l->type = parseNeighborType(type); |
2566 | l->domain = xstrdup(domain); | |
2567 | ||
3d0ac046 | 2568 | for (L = &(p->typelist); *L; L = &((*L)->next)); |
62e76326 | 2569 | *L = l; |
f1dc9b30 | 2570 | } |
270b86af | 2571 | } |
2572 | ||
270b86af | 2573 | static void |
a7d59104 | 2574 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 2575 | { |
f53b06f9 | 2576 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2577 | } |
c1c29eb6 | 2578 | |
94439e4e | 2579 | void |
270b86af | 2580 | parse_int(int *var) |
2581 | { | |
270b86af | 2582 | int i; |
0e4e0e7d | 2583 | i = GetInteger(); |
270b86af | 2584 | *var = i; |
2585 | } | |
090089c4 | 2586 | |
0153d498 | 2587 | static void |
2588 | free_int(int *var) | |
2589 | { | |
a47b9029 | 2590 | *var = 0; |
0153d498 | 2591 | } |
2592 | ||
270b86af | 2593 | static void |
a7d59104 | 2594 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 2595 | { |
f53b06f9 | 2596 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 2597 | } |
090089c4 | 2598 | |
d205783b | 2599 | void |
270b86af | 2600 | parse_onoff(int *var) |
2601 | { | |
2eceb328 | 2602 | char *token = ConfigParser::NextToken(); |
090089c4 | 2603 | |
270b86af | 2604 | if (token == NULL) |
62e76326 | 2605 | self_destruct(); |
2606 | ||
a37d6070 | 2607 | if (!strcmp(token, "on")) { |
62e76326 | 2608 | *var = 1; |
a37d6070 | 2609 | } else if (!strcmp(token, "enable")) { |
54a063a2 TX |
2610 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use 'on'."); |
2611 | *var = 1; | |
a37d6070 | 2612 | } else if (!strcmp(token, "off")) { |
62e76326 | 2613 | *var = 0; |
a37d6070 | 2614 | } else if (!strcmp(token, "disable")) { |
54a063a2 TX |
2615 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use 'off'."); |
2616 | *var = 0; | |
2617 | } else { | |
2618 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'."); | |
2619 | self_destruct(); | |
2620 | } | |
270b86af | 2621 | } |
e90100aa | 2622 | |
0153d498 | 2623 | #define free_onoff free_int |
52d3f198 | 2624 | |
2625 | static void | |
2626 | dump_tristate(StoreEntry * entry, const char *name, int var) | |
2627 | { | |
2628 | const char *state; | |
2629 | ||
2630 | if (var > 0) | |
2631 | state = "on"; | |
2632 | else if (var < 0) | |
2633 | state = "warn"; | |
2634 | else | |
2635 | state = "off"; | |
2636 | ||
2637 | storeAppendPrintf(entry, "%s %s\n", name, state); | |
2638 | } | |
2639 | ||
2640 | static void | |
2641 | parse_tristate(int *var) | |
2642 | { | |
2eceb328 | 2643 | char *token = ConfigParser::NextToken(); |
52d3f198 | 2644 | |
2645 | if (token == NULL) | |
2646 | self_destruct(); | |
2647 | ||
a37d6070 | 2648 | if (!strcmp(token, "on")) { |
54a063a2 | 2649 | *var = 1; |
a37d6070 | 2650 | } else if (!strcmp(token, "enable")) { |
54a063a2 | 2651 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'enable' is deprecated. Please update to use value 'on'."); |
52d3f198 | 2652 | *var = 1; |
a37d6070 | 2653 | } else if (!strcmp(token, "warn")) { |
52d3f198 | 2654 | *var = -1; |
a37d6070 | 2655 | } else if (!strcmp(token, "off")) { |
52d3f198 | 2656 | *var = 0; |
a37d6070 | 2657 | } else if (!strcmp(token, "disable")) { |
54a063a2 TX |
2658 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'disable' is deprecated. Please update to use value 'off'."); |
2659 | *var = 0; | |
2660 | } else { | |
2661 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'."); | |
2662 | self_destruct(); | |
2663 | } | |
52d3f198 | 2664 | } |
2665 | ||
2666 | #define free_tristate free_int | |
30a4f2a8 | 2667 | |
079a8480 AJ |
2668 | void |
2669 | parse_pipelinePrefetch(int *var) | |
2670 | { | |
bde7a8ce | 2671 | char *token = ConfigParser::PeekAtToken(); |
079a8480 AJ |
2672 | |
2673 | if (token == NULL) | |
2674 | self_destruct(); | |
2675 | ||
2676 | if (!strcmp(token, "on")) { | |
2677 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number)."); | |
2678 | *var = 1; | |
bde7a8ce CT |
2679 | //pop the token |
2680 | (void)ConfigParser::NextToken(); | |
079a8480 AJ |
2681 | } else if (!strcmp(token, "off")) { |
2682 | debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'."); | |
2683 | *var = 0; | |
bde7a8ce CT |
2684 | //pop the token |
2685 | (void)ConfigParser::NextToken(); | |
2686 | } else | |
079a8480 | 2687 | parse_int(var); |
079a8480 AJ |
2688 | } |
2689 | ||
2690 | #define free_pipelinePrefetch free_int | |
2691 | #define dump_pipelinePrefetch dump_int | |
2692 | ||
270b86af | 2693 | static void |
8d9a8184 | 2694 | dump_refreshpattern(StoreEntry * entry, const char *name, RefreshPattern * head) |
270b86af | 2695 | { |
d41de3c1 | 2696 | while (head != NULL) { |
0e1d7629 | 2697 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d", |
62e76326 | 2698 | name, |
2699 | head->flags.icase ? " -i" : null_string, | |
2700 | head->pattern, | |
2701 | (int) head->min / 60, | |
2702 | (int) (100.0 * head->pct + 0.5), | |
2703 | (int) head->max / 60); | |
4c3ef9b2 | 2704 | |
570d3f75 AJ |
2705 | if (head->max_stale >= 0) |
2706 | storeAppendPrintf(entry, " max-stale=%d", head->max_stale); | |
2707 | ||
4c3ef9b2 | 2708 | if (head->flags.refresh_ims) |
2709 | storeAppendPrintf(entry, " refresh-ims"); | |
2710 | ||
3d8b6ba4 AJ |
2711 | if (head->flags.store_stale) |
2712 | storeAppendPrintf(entry, " store-stale"); | |
2713 | ||
626096be | 2714 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2715 | |
2716 | if (head->flags.override_expire) | |
2717 | storeAppendPrintf(entry, " override-expire"); | |
2718 | ||
2719 | if (head->flags.override_lastmod) | |
2720 | storeAppendPrintf(entry, " override-lastmod"); | |
2721 | ||
2722 | if (head->flags.reload_into_ims) | |
2723 | storeAppendPrintf(entry, " reload-into-ims"); | |
2724 | ||
2725 | if (head->flags.ignore_reload) | |
2726 | storeAppendPrintf(entry, " ignore-reload"); | |
2727 | ||
38f9c547 | 2728 | if (head->flags.ignore_no_store) |
2729 | storeAppendPrintf(entry, " ignore-no-store"); | |
2730 | ||
4ca08219 AJ |
2731 | if (head->flags.ignore_must_revalidate) |
2732 | storeAppendPrintf(entry, " ignore-must-revalidate"); | |
2733 | ||
38f9c547 | 2734 | if (head->flags.ignore_private) |
2735 | storeAppendPrintf(entry, " ignore-private"); | |
2736 | ||
2737 | if (head->flags.ignore_auth) | |
2738 | storeAppendPrintf(entry, " ignore-auth"); | |
2739 | ||
9f60cfdf | 2740 | #endif |
62e76326 | 2741 | |
2742 | storeAppendPrintf(entry, "\n"); | |
2743 | ||
2744 | head = head->next; | |
d41de3c1 | 2745 | } |
270b86af | 2746 | } |
090089c4 | 2747 | |
270b86af | 2748 | static void |
8d9a8184 | 2749 | parse_refreshpattern(RefreshPattern ** head) |
270b86af | 2750 | { |
f1dc9b30 | 2751 | char *token; |
2752 | char *pattern; | |
2753 | time_t min = 0; | |
c3f6d204 | 2754 | double pct = 0.0; |
f1dc9b30 | 2755 | time_t max = 0; |
4c3ef9b2 | 2756 | int refresh_ims = 0; |
3d8b6ba4 | 2757 | int store_stale = 0; |
570d3f75 | 2758 | int max_stale = -1; |
3d8b6ba4 | 2759 | |
626096be | 2760 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2761 | |
1dfa1d81 | 2762 | int override_expire = 0; |
2763 | int override_lastmod = 0; | |
cbe3a719 | 2764 | int reload_into_ims = 0; |
2765 | int ignore_reload = 0; | |
38f9c547 | 2766 | int ignore_no_store = 0; |
4ca08219 | 2767 | int ignore_must_revalidate = 0; |
38f9c547 | 2768 | int ignore_private = 0; |
2769 | int ignore_auth = 0; | |
9f60cfdf | 2770 | #endif |
62e76326 | 2771 | |
f1dc9b30 | 2772 | int i; |
8d9a8184 | 2773 | RefreshPattern *t; |
f1dc9b30 | 2774 | regex_t comp; |
2775 | int errcode; | |
2776 | int flags = REG_EXTENDED | REG_NOSUB; | |
62e76326 | 2777 | |
bde7a8ce | 2778 | if ((token = ConfigParser::RegexPattern()) != NULL) { |
2f3c75c3 AJ |
2779 | |
2780 | if (strcmp(token, "-i") == 0) { | |
2781 | flags |= REG_ICASE; | |
bde7a8ce | 2782 | token = ConfigParser::RegexPattern(); |
2f3c75c3 AJ |
2783 | } else if (strcmp(token, "+i") == 0) { |
2784 | flags &= ~REG_ICASE; | |
bde7a8ce | 2785 | token = ConfigParser::RegexPattern(); |
2f3c75c3 | 2786 | } |
62e76326 | 2787 | |
f1dc9b30 | 2788 | } |
62e76326 | 2789 | |
9eeb8e4b | 2790 | if (token == NULL) { |
2f3c75c3 | 2791 | debugs(3, DBG_CRITICAL, "FATAL: refresh_pattern missing the regex pattern parameter"); |
62e76326 | 2792 | self_destruct(); |
9eeb8e4b | 2793 | return; |
2794 | } | |
62e76326 | 2795 | |
f1dc9b30 | 2796 | pattern = xstrdup(token); |
62e76326 | 2797 | |
0e4e0e7d | 2798 | i = GetInteger(); /* token: min */ |
62e76326 | 2799 | |
a632ba71 AJ |
2800 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2801 | if (i < 0) { | |
2802 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero."); | |
2803 | i = 0; | |
2804 | } | |
2805 | if (i > 60*24*365) { | |
2806 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year."); | |
2807 | i = 60*24*365; | |
2808 | } | |
2809 | ||
f1dc9b30 | 2810 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2811 | |
54a063a2 | 2812 | i = GetPercentage(); /* token: pct */ |
62e76326 | 2813 | |
c3f6d204 | 2814 | pct = (double) i / 100.0; |
62e76326 | 2815 | |
0e4e0e7d | 2816 | i = GetInteger(); /* token: max */ |
62e76326 | 2817 | |
a632ba71 AJ |
2818 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2819 | if (i < 0) { | |
2820 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero."); | |
2821 | i = 0; | |
2822 | } | |
2823 | if (i > 60*24*365) { | |
2824 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year."); | |
2825 | i = 60*24*365; | |
2826 | } | |
2827 | ||
f1dc9b30 | 2828 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2829 | |
1dfa1d81 | 2830 | /* Options */ |
2eceb328 | 2831 | while ((token = ConfigParser::NextToken()) != NULL) { |
4c3ef9b2 | 2832 | if (!strcmp(token, "refresh-ims")) { |
2833 | refresh_ims = 1; | |
3d8b6ba4 AJ |
2834 | } else if (!strcmp(token, "store-stale")) { |
2835 | store_stale = 1; | |
570d3f75 | 2836 | } else if (!strncmp(token, "max-stale=", 10)) { |
54a063a2 | 2837 | max_stale = xatoi(token + 10); |
626096be | 2838 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2839 | |
4c3ef9b2 | 2840 | } else if (!strcmp(token, "override-expire")) |
62e76326 | 2841 | override_expire = 1; |
2842 | else if (!strcmp(token, "override-lastmod")) | |
2843 | override_lastmod = 1; | |
38f9c547 | 2844 | else if (!strcmp(token, "ignore-no-store")) |
2845 | ignore_no_store = 1; | |
4ca08219 AJ |
2846 | else if (!strcmp(token, "ignore-must-revalidate")) |
2847 | ignore_must_revalidate = 1; | |
38f9c547 | 2848 | else if (!strcmp(token, "ignore-private")) |
2849 | ignore_private = 1; | |
2850 | else if (!strcmp(token, "ignore-auth")) | |
2851 | ignore_auth = 1; | |
62e76326 | 2852 | else if (!strcmp(token, "reload-into-ims")) { |
2853 | reload_into_ims = 1; | |
2854 | refresh_nocache_hack = 1; | |
2855 | /* tell client_side.c that this is used */ | |
2856 | } else if (!strcmp(token, "ignore-reload")) { | |
2857 | ignore_reload = 1; | |
2858 | refresh_nocache_hack = 1; | |
2859 | /* tell client_side.c that this is used */ | |
9f60cfdf | 2860 | #endif |
62e76326 | 2861 | |
7ed5335a AJ |
2862 | } else if (!strcmp(token, "ignore-no-cache")) { |
2863 | debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it."); | |
4c3ef9b2 | 2864 | } else |
fa84c01d | 2865 | debugs(22, DBG_CRITICAL, "refreshAddToList: Unknown option '" << pattern << "': " << token); |
1dfa1d81 | 2866 | } |
62e76326 | 2867 | |
f1dc9b30 | 2868 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
62e76326 | 2869 | char errbuf[256]; |
2870 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
fa84c01d FC |
2871 | debugs(22, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
2872 | debugs(22, DBG_CRITICAL, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf); | |
eeaa522f | 2873 | xfree(pattern); |
62e76326 | 2874 | return; |
f1dc9b30 | 2875 | } |
62e76326 | 2876 | |
c3f6d204 | 2877 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 2878 | max = max < 0 ? 0 : max; |
8d9a8184 | 2879 | t = static_cast<RefreshPattern *>(xcalloc(1, sizeof(RefreshPattern))); |
f1dc9b30 | 2880 | t->pattern = (char *) xstrdup(pattern); |
2881 | t->compiled_pattern = comp; | |
2882 | t->min = min; | |
c3f6d204 | 2883 | t->pct = pct; |
f1dc9b30 | 2884 | t->max = max; |
62e76326 | 2885 | |
c3f6d204 | 2886 | if (flags & REG_ICASE) |
be4d35dc | 2887 | t->flags.icase = true; |
62e76326 | 2888 | |
4c3ef9b2 | 2889 | if (refresh_ims) |
be4d35dc | 2890 | t->flags.refresh_ims = true; |
4c3ef9b2 | 2891 | |
3d8b6ba4 | 2892 | if (store_stale) |
be4d35dc | 2893 | t->flags.store_stale = true; |
3d8b6ba4 | 2894 | |
570d3f75 AJ |
2895 | t->max_stale = max_stale; |
2896 | ||
626096be | 2897 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2898 | |
1dfa1d81 | 2899 | if (override_expire) |
be4d35dc | 2900 | t->flags.override_expire = true; |
62e76326 | 2901 | |
1dfa1d81 | 2902 | if (override_lastmod) |
be4d35dc | 2903 | t->flags.override_lastmod = true; |
62e76326 | 2904 | |
cbe3a719 | 2905 | if (reload_into_ims) |
be4d35dc | 2906 | t->flags.reload_into_ims = true; |
62e76326 | 2907 | |
cbe3a719 | 2908 | if (ignore_reload) |
be4d35dc | 2909 | t->flags.ignore_reload = true; |
62e76326 | 2910 | |
38f9c547 | 2911 | if (ignore_no_store) |
be4d35dc | 2912 | t->flags.ignore_no_store = true; |
38f9c547 | 2913 | |
4ca08219 | 2914 | if (ignore_must_revalidate) |
be4d35dc | 2915 | t->flags.ignore_must_revalidate = true; |
4ca08219 | 2916 | |
38f9c547 | 2917 | if (ignore_private) |
be4d35dc | 2918 | t->flags.ignore_private = true; |
38f9c547 | 2919 | |
2920 | if (ignore_auth) | |
be4d35dc | 2921 | t->flags.ignore_auth = true; |
38f9c547 | 2922 | |
9f60cfdf | 2923 | #endif |
62e76326 | 2924 | |
f1dc9b30 | 2925 | t->next = NULL; |
62e76326 | 2926 | |
f1dc9b30 | 2927 | while (*head) |
62e76326 | 2928 | head = &(*head)->next; |
2929 | ||
f1dc9b30 | 2930 | *head = t; |
62e76326 | 2931 | |
f1dc9b30 | 2932 | safe_free(pattern); |
270b86af | 2933 | } |
090089c4 | 2934 | |
270b86af | 2935 | static void |
8d9a8184 | 2936 | free_refreshpattern(RefreshPattern ** head) |
270b86af | 2937 | { |
8d9a8184 | 2938 | RefreshPattern *t; |
62e76326 | 2939 | |
79d39a72 | 2940 | while ((t = *head) != NULL) { |
62e76326 | 2941 | *head = t->next; |
2942 | safe_free(t->pattern); | |
2943 | regfree(&t->compiled_pattern); | |
2944 | safe_free(t); | |
f1dc9b30 | 2945 | } |
c2066637 | 2946 | |
626096be | 2947 | #if USE_HTTP_VIOLATIONS |
c2066637 | 2948 | refresh_nocache_hack = 0; |
8970d351 | 2949 | |
2950 | #endif | |
270b86af | 2951 | } |
12b9e9b1 | 2952 | |
270b86af | 2953 | static void |
a7d59104 | 2954 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 2955 | { |
f53b06f9 | 2956 | if (var != NULL) |
62e76326 | 2957 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 2958 | } |
98ffb7e4 | 2959 | |
270b86af | 2960 | static void |
0153d498 | 2961 | parse_string(char **var) |
270b86af | 2962 | { |
2eceb328 | 2963 | char *token = ConfigParser::NextToken(); |
270b86af | 2964 | safe_free(*var); |
62e76326 | 2965 | |
270b86af | 2966 | if (token == NULL) |
62e76326 | 2967 | self_destruct(); |
2968 | ||
270b86af | 2969 | *var = xstrdup(token); |
2970 | } | |
b15e6857 | 2971 | |
0153d498 | 2972 | static void |
2973 | free_string(char **var) | |
2974 | { | |
027acbaf | 2975 | safe_free(*var); |
0153d498 | 2976 | } |
caebbe00 | 2977 | |
94439e4e | 2978 | void |
f1dc9b30 | 2979 | parse_eol(char *volatile *var) |
270b86af | 2980 | { |
65657c1a AJ |
2981 | if (!var) { |
2982 | self_destruct(); | |
2983 | return; | |
2984 | } | |
2985 | ||
2eceb328 | 2986 | unsigned char *token = (unsigned char *) ConfigParser::NextQuotedOrToEol(); |
270b86af | 2987 | safe_free(*var); |
62e76326 | 2988 | |
9eeb8e4b | 2989 | if (!token) { |
62e76326 | 2990 | self_destruct(); |
9eeb8e4b | 2991 | return; |
2992 | } | |
62e76326 | 2993 | |
e4755e29 | 2994 | while (*token && xisspace(*token)) |
a38ec4b1 | 2995 | ++token; |
62e76326 | 2996 | |
9eeb8e4b | 2997 | if (!*token) { |
62e76326 | 2998 | self_destruct(); |
9eeb8e4b | 2999 | return; |
3000 | } | |
62e76326 | 3001 | |
852751f7 | 3002 | *var = xstrdup((char *) token); |
270b86af | 3003 | } |
090089c4 | 3004 | |
52d3f198 | 3005 | #define dump_eol dump_string |
3006 | #define free_eol free_string | |
3007 | ||
b11724bb CT |
3008 | static void |
3009 | parse_TokenOrQuotedString(char **var) | |
3010 | { | |
3011 | char *token = ConfigParser::NextQuotedToken(); | |
3012 | safe_free(*var); | |
3013 | ||
3014 | if (token == NULL) | |
3015 | self_destruct(); | |
3016 | ||
3017 | *var = xstrdup(token); | |
3018 | } | |
3019 | ||
3020 | #define dump_TokenOrQuotedString dump_string | |
3021 | #define free_TokenOrQuotedString free_string | |
3022 | ||
270b86af | 3023 | static void |
a7d59104 | 3024 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 3025 | { |
f53b06f9 | 3026 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 3027 | } |
3028 | ||
94439e4e | 3029 | void |
a47b9029 | 3030 | parse_time_t(time_t * var) |
0ffd22bc | 3031 | { |
fd0f51c4 | 3032 | time_msec_t tval; |
9b741834 | 3033 | parseTimeLine(&tval, T_SECOND_STR, false); |
fd0f51c4 | 3034 | *var = static_cast<time_t>(tval/1000); |
0ffd22bc | 3035 | } |
3036 | ||
270b86af | 3037 | static void |
a47b9029 | 3038 | free_time_t(time_t * var) |
270b86af | 3039 | { |
a47b9029 | 3040 | *var = 0; |
270b86af | 3041 | } |
9906e724 | 3042 | |
fd0f51c4 CT |
3043 | static void |
3044 | dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var) | |
3045 | { | |
3046 | if (var % 1000) | |
c91ca3ce | 3047 | storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var); |
fd0f51c4 CT |
3048 | else |
3049 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) ); | |
3050 | } | |
3051 | ||
3052 | void | |
3053 | parse_time_msec(time_msec_t * var) | |
3054 | { | |
9b741834 | 3055 | parseTimeLine(var, T_SECOND_STR, true); |
fd0f51c4 CT |
3056 | } |
3057 | ||
3058 | static void | |
3059 | free_time_msec(time_msec_t * var) | |
3060 | { | |
3061 | *var = 0; | |
3062 | } | |
3063 | ||
0477a072 | 3064 | #if UNUSED_CODE |
9906e724 | 3065 | static void |
a7d59104 | 3066 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 3067 | { |
f53b06f9 | 3068 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 3069 | } |
0477a072 | 3070 | #endif |
1b635117 | 3071 | |
3072 | static void | |
a7d59104 | 3073 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 3074 | { |
f53b06f9 | 3075 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 3076 | } |
3077 | ||
e210930b AJ |
3078 | static void |
3079 | dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var) | |
3080 | { | |
3081 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); | |
3082 | } | |
e210930b | 3083 | |
3e62bd58 | 3084 | #if UNUSED_CODE |
9906e724 | 3085 | static void |
a7d59104 | 3086 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 3087 | { |
f53b06f9 | 3088 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 3089 | } |
3e62bd58 | 3090 | #endif |
9906e724 | 3091 | |
47f6e231 | 3092 | static void |
3093 | dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
3094 | { | |
c91ca3ce | 3095 | storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR); |
47f6e231 | 3096 | } |
3097 | ||
3098 | static void | |
3099 | dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
3100 | { | |
c91ca3ce | 3101 | storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR); |
47f6e231 | 3102 | } |
3103 | ||
0477a072 | 3104 | #if UNUSED_CODE |
9906e724 | 3105 | static void |
a47b9029 | 3106 | parse_size_t(size_t * var) |
1b635117 | 3107 | { |
1b635117 | 3108 | int i; |
0e4e0e7d | 3109 | i = GetInteger(); |
1b635117 | 3110 | *var = (size_t) i; |
3111 | } | |
0477a072 | 3112 | #endif |
1b635117 | 3113 | |
3114 | static void | |
3115 | parse_b_size_t(size_t * var) | |
9906e724 | 3116 | { |
3117 | parseBytesLine(var, B_BYTES_STR); | |
3118 | } | |
3119 | ||
e210930b AJ |
3120 | static void |
3121 | parse_b_ssize_t(ssize_t * var) | |
3122 | { | |
3123 | parseBytesLineSigned(var, B_BYTES_STR); | |
3124 | } | |
e210930b | 3125 | |
3e62bd58 | 3126 | #if UNUSED_CODE |
9906e724 | 3127 | static void |
a47b9029 | 3128 | parse_kb_size_t(size_t * var) |
9906e724 | 3129 | { |
3130 | parseBytesLine(var, B_KBYTES_STR); | |
3131 | } | |
3e62bd58 | 3132 | #endif |
9906e724 | 3133 | |
47f6e231 | 3134 | static void |
3135 | parse_b_int64_t(int64_t * var) | |
3136 | { | |
3137 | parseBytesLine64(var, B_BYTES_STR); | |
3138 | } | |
3139 | ||
3140 | static void | |
3141 | parse_kb_int64_t(int64_t * var) | |
3142 | { | |
3143 | parseBytesLine64(var, B_KBYTES_STR); | |
3144 | } | |
3145 | ||
9906e724 | 3146 | static void |
a47b9029 | 3147 | free_size_t(size_t * var) |
9906e724 | 3148 | { |
a47b9029 | 3149 | *var = 0; |
9906e724 | 3150 | } |
3151 | ||
e210930b AJ |
3152 | static void |
3153 | free_ssize_t(ssize_t * var) | |
3154 | { | |
3155 | *var = 0; | |
3156 | } | |
e210930b | 3157 | |
47f6e231 | 3158 | static void |
3159 | free_b_int64_t(int64_t * var) | |
3160 | { | |
3161 | *var = 0; | |
3162 | } | |
3163 | ||
1b635117 | 3164 | #define free_b_size_t free_size_t |
e210930b | 3165 | #define free_b_ssize_t free_ssize_t |
9906e724 | 3166 | #define free_kb_size_t free_size_t |
3167 | #define free_mb_size_t free_size_t | |
3168 | #define free_gb_size_t free_size_t | |
47f6e231 | 3169 | #define free_kb_int64_t free_b_int64_t |
090089c4 | 3170 | |
8203a132 | 3171 | static void |
f45dd259 | 3172 | dump_u_short(StoreEntry * entry, const char *name, unsigned short var) |
090089c4 | 3173 | { |
f53b06f9 | 3174 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 3175 | } |
090089c4 | 3176 | |
0153d498 | 3177 | static void |
f45dd259 | 3178 | free_u_short(unsigned short * u) |
0153d498 | 3179 | { |
3180 | *u = 0; | |
3181 | } | |
3182 | ||
270b86af | 3183 | static void |
f45dd259 | 3184 | parse_u_short(unsigned short * var) |
b67e2c8c | 3185 | { |
3186 | ConfigParser::ParseUShort(var); | |
3187 | } | |
3188 | ||
3189 | void | |
f45dd259 | 3190 | ConfigParser::ParseUShort(unsigned short *var) |
270b86af | 3191 | { |
0e656b69 | 3192 | *var = GetShort(); |
090089c4 | 3193 | } |
3194 | ||
3a69ddf3 | 3195 | void |
3196 | ConfigParser::ParseBool(bool *var) | |
3197 | { | |
3198 | int i = GetInteger(); | |
3199 | ||
3200 | if (0 == i) | |
3201 | *var = false; | |
3202 | else if (1 == i) | |
3203 | *var = true; | |
3204 | else | |
3205 | self_destruct(); | |
3206 | } | |
3207 | ||
270b86af | 3208 | static void |
a7d59104 | 3209 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 3210 | { |
270b86af | 3211 | while (list != NULL) { |
62e76326 | 3212 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
3213 | list = list->next; | |
429fdbec | 3214 | } |
429fdbec | 3215 | } |
3216 | ||
3a69ddf3 | 3217 | void |
3218 | ConfigParser::ParseWordList(wordlist ** list) | |
3219 | { | |
3220 | parse_wordlist(list); | |
3221 | } | |
3222 | ||
94439e4e | 3223 | void |
270b86af | 3224 | parse_wordlist(wordlist ** list) |
429fdbec | 3225 | { |
270b86af | 3226 | char *token; |
bde7a8ce | 3227 | while ((token = ConfigParser::NextQuotedToken())) |
62e76326 | 3228 | wordlistAdd(list, token); |
429fdbec | 3229 | } |
270b86af | 3230 | |
b3d8a9e8 | 3231 | #if 0 /* now unused */ |
f8d9f54a | 3232 | static int |
5da06f20 | 3233 | check_null_wordlist(wordlist * w) |
f8d9f54a | 3234 | { |
3235 | return w == NULL; | |
3236 | } | |
b3d8a9e8 | 3237 | #endif |
f8d9f54a | 3238 | |
63e9d884 | 3239 | static int |
c6d5b87b | 3240 | check_null_acl_access(acl_access * a) |
63e9d884 | 3241 | { |
3242 | return a == NULL; | |
3243 | } | |
3244 | ||
0153d498 | 3245 | #define free_wordlist wordlistDestroy |
270b86af | 3246 | |
d548ee64 | 3247 | #define free_uri_whitespace free_int |
3248 | ||
3249 | static void | |
3250 | parse_uri_whitespace(int *var) | |
3251 | { | |
2eceb328 | 3252 | char *token = ConfigParser::NextToken(); |
62e76326 | 3253 | |
d548ee64 | 3254 | if (token == NULL) |
62e76326 | 3255 | self_destruct(); |
3256 | ||
a37d6070 | 3257 | if (!strcmp(token, "strip")) |
62e76326 | 3258 | *var = URI_WHITESPACE_STRIP; |
a37d6070 | 3259 | else if (!strcmp(token, "deny")) |
62e76326 | 3260 | *var = URI_WHITESPACE_DENY; |
a37d6070 | 3261 | else if (!strcmp(token, "allow")) |
62e76326 | 3262 | *var = URI_WHITESPACE_ALLOW; |
a37d6070 | 3263 | else if (!strcmp(token, "encode")) |
62e76326 | 3264 | *var = URI_WHITESPACE_ENCODE; |
a37d6070 | 3265 | else if (!strcmp(token, "chop")) |
62e76326 | 3266 | *var = URI_WHITESPACE_CHOP; |
54a063a2 TX |
3267 | else { |
3268 | debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'."); | |
62e76326 | 3269 | self_destruct(); |
54a063a2 | 3270 | } |
d548ee64 | 3271 | } |
3272 | ||
d548ee64 | 3273 | static void |
3274 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
3275 | { | |
c193c972 | 3276 | const char *s; |
62e76326 | 3277 | |
d548ee64 | 3278 | if (var == URI_WHITESPACE_ALLOW) |
62e76326 | 3279 | s = "allow"; |
d548ee64 | 3280 | else if (var == URI_WHITESPACE_ENCODE) |
62e76326 | 3281 | s = "encode"; |
d548ee64 | 3282 | else if (var == URI_WHITESPACE_CHOP) |
62e76326 | 3283 | s = "chop"; |
7e3ce7b9 | 3284 | else if (var == URI_WHITESPACE_DENY) |
62e76326 | 3285 | s = "deny"; |
7e3ce7b9 | 3286 | else |
62e76326 | 3287 | s = "strip"; |
3288 | ||
d548ee64 | 3289 | storeAppendPrintf(entry, "%s %s\n", name, s); |
3290 | } | |
3291 | ||
6a566b9c | 3292 | static void |
c1dd71ae | 3293 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 3294 | { |
3295 | if (!*settings) | |
62e76326 | 3296 | return; |
3297 | ||
6a566b9c | 3298 | free_string(&(*settings)->type); |
62e76326 | 3299 | |
6a566b9c | 3300 | free_wordlist(&(*settings)->args); |
62e76326 | 3301 | |
c8f4eac4 | 3302 | delete *settings; |
62e76326 | 3303 | |
6a566b9c | 3304 | *settings = NULL; |
3305 | } | |
3306 | ||
3307 | static void | |
c1dd71ae | 3308 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 3309 | { |
3310 | if (*settings) | |
62e76326 | 3311 | free_removalpolicy(settings); |
3312 | ||
c8f4eac4 | 3313 | *settings = new RemovalPolicySettings; |
62e76326 | 3314 | |
6a566b9c | 3315 | parse_string(&(*settings)->type); |
62e76326 | 3316 | |
6a566b9c | 3317 | parse_wordlist(&(*settings)->args); |
3318 | } | |
3319 | ||
3320 | static void | |
c1dd71ae | 3321 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 3322 | { |
3323 | wordlist *args; | |
3324 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
3325 | args = settings->args; | |
62e76326 | 3326 | |
6a566b9c | 3327 | while (args) { |
62e76326 | 3328 | storeAppendPrintf(entry, " %s", args->key); |
3329 | args = args->next; | |
6a566b9c | 3330 | } |
62e76326 | 3331 | |
be58afb5 | 3332 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 3333 | } |
c1dd71ae | 3334 | |
de0cb3d8 AR |
3335 | inline void |
3336 | free_YesNoNone(YesNoNone *) | |
57af1e3f | 3337 | { |
de0cb3d8 | 3338 | // do nothing: no explicit cleanup is required |
57af1e3f AR |
3339 | } |
3340 | ||
3341 | static void | |
3342 | parse_YesNoNone(YesNoNone *option) | |
3343 | { | |
3344 | int value = 0; | |
3345 | parse_onoff(&value); | |
3346 | option->configure(value > 0); | |
3347 | } | |
3348 | ||
3349 | static void | |
3350 | dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option) | |
3351 | { | |
3352 | if (option.configured()) | |
3353 | dump_onoff(entry, name, option ? 1 : 0); | |
3354 | } | |
3355 | ||
ea21d497 HN |
3356 | static void |
3357 | free_memcachemode(SquidConfig * config) | |
3358 | { | |
3359 | return; | |
3360 | } | |
3361 | ||
3362 | static void | |
3363 | parse_memcachemode(SquidConfig * config) | |
3364 | { | |
2eceb328 | 3365 | char *token = ConfigParser::NextToken(); |
ea21d497 | 3366 | if (!token) |
e1381638 | 3367 | self_destruct(); |
ea21d497 | 3368 | |
10aeba1d | 3369 | if (strcmp(token, "always") == 0) { |
e1381638 AJ |
3370 | Config.onoff.memory_cache_first = 1; |
3371 | Config.onoff.memory_cache_disk = 1; | |
10aeba1d | 3372 | } else if (strcmp(token, "disk") == 0) { |
e1381638 AJ |
3373 | Config.onoff.memory_cache_first = 0; |
3374 | Config.onoff.memory_cache_disk = 1; | |
ea21d497 | 3375 | } else if (strncmp(token, "net", 3) == 0) { |
e1381638 AJ |
3376 | Config.onoff.memory_cache_first = 1; |
3377 | Config.onoff.memory_cache_disk = 0; | |
10aeba1d | 3378 | } else if (strcmp(token, "never") == 0) { |
e1381638 AJ |
3379 | Config.onoff.memory_cache_first = 0; |
3380 | Config.onoff.memory_cache_disk = 0; | |
54a063a2 TX |
3381 | } else { |
3382 | debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token << "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'."); | |
e1381638 | 3383 | self_destruct(); |
54a063a2 | 3384 | } |
ea21d497 HN |
3385 | } |
3386 | ||
3387 | static void | |
3388 | dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config) | |
3389 | { | |
3390 | storeAppendPrintf(entry, "%s ", name); | |
3391 | if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) | |
e1381638 | 3392 | storeAppendPrintf(entry, "always"); |
ea21d497 | 3393 | else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) |
e1381638 | 3394 | storeAppendPrintf(entry, "disk"); |
ea21d497 | 3395 | else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3396 | storeAppendPrintf(entry, "network"); |
ea21d497 | 3397 | else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3398 | storeAppendPrintf(entry, "none"); |
ea21d497 HN |
3399 | storeAppendPrintf(entry, "\n"); |
3400 | } | |
3401 | ||
cca8ba0d | 3402 | #include "cf_parser.cci" |
f1dc9b30 | 3403 | |
3404 | peer_t | |
3405 | parseNeighborType(const char *s) | |
3406 | { | |
a37d6070 | 3407 | if (!strcmp(s, "parent")) |
62e76326 | 3408 | return PEER_PARENT; |
3409 | ||
a37d6070 | 3410 | if (!strcmp(s, "neighbor")) |
62e76326 | 3411 | return PEER_SIBLING; |
3412 | ||
a37d6070 | 3413 | if (!strcmp(s, "neighbour")) |
62e76326 | 3414 | return PEER_SIBLING; |
3415 | ||
a37d6070 | 3416 | if (!strcmp(s, "sibling")) |
62e76326 | 3417 | return PEER_SIBLING; |
3418 | ||
a37d6070 | 3419 | if (!strcmp(s, "multicast")) |
62e76326 | 3420 | return PEER_MULTICAST; |
3421 | ||
fa84c01d | 3422 | debugs(15, DBG_CRITICAL, "WARNING: Unknown neighbor type: " << s); |
62e76326 | 3423 | |
f1dc9b30 | 3424 | return PEER_SIBLING; |
3425 | } | |
f150dd4b | 3426 | |
0b0cfcf2 | 3427 | #if USE_WCCPv2 |
52f772de | 3428 | static void |
b7ac5457 | 3429 | parse_IpAddress_list(Ip::Address_list ** head) |
52f772de | 3430 | { |
3431 | char *token; | |
b7ac5457 AJ |
3432 | Ip::Address_list *s; |
3433 | Ip::Address ipa; | |
62e76326 | 3434 | |
2eceb328 | 3435 | while ((token = ConfigParser::NextToken())) { |
82b7abe3 AJ |
3436 | if (GetHostWithPort(token, &ipa)) { |
3437 | ||
3438 | while (*head) | |
3439 | head = &(*head)->next; | |
3440 | ||
b7ac5457 | 3441 | s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s))); |
82b7abe3 AJ |
3442 | s->s = ipa; |
3443 | ||
3444 | *head = s; | |
9d65168e | 3445 | } else |
82b7abe3 | 3446 | self_destruct(); |
7e3ce7b9 | 3447 | } |
3448 | } | |
3449 | ||
3450 | static void | |
b7ac5457 | 3451 | dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s) |
7e3ce7b9 | 3452 | { |
cc192b50 | 3453 | char ntoabuf[MAX_IPSTRLEN]; |
3454 | ||
7e3ce7b9 | 3455 | while (s) { |
cc192b50 | 3456 | storeAppendPrintf(e, "%s %s\n", |
62e76326 | 3457 | n, |
4dd643d5 | 3458 | s->s.toStr(ntoabuf,MAX_IPSTRLEN)); |
62e76326 | 3459 | s = s->next; |
7e3ce7b9 | 3460 | } |
3461 | } | |
3462 | ||
3463 | static void | |
b7ac5457 | 3464 | free_IpAddress_list(Ip::Address_list ** head) |
7e3ce7b9 | 3465 | { |
26ac0430 AJ |
3466 | if (*head) delete *head; |
3467 | *head = NULL; | |
7e3ce7b9 | 3468 | } |
3469 | ||
0b0cfcf2 | 3470 | #if CURRENTLY_UNUSED |
3471 | /* This code was previously used by http_port. Left as it really should | |
3472 | * be used by icp_port and htcp_port | |
3473 | */ | |
7e3ce7b9 | 3474 | static int |
b7ac5457 | 3475 | check_null_IpAddress_list(const Ip::Address_list * s) |
7e3ce7b9 | 3476 | { |
3477 | return NULL == s; | |
3478 | } | |
62e76326 | 3479 | |
3f38a55e | 3480 | #endif /* CURRENTLY_UNUSED */ |
0b0cfcf2 | 3481 | #endif /* USE_WCCPv2 */ |
7e3ce7b9 | 3482 | |
d193a436 | 3483 | static void |
fa720bfb | 3484 | parsePortSpecification(const AnyP::PortCfgPointer &s, char *token) |
d193a436 | 3485 | { |
3f38a55e | 3486 | char *host = NULL; |
3f38a55e | 3487 | unsigned short port = 0; |
cc192b50 | 3488 | char *t = NULL; |
3489 | char *junk = NULL; | |
62e76326 | 3490 | |
5529ca8a | 3491 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; |
13adaf1f | 3492 | s->name = xstrdup(token); |
d67acb4e | 3493 | s->connection_auth_disabled = false; |
5529ca8a | 3494 | |
1ca54a54 | 3495 | const char *portType = AnyP::UriScheme(s->transport.protocol).c_str(); |
eb6ac808 | 3496 | |
cc192b50 | 3497 | if (*token == '[') { |
3498 | /* [ipv6]:port */ | |
26ac0430 AJ |
3499 | host = token + 1; |
3500 | t = strchr(host, ']'); | |
3501 | if (!t) { | |
eb6ac808 | 3502 | debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing ']' on IPv6 address: " << token); |
26ac0430 | 3503 | self_destruct(); |
cc192b50 | 3504 | } |
a38ec4b1 FC |
3505 | *t = '\0'; |
3506 | ++t; | |
26ac0430 | 3507 | if (*t != ':') { |
eb6ac808 | 3508 | debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port in: " << token); |
26ac0430 | 3509 | self_destruct(); |
cc192b50 | 3510 | } |
055421ee | 3511 | if (!Ip::EnableIpv6) { |
eb6ac808 | 3512 | debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: IPv6 is not available."); |
26ac0430 AJ |
3513 | self_destruct(); |
3514 | } | |
055421ee AJ |
3515 | port = xatos(t + 1); |
3516 | } else if ((t = strchr(token, ':'))) { | |
3517 | /* host:port */ | |
3518 | /* ipv4:port */ | |
3519 | host = token; | |
3520 | *t = '\0'; | |
3521 | port = xatos(t + 1); | |
3522 | ||
54a063a2 TX |
3523 | } else if (strtol(token, &junk, 10) && !*junk) { |
3524 | port = xatos(token); | |
eb6ac808 | 3525 | debugs(3, 3, portType << "_port: found Listen on Port: " << port); |
055421ee | 3526 | } else { |
eb6ac808 | 3527 | debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: missing Port: " << token); |
055421ee AJ |
3528 | self_destruct(); |
3529 | } | |
62e76326 | 3530 | |
859741ed | 3531 | if (port == 0 && host != NULL) { |
eb6ac808 | 3532 | debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: Port cannot be 0: " << token); |
0e656b69 | 3533 | self_destruct(); |
cc192b50 | 3534 | } |
0e656b69 | 3535 | |
cc192b50 | 3536 | if (NULL == host) { |
4dd643d5 AJ |
3537 | s->s.setAnyAddr(); |
3538 | s->s.port(port); | |
6df7ad56 | 3539 | if (!Ip::EnableIpv6) |
4dd643d5 | 3540 | s->s.setIPv4(); |
eb6ac808 | 3541 | debugs(3, 3, portType << "_port: found Listen on wildcard address: *:" << s->s.port()); |
c49d44e1 | 3542 | } else if ( (s->s = host) ) { /* check/parse numeric IPA */ |
4dd643d5 | 3543 | s->s.port(port); |
6df7ad56 | 3544 | if (!Ip::EnableIpv6) |
4dd643d5 | 3545 | s->s.setIPv4(); |
eb6ac808 | 3546 | debugs(3, 3, portType << "_port: Listen on Host/IP: " << host << " --> " << s->s); |
26ac0430 | 3547 | } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */ |
62e76326 | 3548 | /* dont use ipcache */ |
62e76326 | 3549 | s->defaultsite = xstrdup(host); |
4dd643d5 | 3550 | s->s.port(port); |
6df7ad56 | 3551 | if (!Ip::EnableIpv6) |
4dd643d5 | 3552 | s->s.setIPv4(); |
eb6ac808 | 3553 | debugs(3, 3, portType << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s); |
26ac0430 | 3554 | } else { |
eb6ac808 | 3555 | debugs(3, DBG_CRITICAL, "FATAL: " << portType << "_port: failed to resolve Host/IP: " << host); |
62e76326 | 3556 | self_destruct(); |
cc192b50 | 3557 | } |
3f38a55e | 3558 | } |
3559 | ||
ecb19f1a AR |
3560 | /// parses the protocol= option of the *_port directive, returning parsed value |
3561 | /// unsupported option values result in a fatal error message | |
3cc0f4e7 | 3562 | /// upper case values required; caller may convert for backward compatibility |
ecb19f1a | 3563 | static AnyP::ProtocolVersion |
3cc0f4e7 | 3564 | parsePortProtocol(const SBuf &value) |
ecb19f1a AR |
3565 | { |
3566 | // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0 | |
3567 | // and RFC 2616 requires us to upgrade 1.0 to 1.1 | |
3cc0f4e7 | 3568 | if (value.cmp("HTTP") == 0 || value.cmp("HTTP/1.1") == 0) |
ecb19f1a AR |
3569 | return AnyP::ProtocolVersion(AnyP::PROTO_HTTP, 1,1); |
3570 | ||
3cc0f4e7 | 3571 | if (value.cmp("HTTPS") == 0 || value.cmp("HTTPS/1.1") == 0) |
ecb19f1a AR |
3572 | return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS, 1,1); |
3573 | ||
3cc0f4e7 | 3574 | if (value.cmp("FTP") == 0) |
aea65fec | 3575 | return Ftp::ProtocolVersion(); |
ecb19f1a | 3576 | |
3cc0f4e7 | 3577 | fatalf("%s directive does not support protocol=" SQUIDSBUFPH "\n", cfg_directive, SQUIDSBUFPRINT(value)); |
ecb19f1a AR |
3578 | return AnyP::ProtocolVersion(); // not reached |
3579 | } | |
3580 | ||
3f38a55e | 3581 | static void |
fa720bfb | 3582 | parse_port_option(AnyP::PortCfgPointer &s, char *token) |
3f38a55e | 3583 | { |
c7b1dd5d AJ |
3584 | /* modes first */ |
3585 | ||
3586 | if (strcmp(token, "accel") == 0) { | |
c3d24490 | 3587 | if (s->flags.isIntercepted()) { |
3cc0f4e7 | 3588 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Accelerator mode requires its own port. It cannot be shared with other modes."); |
c7b1dd5d AJ |
3589 | self_destruct(); |
3590 | } | |
6a25a046 | 3591 | s->flags.accelSurrogate = true; |
86ab7a90 | 3592 | s->vhost = true; |
c7b1dd5d | 3593 | } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) { |
6a25a046 | 3594 | if (s->flags.accelSurrogate || s->flags.tproxyIntercept) { |
3cc0f4e7 | 3595 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": Intercept mode requires its own interception port. It cannot be shared with other modes."); |
c7b1dd5d AJ |
3596 | self_destruct(); |
3597 | } | |
6a25a046 | 3598 | s->flags.natIntercept = true; |
c7b1dd5d AJ |
3599 | Ip::Interceptor.StartInterception(); |
3600 | /* Log information regarding the port modes under interception. */ | |
3601 | debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s); | |
3602 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)"); | |
c7b1dd5d | 3603 | } else if (strcmp(token, "tproxy") == 0) { |
6a25a046 | 3604 | if (s->flags.natIntercept || s->flags.accelSurrogate) { |
3cc0f4e7 | 3605 | debugs(3,DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY option requires its own interception port. It cannot be shared with other modes."); |
c7b1dd5d AJ |
3606 | self_destruct(); |
3607 | } | |
6a25a046 | 3608 | s->flags.tproxyIntercept = true; |
c7b1dd5d AJ |
3609 | Ip::Interceptor.StartTransparency(); |
3610 | /* Log information regarding the port modes under transparency. */ | |
0d901ef4 | 3611 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (TPROXY enabled)"); |
c7b1dd5d | 3612 | |
151ba0d4 | 3613 | if (s->flags.proxySurrogate) { |
d3d92daa | 3614 | debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)"); |
151ba0d4 AJ |
3615 | } |
3616 | ||
c7b1dd5d | 3617 | if (!Ip::Interceptor.ProbeForTproxy(s->s)) { |
3cc0f4e7 | 3618 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": TPROXY support in the system does not work."); |
c7b1dd5d AJ |
3619 | self_destruct(); |
3620 | } | |
3621 | ||
d3d92daa | 3622 | } else if (strcmp(token, "require-proxy-header") == 0) { |
00d0ce87 | 3623 | s->flags.proxySurrogate = true; |
13edf4cc AJ |
3624 | if (s->flags.tproxyIntercept) { |
3625 | // receiving is still permitted, so we do not unset the TPROXY flag | |
3626 | // spoofing access control override takes care of the spoof disable later | |
3627 | debugs(3, DBG_IMPORTANT, "Disabling TPROXY Spoofing on port " << s->s << " (require-proxy-header enabled)"); | |
3628 | } | |
00d0ce87 | 3629 | |
c7b1dd5d | 3630 | } else if (strncmp(token, "defaultsite=", 12) == 0) { |
6a25a046 | 3631 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3632 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": defaultsite option requires Acceleration mode flag."); |
c7b1dd5d AJ |
3633 | self_destruct(); |
3634 | } | |
62e76326 | 3635 | safe_free(s->defaultsite); |
3636 | s->defaultsite = xstrdup(token + 12); | |
3f38a55e | 3637 | } else if (strcmp(token, "vhost") == 0) { |
6a25a046 | 3638 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3639 | debugs(3, DBG_CRITICAL, "WARNING: " << cfg_directive << ": vhost option is deprecated. Use 'accel' mode flag instead."); |
cf673853 | 3640 | } |
6a25a046 | 3641 | s->flags.accelSurrogate = true; |
86ab7a90 | 3642 | s->vhost = true; |
cf673853 | 3643 | } else if (strcmp(token, "no-vhost") == 0) { |
6a25a046 | 3644 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3645 | debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": no-vhost option requires Acceleration mode flag."); |
c7b1dd5d | 3646 | } |
86ab7a90 | 3647 | s->vhost = false; |
3f38a55e | 3648 | } else if (strcmp(token, "vport") == 0) { |
6a25a046 | 3649 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3650 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag."); |
c7b1dd5d AJ |
3651 | self_destruct(); |
3652 | } | |
62e76326 | 3653 | s->vport = -1; |
3f38a55e | 3654 | } else if (strncmp(token, "vport=", 6) == 0) { |
6a25a046 | 3655 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3656 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": vport option requires Acceleration mode flag."); |
c7b1dd5d AJ |
3657 | self_destruct(); |
3658 | } | |
0e656b69 | 3659 | s->vport = xatos(token + 6); |
3f38a55e | 3660 | } else if (strncmp(token, "protocol=", 9) == 0) { |
6a25a046 | 3661 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3662 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": protocol option requires Acceleration mode flag."); |
c7b1dd5d AJ |
3663 | self_destruct(); |
3664 | } | |
3cc0f4e7 | 3665 | s->transport = parsePortProtocol(ToUpper(SBuf(token + 9))); |
7f7bdd96 | 3666 | } else if (strcmp(token, "allow-direct") == 0) { |
6a25a046 | 3667 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3668 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": allow-direct option requires Acceleration mode flag."); |
c7b1dd5d AJ |
3669 | self_destruct(); |
3670 | } | |
86ab7a90 | 3671 | s->allow_direct = true; |
90fa5816 | 3672 | } else if (strcmp(token, "act-as-origin") == 0) { |
6a25a046 | 3673 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3674 | debugs(3, DBG_IMPORTANT, "ERROR: " << cfg_directive << ": act-as-origin option requires Acceleration mode flag."); |
90fa5816 | 3675 | } else |
86ab7a90 | 3676 | s->actAsOrigin = true; |
432bc83c | 3677 | } else if (strcmp(token, "ignore-cc") == 0) { |
626096be | 3678 | #if !USE_HTTP_VIOLATIONS |
6a25a046 | 3679 | if (!s->flags.accelSurrogate) { |
3cc0f4e7 | 3680 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": ignore-cc option requires Acceleration mode flag."); |
838daf3f A |
3681 | self_destruct(); |
3682 | } | |
432bc83c | 3683 | #endif |
86ab7a90 | 3684 | s->ignore_cc = true; |
c7b1dd5d AJ |
3685 | } else if (strncmp(token, "name=", 5) == 0) { |
3686 | safe_free(s->name); | |
3687 | s->name = xstrdup(token + 5); | |
d67acb4e AJ |
3688 | } else if (strcmp(token, "no-connection-auth") == 0) { |
3689 | s->connection_auth_disabled = true; | |
3690 | } else if (strcmp(token, "connection-auth=off") == 0) { | |
26ac0430 | 3691 | s->connection_auth_disabled = true; |
d67acb4e | 3692 | } else if (strcmp(token, "connection-auth") == 0) { |
26ac0430 | 3693 | s->connection_auth_disabled = false; |
d67acb4e | 3694 | } else if (strcmp(token, "connection-auth=on") == 0) { |
26ac0430 | 3695 | s->connection_auth_disabled = false; |
5529ca8a | 3696 | } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) { |
a37d6070 | 3697 | if (!strcmp(token + 23, "off")) |
5529ca8a | 3698 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; |
a37d6070 | 3699 | else if (!strcmp(token + 23, "transparent")) |
5529ca8a | 3700 | s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT; |
a37d6070 | 3701 | else if (!strcmp(token + 23, "always")) |
5529ca8a | 3702 | s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS; |
3703 | else | |
3704 | self_destruct(); | |
cc192b50 | 3705 | } else if (strcmp(token, "ipv4") == 0) { |
4dd643d5 | 3706 | if ( !s->s.setIPv4() ) { |
3cc0f4e7 | 3707 | debugs(3, DBG_CRITICAL, "FATAL: " << cfg_directive << ": IPv6 addresses cannot be used as IPv4-Only. " << s->s ); |
cc192b50 | 3708 | self_destruct(); |
3709 | } | |
26ac0430 | 3710 | } else if (strcmp(token, "tcpkeepalive") == 0) { |
86ab7a90 | 3711 | s->tcp_keepalive.enabled = true; |
b2130d58 | 3712 | } else if (strncmp(token, "tcpkeepalive=", 13) == 0) { |
26ac0430 | 3713 | char *t = token + 13; |
86ab7a90 | 3714 | s->tcp_keepalive.enabled = true; |
e398d16e | 3715 | s->tcp_keepalive.idle = xatoui(t,','); |
26ac0430 AJ |
3716 | t = strchr(t, ','); |
3717 | if (t) { | |
a38ec4b1 | 3718 | ++t; |
e398d16e | 3719 | s->tcp_keepalive.interval = xatoui(t,','); |
26ac0430 AJ |
3720 | t = strchr(t, ','); |
3721 | } | |
3722 | if (t) { | |
a38ec4b1 | 3723 | ++t; |
54a063a2 | 3724 | s->tcp_keepalive.timeout = xatoui(t); |
26ac0430 | 3725 | } |
cb4f4424 | 3726 | #if USE_OPENSSL |
a37d6070 | 3727 | } else if (strcmp(token, "sslBump") == 0) { |
3a0c8eb5 | 3728 | debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " << |
3cc0f4e7 | 3729 | "in " << cfg_directive << ". Use 'ssl-bump' instead."); |
c3d24490 | 3730 | s->flags.tunnelSslBumping = true; |
3a0c8eb5 | 3731 | } else if (strcmp(token, "ssl-bump") == 0) { |
c3d24490 | 3732 | s->flags.tunnelSslBumping = true; |
154dc884 | 3733 | } else if (strncmp(token, "cert=", 5) == 0) { |
3734 | safe_free(s->cert); | |
3735 | s->cert = xstrdup(token + 5); | |
3736 | } else if (strncmp(token, "key=", 4) == 0) { | |
3737 | safe_free(s->key); | |
3738 | s->key = xstrdup(token + 4); | |
3739 | } else if (strncmp(token, "version=", 8) == 0) { | |
3740 | s->version = xatoi(token + 8); | |
154dc884 | 3741 | if (s->version < 1 || s->version > 4) |
3742 | self_destruct(); | |
3743 | } else if (strncmp(token, "options=", 8) == 0) { | |
3744 | safe_free(s->options); | |
3745 | s->options = xstrdup(token + 8); | |
3746 | } else if (strncmp(token, "cipher=", 7) == 0) { | |
3747 | safe_free(s->cipher); | |
3748 | s->cipher = xstrdup(token + 7); | |
3749 | } else if (strncmp(token, "clientca=", 9) == 0) { | |
3750 | safe_free(s->clientca); | |
3751 | s->clientca = xstrdup(token + 9); | |
3752 | } else if (strncmp(token, "cafile=", 7) == 0) { | |
3753 | safe_free(s->cafile); | |
3754 | s->cafile = xstrdup(token + 7); | |
3755 | } else if (strncmp(token, "capath=", 7) == 0) { | |
3756 | safe_free(s->capath); | |
3757 | s->capath = xstrdup(token + 7); | |
3758 | } else if (strncmp(token, "crlfile=", 8) == 0) { | |
3759 | safe_free(s->crlfile); | |
3760 | s->crlfile = xstrdup(token + 8); | |
3761 | } else if (strncmp(token, "dhparams=", 9) == 0) { | |
3762 | safe_free(s->dhfile); | |
3763 | s->dhfile = xstrdup(token + 9); | |
3764 | } else if (strncmp(token, "sslflags=", 9) == 0) { | |
3765 | safe_free(s->sslflags); | |
3766 | s->sslflags = xstrdup(token + 9); | |
3767 | } else if (strncmp(token, "sslcontext=", 11) == 0) { | |
95d2589c CT |
3768 | safe_free(s->sslContextSessionId); |
3769 | s->sslContextSessionId = xstrdup(token + 11); | |
3770 | } else if (strcmp(token, "generate-host-certificates") == 0) { | |
3771 | s->generateHostCertificates = true; | |
3772 | } else if (strcmp(token, "generate-host-certificates=on") == 0) { | |
3773 | s->generateHostCertificates = true; | |
3774 | } else if (strcmp(token, "generate-host-certificates=off") == 0) { | |
3775 | s->generateHostCertificates = false; | |
3776 | } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) { | |
3777 | parseBytesOptionValue(&s->dynamicCertMemCacheSize, B_BYTES_STR, token + 28); | |
154dc884 | 3778 | #endif |
3cc0f4e7 | 3779 | } else if (strcmp(token, "ftp-track-dirs") == 0) { |
27c841f6 | 3780 | s->ftp_track_dirs = true; |
3f38a55e | 3781 | } else { |
3cc0f4e7 | 3782 | debugs(3, DBG_CRITICAL, "FATAL: Unknown " << cfg_directive << " option '" << token << "'."); |
62e76326 | 3783 | self_destruct(); |
3f38a55e | 3784 | } |
3785 | } | |
3786 | ||
3f38a55e | 3787 | void |
3788 | add_http_port(char *portspec) | |
3789 | { | |
fa720bfb | 3790 | AnyP::PortCfgPointer s = new AnyP::PortCfg(); |
3cc0f4e7 | 3791 | s->transport = parsePortProtocol(SBuf("HTTP")); |
859741ed | 3792 | parsePortSpecification(s, portspec); |
65d448bc | 3793 | // we may need to merge better if the above returns a list with clones |
7e07ced1 | 3794 | assert(s->next == NULL); |
fa720bfb AJ |
3795 | s->next = HttpPortList; |
3796 | HttpPortList = s; | |
3f38a55e | 3797 | } |
3798 | ||
3799 | static void | |
fa720bfb | 3800 | parsePortCfg(AnyP::PortCfgPointer *head, const char *optionName) |
d3388e1f | 3801 | { |
3cc0f4e7 | 3802 | SBuf protoName; |
d3388e1f | 3803 | if (strcmp(optionName, "http_port") == 0 || |
b5944cff | 3804 | strcmp(optionName, "ascii_port") == 0) |
3cc0f4e7 | 3805 | protoName = "HTTP"; |
d3388e1f | 3806 | else if (strcmp(optionName, "https_port") == 0) |
3cc0f4e7 | 3807 | protoName = "HTTPS"; |
434a79b0 | 3808 | else if (strcmp(optionName, "ftp_port") == 0) |
3cc0f4e7 AR |
3809 | protoName = "FTP"; |
3810 | if (protoName.isEmpty()) { | |
d3388e1f AR |
3811 | self_destruct(); |
3812 | return; | |
3813 | } | |
3814 | ||
2eceb328 | 3815 | char *token = ConfigParser::NextToken(); |
62e76326 | 3816 | |
9eeb8e4b | 3817 | if (!token) { |
62e76326 | 3818 | self_destruct(); |
9eeb8e4b | 3819 | return; |
3820 | } | |
62e76326 | 3821 | |
fa720bfb | 3822 | AnyP::PortCfgPointer s = new AnyP::PortCfg(); |
3cc0f4e7 | 3823 | s->transport = parsePortProtocol(protoName); // default; protocol=... overwrites |
859741ed | 3824 | parsePortSpecification(s, token); |
62e76326 | 3825 | |
3f38a55e | 3826 | /* parse options ... */ |
2eceb328 | 3827 | while ((token = ConfigParser::NextToken())) { |
65d448bc | 3828 | parse_port_option(s, token); |
3f38a55e | 3829 | } |
62e76326 | 3830 | |
6507233b | 3831 | if (s->transport.protocol == AnyP::PROTO_HTTPS) { |
151ba0d4 | 3832 | #if USE_OPENSSL |
38450a50 | 3833 | /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */ |
c3d24490 | 3834 | const bool hijacked = s->flags.isIntercepted(); |
6a25a046 | 3835 | if (s->flags.tunnelSslBumping && !hijacked) { |
38450a50 | 3836 | debugs(3, DBG_CRITICAL, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing."); |
03f00a11 CT |
3837 | self_destruct(); |
3838 | } | |
6a25a046 | 3839 | if (hijacked && !s->flags.tunnelSslBumping) { |
38450a50 | 3840 | debugs(3, DBG_CRITICAL, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing."); |
03f00a11 CT |
3841 | self_destruct(); |
3842 | } | |
03f00a11 | 3843 | #endif |
a07a354f | 3844 | if (s->flags.proxySurrogate) { |
d3d92daa | 3845 | debugs(3,DBG_CRITICAL, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports."); |
151ba0d4 AJ |
3846 | self_destruct(); |
3847 | } | |
3cc0f4e7 | 3848 | } else if (protoName.cmp("FTP") == 0) { |
434a79b0 DK |
3849 | /* ftp_port does not support ssl-bump */ |
3850 | if (s->flags.tunnelSslBumping) { | |
3851 | debugs(3, DBG_CRITICAL, "FATAL: ssl-bump is not supported for ftp_port."); | |
3852 | self_destruct(); | |
3853 | } | |
a07a354f AJ |
3854 | if (s->flags.proxySurrogate) { |
3855 | // Passive FTP data channel does not work without deep protocol inspection in the frontend. | |
3856 | debugs(3,DBG_CRITICAL, "FATAL: require-proxy-header option is not supported on ftp_port."); | |
3857 | self_destruct(); | |
3858 | } | |
03f00a11 | 3859 | } |
03f00a11 | 3860 | |
4dd643d5 | 3861 | if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.isAnyAddr()) { |
7e07ced1 | 3862 | // clone the port options from *s to *(s->next) |
fa720bfb | 3863 | s->next = s->clone(); |
4dd643d5 | 3864 | s->next->s.setIPv4(); |
1ca54a54 | 3865 | debugs(3, 3, AnyP::UriScheme(s->transport.protocol).c_str() << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); |
7e07ced1 | 3866 | } |
7e07ced1 | 3867 | |
fa720bfb AJ |
3868 | while (*head != NULL) |
3869 | head = &((*head)->next); | |
62e76326 | 3870 | |
fa720bfb | 3871 | *head = s; |
3f38a55e | 3872 | } |
3873 | ||
3874 | static void | |
fa720bfb | 3875 | dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s) |
3f38a55e | 3876 | { |
cc192b50 | 3877 | char buf[MAX_IPSTRLEN]; |
3878 | ||
3879 | storeAppendPrintf(e, "%s %s", | |
62e76326 | 3880 | n, |
4dd643d5 | 3881 | s->s.toUrl(buf,MAX_IPSTRLEN)); |
62e76326 | 3882 | |
df1b20e4 | 3883 | // MODES and specific sub-options. |
6a25a046 | 3884 | if (s->flags.natIntercept) |
2ad20b4f | 3885 | storeAppendPrintf(e, " intercept"); |
62e76326 | 3886 | |
6a25a046 | 3887 | else if (s->flags.tproxyIntercept) |
c7b1dd5d AJ |
3888 | storeAppendPrintf(e, " tproxy"); |
3889 | ||
00d0ce87 | 3890 | else if (s->flags.proxySurrogate) |
d3d92daa | 3891 | storeAppendPrintf(e, " require-proxy-header"); |
00d0ce87 | 3892 | |
6a25a046 | 3893 | else if (s->flags.accelSurrogate) { |
c7b1dd5d AJ |
3894 | storeAppendPrintf(e, " accel"); |
3895 | ||
df1b20e4 AJ |
3896 | if (s->vhost) |
3897 | storeAppendPrintf(e, " vhost"); | |
62e76326 | 3898 | |
df1b20e4 AJ |
3899 | if (s->vport < 0) |
3900 | storeAppendPrintf(e, " vport"); | |
3901 | else if (s->vport > 0) | |
3902 | storeAppendPrintf(e, " vport=%d", s->vport); | |
5529ca8a | 3903 | |
df1b20e4 AJ |
3904 | if (s->defaultsite) |
3905 | storeAppendPrintf(e, " defaultsite=%s", s->defaultsite); | |
3906 | ||
eb6ac808 AJ |
3907 | // TODO: compare against prefix of 'n' instead of assuming http_port |
3908 | if (s->transport.protocol != AnyP::PROTO_HTTP) | |
1ca54a54 | 3909 | storeAppendPrintf(e, " protocol=%s", AnyP::UriScheme(s->transport.protocol).c_str()); |
df1b20e4 AJ |
3910 | |
3911 | if (s->allow_direct) | |
3912 | storeAppendPrintf(e, " allow-direct"); | |
3913 | ||
3914 | if (s->ignore_cc) | |
3915 | storeAppendPrintf(e, " ignore-cc"); | |
3916 | ||
3917 | } | |
3918 | ||
3919 | // Generic independent options | |
3920 | ||
3921 | if (s->name) | |
3922 | storeAppendPrintf(e, " name=%s", s->name); | |
3923 | ||
33e701f3 | 3924 | #if USE_HTTP_VIOLATIONS |
6a25a046 | 3925 | if (!s->flags.accelSurrogate && s->ignore_cc) |
df1b20e4 AJ |
3926 | storeAppendPrintf(e, " ignore-cc"); |
3927 | #endif | |
c7b1dd5d | 3928 | |
d67acb4e AJ |
3929 | if (s->connection_auth_disabled) |
3930 | storeAppendPrintf(e, " connection-auth=off"); | |
3931 | else | |
3932 | storeAppendPrintf(e, " connection-auth=on"); | |
3933 | ||
5529ca8a | 3934 | if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) { |
3935 | const char *pmtu; | |
3936 | ||
3937 | if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS) | |
3938 | pmtu = "always"; | |
3939 | else | |
3940 | pmtu = "transparent"; | |
3941 | ||
3942 | storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu); | |
3943 | } | |
b2130d58 | 3944 | |
4dd643d5 | 3945 | if (s->s.isAnyAddr() && !s->s.isIPv6()) |
df1b20e4 AJ |
3946 | storeAppendPrintf(e, " ipv4"); |
3947 | ||
b2130d58 | 3948 | if (s->tcp_keepalive.enabled) { |
26ac0430 | 3949 | if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) { |
68924b6d | 3950 | storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout); |
26ac0430 | 3951 | } else { |
68924b6d | 3952 | storeAppendPrintf(e, " tcpkeepalive"); |
26ac0430 | 3953 | } |
b2130d58 | 3954 | } |
154dc884 | 3955 | |
cb4f4424 | 3956 | #if USE_OPENSSL |
6a25a046 | 3957 | if (s->flags.tunnelSslBumping) |
df1b20e4 | 3958 | storeAppendPrintf(e, " ssl-bump"); |
c7b1dd5d | 3959 | |
26ac0430 AJ |
3960 | if (s->cert) |
3961 | storeAppendPrintf(e, " cert=%s", s->cert); | |
154dc884 | 3962 | |
26ac0430 AJ |
3963 | if (s->key) |
3964 | storeAppendPrintf(e, " key=%s", s->key); | |
154dc884 | 3965 | |
26ac0430 AJ |
3966 | if (s->version) |
3967 | storeAppendPrintf(e, " version=%d", s->version); | |
154dc884 | 3968 | |
26ac0430 AJ |
3969 | if (s->options) |
3970 | storeAppendPrintf(e, " options=%s", s->options); | |
154dc884 | 3971 | |
26ac0430 AJ |
3972 | if (s->cipher) |
3973 | storeAppendPrintf(e, " cipher=%s", s->cipher); | |
154dc884 | 3974 | |
26ac0430 AJ |
3975 | if (s->cafile) |
3976 | storeAppendPrintf(e, " cafile=%s", s->cafile); | |
154dc884 | 3977 | |
26ac0430 AJ |
3978 | if (s->capath) |
3979 | storeAppendPrintf(e, " capath=%s", s->capath); | |
154dc884 | 3980 | |
26ac0430 AJ |
3981 | if (s->crlfile) |
3982 | storeAppendPrintf(e, " crlfile=%s", s->crlfile); | |
154dc884 | 3983 | |
26ac0430 AJ |
3984 | if (s->dhfile) |
3985 | storeAppendPrintf(e, " dhparams=%s", s->dhfile); | |
154dc884 | 3986 | |
26ac0430 AJ |
3987 | if (s->sslflags) |
3988 | storeAppendPrintf(e, " sslflags=%s", s->sslflags); | |
154dc884 | 3989 | |
95d2589c CT |
3990 | if (s->sslContextSessionId) |
3991 | storeAppendPrintf(e, " sslcontext=%s", s->sslContextSessionId); | |
3992 | ||
3993 | if (s->generateHostCertificates) | |
3994 | storeAppendPrintf(e, " generate-host-certificates"); | |
3995 | ||
3996 | if (s->dynamicCertMemCacheSize != std::numeric_limits<size_t>::max()) | |
3997 | storeAppendPrintf(e, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s->dynamicCertMemCacheSize, B_BYTES_STR); | |
154dc884 | 3998 | #endif |
3f38a55e | 3999 | } |
62e76326 | 4000 | |
3f38a55e | 4001 | static void |
fa720bfb | 4002 | dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfgPointer &s) |
3f38a55e | 4003 | { |
fa720bfb AJ |
4004 | for (AnyP::PortCfgPointer p = s; p != NULL; p = p->next) { |
4005 | dump_generic_port(e, n, p); | |
62e76326 | 4006 | storeAppendPrintf(e, "\n"); |
3f38a55e | 4007 | } |
4008 | } | |
4009 | ||
f150dd4b | 4010 | void |
4011 | configFreeMemory(void) | |
4012 | { | |
23ff6968 | 4013 | free_all(); |
cb4f4424 | 4014 | #if USE_OPENSSL |
29bf4910 CT |
4015 | SSL_CTX_free(Config.ssl_client.sslContext); |
4016 | #endif | |
f150dd4b | 4017 | } |
f0b19334 | 4018 | |
94439e4e | 4019 | void |
f0b19334 | 4020 | requirePathnameExists(const char *name, const char *path) |
4021 | { | |
62e76326 | 4022 | |
f0b19334 | 4023 | struct stat sb; |
08577e16 | 4024 | char pathbuf[BUFSIZ]; |
f0b19334 | 4025 | assert(path != NULL); |
62e76326 | 4026 | |
0b796acd | 4027 | if (Config.chroot_dir && (geteuid() == 0)) { |
62e76326 | 4028 | snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path); |
4029 | path = pathbuf; | |
08577e16 | 4030 | } |
62e76326 | 4031 | |
a572d8be | 4032 | if (stat(path, &sb) < 0) { |
a32a190b AJ |
4033 | debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL ":"") << "ERROR: " << name << " " << path << ": " << xstrerror()); |
4034 | // keep going to find more issues if we are only checking the config file with "-k parse" | |
4035 | if (opt_parse_cfg_only) | |
4036 | return; | |
4037 | // this is fatal if it is found during startup or reconfigure | |
a572d8be | 4038 | if (opt_send_signal == -1 || opt_send_signal == SIGHUP) |
4039 | fatalf("%s %s: %s", name, path, xstrerror()); | |
a572d8be | 4040 | } |
f0b19334 | 4041 | } |
d860a1aa | 4042 | |
4043 | char * | |
4044 | strtokFile(void) | |
4045 | { | |
d295d770 | 4046 | return ConfigParser::strtokFile(); |
d860a1aa | 4047 | } |
7684c4b1 | 4048 | |
450e0c10 | 4049 | #include "AccessLogEntry.h" |
7684c4b1 | 4050 | |
fb0c2f17 NH |
4051 | /** |
4052 | * We support several access_log configuration styles: | |
4053 | * | |
4054 | * #1: Deprecated ancient style without an explicit logging module: | |
4055 | * access_log /var/log/access.log | |
4056 | * | |
4057 | * #2: The "none" logging module (i.e., no logging [of matching transactions]): | |
4058 | * access_log none [acl ...] | |
4059 | * | |
4060 | * #3: Configurable logging module without named options: | |
4061 | * Logformat or the first ACL name, whichever comes first, may not contain '='. | |
4062 | * If no explicit logformat name is given, the first ACL name, if any, | |
4063 | * should not be an existing logformat name or it will be treated as such. | |
4064 | * access_log module:place [logformat_name] [acl ...] | |
4065 | * | |
4066 | * #4: Configurable logging module with name=value options such as logformat=x: | |
4067 | * The first ACL name may not contain '='. | |
4068 | * access_log module:place [option ...] [acl ...] | |
4069 | * | |
4070 | */ | |
7684c4b1 | 4071 | static void |
87ddff6e | 4072 | parse_access_log(CustomLog ** logs) |
7684c4b1 | 4073 | { |
87ddff6e | 4074 | CustomLog *cl = (CustomLog *)xcalloc(1, sizeof(*cl)); |
7684c4b1 | 4075 | |
fb0c2f17 NH |
4076 | // default buffer size and fatal settings |
4077 | cl->bufferSize = 8*MAX_URL; | |
4078 | cl->fatal = true; | |
4079 | ||
4080 | /* determine configuration style */ | |
4081 | ||
2eceb328 | 4082 | const char *filename = ConfigParser::NextToken(); |
fb0c2f17 | 4083 | if (!filename) { |
7684c4b1 | 4084 | self_destruct(); |
9eeb8e4b | 4085 | return; |
4086 | } | |
7684c4b1 | 4087 | |
4088 | if (strcmp(filename, "none") == 0) { | |
20efa1c2 | 4089 | cl->type = Log::Format::CLF_NONE; |
6f58d7d7 | 4090 | aclParseAclList(LegacyParser, &cl->aclList, filename); |
6375a714 AJ |
4091 | while (*logs) |
4092 | logs = &(*logs)->next; | |
4093 | *logs = cl; | |
4094 | return; | |
7684c4b1 | 4095 | } |
4096 | ||
fb0c2f17 NH |
4097 | cl->filename = xstrdup(filename); |
4098 | cl->type = Log::Format::CLF_UNKNOWN; | |
4099 | ||
bde7a8ce | 4100 | const char *token = ConfigParser::PeekAtToken(); |
fb0c2f17 NH |
4101 | if (!token) { // style #1 |
4102 | // no options to deal with | |
4103 | } else if (!strchr(token, '=')) { // style #3 | |
bde7a8ce CT |
4104 | // if logformat name is recognized, |
4105 | // pop the previewed token; Else it must be an ACL name | |
4106 | if (setLogformat(cl, token, false)) | |
4107 | (void)ConfigParser::NextToken(); | |
fb0c2f17 NH |
4108 | } else { // style #4 |
4109 | do { | |
4110 | if (strncasecmp(token, "on-error=", 9) == 0) { | |
4111 | if (strncasecmp(token+9, "die", 3) == 0) { | |
4112 | cl->fatal = true; | |
4113 | } else if (strncasecmp(token+9, "drop", 4) == 0) { | |
4114 | cl->fatal = false; | |
4115 | } else { | |
4116 | debugs(3, DBG_CRITICAL, "Unknown value for on-error '" << | |
4117 | token << "' expected 'drop' or 'die'"); | |
4118 | self_destruct(); | |
4119 | } | |
4120 | } else if (strncasecmp(token, "buffer-size=", 12) == 0) { | |
4121 | parseBytesOptionValue(&cl->bufferSize, B_BYTES_STR, token+12); | |
4122 | } else if (strncasecmp(token, "logformat=", 10) == 0) { | |
4123 | setLogformat(cl, token+10, true); | |
4124 | } else if (!strchr(token, '=')) { | |
bde7a8ce | 4125 | // Do not pop the token; it must be an ACL name |
fb0c2f17 NH |
4126 | break; // done with name=value options, now to ACLs |
4127 | } else { | |
4128 | debugs(3, DBG_CRITICAL, "Unknown access_log option " << token); | |
4129 | self_destruct(); | |
4130 | } | |
bde7a8ce CT |
4131 | // Pop the token, it was a valid "name=value" option |
4132 | (void)ConfigParser::NextToken(); | |
4133 | // Get next with preview ConfigParser::NextToken call. | |
4134 | } while ((token = ConfigParser::PeekAtToken()) != NULL); | |
fb0c2f17 | 4135 | } |
7684c4b1 | 4136 | |
fb0c2f17 NH |
4137 | // set format if it has not been specified explicitly |
4138 | if (cl->type == Log::Format::CLF_UNKNOWN) | |
4139 | setLogformat(cl, "squid", true); | |
7684c4b1 | 4140 | |
0a003ce5 | 4141 | aclParseAclList(LegacyParser, &cl->aclList, cl->filename); |
fb0c2f17 NH |
4142 | |
4143 | while (*logs) | |
4144 | logs = &(*logs)->next; | |
4145 | ||
4146 | *logs = cl; | |
4147 | } | |
4148 | ||
4149 | /// sets CustomLog::type and, if needed, CustomLog::lf | |
4150 | /// returns false iff there is no named log format | |
4151 | static bool | |
4152 | setLogformat(CustomLog *cl, const char *logdef_name, const bool dieWhenMissing) | |
4153 | { | |
4154 | assert(cl); | |
4155 | assert(logdef_name); | |
4156 | ||
4157 | debugs(3, 9, "possible " << cl->filename << " logformat: " << logdef_name); | |
4158 | ||
4159 | if (cl->type != Log::Format::CLF_UNKNOWN) { | |
4160 | debugs(3, DBG_CRITICAL, "Second logformat name in one access_log: " << | |
4161 | logdef_name << " " << cl->type << " ? " << Log::Format::CLF_NONE); | |
4162 | self_destruct(); | |
4163 | return false; | |
4164 | } | |
7684c4b1 | 4165 | |
4166 | /* look for the definition pointer corresponding to this name */ | |
38e16f92 | 4167 | Format::Format *lf = Log::TheConfig.logformats; |
7684c4b1 | 4168 | |
4169 | while (lf != NULL) { | |
bf8fe701 | 4170 | debugs(3, 9, "Comparing against '" << lf->name << "'"); |
7684c4b1 | 4171 | |
4172 | if (strcmp(lf->name, logdef_name) == 0) | |
4173 | break; | |
4174 | ||
4175 | lf = lf->next; | |
4176 | } | |
4177 | ||
4178 | if (lf != NULL) { | |
20efa1c2 | 4179 | cl->type = Log::Format::CLF_CUSTOM; |
7684c4b1 | 4180 | cl->logFormat = lf; |
4181 | } else if (strcmp(logdef_name, "auto") == 0) { | |
fa84c01d | 4182 | debugs(0, DBG_CRITICAL, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead."); |
20efa1c2 | 4183 | cl->type = Log::Format::CLF_SQUID; |
7684c4b1 | 4184 | } else if (strcmp(logdef_name, "squid") == 0) { |
20efa1c2 | 4185 | cl->type = Log::Format::CLF_SQUID; |
7684c4b1 | 4186 | } else if (strcmp(logdef_name, "common") == 0) { |
20efa1c2 AJ |
4187 | cl->type = Log::Format::CLF_COMMON; |
4188 | } else if (strcmp(logdef_name, "combined") == 0) { | |
4189 | cl->type = Log::Format::CLF_COMBINED; | |
3ff65596 AR |
4190 | #if ICAP_CLIENT |
4191 | } else if (strcmp(logdef_name, "icap_squid") == 0) { | |
20efa1c2 | 4192 | cl->type = Log::Format::CLF_ICAP_SQUID; |
3ff65596 | 4193 | #endif |
20efa1c2 AJ |
4194 | } else if (strcmp(logdef_name, "useragent") == 0) { |
4195 | cl->type = Log::Format::CLF_USERAGENT; | |
4196 | } else if (strcmp(logdef_name, "referrer") == 0) { | |
4197 | cl->type = Log::Format::CLF_REFERER; | |
fb0c2f17 | 4198 | } else if (dieWhenMissing) { |
fa84c01d | 4199 | debugs(3, DBG_CRITICAL, "Log format '" << logdef_name << "' is not defined"); |
7684c4b1 | 4200 | self_destruct(); |
fb0c2f17 NH |
4201 | return false; |
4202 | } else { | |
4203 | return false; | |
7684c4b1 | 4204 | } |
4205 | ||
fb0c2f17 | 4206 | return true; |
7684c4b1 | 4207 | } |
4208 | ||
d64bef4c | 4209 | static int |
87ddff6e | 4210 | check_null_access_log(CustomLog *customlog_definitions) |
d64bef4c | 4211 | { |
4212 | return customlog_definitions == NULL; | |
4213 | } | |
4214 | ||
7684c4b1 | 4215 | static void |
87ddff6e | 4216 | dump_access_log(StoreEntry * entry, const char *name, CustomLog * logs) |
7684c4b1 | 4217 | { |
87ddff6e | 4218 | CustomLog *log; |
7684c4b1 | 4219 | |
4220 | for (log = logs; log; log = log->next) { | |
4221 | storeAppendPrintf(entry, "%s ", name); | |
4222 | ||
4223 | switch (log->type) { | |
4224 | ||
20efa1c2 | 4225 | case Log::Format::CLF_CUSTOM: |
7684c4b1 | 4226 | storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name); |
4227 | break; | |
4228 | ||
20efa1c2 | 4229 | case Log::Format::CLF_NONE: |
7684c4b1 | 4230 | storeAppendPrintf(entry, "none"); |
4231 | break; | |
4232 | ||
20efa1c2 | 4233 | case Log::Format::CLF_SQUID: |
7684c4b1 | 4234 | storeAppendPrintf(entry, "%s squid", log->filename); |
4235 | break; | |
4236 | ||
20efa1c2 AJ |
4237 | case Log::Format::CLF_COMBINED: |
4238 | storeAppendPrintf(entry, "%s combined", log->filename); | |
4239 | break; | |
4240 | ||
4241 | case Log::Format::CLF_COMMON: | |
4242 | storeAppendPrintf(entry, "%s common", log->filename); | |
7684c4b1 | 4243 | break; |
20efa1c2 | 4244 | |
3ff65596 | 4245 | #if ICAP_CLIENT |
20efa1c2 | 4246 | case Log::Format::CLF_ICAP_SQUID: |
3ff65596 AR |
4247 | storeAppendPrintf(entry, "%s icap_squid", log->filename); |
4248 | break; | |
4249 | #endif | |
20efa1c2 AJ |
4250 | case Log::Format::CLF_USERAGENT: |
4251 | storeAppendPrintf(entry, "%s useragent", log->filename); | |
4252 | break; | |
7684c4b1 | 4253 | |
20efa1c2 AJ |
4254 | case Log::Format::CLF_REFERER: |
4255 | storeAppendPrintf(entry, "%s referrer", log->filename); | |
7684c4b1 | 4256 | break; |
4257 | ||
20efa1c2 | 4258 | case Log::Format::CLF_UNKNOWN: |
7684c4b1 | 4259 | break; |
4260 | } | |
4261 | ||
4262 | if (log->aclList) | |
4263 | dump_acl_list(entry, log->aclList); | |
4264 | ||
4265 | storeAppendPrintf(entry, "\n"); | |
4266 | } | |
4267 | } | |
4268 | ||
7684c4b1 | 4269 | static void |
87ddff6e | 4270 | free_access_log(CustomLog ** definitions) |
7684c4b1 | 4271 | { |
4272 | while (*definitions) { | |
87ddff6e | 4273 | CustomLog *log = *definitions; |
7684c4b1 | 4274 | *definitions = log->next; |
4275 | ||
4276 | log->logFormat = NULL; | |
20efa1c2 | 4277 | log->type = Log::Format::CLF_UNKNOWN; |
7684c4b1 | 4278 | |
4279 | if (log->aclList) | |
4280 | aclDestroyAclList(&log->aclList); | |
4281 | ||
4282 | safe_free(log->filename); | |
4283 | ||
4284 | xfree(log); | |
4285 | } | |
4286 | } | |
3a69ddf3 | 4287 | |
96c2bb61 AR |
4288 | /// parses list of integers form name=N1,N2,N3,... |
4289 | static bool | |
c8ea3cc0 | 4290 | parseNamedIntList(const char *data, const String &name, std::vector<int> &list) |
96c2bb61 AR |
4291 | { |
4292 | if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) { | |
4293 | data += name.size(); | |
4294 | if (*data == '=') { | |
4295 | while (true) { | |
4296 | ++data; | |
4297 | int value = 0; | |
4298 | if (!StringToInt(data, value, &data, 10)) | |
4299 | break; | |
4300 | list.push_back(value); | |
4301 | if (*data == '\0' || *data != ',') | |
4302 | break; | |
4303 | } | |
4304 | } | |
4305 | } | |
cff99cec | 4306 | return data && *data == '\0'; |
96c2bb61 AR |
4307 | } |
4308 | ||
4309 | static void | |
212af65c A |
4310 | parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap) |
4311 | { | |
96c2bb61 AR |
4312 | #if !HAVE_CPU_AFFINITY |
4313 | debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " << | |
4314 | "support, do not set 'cpu_affinity_map'"); | |
4315 | self_destruct(); | |
4316 | #endif /* HAVE_CPU_AFFINITY */ | |
4317 | ||
4318 | if (!*cpuAffinityMap) | |
4319 | *cpuAffinityMap = new CpuAffinityMap; | |
4320 | ||
2eceb328 CT |
4321 | const char *const pToken = ConfigParser::NextToken(); |
4322 | const char *const cToken = ConfigParser::NextToken(); | |
c8ea3cc0 | 4323 | std::vector<int> processes, cores; |
96c2bb61 AR |
4324 | if (!parseNamedIntList(pToken, "process_numbers", processes)) { |
4325 | debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " << | |
4326 | "in 'cpu_affinity_map'"); | |
4327 | self_destruct(); | |
4328 | } else if (!parseNamedIntList(cToken, "cores", cores)) { | |
4329 | debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " << | |
4330 | "'cpu_affinity_map'"); | |
4331 | self_destruct(); | |
4332 | } else if (!(*cpuAffinityMap)->add(processes, cores)) { | |
4333 | debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " << | |
4334 | "process_numbers and cores lists differ in length or " << | |
4335 | "contain numbers <= 0"); | |
4336 | self_destruct(); | |
4337 | } | |
4338 | } | |
4339 | ||
4340 | static void | |
212af65c A |
4341 | dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap) |
4342 | { | |
96c2bb61 AR |
4343 | if (cpuAffinityMap) { |
4344 | storeAppendPrintf(entry, "%s process_numbers=", name); | |
4345 | for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) { | |
4346 | storeAppendPrintf(entry, "%s%i", (i ? "," : ""), | |
4347 | cpuAffinityMap->processes()[i]); | |
4348 | } | |
4349 | storeAppendPrintf(entry, " cores="); | |
eaed60cc | 4350 | for (size_t i = 0; i < cpuAffinityMap->cores().size(); ++i) { |
96c2bb61 AR |
4351 | storeAppendPrintf(entry, "%s%i", (i ? "," : ""), |
4352 | cpuAffinityMap->cores()[i]); | |
4353 | } | |
4354 | storeAppendPrintf(entry, "\n"); | |
4355 | } | |
4356 | } | |
4357 | ||
4358 | static void | |
212af65c A |
4359 | free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap) |
4360 | { | |
96c2bb61 AR |
4361 | delete *cpuAffinityMap; |
4362 | *cpuAffinityMap = NULL; | |
4363 | } | |
4364 | ||
62c7f90e AR |
4365 | #if USE_ADAPTATION |
4366 | ||
4367 | static void | |
4368 | parse_adaptation_service_set_type() | |
4369 | { | |
4370 | Adaptation::Config::ParseServiceSet(); | |
4371 | } | |
4372 | ||
a22e6cd3 AR |
4373 | static void |
4374 | parse_adaptation_service_chain_type() | |
4375 | { | |
4376 | Adaptation::Config::ParseServiceChain(); | |
4377 | } | |
4378 | ||
62c7f90e AR |
4379 | static void |
4380 | parse_adaptation_access_type() | |
4381 | { | |
4382 | Adaptation::Config::ParseAccess(LegacyParser); | |
4383 | } | |
62c7f90e AR |
4384 | #endif /* USE_ADAPTATION */ |
4385 | ||
3a69ddf3 | 4386 | #if ICAP_CLIENT |
4387 | ||
4388 | static void | |
26cc52cb | 4389 | parse_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 4390 | { |
462e63d3 | 4391 | cfg->parseService(); |
3a69ddf3 | 4392 | } |
4393 | ||
4394 | static void | |
26cc52cb | 4395 | free_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 4396 | { |
462e63d3 | 4397 | cfg->freeService(); |
3a69ddf3 | 4398 | } |
4399 | ||
4400 | static void | |
26cc52cb | 4401 | dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg) |
3a69ddf3 | 4402 | { |
462e63d3 | 4403 | cfg.dumpService(entry, name); |
3a69ddf3 | 4404 | } |
4405 | ||
4406 | static void | |
c939dc70 | 4407 | parse_icap_class_type() |
3a69ddf3 | 4408 | { |
fa84c01d | 4409 | debugs(93, DBG_CRITICAL, "WARNING: 'icap_class' is depricated. " << |
26ac0430 | 4410 | "Use 'adaptation_service_set' instead"); |
62c7f90e | 4411 | Adaptation::Config::ParseServiceSet(); |
3a69ddf3 | 4412 | } |
4413 | ||
3a69ddf3 | 4414 | static void |
c939dc70 | 4415 | parse_icap_access_type() |
3a69ddf3 | 4416 | { |
fa84c01d | 4417 | debugs(93, DBG_CRITICAL, "WARNING: 'icap_access' is depricated. " << |
26ac0430 | 4418 | "Use 'adaptation_access' instead"); |
21a26d31 | 4419 | Adaptation::Config::ParseAccess(LegacyParser); |
3a69ddf3 | 4420 | } |
4421 | ||
3a69ddf3 | 4422 | #endif |
21a26d31 | 4423 | |
21a26d31 AR |
4424 | #if USE_ECAP |
4425 | ||
4426 | static void | |
574b508c | 4427 | parse_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
4428 | { |
4429 | cfg->parseService(); | |
4430 | } | |
4431 | ||
4432 | static void | |
574b508c | 4433 | free_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
4434 | { |
4435 | cfg->freeService(); | |
4436 | } | |
4437 | ||
4438 | static void | |
574b508c | 4439 | dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg) |
21a26d31 AR |
4440 | { |
4441 | cfg.dumpService(entry, name); | |
4442 | } | |
4443 | ||
4444 | #endif /* USE_ECAP */ | |
8277060a CT |
4445 | |
4446 | #if ICAP_CLIENT | |
4447 | static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
4448 | { | |
4449 | char *token; | |
4450 | time_t d; | |
4451 | time_t m; | |
4452 | cfg->service_failure_limit = GetInteger(); | |
4453 | ||
2eceb328 | 4454 | if ((token = ConfigParser::NextToken()) == NULL) |
8277060a CT |
4455 | return; |
4456 | ||
4457 | if (strcmp(token,"in") != 0) { | |
fa84c01d | 4458 | debugs(3, DBG_CRITICAL, "expecting 'in' on'" << config_input_line << "'"); |
8277060a CT |
4459 | self_destruct(); |
4460 | } | |
4461 | ||
2eceb328 | 4462 | if ((token = ConfigParser::NextToken()) == NULL) { |
8277060a CT |
4463 | self_destruct(); |
4464 | } | |
4465 | ||
4466 | d = static_cast<time_t> (xatoi(token)); | |
a459e80a | 4467 | |
8277060a CT |
4468 | m = static_cast<time_t> (1); |
4469 | ||
4470 | if (0 == d) | |
4471 | (void) 0; | |
2eceb328 | 4472 | else if ((token = ConfigParser::NextToken()) == NULL) { |
fa84c01d | 4473 | debugs(3, DBG_CRITICAL, "No time-units on '" << config_input_line << "'"); |
8277060a | 4474 | self_destruct(); |
9b741834 | 4475 | } else if ((m = parseTimeUnits(token, false)) == 0) |
8277060a CT |
4476 | self_destruct(); |
4477 | ||
4478 | cfg->oldest_service_failure = (m * d); | |
4479 | } | |
4480 | ||
4481 | static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg) | |
4482 | { | |
4483 | storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit); | |
4484 | if (cfg.oldest_service_failure > 0) { | |
4485 | storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure); | |
4486 | } | |
4487 | storeAppendPrintf(entry, "\n"); | |
4488 | } | |
4489 | ||
4490 | static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
4491 | { | |
4492 | cfg->oldest_service_failure = 0; | |
4493 | cfg->service_failure_limit = 0; | |
4494 | } | |
aebe6888 | 4495 | #endif |
8277060a | 4496 | |
cb4f4424 | 4497 | #if USE_OPENSSL |
fb2178bb CT |
4498 | static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt) |
4499 | { | |
4500 | char *al; | |
4501 | sslproxy_cert_adapt *ca = (sslproxy_cert_adapt *) xcalloc(1, sizeof(sslproxy_cert_adapt)); | |
2eceb328 | 4502 | if ((al = ConfigParser::NextToken()) == NULL) { |
fb2178bb CT |
4503 | self_destruct(); |
4504 | return; | |
4505 | } | |
87f237a9 | 4506 | |
fb2178bb CT |
4507 | const char *param; |
4508 | if ( char *s = strchr(al, '{')) { | |
4509 | *s = '\0'; // terminate the al string | |
a38ec4b1 | 4510 | ++s; |
fb2178bb CT |
4511 | param = s; |
4512 | s = strchr(s, '}'); | |
4513 | if (!s) { | |
4514 | self_destruct(); | |
4515 | return; | |
4516 | } | |
4517 | *s = '\0'; | |
87f237a9 | 4518 | } else |
fb2178bb CT |
4519 | param = NULL; |
4520 | ||
4521 | if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidAfter]) == 0) { | |
4522 | ca->alg = Ssl::algSetValidAfter; | |
b8889258 | 4523 | ca->param = xstrdup("on"); |
87f237a9 | 4524 | } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetValidBefore]) == 0) { |
fb2178bb | 4525 | ca->alg = Ssl::algSetValidBefore; |
b8889258 | 4526 | ca->param = xstrdup("on"); |
87f237a9 | 4527 | } else if (strcmp(al, Ssl::CertAdaptAlgorithmStr[Ssl::algSetCommonName]) == 0) { |
fb2178bb CT |
4528 | ca->alg = Ssl::algSetCommonName; |
4529 | if (param) { | |
5367d845 CT |
4530 | if (strlen(param) > 64) { |
4531 | debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param << "} : using common name longer than 64 bytes is not supported"); | |
4532 | self_destruct(); | |
4533 | return; | |
4534 | } | |
b8889258 | 4535 | ca->param = xstrdup(param); |
fb2178bb CT |
4536 | } |
4537 | } else { | |
4538 | debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al); | |
4539 | self_destruct(); | |
4540 | return; | |
4541 | } | |
4542 | ||
6f58d7d7 | 4543 | aclParseAclList(LegacyParser, &ca->aclList, al); |
fb2178bb | 4544 | |
87f237a9 | 4545 | while (*cert_adapt) |
fb2178bb CT |
4546 | cert_adapt = &(*cert_adapt)->next; |
4547 | ||
4548 | *cert_adapt = ca; | |
4549 | } | |
4550 | ||
4551 | static void dump_sslproxy_cert_adapt(StoreEntry *entry, const char *name, sslproxy_cert_adapt *cert_adapt) | |
4552 | { | |
4553 | for (sslproxy_cert_adapt *ca = cert_adapt; ca != NULL; ca = ca->next) { | |
4554 | storeAppendPrintf(entry, "%s ", name); | |
4555 | storeAppendPrintf(entry, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca->alg), ca->param); | |
4556 | if (ca->aclList) | |
4557 | dump_acl_list(entry, ca->aclList); | |
4558 | storeAppendPrintf(entry, "\n"); | |
4559 | } | |
4560 | } | |
4561 | ||
4562 | static void free_sslproxy_cert_adapt(sslproxy_cert_adapt **cert_adapt) | |
4563 | { | |
87f237a9 | 4564 | while (*cert_adapt) { |
fb2178bb CT |
4565 | sslproxy_cert_adapt *ca = *cert_adapt; |
4566 | *cert_adapt = ca->next; | |
4567 | safe_free(ca->param); | |
4568 | ||
4569 | if (ca->aclList) | |
4570 | aclDestroyAclList(&ca->aclList); | |
4571 | ||
4572 | safe_free(ca); | |
4573 | } | |
4574 | } | |
aebe6888 CT |
4575 | |
4576 | static void parse_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign) | |
4577 | { | |
4578 | char *al; | |
4579 | sslproxy_cert_sign *cs = (sslproxy_cert_sign *) xcalloc(1, sizeof(sslproxy_cert_sign)); | |
2eceb328 | 4580 | if ((al = ConfigParser::NextToken()) == NULL) { |
aebe6888 CT |
4581 | self_destruct(); |
4582 | return; | |
4583 | } | |
4584 | ||
4585 | if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignTrusted]) == 0) | |
4586 | cs->alg = Ssl::algSignTrusted; | |
4587 | else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignUntrusted]) == 0) | |
4588 | cs->alg = Ssl::algSignUntrusted; | |
4589 | else if (strcmp(al, Ssl::CertSignAlgorithmStr[Ssl::algSignSelf]) == 0) | |
4590 | cs->alg = Ssl::algSignSelf; | |
4591 | else { | |
4592 | debugs(3, DBG_CRITICAL, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al); | |
4593 | self_destruct(); | |
4594 | return; | |
4595 | } | |
4596 | ||
6f58d7d7 | 4597 | aclParseAclList(LegacyParser, &cs->aclList, al); |
aebe6888 | 4598 | |
87f237a9 | 4599 | while (*cert_sign) |
aebe6888 CT |
4600 | cert_sign = &(*cert_sign)->next; |
4601 | ||
4602 | *cert_sign = cs; | |
4603 | } | |
4604 | ||
4605 | static void dump_sslproxy_cert_sign(StoreEntry *entry, const char *name, sslproxy_cert_sign *cert_sign) | |
4606 | { | |
4607 | sslproxy_cert_sign *cs; | |
4608 | for (cs = cert_sign; cs != NULL; cs = cs->next) { | |
4609 | storeAppendPrintf(entry, "%s ", name); | |
4610 | storeAppendPrintf(entry, "%s ", Ssl::certSignAlgorithm(cs->alg)); | |
4611 | if (cs->aclList) | |
4612 | dump_acl_list(entry, cs->aclList); | |
4613 | storeAppendPrintf(entry, "\n"); | |
4614 | } | |
4615 | } | |
4616 | ||
4617 | static void free_sslproxy_cert_sign(sslproxy_cert_sign **cert_sign) | |
4618 | { | |
87f237a9 | 4619 | while (*cert_sign) { |
aebe6888 CT |
4620 | sslproxy_cert_sign *cs = *cert_sign; |
4621 | *cert_sign = cs->next; | |
4622 | ||
4623 | if (cs->aclList) | |
4624 | aclDestroyAclList(&cs->aclList); | |
4625 | ||
4626 | safe_free(cs); | |
4627 | } | |
4628 | } | |
fb2178bb | 4629 | |
38450a50 CT |
4630 | class sslBumpCfgRr: public ::RegisteredRunner |
4631 | { | |
4632 | public: | |
4633 | static Ssl::BumpMode lastDeprecatedRule; | |
4634 | /* RegisteredRunner API */ | |
21b7990f | 4635 | virtual void finalizeConfig(); |
38450a50 CT |
4636 | }; |
4637 | ||
4638 | Ssl::BumpMode sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd; | |
4639 | ||
21b7990f | 4640 | RunnerRegistrationEntry(sslBumpCfgRr); |
38450a50 | 4641 | |
21b7990f AR |
4642 | void |
4643 | sslBumpCfgRr::finalizeConfig() | |
38450a50 CT |
4644 | { |
4645 | if (lastDeprecatedRule != Ssl::bumpEnd) { | |
4646 | assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone); | |
4647 | static char buf[1024]; | |
4648 | if (lastDeprecatedRule == Ssl::bumpClientFirst) { | |
4649 | strcpy(buf, "ssl_bump deny all"); | |
4650 | debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated implicit " | |
4651 | "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations " | |
4652 | "must not use implicit rules. Update your ssl_bump rules."); | |
4653 | } else { | |
4654 | strcpy(buf, "ssl_bump allow all"); | |
4655 | debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated implicit " | |
4656 | "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually " | |
4657 | "inferior to the newer server-first bumping mode. New ssl_bump" | |
4658 | " configurations must not use implicit rules. Update your ssl_bump rules."); | |
4659 | } | |
4660 | parse_line(buf); | |
4661 | } | |
4662 | } | |
4663 | ||
caf3666d AR |
4664 | static void parse_sslproxy_ssl_bump(acl_access **ssl_bump) |
4665 | { | |
38450a50 CT |
4666 | typedef const char *BumpCfgStyle; |
4667 | BumpCfgStyle bcsNone = NULL; | |
4668 | BumpCfgStyle bcsNew = "new client/server-first/none"; | |
4669 | BumpCfgStyle bcsOld = "deprecated allow/deny"; | |
4670 | static BumpCfgStyle bumpCfgStyleLast = bcsNone; | |
4671 | BumpCfgStyle bumpCfgStyleNow = bcsNone; | |
caf3666d | 4672 | char *bm; |
2eceb328 | 4673 | if ((bm = ConfigParser::NextToken()) == NULL) { |
caf3666d AR |
4674 | self_destruct(); |
4675 | return; | |
4676 | } | |
4677 | ||
38450a50 CT |
4678 | // if this is the first rule proccessed |
4679 | if (*ssl_bump == NULL) { | |
4680 | bumpCfgStyleLast = bcsNone; | |
4681 | sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd; | |
4682 | } | |
4683 | ||
6f58d7d7 | 4684 | allow_t action = allow_t(ACCESS_ALLOWED); |
caf3666d | 4685 | |
38450a50 | 4686 | if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpClientFirst]) == 0) { |
6f58d7d7 | 4687 | action.kind = Ssl::bumpClientFirst; |
38450a50 CT |
4688 | bumpCfgStyleNow = bcsNew; |
4689 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpServerFirst]) == 0) { | |
6f58d7d7 | 4690 | action.kind = Ssl::bumpServerFirst; |
38450a50 | 4691 | bumpCfgStyleNow = bcsNew; |
5d65362c CT |
4692 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpPeek]) == 0) { |
4693 | action.kind = Ssl::bumpPeek; | |
4694 | bumpCfgStyleNow = bcsNew; | |
4695 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpStare]) == 0) { | |
4696 | action.kind = Ssl::bumpStare; | |
4697 | bumpCfgStyleNow = bcsNew; | |
4698 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpSplice]) == 0) { | |
4699 | action.kind = Ssl::bumpSplice; | |
4700 | bumpCfgStyleNow = bcsNew; | |
4701 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpBump]) == 0) { | |
4702 | action.kind = Ssl::bumpBump; | |
4703 | bumpCfgStyleNow = bcsNew; | |
4704 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpTerminate]) == 0) { | |
4705 | action.kind = Ssl::bumpTerminate; | |
4706 | bumpCfgStyleNow = bcsNew; | |
38450a50 | 4707 | } else if (strcmp(bm, Ssl::BumpModeStr[Ssl::bumpNone]) == 0) { |
6f58d7d7 | 4708 | action.kind = Ssl::bumpNone; |
38450a50 CT |
4709 | bumpCfgStyleNow = bcsNew; |
4710 | } else if (strcmp(bm, "allow") == 0) { | |
4711 | debugs(3, DBG_CRITICAL, "SECURITY NOTICE: auto-converting deprecated " | |
4712 | "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which " | |
4713 | "is usually inferior to the newer server-first " | |
4714 | "bumping mode. Update your ssl_bump rules."); | |
6f58d7d7 | 4715 | action.kind = Ssl::bumpClientFirst; |
38450a50 CT |
4716 | bumpCfgStyleNow = bcsOld; |
4717 | sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpClientFirst; | |
4718 | } else if (strcmp(bm, "deny") == 0) { | |
4719 | debugs(3, DBG_CRITICAL, "WARNING: auto-converting deprecated " | |
4720 | "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update " | |
4721 | "your ssl_bump rules."); | |
6f58d7d7 | 4722 | action.kind = Ssl::bumpNone; |
38450a50 CT |
4723 | bumpCfgStyleNow = bcsOld; |
4724 | sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpNone; | |
caf3666d AR |
4725 | } else { |
4726 | debugs(3, DBG_CRITICAL, "FATAL: unknown ssl_bump mode: " << bm); | |
4727 | self_destruct(); | |
4728 | return; | |
4729 | } | |
4730 | ||
38450a50 | 4731 | if (bumpCfgStyleLast != bcsNone && bumpCfgStyleNow != bumpCfgStyleLast) { |
87f237a9 | 4732 | debugs(3, DBG_CRITICAL, "FATAL: do not mix " << bumpCfgStyleNow << " actions with " << |
38450a50 CT |
4733 | bumpCfgStyleLast << " actions. Update your ssl_bump rules."); |
4734 | self_destruct(); | |
4735 | return; | |
4736 | } | |
4737 | ||
4738 | bumpCfgStyleLast = bumpCfgStyleNow; | |
4739 | ||
8984b8cd | 4740 | Acl::AndNode *rule = new Acl::AndNode; |
6f58d7d7 | 4741 | rule->context("(ssl_bump rule)", config_input_line); |
8984b8cd CT |
4742 | rule->lineParse(); |
4743 | // empty rule OK | |
6f58d7d7 AR |
4744 | |
4745 | assert(ssl_bump); | |
4746 | if (!*ssl_bump) { | |
4747 | *ssl_bump = new Acl::Tree; | |
4748 | (*ssl_bump)->context("(ssl_bump rules)", config_input_line); | |
4749 | } | |
caf3666d | 4750 | |
6f58d7d7 | 4751 | (*ssl_bump)->add(rule, action); |
caf3666d AR |
4752 | } |
4753 | ||
4754 | static void dump_sslproxy_ssl_bump(StoreEntry *entry, const char *name, acl_access *ssl_bump) | |
4755 | { | |
2cb8d372 FC |
4756 | if (ssl_bump) |
4757 | dump_SBufList(entry, ssl_bump->treeDump(name, Ssl::BumpModeStr)); | |
caf3666d AR |
4758 | } |
4759 | ||
4760 | static void free_sslproxy_ssl_bump(acl_access **ssl_bump) | |
4761 | { | |
4762 | free_acl_access(ssl_bump); | |
4763 | } | |
8277060a CT |
4764 | |
4765 | #endif | |
f4698e0b CT |
4766 | |
4767 | static void dump_HeaderWithAclList(StoreEntry * entry, const char *name, HeaderWithAclList *headers) | |
4768 | { | |
4769 | if (!headers) | |
4770 | return; | |
4771 | ||
4772 | for (HeaderWithAclList::iterator hwa = headers->begin(); hwa != headers->end(); ++hwa) { | |
4773 | storeAppendPrintf(entry, "%s ", hwa->fieldName.c_str()); | |
4774 | storeAppendPrintf(entry, "%s ", hwa->fieldValue.c_str()); | |
4775 | if (hwa->aclList) | |
4776 | dump_acl_list(entry, hwa->aclList); | |
4777 | storeAppendPrintf(entry, "\n"); | |
4778 | } | |
4779 | } | |
4780 | ||
4781 | static void parse_HeaderWithAclList(HeaderWithAclList **headers) | |
4782 | { | |
4783 | char *fn; | |
4784 | if (!*headers) { | |
4785 | *headers = new HeaderWithAclList; | |
4786 | } | |
2eceb328 | 4787 | if ((fn = ConfigParser::NextToken()) == NULL) { |
f4698e0b CT |
4788 | self_destruct(); |
4789 | return; | |
4790 | } | |
4791 | HeaderWithAcl hwa; | |
4792 | hwa.fieldName = fn; | |
4793 | hwa.fieldId = httpHeaderIdByNameDef(fn, strlen(fn)); | |
4794 | if (hwa.fieldId == HDR_BAD_HDR) | |
4795 | hwa.fieldId = HDR_OTHER; | |
4796 | ||
2eceb328 CT |
4797 | Format::Format *nlf = new ::Format::Format("hdrWithAcl"); |
4798 | ConfigParser::EnableMacros(); | |
bde7a8ce | 4799 | String buf = ConfigParser::NextQuotedToken(); |
2eceb328 | 4800 | ConfigParser::DisableMacros(); |
f4698e0b | 4801 | hwa.fieldValue = buf.termedBuf(); |
2eceb328 | 4802 | hwa.quoted = ConfigParser::LastTokenWasQuoted(); |
f4698e0b | 4803 | if (hwa.quoted) { |
f4698e0b CT |
4804 | if (!nlf->parse(hwa.fieldValue.c_str())) { |
4805 | self_destruct(); | |
4806 | return; | |
4807 | } | |
4808 | hwa.valueFormat = nlf; | |
2eceb328 CT |
4809 | } else |
4810 | delete nlf; | |
6f58d7d7 | 4811 | aclParseAclList(LegacyParser, &hwa.aclList, (hwa.fieldName + ':' + hwa.fieldValue).c_str()); |
f4698e0b CT |
4812 | (*headers)->push_back(hwa); |
4813 | } | |
4814 | ||
4815 | static void free_HeaderWithAclList(HeaderWithAclList **header) | |
4816 | { | |
4817 | if (!(*header)) | |
4818 | return; | |
4819 | ||
4820 | for (HeaderWithAclList::iterator hwa = (*header)->begin(); hwa != (*header)->end(); ++hwa) { | |
4821 | if (hwa->aclList) | |
4822 | aclDestroyAclList(&hwa->aclList); | |
4823 | ||
4824 | if (hwa->valueFormat) { | |
4825 | delete hwa->valueFormat; | |
4826 | hwa->valueFormat = NULL; | |
4827 | } | |
4828 | } | |
4829 | delete *header; | |
4830 | *header = NULL; | |
4831 | } | |
d7f4a0b7 CT |
4832 | |
4833 | static void parse_note(Notes *notes) | |
4834 | { | |
4835 | assert(notes); | |
4836 | notes->parse(LegacyParser); | |
4837 | } | |
4838 | ||
4839 | static void dump_note(StoreEntry *entry, const char *name, Notes ¬es) | |
4840 | { | |
4841 | notes.dump(entry, name); | |
4842 | } | |
4843 | ||
4844 | static void free_note(Notes *notes) | |
4845 | { | |
4846 | notes->clean(); | |
4847 | } | |
bde7a8ce | 4848 | |
ddf5aa2b CT |
4849 | static bool FtpEspvDeprecated = false; |
4850 | static void parse_ftp_epsv(acl_access **ftp_epsv) | |
4851 | { | |
4852 | allow_t ftpEpsvDeprecatedAction; | |
4853 | bool ftpEpsvIsDeprecatedRule = false; | |
4854 | ||
4855 | char *t = ConfigParser::PeekAtToken(); | |
e2849af8 | 4856 | if (!t) { |
ddf5aa2b CT |
4857 | self_destruct(); |
4858 | return; | |
4859 | } | |
4860 | ||
4861 | if (!strcmp(t, "off")) { | |
4862 | (void)ConfigParser::NextToken(); | |
4863 | ftpEpsvIsDeprecatedRule = true; | |
4864 | ftpEpsvDeprecatedAction = allow_t(ACCESS_DENIED); | |
4865 | } else if (!strcmp(t, "on")) { | |
4866 | (void)ConfigParser::NextToken(); | |
4867 | ftpEpsvIsDeprecatedRule = true; | |
4868 | ftpEpsvDeprecatedAction = allow_t(ACCESS_ALLOWED); | |
4869 | } | |
4870 | ||
4871 | // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules: | |
4872 | // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off" | |
4873 | // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..." | |
4874 | // then abort | |
4875 | if ((!ftpEpsvIsDeprecatedRule && FtpEspvDeprecated) || | |
e2849af8 | 4876 | (ftpEpsvIsDeprecatedRule && !FtpEspvDeprecated && *ftp_epsv != NULL)) { |
ddf5aa2b CT |
4877 | 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."); |
4878 | self_destruct(); | |
4879 | } | |
4880 | ||
4881 | if (ftpEpsvIsDeprecatedRule) { | |
4882 | // overwrite previous ftp_epsv lines | |
4883 | delete *ftp_epsv; | |
4884 | if (ftpEpsvDeprecatedAction == allow_t(ACCESS_DENIED)) { | |
4885 | Acl::AndNode *ftpEpsvRule = new Acl::AndNode; | |
4886 | ftpEpsvRule->context("(ftp_epsv rule)", config_input_line); | |
4887 | ACL *a = ACL::FindByName("all"); | |
4888 | if (!a) { | |
4889 | self_destruct(); | |
4890 | return; | |
4891 | } | |
4892 | ftpEpsvRule->add(a); | |
4893 | *ftp_epsv = new Acl::Tree; | |
4894 | (*ftp_epsv)->context("(ftp_epsv rules)", config_input_line); | |
4895 | (*ftp_epsv)->add(ftpEpsvRule, ftpEpsvDeprecatedAction); | |
4896 | } else | |
4897 | *ftp_epsv = NULL; | |
4898 | FtpEspvDeprecated = true; | |
4899 | } else { | |
4900 | aclParseAccessLine(cfg_directive, LegacyParser, ftp_epsv); | |
4901 | } | |
4902 | } | |
4903 | ||
4904 | static void dump_ftp_epsv(StoreEntry *entry, const char *name, acl_access *ftp_epsv) | |
4905 | { | |
dfad5100 FC |
4906 | if (ftp_epsv) |
4907 | dump_SBufList(entry, ftp_epsv->treeDump(name, NULL)); | |
ddf5aa2b CT |
4908 | } |
4909 | ||
4910 | static void free_ftp_epsv(acl_access **ftp_epsv) | |
4911 | { | |
4912 | free_acl_access(ftp_epsv); | |
4913 | FtpEspvDeprecated = false; | |
4914 | } | |
4915 | ||
32fd6d8a CT |
4916 | static void |
4917 | parse_url_rewrite_timeout(SquidConfig *config) | |
4918 | { | |
4919 | time_msec_t tval; | |
4920 | parseTimeLine(&tval, T_SECOND_STR, false, true); | |
4921 | Config.Timeout.urlRewrite = static_cast<time_t>(tval/1000); | |
4922 | ||
4923 | char *key, *value; | |
4924 | while(ConfigParser::NextKvPair(key, value)) { | |
4925 | if (strcasecmp(key, "on_timeout") == 0) { | |
4926 | if (strcasecmp(value, "bypass") == 0) | |
4927 | Config.onUrlRewriteTimeout.action = toutActBypass; | |
4928 | else if (strcasecmp(value, "fail") == 0) | |
4929 | Config.onUrlRewriteTimeout.action = toutActFail; | |
4930 | else if (strcasecmp(value, "retry") == 0) | |
4931 | Config.onUrlRewriteTimeout.action = toutActRetry; | |
4932 | else if (strcasecmp(value, "use_configured_response") == 0) { | |
4933 | Config.onUrlRewriteTimeout.action = toutActUseConfiguredResponse; | |
4934 | } else { | |
4935 | debugs(3, DBG_CRITICAL, "FATAL: unsuported \"on_timeout\" action:" << value); | |
4936 | self_destruct(); | |
4937 | } | |
4938 | } else if (strcasecmp(key, "response") == 0) { | |
4939 | Config.onUrlRewriteTimeout.response = xstrdup(value); | |
4940 | } else { | |
4941 | debugs(3, DBG_CRITICAL, "FATAL: unsuported option " << key); | |
4942 | self_destruct(); | |
4943 | } | |
4944 | } | |
4945 | ||
4946 | if (Config.onUrlRewriteTimeout.action == toutActUseConfiguredResponse && !Config.onUrlRewriteTimeout.response) { | |
4947 | debugs(3, DBG_CRITICAL, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option"); | |
4948 | self_destruct(); | |
4949 | } | |
4950 | ||
4951 | if (Config.onUrlRewriteTimeout.action != toutActUseConfiguredResponse && Config.onUrlRewriteTimeout.response) { | |
4952 | debugs(3, DBG_CRITICAL, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option"); | |
4953 | self_destruct(); | |
4954 | } | |
4955 | } | |
4956 | ||
4957 | static void | |
4958 | dump_url_rewrite_timeout(StoreEntry *entry, const char *name, SquidConfig &config) | |
4959 | { | |
4960 | const char *onTimedOutActions[] = {"bypass", "fail", "retry", "use_configured_response"}; | |
4961 | assert(Config.onUrlRewriteTimeout.action >= 0 && Config.onUrlRewriteTimeout.action <= toutActUseConfiguredResponse); | |
4962 | ||
4963 | dump_time_t(entry, name, Config.Timeout.urlRewrite); | |
4964 | storeAppendPrintf(entry, " on_timeout=%s", onTimedOutActions[Config.onUrlRewriteTimeout.action]); | |
4965 | ||
4966 | if (Config.onUrlRewriteTimeout.response) | |
4967 | storeAppendPrintf(entry, " response=\"%s\"", Config.onUrlRewriteTimeout.response); | |
4968 | ||
4969 | storeAppendPrintf(entry, "\n"); | |
4970 | } | |
4971 | ||
4972 | static void | |
4973 | free_url_rewrite_timeout(SquidConfig *config) | |
4974 | { | |
4975 | Config.Timeout.urlRewrite = 0; | |
4976 | Config.onUrlRewriteTimeout.action = 0; | |
4977 | xfree(Config.onUrlRewriteTimeout.response); | |
4978 | Config.onUrlRewriteTimeout.response = NULL; | |
4979 | } | |
4980 | ||
bde7a8ce CT |
4981 | static void |
4982 | parse_configuration_includes_quoted_values(bool *recognizeQuotedValues) | |
4983 | { | |
4984 | int val = 0; | |
4985 | parse_onoff(&val); | |
4986 | ||
4987 | // If quoted values is set to on then enable new strict mode parsing | |
4988 | if (val) { | |
4989 | ConfigParser::RecognizeQuotedValues = true; | |
4990 | ConfigParser::StrictMode = true; | |
4991 | } else { | |
4992 | ConfigParser::RecognizeQuotedValues = false; | |
4993 | ConfigParser::StrictMode = false; | |
4994 | } | |
4995 | } | |
4996 | ||
4997 | static void | |
4998 | dump_configuration_includes_quoted_values(StoreEntry *const entry, const char *const name, bool recognizeQuotedValues) | |
4999 | { | |
5000 | int val = ConfigParser::RecognizeQuotedValues ? 1 : 0; | |
5001 | dump_onoff(entry, name, val); | |
5002 | } | |
5003 | ||
5004 | static void | |
5005 | free_configuration_includes_quoted_values(bool *recognizeQuotedValues) | |
5006 | { | |
5007 | ConfigParser::RecognizeQuotedValues = false; | |
5008 | ConfigParser::StrictMode = false; | |
5009 | } |