2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 03 Configuration File Parsing */
13 #include "acl/AclDenyInfoList.h"
14 #include "acl/AclSizeLimit.h"
15 #include "acl/Address.h"
16 #include "acl/Gadgets.h"
17 #include "acl/MethodData.h"
19 #include "anyp/PortCfg.h"
20 #include "anyp/UriScheme.h"
21 #include "auth/Config.h"
22 #include "auth/Scheme.h"
24 #include "base/PackableStream.h"
25 #include "base/RunnersRegistry.h"
27 #include "CachePeer.h"
28 #include "ConfigOption.h"
29 #include "ConfigParser.h"
30 #include "CpuAffinityMap.h"
31 #include "DiskIO/DiskIOModule.h"
32 #include "eui/Config.h"
33 #include "ExternalACL.h"
34 #include "format/Format.h"
35 #include "ftp/Elements.h"
37 #include "HttpHeaderTools.h"
38 #include "HttpUpgradeProtocolAccess.h"
39 #include "icmp/IcmpConfig.h"
40 #include "ident/Config.h"
41 #include "ip/Intercept.h"
42 #include "ip/NfMarkConfig.h"
43 #include "ip/QosConfig.h"
46 #include "log/Config.h"
47 #include "log/CustomLog.h"
49 #include "MessageDelayPools.h"
50 #include "mgr/ActionPasswordList.h"
51 #include "mgr/Registration.h"
52 #include "neighbors.h"
53 #include "NeighborTypeDomainList.h"
56 #include "PeerDigest.h"
57 #include "PeerPoolMgr.h"
59 #include "RefreshPattern.h"
61 #include "sbuf/List.h"
62 #include "sbuf/Stream.h"
63 #include "SquidConfig.h"
64 #include "SquidString.h"
65 #include "ssl/ProxyCerts.h"
67 #include "store/Disks.h"
71 /* wccp2 has its own conditional definitions */
74 #include "adaptation/Config.h"
77 #include "adaptation/icap/Config.h"
80 #include "adaptation/ecap/Config.h"
83 #include "ssl/Config.h"
84 #include "ssl/support.h"
87 #include "esi/Parser.h"
105 #if HAVE_SYS_SOCKET_H
106 #include <sys/socket.h>
109 #include <sys/stat.h>
113 #include "ssl/gadgets.h"
117 static void parse_adaptation_service_set_type();
118 static void parse_adaptation_service_chain_type();
119 static void parse_adaptation_access_type();
123 static void parse_icap_service_type(Adaptation::Icap::Config
*);
124 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
125 static void free_icap_service_type(Adaptation::Icap::Config
*);
126 static void parse_icap_class_type();
127 static void parse_icap_access_type();
129 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
130 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
131 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
135 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
136 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
137 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
140 static peer_t
parseNeighborType(const char *s
);
142 static const char *const T_NANOSECOND_STR
= "nanosecond";
143 static const char *const T_MICROSECOND_STR
= "microsecond";
144 static const char *const T_MILLISECOND_STR
= "millisecond";
145 static const char *const T_SECOND_STR
= "second";
146 static const char *const T_MINUTE_STR
= "minute";
147 static const char *const T_HOUR_STR
= "hour";
148 static const char *const T_DAY_STR
= "day";
149 static const char *const T_WEEK_STR
= "week";
150 static const char *const T_FORTNIGHT_STR
= "fortnight";
151 static const char *const T_MONTH_STR
= "month";
152 static const char *const T_YEAR_STR
= "year";
153 static const char *const T_DECADE_STR
= "decade";
155 static const char *const B_BYTES_STR
= "bytes";
156 static const char *const B_KBYTES_STR
= "KB";
157 static const char *const B_MBYTES_STR
= "MB";
158 static const char *const B_GBYTES_STR
= "GB";
160 static const char *const list_sep
= ", \t\n\r";
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_access_log(CustomLog
** customlog_definitions
);
166 static int check_null_access_log(CustomLog
*customlog_definitions
);
167 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
168 static void free_access_log(CustomLog
** definitions
);
170 static void configDoConfigure(void);
171 static void parse_refreshpattern(RefreshPattern
**);
172 static void parse_u_short(unsigned short * var
);
173 static void parse_string(char **);
174 static void default_all(void);
175 static void defaults_if_none(void);
176 static void defaults_postscriptum(void);
177 static int parse_line(char *);
178 static void parse_obsolete(const char *);
179 static void parseBytesLine(size_t * bptr
, const char *units
);
180 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
181 static size_t parseBytesUnits(const char *unit
);
182 static void free_all(void);
183 void requirePathnameExists(const char *name
, const char *path
);
184 static OBJH dump_config
;
185 #if USE_HTTP_VIOLATIONS
186 static void free_HeaderManglers(HeaderManglers
**pm
);
187 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
188 static void parse_http_header_access(HeaderManglers
**manglers
);
189 #define free_http_header_access free_HeaderManglers
190 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
191 static void parse_http_header_replace(HeaderManglers
**manglers
);
192 #define free_http_header_replace free_HeaderManglers
194 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
195 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
196 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
197 static void parse_note(Notes
*);
198 static void dump_note(StoreEntry
*, const char *, Notes
&);
199 static void free_note(Notes
*);
200 static void parse_denyinfo(AclDenyInfoList
** var
);
201 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
202 static void free_denyinfo(AclDenyInfoList
** var
);
205 static void parse_IpAddress_list(Ip::Address_list
**);
206 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
207 static void free_IpAddress_list(Ip::Address_list
**);
209 static int check_null_IpAddress_list(const Ip::Address_list
*);
210 #endif /* CURRENTLY_UNUSED */
211 #endif /* USE_WCCPv2 */
213 static void parsePortCfg(AnyP::PortCfgPointer
*, const char *protocol
);
214 #define parse_PortCfg(l) parsePortCfg((l), token)
215 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfgPointer
&);
216 #define free_PortCfg(h) *(h)=NULL
219 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
220 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
221 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
222 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
223 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
224 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
225 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
226 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
227 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
228 #endif /* USE_OPENSSL */
230 static void parse_ftp_epsv(acl_access
**ftp_epsv
);
231 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
);
232 static void free_ftp_epsv(acl_access
**ftp_epsv
);
234 static void parse_b_size_t(size_t * var
);
235 static void parse_b_int64_t(int64_t * var
);
237 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
238 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
239 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
241 static void parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
242 static void dump_UrlHelperTimeout(StoreEntry
*, const char *, SquidConfig::UrlHelperTimeout
&);
243 static void free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
245 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
247 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
248 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
249 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
250 static void parse_on_unsupported_protocol(acl_access
**access
);
251 static void dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
);
252 static void free_on_unsupported_protocol(acl_access
**access
);
253 static void ParseAclWithAction(acl_access
**access
, const Acl::Answer
&action
, const char *desc
, ACL
*acl
= nullptr);
254 static void parse_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuards
);
255 static void dump_http_upgrade_request_protocols(StoreEntry
*entry
, const char *name
, HttpUpgradeProtocolAccess
*protoGuards
);
256 static void free_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuards
);
259 * LegacyParser is a parser for legacy code that uses the global
260 * approach. This is static so that it is only exposed to cache_cf.
261 * Other modules needing access to a ConfigParser should have it
262 * provided to them in their parserFOO methods.
264 static ConfigParser LegacyParser
= ConfigParser();
269 LegacyParser
.destruct();
273 SetConfigFilename(char const *file_name
, bool is_pipe
)
276 cfg_filename
= file_name
+ 1;
278 cfg_filename
= file_name
;
282 skip_ws(const char* s
)
291 parseManyConfigFiles(char* files
, int depth
)
294 char* saveptr
= NULL
;
299 memset(&globbuf
, 0, sizeof(globbuf
));
300 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
301 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
303 fatalf("Unable to find configuration file: %s: %s", path
, xstrerr(xerrno
));
306 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
307 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
311 char* file
= strwordtok(files
, &saveptr
);
312 while (file
!= NULL
) {
313 error_count
+= parseOneConfigFile(file
, depth
);
314 file
= strwordtok(NULL
, &saveptr
);
316 #endif /* HAVE_GLOB */
321 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
324 assert(newSubstr
!= NULL
);
326 unsigned newSubstrLen
= strlen(newSubstr
);
327 if (newSubstrLen
> substrLen
)
328 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
330 // move tail part including zero
331 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
332 // copy new substring in place
333 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
339 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
341 assert(line
!= NULL
);
342 assert(macroName
!= NULL
);
343 assert(substStr
!= NULL
);
344 unsigned macroNameLen
= strlen(macroName
);
345 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
346 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
350 ProcessMacros(char*& line
, int& len
)
352 SubstituteMacro(line
, len
, "${service_name}", service_name
.c_str());
353 SubstituteMacro(line
, len
, "${process_name}", TheKidName
.c_str());
354 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
358 trim_trailing_ws(char* str
)
361 unsigned i
= strlen(str
);
362 while ((i
> 0) && xisspace(str
[i
- 1]))
368 FindStatement(const char* line
, const char* statement
)
370 assert(line
!= NULL
);
371 assert(statement
!= NULL
);
373 const char* str
= skip_ws(line
);
374 unsigned len
= strlen(statement
);
375 if (strncmp(str
, statement
, len
) == 0) {
379 else if (xisspace(*str
))
387 StrToInt(const char* str
, long& number
)
392 number
= strtol(str
, &end
, 0);
394 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
398 EvalBoolExpr(const char* expr
)
400 assert(expr
!= NULL
);
401 if (strcmp(expr
, "true") == 0) {
403 } else if (strcmp(expr
, "false") == 0) {
405 } else if (const char* equation
= strchr(expr
, '=')) {
406 const char* rvalue
= skip_ws(equation
+ 1);
407 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
408 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
409 trim_trailing_ws(lvalue
);
412 if (!StrToInt(lvalue
, number1
))
413 fatalf("String is not a integer number: '%s'\n", lvalue
);
415 if (!StrToInt(rvalue
, number2
))
416 fatalf("String is not a integer number: '%s'\n", rvalue
);
419 return number1
== number2
;
421 fatalf("Unable to evaluate expression '%s'\n", expr
);
422 return false; // this place cannot be reached
426 parseOneConfigFile(const char *file_name
, unsigned int depth
)
429 const char *orig_cfg_filename
= cfg_filename
;
430 const int orig_config_lineno
= config_lineno
;
432 char *tmp_line
= NULL
;
433 int tmp_line_len
= 0;
437 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
439 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
443 if (file_name
[0] == '!' || file_name
[0] == '|') {
444 fp
= popen(file_name
+ 1, "r");
447 fp
= fopen(file_name
, "r");
452 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerr(xerrno
));
456 setmode(fileno(fp
), O_TEXT
);
459 SetConfigFilename(file_name
, bool(is_pipe
));
461 memset(config_input_line
, '\0', BUFSIZ
);
465 std::vector
<bool> if_states
;
466 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
469 if ((token
= strchr(config_input_line
, '\n')))
472 if ((token
= strchr(config_input_line
, '\r')))
475 // strip any prefix whitespace off the line.
476 const char *p
= skip_ws(config_input_line
);
477 if (config_input_line
!= p
)
478 memmove(config_input_line
, p
, strlen(p
)+1);
480 if (strncmp(config_input_line
, "#line ", 6) == 0) {
481 static char new_file_name
[1024];
483 static char new_lineno
;
484 token
= config_input_line
+ 6;
485 new_lineno
= strtol(token
, &file
, 0) - 1;
488 continue; /* Not a valid #line directive, may be a comment */
490 while (*file
&& xisspace((unsigned char) *file
))
495 continue; /* Not a valid #line directive, may be a comment */
497 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
499 if ((token
= strchr(new_file_name
, '"')))
502 SetConfigFilename(new_file_name
, false);
505 config_lineno
= new_lineno
;
508 if (config_input_line
[0] == '#')
511 if (config_input_line
[0] == '\0')
514 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
516 size_t append_len
= strlen(append
);
518 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
520 strcpy(tmp_line
+ tmp_line_len
, append
);
522 tmp_line_len
+= append_len
;
524 if (tmp_line
[tmp_line_len
-1] == '\\') {
525 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
526 tmp_line
[--tmp_line_len
] = '\0';
530 trim_trailing_ws(tmp_line
);
531 ProcessMacros(tmp_line
, tmp_line_len
);
532 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
534 if (const char* expr
= FindStatement(tmp_line
, "if")) {
535 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
536 } else if (FindStatement(tmp_line
, "endif")) {
537 if (!if_states
.empty())
538 if_states
.pop_back(); // remove last if-statement meaning
540 fatalf("'endif' without 'if'\n");
541 } else if (FindStatement(tmp_line
, "else")) {
542 if (!if_states
.empty())
543 if_states
.back() = !if_states
.back();
545 fatalf("'else' without 'if'\n");
546 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
547 /* Handle includes here */
548 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
549 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
552 if (!parse_line(tmp_line
)) {
553 debugs(3, DBG_CRITICAL
, ConfigParser::CurrentLocation() << ": unrecognized: '" << tmp_line
<< "'");
558 debugs(3, DBG_CRITICAL
, "configuration error: " << CurrentException
);
568 if (!if_states
.empty())
569 fatalf("if-statement without 'endif'\n");
572 int ret
= pclose(fp
);
575 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
580 SetConfigFilename(orig_cfg_filename
, false);
581 config_lineno
= orig_config_lineno
;
589 parseConfigFileOrThrow(const char *file_name
)
597 ACLMethodData::ThePurgeCount
= 0;
600 err_count
= parseOneConfigFile(file_name
, 0);
604 defaults_postscriptum();
607 * We must call configDoConfigure() before leave_suid() because
608 * configDoConfigure() is where we turn username strings into
613 if (opt_send_signal
== -1) {
614 Mgr::RegisterAction("config",
615 "Current Squid Configuration",
623 // TODO: Refactor main.cc to centrally handle (and report) all exceptions.
625 parseConfigFile(const char *file_name
)
628 return parseConfigFileOrThrow(file_name
);
630 catch (const std::exception
&ex
) {
631 debugs(3, DBG_CRITICAL
, "FATAL: bad configuration: " << ex
.what());
633 return 1; // not reached
638 * The templated functions below are essentially ConfigParser methods. They are
639 * not implemented as such because our generated code calling them is the only
640 * code that can instantiate implementations for each T -- we cannot place these
641 * definitions into ConfigParser.cc unless cf_parser.cci is moved there.
644 // TODO: When adding Ts incompatible with this trivial API and implementation,
645 // replace both with a ConfigParser-maintained table of seen directives.
646 /// whether we have seen (and, hence, configured) the given directive
647 template <typename T
>
649 SawDirective(const T
&raw
)
654 /// Sets the given raw SquidConfig data member.
655 /// Extracts and interprets parser's configuration tokens.
656 template <typename T
>
658 ParseDirective(T
&raw
, ConfigParser
&parser
)
660 if (SawDirective(raw
))
661 parser
.rejectDuplicateDirective();
663 // TODO: parser.openDirective(directiveName);
665 raw
= Configuration::Component
<T
>::Parse(parser
);
667 parser
.closeDirective();
670 /// reports raw SquidConfig data member configuration using squid.conf syntax
671 /// \param name the name of the configuration directive being dumped
672 template <typename T
>
674 DumpDirective(const T
&raw
, StoreEntry
*entry
, const char *name
)
676 if (!SawDirective(raw
))
677 return; // not configured
679 entry
->append(name
, strlen(name
));
681 Configuration::Component
<T
>::Print(os
, raw
);
682 const auto buf
= os
.buf();
684 entry
->append(" ", 1);
685 entry
->append(buf
.rawContent(), buf
.length());
687 entry
->append("\n", 1);
690 /// frees any resources associated with the given raw SquidConfig data member
691 template <typename T
>
693 FreeDirective(T
&raw
)
695 Configuration::Component
<T
>::Free(raw
);
697 // While the implementation may change, there is no way to avoid zeroing.
698 // Even migration to a proper SquidConfig class would not help: While
699 // ordinary destructors do not need to zero data members, a SquidConfig
700 // destructor would have to zero to protect any SquidConfig::x destruction
701 // code from accidentally dereferencing an already destroyed Config.y.
702 static_assert(std::is_trivial
<T
>::value
, "SquidConfig member is trivial");
703 memset(&raw
, 0, sizeof(raw
));
707 configDoConfigure(void)
710 /* init memory as early as possible */
714 if (Debug::rotateNumber
< 0) {
715 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
718 #if SIZEOF_OFF_T <= 4
719 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
720 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
721 Config
.Store
.maxObjectSize
= 0x7FFF0000;
725 if (Config
.Announce
.period
> 0) {
726 Config
.onoff
.announce
= 1;
728 Config
.Announce
.period
= 86400 * 365; /* one year */
729 Config
.onoff
.announce
= 0;
732 if (Config
.onoff
.httpd_suppress_version_string
)
733 visible_appname_string
= (char *)appname_string
;
735 visible_appname_string
= (char const *)APP_FULLNAME
;
737 if (Config
.Program
.redirect
) {
738 if (Config
.redirectChildren
.n_max
< 1) {
739 Config
.redirectChildren
.n_max
= 0;
740 wordlistDestroy(&Config
.Program
.redirect
);
744 if (Config
.Program
.store_id
) {
745 if (Config
.storeIdChildren
.n_max
< 1) {
746 Config
.storeIdChildren
.n_max
= 0;
747 wordlistDestroy(&Config
.Program
.store_id
);
751 if (Config
.appendDomain
)
752 if (*Config
.appendDomain
!= '.')
753 fatal("append_domain must begin with a '.'");
755 if (Config
.errHtmlText
== NULL
)
756 Config
.errHtmlText
= xstrdup(null_string
);
758 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
759 if (Config
.max_filedescriptors
> 0) {
760 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
762 #elif USE_SELECT || USE_SELECT_WIN32
763 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
764 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
770 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
772 visible_appname_string
);
775 * the extra space is for loop detection in client_side.c -- we search
776 * for substrings in the Via header.
778 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
780 visible_appname_string
);
782 /* Use visible_hostname as default surrogate_id */
783 if (!Config
.Accel
.surrogate_id
) {
784 const char *t
= getMyHostname();
785 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
788 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
789 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
791 if (Config
.appendDomain
)
792 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
794 Config
.appendDomainLen
= 0;
796 if (Config
.connect_retries
> 10) {
797 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
798 Config
.connect_retries
= 10;
801 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
804 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
806 bool logDaemonUsed
= false;
807 for (const auto *log
= Config
.Log
.accesslogs
; !logDaemonUsed
&& log
; log
= log
->next
)
808 logDaemonUsed
= log
->usesDaemon();
810 for (const auto *log
= Config
.Log
.icaplogs
; !logDaemonUsed
&& log
; log
= log
->next
)
811 logDaemonUsed
= log
->usesDaemon();
814 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
816 if (Config
.Program
.redirect
)
817 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
819 if (Config
.Program
.store_id
)
820 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
822 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
824 if (Config
.errorDirectory
)
825 requirePathnameExists("Error Directory", Config
.errorDirectory
);
827 #if USE_HTTP_VIOLATIONS
830 const RefreshPattern
*R
;
832 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
833 if (!R
->flags
.override_expire
)
836 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
841 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
842 if (!R
->flags
.override_lastmod
)
845 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
850 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
851 if (!R
->flags
.reload_into_ims
)
854 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
859 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
860 if (!R
->flags
.ignore_reload
)
863 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
868 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
869 if (!R
->flags
.ignore_no_store
)
872 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
877 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
878 if (!R
->flags
.ignore_private
)
881 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
887 #if !USE_HTTP_VIOLATIONS
888 Config
.onoff
.via
= 1;
891 if (!Config
.onoff
.via
)
892 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
896 // we enable runtime PURGE checks if there is at least one PURGE method ACL
897 // TODO: replace with a dedicated "purge" ACL option?
898 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
900 if (geteuid() == 0) {
901 if (NULL
!= Config
.effectiveUser
) {
903 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
907 * Andres Kroonmaa <andre@online.ee>:
908 * Some getpwnam() implementations (Solaris?) require
909 * an available FD < 256 for opening a FILE* to the
912 * This should be safe at startup, but might still fail
913 * during reconfigure.
915 fatalf("getpwnam failed to find userid for effective user '%s'",
916 Config
.effectiveUser
);
920 Config2
.effectiveUserID
= pwd
->pw_uid
;
922 Config2
.effectiveGroupID
= pwd
->pw_gid
;
925 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
926 // putenv() leaks by design; avoid leaks when nothing changes
928 if (lastDir
.isEmpty() || lastDir
.cmp(pwd
->pw_dir
) != 0) {
929 lastDir
= pwd
->pw_dir
;
930 int len
= strlen(pwd
->pw_dir
) + 6;
931 char *env_str
= (char *)xcalloc(len
, 1);
932 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
939 Config2
.effectiveUserID
= geteuid();
940 Config2
.effectiveGroupID
= getegid();
943 if (NULL
!= Config
.effectiveGroup
) {
945 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
948 fatalf("getgrnam failed to find groupid for effective group '%s'",
949 Config
.effectiveGroup
);
953 Config2
.effectiveGroupID
= grp
->gr_gid
;
957 if (Config
.ssl_client
.foreignIntermediateCertsPath
)
958 Ssl::loadSquidUntrusted(Config
.ssl_client
.foreignIntermediateCertsPath
);
961 if (Security::ProxyOutgoingConfig
.encryptTransport
) {
962 debugs(3, DBG_IMPORTANT
, "Initializing https:// proxy context");
963 Config
.ssl_client
.sslContext
= Security::ProxyOutgoingConfig
.createClientContext(false);
964 if (!Config
.ssl_client
.sslContext
) {
966 fatal("ERROR: Could not initialize https:// proxy context");
968 debugs(3, DBG_IMPORTANT
, "ERROR: proxying https:// currently still requires --with-openssl");
972 Ssl::useSquidUntrusted(Config
.ssl_client
.sslContext
.get());
976 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
978 // default value for ssldomain= is the peer host/IP
979 if (p
->secure
.sslDomain
.isEmpty())
980 p
->secure
.sslDomain
= p
->host
;
982 if (p
->secure
.encryptTransport
) {
983 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " TLS context");
984 p
->sslContext
= p
->secure
.createClientContext(true);
985 if (!p
->sslContext
) {
986 debugs(3, DBG_CRITICAL
, "ERROR: Could not initialize cache_peer " << p
->name
<< " TLS context");
993 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
994 if (!s
->secure
.encryptTransport
)
996 debugs(3, DBG_IMPORTANT
, "Initializing " << AnyP::UriScheme(s
->transport
.protocol
) << "_port " << s
->s
<< " TLS contexts");
997 s
->secure
.initServerContexts(*s
);
1000 // prevent infinite fetch loops in the request parser
1001 // due to buffer full but not enough data received to finish parse
1002 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
1003 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
1004 " Change client_request_buffer_max or request_header_max_size limits.",
1005 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
1009 * Disable client side request pipelining if client_persistent_connections OFF.
1010 * Waste of resources queueing any pipelined requests when the first will close the connection.
1012 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
1013 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
1014 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
1015 Config
.pipeline_max_prefetch
= 0;
1020 * disable client side request pipelining. There is a race with
1021 * Negotiate and NTLM when the client sends a second request on an
1022 * connection before the authenticate challenge is sent. With
1023 * pipelining OFF, the client may fail to authenticate, but squid's
1024 * state will be preserved.
1026 if (Config
.pipeline_max_prefetch
> 0) {
1027 Auth::SchemeConfig
*nego
= Auth::SchemeConfig::Find("Negotiate");
1028 Auth::SchemeConfig
*ntlm
= Auth::SchemeConfig::Find("NTLM");
1029 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
1030 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
1031 Config
.pipeline_max_prefetch
= 0;
1035 for (auto &authSchemes
: Auth::TheConfig
.schemeLists
) {
1036 authSchemes
.expand();
1037 if (authSchemes
.authConfigs
.empty()) {
1038 debugs(3, DBG_CRITICAL
, "auth_schemes: at least one scheme name is required; got: " << authSchemes
.rawSchemes
);
1045 /** Parse a line containing an obsolete directive.
1046 * To upgrade it where possible instead of just "Bungled config" for
1047 * directives which cannot be marked as simply aliases of the some name.
1048 * For example if the parameter order and content has changed.
1049 * Or if the directive has been completely removed.
1052 parse_obsolete(const char *name
)
1054 // Directives which have been radically changed rather than removed
1055 if (!strcmp(name
, "url_rewrite_concurrency")) {
1058 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
1059 Config
.redirectChildren
.concurrency
= cval
;
1062 if (!strcmp(name
, "log_access")) {
1067 if (!strcmp(name
, "log_icap")) {
1072 if (!strcmp(name
, "ignore_ims_on_miss")) {
1073 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1074 // than the 2.7 directive. We need to parse and invert the configured value.
1077 Config
.onoff
.cache_miss_revalidate
= !temp
;
1080 if (!strncmp(name
, "sslproxy_", 9)) {
1081 // the replacement directive tls_outgoing_options uses options instead of whole-line input
1083 if (!strcmp(name
, "sslproxy_cafile"))
1084 tmp
.append("cafile=");
1085 else if (!strcmp(name
, "sslproxy_capath"))
1086 tmp
.append("capath=");
1087 else if (!strcmp(name
, "sslproxy_cipher"))
1088 tmp
.append("cipher=");
1089 else if (!strcmp(name
, "sslproxy_client_certificate"))
1090 tmp
.append("cert=");
1091 else if (!strcmp(name
, "sslproxy_client_key"))
1093 else if (!strcmp(name
, "sslproxy_flags"))
1094 tmp
.append("flags=");
1095 else if (!strcmp(name
, "sslproxy_options"))
1096 tmp
.append("options=");
1097 else if (!strcmp(name
, "sslproxy_version"))
1098 tmp
.append("version=");
1100 debugs(3, DBG_CRITICAL
, "ERROR: unknown directive: " << name
);
1105 // add the value as unquoted-string because the old values did not support whitespace
1106 const char *token
= ConfigParser::NextQuotedOrToEol();
1107 tmp
.append(token
, strlen(token
));
1108 Security::ProxyOutgoingConfig
.parse(tmp
.c_str());
1112 template <class MinimalUnit
>
1116 const auto minUnit
= MinimalUnit(1);
1117 if(minUnit
== std::chrono::nanoseconds(1))
1118 return T_NANOSECOND_STR
;
1119 else if (minUnit
== std::chrono::microseconds(1))
1120 return T_MICROSECOND_STR
;
1121 else if (minUnit
== std::chrono::milliseconds(1))
1122 return T_MILLISECOND_STR
;
1124 assert(minUnit
>= std::chrono::seconds(1));
1125 return T_SECOND_STR
;
1129 /// Assigns 'ns' the number of nanoseconds corresponding to 'unitName'.
1130 /// \param MinimalUnit is a chrono duration type specifying the minimal
1131 /// allowed time unit.
1132 /// \returns true if unitName is correct and its time unit is not less
1133 /// than MinimalUnit.
1134 template <class MinimalUnit
>
1136 parseTimeUnit(const char *unitName
, std::chrono::nanoseconds
&ns
)
1139 throw TexcHere("missing time unit");
1141 if (!strncasecmp(unitName
, T_NANOSECOND_STR
, strlen(T_NANOSECOND_STR
)))
1142 ns
= std::chrono::nanoseconds(1);
1143 else if (!strncasecmp(unitName
, T_MICROSECOND_STR
, strlen(T_MICROSECOND_STR
)))
1144 ns
= std::chrono::microseconds(1);
1145 else if (!strncasecmp(unitName
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1146 ns
= std::chrono::milliseconds(1);
1147 else if (!strncasecmp(unitName
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1148 ns
= std::chrono::seconds(1);
1149 else if (!strncasecmp(unitName
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1150 ns
= std::chrono::minutes(1);
1151 else if (!strncasecmp(unitName
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1152 ns
= std::chrono::hours(1);
1153 else if (!strncasecmp(unitName
, T_DAY_STR
, strlen(T_DAY_STR
)))
1154 ns
= std::chrono::hours(24);
1155 else if (!strncasecmp(unitName
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1156 ns
= std::chrono::hours(24 * 7);
1157 else if (!strncasecmp(unitName
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1158 ns
= std::chrono::hours(24 * 14);
1159 else if (!strncasecmp(unitName
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1160 ns
= std::chrono::hours(24 * 30);
1161 else if (!strncasecmp(unitName
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1162 ns
= std::chrono::hours(static_cast<std::chrono::hours::rep
>(HoursPerYear
));
1163 else if (!strncasecmp(unitName
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1164 ns
= std::chrono::hours(static_cast<std::chrono::hours::rep
>(HoursPerYear
* 10));
1168 if (ns
< MinimalUnit(1)) {
1169 throw TexcHere(ToSBuf("time unit '", unitName
, "' is too small to be used in this context, the minimal unit is ",
1170 TimeUnitToString
<MinimalUnit
>()));
1176 static std::chrono::nanoseconds
1177 ToNanoSeconds(const double value
, const std::chrono::nanoseconds
&unit
)
1180 throw TexcHere("time must have a positive value");
1182 if (value
> (static_cast<double>(std::chrono::nanoseconds::max().count()) / unit
.count())) {
1183 const auto maxYears
= std::chrono::duration_cast
<std::chrono::hours
>(std::chrono::nanoseconds::max()).count()/HoursPerYear
;
1184 throw TexcHere(ToSBuf("time values cannot exceed ", maxYears
, " years"));
1187 return std::chrono::duration_cast
<std::chrono::nanoseconds
>(unit
* value
);
1190 template <class TimeUnit
>
1192 FromNanoseconds(const std::chrono::nanoseconds
&ns
, const double parsedValue
)
1194 const auto result
= std::chrono::duration_cast
<TimeUnit
>(ns
);
1195 if (!result
.count()) {
1196 throw TexcHere(ToSBuf("time value '", parsedValue
,
1197 "' is too small to be used in this context, the minimal value is 1 ",
1198 TimeUnitToString
<TimeUnit
>()));
1203 /// Parses a time specification from the config file and
1204 /// returns the time as a chrono duration object of 'TimeUnit' type.
1205 template <class TimeUnit
>
1209 const auto valueToken
= ConfigParser::NextToken();
1211 throw TexcHere("cannot read a time value");
1213 const auto parsedValue
= xatof(valueToken
);
1215 if (parsedValue
== 0)
1216 return TimeUnit::zero();
1218 std::chrono::nanoseconds parsedUnitDuration
;
1220 const auto token
= ConfigParser::PeekAtToken();
1222 if (!parseTimeUnit
<TimeUnit
>(token
, parsedUnitDuration
))
1223 throw TexcHere(ToSBuf("unknown time unit '", token
, "'"));
1225 (void)ConfigParser::NextToken();
1227 const auto nanoseconds
= ToNanoSeconds(parsedValue
, parsedUnitDuration
);
1229 // validate precisions (time-units-small only)
1230 if (TimeUnit(1) <= std::chrono::microseconds(1)) {
1231 if (0 < nanoseconds
.count() && nanoseconds
.count() < 3) {
1232 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), ConfigParser::CurrentLocation() << ": WARNING: " <<
1233 "Squid time measurement precision is likely to be far worse than " <<
1234 "the nanosecond-level precision implied by the configured value: " << parsedValue
<< ' ' << token
);
1238 return FromNanoseconds
<TimeUnit
>(nanoseconds
, parsedValue
);
1242 parseBytesLine64(int64_t * bptr
, const char *units
)
1249 if ((u
= parseBytesUnits(units
)) == 0) {
1254 if ((token
= ConfigParser::NextToken()) == NULL
) {
1259 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1266 m
= u
; /* default to 'units' if none specified */
1270 else if ((token
= ConfigParser::NextToken()) == NULL
)
1271 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1272 config_input_line
<< "', assuming " <<
1273 d
<< " " << units
);
1274 else if ((m
= parseBytesUnits(token
)) == 0) {
1279 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1281 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1282 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1283 d
<< " " << token
<< ": integer overflow (int64_t).");
1289 parseBytesLine(size_t * bptr
, const char *units
)
1296 if ((u
= parseBytesUnits(units
)) == 0) {
1301 if ((token
= ConfigParser::NextToken()) == NULL
) {
1306 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1307 *bptr
= static_cast<size_t>(-1);
1313 m
= u
; /* default to 'units' if none specified */
1317 else if ((token
= ConfigParser::NextToken()) == NULL
)
1318 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1319 config_input_line
<< "', assuming " <<
1320 d
<< " " << units
);
1321 else if ((m
= parseBytesUnits(token
)) == 0) {
1326 *bptr
= static_cast<size_t>(m
* d
/ u
);
1328 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1329 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1330 d
<< " " << token
<< ": integer overflow (size_t).");
1336 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1343 if ((u
= parseBytesUnits(units
)) == 0) {
1348 if ((token
= ConfigParser::NextToken()) == NULL
) {
1353 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1360 m
= u
; /* default to 'units' if none specified */
1364 else if ((token
= ConfigParser::NextToken()) == NULL
)
1365 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1366 config_input_line
<< "', assuming " <<
1367 d
<< " " << units
);
1368 else if ((m
= parseBytesUnits(token
)) == 0) {
1373 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1375 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1376 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1377 d
<< " " << token
<< ": integer overflow (ssize_t).");
1383 * Parse bytes from a string.
1384 * Similar to the parseBytesLine function but parses the string value instead of
1385 * the current token value.
1388 parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1391 if ((u
= parseBytesUnits(units
)) == 0) {
1396 // Find number from string beginning.
1397 char const * number_begin
= value
;
1398 char const * number_end
= value
;
1400 while ((*number_end
>= '0' && *number_end
<= '9')) {
1405 number
.assign(number_begin
, number_end
- number_begin
);
1407 int d
= xatoi(number
.termedBuf());
1409 if ((m
= parseBytesUnits(number_end
)) == 0) {
1414 *bptr
= static_cast<size_t>(m
* d
/ u
);
1415 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1420 parseBytesUnits(const char *unit
)
1422 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1425 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1428 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1431 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1434 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1440 parse_SBufList(SBufList
* list
)
1442 while (char *token
= ConfigParser::NextQuotedToken())
1443 list
->push_back(SBuf(token
));
1446 // just dump a list, no directive name
1448 dump_SBufList(StoreEntry
* entry
, const SBufList
&words
)
1450 for (const auto &i
: words
) {
1451 entry
->append(i
.rawContent(), i
.length());
1452 entry
->append(" ",1);
1454 entry
->append("\n",1);
1457 // dump a SBufList type directive with name
1459 dump_SBufList(StoreEntry
* entry
, const char *name
, SBufList
&list
)
1461 if (!list
.empty()) {
1462 entry
->append(name
, strlen(name
));
1463 entry
->append(" ", 1);
1464 dump_SBufList(entry
, list
);
1469 free_SBufList(SBufList
*list
)
1476 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1478 while (ae
!= NULL
) {
1479 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1480 storeAppendPrintf(entry
, "%s %s %s ",
1485 tail
.splice(tail
.end(), ae
->dumpOptions());
1486 tail
.splice(tail
.end(), ae
->dump()); // ACL parameters
1487 dump_SBufList(entry
, tail
);
1493 parse_acl(ACL
** ae
)
1495 ACL::ParseAclLine(LegacyParser
, ae
);
1505 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1507 // XXX: Should dump ACL names like "foo !bar" but dumps parsing context like
1508 // "(clientside_tos 0x11 line)".
1509 dump_SBufList(entry
, head
->dump());
1513 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1516 dump_SBufList(entry
, head
->treeDump(name
, &Acl::AllowOrDeny
));
1520 parse_acl_access(acl_access
** head
)
1522 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1526 free_acl_access(acl_access
** head
)
1528 aclDestroyAccessList(head
);
1532 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1534 char buf
[MAX_IPSTRLEN
];
1535 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1539 parse_address(Ip::Address
*addr
)
1541 char *token
= ConfigParser::NextToken();
1548 if (!strcmp(token
,"any_addr"))
1550 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1552 else if ( (*addr
= token
) ) // try parse numeric/IPA
1554 else if (addr
->GetHostByName(token
)) // do not use ipcache
1556 else { // not an IP and not a hostname
1557 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
1563 free_address(Ip::Address
*addr
)
1569 dump_acl_address(StoreEntry
* entry
, const char *name
, Acl::Address
* head
)
1571 char buf
[MAX_IPSTRLEN
];
1573 for (Acl::Address
*l
= head
; l
; l
= l
->next
) {
1574 if (!l
->addr
.isAnyAddr())
1575 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.toStr(buf
,MAX_IPSTRLEN
));
1577 storeAppendPrintf(entry
, "%s autoselect", name
);
1579 dump_acl_list(entry
, l
->aclList
);
1581 storeAppendPrintf(entry
, "\n");
1586 parse_acl_address(Acl::Address
** head
)
1588 Acl::Address
*l
= new Acl::Address
;
1589 parse_address(&l
->addr
);
1590 aclParseAclList(LegacyParser
, &l
->aclList
, l
->addr
);
1592 Acl::Address
**tail
= head
;
1594 tail
= &(*tail
)->next
;
1600 free_acl_address(Acl::Address
** head
)
1607 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1611 for (l
= head
; l
; l
= l
->next
) {
1613 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1615 storeAppendPrintf(entry
, "%s none", name
);
1617 dump_acl_list(entry
, l
->aclList
);
1619 storeAppendPrintf(entry
, "\n");
1624 parse_acl_tos(acl_tos
** head
)
1626 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1627 char *token
= ConfigParser::NextToken();
1634 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1639 const unsigned int chTos
= tos
& 0xFC;
1641 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: Tos value '" << tos
<< "' adjusted to '" << chTos
<< "'");
1645 acl_tos
*l
= new acl_tos
;
1647 l
->tos
= (tos_t
)tos
;
1649 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1651 acl_tos
**tail
= head
; /* sane name below */
1653 tail
= &(*tail
)->next
;
1659 free_acl_tos(acl_tos
** head
)
1665 #if SO_MARK && USE_LIBCAP
1668 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1670 for (acl_nfmark
*l
= head
; l
; l
= l
->next
) {
1671 storeAppendPrintf(entry
, "%s %s", name
, ToSBuf(l
->markConfig
).c_str());
1673 dump_acl_list(entry
, l
->aclList
);
1675 storeAppendPrintf(entry
, "\n");
1680 parse_acl_nfmark(acl_nfmark
** head
)
1682 SBuf
token(ConfigParser::NextToken());
1683 const auto mc
= Ip::NfMarkConfig::Parse(token
);
1685 // Packet marking directives should not allow to use masks.
1686 const auto pkt_dirs
= {"mark_client_packet", "clientside_mark", "tcp_outgoing_mark"};
1687 if (mc
.hasMask() && std::find(pkt_dirs
.begin(), pkt_dirs
.end(), cfg_directive
) != pkt_dirs
.end())
1688 throw TexcHere(ToSBuf("'", cfg_directive
, "' does not support masked marks"));
1690 acl_nfmark
*l
= new acl_nfmark
;
1693 aclParseAclList(LegacyParser
, &l
->aclList
, token
.c_str());
1695 acl_nfmark
**tail
= head
; /* sane name below */
1697 tail
= &(*tail
)->next
;
1703 free_acl_nfmark(acl_nfmark
** head
)
1708 #endif /* SO_MARK */
1711 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1713 for (AclSizeLimit
*l
= head
; l
; l
= l
->next
) {
1715 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1717 storeAppendPrintf(entry
, "%s none", name
);
1719 dump_acl_list(entry
, l
->aclList
);
1721 storeAppendPrintf(entry
, "\n");
1726 parse_acl_b_size_t(AclSizeLimit
** head
)
1728 AclSizeLimit
*l
= new AclSizeLimit
;
1730 parse_b_int64_t(&l
->size
);
1732 aclParseAclList(LegacyParser
, &l
->aclList
, l
->size
);
1734 AclSizeLimit
**tail
= head
; /* sane name below */
1736 tail
= &(*tail
)->next
;
1742 free_acl_b_size_t(AclSizeLimit
** head
)
1750 #include "DelayConfig.h"
1751 #include "DelayPools.h"
1752 /* do nothing - free_delay_pool_count is the magic free function.
1753 * this is why delay_pool_count isn't just marked TYPE: u_short
1755 #define free_delay_pool_class(X)
1756 #define free_delay_pool_access(X)
1757 #define free_delay_pool_rates(X)
1758 #define dump_delay_pool_class(X, Y, Z)
1759 #define dump_delay_pool_access(X, Y, Z)
1760 #define dump_delay_pool_rates(X, Y, Z)
1763 free_delay_pool_count(DelayConfig
* cfg
)
1765 cfg
->freePoolCount();
1769 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1771 cfg
.dumpPoolCount (entry
, name
);
1775 parse_delay_pool_count(DelayConfig
* cfg
)
1777 cfg
->parsePoolCount();
1781 parse_delay_pool_class(DelayConfig
* cfg
)
1783 cfg
->parsePoolClass();
1787 parse_delay_pool_rates(DelayConfig
* cfg
)
1789 cfg
->parsePoolRates();
1793 parse_delay_pool_access(DelayConfig
* cfg
)
1795 cfg
->parsePoolAccess(LegacyParser
);
1801 #include "ClientDelayConfig.h"
1802 /* do nothing - free_client_delay_pool_count is the magic free function.
1803 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1806 #define free_client_delay_pool_access(X)
1807 #define free_client_delay_pool_rates(X)
1808 #define dump_client_delay_pool_access(X, Y, Z)
1809 #define dump_client_delay_pool_rates(X, Y, Z)
1812 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1818 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1820 cfg
.dumpPoolCount (entry
, name
);
1824 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1826 cfg
->parsePoolCount();
1830 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1832 cfg
->parsePoolRates();
1836 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1838 cfg
->parsePoolAccess(LegacyParser
);
1842 #if USE_HTTP_VIOLATIONS
1844 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1847 manglers
->dumpAccess(entry
, name
);
1851 parse_http_header_access(HeaderManglers
**pm
)
1855 if ((t
= ConfigParser::NextToken()) == NULL
) {
1856 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1857 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1862 *pm
= new HeaderManglers
;
1863 HeaderManglers
*manglers
= *pm
;
1864 headerMangler
*mangler
= manglers
->track(t
);
1867 std::string directive
= "http_header_access ";
1869 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1873 free_HeaderManglers(HeaderManglers
**pm
)
1875 // we delete the entire http_header_* mangler configuration at once
1876 if (const HeaderManglers
*manglers
= *pm
) {
1883 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1886 manglers
->dumpReplacement(entry
, name
);
1890 parse_http_header_replace(HeaderManglers
**pm
)
1894 if ((t
= ConfigParser::NextToken()) == NULL
) {
1895 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1896 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1900 const char *value
= ConfigParser::NextQuotedOrToEol();
1903 *pm
= new HeaderManglers
;
1904 HeaderManglers
*manglers
= *pm
;
1905 manglers
->setReplacement(t
, value
);
1911 dump_cachedir(StoreEntry
* entry
, const char *name
, const Store::DiskConfig
&swap
)
1913 Store::Disks::Dump(swap
, *entry
, name
);
1917 check_null_string(char *s
)
1924 parse_authparam(Auth::ConfigVector
* config
)
1926 char *type_str
= ConfigParser::NextToken();
1932 char *param_str
= ConfigParser::NextToken();
1938 /* find a configuration for the scheme in the currently parsed configs... */
1939 Auth::SchemeConfig
*schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1941 if (schemeCfg
== NULL
) {
1942 /* Create a configuration based on the scheme info */
1943 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1945 if (theScheme
== NULL
) {
1946 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1951 config
->push_back(theScheme
->createConfig());
1952 schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1953 if (schemeCfg
== NULL
) {
1954 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1960 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1964 free_authparam(Auth::ConfigVector
* cfg
)
1966 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1969 /* on reconfigure initialize new auth schemes for the new config. */
1970 if (reconfiguring
) {
1976 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1978 for (auto *scheme
: cfg
)
1979 scheme
->dump(entry
, name
, scheme
);
1983 parse_AuthSchemes(acl_access
**authSchemes
)
1985 const char *tok
= ConfigParser::NextQuotedToken();
1987 debugs(29, DBG_CRITICAL
, "FATAL: auth_schemes missing the parameter");
1991 Auth::TheConfig
.schemeLists
.emplace_back(tok
, ConfigParser::LastTokenWasQuoted());
1992 const auto action
= Acl::Answer(ACCESS_ALLOWED
, Auth::TheConfig
.schemeLists
.size() - 1);
1993 ParseAclWithAction(authSchemes
, action
, "auth_schemes");
1997 free_AuthSchemes(acl_access
**authSchemes
)
1999 Auth::TheConfig
.schemeLists
.clear();
2000 free_acl_access(authSchemes
);
2004 dump_AuthSchemes(StoreEntry
*entry
, const char *name
, acl_access
*authSchemes
)
2007 dump_SBufList(entry
, authSchemes
->treeDump(name
, [](const Acl::Answer
&action
) {
2008 return Auth::TheConfig
.schemeLists
.at(action
.kind
).rawSchemes
;
2012 #endif /* USE_AUTH */
2015 ParseAclWithAction(acl_access
**access
, const Acl::Answer
&action
, const char *desc
, ACL
*acl
)
2020 *access
= new Acl::Tree
;
2021 name
.Printf("(%s rules)", desc
);
2022 (*access
)->context(name
.c_str(), config_input_line
);
2024 Acl::AndNode
*rule
= new Acl::AndNode
;
2025 name
.Printf("(%s rule)", desc
);
2026 rule
->context(name
.c_str(), config_input_line
);
2031 (*access
)->add(rule
, action
);
2035 parse_cachedir(Store::DiskConfig
*swap
)
2038 Store::Disks::Parse(*swap
);
2042 peer_type_str(const peer_t type
)
2044 const char * result
;
2056 case PEER_MULTICAST
:
2057 result
= "multicast";
2069 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2071 NeighborTypeDomainList
*t
;
2072 LOCAL_ARRAY(char, xname
, 128);
2075 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2082 dump_peer_options(entry
, p
);
2085 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2086 dump_acl_access(entry
, xname
, p
->access
);
2089 for (t
= p
->typelist
; t
; t
= t
->next
) {
2090 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2092 peer_type_str(t
->type
),
2101 * utility function to prevent getservbyname() being called with a numeric value
2102 * on Windows at least it returns garage results.
2105 isUnsignedNumeric(const char *str
, size_t len
)
2107 if (len
< 1) return false;
2109 for (; len
>0 && *str
; ++str
, --len
) {
2110 if (! isdigit(*str
))
2117 \param proto 'tcp' or 'udp' for protocol
2118 \returns Port the named service is supposed to be listening on.
2120 static unsigned short
2121 GetService(const char *proto
)
2123 struct servent
*port
= NULL
;
2124 /** Parses a port number or service name from the squid.conf */
2125 char *token
= ConfigParser::NextToken();
2126 if (token
== NULL
) {
2128 return 0; /* NEVER REACHED */
2130 /** Returns either the service port number from /etc/services */
2131 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2132 port
= getservbyname(token
, proto
);
2134 return ntohs((unsigned short)port
->s_port
);
2136 /** Or a numeric translation of the config text. */
2137 return xatos(token
);
2141 \returns Port the named TCP service is supposed to be listening on.
2142 \copydoc GetService(const char *proto)
2144 inline unsigned short
2147 return GetService("tcp");
2151 \returns Port the named UDP service is supposed to be listening on.
2152 \copydoc GetService(const char *proto)
2154 inline unsigned short
2157 return GetService("udp");
2161 parse_peer(CachePeer
** head
)
2163 char *host_str
= ConfigParser::NextToken();
2169 char *token
= ConfigParser::NextToken();
2175 CachePeer
*p
= new CachePeer
;
2176 p
->host
= xstrdup(host_str
);
2178 p
->name
= xstrdup(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 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2274 p
->options
.carp
= true;
2275 } else if (!strncmp(token
, "carp-key=", 9)) {
2276 if (p
->options
.carp
!= true)
2277 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
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 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2302 p
->options
.userhash
= true;
2304 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2306 } else if (!strcmp(token
, "sourcehash")) {
2307 if (p
->type
!= PEER_PARENT
)
2308 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
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)) {
2344 p
->name
= xstrdup(token
+ 5);
2345 } else if (!strncmp(token
, "forceddomain=", 13)) {
2346 safe_free(p
->domain
);
2348 p
->domain
= xstrdup(token
+ 13);
2350 } else if (strncmp(token
, "ssl", 3) == 0) {
2352 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option '" << token
<< "' requires --with-openssl");
2354 p
->secure
.parse(token
+3);
2356 } else if (strncmp(token
, "tls-", 4) == 0) {
2357 p
->secure
.parse(token
+4);
2358 } else if (strncmp(token
, "tls", 3) == 0) {
2359 p
->secure
.parse(token
+3);
2360 } else if (strcmp(token
, "front-end-https") == 0) {
2361 p
->front_end_https
= 1;
2362 } else if (strcmp(token
, "front-end-https=on") == 0) {
2363 p
->front_end_https
= 1;
2364 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2365 p
->front_end_https
= 2;
2366 } else if (strcmp(token
, "connection-auth=off") == 0) {
2367 p
->connection_auth
= 0;
2368 } else if (strcmp(token
, "connection-auth") == 0) {
2369 p
->connection_auth
= 1;
2370 } else if (strcmp(token
, "connection-auth=on") == 0) {
2371 p
->connection_auth
= 1;
2372 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2373 p
->connection_auth
= 2;
2374 } else if (token
[0] == '#') {
2375 // start of a text comment. stop reading this line.
2378 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2382 if (peerFindByName(p
->name
))
2383 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2385 if (p
->max_conn
> 0 && p
->max_conn
< p
->standby
.limit
)
2386 fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p
->host
, p
->max_conn
, p
->standby
.limit
);
2391 if (p
->connect_fail_limit
< 1)
2392 p
->connect_fail_limit
= 10;
2394 #if USE_CACHE_DIGESTS
2395 if (!p
->options
.no_digest
)
2396 peerDigestCreate(p
);
2399 if (p
->secure
.encryptTransport
)
2400 p
->secure
.parseOptions();
2402 p
->index
= ++Config
.npeers
;
2404 while (*head
!= NULL
)
2405 head
= &(*head
)->next
;
2413 free_peer(CachePeer
** P
)
2421 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2424 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2425 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2427 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2429 for (auto w
: list
->actions
)
2430 entry
->appendf(" " SQUIDSBUFPH
, SQUIDSBUFPRINT(w
));
2432 storeAppendPrintf(entry
, "\n");
2438 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2440 char *passwd
= nullptr;
2441 parse_string(&passwd
);
2443 Mgr::ActionPasswordList
*p
= new Mgr::ActionPasswordList
;
2446 while (char *token
= ConfigParser::NextQuotedToken())
2447 p
->actions
.push_back(SBuf(token
));
2449 Mgr::ActionPasswordList
**P
;
2450 for (P
= head
; *P
; P
= &(*P
)->next
) {
2452 * See if any of the actions from this line already have a
2453 * password from previous lines. The password checking
2454 * routines in cache_manager.c take the the password from
2455 * the first Mgr::ActionPasswordList that contains the
2456 * requested action. Thus, we should warn users who might
2457 * think they can have two passwords for the same action.
2459 for (const auto &w
: (*P
)->actions
) {
2460 for (const auto &u
: p
->actions
) {
2464 debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u
<< "' (line " << config_lineno
<< ") already has a password");
2473 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2480 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2482 while (var
!= NULL
) {
2483 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2485 for (const auto &aclName
: var
->acl_list
)
2486 storeAppendPrintf(entry
, " " SQUIDSBUFPH
, SQUIDSBUFPRINT(aclName
));
2488 storeAppendPrintf(entry
, "\n");
2495 parse_denyinfo(AclDenyInfoList
** var
)
2497 aclParseDenyInfoLine(var
);
2501 free_denyinfo(AclDenyInfoList
** list
)
2508 parse_peer_access(void)
2510 char *host
= ConfigParser::NextToken();
2516 CachePeer
*p
= peerFindByName(host
);
2518 debugs(15, DBG_CRITICAL
, "ERROR: " << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2522 std::string directive
= "peer_access ";
2524 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
->access
);
2528 parse_hostdomaintype(void)
2530 char *host
= ConfigParser::NextToken();
2536 char *type
= ConfigParser::NextToken();
2542 char *domain
= nullptr;
2543 while ((domain
= ConfigParser::NextToken())) {
2544 CachePeer
*p
= peerFindByName(host
);
2546 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2550 auto *l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2551 l
->type
= parseNeighborType(type
);
2552 l
->domain
= xstrdup(domain
);
2554 NeighborTypeDomainList
**L
= nullptr;
2555 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2561 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2563 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2581 dump_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2583 storeAppendPrintf(entry
, "%s %" PRId64
"\n", name
, var
);
2587 parse_int64_t(int64_t *var
)
2595 free_int64_t(int64_t *var
)
2601 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2603 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2607 parse_onoff(int *var
)
2609 char *token
= ConfigParser::NextToken();
2615 if (!strcmp(token
, "on")) {
2617 } else if (!strcmp(token
, "enable")) {
2618 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2620 } else if (!strcmp(token
, "off")) {
2622 } else if (!strcmp(token
, "disable")) {
2623 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2626 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2631 #define free_onoff free_int
2634 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2645 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2649 parse_tristate(int *var
)
2651 char *token
= ConfigParser::NextToken();
2657 if (!strcmp(token
, "on")) {
2659 } else if (!strcmp(token
, "enable")) {
2660 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2662 } else if (!strcmp(token
, "warn")) {
2664 } else if (!strcmp(token
, "off")) {
2666 } else if (!strcmp(token
, "disable")) {
2667 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2670 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2675 #define free_tristate free_int
2678 parse_pipelinePrefetch(int *var
)
2680 char *token
= ConfigParser::PeekAtToken();
2686 if (!strcmp(token
, "on")) {
2687 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2690 (void)ConfigParser::NextToken();
2691 } else if (!strcmp(token
, "off")) {
2692 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2695 (void)ConfigParser::NextToken();
2700 #define free_pipelinePrefetch free_int
2701 #define dump_pipelinePrefetch dump_int
2704 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2706 while (head
!= NULL
) {
2707 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2709 head
->pattern
.flags
®_ICASE
? " -i" : null_string
,
2710 head
->pattern
.c_str(),
2711 (int) head
->min
/ 60,
2712 (int) (100.0 * head
->pct
+ 0.5),
2713 (int) head
->max
/ 60);
2715 if (head
->max_stale
>= 0)
2716 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2718 if (head
->flags
.refresh_ims
)
2719 storeAppendPrintf(entry
, " refresh-ims");
2721 if (head
->flags
.store_stale
)
2722 storeAppendPrintf(entry
, " store-stale");
2724 #if USE_HTTP_VIOLATIONS
2726 if (head
->flags
.override_expire
)
2727 storeAppendPrintf(entry
, " override-expire");
2729 if (head
->flags
.override_lastmod
)
2730 storeAppendPrintf(entry
, " override-lastmod");
2732 if (head
->flags
.reload_into_ims
)
2733 storeAppendPrintf(entry
, " reload-into-ims");
2735 if (head
->flags
.ignore_reload
)
2736 storeAppendPrintf(entry
, " ignore-reload");
2738 if (head
->flags
.ignore_no_store
)
2739 storeAppendPrintf(entry
, " ignore-no-store");
2741 if (head
->flags
.ignore_private
)
2742 storeAppendPrintf(entry
, " ignore-private");
2745 storeAppendPrintf(entry
, "\n");
2752 parse_refreshpattern(RefreshPattern
** head
)
2759 int refresh_ims
= 0;
2760 int store_stale
= 0;
2763 #if USE_HTTP_VIOLATIONS
2765 int override_expire
= 0;
2766 int override_lastmod
= 0;
2767 int reload_into_ims
= 0;
2768 int ignore_reload
= 0;
2769 int ignore_no_store
= 0;
2770 int ignore_private
= 0;
2777 int flags
= REG_EXTENDED
| REG_NOSUB
;
2779 if ((token
= ConfigParser::RegexPattern()) != NULL
) {
2781 if (strcmp(token
, "-i") == 0) {
2783 token
= ConfigParser::RegexPattern();
2784 } else if (strcmp(token
, "+i") == 0) {
2785 flags
&= ~REG_ICASE
;
2786 token
= ConfigParser::RegexPattern();
2791 if (token
== NULL
) {
2792 debugs(3, DBG_CRITICAL
, "FATAL: refresh_pattern missing the regex pattern parameter");
2797 pattern
= xstrdup(token
);
2799 i
= GetInteger(); /* token: min */
2801 /* catch negative and insanely huge values close to 32-bit wrap */
2803 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2806 if (i
> 60*24*365) {
2807 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2811 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2813 pct
= GetPercentage(false); /* token: pct . with no limit on size */
2815 i
= GetInteger(); /* token: max */
2817 /* catch negative and insanely huge values close to 32-bit wrap */
2819 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2822 if (i
> 60*24*365) {
2823 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2827 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2830 while ((token
= ConfigParser::NextToken()) != NULL
) {
2831 if (!strcmp(token
, "refresh-ims")) {
2833 } else if (!strcmp(token
, "store-stale")) {
2835 } else if (!strncmp(token
, "max-stale=", 10)) {
2836 max_stale
= xatoi(token
+ 10);
2838 #if USE_HTTP_VIOLATIONS
2840 } else if (!strcmp(token
, "override-expire"))
2841 override_expire
= 1;
2842 else if (!strcmp(token
, "override-lastmod"))
2843 override_lastmod
= 1;
2844 else if (!strcmp(token
, "ignore-no-store"))
2845 ignore_no_store
= 1;
2846 else if (!strcmp(token
, "ignore-private"))
2848 else if (!strcmp(token
, "reload-into-ims")) {
2849 reload_into_ims
= 1;
2850 refresh_nocache_hack
= 1;
2851 /* tell client_side.c that this is used */
2852 } else if (!strcmp(token
, "ignore-reload")) {
2854 refresh_nocache_hack
= 1;
2855 /* tell client_side.c that this is used */
2858 } else if (!strcmp(token
, "ignore-no-cache") ||
2859 !strcmp(token
, "ignore-must-revalidate") ||
2860 !strcmp(token
, "ignore-auth")
2862 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token
<< "' is obsolete. Remove it.");
2864 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2867 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2869 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2870 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2871 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2876 pct
= pct
< 0.0 ? 0.0 : pct
;
2877 max
= max
< 0 ? 0 : max
;
2878 t
= new RefreshPattern(pattern
, flags
);
2879 t
->pattern
.regex
= comp
;
2885 t
->flags
.refresh_ims
= true;
2888 t
->flags
.store_stale
= true;
2890 t
->max_stale
= max_stale
;
2892 #if USE_HTTP_VIOLATIONS
2894 if (override_expire
)
2895 t
->flags
.override_expire
= true;
2897 if (override_lastmod
)
2898 t
->flags
.override_lastmod
= true;
2900 if (reload_into_ims
)
2901 t
->flags
.reload_into_ims
= true;
2904 t
->flags
.ignore_reload
= true;
2906 if (ignore_no_store
)
2907 t
->flags
.ignore_no_store
= true;
2910 t
->flags
.ignore_private
= true;
2916 head
= &(*head
)->next
;
2924 free_refreshpattern(RefreshPattern
** head
)
2929 #if USE_HTTP_VIOLATIONS
2930 refresh_nocache_hack
= 0;
2936 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2939 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2943 parse_string(char **var
)
2947 char *token
= ConfigParser::NextToken();
2953 *var
= xstrdup(token
);
2957 free_string(char **var
)
2963 parse_eol(char *volatile *var
)
2970 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
2978 while (*token
&& xisspace(*token
))
2986 *var
= xstrdup((char *) token
);
2989 #define dump_eol dump_string
2990 #define free_eol free_string
2993 parse_TokenOrQuotedString(char **var
)
2997 char *token
= ConfigParser::NextQuotedToken();
3003 *var
= xstrdup(token
);
3006 #define dump_TokenOrQuotedString dump_string
3007 #define free_TokenOrQuotedString free_string
3010 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3012 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3016 parse_time_t(time_t * var
)
3018 const auto maxTime
= std::numeric_limits
<time_t>::max();
3019 const auto seconds
= parseTimeLine
<std::chrono::seconds
>();
3020 if (maxTime
< seconds
.count())
3021 throw TexcHere(ToSBuf("directive supports time values up to ", maxTime
, " but is given ", seconds
.count(), " seconds"));
3022 *var
= static_cast<time_t>(seconds
.count());
3026 free_time_t(time_t * var
)
3032 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3035 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3037 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3041 parse_time_msec(time_msec_t
* var
)
3043 *var
= parseTimeLine
<std::chrono::milliseconds
>().count();
3047 free_time_msec(time_msec_t
* var
)
3053 dump_time_nanoseconds(StoreEntry
*entry
, const char *name
, const std::chrono::nanoseconds
&var
)
3055 // std::chrono::nanoseconds::rep is unknown a priori so we cast to (and print) the largest supported integer
3056 storeAppendPrintf(entry
, "%s %jd nanoseconds\n", name
, static_cast<intmax_t>(var
.count()));
3060 parse_time_nanoseconds(std::chrono::nanoseconds
*var
)
3062 *var
= parseTimeLine
<std::chrono::nanoseconds
>();
3066 free_time_nanoseconds(std::chrono::nanoseconds
*var
)
3068 *var
= std::chrono::nanoseconds::zero();
3072 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3074 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3078 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3080 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3084 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3086 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3090 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3092 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3096 parse_b_size_t(size_t * var
)
3098 parseBytesLine(var
, B_BYTES_STR
);
3102 parse_b_ssize_t(ssize_t
* var
)
3104 parseBytesLineSigned(var
, B_BYTES_STR
);
3108 parse_b_int64_t(int64_t * var
)
3110 parseBytesLine64(var
, B_BYTES_STR
);
3114 parse_kb_int64_t(int64_t * var
)
3116 parseBytesLine64(var
, B_KBYTES_STR
);
3120 free_size_t(size_t * var
)
3126 free_ssize_t(ssize_t
* var
)
3132 free_b_int64_t(int64_t * var
)
3137 #define free_b_size_t free_size_t
3138 #define free_b_ssize_t free_ssize_t
3139 #define free_kb_size_t free_size_t
3140 #define free_mb_size_t free_size_t
3141 #define free_gb_size_t free_size_t
3142 #define free_kb_int64_t free_b_int64_t
3145 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3147 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3151 free_u_short(unsigned short * u
)
3157 parse_u_short(unsigned short * var
)
3159 ConfigParser::ParseUShort(var
);
3163 ConfigParser::ParseUShort(unsigned short *var
)
3169 ConfigParser::ParseBool(bool *var
)
3171 int i
= GetInteger();
3182 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3184 while (list
!= NULL
) {
3185 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3191 ConfigParser::ParseWordList(wordlist
** list
)
3193 parse_wordlist(list
);
3197 parse_wordlist(wordlist
** list
)
3200 while ((token
= ConfigParser::NextQuotedToken()))
3201 wordlistAdd(list
, token
);
3205 check_null_acl_access(acl_access
* a
)
3210 #define free_wordlist wordlistDestroy
3212 #define free_uri_whitespace free_int
3215 parse_uri_whitespace(int *var
)
3217 char *token
= ConfigParser::NextToken();
3223 if (!strcmp(token
, "strip"))
3224 *var
= URI_WHITESPACE_STRIP
;
3225 else if (!strcmp(token
, "deny"))
3226 *var
= URI_WHITESPACE_DENY
;
3227 else if (!strcmp(token
, "allow"))
3228 *var
= URI_WHITESPACE_ALLOW
;
3229 else if (!strcmp(token
, "encode"))
3230 *var
= URI_WHITESPACE_ENCODE
;
3231 else if (!strcmp(token
, "chop"))
3232 *var
= URI_WHITESPACE_CHOP
;
3234 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3240 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3244 if (var
== URI_WHITESPACE_ALLOW
)
3246 else if (var
== URI_WHITESPACE_ENCODE
)
3248 else if (var
== URI_WHITESPACE_CHOP
)
3250 else if (var
== URI_WHITESPACE_DENY
)
3255 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3259 free_removalpolicy(RemovalPolicySettings
** settings
)
3264 free_string(&(*settings
)->type
);
3266 free_wordlist(&(*settings
)->args
);
3274 parse_removalpolicy(RemovalPolicySettings
** settings
)
3277 free_removalpolicy(settings
);
3279 *settings
= new RemovalPolicySettings
;
3281 parse_string(&(*settings
)->type
);
3283 parse_wordlist(&(*settings
)->args
);
3287 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3290 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3291 args
= settings
->args
;
3294 storeAppendPrintf(entry
, " %s", args
->key
);
3298 storeAppendPrintf(entry
, "\n");
3302 free_YesNoNone(YesNoNone
*)
3306 parse_YesNoNone(YesNoNone
*option
)
3309 parse_onoff(&value
);
3310 option
->configure(value
> 0);
3314 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3316 if (option
.configured())
3317 dump_onoff(entry
, name
, option
? 1 : 0);
3321 free_memcachemode(SquidConfig
*)
3325 parse_memcachemode(SquidConfig
*)
3327 char *token
= ConfigParser::NextToken();
3333 if (strcmp(token
, "always") == 0) {
3334 Config
.onoff
.memory_cache_first
= 1;
3335 Config
.onoff
.memory_cache_disk
= 1;
3336 } else if (strcmp(token
, "disk") == 0) {
3337 Config
.onoff
.memory_cache_first
= 0;
3338 Config
.onoff
.memory_cache_disk
= 1;
3339 } else if (strncmp(token
, "net", 3) == 0) {
3340 Config
.onoff
.memory_cache_first
= 1;
3341 Config
.onoff
.memory_cache_disk
= 0;
3342 } else if (strcmp(token
, "never") == 0) {
3343 Config
.onoff
.memory_cache_first
= 0;
3344 Config
.onoff
.memory_cache_disk
= 0;
3346 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3352 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&)
3354 storeAppendPrintf(entry
, "%s ", name
);
3355 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3356 storeAppendPrintf(entry
, "always");
3357 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3358 storeAppendPrintf(entry
, "disk");
3359 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3360 storeAppendPrintf(entry
, "network");
3361 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3362 storeAppendPrintf(entry
, "none");
3363 storeAppendPrintf(entry
, "\n");
3366 #include "cf_parser.cci"
3369 parseNeighborType(const char *s
)
3371 if (!strcmp(s
, "parent"))
3374 if (!strcmp(s
, "neighbor"))
3375 return PEER_SIBLING
;
3377 if (!strcmp(s
, "neighbour"))
3378 return PEER_SIBLING
;
3380 if (!strcmp(s
, "sibling"))
3381 return PEER_SIBLING
;
3383 if (!strcmp(s
, "multicast"))
3384 return PEER_MULTICAST
;
3386 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3388 return PEER_SIBLING
;
3393 parse_IpAddress_list(Ip::Address_list
** head
)
3396 Ip::Address_list
*s
;
3399 while ((token
= ConfigParser::NextToken())) {
3400 if (GetHostWithPort(token
, &ipa
)) {
3403 head
= &(*head
)->next
;
3405 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3417 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3419 char ntoabuf
[MAX_IPSTRLEN
];
3422 storeAppendPrintf(e
, "%s %s\n",
3424 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3430 free_IpAddress_list(Ip::Address_list
** head
)
3432 if (*head
) delete *head
;
3436 #if CURRENTLY_UNUSED
3437 /* This code was previously used by http_port. Left as it really should
3438 * be used by icp_port and htcp_port
3441 check_null_IpAddress_list(const Ip::Address_list
* s
)
3446 #endif /* CURRENTLY_UNUSED */
3447 #endif /* USE_WCCPv2 */
3450 parsePortSpecification(const AnyP::PortCfgPointer
&s
, char *token
)
3453 unsigned short port
= 0;
3457 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3458 s
->name
= xstrdup(token
);
3459 s
->connection_auth_disabled
= false;
3461 const SBuf
&portType
= AnyP::UriScheme(s
->transport
.protocol
).image();
3463 if (*token
== '[') {
3466 t
= strchr(host
, ']');
3468 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3475 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3479 if (!Ip::EnableIpv6
) {
3480 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3484 port
= xatos(t
+ 1);
3485 } else if ((t
= strchr(token
, ':'))) {
3490 port
= xatos(t
+ 1);
3492 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3493 port
= xatos(token
);
3494 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3496 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3501 if (port
== 0 && host
!= NULL
) {
3502 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3510 if (!Ip::EnableIpv6
)
3512 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3513 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3515 if (!Ip::EnableIpv6
)
3517 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3518 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3519 /* do not use ipcache */
3520 s
->defaultsite
= xstrdup(host
);
3522 if (!Ip::EnableIpv6
)
3524 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3526 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3531 /// parses the protocol= option of the *_port directive, returning parsed value
3532 /// unsupported option values result in a fatal error message
3533 /// upper case values required; caller may convert for backward compatibility
3534 static AnyP::ProtocolVersion
3535 parsePortProtocol(const SBuf
&value
)
3537 // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3538 // and RFC 2616 requires us to upgrade 1.0 to 1.1
3539 if (value
.cmp("HTTP") == 0 || value
.cmp("HTTP/1.1") == 0)
3540 return Http::ProtocolVersion(1,1);
3542 if (value
.cmp("HTTPS") == 0 || value
.cmp("HTTPS/1.1") == 0)
3543 return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS
, 1,1);
3545 if (value
.cmp("FTP") == 0)
3546 return Ftp::ProtocolVersion();
3548 fatalf("%s directive does not support protocol=" SQUIDSBUFPH
"\n", cfg_directive
, SQUIDSBUFPRINT(value
));
3549 return AnyP::ProtocolVersion(); // not reached
3553 parse_port_option(AnyP::PortCfgPointer
&s
, char *token
)
3557 if (strcmp(token
, "accel") == 0) {
3558 if (s
->flags
.isIntercepted()) {
3559 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3563 s
->flags
.accelSurrogate
= true;
3565 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3566 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3567 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3571 s
->flags
.natIntercept
= true;
3572 Ip::Interceptor
.StartInterception();
3573 /* Log information regarding the port modes under interception. */
3574 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3575 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3576 } else if (strcmp(token
, "tproxy") == 0) {
3577 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3578 debugs(3,DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3582 s
->flags
.tproxyIntercept
= true;
3583 Ip::Interceptor
.StartTransparency();
3584 /* Log information regarding the port modes under transparency. */
3585 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3587 if (s
->flags
.proxySurrogate
) {
3588 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3591 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3592 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY support in the system does not work.");
3597 } else if (strcmp(token
, "require-proxy-header") == 0) {
3598 s
->flags
.proxySurrogate
= true;
3599 if (s
->flags
.tproxyIntercept
) {
3600 // receiving is still permitted, so we do not unset the TPROXY flag
3601 // spoofing access control override takes care of the spoof disable later
3602 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3605 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3606 if (!s
->flags
.accelSurrogate
) {
3607 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": defaultsite option requires Acceleration mode flag.");
3611 safe_free(s
->defaultsite
);
3612 s
->defaultsite
= xstrdup(token
+ 12);
3613 } else if (strcmp(token
, "vhost") == 0) {
3614 if (!s
->flags
.accelSurrogate
) {
3615 debugs(3, DBG_CRITICAL
, "WARNING: " << cfg_directive
<< ": vhost option is deprecated. Use 'accel' mode flag instead.");
3617 s
->flags
.accelSurrogate
= true;
3619 } else if (strcmp(token
, "no-vhost") == 0) {
3620 if (!s
->flags
.accelSurrogate
) {
3621 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": no-vhost option requires Acceleration mode flag.");
3624 } else if (strcmp(token
, "vport") == 0) {
3625 if (!s
->flags
.accelSurrogate
) {
3626 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3631 } else if (strncmp(token
, "vport=", 6) == 0) {
3632 if (!s
->flags
.accelSurrogate
) {
3633 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3637 s
->vport
= xatos(token
+ 6);
3638 } else if (strncmp(token
, "protocol=", 9) == 0) {
3639 if (!s
->flags
.accelSurrogate
) {
3640 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": protocol option requires Acceleration mode flag.");
3644 s
->transport
= parsePortProtocol(ToUpper(SBuf(token
+ 9)));
3645 } else if (strcmp(token
, "allow-direct") == 0) {
3646 if (!s
->flags
.accelSurrogate
) {
3647 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": allow-direct option requires Acceleration mode flag.");
3651 s
->allow_direct
= true;
3652 } else if (strcmp(token
, "act-as-origin") == 0) {
3653 if (!s
->flags
.accelSurrogate
) {
3654 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": act-as-origin option requires Acceleration mode flag.");
3656 s
->actAsOrigin
= true;
3657 } else if (strcmp(token
, "ignore-cc") == 0) {
3658 #if !USE_HTTP_VIOLATIONS
3659 if (!s
->flags
.accelSurrogate
) {
3660 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": ignore-cc option requires Acceleration mode flag.");
3665 s
->ignore_cc
= true;
3666 } else if (strncmp(token
, "name=", 5) == 0) {
3668 s
->name
= xstrdup(token
+ 5);
3669 } else if (strcmp(token
, "no-connection-auth") == 0) {
3670 s
->connection_auth_disabled
= true;
3671 } else if (strcmp(token
, "connection-auth=off") == 0) {
3672 s
->connection_auth_disabled
= true;
3673 } else if (strcmp(token
, "connection-auth") == 0) {
3674 s
->connection_auth_disabled
= false;
3675 } else if (strcmp(token
, "connection-auth=on") == 0) {
3676 s
->connection_auth_disabled
= false;
3677 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3678 if (!strcmp(token
+ 23, "off"))
3679 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3680 else if (!strcmp(token
+ 23, "transparent"))
3681 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3682 else if (!strcmp(token
+ 23, "always"))
3683 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3688 } else if (strcmp(token
, "ipv4") == 0) {
3689 if ( !s
->s
.setIPv4() ) {
3690 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3694 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3695 s
->tcp_keepalive
.enabled
= true;
3696 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3697 char *t
= token
+ 13;
3698 s
->tcp_keepalive
.enabled
= true;
3699 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3703 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3708 s
->tcp_keepalive
.timeout
= xatoui(t
);
3711 } else if (strcmp(token
, "sslBump") == 0) {
3712 debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token
<< "' is deprecated " <<
3713 "in " << cfg_directive
<< ". Use 'ssl-bump' instead.");
3714 s
->flags
.tunnelSslBumping
= true;
3715 } else if (strcmp(token
, "ssl-bump") == 0) {
3716 s
->flags
.tunnelSslBumping
= true;
3717 } else if (strncmp(token
, "cert=", 5) == 0) {
3718 s
->secure
.parse(token
);
3719 } else if (strncmp(token
, "key=", 4) == 0) {
3720 s
->secure
.parse(token
);
3721 } else if (strncmp(token
, "version=", 8) == 0) {
3722 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3723 "in " << cfg_directive
<< ". Use 'options=' instead.");
3724 s
->secure
.parse(token
);
3725 } else if (strncmp(token
, "options=", 8) == 0) {
3726 s
->secure
.parse(token
);
3727 } else if (strncmp(token
, "cipher=", 7) == 0) {
3728 s
->secure
.parse(token
);
3729 } else if (strncmp(token
, "clientca=", 9) == 0) {
3730 s
->secure
.parse(token
);
3731 } else if (strncmp(token
, "cafile=", 7) == 0) {
3732 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3733 "in " << cfg_directive
<< ". Use 'tls-cafile=' instead.");
3734 s
->secure
.parse(token
);
3735 } else if (strncmp(token
, "capath=", 7) == 0) {
3736 s
->secure
.parse(token
);
3737 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3738 s
->secure
.parse(token
);
3739 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3740 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: '" << token
<< "' is deprecated " <<
3741 "in " << cfg_directive
<< ". Use 'tls-dh=' instead.");
3742 s
->secure
.parse(token
);
3743 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3744 // NP: deprecation warnings output by secure.parse() when relevant
3745 s
->secure
.parse(token
+3);
3746 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3747 // NP: deprecation warnings output by secure.parse() when relevant
3748 s
->secure
.parse(token
+3);
3749 } else if (strncmp(token
, "generate-host-certificates", 26) == 0) {
3750 s
->secure
.parse(token
);
3752 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3753 s
->secure
.parse(token
);
3754 } else if (strncmp(token
, "tls-", 4) == 0) {
3755 s
->secure
.parse(token
+4);
3756 } else if (strcmp(token
, "ftp-track-dirs") == 0) {
3757 s
->ftp_track_dirs
= true;
3758 } else if (strcmp(token
, "worker-queues") == 0) {
3759 #if !defined(SO_REUSEADDR)
3760 #error missing system #include that #defines SO_* constants
3762 #if !defined(SO_REUSEPORT)
3763 throw TexcHere(ToSBuf(cfg_directive
, ' ', token
, " option requires building Squid where SO_REUSEPORT is supported by the TCP stack"));
3765 s
->workerQueues
= true;
3767 debugs(3, DBG_CRITICAL
, "FATAL: Unknown " << cfg_directive
<< " option '" << token
<< "'.");
3773 add_http_port(char *portspec
)
3775 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3776 s
->transport
= parsePortProtocol(SBuf("HTTP"));
3777 parsePortSpecification(s
, portspec
);
3778 // we may need to merge better if the above returns a list with clones
3779 assert(s
->next
== NULL
);
3780 s
->next
= HttpPortList
;
3785 parsePortCfg(AnyP::PortCfgPointer
*head
, const char *optionName
)
3788 if (strcmp(optionName
, "http_port") == 0 ||
3789 strcmp(optionName
, "ascii_port") == 0)
3791 else if (strcmp(optionName
, "https_port") == 0)
3792 protoName
= "HTTPS";
3793 else if (strcmp(optionName
, "ftp_port") == 0)
3795 if (protoName
.isEmpty()) {
3800 char *token
= ConfigParser::NextToken();
3807 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3808 s
->transport
= parsePortProtocol(protoName
); // default; protocol=... overwrites
3809 parsePortSpecification(s
, token
);
3811 /* parse options ... */
3812 while ((token
= ConfigParser::NextToken())) {
3813 parse_port_option(s
, token
);
3816 s
->secure
.syncCaFiles();
3818 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3819 s
->secure
.encryptTransport
= true;
3821 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3822 const bool hijacked
= s
->flags
.isIntercepted();
3823 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3824 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3828 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3829 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3834 if (s
->flags
.proxySurrogate
) {
3835 debugs(3,DBG_CRITICAL
, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3839 } else if (protoName
.cmp("FTP") == 0) {
3840 /* ftp_port does not support ssl-bump */
3841 if (s
->flags
.tunnelSslBumping
) {
3842 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump is not supported for ftp_port.");
3846 if (s
->flags
.proxySurrogate
) {
3847 // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3848 debugs(3,DBG_CRITICAL
, "FATAL: require-proxy-header option is not supported on ftp_port.");
3854 if (s
->secure
.encryptTransport
) {
3855 if (s
->secure
.certs
.empty()) {
3856 debugs(3, DBG_CRITICAL
, "FATAL: " << AnyP::UriScheme(s
->transport
.protocol
) << "_port requires a cert= parameter");
3860 s
->secure
.parseOptions();
3863 // *_port line should now be fully valid so we can clone it if necessary
3864 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3865 // clone the port options from *s to *(s->next)
3866 s
->next
= s
->clone();
3867 s
->next
->s
.setIPv4();
3868 debugs(3, 3, AnyP::UriScheme(s
->transport
.protocol
).image() << "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3871 while (*head
!= NULL
)
3872 head
= &((*head
)->next
);
3878 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3880 char buf
[MAX_IPSTRLEN
];
3882 storeAppendPrintf(e
, "%s %s",
3884 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3886 // MODES and specific sub-options.
3887 if (s
->flags
.natIntercept
)
3888 storeAppendPrintf(e
, " intercept");
3890 else if (s
->flags
.tproxyIntercept
)
3891 storeAppendPrintf(e
, " tproxy");
3893 else if (s
->flags
.proxySurrogate
)
3894 storeAppendPrintf(e
, " require-proxy-header");
3896 else if (s
->flags
.accelSurrogate
) {
3897 storeAppendPrintf(e
, " accel");
3900 storeAppendPrintf(e
, " vhost");
3903 storeAppendPrintf(e
, " vport");
3904 else if (s
->vport
> 0)
3905 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3908 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3910 // TODO: compare against prefix of 'n' instead of assuming http_port
3911 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3912 storeAppendPrintf(e
, " protocol=%s", AnyP::ProtocolType_str
[s
->transport
.protocol
]);
3914 if (s
->allow_direct
)
3915 storeAppendPrintf(e
, " allow-direct");
3918 storeAppendPrintf(e
, " ignore-cc");
3922 // Generic independent options
3925 storeAppendPrintf(e
, " name=%s", s
->name
);
3927 #if USE_HTTP_VIOLATIONS
3928 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3929 storeAppendPrintf(e
, " ignore-cc");
3932 if (s
->connection_auth_disabled
)
3933 storeAppendPrintf(e
, " connection-auth=off");
3935 storeAppendPrintf(e
, " connection-auth=on");
3937 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3940 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3943 pmtu
= "transparent";
3945 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3948 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3949 storeAppendPrintf(e
, " ipv4");
3951 if (s
->tcp_keepalive
.enabled
) {
3952 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3953 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3955 storeAppendPrintf(e
, " tcpkeepalive");
3960 if (s
->flags
.tunnelSslBumping
)
3961 storeAppendPrintf(e
, " ssl-bump");
3964 s
->secure
.dumpCfg(e
, "tls-");
3968 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3970 for (AnyP::PortCfgPointer p
= s
; p
!= NULL
; p
= p
->next
) {
3971 dump_generic_port(e
, n
, p
);
3972 storeAppendPrintf(e
, "\n");
3977 configFreeMemory(void)
3980 Config
.ssl_client
.sslContext
.reset();
3982 Ssl::unloadSquidUntrusted();
3987 requirePathnameExists(const char *name
, const char *path
)
3991 char pathbuf
[BUFSIZ
];
3992 assert(path
!= NULL
);
3994 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3995 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3999 if (stat(path
, &sb
) < 0) {
4001 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL: ":"ERROR: ") << name
<< " " << path
<< ": " << xstrerr(xerrno
));
4002 // keep going to find more issues if we are only checking the config file with "-k parse"
4003 if (opt_parse_cfg_only
)
4005 // this is fatal if it is found during startup or reconfigure
4006 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4007 fatalf("%s %s: %s", name
, path
, xstrerr(xerrno
));
4011 #include "AccessLogEntry.h"
4014 * We support several access_log configuration styles:
4016 * #1: Deprecated ancient style without an explicit logging module:
4017 * access_log /var/log/access.log
4019 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
4020 * access_log none [acl ...]
4022 * #3: Configurable logging module without named options:
4023 * Logformat or the first ACL name, whichever comes first, may not contain '='.
4024 * If no explicit logformat name is given, the first ACL name, if any,
4025 * should not be an existing logformat name or it will be treated as such.
4026 * access_log module:place [logformat_name] [acl ...]
4028 * #4: Configurable logging module with name=value options such as logformat=x:
4029 * The first ACL name may not contain '='.
4030 * Without any optional parts, directives using this style are indistinguishable
4031 * from directives using style #1 until we start requiring the "module:" prefix.
4032 * access_log module:place [option ...] [acl ...]
4036 parse_access_log(CustomLog
** logs
)
4038 const char *filename
= ConfigParser::NextToken();
4044 const auto cl
= new CustomLog();
4046 cl
->filename
= xstrdup(filename
);
4048 if (strcmp(filename
, "none") == 0) {
4049 cl
->type
= Log::Format::CLF_NONE
;
4050 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
4052 logs
= &(*logs
)->next
;
4057 const char *token
= ConfigParser::PeekAtToken();
4058 if (token
&& !strchr(token
, '=')) { // style #3
4059 // TODO: Deprecate this style to avoid this dangerous guessing.
4060 if (Log::TheConfig
.knownFormat(token
)) {
4061 cl
->setLogformat(token
);
4062 (void)ConfigParser::NextToken(); // consume the token used above
4064 // assume there is no explicit logformat name and use the default
4065 cl
->setLogformat("squid");
4067 } else { // style #1 or style #4
4068 // TODO: Drop deprecated style #1 support. We already warn about it, and
4069 // its exceptional treatment makes detecting "module" typos impractical!
4070 cl
->parseOptions(LegacyParser
, "squid");
4072 assert(cl
->type
); // setLogformat() was called
4074 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4077 logs
= &(*logs
)->next
;
4083 check_null_access_log(CustomLog
*customlog_definitions
)
4085 return customlog_definitions
== NULL
;
4089 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4092 for (auto log
= logs
; log
; log
= log
->next
) {
4094 PackableStream
os(*entry
);
4095 os
<< name
; // directive name
4096 os
<< ' ' << log
->filename
; // including "none"
4097 log
->dumpOptions(os
);
4101 dump_acl_list(entry
, log
->aclList
);
4103 storeAppendPrintf(entry
, "\n");
4108 free_access_log(CustomLog
** definitions
)
4110 while (*definitions
) {
4111 CustomLog
*log
= *definitions
;
4112 *definitions
= log
->next
;
4117 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4118 /// parses list of integers form name=N1,N2,N3,...
4120 parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
)
4122 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4123 data
+= name
.size();
4128 if (!StringToInt(data
, value
, &data
, 10))
4130 list
.push_back(value
);
4131 if (*data
== '\0' || *data
!= ',')
4136 return data
&& *data
== '\0';
4141 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4143 #if !HAVE_CPU_AFFINITY
4144 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4145 "support, do not set 'cpu_affinity_map'");
4148 #else /* HAVE_CPU_AFFINITY */
4149 if (!*cpuAffinityMap
)
4150 *cpuAffinityMap
= new CpuAffinityMap
;
4152 const char *const pToken
= ConfigParser::NextToken();
4153 const char *const cToken
= ConfigParser::NextToken();
4154 std::vector
<int> processes
, cores
;
4155 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4156 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4157 "in 'cpu_affinity_map'");
4159 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4160 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4161 "'cpu_affinity_map'");
4163 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4164 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4165 "process_numbers and cores lists differ in length or " <<
4166 "contain numbers <= 0");
4173 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4175 if (cpuAffinityMap
) {
4176 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4177 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4178 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4179 cpuAffinityMap
->processes()[i
]);
4181 storeAppendPrintf(entry
, " cores=");
4182 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4183 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4184 cpuAffinityMap
->cores()[i
]);
4186 storeAppendPrintf(entry
, "\n");
4191 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4193 delete *cpuAffinityMap
;
4194 *cpuAffinityMap
= NULL
;
4200 parse_adaptation_service_set_type()
4202 Adaptation::Config::ParseServiceSet();
4206 parse_adaptation_service_chain_type()
4208 Adaptation::Config::ParseServiceChain();
4212 parse_adaptation_access_type()
4214 Adaptation::Config::ParseAccess(LegacyParser
);
4216 #endif /* USE_ADAPTATION */
4221 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4223 cfg
->parseService();
4227 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4233 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4235 cfg
.dumpService(entry
, name
);
4239 parse_icap_class_type()
4241 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is deprecated. " <<
4242 "Use 'adaptation_service_set' instead");
4243 Adaptation::Config::ParseServiceSet();
4247 parse_icap_access_type()
4249 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is deprecated. " <<
4250 "Use 'adaptation_access' instead");
4251 Adaptation::Config::ParseAccess(LegacyParser
);
4259 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4261 cfg
->parseService();
4265 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4271 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4273 cfg
.dumpService(entry
, name
);
4276 #endif /* USE_ECAP */
4279 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4282 cfg
->service_failure_limit
= GetInteger();
4284 if ((token
= ConfigParser::NextToken()) == NULL
)
4287 if (strcmp(token
,"in") != 0) {
4288 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4293 parse_time_t(&cfg
->oldest_service_failure
);
4296 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4298 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4299 if (cfg
.oldest_service_failure
> 0) {
4300 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4302 storeAppendPrintf(entry
, "\n");
4305 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4307 cfg
->oldest_service_failure
= 0;
4308 cfg
->service_failure_limit
= 0;
4313 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4316 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4317 if ((al
= ConfigParser::NextToken()) == NULL
) {
4324 if ( char *s
= strchr(al
, '{')) {
4325 *s
= '\0'; // terminate the al string
4338 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4339 ca
->alg
= Ssl::algSetValidAfter
;
4340 ca
->param
= xstrdup("on");
4341 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4342 ca
->alg
= Ssl::algSetValidBefore
;
4343 ca
->param
= xstrdup("on");
4344 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4345 ca
->alg
= Ssl::algSetCommonName
;
4347 if (strlen(param
) > 64) {
4348 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4353 ca
->param
= xstrdup(param
);
4356 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4362 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4365 cert_adapt
= &(*cert_adapt
)->next
;
4370 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4372 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4373 storeAppendPrintf(entry
, "%s ", name
);
4374 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4376 dump_acl_list(entry
, ca
->aclList
);
4377 storeAppendPrintf(entry
, "\n");
4381 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4383 while (*cert_adapt
) {
4384 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4385 *cert_adapt
= ca
->next
;
4386 safe_free(ca
->param
);
4389 aclDestroyAclList(&ca
->aclList
);
4395 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4398 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4399 if ((al
= ConfigParser::NextToken()) == NULL
) {
4405 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4406 cs
->alg
= Ssl::algSignTrusted
;
4407 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4408 cs
->alg
= Ssl::algSignUntrusted
;
4409 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4410 cs
->alg
= Ssl::algSignSelf
;
4412 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4418 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4421 cert_sign
= &(*cert_sign
)->next
;
4426 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4428 sslproxy_cert_sign
*cs
;
4429 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4430 storeAppendPrintf(entry
, "%s ", name
);
4431 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4433 dump_acl_list(entry
, cs
->aclList
);
4434 storeAppendPrintf(entry
, "\n");
4438 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4440 while (*cert_sign
) {
4441 sslproxy_cert_sign
*cs
= *cert_sign
;
4442 *cert_sign
= cs
->next
;
4445 aclDestroyAclList(&cs
->aclList
);
4451 class sslBumpCfgRr
: public ::RegisteredRunner
4454 static Ssl::BumpMode lastDeprecatedRule
;
4455 /* RegisteredRunner API */
4456 virtual void finalizeConfig();
4459 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4461 RunnerRegistrationEntry(sslBumpCfgRr
);
4464 sslBumpCfgRr::finalizeConfig()
4466 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4467 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4468 static char buf
[1024];
4469 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4470 strcpy(buf
, "ssl_bump deny all");
4471 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4472 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4473 "must not use implicit rules. Update your ssl_bump rules.");
4475 strcpy(buf
, "ssl_bump allow all");
4476 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4477 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4478 "inferior to the newer server-first bumping mode. New ssl_bump"
4479 " configurations must not use implicit rules. Update your ssl_bump rules.");
4485 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4487 typedef const char *BumpCfgStyle
;
4488 BumpCfgStyle bcsNone
= NULL
;
4489 BumpCfgStyle bcsNew
= "new client/server-first/none";
4490 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4491 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4492 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4494 if ((bm
= ConfigParser::NextToken()) == NULL
) {
4499 // if this is the first rule processed
4500 if (*ssl_bump
== NULL
) {
4501 bumpCfgStyleLast
= bcsNone
;
4502 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4505 auto action
= Acl::Answer(ACCESS_ALLOWED
);
4507 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4508 action
.kind
= Ssl::bumpClientFirst
;
4509 bumpCfgStyleNow
= bcsNew
;
4510 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4511 action
.kind
= Ssl::bumpServerFirst
;
4512 bumpCfgStyleNow
= bcsNew
;
4513 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpPeek
]) == 0) {
4514 action
.kind
= Ssl::bumpPeek
;
4515 bumpCfgStyleNow
= bcsNew
;
4516 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpStare
]) == 0) {
4517 action
.kind
= Ssl::bumpStare
;
4518 bumpCfgStyleNow
= bcsNew
;
4519 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpSplice
]) == 0) {
4520 action
.kind
= Ssl::bumpSplice
;
4521 bumpCfgStyleNow
= bcsNew
;
4522 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpBump
]) == 0) {
4523 action
.kind
= Ssl::bumpBump
;
4524 bumpCfgStyleNow
= bcsNew
;
4525 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpTerminate
]) == 0) {
4526 action
.kind
= Ssl::bumpTerminate
;
4527 bumpCfgStyleNow
= bcsNew
;
4528 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4529 action
.kind
= Ssl::bumpNone
;
4530 bumpCfgStyleNow
= bcsNew
;
4531 } else if (strcmp(bm
, "allow") == 0) {
4532 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4533 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4534 "is usually inferior to the newer server-first "
4535 "bumping mode. Update your ssl_bump rules.");
4536 action
.kind
= Ssl::bumpClientFirst
;
4537 bumpCfgStyleNow
= bcsOld
;
4538 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4539 } else if (strcmp(bm
, "deny") == 0) {
4540 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4541 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4542 "your ssl_bump rules.");
4543 action
.kind
= Ssl::bumpNone
;
4544 bumpCfgStyleNow
= bcsOld
;
4545 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4547 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4552 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4553 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4554 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4559 bumpCfgStyleLast
= bumpCfgStyleNow
;
4562 ParseAclWithAction(ssl_bump
, action
, "ssl_bump");
4565 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4568 dump_SBufList(entry
, ssl_bump
->treeDump(name
, [](const Acl::Answer
&action
) {
4569 return Ssl::BumpModeStr
.at(action
.kind
);
4573 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4575 free_acl_access(ssl_bump
);
4580 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4585 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4586 storeAppendPrintf(entry
, "%s %s %s", name
, hwa
->fieldName
.c_str(), hwa
->fieldValue
.c_str());
4588 dump_acl_list(entry
, hwa
->aclList
);
4589 storeAppendPrintf(entry
, "\n");
4593 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4597 *headers
= new HeaderWithAclList
;
4599 if ((fn
= ConfigParser::NextToken()) == NULL
) {
4605 hwa
.fieldId
= Http::HeaderLookupTable
.lookup(hwa
.fieldName
).id
;
4606 if (hwa
.fieldId
== Http::HdrType::BAD_HDR
)
4607 hwa
.fieldId
= Http::HdrType::OTHER
;
4609 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4610 ConfigParser::EnableMacros();
4611 String buf
= ConfigParser::NextQuotedToken();
4612 ConfigParser::DisableMacros();
4613 hwa
.fieldValue
= buf
.termedBuf();
4614 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4616 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4620 hwa
.valueFormat
= nlf
;
4623 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4624 (*headers
)->push_back(hwa
);
4627 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4632 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4634 aclDestroyAclList(&hwa
->aclList
);
4636 if (hwa
->valueFormat
) {
4637 delete hwa
->valueFormat
;
4638 hwa
->valueFormat
= NULL
;
4645 static void parse_note(Notes
*notes
)
4648 notes
->parse(LegacyParser
);
4651 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4653 notes
.dump(entry
, name
);
4656 static void free_note(Notes
*notes
)
4661 static bool FtpEspvDeprecated
= false;
4662 static void parse_ftp_epsv(acl_access
**ftp_epsv
)
4664 Acl::Answer ftpEpsvDeprecatedAction
;
4665 bool ftpEpsvIsDeprecatedRule
= false;
4667 char *t
= ConfigParser::PeekAtToken();
4673 if (!strcmp(t
, "off")) {
4674 (void)ConfigParser::NextToken();
4675 ftpEpsvIsDeprecatedRule
= true;
4676 ftpEpsvDeprecatedAction
= Acl::Answer(ACCESS_DENIED
);
4677 } else if (!strcmp(t
, "on")) {
4678 (void)ConfigParser::NextToken();
4679 ftpEpsvIsDeprecatedRule
= true;
4680 ftpEpsvDeprecatedAction
= Acl::Answer(ACCESS_ALLOWED
);
4683 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4684 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4685 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4687 if ((!ftpEpsvIsDeprecatedRule
&& FtpEspvDeprecated
) ||
4688 (ftpEpsvIsDeprecatedRule
&& !FtpEspvDeprecated
&& *ftp_epsv
!= NULL
)) {
4689 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.");
4694 if (ftpEpsvIsDeprecatedRule
) {
4695 // overwrite previous ftp_epsv lines
4697 *ftp_epsv
= nullptr;
4699 if (ftpEpsvDeprecatedAction
== Acl::Answer(ACCESS_DENIED
)) {
4700 if (ACL
*a
= ACL::FindByName("all"))
4701 ParseAclWithAction(ftp_epsv
, ftpEpsvDeprecatedAction
, "ftp_epsv", a
);
4707 FtpEspvDeprecated
= true;
4709 aclParseAccessLine(cfg_directive
, LegacyParser
, ftp_epsv
);
4713 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
)
4716 dump_SBufList(entry
, ftp_epsv
->treeDump(name
, Acl::AllowOrDeny
));
4719 static void free_ftp_epsv(acl_access
**ftp_epsv
)
4721 free_acl_access(ftp_epsv
);
4722 FtpEspvDeprecated
= false;
4725 /// Like parseTimeLine() but does not require the timeunit to be specified.
4726 /// If missed, the default 'second' timeunit is assumed.
4727 static std::chrono::seconds
4728 ParseUrlRewriteTimeout()
4730 const auto timeValueToken
= ConfigParser::NextToken();
4731 if (!timeValueToken
)
4732 throw TexcHere("cannot read a time value");
4734 using Seconds
= std::chrono::seconds
;
4736 const auto parsedTimeValue
= xatof(timeValueToken
);
4738 if (parsedTimeValue
== 0)
4739 return std::chrono::seconds::zero();
4741 std::chrono::nanoseconds parsedUnitDuration
;
4743 const auto unitToken
= ConfigParser::PeekAtToken();
4744 if (parseTimeUnit
<Seconds
>(unitToken
, parsedUnitDuration
))
4745 (void)ConfigParser::NextToken();
4747 const auto defaultParsed
= parseTimeUnit
<Seconds
>(T_SECOND_STR
, parsedUnitDuration
);
4748 assert(defaultParsed
);
4749 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), ConfigParser::CurrentLocation() <<
4750 ": WARNING: missing time unit, using deprecated default '" << T_SECOND_STR
<< "'");
4753 const auto nanoseconds
= ToNanoSeconds(parsedTimeValue
, parsedUnitDuration
);
4755 return FromNanoseconds
<Seconds
>(nanoseconds
, parsedTimeValue
);
4759 parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4761 // TODO: do not allow optional timeunit (as the documentation prescribes)
4762 // and use parseTimeLine() instead.
4763 Config
.Timeout
.urlRewrite
= ParseUrlRewriteTimeout().count();
4766 while(ConfigParser::NextKvPair(key
, value
)) {
4767 if (strcasecmp(key
, "on_timeout") == 0) {
4768 if (strcasecmp(value
, "bypass") == 0)
4769 config
->action
= toutActBypass
;
4770 else if (strcasecmp(value
, "fail") == 0)
4771 config
->action
= toutActFail
;
4772 else if (strcasecmp(value
, "retry") == 0)
4773 config
->action
= toutActRetry
;
4774 else if (strcasecmp(value
, "use_configured_response") == 0) {
4775 config
->action
= toutActUseConfiguredResponse
;
4777 debugs(3, DBG_CRITICAL
, "FATAL: unsupported \"on_timeout\" action: " << value
);
4781 } else if (strcasecmp(key
, "response") == 0) {
4782 config
->response
= xstrdup(value
);
4784 debugs(3, DBG_CRITICAL
, "FATAL: unsupported option " << key
);
4790 if (config
->action
== toutActUseConfiguredResponse
&& !config
->response
) {
4791 debugs(3, DBG_CRITICAL
, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4795 if (config
->action
!= toutActUseConfiguredResponse
&& config
->response
) {
4796 debugs(3, DBG_CRITICAL
, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4802 dump_UrlHelperTimeout(StoreEntry
*entry
, const char *name
, SquidConfig::UrlHelperTimeout
&config
)
4804 const char *onTimedOutActions
[] = {"bypass", "fail", "retry", "use_configured_response"};
4805 assert(config
.action
>= 0 && config
.action
<= toutActUseConfiguredResponse
);
4807 dump_time_t(entry
, name
, Config
.Timeout
.urlRewrite
);
4808 storeAppendPrintf(entry
, " on_timeout=%s", onTimedOutActions
[config
.action
]);
4810 if (config
.response
)
4811 storeAppendPrintf(entry
, " response=\"%s\"", config
.response
);
4813 storeAppendPrintf(entry
, "\n");
4817 free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4819 Config
.Timeout
.urlRewrite
= 0;
4821 safe_free(config
->response
);
4825 parse_configuration_includes_quoted_values(bool *)
4830 // If quoted values is set to on then enable new strict mode parsing
4832 ConfigParser::RecognizeQuotedValues
= true;
4833 ConfigParser::StrictMode
= true;
4835 ConfigParser::RecognizeQuotedValues
= false;
4836 ConfigParser::StrictMode
= false;
4841 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool)
4843 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4844 dump_onoff(entry
, name
, val
);
4848 free_configuration_includes_quoted_values(bool *)
4850 ConfigParser::RecognizeQuotedValues
= false;
4851 ConfigParser::StrictMode
= false;
4855 parse_on_unsupported_protocol(acl_access
**access
)
4858 if ((tm
= ConfigParser::NextToken()) == NULL
) {
4863 auto action
= Acl::Answer(ACCESS_ALLOWED
);
4864 if (strcmp(tm
, "tunnel") == 0)
4866 else if (strcmp(tm
, "respond") == 0)
4869 debugs(3, DBG_CRITICAL
, "FATAL: unknown on_unsupported_protocol mode: " << tm
);
4875 ParseAclWithAction(access
, action
, "on_unsupported_protocol");
4879 dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
)
4881 static const std::vector
<const char *> onErrorTunnelMode
= {
4887 SBufList lines
= access
->treeDump(name
, [](const Acl::Answer
&action
) {
4888 return onErrorTunnelMode
.at(action
.kind
);
4890 dump_SBufList(entry
, lines
);
4895 free_on_unsupported_protocol(acl_access
**access
)
4897 free_acl_access(access
);
4901 parse_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuardsPtr
)
4903 assert(protoGuardsPtr
);
4904 auto &protoGuards
= *protoGuardsPtr
;
4906 protoGuards
= new HttpUpgradeProtocolAccess();
4907 protoGuards
->configureGuard(LegacyParser
);
4911 dump_http_upgrade_request_protocols(StoreEntry
*entry
, const char *rawName
, HttpUpgradeProtocolAccess
*protoGuards
)
4916 const SBuf
name(rawName
);
4917 protoGuards
->forEach([entry
,&name
](const SBuf
&proto
, const acl_access
*acls
) {
4919 line
.push_back(name
);
4920 line
.push_back(proto
);
4921 const auto acld
= acls
->treeDump("", &Acl::AllowOrDeny
);
4922 line
.insert(line
.end(), acld
.begin(), acld
.end());
4923 dump_SBufList(entry
, line
);
4928 free_http_upgrade_request_protocols(HttpUpgradeProtocolAccess
**protoGuardsPtr
)
4930 assert(protoGuardsPtr
);
4931 auto &protoGuards
= *protoGuardsPtr
;
4933 protoGuards
= nullptr;