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