2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 03 Configuration File Parsing */
13 #include "acl/AclDenyInfoList.h"
14 #include "acl/AclSizeLimit.h"
15 #include "acl/Address.h"
16 #include "acl/Gadgets.h"
17 #include "acl/MethodData.h"
19 #include "anyp/PortCfg.h"
20 #include "anyp/UriScheme.h"
21 #include "auth/Config.h"
22 #include "auth/Scheme.h"
24 #include "base/PackableStream.h"
25 #include "base/RunnersRegistry.h"
27 #include "CachePeer.h"
28 #include "ConfigOption.h"
29 #include "ConfigParser.h"
30 #include "CpuAffinityMap.h"
31 #include "DebugMessages.h"
32 #include "DiskIO/DiskIOModule.h"
33 #include "eui/Config.h"
34 #include "ExternalACL.h"
35 #include "format/Format.h"
36 #include "ftp/Elements.h"
38 #include "HttpHeaderTools.h"
39 #include "HttpUpgradeProtocolAccess.h"
40 #include "icmp/IcmpConfig.h"
41 #include "ident/Config.h"
42 #include "ip/Intercept.h"
43 #include "ip/NfMarkConfig.h"
44 #include "ip/QosConfig.h"
47 #include "log/Config.h"
48 #include "log/CustomLog.h"
50 #include "MessageDelayPools.h"
51 #include "mgr/ActionPasswordList.h"
52 #include "mgr/Registration.h"
53 #include "neighbors.h"
54 #include "NeighborTypeDomainList.h"
57 #include "PeerDigest.h"
58 #include "PeerPoolMgr.h"
60 #include "RefreshPattern.h"
62 #include "sbuf/List.h"
63 #include "sbuf/Stream.h"
64 #include "SquidConfig.h"
65 #include "SquidString.h"
66 #include "ssl/ProxyCerts.h"
68 #include "store/Disks.h"
72 /* wccp2 has its own conditional definitions */
75 #include "adaptation/Config.h"
78 #include "adaptation/icap/Config.h"
81 #include "adaptation/ecap/Config.h"
84 #include "ssl/Config.h"
85 #include "ssl/support.h"
88 #include "esi/Parser.h"
106 #if HAVE_SYS_SOCKET_H
107 #include <sys/socket.h>
110 #include <sys/stat.h>
114 #include "ssl/gadgets.h"
118 static void parse_adaptation_service_set_type();
119 static void parse_adaptation_service_chain_type();
120 static void parse_adaptation_access_type();
124 static void parse_icap_service_type(Adaptation::Icap::Config
*);
125 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
126 static void free_icap_service_type(Adaptation::Icap::Config
*);
127 static void parse_icap_class_type();
128 static void parse_icap_access_type();
130 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
131 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
132 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
136 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
137 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
138 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
141 static peer_t
parseNeighborType(const char *s
);
143 static const char *const T_NANOSECOND_STR
= "nanosecond";
144 static const char *const T_MICROSECOND_STR
= "microsecond";
145 static const char *const T_MILLISECOND_STR
= "millisecond";
146 static const char *const T_SECOND_STR
= "second";
147 static const char *const T_MINUTE_STR
= "minute";
148 static const char *const T_HOUR_STR
= "hour";
149 static const char *const T_DAY_STR
= "day";
150 static const char *const T_WEEK_STR
= "week";
151 static const char *const T_FORTNIGHT_STR
= "fortnight";
152 static const char *const T_MONTH_STR
= "month";
153 static const char *const T_YEAR_STR
= "year";
154 static const char *const T_DECADE_STR
= "decade";
156 static const char *const B_BYTES_STR
= "bytes";
157 static const char *const B_KBYTES_STR
= "KB";
158 static const char *const B_MBYTES_STR
= "MB";
159 static const char *const B_GBYTES_STR
= "GB";
161 // std::chrono::years requires C++20. Do our own rough calculation for now.
162 static const double HoursPerYear
= 24*365.2522;
164 static void parse_cache_log_message(DebugMessages
**messages
);
165 static void dump_cache_log_message(StoreEntry
*entry
, const char *name
, const DebugMessages
*messages
);
166 static void free_cache_log_message(DebugMessages
**messages
);
168 static void parse_access_log(CustomLog
** customlog_definitions
);
169 static int check_null_access_log(CustomLog
*customlog_definitions
);
170 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
171 static void free_access_log(CustomLog
** definitions
);
173 static void configDoConfigure(void);
174 static void parse_refreshpattern(RefreshPattern
**);
175 static void parse_u_short(unsigned short * var
);
176 static void parse_string(char **);
177 static void default_all(void);
178 static void defaults_if_none(void);
179 static void defaults_postscriptum(void);
180 static int parse_line(char *);
181 static void parse_obsolete(const char *);
182 static void parseBytesLine(size_t * bptr
, const char *units
);
183 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
184 static size_t parseBytesUnits(const char *unit
);
185 static void free_all(void);
186 void requirePathnameExists(const char *name
, const char *path
);
187 static OBJH dump_config
;
188 #if USE_HTTP_VIOLATIONS
189 static void free_HeaderManglers(HeaderManglers
**pm
);
190 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
191 static void parse_http_header_access(HeaderManglers
**manglers
);
192 #define free_http_header_access free_HeaderManglers
193 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
194 static void parse_http_header_replace(HeaderManglers
**manglers
);
195 #define free_http_header_replace free_HeaderManglers
197 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
198 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
199 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
200 static void parse_note(Notes
*);
201 static void dump_note(StoreEntry
*, const char *, Notes
&);
202 static void free_note(Notes
*);
203 static void parse_denyinfo(AclDenyInfoList
** var
);
204 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
205 static void free_denyinfo(AclDenyInfoList
** var
);
208 static void parse_IpAddress_list(Ip::Address_list
**);
209 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
210 static void free_IpAddress_list(Ip::Address_list
**);
212 static int check_null_IpAddress_list(const Ip::Address_list
*);
213 #endif /* CURRENTLY_UNUSED */
214 #endif /* USE_WCCPv2 */
216 static void parsePortCfg(AnyP::PortCfgPointer
*, const char *protocol
);
217 #define parse_PortCfg(l) parsePortCfg((l), token)
218 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfgPointer
&);
219 #define free_PortCfg(h) *(h)=NULL
222 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
223 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
224 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
225 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
226 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
227 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
228 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
229 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
230 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
231 #endif /* USE_OPENSSL */
233 static void parse_ftp_epsv(acl_access
**ftp_epsv
);
234 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
);
235 static void free_ftp_epsv(acl_access
**ftp_epsv
);
237 static void parse_b_size_t(size_t * var
);
238 static void parse_b_int64_t(int64_t * var
);
240 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
241 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
242 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
244 static void parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
245 static void dump_UrlHelperTimeout(StoreEntry
*, const char *, SquidConfig::UrlHelperTimeout
&);
246 static void free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
248 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
250 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
251 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
252 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
253 static void parse_on_unsupported_protocol(acl_access
**access
);
254 static void dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
);
255 static void free_on_unsupported_protocol(acl_access
**access
);
256 static void ParseAclWithAction(acl_access
**access
, const Acl::Answer
&action
, const char *desc
, ACL
*acl
= nullptr);
257 static void parse_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuards
);
258 static void dump_http_upgrade_request_protocols(StoreEntry
*entry
, const char *name
, HttpUpgradeProtocolAccess
*protoGuards
);
259 static void free_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuards
);
262 * LegacyParser is a parser for legacy code that uses the global
263 * approach. This is static so that it is only exposed to cache_cf.
264 * Other modules needing access to a ConfigParser should have it
265 * provided to them in their parserFOO methods.
267 static ConfigParser LegacyParser
= ConfigParser();
269 const char *cfg_directive
= nullptr;
270 const char *cfg_filename
= nullptr;
271 int config_lineno
= 0;
272 char config_input_line
[BUFSIZ
] = {};
277 LegacyParser
.destruct();
281 SetConfigFilename(char const *file_name
, bool is_pipe
)
284 cfg_filename
= file_name
+ 1;
286 cfg_filename
= file_name
;
290 skip_ws(const char* s
)
299 parseManyConfigFiles(char* files
, int depth
)
302 char* saveptr
= NULL
;
307 memset(&globbuf
, 0, sizeof(globbuf
));
308 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
309 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
311 fatalf("Unable to find configuration file: %s: %s", path
, xstrerr(xerrno
));
314 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
315 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
319 char* file
= strwordtok(files
, &saveptr
);
320 while (file
!= NULL
) {
321 error_count
+= parseOneConfigFile(file
, depth
);
322 file
= strwordtok(NULL
, &saveptr
);
324 #endif /* HAVE_GLOB */
329 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
332 assert(newSubstr
!= NULL
);
334 unsigned newSubstrLen
= strlen(newSubstr
);
335 if (newSubstrLen
> substrLen
)
336 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
338 // move tail part including zero
339 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
340 // copy new substring in place
341 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
347 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
349 assert(line
!= NULL
);
350 assert(macroName
!= NULL
);
351 assert(substStr
!= NULL
);
352 unsigned macroNameLen
= strlen(macroName
);
353 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
354 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
358 ProcessMacros(char*& line
, int& len
)
360 SubstituteMacro(line
, len
, "${service_name}", service_name
.c_str());
361 SubstituteMacro(line
, len
, "${process_name}", TheKidName
.c_str());
362 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
366 trim_trailing_ws(char* str
)
369 unsigned i
= strlen(str
);
370 while ((i
> 0) && xisspace(str
[i
- 1]))
376 FindStatement(const char* line
, const char* statement
)
378 assert(line
!= NULL
);
379 assert(statement
!= NULL
);
381 const char* str
= skip_ws(line
);
382 unsigned len
= strlen(statement
);
383 if (strncmp(str
, statement
, len
) == 0) {
387 else if (xisspace(*str
))
395 StrToInt(const char* str
, long& number
)
400 number
= strtol(str
, &end
, 0);
402 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
406 EvalBoolExpr(const char* expr
)
408 assert(expr
!= NULL
);
409 if (strcmp(expr
, "true") == 0) {
411 } else if (strcmp(expr
, "false") == 0) {
413 } else if (const char* equation
= strchr(expr
, '=')) {
414 const char* rvalue
= skip_ws(equation
+ 1);
415 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
416 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
417 trim_trailing_ws(lvalue
);
420 if (!StrToInt(lvalue
, number1
))
421 fatalf("String is not a integer number: '%s'\n", lvalue
);
423 if (!StrToInt(rvalue
, number2
))
424 fatalf("String is not a integer number: '%s'\n", rvalue
);
427 return number1
== number2
;
429 fatalf("Unable to evaluate expression '%s'\n", expr
);
430 return false; // this place cannot be reached
434 parseOneConfigFile(const char *file_name
, unsigned int depth
)
437 const char *orig_cfg_filename
= cfg_filename
;
438 const int orig_config_lineno
= config_lineno
;
440 char *tmp_line
= NULL
;
441 int tmp_line_len
= 0;
445 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
447 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
451 if (file_name
[0] == '!' || file_name
[0] == '|') {
452 fp
= popen(file_name
+ 1, "r");
455 fp
= fopen(file_name
, "r");
460 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerr(xerrno
));
464 setmode(fileno(fp
), O_TEXT
);
467 SetConfigFilename(file_name
, bool(is_pipe
));
469 memset(config_input_line
, '\0', BUFSIZ
);
473 std::vector
<bool> if_states
;
474 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
477 if ((token
= strchr(config_input_line
, '\n')))
480 if ((token
= strchr(config_input_line
, '\r')))
483 // strip any prefix whitespace off the line.
484 const char *p
= skip_ws(config_input_line
);
485 if (config_input_line
!= p
)
486 memmove(config_input_line
, p
, strlen(p
)+1);
488 if (strncmp(config_input_line
, "#line ", 6) == 0) {
489 static char new_file_name
[1024];
491 static char new_lineno
;
492 token
= config_input_line
+ 6;
493 new_lineno
= strtol(token
, &file
, 0) - 1;
496 continue; /* Not a valid #line directive, may be a comment */
498 while (*file
&& xisspace((unsigned char) *file
))
503 continue; /* Not a valid #line directive, may be a comment */
505 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
507 if ((token
= strchr(new_file_name
, '"')))
510 SetConfigFilename(new_file_name
, false);
513 config_lineno
= new_lineno
;
516 if (config_input_line
[0] == '#')
519 if (config_input_line
[0] == '\0')
522 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
524 size_t append_len
= strlen(append
);
526 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
528 strcpy(tmp_line
+ tmp_line_len
, append
);
530 tmp_line_len
+= append_len
;
532 if (tmp_line
[tmp_line_len
-1] == '\\') {
533 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
534 tmp_line
[--tmp_line_len
] = '\0';
538 trim_trailing_ws(tmp_line
);
539 ProcessMacros(tmp_line
, tmp_line_len
);
540 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
542 if (const char* expr
= FindStatement(tmp_line
, "if")) {
543 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
544 } else if (FindStatement(tmp_line
, "endif")) {
545 if (!if_states
.empty())
546 if_states
.pop_back(); // remove last if-statement meaning
548 fatalf("'endif' without 'if'\n");
549 } else if (FindStatement(tmp_line
, "else")) {
550 if (!if_states
.empty())
551 if_states
.back() = !if_states
.back();
553 fatalf("'else' without 'if'\n");
554 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
555 /* Handle includes here */
556 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
557 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
560 if (!parse_line(tmp_line
)) {
561 debugs(3, DBG_CRITICAL
, ConfigParser::CurrentLocation() << ": unrecognized: '" << tmp_line
<< "'");
566 debugs(3, DBG_CRITICAL
, "configuration error: " << CurrentException
);
576 if (!if_states
.empty())
577 fatalf("if-statement without 'endif'\n");
580 int ret
= pclose(fp
);
583 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
588 SetConfigFilename(orig_cfg_filename
, false);
589 config_lineno
= orig_config_lineno
;
597 parseConfigFileOrThrow(const char *file_name
)
605 ACLMethodData::ThePurgeCount
= 0;
608 err_count
= parseOneConfigFile(file_name
, 0);
612 defaults_postscriptum();
615 * We must call configDoConfigure() before leave_suid() because
616 * configDoConfigure() is where we turn username strings into
621 if (opt_send_signal
== -1) {
622 Mgr::RegisterAction("config",
623 "Current Squid Configuration",
631 // TODO: Refactor main.cc to centrally handle (and report) all exceptions.
633 parseConfigFile(const char *file_name
)
636 return parseConfigFileOrThrow(file_name
);
638 catch (const std::exception
&ex
) {
639 debugs(3, DBG_CRITICAL
, "FATAL: bad configuration: " << ex
.what());
641 return 1; // not reached
646 * The templated functions below are essentially ConfigParser methods. They are
647 * not implemented as such because our generated code calling them is the only
648 * code that can instantiate implementations for each T -- we cannot place these
649 * definitions into ConfigParser.cc unless cf_parser.cci is moved there.
652 // TODO: When adding Ts incompatible with this trivial API and implementation,
653 // replace both with a ConfigParser-maintained table of seen directives.
654 /// whether we have seen (and, hence, configured) the given directive
655 template <typename T
>
657 SawDirective(const T
&raw
)
662 /// Sets the given raw SquidConfig data member.
663 /// Extracts and interprets parser's configuration tokens.
664 template <typename T
>
666 ParseDirective(T
&raw
, ConfigParser
&parser
)
668 if (SawDirective(raw
))
669 parser
.rejectDuplicateDirective();
671 // TODO: parser.openDirective(directiveName);
673 raw
= Configuration::Component
<T
>::Parse(parser
);
675 parser
.closeDirective();
678 /// reports raw SquidConfig data member configuration using squid.conf syntax
679 /// \param name the name of the configuration directive being dumped
680 template <typename T
>
682 DumpDirective(const T
&raw
, StoreEntry
*entry
, const char *name
)
684 if (!SawDirective(raw
))
685 return; // not configured
687 entry
->append(name
, strlen(name
));
689 Configuration::Component
<T
>::Print(os
, raw
);
690 const auto buf
= os
.buf();
692 entry
->append(" ", 1);
693 entry
->append(buf
.rawContent(), buf
.length());
695 entry
->append("\n", 1);
698 /// frees any resources associated with the given raw SquidConfig data member
699 template <typename T
>
701 FreeDirective(T
&raw
)
703 Configuration::Component
<T
>::Free(raw
);
705 // While the implementation may change, there is no way to avoid zeroing.
706 // Even migration to a proper SquidConfig class would not help: While
707 // ordinary destructors do not need to zero data members, a SquidConfig
708 // destructor would have to zero to protect any SquidConfig::x destruction
709 // code from accidentally dereferencing an already destroyed Config.y.
710 static_assert(std::is_trivial
<T
>::value
, "SquidConfig member is trivial");
711 memset(&raw
, 0, sizeof(raw
));
715 configDoConfigure(void)
718 /* init memory as early as possible */
722 if (Debug::rotateNumber
< 0) {
723 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
726 #if SIZEOF_OFF_T <= 4
727 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
728 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
729 Config
.Store
.maxObjectSize
= 0x7FFF0000;
733 if (Config
.Announce
.period
> 0) {
734 Config
.onoff
.announce
= 1;
736 Config
.Announce
.period
= 86400 * 365; /* one year */
737 Config
.onoff
.announce
= 0;
740 if (Config
.onoff
.httpd_suppress_version_string
)
741 visible_appname_string
= (char *)appname_string
;
743 visible_appname_string
= (char const *)APP_FULLNAME
;
745 if (Config
.Program
.redirect
) {
746 if (Config
.redirectChildren
.n_max
< 1) {
747 Config
.redirectChildren
.n_max
= 0;
748 wordlistDestroy(&Config
.Program
.redirect
);
752 if (Config
.Program
.store_id
) {
753 if (Config
.storeIdChildren
.n_max
< 1) {
754 Config
.storeIdChildren
.n_max
= 0;
755 wordlistDestroy(&Config
.Program
.store_id
);
759 if (Config
.appendDomain
)
760 if (*Config
.appendDomain
!= '.')
761 fatal("append_domain must begin with a '.'");
763 if (Config
.errHtmlText
== NULL
)
764 Config
.errHtmlText
= xstrdup(null_string
);
766 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
767 if (Config
.max_filedescriptors
> 0) {
768 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
770 #elif USE_SELECT || USE_SELECT_WIN32
771 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
772 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
778 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
780 visible_appname_string
);
783 * the extra space is for loop detection in client_side.c -- we search
784 * for substrings in the Via header.
786 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
788 visible_appname_string
);
790 /* Use visible_hostname as default surrogate_id */
791 if (!Config
.Accel
.surrogate_id
) {
792 const char *t
= getMyHostname();
793 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
796 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
797 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
799 if (Config
.appendDomain
)
800 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
802 Config
.appendDomainLen
= 0;
804 if (Config
.connect_retries
> 10) {
805 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
806 Config
.connect_retries
= 10;
809 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
812 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
814 bool logDaemonUsed
= false;
815 for (const auto *log
= Config
.Log
.accesslogs
; !logDaemonUsed
&& log
; log
= log
->next
)
816 logDaemonUsed
= log
->usesDaemon();
818 for (const auto *log
= Config
.Log
.icaplogs
; !logDaemonUsed
&& log
; log
= log
->next
)
819 logDaemonUsed
= log
->usesDaemon();
822 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
824 if (Config
.Program
.redirect
)
825 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
827 if (Config
.Program
.store_id
)
828 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
830 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
832 if (Config
.errorDirectory
)
833 requirePathnameExists("Error Directory", Config
.errorDirectory
);
835 #if USE_HTTP_VIOLATIONS
838 const RefreshPattern
*R
;
840 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
841 if (!R
->flags
.override_expire
)
844 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
849 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
850 if (!R
->flags
.override_lastmod
)
853 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
858 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
859 if (!R
->flags
.reload_into_ims
)
862 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
867 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
868 if (!R
->flags
.ignore_reload
)
871 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
876 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
877 if (!R
->flags
.ignore_no_store
)
880 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
885 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
886 if (!R
->flags
.ignore_private
)
889 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
895 #if !USE_HTTP_VIOLATIONS
896 Config
.onoff
.via
= 1;
899 if (!Config
.onoff
.via
)
900 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
904 // we enable runtime PURGE checks if there is at least one PURGE method ACL
905 // TODO: replace with a dedicated "purge" ACL option?
906 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
908 if (geteuid() == 0) {
909 if (NULL
!= Config
.effectiveUser
) {
911 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
915 * Andres Kroonmaa <andre@online.ee>:
916 * Some getpwnam() implementations (Solaris?) require
917 * an available FD < 256 for opening a FILE* to the
920 * This should be safe at startup, but might still fail
921 * during reconfigure.
923 fatalf("getpwnam failed to find userid for effective user '%s'",
924 Config
.effectiveUser
);
928 Config2
.effectiveUserID
= pwd
->pw_uid
;
930 Config2
.effectiveGroupID
= pwd
->pw_gid
;
933 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
934 // putenv() leaks by design; avoid leaks when nothing changes
936 if (lastDir
.isEmpty() || lastDir
.cmp(pwd
->pw_dir
) != 0) {
937 lastDir
= pwd
->pw_dir
;
938 int len
= strlen(pwd
->pw_dir
) + 6;
939 char *env_str
= (char *)xcalloc(len
, 1);
940 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
947 Config2
.effectiveUserID
= geteuid();
948 Config2
.effectiveGroupID
= getegid();
951 if (NULL
!= Config
.effectiveGroup
) {
953 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
956 fatalf("getgrnam failed to find groupid for effective group '%s'",
957 Config
.effectiveGroup
);
961 Config2
.effectiveGroupID
= grp
->gr_gid
;
965 if (Config
.ssl_client
.foreignIntermediateCertsPath
)
966 Ssl::loadSquidUntrusted(Config
.ssl_client
.foreignIntermediateCertsPath
);
969 if (Security::ProxyOutgoingConfig
.encryptTransport
) {
970 debugs(3, DBG_IMPORTANT
, "Initializing https:// proxy context");
971 Config
.ssl_client
.sslContext
= Security::ProxyOutgoingConfig
.createClientContext(false);
972 if (!Config
.ssl_client
.sslContext
) {
974 fatal("ERROR: Could not initialize https:// proxy context");
976 debugs(3, DBG_IMPORTANT
, "ERROR: proxying https:// currently still requires --with-openssl");
980 Ssl::useSquidUntrusted(Config
.ssl_client
.sslContext
.get());
984 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
986 // default value for ssldomain= is the peer host/IP
987 if (p
->secure
.sslDomain
.isEmpty())
988 p
->secure
.sslDomain
= p
->host
;
990 if (p
->secure
.encryptTransport
) {
991 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " TLS context");
992 p
->sslContext
= p
->secure
.createClientContext(true);
993 if (!p
->sslContext
) {
994 debugs(3, DBG_CRITICAL
, "ERROR: Could not initialize cache_peer " << p
->name
<< " TLS context");
1001 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
1002 if (!s
->secure
.encryptTransport
)
1004 debugs(3, DBG_IMPORTANT
, "Initializing " << AnyP::UriScheme(s
->transport
.protocol
) << "_port " << s
->s
<< " TLS contexts");
1005 s
->secure
.initServerContexts(*s
);
1008 // prevent infinite fetch loops in the request parser
1009 // due to buffer full but not enough data received to finish parse
1010 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
1011 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
1012 " Change client_request_buffer_max or request_header_max_size limits.",
1013 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
1017 * Disable client side request pipelining if client_persistent_connections OFF.
1018 * Waste of resources queueing any pipelined requests when the first will close the connection.
1020 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
1021 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
1022 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
1023 Config
.pipeline_max_prefetch
= 0;
1028 * disable client side request pipelining. There is a race with
1029 * Negotiate and NTLM when the client sends a second request on an
1030 * connection before the authenticate challenge is sent. With
1031 * pipelining OFF, the client may fail to authenticate, but squid's
1032 * state will be preserved.
1034 if (Config
.pipeline_max_prefetch
> 0) {
1035 Auth::SchemeConfig
*nego
= Auth::SchemeConfig::Find("Negotiate");
1036 Auth::SchemeConfig
*ntlm
= Auth::SchemeConfig::Find("NTLM");
1037 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
1038 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
1039 Config
.pipeline_max_prefetch
= 0;
1043 for (auto &authSchemes
: Auth::TheConfig
.schemeLists
) {
1044 authSchemes
.expand();
1045 if (authSchemes
.authConfigs
.empty()) {
1046 debugs(3, DBG_CRITICAL
, "auth_schemes: at least one scheme name is required; got: " << authSchemes
.rawSchemes
);
1053 /** Parse a line containing an obsolete directive.
1054 * To upgrade it where possible instead of just "Bungled config" for
1055 * directives which cannot be marked as simply aliases of the some name.
1056 * For example if the parameter order and content has changed.
1057 * Or if the directive has been completely removed.
1060 parse_obsolete(const char *name
)
1062 // Directives which have been radically changed rather than removed
1063 if (!strcmp(name
, "url_rewrite_concurrency")) {
1066 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
1067 Config
.redirectChildren
.concurrency
= cval
;
1070 if (!strcmp(name
, "log_access")) {
1075 if (!strcmp(name
, "log_icap")) {
1080 if (!strcmp(name
, "ignore_ims_on_miss")) {
1081 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1082 // than the 2.7 directive. We need to parse and invert the configured value.
1085 Config
.onoff
.cache_miss_revalidate
= !temp
;
1088 if (!strncmp(name
, "sslproxy_", 9)) {
1089 // the replacement directive tls_outgoing_options uses options instead of whole-line input
1091 if (!strcmp(name
, "sslproxy_cafile"))
1092 tmp
.append("cafile=");
1093 else if (!strcmp(name
, "sslproxy_capath"))
1094 tmp
.append("capath=");
1095 else if (!strcmp(name
, "sslproxy_cipher"))
1096 tmp
.append("cipher=");
1097 else if (!strcmp(name
, "sslproxy_client_certificate"))
1098 tmp
.append("cert=");
1099 else if (!strcmp(name
, "sslproxy_client_key"))
1101 else if (!strcmp(name
, "sslproxy_flags"))
1102 tmp
.append("flags=");
1103 else if (!strcmp(name
, "sslproxy_options"))
1104 tmp
.append("options=");
1105 else if (!strcmp(name
, "sslproxy_version"))
1106 tmp
.append("version=");
1108 debugs(3, DBG_CRITICAL
, "ERROR: unknown directive: " << name
);
1113 // add the value as unquoted-string because the old values did not support whitespace
1114 const char *token
= ConfigParser::NextQuotedOrToEol();
1115 tmp
.append(token
, strlen(token
));
1116 Security::ProxyOutgoingConfig
.parse(tmp
.c_str());
1120 template <class MinimalUnit
>
1124 const auto minUnit
= MinimalUnit(1);
1125 if(minUnit
== std::chrono::nanoseconds(1))
1126 return T_NANOSECOND_STR
;
1127 else if (minUnit
== std::chrono::microseconds(1))
1128 return T_MICROSECOND_STR
;
1129 else if (minUnit
== std::chrono::milliseconds(1))
1130 return T_MILLISECOND_STR
;
1132 assert(minUnit
>= std::chrono::seconds(1));
1133 return T_SECOND_STR
;
1137 /// Assigns 'ns' the number of nanoseconds corresponding to 'unitName'.
1138 /// \param MinimalUnit is a chrono duration type specifying the minimal
1139 /// allowed time unit.
1140 /// \returns true if unitName is correct and its time unit is not less
1141 /// than MinimalUnit.
1142 template <class MinimalUnit
>
1144 parseTimeUnit(const char *unitName
, std::chrono::nanoseconds
&ns
)
1147 throw TexcHere("missing time unit");
1149 if (!strncasecmp(unitName
, T_NANOSECOND_STR
, strlen(T_NANOSECOND_STR
)))
1150 ns
= std::chrono::nanoseconds(1);
1151 else if (!strncasecmp(unitName
, T_MICROSECOND_STR
, strlen(T_MICROSECOND_STR
)))
1152 ns
= std::chrono::microseconds(1);
1153 else if (!strncasecmp(unitName
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1154 ns
= std::chrono::milliseconds(1);
1155 else if (!strncasecmp(unitName
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1156 ns
= std::chrono::seconds(1);
1157 else if (!strncasecmp(unitName
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1158 ns
= std::chrono::minutes(1);
1159 else if (!strncasecmp(unitName
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1160 ns
= std::chrono::hours(1);
1161 else if (!strncasecmp(unitName
, T_DAY_STR
, strlen(T_DAY_STR
)))
1162 ns
= std::chrono::hours(24);
1163 else if (!strncasecmp(unitName
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1164 ns
= std::chrono::hours(24 * 7);
1165 else if (!strncasecmp(unitName
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1166 ns
= std::chrono::hours(24 * 14);
1167 else if (!strncasecmp(unitName
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1168 ns
= std::chrono::hours(24 * 30);
1169 else if (!strncasecmp(unitName
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1170 ns
= std::chrono::hours(static_cast<std::chrono::hours::rep
>(HoursPerYear
));
1171 else if (!strncasecmp(unitName
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1172 ns
= std::chrono::hours(static_cast<std::chrono::hours::rep
>(HoursPerYear
* 10));
1176 if (ns
< MinimalUnit(1)) {
1177 throw TexcHere(ToSBuf("time unit '", unitName
, "' is too small to be used in this context, the minimal unit is ",
1178 TimeUnitToString
<MinimalUnit
>()));
1184 static std::chrono::nanoseconds
1185 ToNanoSeconds(const double value
, const std::chrono::nanoseconds
&unit
)
1188 throw TexcHere("time must have a positive value");
1190 if (value
> (static_cast<double>(std::chrono::nanoseconds::max().count()) / unit
.count())) {
1191 const auto maxYears
= std::chrono::duration_cast
<std::chrono::hours
>(std::chrono::nanoseconds::max()).count()/HoursPerYear
;
1192 throw TexcHere(ToSBuf("time values cannot exceed ", maxYears
, " years"));
1195 return std::chrono::duration_cast
<std::chrono::nanoseconds
>(unit
* value
);
1198 template <class TimeUnit
>
1200 FromNanoseconds(const std::chrono::nanoseconds
&ns
, const double parsedValue
)
1202 const auto result
= std::chrono::duration_cast
<TimeUnit
>(ns
);
1203 if (!result
.count()) {
1204 throw TexcHere(ToSBuf("time value '", parsedValue
,
1205 "' is too small to be used in this context, the minimal value is 1 ",
1206 TimeUnitToString
<TimeUnit
>()));
1211 /// Parses a time specification from the config file and
1212 /// returns the time as a chrono duration object of 'TimeUnit' type.
1213 template <class TimeUnit
>
1217 const auto valueToken
= ConfigParser::NextToken();
1219 throw TexcHere("cannot read a time value");
1221 const auto parsedValue
= xatof(valueToken
);
1223 if (parsedValue
== 0)
1224 return TimeUnit::zero();
1226 std::chrono::nanoseconds parsedUnitDuration
;
1228 const auto token
= ConfigParser::PeekAtToken();
1230 if (!parseTimeUnit
<TimeUnit
>(token
, parsedUnitDuration
))
1231 throw TexcHere(ToSBuf("unknown time unit '", token
, "'"));
1233 (void)ConfigParser::NextToken();
1235 const auto nanoseconds
= ToNanoSeconds(parsedValue
, parsedUnitDuration
);
1237 // validate precisions (time-units-small only)
1238 if (TimeUnit(1) <= std::chrono::microseconds(1)) {
1239 if (0 < nanoseconds
.count() && nanoseconds
.count() < 3) {
1240 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), ConfigParser::CurrentLocation() << ": WARNING: " <<
1241 "Squid time measurement precision is likely to be far worse than " <<
1242 "the nanosecond-level precision implied by the configured value: " << parsedValue
<< ' ' << token
);
1246 return FromNanoseconds
<TimeUnit
>(nanoseconds
, parsedValue
);
1250 parseBytesLine64(int64_t * bptr
, const char *units
)
1257 if ((u
= parseBytesUnits(units
)) == 0) {
1262 if ((token
= ConfigParser::NextToken()) == NULL
) {
1267 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1274 m
= u
; /* default to 'units' if none specified */
1278 else if ((token
= ConfigParser::NextToken()) == NULL
)
1279 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1280 config_input_line
<< "', assuming " <<
1281 d
<< " " << units
);
1282 else if ((m
= parseBytesUnits(token
)) == 0) {
1287 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1289 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1290 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1291 d
<< " " << token
<< ": integer overflow (int64_t).");
1297 parseBytesLine(size_t * bptr
, const char *units
)
1304 if ((u
= parseBytesUnits(units
)) == 0) {
1309 if ((token
= ConfigParser::NextToken()) == NULL
) {
1314 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1315 *bptr
= static_cast<size_t>(-1);
1321 m
= u
; /* default to 'units' if none specified */
1325 else if ((token
= ConfigParser::NextToken()) == NULL
)
1326 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1327 config_input_line
<< "', assuming " <<
1328 d
<< " " << units
);
1329 else if ((m
= parseBytesUnits(token
)) == 0) {
1334 *bptr
= static_cast<size_t>(m
* d
/ u
);
1336 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1337 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1338 d
<< " " << token
<< ": integer overflow (size_t).");
1344 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1351 if ((u
= parseBytesUnits(units
)) == 0) {
1356 if ((token
= ConfigParser::NextToken()) == NULL
) {
1361 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1368 m
= u
; /* default to 'units' if none specified */
1372 else if ((token
= ConfigParser::NextToken()) == NULL
)
1373 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1374 config_input_line
<< "', assuming " <<
1375 d
<< " " << units
);
1376 else if ((m
= parseBytesUnits(token
)) == 0) {
1381 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1383 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1384 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1385 d
<< " " << token
<< ": integer overflow (ssize_t).");
1391 * Parse bytes from a string.
1392 * Similar to the parseBytesLine function but parses the string value instead of
1393 * the current token value.
1396 parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1399 if ((u
= parseBytesUnits(units
)) == 0) {
1404 // Find number from string beginning.
1405 char const * number_begin
= value
;
1406 char const * number_end
= value
;
1408 while ((*number_end
>= '0' && *number_end
<= '9')) {
1413 number
.assign(number_begin
, number_end
- number_begin
);
1415 int d
= xatoi(number
.termedBuf());
1417 if ((m
= parseBytesUnits(number_end
)) == 0) {
1422 *bptr
= static_cast<size_t>(m
* d
/ u
);
1423 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1428 parseBytesUnits(const char *unit
)
1430 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1433 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1436 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1439 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1442 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1448 parse_SBufList(SBufList
* list
)
1450 while (char *token
= ConfigParser::NextQuotedToken())
1451 list
->push_back(SBuf(token
));
1454 // just dump a list, no directive name
1456 dump_SBufList(StoreEntry
* entry
, const SBufList
&words
)
1458 for (const auto &i
: words
) {
1459 entry
->append(i
.rawContent(), i
.length());
1460 entry
->append(" ",1);
1462 entry
->append("\n",1);
1465 // dump a SBufList type directive with name
1467 dump_SBufList(StoreEntry
* entry
, const char *name
, SBufList
&list
)
1469 if (!list
.empty()) {
1470 entry
->append(name
, strlen(name
));
1471 entry
->append(" ", 1);
1472 dump_SBufList(entry
, list
);
1477 free_SBufList(SBufList
*list
)
1484 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1486 while (ae
!= NULL
) {
1487 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1488 storeAppendPrintf(entry
, "%s %s %s ",
1493 tail
.splice(tail
.end(), ae
->dumpOptions());
1494 tail
.splice(tail
.end(), ae
->dump()); // ACL parameters
1495 dump_SBufList(entry
, tail
);
1501 parse_acl(ACL
** ae
)
1503 ACL::ParseAclLine(LegacyParser
, ae
);
1513 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1515 // XXX: Should dump ACL names like "foo !bar" but dumps parsing context like
1516 // "(clientside_tos 0x11 line)".
1517 dump_SBufList(entry
, head
->dump());
1521 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1524 dump_SBufList(entry
, head
->treeDump(name
, &Acl::AllowOrDeny
));
1528 parse_acl_access(acl_access
** head
)
1530 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1534 free_acl_access(acl_access
** head
)
1536 aclDestroyAccessList(head
);
1540 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1542 char buf
[MAX_IPSTRLEN
];
1543 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1547 parse_address(Ip::Address
*addr
)
1549 char *token
= ConfigParser::NextToken();
1556 if (!strcmp(token
,"any_addr"))
1558 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1560 else if ( (*addr
= token
) ) // try parse numeric/IPA
1562 else if (addr
->GetHostByName(token
)) // do not use ipcache
1564 else { // not an IP and not a hostname
1565 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
1571 free_address(Ip::Address
*addr
)
1577 dump_acl_address(StoreEntry
* entry
, const char *name
, Acl::Address
* head
)
1579 char buf
[MAX_IPSTRLEN
];
1581 for (Acl::Address
*l
= head
; l
; l
= l
->next
) {
1582 if (!l
->addr
.isAnyAddr())
1583 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.toStr(buf
,MAX_IPSTRLEN
));
1585 storeAppendPrintf(entry
, "%s autoselect", name
);
1587 dump_acl_list(entry
, l
->aclList
);
1589 storeAppendPrintf(entry
, "\n");
1594 parse_acl_address(Acl::Address
** head
)
1596 Acl::Address
*l
= new Acl::Address
;
1597 parse_address(&l
->addr
);
1598 aclParseAclList(LegacyParser
, &l
->aclList
, l
->addr
);
1600 Acl::Address
**tail
= head
;
1602 tail
= &(*tail
)->next
;
1608 free_acl_address(Acl::Address
** head
)
1615 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1619 for (l
= head
; l
; l
= l
->next
) {
1621 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1623 storeAppendPrintf(entry
, "%s none", name
);
1625 dump_acl_list(entry
, l
->aclList
);
1627 storeAppendPrintf(entry
, "\n");
1632 parse_acl_tos(acl_tos
** head
)
1634 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1635 char *token
= ConfigParser::NextToken();
1642 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1647 const unsigned int chTos
= tos
& 0xFC;
1649 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: Tos value '" << tos
<< "' adjusted to '" << chTos
<< "'");
1653 acl_tos
*l
= new acl_tos
;
1655 l
->tos
= (tos_t
)tos
;
1657 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1659 acl_tos
**tail
= head
; /* sane name below */
1661 tail
= &(*tail
)->next
;
1667 free_acl_tos(acl_tos
** head
)
1673 #if SO_MARK && USE_LIBCAP
1676 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1678 for (acl_nfmark
*l
= head
; l
; l
= l
->next
) {
1679 storeAppendPrintf(entry
, "%s %s", name
, ToSBuf(l
->markConfig
).c_str());
1681 dump_acl_list(entry
, l
->aclList
);
1683 storeAppendPrintf(entry
, "\n");
1688 parse_acl_nfmark(acl_nfmark
** head
)
1690 SBuf
token(ConfigParser::NextToken());
1691 const auto mc
= Ip::NfMarkConfig::Parse(token
);
1693 // Packet marking directives should not allow to use masks.
1694 const auto pkt_dirs
= {"mark_client_packet", "clientside_mark", "tcp_outgoing_mark"};
1695 if (mc
.hasMask() && std::find(pkt_dirs
.begin(), pkt_dirs
.end(), cfg_directive
) != pkt_dirs
.end())
1696 throw TexcHere(ToSBuf("'", cfg_directive
, "' does not support masked marks"));
1698 acl_nfmark
*l
= new acl_nfmark
;
1701 aclParseAclList(LegacyParser
, &l
->aclList
, token
.c_str());
1703 acl_nfmark
**tail
= head
; /* sane name below */
1705 tail
= &(*tail
)->next
;
1711 free_acl_nfmark(acl_nfmark
** head
)
1716 #endif /* SO_MARK */
1719 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1721 for (AclSizeLimit
*l
= head
; l
; l
= l
->next
) {
1723 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1725 storeAppendPrintf(entry
, "%s none", name
);
1727 dump_acl_list(entry
, l
->aclList
);
1729 storeAppendPrintf(entry
, "\n");
1734 parse_acl_b_size_t(AclSizeLimit
** head
)
1736 AclSizeLimit
*l
= new AclSizeLimit
;
1738 parse_b_int64_t(&l
->size
);
1740 aclParseAclList(LegacyParser
, &l
->aclList
, l
->size
);
1742 AclSizeLimit
**tail
= head
; /* sane name below */
1744 tail
= &(*tail
)->next
;
1750 free_acl_b_size_t(AclSizeLimit
** head
)
1758 #include "DelayConfig.h"
1759 #include "DelayPools.h"
1760 /* do nothing - free_delay_pool_count is the magic free function.
1761 * this is why delay_pool_count isn't just marked TYPE: u_short
1763 #define free_delay_pool_class(X)
1764 #define free_delay_pool_access(X)
1765 #define free_delay_pool_rates(X)
1766 #define dump_delay_pool_class(X, Y, Z)
1767 #define dump_delay_pool_access(X, Y, Z)
1768 #define dump_delay_pool_rates(X, Y, Z)
1771 free_delay_pool_count(DelayConfig
* cfg
)
1773 cfg
->freePoolCount();
1777 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1779 cfg
.dumpPoolCount (entry
, name
);
1783 parse_delay_pool_count(DelayConfig
* cfg
)
1785 cfg
->parsePoolCount();
1789 parse_delay_pool_class(DelayConfig
* cfg
)
1791 cfg
->parsePoolClass();
1795 parse_delay_pool_rates(DelayConfig
* cfg
)
1797 cfg
->parsePoolRates();
1801 parse_delay_pool_access(DelayConfig
* cfg
)
1803 cfg
->parsePoolAccess(LegacyParser
);
1809 #include "ClientDelayConfig.h"
1810 /* do nothing - free_client_delay_pool_count is the magic free function.
1811 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1814 #define free_client_delay_pool_access(X)
1815 #define free_client_delay_pool_rates(X)
1816 #define dump_client_delay_pool_access(X, Y, Z)
1817 #define dump_client_delay_pool_rates(X, Y, Z)
1820 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1826 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1828 cfg
.dumpPoolCount (entry
, name
);
1832 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1834 cfg
->parsePoolCount();
1838 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1840 cfg
->parsePoolRates();
1844 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1846 cfg
->parsePoolAccess(LegacyParser
);
1850 #if USE_HTTP_VIOLATIONS
1852 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1855 manglers
->dumpAccess(entry
, name
);
1859 parse_http_header_access(HeaderManglers
**pm
)
1863 if ((t
= ConfigParser::NextToken()) == NULL
) {
1864 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1865 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1870 *pm
= new HeaderManglers
;
1871 HeaderManglers
*manglers
= *pm
;
1872 headerMangler
*mangler
= manglers
->track(t
);
1875 std::string directive
= "http_header_access ";
1877 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1881 free_HeaderManglers(HeaderManglers
**pm
)
1883 // we delete the entire http_header_* mangler configuration at once
1884 if (const HeaderManglers
*manglers
= *pm
) {
1891 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1894 manglers
->dumpReplacement(entry
, name
);
1898 parse_http_header_replace(HeaderManglers
**pm
)
1902 if ((t
= ConfigParser::NextToken()) == NULL
) {
1903 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1904 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1908 const char *value
= ConfigParser::NextQuotedOrToEol();
1911 *pm
= new HeaderManglers
;
1912 HeaderManglers
*manglers
= *pm
;
1913 manglers
->setReplacement(t
, value
);
1919 dump_cachedir(StoreEntry
* entry
, const char *name
, const Store::DiskConfig
&swap
)
1921 Store::Disks::Dump(swap
, *entry
, name
);
1925 check_null_string(char *s
)
1932 parse_authparam(Auth::ConfigVector
* config
)
1934 char *type_str
= ConfigParser::NextToken();
1940 char *param_str
= ConfigParser::NextToken();
1946 /* find a configuration for the scheme in the currently parsed configs... */
1947 Auth::SchemeConfig
*schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1949 if (schemeCfg
== NULL
) {
1950 /* Create a configuration based on the scheme info */
1951 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1953 if (theScheme
== NULL
) {
1954 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1959 config
->push_back(theScheme
->createConfig());
1960 schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1961 if (schemeCfg
== NULL
) {
1962 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1968 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1972 free_authparam(Auth::ConfigVector
* cfg
)
1974 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1977 /* on reconfigure initialize new auth schemes for the new config. */
1978 if (reconfiguring
) {
1984 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1986 for (auto *scheme
: cfg
)
1987 scheme
->dump(entry
, name
, scheme
);
1991 parse_AuthSchemes(acl_access
**authSchemes
)
1993 const char *tok
= ConfigParser::NextQuotedToken();
1995 debugs(29, DBG_CRITICAL
, "FATAL: auth_schemes missing the parameter");
1999 Auth::TheConfig
.schemeLists
.emplace_back(tok
, ConfigParser::LastTokenWasQuoted());
2000 const auto action
= Acl::Answer(ACCESS_ALLOWED
, Auth::TheConfig
.schemeLists
.size() - 1);
2001 ParseAclWithAction(authSchemes
, action
, "auth_schemes");
2005 free_AuthSchemes(acl_access
**authSchemes
)
2007 Auth::TheConfig
.schemeLists
.clear();
2008 free_acl_access(authSchemes
);
2012 dump_AuthSchemes(StoreEntry
*entry
, const char *name
, acl_access
*authSchemes
)
2015 dump_SBufList(entry
, authSchemes
->treeDump(name
, [](const Acl::Answer
&action
) {
2016 return Auth::TheConfig
.schemeLists
.at(action
.kind
).rawSchemes
;
2020 #endif /* USE_AUTH */
2023 ParseAclWithAction(acl_access
**access
, const Acl::Answer
&action
, const char *desc
, ACL
*acl
)
2028 *access
= new Acl::Tree
;
2029 name
.Printf("(%s rules)", desc
);
2030 (*access
)->context(name
.c_str(), config_input_line
);
2032 Acl::AndNode
*rule
= new Acl::AndNode
;
2033 name
.Printf("(%s rule)", desc
);
2034 rule
->context(name
.c_str(), config_input_line
);
2039 (*access
)->add(rule
, action
);
2043 parse_cachedir(Store::DiskConfig
*swap
)
2046 Store::Disks::Parse(*swap
);
2050 peer_type_str(const peer_t type
)
2052 const char * result
;
2064 case PEER_MULTICAST
:
2065 result
= "multicast";
2077 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2079 NeighborTypeDomainList
*t
;
2080 LOCAL_ARRAY(char, xname
, 128);
2083 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2090 dump_peer_options(entry
, p
);
2093 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2094 dump_acl_access(entry
, xname
, p
->access
);
2097 for (t
= p
->typelist
; t
; t
= t
->next
) {
2098 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2100 peer_type_str(t
->type
),
2109 * utility function to prevent getservbyname() being called with a numeric value
2110 * on Windows at least it returns garage results.
2113 isUnsignedNumeric(const char *str
, size_t len
)
2115 if (len
< 1) return false;
2117 for (; len
>0 && *str
; ++str
, --len
) {
2118 if (! isdigit(*str
))
2125 \param proto 'tcp' or 'udp' for protocol
2126 \returns Port the named service is supposed to be listening on.
2128 static unsigned short
2129 GetService(const char *proto
)
2131 struct servent
*port
= NULL
;
2132 /** Parses a port number or service name from the squid.conf */
2133 char *token
= ConfigParser::NextToken();
2134 if (token
== NULL
) {
2136 return 0; /* NEVER REACHED */
2138 /** Returns either the service port number from /etc/services */
2139 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2140 port
= getservbyname(token
, proto
);
2142 return ntohs((unsigned short)port
->s_port
);
2144 /** Or a numeric translation of the config text. */
2145 return xatos(token
);
2149 \returns Port the named TCP service is supposed to be listening on.
2150 \copydoc GetService(const char *proto)
2152 inline unsigned short
2155 return GetService("tcp");
2159 \returns Port the named UDP service is supposed to be listening on.
2160 \copydoc GetService(const char *proto)
2162 inline unsigned short
2165 return GetService("udp");
2169 parse_peer(CachePeer
** head
)
2171 char *host_str
= ConfigParser::NextToken();
2177 char *token
= ConfigParser::NextToken();
2183 CachePeer
*p
= new CachePeer
;
2184 p
->host
= xstrdup(host_str
);
2186 p
->name
= xstrdup(host_str
);
2187 p
->type
= parseNeighborType(token
);
2189 if (p
->type
== PEER_MULTICAST
) {
2190 p
->options
.no_digest
= true;
2191 p
->options
.no_netdb_exchange
= true;
2194 p
->http_port
= GetTcpService();
2196 if (!p
->http_port
) {
2202 p
->icp
.port
= GetUdpService();
2204 while ((token
= ConfigParser::NextToken())) {
2205 if (!strcmp(token
, "proxy-only")) {
2206 p
->options
.proxy_only
= true;
2207 } else if (!strcmp(token
, "no-query")) {
2208 p
->options
.no_query
= true;
2209 } else if (!strcmp(token
, "background-ping")) {
2210 p
->options
.background_ping
= true;
2211 } else if (!strcmp(token
, "no-digest")) {
2212 p
->options
.no_digest
= true;
2213 } else if (!strcmp(token
, "no-tproxy")) {
2214 p
->options
.no_tproxy
= true;
2215 } else if (!strcmp(token
, "multicast-responder")) {
2216 p
->options
.mcast_responder
= true;
2217 #if PEER_MULTICAST_SIBLINGS
2218 } else if (!strcmp(token
, "multicast-siblings")) {
2219 p
->options
.mcast_siblings
= true;
2221 } else if (!strncmp(token
, "weight=", 7)) {
2222 p
->weight
= xatoi(token
+ 7);
2223 } else if (!strncmp(token
, "basetime=", 9)) {
2224 p
->basetime
= xatoi(token
+ 9);
2225 } else if (!strcmp(token
, "closest-only")) {
2226 p
->options
.closest_only
= true;
2227 } else if (!strncmp(token
, "ttl=", 4)) {
2228 p
->mcast
.ttl
= xatoi(token
+ 4);
2230 if (p
->mcast
.ttl
< 0)
2233 if (p
->mcast
.ttl
> 128)
2235 } else if (!strcmp(token
, "default")) {
2236 p
->options
.default_parent
= true;
2237 } else if (!strcmp(token
, "round-robin")) {
2238 p
->options
.roundrobin
= true;
2239 } else if (!strcmp(token
, "weighted-round-robin")) {
2240 p
->options
.weighted_roundrobin
= true;
2242 } else if (!strcmp(token
, "htcp")) {
2243 p
->options
.htcp
= true;
2244 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2245 /* Note: The htcp- form is deprecated, replaced by htcp= */
2246 p
->options
.htcp
= true;
2247 char *tmp
= xstrdup(token
+5);
2248 char *mode
, *nextmode
;
2249 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2250 nextmode
= strchr(mode
, ',');
2255 if (!strcmp(mode
, "no-clr")) {
2256 if (p
->options
.htcp_only_clr
)
2257 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2258 p
->options
.htcp_no_clr
= true;
2259 } else if (!strcmp(mode
, "no-purge-clr")) {
2260 p
->options
.htcp_no_purge_clr
= true;
2261 } else if (!strcmp(mode
, "only-clr")) {
2262 if (p
->options
.htcp_no_clr
)
2263 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2264 p
->options
.htcp_only_clr
= true;
2265 } else if (!strcmp(mode
, "forward-clr")) {
2266 p
->options
.htcp_forward_clr
= true;
2267 } else if (!strcmp(mode
, "oldsquid")) {
2268 p
->options
.htcp_oldsquid
= true;
2270 fatalf("invalid HTCP mode '%s'", mode
);
2275 } else if (!strcmp(token
, "no-netdb-exchange")) {
2276 p
->options
.no_netdb_exchange
= true;
2278 } else if (!strcmp(token
, "carp")) {
2279 if (p
->type
!= PEER_PARENT
)
2280 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2282 p
->options
.carp
= true;
2283 } else if (!strncmp(token
, "carp-key=", 9)) {
2284 if (p
->options
.carp
!= true)
2285 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2286 p
->options
.carp_key
.set
= true;
2287 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2288 for (; key
; key
= nextkey
) {
2289 nextkey
=strchr(key
,',');
2290 if (nextkey
) ++nextkey
; // skip the comma, any
2291 if (0==strncmp(key
,"scheme",6)) {
2292 p
->options
.carp_key
.scheme
= true;
2293 } else if (0==strncmp(key
,"host",4)) {
2294 p
->options
.carp_key
.host
= true;
2295 } else if (0==strncmp(key
,"port",4)) {
2296 p
->options
.carp_key
.port
= true;
2297 } else if (0==strncmp(key
,"path",4)) {
2298 p
->options
.carp_key
.path
= true;
2299 } else if (0==strncmp(key
,"params",6)) {
2300 p
->options
.carp_key
.params
= true;
2302 fatalf("invalid carp-key '%s'",key
);
2305 } else if (!strcmp(token
, "userhash")) {
2307 if (p
->type
!= PEER_PARENT
)
2308 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2310 p
->options
.userhash
= true;
2312 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2314 } else if (!strcmp(token
, "sourcehash")) {
2315 if (p
->type
!= PEER_PARENT
)
2316 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2318 p
->options
.sourcehash
= true;
2320 } else if (!strcmp(token
, "no-delay")) {
2322 p
->options
.no_delay
= true;
2324 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2326 } else if (!strncmp(token
, "login=", 6)) {
2327 p
->login
= xstrdup(token
+ 6);
2328 rfc1738_unescape(p
->login
);
2329 } else if (!strcmp(token
, "auth-no-keytab")) {
2330 p
->options
.auth_no_keytab
= 1;
2331 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2332 p
->connect_timeout_raw
= xatoi(token
+ 16);
2333 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2334 p
->connect_fail_limit
= xatoi(token
+ 19);
2335 #if USE_CACHE_DIGESTS
2336 } else if (!strncmp(token
, "digest-url=", 11)) {
2337 p
->digest_url
= xstrdup(token
+ 11);
2340 } else if (!strcmp(token
, "allow-miss")) {
2341 p
->options
.allow_miss
= true;
2342 } else if (!strncmp(token
, "max-conn=", 9)) {
2343 p
->max_conn
= xatoi(token
+ 9);
2344 } else if (!strncmp(token
, "standby=", 8)) {
2345 p
->standby
.limit
= xatoi(token
+ 8);
2346 } else if (!strcmp(token
, "originserver")) {
2347 p
->options
.originserver
= true;
2348 } else if (!strncmp(token
, "name=", 5)) {
2352 p
->name
= xstrdup(token
+ 5);
2353 } else if (!strncmp(token
, "forceddomain=", 13)) {
2354 safe_free(p
->domain
);
2356 p
->domain
= xstrdup(token
+ 13);
2358 } else if (strncmp(token
, "ssl", 3) == 0) {
2360 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option '" << token
<< "' requires --with-openssl");
2362 p
->secure
.parse(token
+3);
2364 } else if (strncmp(token
, "tls-", 4) == 0) {
2365 p
->secure
.parse(token
+4);
2366 } else if (strncmp(token
, "tls", 3) == 0) {
2367 p
->secure
.parse(token
+3);
2368 } else if (strcmp(token
, "front-end-https") == 0) {
2369 p
->front_end_https
= 1;
2370 } else if (strcmp(token
, "front-end-https=on") == 0) {
2371 p
->front_end_https
= 1;
2372 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2373 p
->front_end_https
= 2;
2374 } else if (strcmp(token
, "connection-auth=off") == 0) {
2375 p
->connection_auth
= 0;
2376 } else if (strcmp(token
, "connection-auth") == 0) {
2377 p
->connection_auth
= 1;
2378 } else if (strcmp(token
, "connection-auth=on") == 0) {
2379 p
->connection_auth
= 1;
2380 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2381 p
->connection_auth
= 2;
2382 } else if (token
[0] == '#') {
2383 // start of a text comment. stop reading this line.
2386 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2390 if (peerFindByName(p
->name
))
2391 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2393 if (p
->max_conn
> 0 && p
->max_conn
< p
->standby
.limit
)
2394 fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p
->host
, p
->max_conn
, p
->standby
.limit
);
2399 if (p
->connect_fail_limit
< 1)
2400 p
->connect_fail_limit
= 10;
2402 #if USE_CACHE_DIGESTS
2403 if (!p
->options
.no_digest
)
2404 peerDigestCreate(p
);
2407 if (p
->secure
.encryptTransport
)
2408 p
->secure
.parseOptions();
2410 p
->index
= ++Config
.npeers
;
2412 while (*head
!= NULL
)
2413 head
= &(*head
)->next
;
2421 free_peer(CachePeer
** P
)
2429 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2432 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2433 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2435 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2437 for (auto w
: list
->actions
)
2438 entry
->appendf(" " SQUIDSBUFPH
, SQUIDSBUFPRINT(w
));
2440 storeAppendPrintf(entry
, "\n");
2446 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2448 char *passwd
= nullptr;
2449 parse_string(&passwd
);
2451 Mgr::ActionPasswordList
*p
= new Mgr::ActionPasswordList
;
2454 while (char *token
= ConfigParser::NextQuotedToken())
2455 p
->actions
.push_back(SBuf(token
));
2457 Mgr::ActionPasswordList
**P
;
2458 for (P
= head
; *P
; P
= &(*P
)->next
) {
2460 * See if any of the actions from this line already have a
2461 * password from previous lines. The password checking
2462 * routines in cache_manager.c take the the password from
2463 * the first Mgr::ActionPasswordList that contains the
2464 * requested action. Thus, we should warn users who might
2465 * think they can have two passwords for the same action.
2467 for (const auto &w
: (*P
)->actions
) {
2468 for (const auto &u
: p
->actions
) {
2472 debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u
<< "' (line " << config_lineno
<< ") already has a password");
2481 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2488 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2490 while (var
!= NULL
) {
2491 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2493 for (const auto &aclName
: var
->acl_list
)
2494 storeAppendPrintf(entry
, " " SQUIDSBUFPH
, SQUIDSBUFPRINT(aclName
));
2496 storeAppendPrintf(entry
, "\n");
2503 parse_denyinfo(AclDenyInfoList
** var
)
2505 aclParseDenyInfoLine(var
);
2509 free_denyinfo(AclDenyInfoList
** list
)
2516 parse_peer_access(void)
2518 char *host
= ConfigParser::NextToken();
2524 CachePeer
*p
= peerFindByName(host
);
2526 debugs(15, DBG_CRITICAL
, "ERROR: " << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2530 std::string directive
= "peer_access ";
2532 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
->access
);
2536 parse_hostdomaintype(void)
2538 char *host
= ConfigParser::NextToken();
2544 char *type
= ConfigParser::NextToken();
2550 char *domain
= nullptr;
2551 while ((domain
= ConfigParser::NextToken())) {
2552 CachePeer
*p
= peerFindByName(host
);
2554 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2558 auto *l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2559 l
->type
= parseNeighborType(type
);
2560 l
->domain
= xstrdup(domain
);
2562 NeighborTypeDomainList
**L
= nullptr;
2563 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2569 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2571 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2589 dump_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2591 storeAppendPrintf(entry
, "%s %" PRId64
"\n", name
, var
);
2595 parse_int64_t(int64_t *var
)
2603 free_int64_t(int64_t *var
)
2609 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2611 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2615 parse_onoff(int *var
)
2617 char *token
= ConfigParser::NextToken();
2623 if (!strcmp(token
, "on")) {
2625 } else if (!strcmp(token
, "enable")) {
2626 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2628 } else if (!strcmp(token
, "off")) {
2630 } else if (!strcmp(token
, "disable")) {
2631 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2634 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2639 #define free_onoff free_int
2642 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2653 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2657 parse_tristate(int *var
)
2659 char *token
= ConfigParser::NextToken();
2665 if (!strcmp(token
, "on")) {
2667 } else if (!strcmp(token
, "enable")) {
2668 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2670 } else if (!strcmp(token
, "warn")) {
2672 } else if (!strcmp(token
, "off")) {
2674 } else if (!strcmp(token
, "disable")) {
2675 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2678 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2683 #define free_tristate free_int
2686 parse_pipelinePrefetch(int *var
)
2688 char *token
= ConfigParser::PeekAtToken();
2694 if (!strcmp(token
, "on")) {
2695 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2698 (void)ConfigParser::NextToken();
2699 } else if (!strcmp(token
, "off")) {
2700 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2703 (void)ConfigParser::NextToken();
2708 #define free_pipelinePrefetch free_int
2709 #define dump_pipelinePrefetch dump_int
2712 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2714 while (head
!= NULL
) {
2715 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2717 head
->pattern
.flags
®_ICASE
? " -i" : null_string
,
2718 head
->pattern
.c_str(),
2719 (int) head
->min
/ 60,
2720 (int) (100.0 * head
->pct
+ 0.5),
2721 (int) head
->max
/ 60);
2723 if (head
->max_stale
>= 0)
2724 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2726 if (head
->flags
.refresh_ims
)
2727 storeAppendPrintf(entry
, " refresh-ims");
2729 if (head
->flags
.store_stale
)
2730 storeAppendPrintf(entry
, " store-stale");
2732 #if USE_HTTP_VIOLATIONS
2734 if (head
->flags
.override_expire
)
2735 storeAppendPrintf(entry
, " override-expire");
2737 if (head
->flags
.override_lastmod
)
2738 storeAppendPrintf(entry
, " override-lastmod");
2740 if (head
->flags
.reload_into_ims
)
2741 storeAppendPrintf(entry
, " reload-into-ims");
2743 if (head
->flags
.ignore_reload
)
2744 storeAppendPrintf(entry
, " ignore-reload");
2746 if (head
->flags
.ignore_no_store
)
2747 storeAppendPrintf(entry
, " ignore-no-store");
2749 if (head
->flags
.ignore_private
)
2750 storeAppendPrintf(entry
, " ignore-private");
2753 storeAppendPrintf(entry
, "\n");
2760 parse_refreshpattern(RefreshPattern
** head
)
2767 int refresh_ims
= 0;
2768 int store_stale
= 0;
2771 #if USE_HTTP_VIOLATIONS
2773 int override_expire
= 0;
2774 int override_lastmod
= 0;
2775 int reload_into_ims
= 0;
2776 int ignore_reload
= 0;
2777 int ignore_no_store
= 0;
2778 int ignore_private
= 0;
2785 int flags
= REG_EXTENDED
| REG_NOSUB
;
2787 if ((token
= ConfigParser::RegexPattern()) != NULL
) {
2789 if (strcmp(token
, "-i") == 0) {
2791 token
= ConfigParser::RegexPattern();
2792 } else if (strcmp(token
, "+i") == 0) {
2793 flags
&= ~REG_ICASE
;
2794 token
= ConfigParser::RegexPattern();
2799 if (token
== NULL
) {
2800 debugs(3, DBG_CRITICAL
, "FATAL: refresh_pattern missing the regex pattern parameter");
2805 pattern
= xstrdup(token
);
2807 i
= GetInteger(); /* token: min */
2809 /* catch negative and insanely huge values close to 32-bit wrap */
2811 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2814 if (i
> 60*24*365) {
2815 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2819 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2821 pct
= GetPercentage(false); /* token: pct . with no limit on size */
2823 i
= GetInteger(); /* token: max */
2825 /* catch negative and insanely huge values close to 32-bit wrap */
2827 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2830 if (i
> 60*24*365) {
2831 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2835 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2838 while ((token
= ConfigParser::NextToken()) != NULL
) {
2839 if (!strcmp(token
, "refresh-ims")) {
2841 } else if (!strcmp(token
, "store-stale")) {
2843 } else if (!strncmp(token
, "max-stale=", 10)) {
2844 max_stale
= xatoi(token
+ 10);
2846 #if USE_HTTP_VIOLATIONS
2848 } else if (!strcmp(token
, "override-expire"))
2849 override_expire
= 1;
2850 else if (!strcmp(token
, "override-lastmod"))
2851 override_lastmod
= 1;
2852 else if (!strcmp(token
, "ignore-no-store"))
2853 ignore_no_store
= 1;
2854 else if (!strcmp(token
, "ignore-private"))
2856 else if (!strcmp(token
, "reload-into-ims")) {
2857 reload_into_ims
= 1;
2858 refresh_nocache_hack
= 1;
2859 /* tell client_side.c that this is used */
2860 } else if (!strcmp(token
, "ignore-reload")) {
2862 refresh_nocache_hack
= 1;
2863 /* tell client_side.c that this is used */
2866 } else if (!strcmp(token
, "ignore-no-cache") ||
2867 !strcmp(token
, "ignore-must-revalidate") ||
2868 !strcmp(token
, "ignore-auth")
2870 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token
<< "' is obsolete. Remove it.");
2872 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2875 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2877 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2878 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2879 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2884 pct
= pct
< 0.0 ? 0.0 : pct
;
2885 max
= max
< 0 ? 0 : max
;
2886 t
= new RefreshPattern(pattern
, flags
);
2887 t
->pattern
.regex
= comp
;
2893 t
->flags
.refresh_ims
= true;
2896 t
->flags
.store_stale
= true;
2898 t
->max_stale
= max_stale
;
2900 #if USE_HTTP_VIOLATIONS
2902 if (override_expire
)
2903 t
->flags
.override_expire
= true;
2905 if (override_lastmod
)
2906 t
->flags
.override_lastmod
= true;
2908 if (reload_into_ims
)
2909 t
->flags
.reload_into_ims
= true;
2912 t
->flags
.ignore_reload
= true;
2914 if (ignore_no_store
)
2915 t
->flags
.ignore_no_store
= true;
2918 t
->flags
.ignore_private
= true;
2924 head
= &(*head
)->next
;
2932 free_refreshpattern(RefreshPattern
** head
)
2937 #if USE_HTTP_VIOLATIONS
2938 refresh_nocache_hack
= 0;
2944 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2947 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2951 parse_string(char **var
)
2955 char *token
= ConfigParser::NextToken();
2961 *var
= xstrdup(token
);
2965 free_string(char **var
)
2971 parse_eol(char *volatile *var
)
2978 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
2986 while (*token
&& xisspace(*token
))
2994 *var
= xstrdup((char *) token
);
2997 #define dump_eol dump_string
2998 #define free_eol free_string
3001 parse_TokenOrQuotedString(char **var
)
3005 char *token
= ConfigParser::NextQuotedToken();
3011 *var
= xstrdup(token
);
3014 #define dump_TokenOrQuotedString dump_string
3015 #define free_TokenOrQuotedString free_string
3018 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3020 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3024 parse_time_t(time_t * var
)
3026 const auto maxTime
= std::numeric_limits
<time_t>::max();
3027 const auto seconds
= parseTimeLine
<std::chrono::seconds
>();
3028 if (maxTime
< seconds
.count())
3029 throw TexcHere(ToSBuf("directive supports time values up to ", maxTime
, " but is given ", seconds
.count(), " seconds"));
3030 *var
= static_cast<time_t>(seconds
.count());
3034 free_time_t(time_t * var
)
3040 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3043 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3045 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3049 parse_time_msec(time_msec_t
*var
)
3051 *var
= parseTimeLine
<std::chrono::milliseconds
>().count();
3055 free_time_msec(time_msec_t
* var
)
3061 dump_time_nanoseconds(StoreEntry
*entry
, const char *name
, const std::chrono::nanoseconds
&var
)
3063 // std::chrono::nanoseconds::rep is unknown a priori so we cast to (and print) the largest supported integer
3064 storeAppendPrintf(entry
, "%s %jd nanoseconds\n", name
, static_cast<intmax_t>(var
.count()));
3068 parse_time_nanoseconds(std::chrono::nanoseconds
*var
)
3070 *var
= parseTimeLine
<std::chrono::nanoseconds
>();
3074 free_time_nanoseconds(std::chrono::nanoseconds
*var
)
3076 *var
= std::chrono::nanoseconds::zero();
3080 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3082 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3086 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3088 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3092 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3094 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3098 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3100 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3104 parse_b_size_t(size_t * var
)
3106 parseBytesLine(var
, B_BYTES_STR
);
3110 parse_b_ssize_t(ssize_t
* var
)
3112 parseBytesLineSigned(var
, B_BYTES_STR
);
3116 parse_b_int64_t(int64_t * var
)
3118 parseBytesLine64(var
, B_BYTES_STR
);
3122 parse_kb_int64_t(int64_t * var
)
3124 parseBytesLine64(var
, B_KBYTES_STR
);
3128 free_size_t(size_t * var
)
3134 free_ssize_t(ssize_t
* var
)
3140 free_b_int64_t(int64_t * var
)
3145 #define free_b_size_t free_size_t
3146 #define free_b_ssize_t free_ssize_t
3147 #define free_kb_size_t free_size_t
3148 #define free_mb_size_t free_size_t
3149 #define free_gb_size_t free_size_t
3150 #define free_kb_int64_t free_b_int64_t
3153 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3155 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3159 free_u_short(unsigned short * u
)
3165 parse_u_short(unsigned short * var
)
3167 ConfigParser::ParseUShort(var
);
3171 ConfigParser::ParseUShort(unsigned short *var
)
3177 ConfigParser::ParseBool(bool *var
)
3179 int i
= GetInteger();
3190 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3192 while (list
!= NULL
) {
3193 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3199 ConfigParser::ParseWordList(wordlist
** list
)
3201 parse_wordlist(list
);
3205 parse_wordlist(wordlist
** list
)
3208 while ((token
= ConfigParser::NextQuotedToken()))
3209 wordlistAdd(list
, token
);
3213 check_null_acl_access(acl_access
* a
)
3218 #define free_wordlist wordlistDestroy
3220 #define free_uri_whitespace free_int
3223 parse_uri_whitespace(int *var
)
3225 char *token
= ConfigParser::NextToken();
3231 if (!strcmp(token
, "strip"))
3232 *var
= URI_WHITESPACE_STRIP
;
3233 else if (!strcmp(token
, "deny"))
3234 *var
= URI_WHITESPACE_DENY
;
3235 else if (!strcmp(token
, "allow"))
3236 *var
= URI_WHITESPACE_ALLOW
;
3237 else if (!strcmp(token
, "encode"))
3238 *var
= URI_WHITESPACE_ENCODE
;
3239 else if (!strcmp(token
, "chop"))
3240 *var
= URI_WHITESPACE_CHOP
;
3242 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3248 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3252 if (var
== URI_WHITESPACE_ALLOW
)
3254 else if (var
== URI_WHITESPACE_ENCODE
)
3256 else if (var
== URI_WHITESPACE_CHOP
)
3258 else if (var
== URI_WHITESPACE_DENY
)
3263 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3267 free_removalpolicy(RemovalPolicySettings
** settings
)
3272 free_string(&(*settings
)->type
);
3274 free_wordlist(&(*settings
)->args
);
3282 parse_removalpolicy(RemovalPolicySettings
** settings
)
3285 free_removalpolicy(settings
);
3287 *settings
= new RemovalPolicySettings
;
3289 parse_string(&(*settings
)->type
);
3291 parse_wordlist(&(*settings
)->args
);
3295 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3298 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3299 args
= settings
->args
;
3302 storeAppendPrintf(entry
, " %s", args
->key
);
3306 storeAppendPrintf(entry
, "\n");
3310 free_YesNoNone(YesNoNone
*)
3314 parse_YesNoNone(YesNoNone
*option
)
3317 parse_onoff(&value
);
3318 option
->configure(value
> 0);
3322 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3324 if (option
.configured())
3325 dump_onoff(entry
, name
, option
? 1 : 0);
3329 free_memcachemode(SquidConfig
*)
3333 parse_memcachemode(SquidConfig
*)
3335 char *token
= ConfigParser::NextToken();
3341 if (strcmp(token
, "always") == 0) {
3342 Config
.onoff
.memory_cache_first
= 1;
3343 Config
.onoff
.memory_cache_disk
= 1;
3344 } else if (strcmp(token
, "disk") == 0) {
3345 Config
.onoff
.memory_cache_first
= 0;
3346 Config
.onoff
.memory_cache_disk
= 1;
3347 } else if (strncmp(token
, "net", 3) == 0) {
3348 Config
.onoff
.memory_cache_first
= 1;
3349 Config
.onoff
.memory_cache_disk
= 0;
3350 } else if (strcmp(token
, "never") == 0) {
3351 Config
.onoff
.memory_cache_first
= 0;
3352 Config
.onoff
.memory_cache_disk
= 0;
3354 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3360 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&)
3362 storeAppendPrintf(entry
, "%s ", name
);
3363 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3364 storeAppendPrintf(entry
, "always");
3365 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3366 storeAppendPrintf(entry
, "disk");
3367 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3368 storeAppendPrintf(entry
, "network");
3369 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3370 storeAppendPrintf(entry
, "none");
3371 storeAppendPrintf(entry
, "\n");
3374 #include "cf_parser.cci"
3377 parseNeighborType(const char *s
)
3379 if (!strcmp(s
, "parent"))
3382 if (!strcmp(s
, "neighbor"))
3383 return PEER_SIBLING
;
3385 if (!strcmp(s
, "neighbour"))
3386 return PEER_SIBLING
;
3388 if (!strcmp(s
, "sibling"))
3389 return PEER_SIBLING
;
3391 if (!strcmp(s
, "multicast"))
3392 return PEER_MULTICAST
;
3394 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3396 return PEER_SIBLING
;
3401 parse_IpAddress_list(Ip::Address_list
** head
)
3404 Ip::Address_list
*s
;
3407 while ((token
= ConfigParser::NextToken())) {
3408 if (GetHostWithPort(token
, &ipa
)) {
3411 head
= &(*head
)->next
;
3413 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3425 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3427 char ntoabuf
[MAX_IPSTRLEN
];
3430 storeAppendPrintf(e
, "%s %s\n",
3432 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3438 free_IpAddress_list(Ip::Address_list
** head
)
3440 if (*head
) delete *head
;
3444 #if CURRENTLY_UNUSED
3445 /* This code was previously used by http_port. Left as it really should
3446 * be used by icp_port and htcp_port
3449 check_null_IpAddress_list(const Ip::Address_list
* s
)
3454 #endif /* CURRENTLY_UNUSED */
3455 #endif /* USE_WCCPv2 */
3458 parsePortSpecification(const AnyP::PortCfgPointer
&s
, char *token
)
3461 unsigned short port
= 0;
3465 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3466 s
->name
= xstrdup(token
);
3467 s
->connection_auth_disabled
= false;
3469 const SBuf
&portType
= AnyP::UriScheme(s
->transport
.protocol
).image();
3471 if (*token
== '[') {
3474 t
= strchr(host
, ']');
3476 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3483 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3487 if (!Ip::EnableIpv6
) {
3488 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3492 port
= xatos(t
+ 1);
3493 } else if ((t
= strchr(token
, ':'))) {
3498 port
= xatos(t
+ 1);
3500 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3501 port
= xatos(token
);
3502 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3504 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3509 if (port
== 0 && host
!= NULL
) {
3510 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3518 if (!Ip::EnableIpv6
)
3520 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3521 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3523 if (!Ip::EnableIpv6
)
3525 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3526 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3527 /* do not use ipcache */
3528 s
->defaultsite
= xstrdup(host
);
3530 if (!Ip::EnableIpv6
)
3532 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3534 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3539 /// parses the protocol= option of the *_port directive, returning parsed value
3540 /// unsupported option values result in a fatal error message
3541 /// upper case values required; caller may convert for backward compatibility
3542 static AnyP::ProtocolVersion
3543 parsePortProtocol(const SBuf
&value
)
3545 // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3546 // and RFC 2616 requires us to upgrade 1.0 to 1.1
3547 if (value
.cmp("HTTP") == 0 || value
.cmp("HTTP/1.1") == 0)
3548 return Http::ProtocolVersion(1,1);
3550 if (value
.cmp("HTTPS") == 0 || value
.cmp("HTTPS/1.1") == 0)
3551 return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS
, 1,1);
3553 if (value
.cmp("FTP") == 0)
3554 return Ftp::ProtocolVersion();
3556 fatalf("%s directive does not support protocol=" SQUIDSBUFPH
"\n", cfg_directive
, SQUIDSBUFPRINT(value
));
3557 return AnyP::ProtocolVersion(); // not reached
3561 parse_port_option(AnyP::PortCfgPointer
&s
, char *token
)
3565 if (strcmp(token
, "accel") == 0) {
3566 if (s
->flags
.isIntercepted()) {
3567 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3571 s
->flags
.accelSurrogate
= true;
3573 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3574 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3575 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3579 s
->flags
.natIntercept
= true;
3580 Ip::Interceptor
.StartInterception();
3581 /* Log information regarding the port modes under interception. */
3582 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3583 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3584 } else if (strcmp(token
, "tproxy") == 0) {
3585 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3586 debugs(3,DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3590 s
->flags
.tproxyIntercept
= true;
3591 Ip::Interceptor
.StartTransparency();
3592 /* Log information regarding the port modes under transparency. */
3593 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3595 if (s
->flags
.proxySurrogate
) {
3596 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3599 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3600 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY support in the system does not work.");
3605 } else if (strcmp(token
, "require-proxy-header") == 0) {
3606 s
->flags
.proxySurrogate
= true;
3607 if (s
->flags
.tproxyIntercept
) {
3608 // receiving is still permitted, so we do not unset the TPROXY flag
3609 // spoofing access control override takes care of the spoof disable later
3610 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3613 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3614 if (!s
->flags
.accelSurrogate
) {
3615 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": defaultsite option requires Acceleration mode flag.");
3619 safe_free(s
->defaultsite
);
3620 s
->defaultsite
= xstrdup(token
+ 12);
3621 } else if (strcmp(token
, "vhost") == 0) {
3622 if (!s
->flags
.accelSurrogate
) {
3623 debugs(3, DBG_CRITICAL
, "WARNING: " << cfg_directive
<< ": vhost option is deprecated. Use 'accel' mode flag instead.");
3625 s
->flags
.accelSurrogate
= true;
3627 } else if (strcmp(token
, "no-vhost") == 0) {
3628 if (!s
->flags
.accelSurrogate
) {
3629 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": no-vhost option requires Acceleration mode flag.");
3632 } else if (strcmp(token
, "vport") == 0) {
3633 if (!s
->flags
.accelSurrogate
) {
3634 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3639 } else if (strncmp(token
, "vport=", 6) == 0) {
3640 if (!s
->flags
.accelSurrogate
) {
3641 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3645 s
->vport
= xatos(token
+ 6);
3646 } else if (strncmp(token
, "protocol=", 9) == 0) {
3647 if (!s
->flags
.accelSurrogate
) {
3648 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": protocol option requires Acceleration mode flag.");
3652 s
->transport
= parsePortProtocol(ToUpper(SBuf(token
+ 9)));
3653 } else if (strcmp(token
, "allow-direct") == 0) {
3654 if (!s
->flags
.accelSurrogate
) {
3655 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": allow-direct option requires Acceleration mode flag.");
3659 s
->allow_direct
= true;
3660 } else if (strcmp(token
, "act-as-origin") == 0) {
3661 if (!s
->flags
.accelSurrogate
) {
3662 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": act-as-origin option requires Acceleration mode flag.");
3664 s
->actAsOrigin
= true;
3665 } else if (strcmp(token
, "ignore-cc") == 0) {
3666 #if !USE_HTTP_VIOLATIONS
3667 if (!s
->flags
.accelSurrogate
) {
3668 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": ignore-cc option requires Acceleration mode flag.");
3673 s
->ignore_cc
= true;
3674 } else if (strncmp(token
, "name=", 5) == 0) {
3676 s
->name
= xstrdup(token
+ 5);
3677 } else if (strcmp(token
, "no-connection-auth") == 0) {
3678 s
->connection_auth_disabled
= true;
3679 } else if (strcmp(token
, "connection-auth=off") == 0) {
3680 s
->connection_auth_disabled
= true;
3681 } else if (strcmp(token
, "connection-auth") == 0) {
3682 s
->connection_auth_disabled
= false;
3683 } else if (strcmp(token
, "connection-auth=on") == 0) {
3684 s
->connection_auth_disabled
= false;
3685 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3686 if (!strcmp(token
+ 23, "off"))
3687 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3688 else if (!strcmp(token
+ 23, "transparent"))
3689 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3690 else if (!strcmp(token
+ 23, "always"))
3691 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3696 } else if (strcmp(token
, "ipv4") == 0) {
3697 if ( !s
->s
.setIPv4() ) {
3698 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3702 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3703 s
->tcp_keepalive
.enabled
= true;
3704 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3705 char *t
= token
+ 13;
3706 s
->tcp_keepalive
.enabled
= true;
3707 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3711 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3716 s
->tcp_keepalive
.timeout
= xatoui(t
);
3719 } else if (strcmp(token
, "sslBump") == 0) {
3720 debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token
<< "' is deprecated " <<
3721 "in " << cfg_directive
<< ". Use 'ssl-bump' instead.");
3722 s
->flags
.tunnelSslBumping
= true;
3723 } else if (strcmp(token
, "ssl-bump") == 0) {
3724 s
->flags
.tunnelSslBumping
= true;
3725 } else if (strncmp(token
, "cert=", 5) == 0) {
3726 s
->secure
.parse(token
);
3727 } else if (strncmp(token
, "key=", 4) == 0) {
3728 s
->secure
.parse(token
);
3729 } else if (strncmp(token
, "version=", 8) == 0) {
3730 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3731 "in " << cfg_directive
<< ". Use 'options=' instead.");
3732 s
->secure
.parse(token
);
3733 } else if (strncmp(token
, "options=", 8) == 0) {
3734 s
->secure
.parse(token
);
3735 } else if (strncmp(token
, "cipher=", 7) == 0) {
3736 s
->secure
.parse(token
);
3737 } else if (strncmp(token
, "clientca=", 9) == 0) {
3738 s
->secure
.parse(token
);
3739 } else if (strncmp(token
, "cafile=", 7) == 0) {
3740 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3741 "in " << cfg_directive
<< ". Use 'tls-cafile=' instead.");
3742 s
->secure
.parse(token
);
3743 } else if (strncmp(token
, "capath=", 7) == 0) {
3744 s
->secure
.parse(token
);
3745 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3746 s
->secure
.parse(token
);
3747 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3748 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: '" << token
<< "' is deprecated " <<
3749 "in " << cfg_directive
<< ". Use 'tls-dh=' instead.");
3750 s
->secure
.parse(token
);
3751 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3752 // NP: deprecation warnings output by secure.parse() when relevant
3753 s
->secure
.parse(token
+3);
3754 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3755 // NP: deprecation warnings output by secure.parse() when relevant
3756 s
->secure
.parse(token
+3);
3757 } else if (strncmp(token
, "generate-host-certificates", 26) == 0) {
3758 s
->secure
.parse(token
);
3760 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3761 s
->secure
.parse(token
);
3762 } else if (strncmp(token
, "tls-", 4) == 0) {
3763 s
->secure
.parse(token
+4);
3764 } else if (strcmp(token
, "ftp-track-dirs") == 0) {
3765 s
->ftp_track_dirs
= true;
3766 } else if (strcmp(token
, "worker-queues") == 0) {
3767 #if !defined(SO_REUSEADDR)
3768 #error missing system #include that #defines SO_* constants
3770 #if !defined(SO_REUSEPORT)
3771 throw TexcHere(ToSBuf(cfg_directive
, ' ', token
, " option requires building Squid where SO_REUSEPORT is supported by the TCP stack"));
3773 s
->workerQueues
= true;
3775 debugs(3, DBG_CRITICAL
, "FATAL: Unknown " << cfg_directive
<< " option '" << token
<< "'.");
3781 add_http_port(char *portspec
)
3783 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3784 s
->transport
= parsePortProtocol(SBuf("HTTP"));
3785 parsePortSpecification(s
, portspec
);
3786 // we may need to merge better if the above returns a list with clones
3787 assert(s
->next
== NULL
);
3788 s
->next
= HttpPortList
;
3793 parsePortCfg(AnyP::PortCfgPointer
*head
, const char *optionName
)
3796 if (strcmp(optionName
, "http_port") == 0 ||
3797 strcmp(optionName
, "ascii_port") == 0)
3799 else if (strcmp(optionName
, "https_port") == 0)
3800 protoName
= "HTTPS";
3801 else if (strcmp(optionName
, "ftp_port") == 0)
3803 if (protoName
.isEmpty()) {
3808 char *token
= ConfigParser::NextToken();
3815 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3816 s
->transport
= parsePortProtocol(protoName
); // default; protocol=... overwrites
3817 parsePortSpecification(s
, token
);
3819 /* parse options ... */
3820 while ((token
= ConfigParser::NextToken())) {
3821 parse_port_option(s
, token
);
3824 s
->secure
.syncCaFiles();
3826 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3827 s
->secure
.encryptTransport
= true;
3829 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3830 const bool hijacked
= s
->flags
.isIntercepted();
3831 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3832 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3836 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3837 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3842 if (s
->flags
.proxySurrogate
) {
3843 debugs(3,DBG_CRITICAL
, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3847 } else if (protoName
.cmp("FTP") == 0) {
3848 /* ftp_port does not support ssl-bump */
3849 if (s
->flags
.tunnelSslBumping
) {
3850 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump is not supported for ftp_port.");
3854 if (s
->flags
.proxySurrogate
) {
3855 // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3856 debugs(3,DBG_CRITICAL
, "FATAL: require-proxy-header option is not supported on ftp_port.");
3862 if (s
->secure
.encryptTransport
) {
3863 if (s
->secure
.certs
.empty()) {
3864 debugs(3, DBG_CRITICAL
, "FATAL: " << AnyP::UriScheme(s
->transport
.protocol
) << "_port requires a cert= parameter");
3868 s
->secure
.parseOptions();
3871 // *_port line should now be fully valid so we can clone it if necessary
3872 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3873 // clone the port options from *s to *(s->next)
3874 s
->next
= s
->clone();
3875 s
->next
->s
.setIPv4();
3876 debugs(3, 3, AnyP::UriScheme(s
->transport
.protocol
).image() << "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3879 while (*head
!= NULL
)
3880 head
= &((*head
)->next
);
3886 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3888 char buf
[MAX_IPSTRLEN
];
3890 storeAppendPrintf(e
, "%s %s",
3892 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3894 // MODES and specific sub-options.
3895 if (s
->flags
.natIntercept
)
3896 storeAppendPrintf(e
, " intercept");
3898 else if (s
->flags
.tproxyIntercept
)
3899 storeAppendPrintf(e
, " tproxy");
3901 else if (s
->flags
.proxySurrogate
)
3902 storeAppendPrintf(e
, " require-proxy-header");
3904 else if (s
->flags
.accelSurrogate
) {
3905 storeAppendPrintf(e
, " accel");
3908 storeAppendPrintf(e
, " vhost");
3911 storeAppendPrintf(e
, " vport");
3912 else if (s
->vport
> 0)
3913 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3916 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3918 // TODO: compare against prefix of 'n' instead of assuming http_port
3919 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3920 storeAppendPrintf(e
, " protocol=%s", AnyP::ProtocolType_str
[s
->transport
.protocol
]);
3922 if (s
->allow_direct
)
3923 storeAppendPrintf(e
, " allow-direct");
3926 storeAppendPrintf(e
, " ignore-cc");
3930 // Generic independent options
3933 storeAppendPrintf(e
, " name=%s", s
->name
);
3935 #if USE_HTTP_VIOLATIONS
3936 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3937 storeAppendPrintf(e
, " ignore-cc");
3940 if (s
->connection_auth_disabled
)
3941 storeAppendPrintf(e
, " connection-auth=off");
3943 storeAppendPrintf(e
, " connection-auth=on");
3945 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3948 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3951 pmtu
= "transparent";
3953 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3956 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3957 storeAppendPrintf(e
, " ipv4");
3959 if (s
->tcp_keepalive
.enabled
) {
3960 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3961 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3963 storeAppendPrintf(e
, " tcpkeepalive");
3968 if (s
->flags
.tunnelSslBumping
)
3969 storeAppendPrintf(e
, " ssl-bump");
3972 s
->secure
.dumpCfg(e
, "tls-");
3976 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3978 for (AnyP::PortCfgPointer p
= s
; p
!= NULL
; p
= p
->next
) {
3979 dump_generic_port(e
, n
, p
);
3980 storeAppendPrintf(e
, "\n");
3985 configFreeMemory(void)
3988 Config
.ssl_client
.sslContext
.reset();
3990 Ssl::unloadSquidUntrusted();
3995 requirePathnameExists(const char *name
, const char *path
)
3999 char pathbuf
[BUFSIZ
];
4000 assert(path
!= NULL
);
4002 if (Config
.chroot_dir
&& (geteuid() == 0)) {
4003 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4007 if (stat(path
, &sb
) < 0) {
4009 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL: ":"ERROR: ") << name
<< " " << path
<< ": " << xstrerr(xerrno
));
4010 // keep going to find more issues if we are only checking the config file with "-k parse"
4011 if (opt_parse_cfg_only
)
4013 // this is fatal if it is found during startup or reconfigure
4014 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4015 fatalf("%s %s: %s", name
, path
, xstrerr(xerrno
));
4019 #include "AccessLogEntry.h"
4022 * We support several access_log configuration styles:
4024 * #1: Deprecated ancient style without an explicit logging module:
4025 * access_log /var/log/access.log
4027 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
4028 * access_log none [acl ...]
4030 * #3: Configurable logging module without named options:
4031 * Logformat or the first ACL name, whichever comes first, may not contain '='.
4032 * If no explicit logformat name is given, the first ACL name, if any,
4033 * should not be an existing logformat name or it will be treated as such.
4034 * access_log module:place [logformat_name] [acl ...]
4036 * #4: Configurable logging module with name=value options such as logformat=x:
4037 * The first ACL name may not contain '='.
4038 * Without any optional parts, directives using this style are indistinguishable
4039 * from directives using style #1 until we start requiring the "module:" prefix.
4040 * access_log module:place [option ...] [acl ...]
4044 parse_access_log(CustomLog
** logs
)
4046 const char *filename
= ConfigParser::NextToken();
4052 const auto cl
= new CustomLog();
4054 cl
->filename
= xstrdup(filename
);
4056 if (strcmp(filename
, "none") == 0) {
4057 cl
->type
= Log::Format::CLF_NONE
;
4058 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
4060 logs
= &(*logs
)->next
;
4065 const char *token
= ConfigParser::PeekAtToken();
4066 if (token
&& !strchr(token
, '=')) { // style #3
4067 // TODO: Deprecate this style to avoid this dangerous guessing.
4068 if (Log::TheConfig
.knownFormat(token
)) {
4069 cl
->setLogformat(token
);
4070 (void)ConfigParser::NextToken(); // consume the token used above
4072 // assume there is no explicit logformat name and use the default
4073 cl
->setLogformat("squid");
4075 } else { // style #1 or style #4
4076 // TODO: Drop deprecated style #1 support. We already warn about it, and
4077 // its exceptional treatment makes detecting "module" typos impractical!
4078 cl
->parseOptions(LegacyParser
, "squid");
4080 assert(cl
->type
); // setLogformat() was called
4082 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4085 logs
= &(*logs
)->next
;
4091 check_null_access_log(CustomLog
*customlog_definitions
)
4093 return customlog_definitions
== NULL
;
4097 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4100 for (auto log
= logs
; log
; log
= log
->next
) {
4102 PackableStream
os(*entry
);
4103 os
<< name
; // directive name
4104 os
<< ' ' << log
->filename
; // including "none"
4105 log
->dumpOptions(os
);
4109 dump_acl_list(entry
, log
->aclList
);
4111 storeAppendPrintf(entry
, "\n");
4116 free_access_log(CustomLog
** definitions
)
4118 while (*definitions
) {
4119 CustomLog
*log
= *definitions
;
4120 *definitions
= log
->next
;
4125 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4126 /// parses list of integers form name=N1,N2,N3,...
4128 parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
)
4130 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4131 data
+= name
.size();
4136 if (!StringToInt(data
, value
, &data
, 10))
4138 list
.push_back(value
);
4139 if (*data
== '\0' || *data
!= ',')
4144 return data
&& *data
== '\0';
4149 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4151 #if !HAVE_CPU_AFFINITY
4152 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4153 "support, do not set 'cpu_affinity_map'");
4156 #else /* HAVE_CPU_AFFINITY */
4157 if (!*cpuAffinityMap
)
4158 *cpuAffinityMap
= new CpuAffinityMap
;
4160 const char *const pToken
= ConfigParser::NextToken();
4161 const char *const cToken
= ConfigParser::NextToken();
4162 std::vector
<int> processes
, cores
;
4163 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4164 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4165 "in 'cpu_affinity_map'");
4167 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4168 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4169 "'cpu_affinity_map'");
4171 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4172 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4173 "process_numbers and cores lists differ in length or " <<
4174 "contain numbers <= 0");
4181 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4183 if (cpuAffinityMap
) {
4184 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4185 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4186 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4187 cpuAffinityMap
->processes()[i
]);
4189 storeAppendPrintf(entry
, " cores=");
4190 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4191 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4192 cpuAffinityMap
->cores()[i
]);
4194 storeAppendPrintf(entry
, "\n");
4199 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4201 delete *cpuAffinityMap
;
4202 *cpuAffinityMap
= NULL
;
4208 parse_adaptation_service_set_type()
4210 Adaptation::Config::ParseServiceSet();
4214 parse_adaptation_service_chain_type()
4216 Adaptation::Config::ParseServiceChain();
4220 parse_adaptation_access_type()
4222 Adaptation::Config::ParseAccess(LegacyParser
);
4224 #endif /* USE_ADAPTATION */
4229 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4231 cfg
->parseService();
4235 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4241 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4243 cfg
.dumpService(entry
, name
);
4247 parse_icap_class_type()
4249 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is deprecated. " <<
4250 "Use 'adaptation_service_set' instead");
4251 Adaptation::Config::ParseServiceSet();
4255 parse_icap_access_type()
4257 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is deprecated. " <<
4258 "Use 'adaptation_access' instead");
4259 Adaptation::Config::ParseAccess(LegacyParser
);
4267 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4269 cfg
->parseService();
4273 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4279 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4281 cfg
.dumpService(entry
, name
);
4284 #endif /* USE_ECAP */
4287 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4290 cfg
->service_failure_limit
= GetInteger();
4292 if ((token
= ConfigParser::NextToken()) == NULL
)
4295 if (strcmp(token
,"in") != 0) {
4296 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4301 parse_time_t(&cfg
->oldest_service_failure
);
4304 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4306 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4307 if (cfg
.oldest_service_failure
> 0) {
4308 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4310 storeAppendPrintf(entry
, "\n");
4313 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4315 cfg
->oldest_service_failure
= 0;
4316 cfg
->service_failure_limit
= 0;
4321 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4324 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4325 if ((al
= ConfigParser::NextToken()) == NULL
) {
4332 if ( char *s
= strchr(al
, '{')) {
4333 *s
= '\0'; // terminate the al string
4346 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4347 ca
->alg
= Ssl::algSetValidAfter
;
4348 ca
->param
= xstrdup("on");
4349 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4350 ca
->alg
= Ssl::algSetValidBefore
;
4351 ca
->param
= xstrdup("on");
4352 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4353 ca
->alg
= Ssl::algSetCommonName
;
4355 if (strlen(param
) > 64) {
4356 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4361 ca
->param
= xstrdup(param
);
4364 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4370 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4373 cert_adapt
= &(*cert_adapt
)->next
;
4378 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4380 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4381 storeAppendPrintf(entry
, "%s ", name
);
4382 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4384 dump_acl_list(entry
, ca
->aclList
);
4385 storeAppendPrintf(entry
, "\n");
4389 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4391 while (*cert_adapt
) {
4392 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4393 *cert_adapt
= ca
->next
;
4394 safe_free(ca
->param
);
4397 aclDestroyAclList(&ca
->aclList
);
4403 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4406 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4407 if ((al
= ConfigParser::NextToken()) == NULL
) {
4413 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4414 cs
->alg
= Ssl::algSignTrusted
;
4415 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4416 cs
->alg
= Ssl::algSignUntrusted
;
4417 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4418 cs
->alg
= Ssl::algSignSelf
;
4420 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4426 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4429 cert_sign
= &(*cert_sign
)->next
;
4434 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4436 sslproxy_cert_sign
*cs
;
4437 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4438 storeAppendPrintf(entry
, "%s ", name
);
4439 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4441 dump_acl_list(entry
, cs
->aclList
);
4442 storeAppendPrintf(entry
, "\n");
4446 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4448 while (*cert_sign
) {
4449 sslproxy_cert_sign
*cs
= *cert_sign
;
4450 *cert_sign
= cs
->next
;
4453 aclDestroyAclList(&cs
->aclList
);
4459 class sslBumpCfgRr
: public ::RegisteredRunner
4462 static Ssl::BumpMode lastDeprecatedRule
;
4463 /* RegisteredRunner API */
4464 virtual void finalizeConfig();
4467 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4469 RunnerRegistrationEntry(sslBumpCfgRr
);
4472 sslBumpCfgRr::finalizeConfig()
4474 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4475 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4476 static char buf
[1024];
4477 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4478 strcpy(buf
, "ssl_bump deny all");
4479 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4480 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4481 "must not use implicit rules. Update your ssl_bump rules.");
4483 strcpy(buf
, "ssl_bump allow all");
4484 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4485 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4486 "inferior to the newer server-first bumping mode. New ssl_bump"
4487 " configurations must not use implicit rules. Update your ssl_bump rules.");
4493 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4495 typedef const char *BumpCfgStyle
;
4496 BumpCfgStyle bcsNone
= NULL
;
4497 BumpCfgStyle bcsNew
= "new client/server-first/none";
4498 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4499 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4500 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4502 if ((bm
= ConfigParser::NextToken()) == NULL
) {
4507 // if this is the first rule processed
4508 if (*ssl_bump
== NULL
) {
4509 bumpCfgStyleLast
= bcsNone
;
4510 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4513 auto action
= Acl::Answer(ACCESS_ALLOWED
);
4515 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4516 action
.kind
= Ssl::bumpClientFirst
;
4517 bumpCfgStyleNow
= bcsNew
;
4518 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4519 action
.kind
= Ssl::bumpServerFirst
;
4520 bumpCfgStyleNow
= bcsNew
;
4521 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpPeek
]) == 0) {
4522 action
.kind
= Ssl::bumpPeek
;
4523 bumpCfgStyleNow
= bcsNew
;
4524 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpStare
]) == 0) {
4525 action
.kind
= Ssl::bumpStare
;
4526 bumpCfgStyleNow
= bcsNew
;
4527 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpSplice
]) == 0) {
4528 action
.kind
= Ssl::bumpSplice
;
4529 bumpCfgStyleNow
= bcsNew
;
4530 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpBump
]) == 0) {
4531 action
.kind
= Ssl::bumpBump
;
4532 bumpCfgStyleNow
= bcsNew
;
4533 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpTerminate
]) == 0) {
4534 action
.kind
= Ssl::bumpTerminate
;
4535 bumpCfgStyleNow
= bcsNew
;
4536 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4537 action
.kind
= Ssl::bumpNone
;
4538 bumpCfgStyleNow
= bcsNew
;
4539 } else if (strcmp(bm
, "allow") == 0) {
4540 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4541 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4542 "is usually inferior to the newer server-first "
4543 "bumping mode. Update your ssl_bump rules.");
4544 action
.kind
= Ssl::bumpClientFirst
;
4545 bumpCfgStyleNow
= bcsOld
;
4546 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4547 } else if (strcmp(bm
, "deny") == 0) {
4548 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4549 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4550 "your ssl_bump rules.");
4551 action
.kind
= Ssl::bumpNone
;
4552 bumpCfgStyleNow
= bcsOld
;
4553 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4555 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4560 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4561 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4562 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4567 bumpCfgStyleLast
= bumpCfgStyleNow
;
4570 ParseAclWithAction(ssl_bump
, action
, "ssl_bump");
4573 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4576 dump_SBufList(entry
, ssl_bump
->treeDump(name
, [](const Acl::Answer
&action
) {
4577 return Ssl::BumpModeStr
.at(action
.kind
);
4581 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4583 free_acl_access(ssl_bump
);
4588 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4593 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4594 storeAppendPrintf(entry
, "%s %s %s", name
, hwa
->fieldName
.c_str(), hwa
->fieldValue
.c_str());
4596 dump_acl_list(entry
, hwa
->aclList
);
4597 storeAppendPrintf(entry
, "\n");
4601 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4605 *headers
= new HeaderWithAclList
;
4607 if ((fn
= ConfigParser::NextToken()) == NULL
) {
4613 hwa
.fieldId
= Http::HeaderLookupTable
.lookup(hwa
.fieldName
).id
;
4614 if (hwa
.fieldId
== Http::HdrType::BAD_HDR
)
4615 hwa
.fieldId
= Http::HdrType::OTHER
;
4617 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4618 ConfigParser::EnableMacros();
4619 String buf
= ConfigParser::NextQuotedToken();
4620 ConfigParser::DisableMacros();
4621 hwa
.fieldValue
= buf
.termedBuf();
4622 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4624 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4628 hwa
.valueFormat
= nlf
;
4631 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4632 (*headers
)->push_back(hwa
);
4635 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4640 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4642 aclDestroyAclList(&hwa
->aclList
);
4644 if (hwa
->valueFormat
) {
4645 delete hwa
->valueFormat
;
4646 hwa
->valueFormat
= NULL
;
4653 static void parse_note(Notes
*notes
)
4656 notes
->parse(LegacyParser
);
4659 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4661 notes
.dump(entry
, name
);
4664 static void free_note(Notes
*notes
)
4669 static DebugMessageId
ParseDebugMessageId(const char *value
, const char eov
)
4671 const auto id
= xatoui(value
, eov
);
4672 if (!(0 < id
&& id
< DebugMessageIdUpperBound
))
4673 throw TextException(ToSBuf("unknown cache_log_message ID: ", value
), Here());
4674 return static_cast<DebugMessageId
>(id
);
4677 static void parse_cache_log_message(DebugMessages
**debugMessages
)
4680 DebugMessageId minId
= 0;
4681 DebugMessageId maxId
= 0;
4683 char *key
= nullptr;
4684 char *value
= nullptr;
4685 while (ConfigParser::NextKvPair(key
, value
)) {
4686 if (strcmp(key
, "id") == 0) {
4689 minId
= maxId
= ParseDebugMessageId(value
, '\0');
4690 } else if (strcmp(key
, "ids") == 0) {
4693 const auto dash
= strchr(value
, '-');
4695 throw TextException(ToSBuf("malformed cache_log_message ID range: ", key
, '=', value
), Here());
4696 minId
= ParseDebugMessageId(value
, '-');
4697 maxId
= ParseDebugMessageId(dash
+1, '\0');
4699 throw TextException(ToSBuf("invalid cache_log_message ID range: ", key
, '=', value
), Here());
4700 } else if (strcmp(key
, "level") == 0) {
4703 const auto level
= xatoi(value
);
4705 throw TextException(ToSBuf("negative cache_log_message level: ", value
), Here());
4707 } else if (strcmp(key
, "limit") == 0) {
4710 msg
.limit
= xatoull(value
, 10);
4712 throw TextException(ToSBuf("unsupported cache_log_message option: ", key
), Here());
4714 key
= value
= nullptr;
4718 throw TextException(ToSBuf("repeated or conflicting cache_log_message option: ", key
, '=', value
), Here());
4721 throw TextException("cache_log_message is missing a required id=... or ids=... option", Here());
4723 if (!(msg
.levelled() || msg
.limited()))
4724 throw TextException("cache_log_message is missing a required level=... or limit=... option", Here());
4726 assert(debugMessages
);
4727 if (!*debugMessages
)
4728 *debugMessages
= new DebugMessages();
4730 for (auto id
= minId
; id
<= maxId
; ++id
) {
4732 (*debugMessages
)->messages
.at(id
) = msg
;
4736 static void dump_cache_log_message(StoreEntry
*entry
, const char *name
, const DebugMessages
*debugMessages
)
4742 for (const auto &msg
: debugMessages
->messages
) {
4743 if (!msg
.configured())
4745 out
<< name
<< " id=" << msg
.id
;
4747 out
<< " level=" << msg
.level
;
4749 out
<< " limit=" << msg
.limit
;
4752 const auto buf
= out
.buf();
4753 entry
->append(buf
.rawContent(), buf
.length()); // may be empty
4756 static void free_cache_log_message(DebugMessages
**debugMessages
)
4758 // clear old messages to avoid cumulative effect across (re)configurations
4759 assert(debugMessages
);
4760 delete *debugMessages
;
4761 *debugMessages
= nullptr;
4764 static bool FtpEspvDeprecated
= false;
4765 static void parse_ftp_epsv(acl_access
**ftp_epsv
)
4767 Acl::Answer ftpEpsvDeprecatedAction
;
4768 bool ftpEpsvIsDeprecatedRule
= false;
4770 char *t
= ConfigParser::PeekAtToken();
4776 if (!strcmp(t
, "off")) {
4777 (void)ConfigParser::NextToken();
4778 ftpEpsvIsDeprecatedRule
= true;
4779 ftpEpsvDeprecatedAction
= Acl::Answer(ACCESS_DENIED
);
4780 } else if (!strcmp(t
, "on")) {
4781 (void)ConfigParser::NextToken();
4782 ftpEpsvIsDeprecatedRule
= true;
4783 ftpEpsvDeprecatedAction
= Acl::Answer(ACCESS_ALLOWED
);
4786 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4787 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4788 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4790 if ((!ftpEpsvIsDeprecatedRule
&& FtpEspvDeprecated
) ||
4791 (ftpEpsvIsDeprecatedRule
&& !FtpEspvDeprecated
&& *ftp_epsv
!= NULL
)) {
4792 debugs(3, DBG_CRITICAL
, "FATAL: do not mix \"ftp_epsv on|off\" cfg lines with \"ftp_epsv allow|deny ...\" cfg lines. Update your ftp_epsv rules.");
4797 if (ftpEpsvIsDeprecatedRule
) {
4798 // overwrite previous ftp_epsv lines
4800 *ftp_epsv
= nullptr;
4802 if (ftpEpsvDeprecatedAction
== Acl::Answer(ACCESS_DENIED
)) {
4803 if (ACL
*a
= ACL::FindByName("all"))
4804 ParseAclWithAction(ftp_epsv
, ftpEpsvDeprecatedAction
, "ftp_epsv", a
);
4810 FtpEspvDeprecated
= true;
4812 aclParseAccessLine(cfg_directive
, LegacyParser
, ftp_epsv
);
4816 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
)
4819 dump_SBufList(entry
, ftp_epsv
->treeDump(name
, Acl::AllowOrDeny
));
4822 static void free_ftp_epsv(acl_access
**ftp_epsv
)
4824 free_acl_access(ftp_epsv
);
4825 FtpEspvDeprecated
= false;
4828 /// Like parseTimeLine() but does not require the timeunit to be specified.
4829 /// If missed, the default 'second' timeunit is assumed.
4830 static std::chrono::seconds
4831 ParseUrlRewriteTimeout()
4833 const auto timeValueToken
= ConfigParser::NextToken();
4834 if (!timeValueToken
)
4835 throw TexcHere("cannot read a time value");
4837 using Seconds
= std::chrono::seconds
;
4839 const auto parsedTimeValue
= xatof(timeValueToken
);
4841 if (parsedTimeValue
== 0)
4842 return std::chrono::seconds::zero();
4844 std::chrono::nanoseconds parsedUnitDuration
;
4846 const auto unitToken
= ConfigParser::PeekAtToken();
4847 if (parseTimeUnit
<Seconds
>(unitToken
, parsedUnitDuration
))
4848 (void)ConfigParser::NextToken();
4850 const auto defaultParsed
= parseTimeUnit
<Seconds
>(T_SECOND_STR
, parsedUnitDuration
);
4851 assert(defaultParsed
);
4852 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), ConfigParser::CurrentLocation() <<
4853 ": WARNING: missing time unit, using deprecated default '" << T_SECOND_STR
<< "'");
4856 const auto nanoseconds
= ToNanoSeconds(parsedTimeValue
, parsedUnitDuration
);
4858 return FromNanoseconds
<Seconds
>(nanoseconds
, parsedTimeValue
);
4862 parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4864 // TODO: do not allow optional timeunit (as the documentation prescribes)
4865 // and use parseTimeLine() instead.
4866 Config
.Timeout
.urlRewrite
= ParseUrlRewriteTimeout().count();
4869 while(ConfigParser::NextKvPair(key
, value
)) {
4870 if (strcasecmp(key
, "on_timeout") == 0) {
4871 if (strcasecmp(value
, "bypass") == 0)
4872 config
->action
= toutActBypass
;
4873 else if (strcasecmp(value
, "fail") == 0)
4874 config
->action
= toutActFail
;
4875 else if (strcasecmp(value
, "retry") == 0)
4876 config
->action
= toutActRetry
;
4877 else if (strcasecmp(value
, "use_configured_response") == 0) {
4878 config
->action
= toutActUseConfiguredResponse
;
4880 debugs(3, DBG_CRITICAL
, "FATAL: unsupported \"on_timeout\" action: " << value
);
4884 } else if (strcasecmp(key
, "response") == 0) {
4885 config
->response
= xstrdup(value
);
4887 debugs(3, DBG_CRITICAL
, "FATAL: unsupported option " << key
);
4893 if (config
->action
== toutActUseConfiguredResponse
&& !config
->response
) {
4894 debugs(3, DBG_CRITICAL
, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4898 if (config
->action
!= toutActUseConfiguredResponse
&& config
->response
) {
4899 debugs(3, DBG_CRITICAL
, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4905 dump_UrlHelperTimeout(StoreEntry
*entry
, const char *name
, SquidConfig::UrlHelperTimeout
&config
)
4907 const char *onTimedOutActions
[] = {"bypass", "fail", "retry", "use_configured_response"};
4908 assert(config
.action
>= 0 && config
.action
<= toutActUseConfiguredResponse
);
4910 dump_time_t(entry
, name
, Config
.Timeout
.urlRewrite
);
4911 storeAppendPrintf(entry
, " on_timeout=%s", onTimedOutActions
[config
.action
]);
4913 if (config
.response
)
4914 storeAppendPrintf(entry
, " response=\"%s\"", config
.response
);
4916 storeAppendPrintf(entry
, "\n");
4920 free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4922 Config
.Timeout
.urlRewrite
= 0;
4924 safe_free(config
->response
);
4928 parse_configuration_includes_quoted_values(bool *)
4933 // If quoted values is set to on then enable new strict mode parsing
4935 ConfigParser::RecognizeQuotedValues
= true;
4936 ConfigParser::StrictMode
= true;
4938 ConfigParser::RecognizeQuotedValues
= false;
4939 ConfigParser::StrictMode
= false;
4944 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool)
4946 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4947 dump_onoff(entry
, name
, val
);
4951 free_configuration_includes_quoted_values(bool *)
4953 ConfigParser::RecognizeQuotedValues
= false;
4954 ConfigParser::StrictMode
= false;
4958 parse_on_unsupported_protocol(acl_access
**access
)
4961 if ((tm
= ConfigParser::NextToken()) == NULL
) {
4966 auto action
= Acl::Answer(ACCESS_ALLOWED
);
4967 if (strcmp(tm
, "tunnel") == 0)
4969 else if (strcmp(tm
, "respond") == 0)
4972 debugs(3, DBG_CRITICAL
, "FATAL: unknown on_unsupported_protocol mode: " << tm
);
4978 ParseAclWithAction(access
, action
, "on_unsupported_protocol");
4982 dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
)
4984 static const std::vector
<const char *> onErrorTunnelMode
= {
4990 SBufList lines
= access
->treeDump(name
, [](const Acl::Answer
&action
) {
4991 return onErrorTunnelMode
.at(action
.kind
);
4993 dump_SBufList(entry
, lines
);
4998 free_on_unsupported_protocol(acl_access
**access
)
5000 free_acl_access(access
);
5004 parse_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuardsPtr
)
5006 assert(protoGuardsPtr
);
5007 auto &protoGuards
= *protoGuardsPtr
;
5009 protoGuards
= new HttpUpgradeProtocolAccess();
5010 protoGuards
->configureGuard(LegacyParser
);
5014 dump_http_upgrade_request_protocols(StoreEntry
*entry
, const char *rawName
, HttpUpgradeProtocolAccess
*protoGuards
)
5019 const SBuf
name(rawName
);
5020 protoGuards
->forEach([entry
,&name
](const SBuf
&proto
, const acl_access
*acls
) {
5022 line
.push_back(name
);
5023 line
.push_back(proto
);
5024 const auto acld
= acls
->treeDump("", &Acl::AllowOrDeny
);
5025 line
.insert(line
.end(), acld
.begin(), acld
.end());
5026 dump_SBufList(entry
, line
);
5031 free_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuardsPtr
)
5033 assert(protoGuardsPtr
);
5034 auto &protoGuards
= *protoGuardsPtr
;
5036 protoGuards
= nullptr;