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