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