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