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