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