2 * Copyright (C) 1996-2023 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 "debug/Messages.h"
32 #include "DiskIO/DiskIOModule.h"
33 #include "eui/Config.h"
34 #include "ExternalACL.h"
35 #include "format/Format.h"
36 #include "fqdncache.h"
37 #include "ftp/Elements.h"
39 #include "HttpHeaderTools.h"
40 #include "HttpUpgradeProtocolAccess.h"
41 #include "icmp/IcmpConfig.h"
42 #include "ident/Config.h"
43 #include "ip/Intercept.h"
44 #include "ip/NfMarkConfig.h"
45 #include "ip/QosConfig.h"
48 #include "log/Config.h"
49 #include "log/CustomLog.h"
51 #include "MessageDelayPools.h"
52 #include "mgr/ActionPasswordList.h"
53 #include "mgr/Registration.h"
54 #include "neighbors.h"
55 #include "NeighborTypeDomainList.h"
58 #include "PeerDigest.h"
59 #include "PeerPoolMgr.h"
61 #include "RefreshPattern.h"
63 #include "sbuf/List.h"
64 #include "sbuf/Stream.h"
65 #include "SquidConfig.h"
66 #include "SquidString.h"
67 #include "ssl/ProxyCerts.h"
69 #include "store/Disks.h"
73 /* wccp2 has its own conditional definitions */
76 #include "adaptation/Config.h"
79 #include "adaptation/icap/Config.h"
82 #include "adaptation/ecap/Config.h"
85 #include "ssl/Config.h"
86 #include "ssl/support.h"
89 #include "esi/Parser.h"
107 #if HAVE_SYS_SOCKET_H
108 #include <sys/socket.h>
111 #include <sys/stat.h>
115 #include "ssl/gadgets.h"
119 static void parse_adaptation_service_set_type();
120 static void parse_adaptation_service_chain_type();
121 static void parse_adaptation_access_type();
125 static void parse_icap_service_type(Adaptation::Icap::Config
*);
126 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
127 static void free_icap_service_type(Adaptation::Icap::Config
*);
128 static void parse_icap_class_type();
129 static void parse_icap_access_type();
131 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
132 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
133 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
137 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
138 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
139 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
142 static peer_t
parseNeighborType(const char *s
);
144 static const char *const T_NANOSECOND_STR
= "nanosecond";
145 static const char *const T_MICROSECOND_STR
= "microsecond";
146 static const char *const T_MILLISECOND_STR
= "millisecond";
147 static const char *const T_SECOND_STR
= "second";
148 static const char *const T_MINUTE_STR
= "minute";
149 static const char *const T_HOUR_STR
= "hour";
150 static const char *const T_DAY_STR
= "day";
151 static const char *const T_WEEK_STR
= "week";
152 static const char *const T_FORTNIGHT_STR
= "fortnight";
153 static const char *const T_MONTH_STR
= "month";
154 static const char *const T_YEAR_STR
= "year";
155 static const char *const T_DECADE_STR
= "decade";
157 static const char *const B_BYTES_STR
= "bytes";
158 static const char *const B_KBYTES_STR
= "KB";
159 static const char *const B_MBYTES_STR
= "MB";
160 static const char *const B_GBYTES_STR
= "GB";
162 // std::chrono::years requires C++20. Do our own rough calculation for now.
163 static const double HoursPerYear
= 24*365.2522;
165 static void parse_cache_log_message(DebugMessages
**messages
);
166 static void dump_cache_log_message(StoreEntry
*entry
, const char *name
, const DebugMessages
*messages
);
167 static void free_cache_log_message(DebugMessages
**messages
);
169 static void parse_access_log(CustomLog
** customlog_definitions
);
170 static int check_null_access_log(CustomLog
*customlog_definitions
);
171 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
172 static void free_access_log(CustomLog
** definitions
);
174 static void configDoConfigure(void);
175 static void parse_refreshpattern(RefreshPattern
**);
176 static void parse_u_short(unsigned short * var
);
177 static void parse_string(char **);
178 static void default_all(void);
179 static void defaults_if_none(void);
180 static void defaults_postscriptum(void);
181 static int parse_line(char *);
182 static void parse_obsolete(const char *);
183 static void parseBytesLine(size_t * bptr
, const char *units
);
184 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
185 static size_t parseBytesUnits(const char *unit
);
186 static void free_all(void);
187 void requirePathnameExists(const char *name
, const char *path
);
188 static OBJH dump_config
;
189 #if USE_HTTP_VIOLATIONS
190 static void free_HeaderManglers(HeaderManglers
**pm
);
191 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
192 static void parse_http_header_access(HeaderManglers
**manglers
);
193 #define free_http_header_access free_HeaderManglers
194 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
195 static void parse_http_header_replace(HeaderManglers
**manglers
);
196 #define free_http_header_replace free_HeaderManglers
198 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
199 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
200 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
201 static void parse_note(Notes
*);
202 static void dump_note(StoreEntry
*, const char *, Notes
&);
203 static void free_note(Notes
*);
204 static void parse_denyinfo(AclDenyInfoList
** var
);
205 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
206 static void free_denyinfo(AclDenyInfoList
** var
);
209 static void parse_IpAddress_list(Ip::Address_list
**);
210 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
211 static void free_IpAddress_list(Ip::Address_list
**);
213 static int check_null_IpAddress_list(const Ip::Address_list
*);
214 #endif /* CURRENTLY_UNUSED */
215 #endif /* USE_WCCPv2 */
217 static void parsePortCfg(AnyP::PortCfgPointer
*, const char *protocol
);
218 #define parse_PortCfg(l) parsePortCfg((l), token)
219 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfgPointer
&);
220 #define free_PortCfg(h) *(h)=NULL
223 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
224 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
225 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
226 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
227 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
228 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
229 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
230 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
231 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
232 #endif /* USE_OPENSSL */
234 static void parse_ftp_epsv(acl_access
**ftp_epsv
);
235 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
);
236 static void free_ftp_epsv(acl_access
**ftp_epsv
);
238 static void parse_b_size_t(size_t * var
);
239 static void parse_b_int64_t(int64_t * var
);
241 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
242 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
243 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
245 static void parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
246 static void dump_UrlHelperTimeout(StoreEntry
*, const char *, SquidConfig::UrlHelperTimeout
&);
247 static void free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
249 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
251 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
252 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
253 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
254 static void parse_on_unsupported_protocol(acl_access
**access
);
255 static void dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
);
256 static void free_on_unsupported_protocol(acl_access
**access
);
257 static void ParseAclWithAction(acl_access
**access
, const Acl::Answer
&action
, const char *desc
, ACL
*acl
= nullptr);
258 static void parse_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuards
);
259 static void dump_http_upgrade_request_protocols(StoreEntry
*entry
, const char *name
, HttpUpgradeProtocolAccess
*protoGuards
);
260 static void free_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuards
);
263 * LegacyParser is a parser for legacy code that uses the global
264 * approach. This is static so that it is only exposed to cache_cf.
265 * Other modules needing access to a ConfigParser should have it
266 * provided to them in their parserFOO methods.
268 static ConfigParser LegacyParser
= ConfigParser();
270 const char *cfg_directive
= nullptr;
271 const char *cfg_filename
= nullptr;
272 int config_lineno
= 0;
273 char config_input_line
[BUFSIZ
] = {};
278 LegacyParser
.destruct();
282 SetConfigFilename(char const *file_name
, bool is_pipe
)
285 cfg_filename
= file_name
+ 1;
287 cfg_filename
= file_name
;
291 skip_ws(const char* s
)
300 parseManyConfigFiles(char* files
, int depth
)
303 char* saveptr
= nullptr;
308 memset(&globbuf
, 0, sizeof(globbuf
));
309 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(nullptr, &saveptr
)) {
310 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, nullptr, &globbuf
) != 0) {
312 fatalf("Unable to find configuration file: %s: %s", path
, xstrerr(xerrno
));
315 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
316 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
320 char* file
= strwordtok(files
, &saveptr
);
321 while (file
!= NULL
) {
322 error_count
+= parseOneConfigFile(file
, depth
);
323 file
= strwordtok(NULL
, &saveptr
);
325 #endif /* HAVE_GLOB */
330 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
332 assert(str
!= nullptr);
333 assert(newSubstr
!= nullptr);
335 unsigned newSubstrLen
= strlen(newSubstr
);
336 if (newSubstrLen
> substrLen
)
337 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
339 // move tail part including zero
340 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
341 // copy new substring in place
342 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
348 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
350 assert(line
!= nullptr);
351 assert(macroName
!= nullptr);
352 assert(substStr
!= nullptr);
353 unsigned macroNameLen
= strlen(macroName
);
354 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
355 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
359 ProcessMacros(char*& line
, int& len
)
361 SubstituteMacro(line
, len
, "${service_name}", service_name
.c_str());
362 SubstituteMacro(line
, len
, "${process_name}", TheKidName
.c_str());
363 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
367 trim_trailing_ws(char* str
)
369 assert(str
!= nullptr);
370 unsigned i
= strlen(str
);
371 while ((i
> 0) && xisspace(str
[i
- 1]))
377 FindStatement(const char* line
, const char* statement
)
379 assert(line
!= nullptr);
380 assert(statement
!= nullptr);
382 const char* str
= skip_ws(line
);
383 unsigned len
= strlen(statement
);
384 if (strncmp(str
, statement
, len
) == 0) {
388 else if (xisspace(*str
))
396 StrToInt(const char* str
, long& number
)
398 assert(str
!= nullptr);
401 number
= strtol(str
, &end
, 0);
403 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
407 EvalBoolExpr(const char* expr
)
409 assert(expr
!= nullptr);
410 if (strcmp(expr
, "true") == 0) {
412 } else if (strcmp(expr
, "false") == 0) {
414 } else if (const char* equation
= strchr(expr
, '=')) {
415 const char* rvalue
= skip_ws(equation
+ 1);
416 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
417 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
418 trim_trailing_ws(lvalue
);
421 if (!StrToInt(lvalue
, number1
))
422 fatalf("String is not a integer number: '%s'\n", lvalue
);
424 if (!StrToInt(rvalue
, number2
))
425 fatalf("String is not a integer number: '%s'\n", rvalue
);
428 return number1
== number2
;
430 fatalf("Unable to evaluate expression '%s'\n", expr
);
431 return false; // this place cannot be reached
435 parseOneConfigFile(const char *file_name
, unsigned int depth
)
438 const char *orig_cfg_filename
= cfg_filename
;
439 const int orig_config_lineno
= config_lineno
;
440 char *token
= nullptr;
441 char *tmp_line
= nullptr;
442 int tmp_line_len
= 0;
446 debugs(3, Important(68), "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
448 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
452 if (file_name
[0] == '!' || file_name
[0] == '|') {
453 fp
= popen(file_name
+ 1, "r");
456 fp
= fopen(file_name
, "r");
461 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerr(xerrno
));
465 setmode(fileno(fp
), O_TEXT
);
468 SetConfigFilename(file_name
, bool(is_pipe
));
470 memset(config_input_line
, '\0', BUFSIZ
);
474 std::vector
<bool> if_states
;
475 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
478 if ((token
= strchr(config_input_line
, '\n')))
481 if ((token
= strchr(config_input_line
, '\r')))
484 // strip any prefix whitespace off the line.
485 const char *p
= skip_ws(config_input_line
);
486 if (config_input_line
!= p
)
487 memmove(config_input_line
, p
, strlen(p
)+1);
489 if (strncmp(config_input_line
, "#line ", 6) == 0) {
490 static char new_file_name
[1024];
492 static char new_lineno
;
493 token
= config_input_line
+ 6;
494 new_lineno
= strtol(token
, &file
, 0) - 1;
497 continue; /* Not a valid #line directive, may be a comment */
499 while (*file
&& xisspace((unsigned char) *file
))
504 continue; /* Not a valid #line directive, may be a comment */
506 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
508 if ((token
= strchr(new_file_name
, '"')))
511 SetConfigFilename(new_file_name
, false);
514 config_lineno
= new_lineno
;
517 if (config_input_line
[0] == '#')
520 if (config_input_line
[0] == '\0')
523 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
525 size_t append_len
= strlen(append
);
527 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
529 strcpy(tmp_line
+ tmp_line_len
, append
);
531 tmp_line_len
+= append_len
;
533 if (tmp_line
[tmp_line_len
-1] == '\\') {
534 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
535 tmp_line
[--tmp_line_len
] = '\0';
539 trim_trailing_ws(tmp_line
);
540 ProcessMacros(tmp_line
, tmp_line_len
);
541 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
543 if (const char* expr
= FindStatement(tmp_line
, "if")) {
544 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
545 } else if (FindStatement(tmp_line
, "endif")) {
546 if (!if_states
.empty())
547 if_states
.pop_back(); // remove last if-statement meaning
549 fatalf("'endif' without 'if'\n");
550 } else if (FindStatement(tmp_line
, "else")) {
551 if (!if_states
.empty())
552 if_states
.back() = !if_states
.back();
554 fatalf("'else' without 'if'\n");
555 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
556 /* Handle includes here */
557 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
558 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
561 if (!parse_line(tmp_line
)) {
562 debugs(3, DBG_CRITICAL
, ConfigParser::CurrentLocation() << ": unrecognized: '" << tmp_line
<< "'");
567 debugs(3, DBG_CRITICAL
, "ERROR: configuration failure: " << CurrentException
);
577 if (!if_states
.empty())
578 fatalf("if-statement without 'endif'\n");
581 int ret
= pclose(fp
);
584 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
589 SetConfigFilename(orig_cfg_filename
, false);
590 config_lineno
= orig_config_lineno
;
598 parseConfigFileOrThrow(const char *file_name
)
602 debugs(5, 4, MYNAME
);
606 ACLMethodData::ThePurgeCount
= 0;
609 err_count
= parseOneConfigFile(file_name
, 0);
613 defaults_postscriptum();
616 * We must call configDoConfigure() before leave_suid() because
617 * configDoConfigure() is where we turn username strings into
622 if (opt_send_signal
== -1) {
623 Mgr::RegisterAction("config",
624 "Current Squid Configuration",
632 // TODO: Refactor main.cc to centrally handle (and report) all exceptions.
634 parseConfigFile(const char *file_name
)
637 return parseConfigFileOrThrow(file_name
);
639 catch (const std::exception
&ex
) {
640 debugs(3, DBG_CRITICAL
, "FATAL: bad configuration: " << ex
.what());
642 return 1; // not reached
647 * The templated functions below are essentially ConfigParser methods. They are
648 * not implemented as such because our generated code calling them is the only
649 * code that can instantiate implementations for each T -- we cannot place these
650 * definitions into ConfigParser.cc unless cf_parser.cci is moved there.
653 // TODO: When adding Ts incompatible with this trivial API and implementation,
654 // replace both with a ConfigParser-maintained table of seen directives.
655 /// whether we have seen (and, hence, configured) the given directive
656 template <typename T
>
658 SawDirective(const T
&raw
)
663 /// Sets the given raw SquidConfig data member.
664 /// Extracts and interprets parser's configuration tokens.
665 template <typename T
>
667 ParseDirective(T
&raw
, ConfigParser
&parser
)
669 if (SawDirective(raw
))
670 parser
.rejectDuplicateDirective();
672 // TODO: parser.openDirective(directiveName);
674 raw
= Configuration::Component
<T
>::Parse(parser
);
676 parser
.closeDirective();
679 /// reports raw SquidConfig data member configuration using squid.conf syntax
680 /// \param name the name of the configuration directive being dumped
681 template <typename T
>
683 DumpDirective(const T
&raw
, StoreEntry
*entry
, const char *name
)
685 if (!SawDirective(raw
))
686 return; // not configured
688 entry
->append(name
, strlen(name
));
690 Configuration::Component
<T
>::Print(os
, raw
);
691 const auto buf
= os
.buf();
693 entry
->append(" ", 1);
694 entry
->append(buf
.rawContent(), buf
.length());
696 entry
->append("\n", 1);
699 /// frees any resources associated with the given raw SquidConfig data member
700 template <typename T
>
702 FreeDirective(T
&raw
)
704 Configuration::Component
<T
>::Free(raw
);
706 // While the implementation may change, there is no way to avoid zeroing.
707 // Even migration to a proper SquidConfig class would not help: While
708 // ordinary destructors do not need to zero data members, a SquidConfig
709 // destructor would have to zero to protect any SquidConfig::x destruction
710 // code from accidentally dereferencing an already destroyed Config.y.
711 static_assert(std::is_trivial
<T
>::value
, "SquidConfig member is trivial");
712 memset(&raw
, 0, sizeof(raw
));
716 configDoConfigure(void)
719 /* init memory as early as possible */
723 if (Debug::rotateNumber
< 0) {
724 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
727 #if SIZEOF_OFF_T <= 4
728 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
729 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
730 Config
.Store
.maxObjectSize
= 0x7FFF0000;
734 if (Config
.onoff
.httpd_suppress_version_string
)
735 visible_appname_string
= (char *)appname_string
;
737 visible_appname_string
= (char const *)APP_FULLNAME
;
739 if (Config
.Program
.redirect
) {
740 if (Config
.redirectChildren
.n_max
< 1) {
741 Config
.redirectChildren
.n_max
= 0;
742 wordlistDestroy(&Config
.Program
.redirect
);
746 if (Config
.Program
.store_id
) {
747 if (Config
.storeIdChildren
.n_max
< 1) {
748 Config
.storeIdChildren
.n_max
= 0;
749 wordlistDestroy(&Config
.Program
.store_id
);
753 if (Config
.appendDomain
)
754 if (*Config
.appendDomain
!= '.')
755 fatal("append_domain must begin with a '.'");
757 if (Config
.errHtmlText
== nullptr)
758 Config
.errHtmlText
= xstrdup(null_string
);
760 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
761 if (Config
.max_filedescriptors
> 0) {
762 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
764 #elif USE_SELECT || USE_SELECT_WIN32
765 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
766 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
772 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
774 visible_appname_string
);
777 * the extra space is for loop detection in client_side.c -- we search
778 * for substrings in the Via header.
780 snprintf(ThisCache2
, sizeof(ThisCache2
), " %s (%s)",
782 visible_appname_string
);
784 /* Use visible_hostname as default surrogate_id */
785 if (!Config
.Accel
.surrogate_id
) {
786 const char *t
= getMyHostname();
787 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
790 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
791 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
793 if (Config
.appendDomain
)
794 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
796 Config
.appendDomainLen
= 0;
798 if (Config
.connect_retries
> 10) {
799 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
800 Config
.connect_retries
= 10;
803 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
806 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
808 bool logDaemonUsed
= false;
809 for (const auto *log
= Config
.Log
.accesslogs
; !logDaemonUsed
&& log
; log
= log
->next
)
810 logDaemonUsed
= log
->usesDaemon();
812 for (const auto *log
= Config
.Log
.icaplogs
; !logDaemonUsed
&& log
; log
= log
->next
)
813 logDaemonUsed
= log
->usesDaemon();
816 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
818 if (Config
.Program
.redirect
)
819 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
821 if (Config
.Program
.store_id
)
822 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
824 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
826 if (Config
.errorDirectory
)
827 requirePathnameExists("Error Directory", Config
.errorDirectory
);
829 #if USE_HTTP_VIOLATIONS
832 const RefreshPattern
*R
;
834 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
835 if (!R
->flags
.override_expire
)
838 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
843 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
844 if (!R
->flags
.override_lastmod
)
847 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
852 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
853 if (!R
->flags
.reload_into_ims
)
856 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
861 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
862 if (!R
->flags
.ignore_reload
)
865 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
870 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
871 if (!R
->flags
.ignore_no_store
)
874 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
879 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
880 if (!R
->flags
.ignore_private
)
883 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
889 #if !USE_HTTP_VIOLATIONS
890 Config
.onoff
.via
= 1;
893 if (!Config
.onoff
.via
)
894 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
898 // we enable runtime PURGE checks if there is at least one PURGE method ACL
899 // TODO: replace with a dedicated "purge" ACL option?
900 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
902 if (geteuid() == 0) {
903 if (nullptr != Config
.effectiveUser
) {
905 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
907 if (nullptr == pwd
) {
909 * Andres Kroonmaa <andre@online.ee>:
910 * Some getpwnam() implementations (Solaris?) require
911 * an available FD < 256 for opening a FILE* to the
914 * This should be safe at startup, but might still fail
915 * during reconfigure.
917 fatalf("getpwnam failed to find userid for effective user '%s'",
918 Config
.effectiveUser
);
922 Config2
.effectiveUserID
= pwd
->pw_uid
;
924 Config2
.effectiveGroupID
= pwd
->pw_gid
;
927 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
928 // putenv() leaks by design; avoid leaks when nothing changes
930 if (lastDir
.isEmpty() || lastDir
.cmp(pwd
->pw_dir
) != 0) {
931 lastDir
= pwd
->pw_dir
;
932 int len
= strlen(pwd
->pw_dir
) + 6;
933 char *env_str
= (char *)xcalloc(len
, 1);
934 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
941 Config2
.effectiveUserID
= geteuid();
942 Config2
.effectiveGroupID
= getegid();
945 if (nullptr != Config
.effectiveGroup
) {
947 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
949 if (nullptr == grp
) {
950 fatalf("getgrnam failed to find groupid for effective group '%s'",
951 Config
.effectiveGroup
);
955 Config2
.effectiveGroupID
= grp
->gr_gid
;
959 if (Config
.ssl_client
.foreignIntermediateCertsPath
)
960 Ssl::loadSquidUntrusted(Config
.ssl_client
.foreignIntermediateCertsPath
);
963 if (Security::ProxyOutgoingConfig
.encryptTransport
) {
964 debugs(3, 2, "initializing https:// proxy context");
965 Config
.ssl_client
.sslContext
= Security::ProxyOutgoingConfig
.createClientContext(false);
966 if (!Config
.ssl_client
.sslContext
) {
968 fatal("ERROR: Could not initialize https:// proxy context");
970 debugs(3, DBG_IMPORTANT
, "ERROR: proxying https:// currently still requires --with-openssl");
974 Ssl::useSquidUntrusted(Config
.ssl_client
.sslContext
.get());
978 for (CachePeer
*p
= Config
.peers
; p
!= nullptr; p
= p
->next
) {
980 // default value for ssldomain= is the peer host/IP
981 if (p
->secure
.sslDomain
.isEmpty())
982 p
->secure
.sslDomain
= p
->host
;
984 if (p
->secure
.encryptTransport
) {
985 debugs(3, 2, "initializing TLS context for cache_peer " << *p
);
986 p
->sslContext
= p
->secure
.createClientContext(true);
987 if (!p
->sslContext
) {
988 debugs(3, DBG_CRITICAL
, "ERROR: Could not initialize TLS context for cache_peer " << *p
);
995 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= nullptr; s
= s
->next
) {
996 if (!s
->secure
.encryptTransport
)
998 debugs(3, 2, "initializing " << AnyP::UriScheme(s
->transport
.protocol
) << "_port " << s
->s
<< " TLS contexts");
999 s
->secure
.initServerContexts(*s
);
1002 // prevent infinite fetch loops in the request parser
1003 // due to buffer full but not enough data received to finish parse
1004 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
1005 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
1006 " Change client_request_buffer_max or request_header_max_size limits.",
1007 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
1011 * Disable client side request pipelining if client_persistent_connections OFF.
1012 * Waste of resources queueing any pipelined requests when the first will close the connection.
1014 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
1015 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
1016 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
1017 Config
.pipeline_max_prefetch
= 0;
1022 * disable client side request pipelining. There is a race with
1023 * Negotiate and NTLM when the client sends a second request on an
1024 * connection before the authenticate challenge is sent. With
1025 * pipelining OFF, the client may fail to authenticate, but squid's
1026 * state will be preserved.
1028 if (Config
.pipeline_max_prefetch
> 0) {
1029 Auth::SchemeConfig
*nego
= Auth::SchemeConfig::Find("Negotiate");
1030 Auth::SchemeConfig
*ntlm
= Auth::SchemeConfig::Find("NTLM");
1031 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
1032 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
1033 Config
.pipeline_max_prefetch
= 0;
1037 for (auto &authSchemes
: Auth::TheConfig
.schemeLists
) {
1038 authSchemes
.expand();
1039 if (authSchemes
.authConfigs
.empty()) {
1040 debugs(3, DBG_CRITICAL
, "auth_schemes: at least one scheme name is required; got: " << authSchemes
.rawSchemes
);
1047 /** Parse a line containing an obsolete directive.
1048 * To upgrade it where possible instead of just "Bungled config" for
1049 * directives which cannot be marked as simply aliases of the some name.
1050 * For example if the parameter order and content has changed.
1051 * Or if the directive has been completely removed.
1054 parse_obsolete(const char *name
)
1056 // Directives which have been radically changed rather than removed
1057 if (!strcmp(name
, "url_rewrite_concurrency")) {
1060 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
1061 Config
.redirectChildren
.concurrency
= cval
;
1064 if (!strcmp(name
, "log_access")) {
1069 if (!strcmp(name
, "log_icap")) {
1074 if (!strcmp(name
, "ignore_ims_on_miss")) {
1075 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1076 // than the 2.7 directive. We need to parse and invert the configured value.
1079 Config
.onoff
.cache_miss_revalidate
= !temp
;
1082 if (!strncmp(name
, "sslproxy_", 9)) {
1083 // the replacement directive tls_outgoing_options uses options instead of whole-line input
1085 if (!strcmp(name
, "sslproxy_cafile"))
1086 tmp
.append("cafile=");
1087 else if (!strcmp(name
, "sslproxy_capath"))
1088 tmp
.append("capath=");
1089 else if (!strcmp(name
, "sslproxy_cipher"))
1090 tmp
.append("cipher=");
1091 else if (!strcmp(name
, "sslproxy_client_certificate"))
1092 tmp
.append("cert=");
1093 else if (!strcmp(name
, "sslproxy_client_key"))
1095 else if (!strcmp(name
, "sslproxy_flags"))
1096 tmp
.append("flags=");
1097 else if (!strcmp(name
, "sslproxy_options"))
1098 tmp
.append("options=");
1099 else if (!strcmp(name
, "sslproxy_version"))
1100 tmp
.append("version=");
1102 debugs(3, DBG_CRITICAL
, "ERROR: unknown directive: " << name
);
1107 // add the value as unquoted-string because the old values did not support whitespace
1108 const char *token
= ConfigParser::NextQuotedOrToEol();
1109 tmp
.append(token
, strlen(token
));
1110 Security::ProxyOutgoingConfig
.parse(tmp
.c_str());
1114 template <class MinimalUnit
>
1118 const auto minUnit
= MinimalUnit(1);
1119 if(minUnit
== std::chrono::nanoseconds(1))
1120 return T_NANOSECOND_STR
;
1121 else if (minUnit
== std::chrono::microseconds(1))
1122 return T_MICROSECOND_STR
;
1123 else if (minUnit
== std::chrono::milliseconds(1))
1124 return T_MILLISECOND_STR
;
1126 assert(minUnit
>= std::chrono::seconds(1));
1127 return T_SECOND_STR
;
1131 /// Assigns 'ns' the number of nanoseconds corresponding to 'unitName'.
1132 /// \param MinimalUnit is a chrono duration type specifying the minimal
1133 /// allowed time unit.
1134 /// \returns true if unitName is correct and its time unit is not less
1135 /// than MinimalUnit.
1136 template <class MinimalUnit
>
1138 parseTimeUnit(const char *unitName
, std::chrono::nanoseconds
&ns
)
1141 throw TexcHere("missing time unit");
1143 if (!strncasecmp(unitName
, T_NANOSECOND_STR
, strlen(T_NANOSECOND_STR
)))
1144 ns
= std::chrono::nanoseconds(1);
1145 else if (!strncasecmp(unitName
, T_MICROSECOND_STR
, strlen(T_MICROSECOND_STR
)))
1146 ns
= std::chrono::microseconds(1);
1147 else if (!strncasecmp(unitName
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1148 ns
= std::chrono::milliseconds(1);
1149 else if (!strncasecmp(unitName
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1150 ns
= std::chrono::seconds(1);
1151 else if (!strncasecmp(unitName
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1152 ns
= std::chrono::minutes(1);
1153 else if (!strncasecmp(unitName
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1154 ns
= std::chrono::hours(1);
1155 else if (!strncasecmp(unitName
, T_DAY_STR
, strlen(T_DAY_STR
)))
1156 ns
= std::chrono::hours(24);
1157 else if (!strncasecmp(unitName
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1158 ns
= std::chrono::hours(24 * 7);
1159 else if (!strncasecmp(unitName
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1160 ns
= std::chrono::hours(24 * 14);
1161 else if (!strncasecmp(unitName
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1162 ns
= std::chrono::hours(24 * 30);
1163 else if (!strncasecmp(unitName
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1164 ns
= std::chrono::hours(static_cast<std::chrono::hours::rep
>(HoursPerYear
));
1165 else if (!strncasecmp(unitName
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1166 ns
= std::chrono::hours(static_cast<std::chrono::hours::rep
>(HoursPerYear
* 10));
1170 if (ns
< MinimalUnit(1)) {
1171 throw TexcHere(ToSBuf("time unit '", unitName
, "' is too small to be used in this context, the minimal unit is ",
1172 TimeUnitToString
<MinimalUnit
>()));
1178 static std::chrono::nanoseconds
1179 ToNanoSeconds(const double value
, const std::chrono::nanoseconds
&unit
)
1182 throw TexcHere("time must have a positive value");
1184 if (value
> (static_cast<double>(std::chrono::nanoseconds::max().count()) / unit
.count())) {
1185 const auto maxYears
= std::chrono::duration_cast
<std::chrono::hours
>(std::chrono::nanoseconds::max()).count()/HoursPerYear
;
1186 throw TexcHere(ToSBuf("time values cannot exceed ", maxYears
, " years"));
1189 return std::chrono::duration_cast
<std::chrono::nanoseconds
>(unit
* value
);
1192 template <class TimeUnit
>
1194 FromNanoseconds(const std::chrono::nanoseconds
&ns
, const double parsedValue
)
1196 const auto result
= std::chrono::duration_cast
<TimeUnit
>(ns
);
1197 if (!result
.count()) {
1198 throw TexcHere(ToSBuf("time value '", parsedValue
,
1199 "' is too small to be used in this context, the minimal value is 1 ",
1200 TimeUnitToString
<TimeUnit
>()));
1205 /// Parses a time specification from the config file and
1206 /// returns the time as a chrono duration object of 'TimeUnit' type.
1207 template <class TimeUnit
>
1211 const auto valueToken
= ConfigParser::NextToken();
1213 throw TexcHere("cannot read a time value");
1215 const auto parsedValue
= xatof(valueToken
);
1217 if (parsedValue
== 0)
1218 return TimeUnit::zero();
1220 std::chrono::nanoseconds parsedUnitDuration
;
1222 const auto token
= ConfigParser::PeekAtToken();
1224 if (!parseTimeUnit
<TimeUnit
>(token
, parsedUnitDuration
))
1225 throw TexcHere(ToSBuf("unknown time unit '", token
, "'"));
1227 (void)ConfigParser::NextToken();
1229 const auto nanoseconds
= ToNanoSeconds(parsedValue
, parsedUnitDuration
);
1231 // validate precisions (time-units-small only)
1232 if (TimeUnit(1) <= std::chrono::microseconds(1)) {
1233 if (0 < nanoseconds
.count() && nanoseconds
.count() < 3) {
1234 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), ConfigParser::CurrentLocation() << ": WARNING: " <<
1235 "Squid time measurement precision is likely to be far worse than " <<
1236 "the nanosecond-level precision implied by the configured value: " << parsedValue
<< ' ' << token
);
1240 return FromNanoseconds
<TimeUnit
>(nanoseconds
, parsedValue
);
1244 parseBytesLine64(int64_t * bptr
, const char *units
)
1251 if ((u
= parseBytesUnits(units
)) == 0) {
1256 if ((token
= ConfigParser::NextToken()) == nullptr) {
1261 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1268 m
= u
; /* default to 'units' if none specified */
1272 else if ((token
= ConfigParser::NextToken()) == nullptr)
1273 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1274 config_input_line
<< "', assuming " <<
1275 d
<< " " << units
);
1276 else if ((m
= parseBytesUnits(token
)) == 0) {
1281 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1283 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1284 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1285 d
<< " " << token
<< ": integer overflow (int64_t).");
1291 parseBytesLine(size_t * bptr
, const char *units
)
1298 if ((u
= parseBytesUnits(units
)) == 0) {
1303 if ((token
= ConfigParser::NextToken()) == nullptr) {
1308 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1309 *bptr
= static_cast<size_t>(-1);
1315 m
= u
; /* default to 'units' if none specified */
1319 else if ((token
= ConfigParser::NextToken()) == nullptr)
1320 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1321 config_input_line
<< "', assuming " <<
1322 d
<< " " << units
);
1323 else if ((m
= parseBytesUnits(token
)) == 0) {
1328 *bptr
= static_cast<size_t>(m
* d
/ u
);
1330 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1331 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1332 d
<< " " << token
<< ": integer overflow (size_t).");
1338 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1345 if ((u
= parseBytesUnits(units
)) == 0) {
1350 if ((token
= ConfigParser::NextToken()) == nullptr) {
1355 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1362 m
= u
; /* default to 'units' if none specified */
1366 else if ((token
= ConfigParser::NextToken()) == nullptr)
1367 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1368 config_input_line
<< "', assuming " <<
1369 d
<< " " << units
);
1370 else if ((m
= parseBytesUnits(token
)) == 0) {
1375 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1377 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1378 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1379 d
<< " " << token
<< ": integer overflow (ssize_t).");
1385 * Parse bytes from a string.
1386 * Similar to the parseBytesLine function but parses the string value instead of
1387 * the current token value.
1390 parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1393 if ((u
= parseBytesUnits(units
)) == 0) {
1398 // Find number from string beginning.
1399 char const * number_begin
= value
;
1400 char const * number_end
= value
;
1402 while ((*number_end
>= '0' && *number_end
<= '9')) {
1407 number
.assign(number_begin
, number_end
- number_begin
);
1409 int d
= xatoi(number
.termedBuf());
1411 if ((m
= parseBytesUnits(number_end
)) == 0) {
1416 *bptr
= static_cast<size_t>(m
* d
/ u
);
1417 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1422 parseBytesUnits(const char *unit
)
1424 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1427 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1430 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1433 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1436 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1442 parse_SBufList(SBufList
* list
)
1444 while (char *token
= ConfigParser::NextQuotedToken())
1445 list
->push_back(SBuf(token
));
1448 // just dump a list, no directive name
1450 dump_SBufList(StoreEntry
* entry
, const SBufList
&words
)
1452 for (const auto &i
: words
) {
1453 entry
->append(i
.rawContent(), i
.length());
1454 entry
->append(" ",1);
1456 entry
->append("\n",1);
1459 // dump a SBufList type directive with name
1461 dump_SBufList(StoreEntry
* entry
, const char *name
, SBufList
&list
)
1463 if (!list
.empty()) {
1464 entry
->append(name
, strlen(name
));
1465 entry
->append(" ", 1);
1466 dump_SBufList(entry
, list
);
1471 free_SBufList(SBufList
*list
)
1478 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1480 while (ae
!= nullptr) {
1481 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1482 storeAppendPrintf(entry
, "%s %s %s ",
1487 tail
.splice(tail
.end(), ae
->dumpOptions());
1488 tail
.splice(tail
.end(), ae
->dump()); // ACL parameters
1489 dump_SBufList(entry
, tail
);
1495 parse_acl(ACL
** ae
)
1497 ACL::ParseAclLine(LegacyParser
, ae
);
1507 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1509 // XXX: Should dump ACL names like "foo !bar" but dumps parsing context like
1510 // "(clientside_tos 0x11 line)".
1511 dump_SBufList(entry
, head
->dump());
1515 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1518 dump_SBufList(entry
, head
->treeDump(name
, &Acl::AllowOrDeny
));
1522 parse_acl_access(acl_access
** head
)
1524 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1528 free_acl_access(acl_access
** head
)
1530 aclDestroyAccessList(head
);
1534 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1536 char buf
[MAX_IPSTRLEN
];
1537 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1541 parse_address(Ip::Address
*addr
)
1543 char *token
= ConfigParser::NextToken();
1550 if (!strcmp(token
,"any_addr"))
1552 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1554 else if ( (*addr
= token
) ) // try parse numeric/IPA
1556 else if (addr
->GetHostByName(token
)) // do not use ipcache
1558 else { // not an IP and not a hostname
1559 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
1565 free_address(Ip::Address
*addr
)
1571 dump_acl_address(StoreEntry
* entry
, const char *name
, Acl::Address
* head
)
1573 char buf
[MAX_IPSTRLEN
];
1575 for (Acl::Address
*l
= head
; l
; l
= l
->next
) {
1576 if (!l
->addr
.isAnyAddr())
1577 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.toStr(buf
,MAX_IPSTRLEN
));
1579 storeAppendPrintf(entry
, "%s autoselect", name
);
1581 dump_acl_list(entry
, l
->aclList
);
1583 storeAppendPrintf(entry
, "\n");
1588 parse_acl_address(Acl::Address
** head
)
1590 Acl::Address
*l
= new Acl::Address
;
1591 parse_address(&l
->addr
);
1592 aclParseAclList(LegacyParser
, &l
->aclList
, l
->addr
);
1594 Acl::Address
**tail
= head
;
1596 tail
= &(*tail
)->next
;
1602 free_acl_address(Acl::Address
** head
)
1609 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1613 for (l
= head
; l
; l
= l
->next
) {
1615 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1617 storeAppendPrintf(entry
, "%s none", name
);
1619 dump_acl_list(entry
, l
->aclList
);
1621 storeAppendPrintf(entry
, "\n");
1626 parse_acl_tos(acl_tos
** head
)
1628 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1629 char *token
= ConfigParser::NextToken();
1636 if (!xstrtoui(token
, nullptr, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1641 const unsigned int chTos
= tos
& 0xFC;
1643 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: Tos value '" << tos
<< "' adjusted to '" << chTos
<< "'");
1647 acl_tos
*l
= new acl_tos
;
1649 l
->tos
= (tos_t
)tos
;
1651 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1653 acl_tos
**tail
= head
; /* sane name below */
1655 tail
= &(*tail
)->next
;
1661 free_acl_tos(acl_tos
** head
)
1667 #if SO_MARK && USE_LIBCAP
1670 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1672 for (acl_nfmark
*l
= head
; l
; l
= l
->next
) {
1673 storeAppendPrintf(entry
, "%s %s", name
, ToSBuf(l
->markConfig
).c_str());
1675 dump_acl_list(entry
, l
->aclList
);
1677 storeAppendPrintf(entry
, "\n");
1682 parse_acl_nfmark(acl_nfmark
** head
)
1684 SBuf
token(ConfigParser::NextToken());
1685 const auto mc
= Ip::NfMarkConfig::Parse(token
);
1687 // Packet marking directives should not allow to use masks.
1688 const auto pkt_dirs
= {"mark_client_packet", "clientside_mark", "tcp_outgoing_mark"};
1689 if (mc
.hasMask() && std::find(pkt_dirs
.begin(), pkt_dirs
.end(), cfg_directive
) != pkt_dirs
.end())
1690 throw TexcHere(ToSBuf("'", cfg_directive
, "' does not support masked marks"));
1692 acl_nfmark
*l
= new acl_nfmark
;
1695 aclParseAclList(LegacyParser
, &l
->aclList
, token
.c_str());
1697 acl_nfmark
**tail
= head
; /* sane name below */
1699 tail
= &(*tail
)->next
;
1705 free_acl_nfmark(acl_nfmark
** head
)
1710 #endif /* SO_MARK */
1713 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1715 for (AclSizeLimit
*l
= head
; l
; l
= l
->next
) {
1717 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1719 storeAppendPrintf(entry
, "%s none", name
);
1721 dump_acl_list(entry
, l
->aclList
);
1723 storeAppendPrintf(entry
, "\n");
1728 parse_acl_b_size_t(AclSizeLimit
** head
)
1730 AclSizeLimit
*l
= new AclSizeLimit
;
1732 parse_b_int64_t(&l
->size
);
1734 aclParseAclList(LegacyParser
, &l
->aclList
, l
->size
);
1736 AclSizeLimit
**tail
= head
; /* sane name below */
1738 tail
= &(*tail
)->next
;
1744 free_acl_b_size_t(AclSizeLimit
** head
)
1752 #include "DelayConfig.h"
1753 #include "DelayPools.h"
1754 /* do nothing - free_delay_pool_count is the magic free function.
1755 * this is why delay_pool_count isn't just marked TYPE: u_short
1757 #define free_delay_pool_class(X)
1758 #define free_delay_pool_access(X)
1759 #define free_delay_pool_rates(X)
1760 #define dump_delay_pool_class(X, Y, Z)
1761 #define dump_delay_pool_access(X, Y, Z)
1762 #define dump_delay_pool_rates(X, Y, Z)
1765 free_delay_pool_count(DelayConfig
* cfg
)
1767 cfg
->freePoolCount();
1771 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1773 cfg
.dumpPoolCount (entry
, name
);
1777 parse_delay_pool_count(DelayConfig
* cfg
)
1779 cfg
->parsePoolCount();
1783 parse_delay_pool_class(DelayConfig
* cfg
)
1785 cfg
->parsePoolClass();
1789 parse_delay_pool_rates(DelayConfig
* cfg
)
1791 cfg
->parsePoolRates();
1795 parse_delay_pool_access(DelayConfig
* cfg
)
1797 cfg
->parsePoolAccess(LegacyParser
);
1803 #include "ClientDelayConfig.h"
1804 /* do nothing - free_client_delay_pool_count is the magic free function.
1805 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1808 #define free_client_delay_pool_access(X)
1809 #define free_client_delay_pool_rates(X)
1810 #define dump_client_delay_pool_access(X, Y, Z)
1811 #define dump_client_delay_pool_rates(X, Y, Z)
1814 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1820 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1822 cfg
.dumpPoolCount (entry
, name
);
1826 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1828 cfg
->parsePoolCount();
1832 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1834 cfg
->parsePoolRates();
1838 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1840 cfg
->parsePoolAccess(LegacyParser
);
1844 #if USE_HTTP_VIOLATIONS
1846 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1849 manglers
->dumpAccess(entry
, name
);
1853 parse_http_header_access(HeaderManglers
**pm
)
1857 if ((t
= ConfigParser::NextToken()) == nullptr) {
1858 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1859 debugs(3, DBG_CRITICAL
, "ERROR: parse_http_header_access: missing header name.");
1864 *pm
= new HeaderManglers
;
1865 HeaderManglers
*manglers
= *pm
;
1866 headerMangler
*mangler
= manglers
->track(t
);
1869 std::string directive
= "http_header_access ";
1871 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1875 free_HeaderManglers(HeaderManglers
**pm
)
1877 // we delete the entire http_header_* mangler configuration at once
1878 if (const HeaderManglers
*manglers
= *pm
) {
1885 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1888 manglers
->dumpReplacement(entry
, name
);
1892 parse_http_header_replace(HeaderManglers
**pm
)
1896 if ((t
= ConfigParser::NextToken()) == nullptr) {
1897 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1898 debugs(3, DBG_CRITICAL
, "ERROR: parse_http_header_replace: missing header name.");
1902 const char *value
= ConfigParser::NextQuotedOrToEol();
1905 *pm
= new HeaderManglers
;
1906 HeaderManglers
*manglers
= *pm
;
1907 manglers
->setReplacement(t
, value
);
1913 dump_cachedir(StoreEntry
* entry
, const char *name
, const Store::DiskConfig
&swap
)
1915 Store::Disks::Dump(swap
, *entry
, name
);
1919 check_null_string(char *s
)
1921 return s
== nullptr;
1926 parse_authparam(Auth::ConfigVector
* config
)
1928 char *type_str
= ConfigParser::NextToken();
1934 char *param_str
= ConfigParser::NextToken();
1940 /* find a configuration for the scheme in the currently parsed configs... */
1941 Auth::SchemeConfig
*schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1943 if (schemeCfg
== nullptr) {
1944 /* Create a configuration based on the scheme info */
1945 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1947 if (theScheme
== nullptr) {
1948 debugs(3, DBG_CRITICAL
, "ERROR: Failure while parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1953 config
->push_back(theScheme
->createConfig());
1954 schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1955 if (schemeCfg
== nullptr) {
1956 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1962 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1966 free_authparam(Auth::ConfigVector
* cfg
)
1968 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1971 /* on reconfigure initialize new auth schemes for the new config. */
1972 if (reconfiguring
) {
1978 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1980 for (auto *scheme
: cfg
)
1981 scheme
->dump(entry
, name
, scheme
);
1985 parse_AuthSchemes(acl_access
**authSchemes
)
1987 const char *tok
= ConfigParser::NextQuotedToken();
1989 debugs(29, DBG_CRITICAL
, "FATAL: auth_schemes missing the parameter");
1993 Auth::TheConfig
.schemeLists
.emplace_back(tok
, ConfigParser::LastTokenWasQuoted());
1994 const auto action
= Acl::Answer(ACCESS_ALLOWED
, Auth::TheConfig
.schemeLists
.size() - 1);
1995 ParseAclWithAction(authSchemes
, action
, "auth_schemes");
1999 free_AuthSchemes(acl_access
**authSchemes
)
2001 Auth::TheConfig
.schemeLists
.clear();
2002 free_acl_access(authSchemes
);
2006 dump_AuthSchemes(StoreEntry
*entry
, const char *name
, acl_access
*authSchemes
)
2009 dump_SBufList(entry
, authSchemes
->treeDump(name
, [](const Acl::Answer
&action
) {
2010 return Auth::TheConfig
.schemeLists
.at(action
.kind
).rawSchemes
;
2014 #endif /* USE_AUTH */
2017 ParseAclWithAction(acl_access
**access
, const Acl::Answer
&action
, const char *desc
, ACL
*acl
)
2022 *access
= new Acl::Tree
;
2023 name
.Printf("(%s rules)", desc
);
2024 (*access
)->context(name
.c_str(), config_input_line
);
2026 Acl::AndNode
*rule
= new Acl::AndNode
;
2027 name
.Printf("(%s rule)", desc
);
2028 rule
->context(name
.c_str(), config_input_line
);
2033 (*access
)->add(rule
, action
);
2037 parse_cachedir(Store::DiskConfig
*swap
)
2040 Store::Disks::Parse(*swap
);
2044 peer_type_str(const peer_t type
)
2046 const char * result
;
2058 case PEER_MULTICAST
:
2059 result
= "multicast";
2071 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2073 NeighborTypeDomainList
*t
;
2074 LOCAL_ARRAY(char, xname
, 128);
2076 while (p
!= nullptr) {
2077 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2084 dump_peer_options(entry
, p
);
2087 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2088 dump_acl_access(entry
, xname
, p
->access
);
2091 for (t
= p
->typelist
; t
; t
= t
->next
) {
2092 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2094 peer_type_str(t
->type
),
2103 * utility function to prevent getservbyname() being called with a numeric value
2104 * on Windows at least it returns garage results.
2107 isUnsignedNumeric(const char *str
, size_t len
)
2109 if (len
< 1) return false;
2111 for (; len
>0 && *str
; ++str
, --len
) {
2112 if (! isdigit(*str
))
2119 \param proto 'tcp' or 'udp' for protocol
2120 \returns Port the named service is supposed to be listening on.
2122 static unsigned short
2123 GetService(const char *proto
)
2125 struct servent
*port
= nullptr;
2126 /** Parses a port number or service name from the squid.conf */
2127 char *token
= ConfigParser::NextToken();
2128 if (token
== nullptr) {
2130 return 0; /* NEVER REACHED */
2132 /** Returns either the service port number from /etc/services */
2133 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2134 port
= getservbyname(token
, proto
);
2135 if (port
!= nullptr) {
2136 return ntohs((unsigned short)port
->s_port
);
2138 /** Or a numeric translation of the config text. */
2139 return xatos(token
);
2143 \returns Port the named TCP service is supposed to be listening on.
2144 \copydoc GetService(const char *proto)
2146 inline unsigned short
2149 return GetService("tcp");
2153 \returns Port the named UDP service is supposed to be listening on.
2154 \copydoc GetService(const char *proto)
2156 inline unsigned short
2159 return GetService("udp");
2163 parse_peer(CachePeer
** head
)
2165 char *host_str
= ConfigParser::NextToken();
2171 char *token
= ConfigParser::NextToken();
2177 const auto p
= new CachePeer(host_str
);
2179 p
->type
= parseNeighborType(token
);
2181 if (p
->type
== PEER_MULTICAST
) {
2182 p
->options
.no_digest
= true;
2183 p
->options
.no_netdb_exchange
= true;
2186 p
->http_port
= GetTcpService();
2188 if (!p
->http_port
) {
2194 p
->icp
.port
= GetUdpService();
2196 while ((token
= ConfigParser::NextToken())) {
2197 if (!strcmp(token
, "proxy-only")) {
2198 p
->options
.proxy_only
= true;
2199 } else if (!strcmp(token
, "no-query")) {
2200 p
->options
.no_query
= true;
2201 } else if (!strcmp(token
, "background-ping")) {
2202 p
->options
.background_ping
= true;
2203 } else if (!strcmp(token
, "no-digest")) {
2204 p
->options
.no_digest
= true;
2205 } else if (!strcmp(token
, "no-tproxy")) {
2206 p
->options
.no_tproxy
= true;
2207 } else if (!strcmp(token
, "multicast-responder")) {
2208 p
->options
.mcast_responder
= true;
2209 #if PEER_MULTICAST_SIBLINGS
2210 } else if (!strcmp(token
, "multicast-siblings")) {
2211 p
->options
.mcast_siblings
= true;
2213 } else if (!strncmp(token
, "weight=", 7)) {
2214 p
->weight
= xatoi(token
+ 7);
2215 } else if (!strncmp(token
, "basetime=", 9)) {
2216 p
->basetime
= xatoi(token
+ 9);
2217 } else if (!strcmp(token
, "closest-only")) {
2218 p
->options
.closest_only
= true;
2219 } else if (!strncmp(token
, "ttl=", 4)) {
2220 p
->mcast
.ttl
= xatoi(token
+ 4);
2222 if (p
->mcast
.ttl
< 0)
2225 if (p
->mcast
.ttl
> 128)
2227 } else if (!strcmp(token
, "default")) {
2228 p
->options
.default_parent
= true;
2229 } else if (!strcmp(token
, "round-robin")) {
2230 p
->options
.roundrobin
= true;
2231 } else if (!strcmp(token
, "weighted-round-robin")) {
2232 p
->options
.weighted_roundrobin
= true;
2234 } else if (!strcmp(token
, "htcp")) {
2235 p
->options
.htcp
= true;
2236 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2237 /* Note: The htcp- form is deprecated, replaced by htcp= */
2238 p
->options
.htcp
= true;
2239 char *tmp
= xstrdup(token
+5);
2240 char *mode
, *nextmode
;
2241 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2242 nextmode
= strchr(mode
, ',');
2247 if (!strcmp(mode
, "no-clr")) {
2248 if (p
->options
.htcp_only_clr
)
2249 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2250 p
->options
.htcp_no_clr
= true;
2251 } else if (!strcmp(mode
, "no-purge-clr")) {
2252 p
->options
.htcp_no_purge_clr
= true;
2253 } else if (!strcmp(mode
, "only-clr")) {
2254 if (p
->options
.htcp_no_clr
)
2255 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2256 p
->options
.htcp_only_clr
= true;
2257 } else if (!strcmp(mode
, "forward-clr")) {
2258 p
->options
.htcp_forward_clr
= true;
2259 } else if (!strcmp(mode
, "oldsquid")) {
2260 p
->options
.htcp_oldsquid
= true;
2262 fatalf("invalid HTCP mode '%s'", mode
);
2267 } else if (!strcmp(token
, "no-netdb-exchange")) {
2268 p
->options
.no_netdb_exchange
= true;
2270 } else if (!strcmp(token
, "carp")) {
2271 if (p
->type
!= PEER_PARENT
)
2272 throw TextException(ToSBuf("non-parent carp cache_peer ", *p
), Here());
2274 p
->options
.carp
= true;
2275 } else if (!strncmp(token
, "carp-key=", 9)) {
2276 if (p
->options
.carp
!= true)
2277 throw TextException(ToSBuf("carp-key specified on non-carp cache_peer ", *p
), Here());
2278 p
->options
.carp_key
.set
= true;
2279 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2280 for (; key
; key
= nextkey
) {
2281 nextkey
=strchr(key
,',');
2282 if (nextkey
) ++nextkey
; // skip the comma, any
2283 if (0==strncmp(key
,"scheme",6)) {
2284 p
->options
.carp_key
.scheme
= true;
2285 } else if (0==strncmp(key
,"host",4)) {
2286 p
->options
.carp_key
.host
= true;
2287 } else if (0==strncmp(key
,"port",4)) {
2288 p
->options
.carp_key
.port
= true;
2289 } else if (0==strncmp(key
,"path",4)) {
2290 p
->options
.carp_key
.path
= true;
2291 } else if (0==strncmp(key
,"params",6)) {
2292 p
->options
.carp_key
.params
= true;
2294 fatalf("invalid carp-key '%s'",key
);
2297 } else if (!strcmp(token
, "userhash")) {
2299 if (p
->type
!= PEER_PARENT
)
2300 throw TextException(ToSBuf("non-parent userhash cache_peer ", *p
), Here());
2302 p
->options
.userhash
= true;
2304 throw TextException(ToSBuf("missing authentication support; required for userhash cache_peer ", *p
), Here());
2306 } else if (!strcmp(token
, "sourcehash")) {
2307 if (p
->type
!= PEER_PARENT
)
2308 throw TextException(ToSBuf("non-parent sourcehash cache_peer ", *p
), Here());
2310 p
->options
.sourcehash
= true;
2312 } else if (!strcmp(token
, "no-delay")) {
2314 p
->options
.no_delay
= true;
2316 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2318 } else if (!strncmp(token
, "login=", 6)) {
2319 p
->login
= xstrdup(token
+ 6);
2320 rfc1738_unescape(p
->login
);
2321 } else if (!strcmp(token
, "auth-no-keytab")) {
2322 p
->options
.auth_no_keytab
= 1;
2323 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2324 p
->connect_timeout_raw
= xatoi(token
+ 16);
2325 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2326 p
->connect_fail_limit
= xatoi(token
+ 19);
2327 #if USE_CACHE_DIGESTS
2328 } else if (!strncmp(token
, "digest-url=", 11)) {
2329 p
->digest_url
= xstrdup(token
+ 11);
2332 } else if (!strcmp(token
, "allow-miss")) {
2333 p
->options
.allow_miss
= true;
2334 } else if (!strncmp(token
, "max-conn=", 9)) {
2335 p
->max_conn
= xatoi(token
+ 9);
2336 } else if (!strncmp(token
, "standby=", 8)) {
2337 p
->standby
.limit
= xatoi(token
+ 8);
2338 } else if (!strcmp(token
, "originserver")) {
2339 p
->options
.originserver
= true;
2340 } else if (!strncmp(token
, "name=", 5)) {
2341 p
->rename(token
+ 5);
2342 } else if (!strncmp(token
, "forceddomain=", 13)) {
2343 safe_free(p
->domain
);
2345 p
->domain
= xstrdup(token
+ 13);
2347 } else if (strncmp(token
, "ssl", 3) == 0) {
2349 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option '" << token
<< "' requires --with-openssl");
2351 p
->secure
.parse(token
+3);
2353 } else if (strncmp(token
, "tls-", 4) == 0) {
2354 p
->secure
.parse(token
+4);
2355 } else if (strncmp(token
, "tls", 3) == 0) {
2356 p
->secure
.parse(token
+3);
2357 } else if (strcmp(token
, "front-end-https") == 0) {
2358 p
->front_end_https
= 1;
2359 } else if (strcmp(token
, "front-end-https=on") == 0) {
2360 p
->front_end_https
= 1;
2361 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2362 p
->front_end_https
= 2;
2363 } else if (strcmp(token
, "connection-auth=off") == 0) {
2364 p
->connection_auth
= 0;
2365 } else if (strcmp(token
, "connection-auth") == 0) {
2366 p
->connection_auth
= 1;
2367 } else if (strcmp(token
, "connection-auth=on") == 0) {
2368 p
->connection_auth
= 1;
2369 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2370 p
->connection_auth
= 2;
2371 } else if (token
[0] == '#') {
2372 // start of a text comment. stop reading this line.
2375 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2379 if (findCachePeerByName(p
->name
))
2380 throw TextException(ToSBuf("cache_peer ", *p
, " specified twice"), Here());
2382 if (p
->max_conn
> 0 && p
->max_conn
< p
->standby
.limit
)
2383 throw TextException(ToSBuf("cache_peer ", *p
, " max-conn=", p
->max_conn
,
2384 " is lower than its standby=", p
->standby
.limit
), Here());
2389 if (p
->connect_fail_limit
< 1)
2390 p
->connect_fail_limit
= 10;
2392 #if USE_CACHE_DIGESTS
2393 if (!p
->options
.no_digest
)
2394 peerDigestCreate(p
);
2397 if (p
->secure
.encryptTransport
)
2398 p
->secure
.parseOptions();
2400 p
->index
= ++Config
.npeers
;
2402 while (*head
!= nullptr)
2403 head
= &(*head
)->next
;
2411 free_peer(CachePeer
** P
)
2419 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2422 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2423 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2425 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2427 for (auto w
: list
->actions
)
2428 entry
->appendf(" " SQUIDSBUFPH
, SQUIDSBUFPRINT(w
));
2430 storeAppendPrintf(entry
, "\n");
2436 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2438 char *passwd
= nullptr;
2439 parse_string(&passwd
);
2441 Mgr::ActionPasswordList
*p
= new Mgr::ActionPasswordList
;
2444 while (char *token
= ConfigParser::NextQuotedToken())
2445 p
->actions
.push_back(SBuf(token
));
2447 Mgr::ActionPasswordList
**P
;
2448 for (P
= head
; *P
; P
= &(*P
)->next
) {
2450 * See if any of the actions from this line already have a
2451 * password from previous lines. The password checking
2452 * routines in cache_manager.c take the the password from
2453 * the first Mgr::ActionPasswordList that contains the
2454 * requested action. Thus, we should warn users who might
2455 * think they can have two passwords for the same action.
2457 for (const auto &w
: (*P
)->actions
) {
2458 for (const auto &u
: p
->actions
) {
2462 debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u
<< "' (line " << config_lineno
<< ") already has a password");
2471 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2478 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2480 while (var
!= nullptr) {
2481 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2483 for (const auto &aclName
: var
->acl_list
)
2484 storeAppendPrintf(entry
, " " SQUIDSBUFPH
, SQUIDSBUFPRINT(aclName
));
2486 storeAppendPrintf(entry
, "\n");
2493 parse_denyinfo(AclDenyInfoList
** var
)
2495 aclParseDenyInfoLine(var
);
2499 free_denyinfo(AclDenyInfoList
** list
)
2506 parse_peer_access(void)
2508 auto &p
= LegacyParser
.cachePeer("cache_peer_access peer-name");
2509 std::string directive
= "peer_access ";
2510 directive
+= p
.name
;
2511 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
.access
);
2515 parse_hostdomaintype(void)
2517 auto &p
= LegacyParser
.cachePeer("neighbor_type_domain peer-name");
2519 char *type
= ConfigParser::NextToken();
2525 char *domain
= nullptr;
2526 while ((domain
= ConfigParser::NextToken())) {
2527 auto *l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2528 l
->type
= parseNeighborType(type
);
2529 l
->domain
= xstrdup(domain
);
2531 NeighborTypeDomainList
**L
= nullptr;
2532 for (L
= &p
.typelist
; *L
; L
= &((*L
)->next
));
2538 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2540 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2558 dump_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2560 storeAppendPrintf(entry
, "%s %" PRId64
"\n", name
, var
);
2564 parse_int64_t(int64_t *var
)
2572 free_int64_t(int64_t *var
)
2578 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2580 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2584 parse_onoff(int *var
)
2586 char *token
= ConfigParser::NextToken();
2592 if (!strcmp(token
, "on")) {
2594 } else if (!strcmp(token
, "enable")) {
2595 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2597 } else if (!strcmp(token
, "off")) {
2599 } else if (!strcmp(token
, "disable")) {
2600 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2603 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2608 #define free_onoff free_int
2611 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2622 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2626 parse_tristate(int *var
)
2628 char *token
= ConfigParser::NextToken();
2634 if (!strcmp(token
, "on")) {
2636 } else if (!strcmp(token
, "enable")) {
2637 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2639 } else if (!strcmp(token
, "warn")) {
2641 } else if (!strcmp(token
, "off")) {
2643 } else if (!strcmp(token
, "disable")) {
2644 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2647 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2652 #define free_tristate free_int
2655 parse_pipelinePrefetch(int *var
)
2657 char *token
= ConfigParser::PeekAtToken();
2663 if (!strcmp(token
, "on")) {
2664 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2667 (void)ConfigParser::NextToken();
2668 } else if (!strcmp(token
, "off")) {
2669 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2672 (void)ConfigParser::NextToken();
2677 #define free_pipelinePrefetch free_int
2678 #define dump_pipelinePrefetch dump_int
2681 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2683 while (head
!= nullptr) {
2684 PackableStream
os(*entry
);
2686 head
->printHead(os
);
2688 if (head
->max_stale
>= 0)
2689 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2691 if (head
->flags
.refresh_ims
)
2692 storeAppendPrintf(entry
, " refresh-ims");
2694 if (head
->flags
.store_stale
)
2695 storeAppendPrintf(entry
, " store-stale");
2697 #if USE_HTTP_VIOLATIONS
2699 if (head
->flags
.override_expire
)
2700 storeAppendPrintf(entry
, " override-expire");
2702 if (head
->flags
.override_lastmod
)
2703 storeAppendPrintf(entry
, " override-lastmod");
2705 if (head
->flags
.reload_into_ims
)
2706 storeAppendPrintf(entry
, " reload-into-ims");
2708 if (head
->flags
.ignore_reload
)
2709 storeAppendPrintf(entry
, " ignore-reload");
2711 if (head
->flags
.ignore_no_store
)
2712 storeAppendPrintf(entry
, " ignore-no-store");
2714 if (head
->flags
.ignore_private
)
2715 storeAppendPrintf(entry
, " ignore-private");
2718 storeAppendPrintf(entry
, "\n");
2725 parse_refreshpattern(RefreshPattern
** head
)
2731 int refresh_ims
= 0;
2732 int store_stale
= 0;
2735 #if USE_HTTP_VIOLATIONS
2737 int override_expire
= 0;
2738 int override_lastmod
= 0;
2739 int reload_into_ims
= 0;
2740 int ignore_reload
= 0;
2741 int ignore_no_store
= 0;
2742 int ignore_private
= 0;
2748 auto regex
= LegacyParser
.regex("refresh_pattern regex");
2750 i
= GetInteger(); /* token: min */
2752 /* catch negative and insanely huge values close to 32-bit wrap */
2754 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2757 if (i
> 60*24*365) {
2758 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2762 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2764 pct
= GetPercentage(false); /* token: pct . with no limit on size */
2766 i
= GetInteger(); /* token: max */
2768 /* catch negative and insanely huge values close to 32-bit wrap */
2770 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2773 if (i
> 60*24*365) {
2774 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2778 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2781 while ((token
= ConfigParser::NextToken()) != nullptr) {
2782 if (!strcmp(token
, "refresh-ims")) {
2784 } else if (!strcmp(token
, "store-stale")) {
2786 } else if (!strncmp(token
, "max-stale=", 10)) {
2787 max_stale
= xatoi(token
+ 10);
2789 #if USE_HTTP_VIOLATIONS
2791 } else if (!strcmp(token
, "override-expire"))
2792 override_expire
= 1;
2793 else if (!strcmp(token
, "override-lastmod"))
2794 override_lastmod
= 1;
2795 else if (!strcmp(token
, "ignore-no-store"))
2796 ignore_no_store
= 1;
2797 else if (!strcmp(token
, "ignore-private"))
2799 else if (!strcmp(token
, "reload-into-ims")) {
2800 reload_into_ims
= 1;
2801 refresh_nocache_hack
= 1;
2802 /* tell client_side.c that this is used */
2803 } else if (!strcmp(token
, "ignore-reload")) {
2805 refresh_nocache_hack
= 1;
2806 /* tell client_side.c that this is used */
2809 } else if (!strcmp(token
, "ignore-no-cache") ||
2810 !strcmp(token
, "ignore-must-revalidate") ||
2811 !strcmp(token
, "ignore-auth")
2813 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token
<< "' is obsolete. Remove it.");
2815 debugs(22, DBG_CRITICAL
, "ERROR: Unknown refresh_pattern option: " << token
);
2818 pct
= pct
< 0.0 ? 0.0 : pct
;
2819 max
= max
< 0 ? 0 : max
;
2820 t
= new RefreshPattern(std::move(regex
));
2826 t
->flags
.refresh_ims
= true;
2829 t
->flags
.store_stale
= true;
2831 t
->max_stale
= max_stale
;
2833 #if USE_HTTP_VIOLATIONS
2835 if (override_expire
)
2836 t
->flags
.override_expire
= true;
2838 if (override_lastmod
)
2839 t
->flags
.override_lastmod
= true;
2841 if (reload_into_ims
)
2842 t
->flags
.reload_into_ims
= true;
2845 t
->flags
.ignore_reload
= true;
2847 if (ignore_no_store
)
2848 t
->flags
.ignore_no_store
= true;
2851 t
->flags
.ignore_private
= true;
2857 head
= &(*head
)->next
;
2863 free_refreshpattern(RefreshPattern
** head
)
2868 #if USE_HTTP_VIOLATIONS
2869 refresh_nocache_hack
= 0;
2875 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2878 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2882 parse_string(char **var
)
2886 char *token
= ConfigParser::NextToken();
2892 *var
= xstrdup(token
);
2896 free_string(char **var
)
2902 parse_eol(char *volatile *var
)
2909 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
2917 while (*token
&& xisspace(*token
))
2925 *var
= xstrdup((char *) token
);
2928 #define dump_eol dump_string
2929 #define free_eol free_string
2932 parse_TokenOrQuotedString(char **var
)
2936 char *token
= ConfigParser::NextQuotedToken();
2942 *var
= xstrdup(token
);
2945 #define dump_TokenOrQuotedString dump_string
2946 #define free_TokenOrQuotedString free_string
2949 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2951 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2955 parse_time_t(time_t * var
)
2957 const auto maxTime
= std::numeric_limits
<time_t>::max();
2958 const auto seconds
= parseTimeLine
<std::chrono::seconds
>();
2959 if (maxTime
< seconds
.count())
2960 throw TexcHere(ToSBuf("directive supports time values up to ", maxTime
, " but is given ", seconds
.count(), " seconds"));
2961 *var
= static_cast<time_t>(seconds
.count());
2965 free_time_t(time_t * var
)
2971 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
2974 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
2976 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
2980 parse_time_msec(time_msec_t
*var
)
2982 *var
= parseTimeLine
<std::chrono::milliseconds
>().count();
2986 free_time_msec(time_msec_t
* var
)
2992 dump_time_nanoseconds(StoreEntry
*entry
, const char *name
, const std::chrono::nanoseconds
&var
)
2994 // std::chrono::nanoseconds::rep is unknown a priori so we cast to (and print) the largest supported integer
2995 storeAppendPrintf(entry
, "%s %jd nanoseconds\n", name
, static_cast<intmax_t>(var
.count()));
2999 parse_time_nanoseconds(std::chrono::nanoseconds
*var
)
3001 *var
= parseTimeLine
<std::chrono::nanoseconds
>();
3005 free_time_nanoseconds(std::chrono::nanoseconds
*var
)
3007 *var
= std::chrono::nanoseconds::zero();
3011 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3013 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3017 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3019 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3023 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3025 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3029 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3031 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3035 parse_b_size_t(size_t * var
)
3037 parseBytesLine(var
, B_BYTES_STR
);
3041 parse_b_ssize_t(ssize_t
* var
)
3043 parseBytesLineSigned(var
, B_BYTES_STR
);
3047 parse_b_int64_t(int64_t * var
)
3049 parseBytesLine64(var
, B_BYTES_STR
);
3053 parse_kb_int64_t(int64_t * var
)
3055 parseBytesLine64(var
, B_KBYTES_STR
);
3059 free_size_t(size_t * var
)
3065 free_ssize_t(ssize_t
* var
)
3071 free_b_int64_t(int64_t * var
)
3076 #define free_b_size_t free_size_t
3077 #define free_b_ssize_t free_ssize_t
3078 #define free_kb_size_t free_size_t
3079 #define free_mb_size_t free_size_t
3080 #define free_gb_size_t free_size_t
3081 #define free_kb_int64_t free_b_int64_t
3084 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3086 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3090 free_u_short(unsigned short * u
)
3096 parse_u_short(unsigned short * var
)
3098 ConfigParser::ParseUShort(var
);
3102 ConfigParser::ParseUShort(unsigned short *var
)
3108 ConfigParser::ParseBool(bool *var
)
3110 int i
= GetInteger();
3121 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3123 while (list
!= nullptr) {
3124 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3130 ConfigParser::ParseWordList(wordlist
** list
)
3132 parse_wordlist(list
);
3136 parse_wordlist(wordlist
** list
)
3139 while ((token
= ConfigParser::NextQuotedToken()))
3140 wordlistAdd(list
, token
);
3144 check_null_acl_access(acl_access
* a
)
3146 return a
== nullptr;
3149 #define free_wordlist wordlistDestroy
3151 #define free_uri_whitespace free_int
3154 parse_uri_whitespace(int *var
)
3156 char *token
= ConfigParser::NextToken();
3162 if (!strcmp(token
, "strip"))
3163 *var
= URI_WHITESPACE_STRIP
;
3164 else if (!strcmp(token
, "deny"))
3165 *var
= URI_WHITESPACE_DENY
;
3166 else if (!strcmp(token
, "allow"))
3167 *var
= URI_WHITESPACE_ALLOW
;
3168 else if (!strcmp(token
, "encode"))
3169 *var
= URI_WHITESPACE_ENCODE
;
3170 else if (!strcmp(token
, "chop"))
3171 *var
= URI_WHITESPACE_CHOP
;
3173 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3179 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3183 if (var
== URI_WHITESPACE_ALLOW
)
3185 else if (var
== URI_WHITESPACE_ENCODE
)
3187 else if (var
== URI_WHITESPACE_CHOP
)
3189 else if (var
== URI_WHITESPACE_DENY
)
3194 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3198 free_removalpolicy(RemovalPolicySettings
** settings
)
3203 free_string(&(*settings
)->type
);
3205 free_wordlist(&(*settings
)->args
);
3209 *settings
= nullptr;
3213 parse_removalpolicy(RemovalPolicySettings
** settings
)
3216 free_removalpolicy(settings
);
3218 *settings
= new RemovalPolicySettings
;
3220 parse_string(&(*settings
)->type
);
3222 parse_wordlist(&(*settings
)->args
);
3226 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3229 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3230 args
= settings
->args
;
3233 storeAppendPrintf(entry
, " %s", args
->key
);
3237 storeAppendPrintf(entry
, "\n");
3241 free_YesNoNone(YesNoNone
*)
3245 parse_YesNoNone(YesNoNone
*option
)
3248 parse_onoff(&value
);
3249 option
->configure(value
> 0);
3253 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3255 if (option
.configured())
3256 dump_onoff(entry
, name
, option
? 1 : 0);
3260 free_memcachemode(SquidConfig
*)
3264 parse_memcachemode(SquidConfig
*)
3266 char *token
= ConfigParser::NextToken();
3272 if (strcmp(token
, "always") == 0) {
3273 Config
.onoff
.memory_cache_first
= 1;
3274 Config
.onoff
.memory_cache_disk
= 1;
3275 } else if (strcmp(token
, "disk") == 0) {
3276 Config
.onoff
.memory_cache_first
= 0;
3277 Config
.onoff
.memory_cache_disk
= 1;
3278 } else if (strncmp(token
, "net", 3) == 0) {
3279 Config
.onoff
.memory_cache_first
= 1;
3280 Config
.onoff
.memory_cache_disk
= 0;
3281 } else if (strcmp(token
, "never") == 0) {
3282 Config
.onoff
.memory_cache_first
= 0;
3283 Config
.onoff
.memory_cache_disk
= 0;
3285 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3291 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&)
3293 storeAppendPrintf(entry
, "%s ", name
);
3294 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3295 storeAppendPrintf(entry
, "always");
3296 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3297 storeAppendPrintf(entry
, "disk");
3298 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3299 storeAppendPrintf(entry
, "network");
3300 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3301 storeAppendPrintf(entry
, "none");
3302 storeAppendPrintf(entry
, "\n");
3305 #include "cf_parser.cci"
3308 parseNeighborType(const char *s
)
3310 if (!strcmp(s
, "parent"))
3313 if (!strcmp(s
, "neighbor"))
3314 return PEER_SIBLING
;
3316 if (!strcmp(s
, "neighbour"))
3317 return PEER_SIBLING
;
3319 if (!strcmp(s
, "sibling"))
3320 return PEER_SIBLING
;
3322 if (!strcmp(s
, "multicast"))
3323 return PEER_MULTICAST
;
3325 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3327 return PEER_SIBLING
;
3332 parse_IpAddress_list(Ip::Address_list
** head
)
3335 Ip::Address_list
*s
;
3338 while ((token
= ConfigParser::NextToken())) {
3339 if (GetHostWithPort(token
, &ipa
)) {
3342 head
= &(*head
)->next
;
3344 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3356 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3358 char ntoabuf
[MAX_IPSTRLEN
];
3361 storeAppendPrintf(e
, "%s %s\n",
3363 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3369 free_IpAddress_list(Ip::Address_list
** head
)
3371 if (*head
) delete *head
;
3375 #if CURRENTLY_UNUSED
3376 /* This code was previously used by http_port. Left as it really should
3377 * be used by icp_port and htcp_port
3380 check_null_IpAddress_list(const Ip::Address_list
* s
)
3385 #endif /* CURRENTLY_UNUSED */
3386 #endif /* USE_WCCPv2 */
3389 parsePortSpecification(const AnyP::PortCfgPointer
&s
, char *token
)
3391 char *host
= nullptr;
3392 unsigned short port
= 0;
3394 char *junk
= nullptr;
3396 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3397 s
->name
= xstrdup(token
);
3398 s
->connection_auth_disabled
= false;
3400 const SBuf
&portType
= AnyP::UriScheme(s
->transport
.protocol
).image();
3402 if (*token
== '[') {
3405 t
= strchr(host
, ']');
3407 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3414 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3418 if (!Ip::EnableIpv6
) {
3419 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3423 port
= xatos(t
+ 1);
3424 } else if ((t
= strchr(token
, ':'))) {
3429 port
= xatos(t
+ 1);
3431 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3432 port
= xatos(token
);
3433 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3435 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3440 if (port
== 0 && host
!= nullptr) {
3441 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3446 if (nullptr == host
) {
3449 if (!Ip::EnableIpv6
)
3451 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3452 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3454 if (!Ip::EnableIpv6
)
3456 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3457 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3458 /* do not use ipcache */
3459 s
->defaultsite
= xstrdup(host
);
3461 if (!Ip::EnableIpv6
)
3463 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3465 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3470 /// parses the protocol= option of the *_port directive, returning parsed value
3471 /// unsupported option values result in a fatal error message
3472 /// upper case values required; caller may convert for backward compatibility
3473 static AnyP::ProtocolVersion
3474 parsePortProtocol(const SBuf
&value
)
3476 // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3477 // and RFC 2616 requires us to upgrade 1.0 to 1.1
3478 if (value
.cmp("HTTP") == 0 || value
.cmp("HTTP/1.1") == 0)
3479 return Http::ProtocolVersion(1,1);
3481 if (value
.cmp("HTTPS") == 0 || value
.cmp("HTTPS/1.1") == 0)
3482 return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS
, 1,1);
3484 if (value
.cmp("FTP") == 0)
3485 return Ftp::ProtocolVersion();
3487 fatalf("%s directive does not support protocol=" SQUIDSBUFPH
"\n", cfg_directive
, SQUIDSBUFPRINT(value
));
3488 return AnyP::ProtocolVersion(); // not reached
3492 parse_port_option(AnyP::PortCfgPointer
&s
, char *token
)
3496 if (strcmp(token
, "accel") == 0) {
3497 if (s
->flags
.isIntercepted()) {
3498 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3502 s
->flags
.accelSurrogate
= true;
3504 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3505 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3506 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3510 s
->flags
.natIntercept
= true;
3511 Ip::Interceptor
.StartInterception();
3512 /* Log information regarding the port modes under interception. */
3513 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3514 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3515 } else if (strcmp(token
, "tproxy") == 0) {
3516 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3517 debugs(3,DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3521 s
->flags
.tproxyIntercept
= true;
3522 Ip::Interceptor
.StartTransparency();
3523 /* Log information regarding the port modes under transparency. */
3524 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3526 if (s
->flags
.proxySurrogate
) {
3527 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3530 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3531 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY support in the system does not work.");
3536 } else if (strcmp(token
, "require-proxy-header") == 0) {
3537 s
->flags
.proxySurrogate
= true;
3538 if (s
->flags
.tproxyIntercept
) {
3539 // receiving is still permitted, so we do not unset the TPROXY flag
3540 // spoofing access control override takes care of the spoof disable later
3541 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3544 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3545 if (!s
->flags
.accelSurrogate
) {
3546 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": defaultsite option requires Acceleration mode flag.");
3550 safe_free(s
->defaultsite
);
3551 s
->defaultsite
= xstrdup(token
+ 12);
3552 } else if (strcmp(token
, "vhost") == 0) {
3553 if (!s
->flags
.accelSurrogate
) {
3554 debugs(3, DBG_CRITICAL
, "WARNING: " << cfg_directive
<< ": vhost option is deprecated. Use 'accel' mode flag instead.");
3556 s
->flags
.accelSurrogate
= true;
3558 } else if (strcmp(token
, "no-vhost") == 0) {
3559 if (!s
->flags
.accelSurrogate
) {
3560 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": no-vhost option requires Acceleration mode flag.");
3563 } else if (strcmp(token
, "vport") == 0) {
3564 if (!s
->flags
.accelSurrogate
) {
3565 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3570 } else if (strncmp(token
, "vport=", 6) == 0) {
3571 if (!s
->flags
.accelSurrogate
) {
3572 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3576 s
->vport
= xatos(token
+ 6);
3577 } else if (strncmp(token
, "protocol=", 9) == 0) {
3578 if (!s
->flags
.accelSurrogate
) {
3579 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": protocol option requires Acceleration mode flag.");
3583 s
->transport
= parsePortProtocol(ToUpper(SBuf(token
+ 9)));
3584 } else if (strcmp(token
, "allow-direct") == 0) {
3585 if (!s
->flags
.accelSurrogate
) {
3586 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": allow-direct option requires Acceleration mode flag.");
3590 s
->allow_direct
= true;
3591 } else if (strcmp(token
, "act-as-origin") == 0) {
3592 if (!s
->flags
.accelSurrogate
) {
3593 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": act-as-origin option requires Acceleration mode flag.");
3595 s
->actAsOrigin
= true;
3596 } else if (strcmp(token
, "ignore-cc") == 0) {
3597 #if !USE_HTTP_VIOLATIONS
3598 if (!s
->flags
.accelSurrogate
) {
3599 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": ignore-cc option requires Acceleration mode flag.");
3604 s
->ignore_cc
= true;
3605 } else if (strncmp(token
, "name=", 5) == 0) {
3607 s
->name
= xstrdup(token
+ 5);
3608 } else if (strcmp(token
, "no-connection-auth") == 0) {
3609 s
->connection_auth_disabled
= true;
3610 } else if (strcmp(token
, "connection-auth=off") == 0) {
3611 s
->connection_auth_disabled
= true;
3612 } else if (strcmp(token
, "connection-auth") == 0) {
3613 s
->connection_auth_disabled
= false;
3614 } else if (strcmp(token
, "connection-auth=on") == 0) {
3615 s
->connection_auth_disabled
= false;
3616 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3617 if (!strcmp(token
+ 23, "off"))
3618 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3619 else if (!strcmp(token
+ 23, "transparent"))
3620 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3621 else if (!strcmp(token
+ 23, "always"))
3622 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3627 } else if (strcmp(token
, "ipv4") == 0) {
3628 if ( !s
->s
.setIPv4() ) {
3629 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3633 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3634 s
->tcp_keepalive
.enabled
= true;
3635 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3636 char *t
= token
+ 13;
3637 s
->tcp_keepalive
.enabled
= true;
3638 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3642 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3647 s
->tcp_keepalive
.timeout
= xatoui(t
);
3650 } else if (strcmp(token
, "sslBump") == 0) {
3651 debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token
<< "' is deprecated " <<
3652 "in " << cfg_directive
<< ". Use 'ssl-bump' instead.");
3653 s
->flags
.tunnelSslBumping
= true;
3654 } else if (strcmp(token
, "ssl-bump") == 0) {
3655 s
->flags
.tunnelSslBumping
= true;
3656 } else if (strncmp(token
, "cert=", 5) == 0) {
3657 s
->secure
.parse(token
);
3658 } else if (strncmp(token
, "key=", 4) == 0) {
3659 s
->secure
.parse(token
);
3660 } else if (strncmp(token
, "version=", 8) == 0) {
3661 debugs(3, DBG_PARSE_NOTE(1), "WARNING: UPGRADE: '" << token
<< "' is deprecated " <<
3662 "in " << cfg_directive
<< ". Use 'options=' instead.");
3663 s
->secure
.parse(token
);
3664 } else if (strncmp(token
, "options=", 8) == 0) {
3665 s
->secure
.parse(token
);
3666 } else if (strncmp(token
, "cipher=", 7) == 0) {
3667 s
->secure
.parse(token
);
3668 } else if (strncmp(token
, "clientca=", 9) == 0) {
3669 s
->secure
.parse(token
);
3670 } else if (strncmp(token
, "cafile=", 7) == 0) {
3671 debugs(3, DBG_PARSE_NOTE(1), "WARNING: UPGRADE: '" << token
<< "' is deprecated " <<
3672 "in " << cfg_directive
<< ". Use 'tls-cafile=' instead.");
3673 s
->secure
.parse(token
);
3674 } else if (strncmp(token
, "capath=", 7) == 0) {
3675 s
->secure
.parse(token
);
3676 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3677 s
->secure
.parse(token
);
3678 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3679 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: '" << token
<< "' is deprecated " <<
3680 "in " << cfg_directive
<< ". Use 'tls-dh=' instead.");
3681 s
->secure
.parse(token
);
3682 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3683 // NP: deprecation warnings output by secure.parse() when relevant
3684 s
->secure
.parse(token
+3);
3685 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3686 // NP: deprecation warnings output by secure.parse() when relevant
3687 s
->secure
.parse(token
+3);
3688 } else if (strncmp(token
, "generate-host-certificates", 26) == 0) {
3689 s
->secure
.parse(token
);
3691 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3692 s
->secure
.parse(token
);
3693 } else if (strncmp(token
, "tls-", 4) == 0) {
3694 s
->secure
.parse(token
+4);
3695 } else if (strcmp(token
, "ftp-track-dirs") == 0) {
3696 s
->ftp_track_dirs
= true;
3697 } else if (strcmp(token
, "worker-queues") == 0) {
3698 #if !defined(SO_REUSEADDR)
3699 #error missing system #include that #defines SO_* constants
3701 #if !defined(SO_REUSEPORT)
3702 throw TexcHere(ToSBuf(cfg_directive
, ' ', token
, " option requires building Squid where SO_REUSEPORT is supported by the TCP stack"));
3704 s
->workerQueues
= true;
3706 debugs(3, DBG_CRITICAL
, "FATAL: Unknown " << cfg_directive
<< " option '" << token
<< "'.");
3712 add_http_port(char *portspec
)
3714 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3715 s
->transport
= parsePortProtocol(SBuf("HTTP"));
3716 parsePortSpecification(s
, portspec
);
3717 // we may need to merge better if the above returns a list with clones
3718 assert(s
->next
== nullptr);
3719 s
->next
= HttpPortList
;
3724 parsePortCfg(AnyP::PortCfgPointer
*head
, const char *optionName
)
3727 if (strcmp(optionName
, "http_port") == 0 ||
3728 strcmp(optionName
, "ascii_port") == 0)
3730 else if (strcmp(optionName
, "https_port") == 0)
3731 protoName
= "HTTPS";
3732 else if (strcmp(optionName
, "ftp_port") == 0)
3734 if (protoName
.isEmpty()) {
3739 char *token
= ConfigParser::NextToken();
3746 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3747 s
->transport
= parsePortProtocol(protoName
); // default; protocol=... overwrites
3748 parsePortSpecification(s
, token
);
3750 /* parse options ... */
3751 while ((token
= ConfigParser::NextToken())) {
3752 parse_port_option(s
, token
);
3755 s
->secure
.syncCaFiles();
3757 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3758 s
->secure
.encryptTransport
= true;
3760 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3761 const bool hijacked
= s
->flags
.isIntercepted();
3762 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3763 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3767 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3768 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3773 if (s
->flags
.proxySurrogate
) {
3774 debugs(3,DBG_CRITICAL
, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3778 } else if (protoName
.cmp("FTP") == 0) {
3779 /* ftp_port does not support ssl-bump */
3780 if (s
->flags
.tunnelSslBumping
) {
3781 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump is not supported for ftp_port.");
3785 if (s
->flags
.proxySurrogate
) {
3786 // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3787 debugs(3,DBG_CRITICAL
, "FATAL: require-proxy-header option is not supported on ftp_port.");
3793 if (s
->secure
.encryptTransport
) {
3794 if (s
->secure
.certs
.empty()) {
3795 debugs(3, DBG_CRITICAL
, "FATAL: " << AnyP::UriScheme(s
->transport
.protocol
) << "_port requires a cert= parameter");
3799 s
->secure
.parseOptions();
3802 // *_port line should now be fully valid so we can clone it if necessary
3803 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3804 s
->next
= s
->ipV4clone();
3807 while (*head
!= nullptr)
3808 head
= &((*head
)->next
);
3814 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3816 char buf
[MAX_IPSTRLEN
];
3818 storeAppendPrintf(e
, "%s %s",
3820 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3822 // MODES and specific sub-options.
3823 if (s
->flags
.natIntercept
)
3824 storeAppendPrintf(e
, " intercept");
3826 else if (s
->flags
.tproxyIntercept
)
3827 storeAppendPrintf(e
, " tproxy");
3829 else if (s
->flags
.proxySurrogate
)
3830 storeAppendPrintf(e
, " require-proxy-header");
3832 else if (s
->flags
.accelSurrogate
) {
3833 storeAppendPrintf(e
, " accel");
3836 storeAppendPrintf(e
, " vhost");
3839 storeAppendPrintf(e
, " vport");
3840 else if (s
->vport
> 0)
3841 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3844 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3846 // TODO: compare against prefix of 'n' instead of assuming http_port
3847 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3848 storeAppendPrintf(e
, " protocol=%s", AnyP::ProtocolType_str
[s
->transport
.protocol
]);
3850 if (s
->allow_direct
)
3851 storeAppendPrintf(e
, " allow-direct");
3854 storeAppendPrintf(e
, " ignore-cc");
3858 // Generic independent options
3861 storeAppendPrintf(e
, " name=%s", s
->name
);
3863 #if USE_HTTP_VIOLATIONS
3864 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3865 storeAppendPrintf(e
, " ignore-cc");
3868 if (s
->connection_auth_disabled
)
3869 storeAppendPrintf(e
, " connection-auth=off");
3871 storeAppendPrintf(e
, " connection-auth=on");
3873 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3876 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3879 pmtu
= "transparent";
3881 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3884 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3885 storeAppendPrintf(e
, " ipv4");
3887 if (s
->tcp_keepalive
.enabled
) {
3888 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3889 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3891 storeAppendPrintf(e
, " tcpkeepalive");
3896 if (s
->flags
.tunnelSslBumping
)
3897 storeAppendPrintf(e
, " ssl-bump");
3900 s
->secure
.dumpCfg(e
, "tls-");
3904 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3906 for (AnyP::PortCfgPointer p
= s
; p
!= nullptr; p
= p
->next
) {
3907 dump_generic_port(e
, n
, p
);
3908 storeAppendPrintf(e
, "\n");
3913 configFreeMemory(void)
3916 Dns::ResolveClientAddressesAsap
= false;
3917 Config
.ssl_client
.sslContext
.reset();
3919 Ssl::unloadSquidUntrusted();
3924 requirePathnameExists(const char *name
, const char *path
)
3928 char pathbuf
[BUFSIZ
];
3929 assert(path
!= nullptr);
3931 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3932 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3936 if (stat(path
, &sb
) < 0) {
3938 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL: ":"ERROR: ") << name
<< " " << path
<< ": " << xstrerr(xerrno
));
3939 // keep going to find more issues if we are only checking the config file with "-k parse"
3940 if (opt_parse_cfg_only
)
3942 // this is fatal if it is found during startup or reconfigure
3943 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3944 fatalf("%s %s: %s", name
, path
, xstrerr(xerrno
));
3948 #include "AccessLogEntry.h"
3951 * We support several access_log configuration styles:
3953 * #1: Deprecated ancient style without an explicit logging module:
3954 * access_log /var/log/access.log
3956 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
3957 * access_log none [acl ...]
3959 * #3: Configurable logging module without named options:
3960 * Logformat or the first ACL name, whichever comes first, may not contain '='.
3961 * If no explicit logformat name is given, the first ACL name, if any,
3962 * should not be an existing logformat name or it will be treated as such.
3963 * access_log module:place [logformat_name] [acl ...]
3965 * #4: Configurable logging module with name=value options such as logformat=x:
3966 * The first ACL name may not contain '='.
3967 * Without any optional parts, directives using this style are indistinguishable
3968 * from directives using style #1 until we start requiring the "module:" prefix.
3969 * access_log module:place [option ...] [acl ...]
3973 parse_access_log(CustomLog
** logs
)
3975 const char *filename
= ConfigParser::NextToken();
3981 const auto cl
= new CustomLog();
3983 cl
->filename
= xstrdup(filename
);
3985 if (strcmp(filename
, "none") == 0) {
3986 cl
->type
= Log::Format::CLF_NONE
;
3987 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
3989 logs
= &(*logs
)->next
;
3994 const char *token
= ConfigParser::PeekAtToken();
3995 if (token
&& !strchr(token
, '=')) { // style #3
3996 // TODO: Deprecate this style to avoid this dangerous guessing.
3997 if (Log::TheConfig
.knownFormat(token
)) {
3998 cl
->setLogformat(token
);
3999 (void)ConfigParser::NextToken(); // consume the token used above
4001 // assume there is no explicit logformat name and use the default
4002 cl
->setLogformat("squid");
4004 } else { // style #1 or style #4
4005 // TODO: Drop deprecated style #1 support. We already warn about it, and
4006 // its exceptional treatment makes detecting "module" typos impractical!
4007 cl
->parseOptions(LegacyParser
, "squid");
4009 assert(cl
->type
); // setLogformat() was called
4011 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4014 logs
= &(*logs
)->next
;
4020 check_null_access_log(CustomLog
*customlog_definitions
)
4022 return customlog_definitions
== nullptr;
4026 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4029 for (auto log
= logs
; log
; log
= log
->next
) {
4031 PackableStream
os(*entry
);
4032 os
<< name
; // directive name
4033 os
<< ' ' << log
->filename
; // including "none"
4034 log
->dumpOptions(os
);
4038 dump_acl_list(entry
, log
->aclList
);
4040 storeAppendPrintf(entry
, "\n");
4045 free_access_log(CustomLog
** definitions
)
4047 while (*definitions
) {
4048 CustomLog
*log
= *definitions
;
4049 *definitions
= log
->next
;
4054 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4055 /// parses list of integers form name=N1,N2,N3,...
4057 parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
)
4059 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4060 data
+= name
.size();
4065 if (!StringToInt(data
, value
, &data
, 10))
4067 list
.push_back(value
);
4068 if (*data
== '\0' || *data
!= ',')
4073 return data
&& *data
== '\0';
4078 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4080 #if !HAVE_CPU_AFFINITY
4081 (void)cpuAffinityMap
;
4082 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4083 "support, do not set 'cpu_affinity_map'");
4086 #else /* HAVE_CPU_AFFINITY */
4087 if (!*cpuAffinityMap
)
4088 *cpuAffinityMap
= new CpuAffinityMap
;
4090 const char *const pToken
= ConfigParser::NextToken();
4091 const char *const cToken
= ConfigParser::NextToken();
4092 std::vector
<int> processes
, cores
;
4093 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4094 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4095 "in 'cpu_affinity_map'");
4097 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4098 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4099 "'cpu_affinity_map'");
4101 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4102 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4103 "process_numbers and cores lists differ in length or " <<
4104 "contain numbers <= 0");
4111 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4113 if (cpuAffinityMap
) {
4114 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4115 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4116 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4117 cpuAffinityMap
->processes()[i
]);
4119 storeAppendPrintf(entry
, " cores=");
4120 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4121 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4122 cpuAffinityMap
->cores()[i
]);
4124 storeAppendPrintf(entry
, "\n");
4129 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4131 delete *cpuAffinityMap
;
4132 *cpuAffinityMap
= nullptr;
4138 parse_adaptation_service_set_type()
4140 Adaptation::Config::ParseServiceSet();
4144 parse_adaptation_service_chain_type()
4146 Adaptation::Config::ParseServiceChain();
4150 parse_adaptation_access_type()
4152 Adaptation::Config::ParseAccess(LegacyParser
);
4154 #endif /* USE_ADAPTATION */
4159 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4161 cfg
->parseService();
4165 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4171 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4173 cfg
.dumpService(entry
, name
);
4177 parse_icap_class_type()
4179 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is deprecated. " <<
4180 "Use 'adaptation_service_set' instead");
4181 Adaptation::Config::ParseServiceSet();
4185 parse_icap_access_type()
4187 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is deprecated. " <<
4188 "Use 'adaptation_access' instead");
4189 Adaptation::Config::ParseAccess(LegacyParser
);
4197 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4199 cfg
->parseService();
4203 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4209 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4211 cfg
.dumpService(entry
, name
);
4214 #endif /* USE_ECAP */
4217 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4220 cfg
->service_failure_limit
= GetInteger();
4222 if ((token
= ConfigParser::NextToken()) == nullptr)
4225 if (strcmp(token
,"in") != 0) {
4226 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4231 parse_time_t(&cfg
->oldest_service_failure
);
4234 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4236 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4237 if (cfg
.oldest_service_failure
> 0) {
4238 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4240 storeAppendPrintf(entry
, "\n");
4243 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4245 cfg
->oldest_service_failure
= 0;
4246 cfg
->service_failure_limit
= 0;
4251 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4253 auto *al
= ConfigParser::NextToken();
4260 if ( char *s
= strchr(al
, '{')) {
4261 *s
= '\0'; // terminate the al string
4273 std::unique_ptr
<sslproxy_cert_adapt
> ca(new sslproxy_cert_adapt
);
4274 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4275 ca
->alg
= Ssl::algSetValidAfter
;
4276 ca
->param
= xstrdup("on");
4277 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4278 ca
->alg
= Ssl::algSetValidBefore
;
4279 ca
->param
= xstrdup("on");
4280 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4281 ca
->alg
= Ssl::algSetCommonName
;
4283 if (strlen(param
) > 64) {
4284 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4288 ca
->param
= xstrdup(param
);
4291 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4296 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4299 cert_adapt
= &(*cert_adapt
)->next
;
4301 *cert_adapt
= ca
.release();
4304 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4306 for (const auto *ca
= cert_adapt
; ca
; ca
= ca
->next
) {
4307 storeAppendPrintf(entry
, "%s ", name
);
4308 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4310 dump_acl_list(entry
, ca
->aclList
);
4311 storeAppendPrintf(entry
, "\n");
4315 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4318 *cert_adapt
= nullptr;
4321 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4323 const auto al
= ConfigParser::NextToken();
4329 std::unique_ptr
<sslproxy_cert_sign
> cs(new sslproxy_cert_sign
);
4330 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4331 cs
->alg
= Ssl::algSignTrusted
;
4332 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4333 cs
->alg
= Ssl::algSignUntrusted
;
4334 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4335 cs
->alg
= Ssl::algSignSelf
;
4337 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4342 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4345 cert_sign
= &(*cert_sign
)->next
;
4347 *cert_sign
= cs
.release();
4350 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4352 for (const auto *cs
= cert_sign
; cs
; cs
= cs
->next
) {
4353 storeAppendPrintf(entry
, "%s ", name
);
4354 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4356 dump_acl_list(entry
, cs
->aclList
);
4357 storeAppendPrintf(entry
, "\n");
4361 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4364 *cert_sign
= nullptr;
4367 class sslBumpCfgRr
: public ::RegisteredRunner
4370 static Ssl::BumpMode lastDeprecatedRule
;
4371 /* RegisteredRunner API */
4372 void finalizeConfig() override
;
4375 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4377 RunnerRegistrationEntry(sslBumpCfgRr
);
4380 sslBumpCfgRr::finalizeConfig()
4382 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4383 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4384 static char buf
[1024];
4385 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4386 strcpy(buf
, "ssl_bump deny all");
4387 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4388 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4389 "must not use implicit rules. Update your ssl_bump rules.");
4391 strcpy(buf
, "ssl_bump allow all");
4392 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4393 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4394 "inferior to the newer server-first bumping mode. New ssl_bump"
4395 " configurations must not use implicit rules. Update your ssl_bump rules.");
4401 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4403 typedef const char *BumpCfgStyle
;
4404 BumpCfgStyle bcsNone
= nullptr;
4405 BumpCfgStyle bcsNew
= "new client/server-first/none";
4406 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4407 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4408 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4410 if ((bm
= ConfigParser::NextToken()) == nullptr) {
4415 // if this is the first rule processed
4416 if (*ssl_bump
== nullptr) {
4417 bumpCfgStyleLast
= bcsNone
;
4418 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4421 auto action
= Acl::Answer(ACCESS_ALLOWED
);
4423 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4424 action
.kind
= Ssl::bumpClientFirst
;
4425 bumpCfgStyleNow
= bcsNew
;
4426 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4427 action
.kind
= Ssl::bumpServerFirst
;
4428 bumpCfgStyleNow
= bcsNew
;
4429 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpPeek
]) == 0) {
4430 action
.kind
= Ssl::bumpPeek
;
4431 bumpCfgStyleNow
= bcsNew
;
4432 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpStare
]) == 0) {
4433 action
.kind
= Ssl::bumpStare
;
4434 bumpCfgStyleNow
= bcsNew
;
4435 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpSplice
]) == 0) {
4436 action
.kind
= Ssl::bumpSplice
;
4437 bumpCfgStyleNow
= bcsNew
;
4438 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpBump
]) == 0) {
4439 action
.kind
= Ssl::bumpBump
;
4440 bumpCfgStyleNow
= bcsNew
;
4441 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpTerminate
]) == 0) {
4442 action
.kind
= Ssl::bumpTerminate
;
4443 bumpCfgStyleNow
= bcsNew
;
4444 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4445 action
.kind
= Ssl::bumpNone
;
4446 bumpCfgStyleNow
= bcsNew
;
4447 } else if (strcmp(bm
, "allow") == 0) {
4448 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4449 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4450 "is usually inferior to the newer server-first "
4451 "bumping mode. Update your ssl_bump rules.");
4452 action
.kind
= Ssl::bumpClientFirst
;
4453 bumpCfgStyleNow
= bcsOld
;
4454 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4455 } else if (strcmp(bm
, "deny") == 0) {
4456 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4457 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4458 "your ssl_bump rules.");
4459 action
.kind
= Ssl::bumpNone
;
4460 bumpCfgStyleNow
= bcsOld
;
4461 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4463 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4468 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4469 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4470 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4475 bumpCfgStyleLast
= bumpCfgStyleNow
;
4478 ParseAclWithAction(ssl_bump
, action
, "ssl_bump");
4481 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4484 dump_SBufList(entry
, ssl_bump
->treeDump(name
, [](const Acl::Answer
&action
) {
4485 return Ssl::BumpModeStr
.at(action
.kind
);
4489 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4491 free_acl_access(ssl_bump
);
4496 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4501 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4502 storeAppendPrintf(entry
, "%s %s %s", name
, hwa
->fieldName
.c_str(), hwa
->fieldValue
.c_str());
4504 dump_acl_list(entry
, hwa
->aclList
);
4505 storeAppendPrintf(entry
, "\n");
4509 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4513 *headers
= new HeaderWithAclList
;
4515 if ((fn
= ConfigParser::NextToken()) == nullptr) {
4521 hwa
.fieldId
= Http::HeaderLookupTable
.lookup(hwa
.fieldName
).id
;
4522 if (hwa
.fieldId
== Http::HdrType::BAD_HDR
)
4523 hwa
.fieldId
= Http::HdrType::OTHER
;
4525 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4526 ConfigParser::EnableMacros();
4527 String buf
= ConfigParser::NextQuotedToken();
4528 ConfigParser::DisableMacros();
4529 hwa
.fieldValue
= buf
.termedBuf();
4530 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4532 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4536 hwa
.valueFormat
= nlf
;
4539 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4540 (*headers
)->push_back(hwa
);
4543 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4548 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4550 aclDestroyAclList(&hwa
->aclList
);
4552 if (hwa
->valueFormat
) {
4553 delete hwa
->valueFormat
;
4554 hwa
->valueFormat
= nullptr;
4561 static void parse_note(Notes
*notes
)
4564 notes
->parse(LegacyParser
);
4567 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4569 notes
.dump(entry
, name
);
4572 static void free_note(Notes
*notes
)
4577 static DebugMessageId
ParseDebugMessageId(const char *value
, const char eov
)
4579 const auto id
= xatoui(value
, eov
);
4580 if (!(0 < id
&& id
< DebugMessageIdUpperBound
))
4581 throw TextException(ToSBuf("unknown cache_log_message ID: ", value
), Here());
4582 return static_cast<DebugMessageId
>(id
);
4585 static void parse_cache_log_message(DebugMessages
**debugMessages
)
4588 DebugMessageId minId
= 0;
4589 DebugMessageId maxId
= 0;
4591 char *key
= nullptr;
4592 char *value
= nullptr;
4593 while (ConfigParser::NextKvPair(key
, value
)) {
4594 if (strcmp(key
, "id") == 0) {
4597 minId
= maxId
= ParseDebugMessageId(value
, '\0');
4598 } else if (strcmp(key
, "ids") == 0) {
4601 const auto dash
= strchr(value
, '-');
4603 throw TextException(ToSBuf("malformed cache_log_message ID range: ", key
, '=', value
), Here());
4604 minId
= ParseDebugMessageId(value
, '-');
4605 maxId
= ParseDebugMessageId(dash
+1, '\0');
4607 throw TextException(ToSBuf("invalid cache_log_message ID range: ", key
, '=', value
), Here());
4608 } else if (strcmp(key
, "level") == 0) {
4611 const auto level
= xatoi(value
);
4613 throw TextException(ToSBuf("negative cache_log_message level: ", value
), Here());
4615 } else if (strcmp(key
, "limit") == 0) {
4618 msg
.limit
= xatoull(value
, 10);
4620 throw TextException(ToSBuf("unsupported cache_log_message option: ", key
), Here());
4622 key
= value
= nullptr;
4626 throw TextException(ToSBuf("repeated or conflicting cache_log_message option: ", key
, '=', value
), Here());
4629 throw TextException("cache_log_message is missing a required id=... or ids=... option", Here());
4631 if (!(msg
.levelled() || msg
.limited()))
4632 throw TextException("cache_log_message is missing a required level=... or limit=... option", Here());
4634 assert(debugMessages
);
4635 if (!*debugMessages
)
4636 *debugMessages
= new DebugMessages();
4638 for (auto id
= minId
; id
<= maxId
; ++id
) {
4640 (*debugMessages
)->messages
.at(id
) = msg
;
4644 static void dump_cache_log_message(StoreEntry
*entry
, const char *name
, const DebugMessages
*debugMessages
)
4650 for (const auto &msg
: debugMessages
->messages
) {
4651 if (!msg
.configured())
4653 out
<< name
<< " id=" << msg
.id
;
4655 out
<< " level=" << msg
.level
;
4657 out
<< " limit=" << msg
.limit
;
4660 const auto buf
= out
.buf();
4661 entry
->append(buf
.rawContent(), buf
.length()); // may be empty
4664 static void free_cache_log_message(DebugMessages
**debugMessages
)
4666 // clear old messages to avoid cumulative effect across (re)configurations
4667 assert(debugMessages
);
4668 delete *debugMessages
;
4669 *debugMessages
= nullptr;
4672 static bool FtpEspvDeprecated
= false;
4673 static void parse_ftp_epsv(acl_access
**ftp_epsv
)
4675 Acl::Answer ftpEpsvDeprecatedAction
;
4676 bool ftpEpsvIsDeprecatedRule
= false;
4678 char *t
= ConfigParser::PeekAtToken();
4684 if (!strcmp(t
, "off")) {
4685 (void)ConfigParser::NextToken();
4686 ftpEpsvIsDeprecatedRule
= true;
4687 ftpEpsvDeprecatedAction
= Acl::Answer(ACCESS_DENIED
);
4688 } else if (!strcmp(t
, "on")) {
4689 (void)ConfigParser::NextToken();
4690 ftpEpsvIsDeprecatedRule
= true;
4691 ftpEpsvDeprecatedAction
= Acl::Answer(ACCESS_ALLOWED
);
4694 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4695 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4696 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4698 if ((!ftpEpsvIsDeprecatedRule
&& FtpEspvDeprecated
) ||
4699 (ftpEpsvIsDeprecatedRule
&& !FtpEspvDeprecated
&& *ftp_epsv
!= nullptr)) {
4700 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.");
4705 if (ftpEpsvIsDeprecatedRule
) {
4706 // overwrite previous ftp_epsv lines
4708 *ftp_epsv
= nullptr;
4710 if (ftpEpsvDeprecatedAction
== Acl::Answer(ACCESS_DENIED
)) {
4711 if (ACL
*a
= ACL::FindByName("all"))
4712 ParseAclWithAction(ftp_epsv
, ftpEpsvDeprecatedAction
, "ftp_epsv", a
);
4718 FtpEspvDeprecated
= true;
4720 aclParseAccessLine(cfg_directive
, LegacyParser
, ftp_epsv
);
4724 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
)
4727 dump_SBufList(entry
, ftp_epsv
->treeDump(name
, Acl::AllowOrDeny
));
4730 static void free_ftp_epsv(acl_access
**ftp_epsv
)
4732 free_acl_access(ftp_epsv
);
4733 FtpEspvDeprecated
= false;
4736 /// Like parseTimeLine() but does not require the timeunit to be specified.
4737 /// If missed, the default 'second' timeunit is assumed.
4738 static std::chrono::seconds
4739 ParseUrlRewriteTimeout()
4741 const auto timeValueToken
= ConfigParser::NextToken();
4742 if (!timeValueToken
)
4743 throw TexcHere("cannot read a time value");
4745 using Seconds
= std::chrono::seconds
;
4747 const auto parsedTimeValue
= xatof(timeValueToken
);
4749 if (parsedTimeValue
== 0)
4750 return std::chrono::seconds::zero();
4752 std::chrono::nanoseconds parsedUnitDuration
;
4754 const auto unitToken
= ConfigParser::PeekAtToken();
4755 if (parseTimeUnit
<Seconds
>(unitToken
, parsedUnitDuration
))
4756 (void)ConfigParser::NextToken();
4758 const auto defaultParsed
= parseTimeUnit
<Seconds
>(T_SECOND_STR
, parsedUnitDuration
);
4759 assert(defaultParsed
);
4760 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), ConfigParser::CurrentLocation() <<
4761 ": WARNING: missing time unit, using deprecated default '" << T_SECOND_STR
<< "'");
4764 const auto nanoseconds
= ToNanoSeconds(parsedTimeValue
, parsedUnitDuration
);
4766 return FromNanoseconds
<Seconds
>(nanoseconds
, parsedTimeValue
);
4770 parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4772 // TODO: do not allow optional timeunit (as the documentation prescribes)
4773 // and use parseTimeLine() instead.
4774 Config
.Timeout
.urlRewrite
= ParseUrlRewriteTimeout().count();
4777 while(ConfigParser::NextKvPair(key
, value
)) {
4778 if (strcasecmp(key
, "on_timeout") == 0) {
4779 if (strcasecmp(value
, "bypass") == 0)
4780 config
->action
= toutActBypass
;
4781 else if (strcasecmp(value
, "fail") == 0)
4782 config
->action
= toutActFail
;
4783 else if (strcasecmp(value
, "retry") == 0)
4784 config
->action
= toutActRetry
;
4785 else if (strcasecmp(value
, "use_configured_response") == 0) {
4786 config
->action
= toutActUseConfiguredResponse
;
4788 debugs(3, DBG_CRITICAL
, "FATAL: unsupported \"on_timeout\" action: " << value
);
4792 } else if (strcasecmp(key
, "response") == 0) {
4793 config
->response
= xstrdup(value
);
4795 debugs(3, DBG_CRITICAL
, "FATAL: unsupported option " << key
);
4801 if (config
->action
== toutActUseConfiguredResponse
&& !config
->response
) {
4802 debugs(3, DBG_CRITICAL
, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4806 if (config
->action
!= toutActUseConfiguredResponse
&& config
->response
) {
4807 debugs(3, DBG_CRITICAL
, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4813 dump_UrlHelperTimeout(StoreEntry
*entry
, const char *name
, SquidConfig::UrlHelperTimeout
&config
)
4815 const char *onTimedOutActions
[] = {"bypass", "fail", "retry", "use_configured_response"};
4816 assert(config
.action
>= 0 && config
.action
<= toutActUseConfiguredResponse
);
4818 dump_time_t(entry
, name
, Config
.Timeout
.urlRewrite
);
4819 storeAppendPrintf(entry
, " on_timeout=%s", onTimedOutActions
[config
.action
]);
4821 if (config
.response
)
4822 storeAppendPrintf(entry
, " response=\"%s\"", config
.response
);
4824 storeAppendPrintf(entry
, "\n");
4828 free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4830 Config
.Timeout
.urlRewrite
= 0;
4832 safe_free(config
->response
);
4836 parse_configuration_includes_quoted_values(bool *)
4841 // If quoted values is set to on then enable new strict mode parsing
4843 ConfigParser::RecognizeQuotedValues
= true;
4844 ConfigParser::StrictMode
= true;
4846 ConfigParser::RecognizeQuotedValues
= false;
4847 ConfigParser::StrictMode
= false;
4852 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool)
4854 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4855 dump_onoff(entry
, name
, val
);
4859 free_configuration_includes_quoted_values(bool *)
4861 ConfigParser::RecognizeQuotedValues
= false;
4862 ConfigParser::StrictMode
= false;
4866 parse_on_unsupported_protocol(acl_access
**access
)
4869 if ((tm
= ConfigParser::NextToken()) == nullptr) {
4874 auto action
= Acl::Answer(ACCESS_ALLOWED
);
4875 if (strcmp(tm
, "tunnel") == 0)
4877 else if (strcmp(tm
, "respond") == 0)
4880 debugs(3, DBG_CRITICAL
, "FATAL: unknown on_unsupported_protocol mode: " << tm
);
4886 ParseAclWithAction(access
, action
, "on_unsupported_protocol");
4890 dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
)
4892 static const std::vector
<const char *> onErrorTunnelMode
= {
4898 SBufList lines
= access
->treeDump(name
, [](const Acl::Answer
&action
) {
4899 return onErrorTunnelMode
.at(action
.kind
);
4901 dump_SBufList(entry
, lines
);
4906 free_on_unsupported_protocol(acl_access
**access
)
4908 free_acl_access(access
);
4912 parse_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuardsPtr
)
4914 assert(protoGuardsPtr
);
4915 auto &protoGuards
= *protoGuardsPtr
;
4917 protoGuards
= new HttpUpgradeProtocolAccess();
4918 protoGuards
->configureGuard(LegacyParser
);
4922 dump_http_upgrade_request_protocols(StoreEntry
*entry
, const char *rawName
, HttpUpgradeProtocolAccess
*protoGuards
)
4927 const SBuf
name(rawName
);
4928 protoGuards
->forEach([entry
,&name
](const SBuf
&proto
, const acl_access
*acls
) {
4930 line
.push_back(name
);
4931 line
.push_back(proto
);
4932 const auto acld
= acls
->treeDump("", &Acl::AllowOrDeny
);
4933 line
.insert(line
.end(), acld
.begin(), acld
.end());
4934 dump_SBufList(entry
, line
);
4939 free_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuardsPtr
)
4941 assert(protoGuardsPtr
);
4942 auto &protoGuards
= *protoGuardsPtr
;
4944 protoGuards
= nullptr;