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