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