2 * Copyright (C) 1996-2018 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/RunnersRegistry.h"
26 #include "CachePeer.h"
27 #include "ConfigParser.h"
28 #include "CpuAffinityMap.h"
29 #include "DiskIO/DiskIOModule.h"
30 #include "eui/Config.h"
31 #include "ExternalACL.h"
32 #include "format/Format.h"
33 #include "ftp/Elements.h"
35 #include "HttpHeaderTools.h"
36 #include "icmp/IcmpConfig.h"
37 #include "ident/Config.h"
38 #include "ip/Intercept.h"
39 #include "ip/NfMarkConfig.h"
40 #include "ip/QosConfig.h"
43 #include "log/Config.h"
44 #include "log/CustomLog.h"
46 #include "MessageDelayPools.h"
47 #include "mgr/ActionPasswordList.h"
48 #include "mgr/Registration.h"
49 #include "neighbors.h"
50 #include "NeighborTypeDomainList.h"
53 #include "PeerDigest.h"
54 #include "PeerPoolMgr.h"
56 #include "RefreshPattern.h"
58 #include "sbuf/List.h"
59 #include "sbuf/Stream.h"
60 #include "SquidConfig.h"
61 #include "SquidString.h"
62 #include "ssl/ProxyCerts.h"
64 #include "store/Disk.h"
65 #include "store/Disks.h"
66 #include "StoreFileSystem.h"
70 /* wccp2 has its own conditional definitions */
73 #include "adaptation/Config.h"
76 #include "adaptation/icap/Config.h"
79 #include "adaptation/ecap/Config.h"
82 #include "ssl/Config.h"
83 #include "ssl/support.h"
86 #include "esi/Parser.h"
104 #include <sys/stat.h>
108 #include "ssl/gadgets.h"
112 static void parse_adaptation_service_set_type();
113 static void parse_adaptation_service_chain_type();
114 static void parse_adaptation_access_type();
118 static void parse_icap_service_type(Adaptation::Icap::Config
*);
119 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
120 static void free_icap_service_type(Adaptation::Icap::Config
*);
121 static void parse_icap_class_type();
122 static void parse_icap_access_type();
124 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
125 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
126 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
130 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
131 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
132 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
135 static peer_t
parseNeighborType(const char *s
);
137 static const char *const T_MILLISECOND_STR
= "millisecond";
138 static const char *const T_SECOND_STR
= "second";
139 static const char *const T_MINUTE_STR
= "minute";
140 static const char *const T_HOUR_STR
= "hour";
141 static const char *const T_DAY_STR
= "day";
142 static const char *const T_WEEK_STR
= "week";
143 static const char *const T_FORTNIGHT_STR
= "fortnight";
144 static const char *const T_MONTH_STR
= "month";
145 static const char *const T_YEAR_STR
= "year";
146 static const char *const T_DECADE_STR
= "decade";
148 static const char *const B_BYTES_STR
= "bytes";
149 static const char *const B_KBYTES_STR
= "KB";
150 static const char *const B_MBYTES_STR
= "MB";
151 static const char *const B_GBYTES_STR
= "GB";
153 static const char *const list_sep
= ", \t\n\r";
155 static void parse_access_log(CustomLog
** customlog_definitions
);
156 static int check_null_access_log(CustomLog
*customlog_definitions
);
157 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
158 static void free_access_log(CustomLog
** definitions
);
159 static bool setLogformat(CustomLog
*cl
, const char *name
, const bool dieWhenMissing
);
161 static void configDoConfigure(void);
162 static void parse_refreshpattern(RefreshPattern
**);
163 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
164 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
, bool expectMoreArguments
);
165 static void parse_u_short(unsigned short * var
);
166 static void parse_string(char **);
167 static void default_all(void);
168 static void defaults_if_none(void);
169 static void defaults_postscriptum(void);
170 static int parse_line(char *);
171 static void parse_obsolete(const char *);
172 static void parseBytesLine(size_t * bptr
, const char *units
);
173 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
174 static size_t parseBytesUnits(const char *unit
);
175 static void free_all(void);
176 void requirePathnameExists(const char *name
, const char *path
);
177 static OBJH dump_config
;
178 #if USE_HTTP_VIOLATIONS
179 static void free_HeaderManglers(HeaderManglers
**pm
);
180 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
181 static void parse_http_header_access(HeaderManglers
**manglers
);
182 #define free_http_header_access free_HeaderManglers
183 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
184 static void parse_http_header_replace(HeaderManglers
**manglers
);
185 #define free_http_header_replace free_HeaderManglers
187 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
188 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
189 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
190 static void parse_note(Notes
*);
191 static void dump_note(StoreEntry
*, const char *, Notes
&);
192 static void free_note(Notes
*);
193 static void parse_denyinfo(AclDenyInfoList
** var
);
194 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
195 static void free_denyinfo(AclDenyInfoList
** var
);
198 static void parse_IpAddress_list(Ip::Address_list
**);
199 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
200 static void free_IpAddress_list(Ip::Address_list
**);
202 static int check_null_IpAddress_list(const Ip::Address_list
*);
203 #endif /* CURRENTLY_UNUSED */
204 #endif /* USE_WCCPv2 */
206 static void parsePortCfg(AnyP::PortCfgPointer
*, const char *protocol
);
207 #define parse_PortCfg(l) parsePortCfg((l), token)
208 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfgPointer
&);
209 #define free_PortCfg(h) *(h)=NULL
212 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
213 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
214 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
215 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
216 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
217 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
218 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
219 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
220 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
221 #endif /* USE_OPENSSL */
223 static void parse_ftp_epsv(acl_access
**ftp_epsv
);
224 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
);
225 static void free_ftp_epsv(acl_access
**ftp_epsv
);
227 static void parse_b_size_t(size_t * var
);
228 static void parse_b_int64_t(int64_t * var
);
230 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
231 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
232 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
234 static void parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
235 static void dump_UrlHelperTimeout(StoreEntry
*, const char *, SquidConfig::UrlHelperTimeout
&);
236 static void free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
238 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
240 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
241 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
242 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
243 static void parse_on_unsupported_protocol(acl_access
**access
);
244 static void dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
);
245 static void free_on_unsupported_protocol(acl_access
**access
);
246 static void ParseAclWithAction(acl_access
**access
, const allow_t
&action
, const char *desc
, ACL
*acl
= nullptr);
249 * LegacyParser is a parser for legacy code that uses the global
250 * approach. This is static so that it is only exposed to cache_cf.
251 * Other modules needing access to a ConfigParser should have it
252 * provided to them in their parserFOO methods.
254 static ConfigParser LegacyParser
= ConfigParser();
259 LegacyParser
.destruct();
263 SetConfigFilename(char const *file_name
, bool is_pipe
)
266 cfg_filename
= file_name
+ 1;
268 cfg_filename
= file_name
;
272 skip_ws(const char* s
)
281 parseManyConfigFiles(char* files
, int depth
)
284 char* saveptr
= NULL
;
289 memset(&globbuf
, 0, sizeof(globbuf
));
290 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
291 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
293 fatalf("Unable to find configuration file: %s: %s", path
, xstrerr(xerrno
));
296 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
297 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
301 char* file
= strwordtok(files
, &saveptr
);
302 while (file
!= NULL
) {
303 error_count
+= parseOneConfigFile(file
, depth
);
304 file
= strwordtok(NULL
, &saveptr
);
306 #endif /* HAVE_GLOB */
311 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
314 assert(newSubstr
!= NULL
);
316 unsigned newSubstrLen
= strlen(newSubstr
);
317 if (newSubstrLen
> substrLen
)
318 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
320 // move tail part including zero
321 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
322 // copy new substring in place
323 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
329 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
331 assert(line
!= NULL
);
332 assert(macroName
!= NULL
);
333 assert(substStr
!= NULL
);
334 unsigned macroNameLen
= strlen(macroName
);
335 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
336 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
340 ProcessMacros(char*& line
, int& len
)
342 SubstituteMacro(line
, len
, "${service_name}", service_name
.c_str());
343 SubstituteMacro(line
, len
, "${process_name}", TheKidName
.c_str());
344 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
348 trim_trailing_ws(char* str
)
351 unsigned i
= strlen(str
);
352 while ((i
> 0) && xisspace(str
[i
- 1]))
358 FindStatement(const char* line
, const char* statement
)
360 assert(line
!= NULL
);
361 assert(statement
!= NULL
);
363 const char* str
= skip_ws(line
);
364 unsigned len
= strlen(statement
);
365 if (strncmp(str
, statement
, len
) == 0) {
369 else if (xisspace(*str
))
377 StrToInt(const char* str
, long& number
)
382 number
= strtol(str
, &end
, 0);
384 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
388 EvalBoolExpr(const char* expr
)
390 assert(expr
!= NULL
);
391 if (strcmp(expr
, "true") == 0) {
393 } else if (strcmp(expr
, "false") == 0) {
395 } else if (const char* equation
= strchr(expr
, '=')) {
396 const char* rvalue
= skip_ws(equation
+ 1);
397 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
398 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
399 trim_trailing_ws(lvalue
);
402 if (!StrToInt(lvalue
, number1
))
403 fatalf("String is not a integer number: '%s'\n", lvalue
);
405 if (!StrToInt(rvalue
, number2
))
406 fatalf("String is not a integer number: '%s'\n", rvalue
);
409 return number1
== number2
;
411 fatalf("Unable to evaluate expression '%s'\n", expr
);
412 return false; // this place cannot be reached
416 parseOneConfigFile(const char *file_name
, unsigned int depth
)
419 const char *orig_cfg_filename
= cfg_filename
;
420 const int orig_config_lineno
= config_lineno
;
422 char *tmp_line
= NULL
;
423 int tmp_line_len
= 0;
427 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
429 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
433 if (file_name
[0] == '!' || file_name
[0] == '|') {
434 fp
= popen(file_name
+ 1, "r");
437 fp
= fopen(file_name
, "r");
442 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerr(xerrno
));
446 setmode(fileno(fp
), O_TEXT
);
449 SetConfigFilename(file_name
, bool(is_pipe
));
451 memset(config_input_line
, '\0', BUFSIZ
);
455 std::vector
<bool> if_states
;
456 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
459 if ((token
= strchr(config_input_line
, '\n')))
462 if ((token
= strchr(config_input_line
, '\r')))
465 // strip any prefix whitespace off the line.
466 const char *p
= skip_ws(config_input_line
);
467 if (config_input_line
!= p
)
468 memmove(config_input_line
, p
, strlen(p
)+1);
470 if (strncmp(config_input_line
, "#line ", 6) == 0) {
471 static char new_file_name
[1024];
473 static char new_lineno
;
474 token
= config_input_line
+ 6;
475 new_lineno
= strtol(token
, &file
, 0) - 1;
478 continue; /* Not a valid #line directive, may be a comment */
480 while (*file
&& xisspace((unsigned char) *file
))
485 continue; /* Not a valid #line directive, may be a comment */
487 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
489 if ((token
= strchr(new_file_name
, '"')))
492 SetConfigFilename(new_file_name
, false);
495 config_lineno
= new_lineno
;
498 if (config_input_line
[0] == '#')
501 if (config_input_line
[0] == '\0')
504 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
506 size_t append_len
= strlen(append
);
508 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
510 strcpy(tmp_line
+ tmp_line_len
, append
);
512 tmp_line_len
+= append_len
;
514 if (tmp_line
[tmp_line_len
-1] == '\\') {
515 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
516 tmp_line
[--tmp_line_len
] = '\0';
520 trim_trailing_ws(tmp_line
);
521 ProcessMacros(tmp_line
, tmp_line_len
);
522 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
524 if (const char* expr
= FindStatement(tmp_line
, "if")) {
525 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
526 } else if (FindStatement(tmp_line
, "endif")) {
527 if (!if_states
.empty())
528 if_states
.pop_back(); // remove last if-statement meaning
530 fatalf("'endif' without 'if'\n");
531 } else if (FindStatement(tmp_line
, "else")) {
532 if (!if_states
.empty())
533 if_states
.back() = !if_states
.back();
535 fatalf("'else' without 'if'\n");
536 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
537 /* Handle includes here */
538 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
539 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
540 } else if (!parse_line(tmp_line
)) {
541 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
550 if (!if_states
.empty())
551 fatalf("if-statement without 'endif'\n");
554 int ret
= pclose(fp
);
557 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
562 SetConfigFilename(orig_cfg_filename
, false);
563 config_lineno
= orig_config_lineno
;
571 parseConfigFileOrThrow(const char *file_name
)
579 ACLMethodData::ThePurgeCount
= 0;
582 err_count
= parseOneConfigFile(file_name
, 0);
586 defaults_postscriptum();
589 * We must call configDoConfigure() before leave_suid() because
590 * configDoConfigure() is where we turn username strings into
595 if (!Config
.chroot_dir
) {
597 setUmask(Config
.umask
);
598 _db_init(Debug::cache_log
, Debug::debugOptions
);
602 if (opt_send_signal
== -1) {
603 Mgr::RegisterAction("config",
604 "Current Squid Configuration",
612 // TODO: Refactor main.cc to centrally handle (and report) all exceptions.
614 parseConfigFile(const char *file_name
)
617 return parseConfigFileOrThrow(file_name
);
619 catch (const std::exception
&ex
) {
620 debugs(3, DBG_CRITICAL
, "FATAL: bad configuration: " << ex
.what());
622 return 1; // not reached
627 configDoConfigure(void)
630 /* init memory as early as possible */
634 Config
.cacheSwap
.n_strands
= 0; // no diskers by default
635 if (Config
.cacheSwap
.swapDirs
== NULL
) {
636 /* Memory-only cache probably in effect. */
637 /* turn off the cache rebuild delays... */
638 StoreController::store_dirs_rebuilding
= 0;
639 } else if (InDaemonMode()) { // no diskers in non-daemon mode
640 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
641 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
642 if (sd
->needsDiskStrand())
643 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
647 if (Debug::rotateNumber
< 0) {
648 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
651 #if SIZEOF_OFF_T <= 4
652 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
653 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
654 Config
.Store
.maxObjectSize
= 0x7FFF0000;
658 if (Config
.Announce
.period
> 0) {
659 Config
.onoff
.announce
= 1;
661 Config
.Announce
.period
= 86400 * 365; /* one year */
662 Config
.onoff
.announce
= 0;
665 if (Config
.onoff
.httpd_suppress_version_string
)
666 visible_appname_string
= (char *)appname_string
;
668 visible_appname_string
= (char const *)APP_FULLNAME
;
670 if (Config
.Program
.redirect
) {
671 if (Config
.redirectChildren
.n_max
< 1) {
672 Config
.redirectChildren
.n_max
= 0;
673 wordlistDestroy(&Config
.Program
.redirect
);
677 if (Config
.Program
.store_id
) {
678 if (Config
.storeIdChildren
.n_max
< 1) {
679 Config
.storeIdChildren
.n_max
= 0;
680 wordlistDestroy(&Config
.Program
.store_id
);
684 if (Config
.appendDomain
)
685 if (*Config
.appendDomain
!= '.')
686 fatal("append_domain must begin with a '.'");
688 if (Config
.errHtmlText
== NULL
)
689 Config
.errHtmlText
= xstrdup(null_string
);
691 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
692 if (Config
.max_filedescriptors
> 0) {
693 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
695 #elif USE_SELECT || USE_SELECT_WIN32
696 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
697 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
703 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
705 visible_appname_string
);
708 * the extra space is for loop detection in client_side.c -- we search
709 * for substrings in the Via header.
711 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
713 visible_appname_string
);
715 /* Use visible_hostname as default surrogate_id */
716 if (!Config
.Accel
.surrogate_id
) {
717 const char *t
= getMyHostname();
718 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
721 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
722 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
724 if (Config
.appendDomain
)
725 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
727 Config
.appendDomainLen
= 0;
729 if (Config
.connect_retries
> 10) {
730 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
731 Config
.connect_retries
= 10;
734 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
737 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
739 bool logDaemonUsed
= false;
740 for (const auto *log
= Config
.Log
.accesslogs
; !logDaemonUsed
&& log
; log
= log
->next
)
741 logDaemonUsed
= log
->usesDaemon();
743 for (const auto *log
= Config
.Log
.icaplogs
; !logDaemonUsed
&& log
; log
= log
->next
)
744 logDaemonUsed
= log
->usesDaemon();
747 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
749 if (Config
.Program
.redirect
)
750 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
752 if (Config
.Program
.store_id
)
753 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
755 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
757 if (Config
.errorDirectory
)
758 requirePathnameExists("Error Directory", Config
.errorDirectory
);
760 #if USE_HTTP_VIOLATIONS
763 const RefreshPattern
*R
;
765 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
766 if (!R
->flags
.override_expire
)
769 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
774 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
775 if (!R
->flags
.override_lastmod
)
778 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
783 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
784 if (!R
->flags
.reload_into_ims
)
787 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
792 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
793 if (!R
->flags
.ignore_reload
)
796 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
801 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
802 if (!R
->flags
.ignore_no_store
)
805 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
810 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
811 if (!R
->flags
.ignore_private
)
814 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
820 #if !USE_HTTP_VIOLATIONS
821 Config
.onoff
.via
= 1;
824 if (!Config
.onoff
.via
)
825 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
829 // we enable runtime PURGE checks if there is at least one PURGE method ACL
830 // TODO: replace with a dedicated "purge" ACL option?
831 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
833 if (geteuid() == 0) {
834 if (NULL
!= Config
.effectiveUser
) {
836 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
840 * Andres Kroonmaa <andre@online.ee>:
841 * Some getpwnam() implementations (Solaris?) require
842 * an available FD < 256 for opening a FILE* to the
845 * This should be safe at startup, but might still fail
846 * during reconfigure.
848 fatalf("getpwnam failed to find userid for effective user '%s'",
849 Config
.effectiveUser
);
853 Config2
.effectiveUserID
= pwd
->pw_uid
;
855 Config2
.effectiveGroupID
= pwd
->pw_gid
;
858 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
859 // putenv() leaks by design; avoid leaks when nothing changes
861 if (lastDir
.isEmpty() || lastDir
.cmp(pwd
->pw_dir
) != 0) {
862 lastDir
= pwd
->pw_dir
;
863 int len
= strlen(pwd
->pw_dir
) + 6;
864 char *env_str
= (char *)xcalloc(len
, 1);
865 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
872 Config2
.effectiveUserID
= geteuid();
873 Config2
.effectiveGroupID
= getegid();
876 if (NULL
!= Config
.effectiveGroup
) {
878 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
881 fatalf("getgrnam failed to find groupid for effective group '%s'",
882 Config
.effectiveGroup
);
886 Config2
.effectiveGroupID
= grp
->gr_gid
;
890 if (Config
.ssl_client
.foreignIntermediateCertsPath
)
891 Ssl::loadSquidUntrusted(Config
.ssl_client
.foreignIntermediateCertsPath
);
894 if (Security::ProxyOutgoingConfig
.encryptTransport
) {
895 debugs(3, DBG_IMPORTANT
, "Initializing https:// proxy context");
896 Config
.ssl_client
.sslContext
= Security::ProxyOutgoingConfig
.createClientContext(false);
897 if (!Config
.ssl_client
.sslContext
) {
899 fatal("ERROR: Could not initialize https:// proxy context");
901 debugs(3, DBG_IMPORTANT
, "ERROR: proxying https:// currently still requires --with-openssl");
905 Ssl::useSquidUntrusted(Config
.ssl_client
.sslContext
.get());
909 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
911 // default value for ssldomain= is the peer host/IP
912 if (p
->secure
.sslDomain
.isEmpty())
913 p
->secure
.sslDomain
= p
->host
;
915 if (p
->secure
.encryptTransport
) {
916 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " TLS context");
917 p
->sslContext
= p
->secure
.createClientContext(true);
918 if (!p
->sslContext
) {
919 debugs(3, DBG_CRITICAL
, "ERROR: Could not initialize cache_peer " << p
->name
<< " TLS context");
926 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
927 if (!s
->secure
.encryptTransport
)
929 debugs(3, DBG_IMPORTANT
, "Initializing " << AnyP::UriScheme(s
->transport
.protocol
) << "_port " << s
->s
<< " TLS contexts");
930 s
->secure
.initServerContexts(*s
);
933 // prevent infinite fetch loops in the request parser
934 // due to buffer full but not enough data recived to finish parse
935 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
936 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
937 " Change client_request_buffer_max or request_header_max_size limits.",
938 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
942 * Disable client side request pipelining if client_persistent_connections OFF.
943 * Waste of resources queueing any pipelined requests when the first will close the connection.
945 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
946 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
947 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
948 Config
.pipeline_max_prefetch
= 0;
953 * disable client side request pipelining. There is a race with
954 * Negotiate and NTLM when the client sends a second request on an
955 * connection before the authenticate challenge is sent. With
956 * pipelining OFF, the client may fail to authenticate, but squid's
957 * state will be preserved.
959 if (Config
.pipeline_max_prefetch
> 0) {
960 Auth::SchemeConfig
*nego
= Auth::SchemeConfig::Find("Negotiate");
961 Auth::SchemeConfig
*ntlm
= Auth::SchemeConfig::Find("NTLM");
962 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
963 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
964 Config
.pipeline_max_prefetch
= 0;
968 for (auto &authSchemes
: Auth::TheConfig
.schemeLists
) {
969 authSchemes
.expand();
970 if (authSchemes
.authConfigs
.empty()) {
971 debugs(3, DBG_CRITICAL
, "auth_schemes: at least one scheme name is required; got: " << authSchemes
.rawSchemes
);
978 /** Parse a line containing an obsolete directive.
979 * To upgrade it where possible instead of just "Bungled config" for
980 * directives which cannot be marked as simply aliases of the some name.
981 * For example if the parameter order and content has changed.
982 * Or if the directive has been completely removed.
985 parse_obsolete(const char *name
)
987 // Directives which have been radically changed rather than removed
988 if (!strcmp(name
, "url_rewrite_concurrency")) {
991 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
992 Config
.redirectChildren
.concurrency
= cval
;
995 if (!strcmp(name
, "log_access")) {
1000 if (!strcmp(name
, "log_icap")) {
1005 if (!strcmp(name
, "ignore_ims_on_miss")) {
1006 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1007 // than the 2.7 directive. We need to parse and invert the configured value.
1010 Config
.onoff
.cache_miss_revalidate
= !temp
;
1013 if (!strncmp(name
, "sslproxy_", 9)) {
1014 // the replacement directive tls_outgoing_options uses options instead of whole-line input
1016 if (!strcmp(name
, "sslproxy_cafile"))
1017 tmp
.append("cafile=");
1018 else if (!strcmp(name
, "sslproxy_capath"))
1019 tmp
.append("capath=");
1020 else if (!strcmp(name
, "sslproxy_cipher"))
1021 tmp
.append("cipher=");
1022 else if (!strcmp(name
, "sslproxy_client_certificate"))
1023 tmp
.append("cert=");
1024 else if (!strcmp(name
, "sslproxy_client_key"))
1026 else if (!strcmp(name
, "sslproxy_flags"))
1027 tmp
.append("flags=");
1028 else if (!strcmp(name
, "sslproxy_options"))
1029 tmp
.append("options=");
1030 else if (!strcmp(name
, "sslproxy_version"))
1031 tmp
.append("version=");
1033 debugs(3, DBG_CRITICAL
, "ERROR: unknown directive: " << name
);
1038 // add the value as unquoted-string because the old values did not support whitespace
1039 const char *token
= ConfigParser::NextQuotedOrToEol();
1040 tmp
.append(token
, strlen(token
));
1041 Security::ProxyOutgoingConfig
.parse(tmp
.c_str());
1045 /* Parse a time specification from the config file. Store the
1046 * result in 'tptr', after converting it to 'units' */
1048 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
, bool expectMoreArguments
= false)
1050 time_msec_t u
= parseTimeUnits(units
, allowMsec
);
1056 char *token
= ConfigParser::NextToken();;
1062 double d
= xatof(token
);
1064 time_msec_t m
= u
; /* default to 'units' if none specified */
1067 if ((token
= ConfigParser::PeekAtToken()) && (m
= parseTimeUnits(token
, allowMsec
))) {
1068 (void)ConfigParser::NextToken();
1070 } else if (!expectMoreArguments
) {
1075 token
= NULL
; // show default units if dying below
1076 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" << config_input_line
<< "', assuming " << d
<< " " << units
);
1079 token
= NULL
; // show default units if dying below.
1081 *tptr
= static_cast<time_msec_t
>(m
* d
);
1083 if (static_cast<double>(*tptr
) * 2 != m
* d
* 2) {
1084 debugs(3, DBG_CRITICAL
, "FATAL: Invalid value '" <<
1085 d
<< " " << (token
? token
: units
) << ": integer overflow (time_msec_t).");
1091 parseTimeUnits(const char *unit
, bool allowMsec
)
1093 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1096 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1099 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1102 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1105 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1106 return 86400 * 1000;
1108 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1109 return 86400 * 7 * 1000;
1111 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1112 return 86400 * 14 * 1000;
1114 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1115 return static_cast<uint64_t>(86400) * 30 * 1000;
1117 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1118 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1120 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1121 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1123 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1129 parseBytesLine64(int64_t * bptr
, const char *units
)
1136 if ((u
= parseBytesUnits(units
)) == 0) {
1141 if ((token
= ConfigParser::NextToken()) == NULL
) {
1146 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1153 m
= u
; /* default to 'units' if none specified */
1157 else if ((token
= ConfigParser::NextToken()) == NULL
)
1158 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1159 config_input_line
<< "', assuming " <<
1160 d
<< " " << units
);
1161 else if ((m
= parseBytesUnits(token
)) == 0) {
1166 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1168 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1169 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1170 d
<< " " << token
<< ": integer overflow (int64_t).");
1176 parseBytesLine(size_t * bptr
, const char *units
)
1183 if ((u
= parseBytesUnits(units
)) == 0) {
1188 if ((token
= ConfigParser::NextToken()) == NULL
) {
1193 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1194 *bptr
= static_cast<size_t>(-1);
1200 m
= u
; /* default to 'units' if none specified */
1204 else if ((token
= ConfigParser::NextToken()) == NULL
)
1205 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1206 config_input_line
<< "', assuming " <<
1207 d
<< " " << units
);
1208 else if ((m
= parseBytesUnits(token
)) == 0) {
1213 *bptr
= static_cast<size_t>(m
* d
/ u
);
1215 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1216 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1217 d
<< " " << token
<< ": integer overflow (size_t).");
1223 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1230 if ((u
= parseBytesUnits(units
)) == 0) {
1235 if ((token
= ConfigParser::NextToken()) == NULL
) {
1240 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1247 m
= u
; /* default to 'units' if none specified */
1251 else if ((token
= ConfigParser::NextToken()) == NULL
)
1252 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1253 config_input_line
<< "', assuming " <<
1254 d
<< " " << units
);
1255 else if ((m
= parseBytesUnits(token
)) == 0) {
1260 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1262 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1263 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1264 d
<< " " << token
<< ": integer overflow (ssize_t).");
1270 * Parse bytes from a string.
1271 * Similar to the parseBytesLine function but parses the string value instead of
1272 * the current token value.
1275 parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1278 if ((u
= parseBytesUnits(units
)) == 0) {
1283 // Find number from string beginning.
1284 char const * number_begin
= value
;
1285 char const * number_end
= value
;
1287 while ((*number_end
>= '0' && *number_end
<= '9')) {
1292 number
.limitInit(number_begin
, number_end
- number_begin
);
1294 int d
= xatoi(number
.termedBuf());
1296 if ((m
= parseBytesUnits(number_end
)) == 0) {
1301 *bptr
= static_cast<size_t>(m
* d
/ u
);
1302 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1307 parseBytesUnits(const char *unit
)
1309 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1312 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1315 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1318 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1321 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1327 parse_SBufList(SBufList
* list
)
1329 while (char *token
= ConfigParser::NextQuotedToken())
1330 list
->push_back(SBuf(token
));
1333 // just dump a list, no directive name
1335 dump_SBufList(StoreEntry
* entry
, const SBufList
&words
)
1337 for (const auto &i
: words
) {
1338 entry
->append(i
.rawContent(), i
.length());
1339 entry
->append(" ",1);
1341 entry
->append("\n",1);
1344 // dump a SBufList type directive with name
1346 dump_SBufList(StoreEntry
* entry
, const char *name
, SBufList
&list
)
1348 if (!list
.empty()) {
1349 entry
->append(name
, strlen(name
));
1350 entry
->append(" ", 1);
1351 dump_SBufList(entry
, list
);
1356 free_SBufList(SBufList
*list
)
1363 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1365 while (ae
!= NULL
) {
1366 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1367 storeAppendPrintf(entry
, "%s %s %s ",
1372 tail
.splice(tail
.end(), ae
->dumpOptions());
1373 tail
.splice(tail
.end(), ae
->dump()); // ACL parameters
1374 dump_SBufList(entry
, tail
);
1380 parse_acl(ACL
** ae
)
1382 ACL::ParseAclLine(LegacyParser
, ae
);
1392 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1394 dump_SBufList(entry
, head
->dump());
1398 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1401 dump_SBufList(entry
, head
->treeDump(name
, &Acl::AllowOrDeny
));
1405 parse_acl_access(acl_access
** head
)
1407 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1411 free_acl_access(acl_access
** head
)
1413 aclDestroyAccessList(head
);
1417 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1419 char buf
[MAX_IPSTRLEN
];
1420 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1424 parse_address(Ip::Address
*addr
)
1426 char *token
= ConfigParser::NextToken();
1433 if (!strcmp(token
,"any_addr"))
1435 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1437 else if ( (*addr
= token
) ) // try parse numeric/IPA
1439 else if (addr
->GetHostByName(token
)) // do not use ipcache
1441 else { // not an IP and not a hostname
1442 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
1448 free_address(Ip::Address
*addr
)
1454 dump_acl_address(StoreEntry
* entry
, const char *name
, Acl::Address
* head
)
1456 char buf
[MAX_IPSTRLEN
];
1458 for (Acl::Address
*l
= head
; l
; l
= l
->next
) {
1459 if (!l
->addr
.isAnyAddr())
1460 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.toStr(buf
,MAX_IPSTRLEN
));
1462 storeAppendPrintf(entry
, "%s autoselect", name
);
1464 dump_acl_list(entry
, l
->aclList
);
1466 storeAppendPrintf(entry
, "\n");
1471 parse_acl_address(Acl::Address
** head
)
1473 Acl::Address
*l
= new Acl::Address
;
1474 parse_address(&l
->addr
);
1475 aclParseAclList(LegacyParser
, &l
->aclList
, l
->addr
);
1477 Acl::Address
**tail
= head
;
1479 tail
= &(*tail
)->next
;
1485 free_acl_address(Acl::Address
** head
)
1492 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1496 for (l
= head
; l
; l
= l
->next
) {
1498 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1500 storeAppendPrintf(entry
, "%s none", name
);
1502 dump_acl_list(entry
, l
->aclList
);
1504 storeAppendPrintf(entry
, "\n");
1509 parse_acl_tos(acl_tos
** head
)
1511 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1512 char *token
= ConfigParser::NextToken();
1519 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1524 const unsigned int chTos
= tos
& 0xFC;
1526 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: Tos value '" << tos
<< "' adjusted to '" << chTos
<< "'");
1530 acl_tos
*l
= new acl_tos
;
1532 l
->tos
= (tos_t
)tos
;
1534 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1536 acl_tos
**tail
= head
; /* sane name below */
1538 tail
= &(*tail
)->next
;
1544 free_acl_tos(acl_tos
** head
)
1550 #if SO_MARK && USE_LIBCAP
1553 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1555 for (acl_nfmark
*l
= head
; l
; l
= l
->next
) {
1556 storeAppendPrintf(entry
, "%s %s", name
, ToSBuf(l
->markConfig
).c_str());
1558 dump_acl_list(entry
, l
->aclList
);
1560 storeAppendPrintf(entry
, "\n");
1565 parse_acl_nfmark(acl_nfmark
** head
)
1567 SBuf
token(ConfigParser::NextToken());
1568 const auto mc
= Ip::NfMarkConfig::Parse(token
);
1570 // Packet marking directives should not allow to use masks.
1571 const auto pkt_dirs
= {"mark_client_packet", "clientside_mark", "tcp_outgoing_mark"};
1572 if (mc
.hasMask() && std::find(pkt_dirs
.begin(), pkt_dirs
.end(), cfg_directive
) != pkt_dirs
.end())
1573 throw TexcHere(ToSBuf("'", cfg_directive
, "' does not support masked marks"));
1575 acl_nfmark
*l
= new acl_nfmark
;
1578 aclParseAclList(LegacyParser
, &l
->aclList
, token
.c_str());
1580 acl_nfmark
**tail
= head
; /* sane name below */
1582 tail
= &(*tail
)->next
;
1588 free_acl_nfmark(acl_nfmark
** head
)
1593 #endif /* SO_MARK */
1596 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1598 for (AclSizeLimit
*l
= head
; l
; l
= l
->next
) {
1600 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1602 storeAppendPrintf(entry
, "%s none", name
);
1604 dump_acl_list(entry
, l
->aclList
);
1606 storeAppendPrintf(entry
, "\n");
1611 parse_acl_b_size_t(AclSizeLimit
** head
)
1613 AclSizeLimit
*l
= new AclSizeLimit
;
1615 parse_b_int64_t(&l
->size
);
1617 aclParseAclList(LegacyParser
, &l
->aclList
, l
->size
);
1619 AclSizeLimit
**tail
= head
; /* sane name below */
1621 tail
= &(*tail
)->next
;
1627 free_acl_b_size_t(AclSizeLimit
** head
)
1635 #include "DelayConfig.h"
1636 #include "DelayPools.h"
1637 /* do nothing - free_delay_pool_count is the magic free function.
1638 * this is why delay_pool_count isn't just marked TYPE: u_short
1640 #define free_delay_pool_class(X)
1641 #define free_delay_pool_access(X)
1642 #define free_delay_pool_rates(X)
1643 #define dump_delay_pool_class(X, Y, Z)
1644 #define dump_delay_pool_access(X, Y, Z)
1645 #define dump_delay_pool_rates(X, Y, Z)
1648 free_delay_pool_count(DelayConfig
* cfg
)
1650 cfg
->freePoolCount();
1654 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1656 cfg
.dumpPoolCount (entry
, name
);
1660 parse_delay_pool_count(DelayConfig
* cfg
)
1662 cfg
->parsePoolCount();
1666 parse_delay_pool_class(DelayConfig
* cfg
)
1668 cfg
->parsePoolClass();
1672 parse_delay_pool_rates(DelayConfig
* cfg
)
1674 cfg
->parsePoolRates();
1678 parse_delay_pool_access(DelayConfig
* cfg
)
1680 cfg
->parsePoolAccess(LegacyParser
);
1686 #include "ClientDelayConfig.h"
1687 /* do nothing - free_client_delay_pool_count is the magic free function.
1688 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1691 #define free_client_delay_pool_access(X)
1692 #define free_client_delay_pool_rates(X)
1693 #define dump_client_delay_pool_access(X, Y, Z)
1694 #define dump_client_delay_pool_rates(X, Y, Z)
1697 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1703 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1705 cfg
.dumpPoolCount (entry
, name
);
1709 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1711 cfg
->parsePoolCount();
1715 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1717 cfg
->parsePoolRates();
1721 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1723 cfg
->parsePoolAccess(LegacyParser
);
1727 #if USE_HTTP_VIOLATIONS
1729 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1732 manglers
->dumpAccess(entry
, name
);
1736 parse_http_header_access(HeaderManglers
**pm
)
1740 if ((t
= ConfigParser::NextToken()) == NULL
) {
1741 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1742 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1747 *pm
= new HeaderManglers
;
1748 HeaderManglers
*manglers
= *pm
;
1749 headerMangler
*mangler
= manglers
->track(t
);
1752 std::string directive
= "http_header_access ";
1754 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1758 free_HeaderManglers(HeaderManglers
**pm
)
1760 // we delete the entire http_header_* mangler configuration at once
1761 if (const HeaderManglers
*manglers
= *pm
) {
1768 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1771 manglers
->dumpReplacement(entry
, name
);
1775 parse_http_header_replace(HeaderManglers
**pm
)
1779 if ((t
= ConfigParser::NextToken()) == NULL
) {
1780 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1781 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1785 const char *value
= ConfigParser::NextQuotedOrToEol();
1788 *pm
= new HeaderManglers
;
1789 HeaderManglers
*manglers
= *pm
;
1790 manglers
->setReplacement(t
, value
);
1796 dump_cachedir(StoreEntry
* entry
, const char *name
, const Store::DiskConfig
&swap
)
1802 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1803 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1805 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1807 storeAppendPrintf(entry
, "\n");
1812 check_null_string(char *s
)
1819 parse_authparam(Auth::ConfigVector
* config
)
1821 char *type_str
= ConfigParser::NextToken();
1827 char *param_str
= ConfigParser::NextToken();
1833 /* find a configuration for the scheme in the currently parsed configs... */
1834 Auth::SchemeConfig
*schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1836 if (schemeCfg
== NULL
) {
1837 /* Create a configuration based on the scheme info */
1838 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1840 if (theScheme
== NULL
) {
1841 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1846 config
->push_back(theScheme
->createConfig());
1847 schemeCfg
= Auth::SchemeConfig::Find(type_str
);
1848 if (schemeCfg
== NULL
) {
1849 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1855 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1859 free_authparam(Auth::ConfigVector
* cfg
)
1861 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1864 /* on reconfigure initialize new auth schemes for the new config. */
1865 if (reconfiguring
) {
1871 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1873 for (auto *scheme
: cfg
)
1874 scheme
->dump(entry
, name
, scheme
);
1878 parse_AuthSchemes(acl_access
**authSchemes
)
1880 const char *tok
= ConfigParser::NextQuotedToken();
1882 debugs(29, DBG_CRITICAL
, "FATAL: auth_schemes missing the parameter");
1886 Auth::TheConfig
.schemeLists
.emplace_back(tok
, ConfigParser::LastTokenWasQuoted());
1887 const allow_t action
= allow_t(ACCESS_ALLOWED
, Auth::TheConfig
.schemeLists
.size() - 1);
1888 ParseAclWithAction(authSchemes
, action
, "auth_schemes");
1892 free_AuthSchemes(acl_access
**authSchemes
)
1894 Auth::TheConfig
.schemeLists
.clear();
1895 free_acl_access(authSchemes
);
1899 dump_AuthSchemes(StoreEntry
*entry
, const char *name
, acl_access
*authSchemes
)
1902 dump_SBufList(entry
, authSchemes
->treeDump(name
, [](const allow_t
&action
) {
1903 return Auth::TheConfig
.schemeLists
.at(action
.kind
).rawSchemes
;
1907 #endif /* USE_AUTH */
1910 ParseAclWithAction(acl_access
**access
, const allow_t
&action
, const char *desc
, ACL
*acl
)
1915 *access
= new Acl::Tree
;
1916 name
.Printf("(%s rules)", desc
);
1917 (*access
)->context(name
.c_str(), config_input_line
);
1919 Acl::AndNode
*rule
= new Acl::AndNode
;
1920 name
.Printf("(%s rule)", desc
);
1921 rule
->context(name
.c_str(), config_input_line
);
1922 acl
? rule
->add(acl
) : rule
->lineParse();
1923 (*access
)->add(rule
, action
);
1926 /* TODO: just return the object, the # is irrelevant */
1928 find_fstype(char *type
)
1930 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1931 if (strcasecmp(type
, StoreFileSystem::FileSystems().at(i
)->type()) == 0)
1938 parse_cachedir(Store::DiskConfig
*swap
)
1940 char *type_str
= ConfigParser::NextToken();
1946 char *path_str
= ConfigParser::NextToken();
1952 int fs
= find_fstype(type_str
);
1954 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: This proxy does not support the '" << type_str
<< "' cache type. Ignoring.");
1958 /* reconfigure existing dir */
1960 RefCount
<SwapDir
> sd
;
1961 for (int i
= 0; i
< swap
->n_configured
; ++i
) {
1962 assert (swap
->swapDirs
[i
].getRaw());
1964 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1965 /* this is specific to on-fs Stores. The right
1966 * way to handle this is probably to have a mapping
1967 * from paths to stores, and have on-fs stores
1968 * register with that, and lookip in that in their
1969 * own setup logic. RBC 20041225. TODO.
1972 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1974 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().at(fs
)->type()) != 0) {
1975 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1976 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1986 if (swap
->n_configured
> 63) {
1987 /* 7 bits, signed */
1988 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1989 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1994 allocate_new_swapdir(swap
);
1996 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().at(fs
)->createSwapDir();
1998 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
2000 /* parse the FS parameters and options */
2001 sd
->parse(swap
->n_configured
, path_str
);
2003 ++swap
->n_configured
;
2007 peer_type_str(const peer_t type
)
2009 const char * result
;
2021 case PEER_MULTICAST
:
2022 result
= "multicast";
2034 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2036 NeighborTypeDomainList
*t
;
2037 LOCAL_ARRAY(char, xname
, 128);
2040 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2047 dump_peer_options(entry
, p
);
2050 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2051 dump_acl_access(entry
, xname
, p
->access
);
2054 for (t
= p
->typelist
; t
; t
= t
->next
) {
2055 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2057 peer_type_str(t
->type
),
2066 * utility function to prevent getservbyname() being called with a numeric value
2067 * on Windows at least it returns garage results.
2070 isUnsignedNumeric(const char *str
, size_t len
)
2072 if (len
< 1) return false;
2074 for (; len
>0 && *str
; ++str
, --len
) {
2075 if (! isdigit(*str
))
2082 \param proto 'tcp' or 'udp' for protocol
2083 \returns Port the named service is supposed to be listening on.
2085 static unsigned short
2086 GetService(const char *proto
)
2088 struct servent
*port
= NULL
;
2089 /** Parses a port number or service name from the squid.conf */
2090 char *token
= ConfigParser::NextToken();
2091 if (token
== NULL
) {
2093 return 0; /* NEVER REACHED */
2095 /** Returns either the service port number from /etc/services */
2096 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2097 port
= getservbyname(token
, proto
);
2099 return ntohs((unsigned short)port
->s_port
);
2101 /** Or a numeric translation of the config text. */
2102 return xatos(token
);
2106 \returns Port the named TCP service is supposed to be listening on.
2107 \copydoc GetService(const char *proto)
2109 inline unsigned short
2112 return GetService("tcp");
2116 \returns Port the named UDP service is supposed to be listening on.
2117 \copydoc GetService(const char *proto)
2119 inline unsigned short
2122 return GetService("udp");
2126 parse_peer(CachePeer
** head
)
2128 char *host_str
= ConfigParser::NextToken();
2134 char *token
= ConfigParser::NextToken();
2140 CachePeer
*p
= new CachePeer
;
2141 p
->host
= xstrdup(host_str
);
2142 p
->name
= xstrdup(host_str
);
2143 p
->type
= parseNeighborType(token
);
2145 if (p
->type
== PEER_MULTICAST
) {
2146 p
->options
.no_digest
= true;
2147 p
->options
.no_netdb_exchange
= true;
2150 p
->http_port
= GetTcpService();
2152 if (!p
->http_port
) {
2158 p
->icp
.port
= GetUdpService();
2160 while ((token
= ConfigParser::NextToken())) {
2161 if (!strcmp(token
, "proxy-only")) {
2162 p
->options
.proxy_only
= true;
2163 } else if (!strcmp(token
, "no-query")) {
2164 p
->options
.no_query
= true;
2165 } else if (!strcmp(token
, "background-ping")) {
2166 p
->options
.background_ping
= true;
2167 } else if (!strcmp(token
, "no-digest")) {
2168 p
->options
.no_digest
= true;
2169 } else if (!strcmp(token
, "no-tproxy")) {
2170 p
->options
.no_tproxy
= true;
2171 } else if (!strcmp(token
, "multicast-responder")) {
2172 p
->options
.mcast_responder
= true;
2173 #if PEER_MULTICAST_SIBLINGS
2174 } else if (!strcmp(token
, "multicast-siblings")) {
2175 p
->options
.mcast_siblings
= true;
2177 } else if (!strncmp(token
, "weight=", 7)) {
2178 p
->weight
= xatoi(token
+ 7);
2179 } else if (!strncmp(token
, "basetime=", 9)) {
2180 p
->basetime
= xatoi(token
+ 9);
2181 } else if (!strcmp(token
, "closest-only")) {
2182 p
->options
.closest_only
= true;
2183 } else if (!strncmp(token
, "ttl=", 4)) {
2184 p
->mcast
.ttl
= xatoi(token
+ 4);
2186 if (p
->mcast
.ttl
< 0)
2189 if (p
->mcast
.ttl
> 128)
2191 } else if (!strcmp(token
, "default")) {
2192 p
->options
.default_parent
= true;
2193 } else if (!strcmp(token
, "round-robin")) {
2194 p
->options
.roundrobin
= true;
2195 } else if (!strcmp(token
, "weighted-round-robin")) {
2196 p
->options
.weighted_roundrobin
= true;
2198 } else if (!strcmp(token
, "htcp")) {
2199 p
->options
.htcp
= true;
2200 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2201 /* Note: The htcp- form is deprecated, replaced by htcp= */
2202 p
->options
.htcp
= true;
2203 char *tmp
= xstrdup(token
+5);
2204 char *mode
, *nextmode
;
2205 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2206 nextmode
= strchr(mode
, ',');
2211 if (!strcmp(mode
, "no-clr")) {
2212 if (p
->options
.htcp_only_clr
)
2213 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2214 p
->options
.htcp_no_clr
= true;
2215 } else if (!strcmp(mode
, "no-purge-clr")) {
2216 p
->options
.htcp_no_purge_clr
= true;
2217 } else if (!strcmp(mode
, "only-clr")) {
2218 if (p
->options
.htcp_no_clr
)
2219 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2220 p
->options
.htcp_only_clr
= true;
2221 } else if (!strcmp(mode
, "forward-clr")) {
2222 p
->options
.htcp_forward_clr
= true;
2223 } else if (!strcmp(mode
, "oldsquid")) {
2224 p
->options
.htcp_oldsquid
= true;
2226 fatalf("invalid HTCP mode '%s'", mode
);
2231 } else if (!strcmp(token
, "no-netdb-exchange")) {
2232 p
->options
.no_netdb_exchange
= true;
2234 } else if (!strcmp(token
, "carp")) {
2235 if (p
->type
!= PEER_PARENT
)
2236 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2238 p
->options
.carp
= true;
2239 } else if (!strncmp(token
, "carp-key=", 9)) {
2240 if (p
->options
.carp
!= true)
2241 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2242 p
->options
.carp_key
.set
= true;
2243 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2244 for (; key
; key
= nextkey
) {
2245 nextkey
=strchr(key
,',');
2246 if (nextkey
) ++nextkey
; // skip the comma, any
2247 if (0==strncmp(key
,"scheme",6)) {
2248 p
->options
.carp_key
.scheme
= true;
2249 } else if (0==strncmp(key
,"host",4)) {
2250 p
->options
.carp_key
.host
= true;
2251 } else if (0==strncmp(key
,"port",4)) {
2252 p
->options
.carp_key
.port
= true;
2253 } else if (0==strncmp(key
,"path",4)) {
2254 p
->options
.carp_key
.path
= true;
2255 } else if (0==strncmp(key
,"params",6)) {
2256 p
->options
.carp_key
.params
= true;
2258 fatalf("invalid carp-key '%s'",key
);
2261 } else if (!strcmp(token
, "userhash")) {
2263 if (p
->type
!= PEER_PARENT
)
2264 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2266 p
->options
.userhash
= true;
2268 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2270 } else if (!strcmp(token
, "sourcehash")) {
2271 if (p
->type
!= PEER_PARENT
)
2272 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2274 p
->options
.sourcehash
= true;
2276 } else if (!strcmp(token
, "no-delay")) {
2278 p
->options
.no_delay
= true;
2280 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2282 } else if (!strncmp(token
, "login=", 6)) {
2283 p
->login
= xstrdup(token
+ 6);
2284 rfc1738_unescape(p
->login
);
2285 } else if (!strcmp(token
, "auth-no-keytab")) {
2286 p
->options
.auth_no_keytab
= 1;
2287 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2288 p
->connect_timeout_raw
= xatoi(token
+ 16);
2289 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2290 p
->connect_fail_limit
= xatoi(token
+ 19);
2291 #if USE_CACHE_DIGESTS
2292 } else if (!strncmp(token
, "digest-url=", 11)) {
2293 p
->digest_url
= xstrdup(token
+ 11);
2296 } else if (!strcmp(token
, "allow-miss")) {
2297 p
->options
.allow_miss
= true;
2298 } else if (!strncmp(token
, "max-conn=", 9)) {
2299 p
->max_conn
= xatoi(token
+ 9);
2300 } else if (!strncmp(token
, "standby=", 8)) {
2301 p
->standby
.limit
= xatoi(token
+ 8);
2302 } else if (!strcmp(token
, "originserver")) {
2303 p
->options
.originserver
= true;
2304 } else if (!strncmp(token
, "name=", 5)) {
2308 p
->name
= xstrdup(token
+ 5);
2309 } else if (!strncmp(token
, "forceddomain=", 13)) {
2310 safe_free(p
->domain
);
2312 p
->domain
= xstrdup(token
+ 13);
2314 } else if (strncmp(token
, "ssl", 3) == 0) {
2316 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option '" << token
<< "' requires --with-openssl");
2318 p
->secure
.parse(token
+3);
2320 } else if (strncmp(token
, "tls-", 4) == 0) {
2321 p
->secure
.parse(token
+4);
2322 } else if (strncmp(token
, "tls", 3) == 0) {
2323 p
->secure
.parse(token
+3);
2324 } else if (strcmp(token
, "front-end-https") == 0) {
2325 p
->front_end_https
= 1;
2326 } else if (strcmp(token
, "front-end-https=on") == 0) {
2327 p
->front_end_https
= 1;
2328 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2329 p
->front_end_https
= 2;
2330 } else if (strcmp(token
, "connection-auth=off") == 0) {
2331 p
->connection_auth
= 0;
2332 } else if (strcmp(token
, "connection-auth") == 0) {
2333 p
->connection_auth
= 1;
2334 } else if (strcmp(token
, "connection-auth=on") == 0) {
2335 p
->connection_auth
= 1;
2336 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2337 p
->connection_auth
= 2;
2338 } else if (token
[0] == '#') {
2339 // start of a text comment. stop reading this line.
2342 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2346 if (peerFindByName(p
->name
))
2347 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2349 if (p
->max_conn
> 0 && p
->max_conn
< p
->standby
.limit
)
2350 fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p
->host
, p
->max_conn
, p
->standby
.limit
);
2355 if (p
->connect_fail_limit
< 1)
2356 p
->connect_fail_limit
= 10;
2358 #if USE_CACHE_DIGESTS
2360 if (!p
->options
.no_digest
) {
2361 /* XXX This looks odd.. who has the original pointer
2364 PeerDigest
*pd
= peerDigestCreate(p
);
2365 p
->digest
= cbdataReference(pd
);
2370 p
->index
= ++Config
.npeers
;
2372 while (*head
!= NULL
)
2373 head
= &(*head
)->next
;
2381 free_peer(CachePeer
** P
)
2389 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2392 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2393 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2395 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2397 for (auto w
: list
->actions
)
2398 entry
->appendf(" " SQUIDSBUFPH
, SQUIDSBUFPRINT(w
));
2400 storeAppendPrintf(entry
, "\n");
2406 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2408 char *passwd
= nullptr;
2409 parse_string(&passwd
);
2411 Mgr::ActionPasswordList
*p
= new Mgr::ActionPasswordList
;
2414 while (char *token
= ConfigParser::NextQuotedToken())
2415 p
->actions
.push_back(SBuf(token
));
2417 Mgr::ActionPasswordList
**P
;
2418 for (P
= head
; *P
; P
= &(*P
)->next
) {
2420 * See if any of the actions from this line already have a
2421 * password from previous lines. The password checking
2422 * routines in cache_manager.c take the the password from
2423 * the first Mgr::ActionPasswordList that contains the
2424 * requested action. Thus, we should warn users who might
2425 * think they can have two passwords for the same action.
2427 for (const auto &w
: (*P
)->actions
) {
2428 for (const auto &u
: p
->actions
) {
2432 debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u
<< "' (line " << config_lineno
<< ") already has a password");
2441 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2448 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2450 while (var
!= NULL
) {
2451 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2453 for (auto *a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2454 storeAppendPrintf(entry
, " %s", a
->name
);
2456 storeAppendPrintf(entry
, "\n");
2463 parse_denyinfo(AclDenyInfoList
** var
)
2465 aclParseDenyInfoLine(var
);
2469 free_denyinfo(AclDenyInfoList
** list
)
2476 parse_peer_access(void)
2478 char *host
= ConfigParser::NextToken();
2484 CachePeer
*p
= peerFindByName(host
);
2486 debugs(15, DBG_CRITICAL
, "ERROR: " << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2490 std::string directive
= "peer_access ";
2492 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
->access
);
2496 parse_hostdomaintype(void)
2498 char *host
= ConfigParser::NextToken();
2504 char *type
= ConfigParser::NextToken();
2510 char *domain
= nullptr;
2511 while ((domain
= ConfigParser::NextToken())) {
2512 CachePeer
*p
= peerFindByName(host
);
2514 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2518 auto *l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2519 l
->type
= parseNeighborType(type
);
2520 l
->domain
= xstrdup(domain
);
2522 NeighborTypeDomainList
**L
= nullptr;
2523 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2529 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2531 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2549 dump_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2551 storeAppendPrintf(entry
, "%s %" PRId64
"\n", name
, var
);
2555 parse_int64_t(int64_t *var
)
2563 free_int64_t(int64_t *var
)
2569 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2571 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2575 parse_onoff(int *var
)
2577 char *token
= ConfigParser::NextToken();
2583 if (!strcmp(token
, "on")) {
2585 } else if (!strcmp(token
, "enable")) {
2586 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2588 } else if (!strcmp(token
, "off")) {
2590 } else if (!strcmp(token
, "disable")) {
2591 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2594 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2599 #define free_onoff free_int
2602 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2613 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2617 parse_tristate(int *var
)
2619 char *token
= ConfigParser::NextToken();
2625 if (!strcmp(token
, "on")) {
2627 } else if (!strcmp(token
, "enable")) {
2628 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2630 } else if (!strcmp(token
, "warn")) {
2632 } else if (!strcmp(token
, "off")) {
2634 } else if (!strcmp(token
, "disable")) {
2635 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2638 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2643 #define free_tristate free_int
2646 parse_pipelinePrefetch(int *var
)
2648 char *token
= ConfigParser::PeekAtToken();
2654 if (!strcmp(token
, "on")) {
2655 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2658 (void)ConfigParser::NextToken();
2659 } else if (!strcmp(token
, "off")) {
2660 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2663 (void)ConfigParser::NextToken();
2668 #define free_pipelinePrefetch free_int
2669 #define dump_pipelinePrefetch dump_int
2672 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2674 while (head
!= NULL
) {
2675 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2677 head
->pattern
.flags
®_ICASE
? " -i" : null_string
,
2678 head
->pattern
.c_str(),
2679 (int) head
->min
/ 60,
2680 (int) (100.0 * head
->pct
+ 0.5),
2681 (int) head
->max
/ 60);
2683 if (head
->max_stale
>= 0)
2684 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2686 if (head
->flags
.refresh_ims
)
2687 storeAppendPrintf(entry
, " refresh-ims");
2689 if (head
->flags
.store_stale
)
2690 storeAppendPrintf(entry
, " store-stale");
2692 #if USE_HTTP_VIOLATIONS
2694 if (head
->flags
.override_expire
)
2695 storeAppendPrintf(entry
, " override-expire");
2697 if (head
->flags
.override_lastmod
)
2698 storeAppendPrintf(entry
, " override-lastmod");
2700 if (head
->flags
.reload_into_ims
)
2701 storeAppendPrintf(entry
, " reload-into-ims");
2703 if (head
->flags
.ignore_reload
)
2704 storeAppendPrintf(entry
, " ignore-reload");
2706 if (head
->flags
.ignore_no_store
)
2707 storeAppendPrintf(entry
, " ignore-no-store");
2709 if (head
->flags
.ignore_private
)
2710 storeAppendPrintf(entry
, " ignore-private");
2713 storeAppendPrintf(entry
, "\n");
2720 parse_refreshpattern(RefreshPattern
** head
)
2727 int refresh_ims
= 0;
2728 int store_stale
= 0;
2731 #if USE_HTTP_VIOLATIONS
2733 int override_expire
= 0;
2734 int override_lastmod
= 0;
2735 int reload_into_ims
= 0;
2736 int ignore_reload
= 0;
2737 int ignore_no_store
= 0;
2738 int ignore_private
= 0;
2745 int flags
= REG_EXTENDED
| REG_NOSUB
;
2747 if ((token
= ConfigParser::RegexPattern()) != NULL
) {
2749 if (strcmp(token
, "-i") == 0) {
2751 token
= ConfigParser::RegexPattern();
2752 } else if (strcmp(token
, "+i") == 0) {
2753 flags
&= ~REG_ICASE
;
2754 token
= ConfigParser::RegexPattern();
2759 if (token
== NULL
) {
2760 debugs(3, DBG_CRITICAL
, "FATAL: refresh_pattern missing the regex pattern parameter");
2765 pattern
= xstrdup(token
);
2767 i
= GetInteger(); /* token: min */
2769 /* catch negative and insanely huge values close to 32-bit wrap */
2771 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2774 if (i
> 60*24*365) {
2775 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2779 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2781 pct
= GetPercentage(false); /* token: pct . with no limit on size */
2783 i
= GetInteger(); /* token: max */
2785 /* catch negative and insanely huge values close to 32-bit wrap */
2787 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2790 if (i
> 60*24*365) {
2791 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2795 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2798 while ((token
= ConfigParser::NextToken()) != NULL
) {
2799 if (!strcmp(token
, "refresh-ims")) {
2801 } else if (!strcmp(token
, "store-stale")) {
2803 } else if (!strncmp(token
, "max-stale=", 10)) {
2804 max_stale
= xatoi(token
+ 10);
2806 #if USE_HTTP_VIOLATIONS
2808 } else if (!strcmp(token
, "override-expire"))
2809 override_expire
= 1;
2810 else if (!strcmp(token
, "override-lastmod"))
2811 override_lastmod
= 1;
2812 else if (!strcmp(token
, "ignore-no-store"))
2813 ignore_no_store
= 1;
2814 else if (!strcmp(token
, "ignore-private"))
2816 else if (!strcmp(token
, "reload-into-ims")) {
2817 reload_into_ims
= 1;
2818 refresh_nocache_hack
= 1;
2819 /* tell client_side.c that this is used */
2820 } else if (!strcmp(token
, "ignore-reload")) {
2822 refresh_nocache_hack
= 1;
2823 /* tell client_side.c that this is used */
2826 } else if (!strcmp(token
, "ignore-no-cache") ||
2827 !strcmp(token
, "ignore-must-revalidate") ||
2828 !strcmp(token
, "ignore-auth")
2830 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token
<< "' is obsolete. Remove it.");
2832 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2835 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2837 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2838 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2839 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2844 pct
= pct
< 0.0 ? 0.0 : pct
;
2845 max
= max
< 0 ? 0 : max
;
2846 t
= new RefreshPattern(pattern
, flags
);
2847 t
->pattern
.regex
= comp
;
2853 t
->flags
.refresh_ims
= true;
2856 t
->flags
.store_stale
= true;
2858 t
->max_stale
= max_stale
;
2860 #if USE_HTTP_VIOLATIONS
2862 if (override_expire
)
2863 t
->flags
.override_expire
= true;
2865 if (override_lastmod
)
2866 t
->flags
.override_lastmod
= true;
2868 if (reload_into_ims
)
2869 t
->flags
.reload_into_ims
= true;
2872 t
->flags
.ignore_reload
= true;
2874 if (ignore_no_store
)
2875 t
->flags
.ignore_no_store
= true;
2878 t
->flags
.ignore_private
= true;
2884 head
= &(*head
)->next
;
2892 free_refreshpattern(RefreshPattern
** head
)
2897 #if USE_HTTP_VIOLATIONS
2898 refresh_nocache_hack
= 0;
2904 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2907 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2911 parse_string(char **var
)
2915 char *token
= ConfigParser::NextToken();
2921 *var
= xstrdup(token
);
2925 free_string(char **var
)
2931 parse_eol(char *volatile *var
)
2938 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
2946 while (*token
&& xisspace(*token
))
2954 *var
= xstrdup((char *) token
);
2957 #define dump_eol dump_string
2958 #define free_eol free_string
2961 parse_TokenOrQuotedString(char **var
)
2965 char *token
= ConfigParser::NextQuotedToken();
2971 *var
= xstrdup(token
);
2974 #define dump_TokenOrQuotedString dump_string
2975 #define free_TokenOrQuotedString free_string
2978 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2980 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2984 parse_time_t(time_t * var
)
2987 parseTimeLine(&tval
, T_SECOND_STR
, false);
2988 *var
= static_cast<time_t>(tval
/1000);
2992 free_time_t(time_t * var
)
2998 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3001 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3003 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3007 parse_time_msec(time_msec_t
* var
)
3009 parseTimeLine(var
, T_SECOND_STR
, true);
3013 free_time_msec(time_msec_t
* var
)
3020 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3022 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3027 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3029 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3033 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3035 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3040 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3042 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3047 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3049 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3053 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3055 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3060 parse_size_t(size_t * var
)
3069 parse_b_size_t(size_t * var
)
3071 parseBytesLine(var
, B_BYTES_STR
);
3075 parse_b_ssize_t(ssize_t
* var
)
3077 parseBytesLineSigned(var
, B_BYTES_STR
);
3082 parse_kb_size_t(size_t * var
)
3084 parseBytesLine(var
, B_KBYTES_STR
);
3089 parse_b_int64_t(int64_t * var
)
3091 parseBytesLine64(var
, B_BYTES_STR
);
3095 parse_kb_int64_t(int64_t * var
)
3097 parseBytesLine64(var
, B_KBYTES_STR
);
3101 free_size_t(size_t * var
)
3107 free_ssize_t(ssize_t
* var
)
3113 free_b_int64_t(int64_t * var
)
3118 #define free_b_size_t free_size_t
3119 #define free_b_ssize_t free_ssize_t
3120 #define free_kb_size_t free_size_t
3121 #define free_mb_size_t free_size_t
3122 #define free_gb_size_t free_size_t
3123 #define free_kb_int64_t free_b_int64_t
3126 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3128 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3132 free_u_short(unsigned short * u
)
3138 parse_u_short(unsigned short * var
)
3140 ConfigParser::ParseUShort(var
);
3144 ConfigParser::ParseUShort(unsigned short *var
)
3150 ConfigParser::ParseBool(bool *var
)
3152 int i
= GetInteger();
3163 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3165 while (list
!= NULL
) {
3166 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3172 ConfigParser::ParseWordList(wordlist
** list
)
3174 parse_wordlist(list
);
3178 parse_wordlist(wordlist
** list
)
3181 while ((token
= ConfigParser::NextQuotedToken()))
3182 wordlistAdd(list
, token
);
3185 #if 0 /* now unused */
3187 check_null_wordlist(wordlist
* w
)
3194 check_null_acl_access(acl_access
* a
)
3199 #define free_wordlist wordlistDestroy
3201 #define free_uri_whitespace free_int
3204 parse_uri_whitespace(int *var
)
3206 char *token
= ConfigParser::NextToken();
3212 if (!strcmp(token
, "strip"))
3213 *var
= URI_WHITESPACE_STRIP
;
3214 else if (!strcmp(token
, "deny"))
3215 *var
= URI_WHITESPACE_DENY
;
3216 else if (!strcmp(token
, "allow"))
3217 *var
= URI_WHITESPACE_ALLOW
;
3218 else if (!strcmp(token
, "encode"))
3219 *var
= URI_WHITESPACE_ENCODE
;
3220 else if (!strcmp(token
, "chop"))
3221 *var
= URI_WHITESPACE_CHOP
;
3223 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3229 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3233 if (var
== URI_WHITESPACE_ALLOW
)
3235 else if (var
== URI_WHITESPACE_ENCODE
)
3237 else if (var
== URI_WHITESPACE_CHOP
)
3239 else if (var
== URI_WHITESPACE_DENY
)
3244 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3248 free_removalpolicy(RemovalPolicySettings
** settings
)
3253 free_string(&(*settings
)->type
);
3255 free_wordlist(&(*settings
)->args
);
3263 parse_removalpolicy(RemovalPolicySettings
** settings
)
3266 free_removalpolicy(settings
);
3268 *settings
= new RemovalPolicySettings
;
3270 parse_string(&(*settings
)->type
);
3272 parse_wordlist(&(*settings
)->args
);
3276 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3279 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3280 args
= settings
->args
;
3283 storeAppendPrintf(entry
, " %s", args
->key
);
3287 storeAppendPrintf(entry
, "\n");
3291 free_YesNoNone(YesNoNone
*)
3295 parse_YesNoNone(YesNoNone
*option
)
3298 parse_onoff(&value
);
3299 option
->configure(value
> 0);
3303 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3305 if (option
.configured())
3306 dump_onoff(entry
, name
, option
? 1 : 0);
3310 free_memcachemode(SquidConfig
*)
3314 parse_memcachemode(SquidConfig
*)
3316 char *token
= ConfigParser::NextToken();
3322 if (strcmp(token
, "always") == 0) {
3323 Config
.onoff
.memory_cache_first
= 1;
3324 Config
.onoff
.memory_cache_disk
= 1;
3325 } else if (strcmp(token
, "disk") == 0) {
3326 Config
.onoff
.memory_cache_first
= 0;
3327 Config
.onoff
.memory_cache_disk
= 1;
3328 } else if (strncmp(token
, "net", 3) == 0) {
3329 Config
.onoff
.memory_cache_first
= 1;
3330 Config
.onoff
.memory_cache_disk
= 0;
3331 } else if (strcmp(token
, "never") == 0) {
3332 Config
.onoff
.memory_cache_first
= 0;
3333 Config
.onoff
.memory_cache_disk
= 0;
3335 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3341 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&)
3343 storeAppendPrintf(entry
, "%s ", name
);
3344 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3345 storeAppendPrintf(entry
, "always");
3346 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3347 storeAppendPrintf(entry
, "disk");
3348 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3349 storeAppendPrintf(entry
, "network");
3350 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3351 storeAppendPrintf(entry
, "none");
3352 storeAppendPrintf(entry
, "\n");
3355 #include "cf_parser.cci"
3358 parseNeighborType(const char *s
)
3360 if (!strcmp(s
, "parent"))
3363 if (!strcmp(s
, "neighbor"))
3364 return PEER_SIBLING
;
3366 if (!strcmp(s
, "neighbour"))
3367 return PEER_SIBLING
;
3369 if (!strcmp(s
, "sibling"))
3370 return PEER_SIBLING
;
3372 if (!strcmp(s
, "multicast"))
3373 return PEER_MULTICAST
;
3375 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3377 return PEER_SIBLING
;
3382 parse_IpAddress_list(Ip::Address_list
** head
)
3385 Ip::Address_list
*s
;
3388 while ((token
= ConfigParser::NextToken())) {
3389 if (GetHostWithPort(token
, &ipa
)) {
3392 head
= &(*head
)->next
;
3394 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3406 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3408 char ntoabuf
[MAX_IPSTRLEN
];
3411 storeAppendPrintf(e
, "%s %s\n",
3413 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3419 free_IpAddress_list(Ip::Address_list
** head
)
3421 if (*head
) delete *head
;
3425 #if CURRENTLY_UNUSED
3426 /* This code was previously used by http_port. Left as it really should
3427 * be used by icp_port and htcp_port
3430 check_null_IpAddress_list(const Ip::Address_list
* s
)
3435 #endif /* CURRENTLY_UNUSED */
3436 #endif /* USE_WCCPv2 */
3439 parsePortSpecification(const AnyP::PortCfgPointer
&s
, char *token
)
3442 unsigned short port
= 0;
3446 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3447 s
->name
= xstrdup(token
);
3448 s
->connection_auth_disabled
= false;
3450 const SBuf
&portType
= AnyP::UriScheme(s
->transport
.protocol
).image();
3452 if (*token
== '[') {
3455 t
= strchr(host
, ']');
3457 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3464 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3468 if (!Ip::EnableIpv6
) {
3469 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3473 port
= xatos(t
+ 1);
3474 } else if ((t
= strchr(token
, ':'))) {
3479 port
= xatos(t
+ 1);
3481 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3482 port
= xatos(token
);
3483 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3485 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3490 if (port
== 0 && host
!= NULL
) {
3491 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3499 if (!Ip::EnableIpv6
)
3501 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3502 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3504 if (!Ip::EnableIpv6
)
3506 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3507 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3508 /* do not use ipcache */
3509 s
->defaultsite
= xstrdup(host
);
3511 if (!Ip::EnableIpv6
)
3513 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3515 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3520 /// parses the protocol= option of the *_port directive, returning parsed value
3521 /// unsupported option values result in a fatal error message
3522 /// upper case values required; caller may convert for backward compatibility
3523 static AnyP::ProtocolVersion
3524 parsePortProtocol(const SBuf
&value
)
3526 // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3527 // and RFC 2616 requires us to upgrade 1.0 to 1.1
3528 if (value
.cmp("HTTP") == 0 || value
.cmp("HTTP/1.1") == 0)
3529 return Http::ProtocolVersion(1,1);
3531 if (value
.cmp("HTTPS") == 0 || value
.cmp("HTTPS/1.1") == 0)
3532 return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS
, 1,1);
3534 if (value
.cmp("FTP") == 0)
3535 return Ftp::ProtocolVersion();
3537 fatalf("%s directive does not support protocol=" SQUIDSBUFPH
"\n", cfg_directive
, SQUIDSBUFPRINT(value
));
3538 return AnyP::ProtocolVersion(); // not reached
3542 parse_port_option(AnyP::PortCfgPointer
&s
, char *token
)
3546 if (strcmp(token
, "accel") == 0) {
3547 if (s
->flags
.isIntercepted()) {
3548 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3552 s
->flags
.accelSurrogate
= true;
3554 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3555 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3556 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3560 s
->flags
.natIntercept
= true;
3561 Ip::Interceptor
.StartInterception();
3562 /* Log information regarding the port modes under interception. */
3563 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3564 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3565 } else if (strcmp(token
, "tproxy") == 0) {
3566 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3567 debugs(3,DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3571 s
->flags
.tproxyIntercept
= true;
3572 Ip::Interceptor
.StartTransparency();
3573 /* Log information regarding the port modes under transparency. */
3574 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3576 if (s
->flags
.proxySurrogate
) {
3577 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3580 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3581 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY support in the system does not work.");
3586 } else if (strcmp(token
, "require-proxy-header") == 0) {
3587 s
->flags
.proxySurrogate
= true;
3588 if (s
->flags
.tproxyIntercept
) {
3589 // receiving is still permitted, so we do not unset the TPROXY flag
3590 // spoofing access control override takes care of the spoof disable later
3591 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3594 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3595 if (!s
->flags
.accelSurrogate
) {
3596 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": defaultsite option requires Acceleration mode flag.");
3600 safe_free(s
->defaultsite
);
3601 s
->defaultsite
= xstrdup(token
+ 12);
3602 } else if (strcmp(token
, "vhost") == 0) {
3603 if (!s
->flags
.accelSurrogate
) {
3604 debugs(3, DBG_CRITICAL
, "WARNING: " << cfg_directive
<< ": vhost option is deprecated. Use 'accel' mode flag instead.");
3606 s
->flags
.accelSurrogate
= true;
3608 } else if (strcmp(token
, "no-vhost") == 0) {
3609 if (!s
->flags
.accelSurrogate
) {
3610 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": no-vhost option requires Acceleration mode flag.");
3613 } else if (strcmp(token
, "vport") == 0) {
3614 if (!s
->flags
.accelSurrogate
) {
3615 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3620 } else if (strncmp(token
, "vport=", 6) == 0) {
3621 if (!s
->flags
.accelSurrogate
) {
3622 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3626 s
->vport
= xatos(token
+ 6);
3627 } else if (strncmp(token
, "protocol=", 9) == 0) {
3628 if (!s
->flags
.accelSurrogate
) {
3629 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": protocol option requires Acceleration mode flag.");
3633 s
->transport
= parsePortProtocol(ToUpper(SBuf(token
+ 9)));
3634 } else if (strcmp(token
, "allow-direct") == 0) {
3635 if (!s
->flags
.accelSurrogate
) {
3636 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": allow-direct option requires Acceleration mode flag.");
3640 s
->allow_direct
= true;
3641 } else if (strcmp(token
, "act-as-origin") == 0) {
3642 if (!s
->flags
.accelSurrogate
) {
3643 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": act-as-origin option requires Acceleration mode flag.");
3645 s
->actAsOrigin
= true;
3646 } else if (strcmp(token
, "ignore-cc") == 0) {
3647 #if !USE_HTTP_VIOLATIONS
3648 if (!s
->flags
.accelSurrogate
) {
3649 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": ignore-cc option requires Acceleration mode flag.");
3654 s
->ignore_cc
= true;
3655 } else if (strncmp(token
, "name=", 5) == 0) {
3657 s
->name
= xstrdup(token
+ 5);
3658 } else if (strcmp(token
, "no-connection-auth") == 0) {
3659 s
->connection_auth_disabled
= true;
3660 } else if (strcmp(token
, "connection-auth=off") == 0) {
3661 s
->connection_auth_disabled
= true;
3662 } else if (strcmp(token
, "connection-auth") == 0) {
3663 s
->connection_auth_disabled
= false;
3664 } else if (strcmp(token
, "connection-auth=on") == 0) {
3665 s
->connection_auth_disabled
= false;
3666 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3667 if (!strcmp(token
+ 23, "off"))
3668 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3669 else if (!strcmp(token
+ 23, "transparent"))
3670 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3671 else if (!strcmp(token
+ 23, "always"))
3672 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3677 } else if (strcmp(token
, "ipv4") == 0) {
3678 if ( !s
->s
.setIPv4() ) {
3679 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3683 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3684 s
->tcp_keepalive
.enabled
= true;
3685 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3686 char *t
= token
+ 13;
3687 s
->tcp_keepalive
.enabled
= true;
3688 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3692 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3697 s
->tcp_keepalive
.timeout
= xatoui(t
);
3700 } else if (strcmp(token
, "sslBump") == 0) {
3701 debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token
<< "' is deprecated " <<
3702 "in " << cfg_directive
<< ". Use 'ssl-bump' instead.");
3703 s
->flags
.tunnelSslBumping
= true;
3704 } else if (strcmp(token
, "ssl-bump") == 0) {
3705 s
->flags
.tunnelSslBumping
= true;
3706 } else if (strncmp(token
, "cert=", 5) == 0) {
3707 s
->secure
.parse(token
);
3708 } else if (strncmp(token
, "key=", 4) == 0) {
3709 s
->secure
.parse(token
);
3710 } else if (strncmp(token
, "version=", 8) == 0) {
3711 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3712 "in " << cfg_directive
<< ". Use 'options=' instead.");
3713 s
->secure
.parse(token
);
3714 } else if (strncmp(token
, "options=", 8) == 0) {
3715 s
->secure
.parse(token
);
3716 } else if (strncmp(token
, "cipher=", 7) == 0) {
3717 s
->secure
.parse(token
);
3718 } else if (strncmp(token
, "clientca=", 9) == 0) {
3719 s
->secure
.parse(token
);
3720 } else if (strncmp(token
, "cafile=", 7) == 0) {
3721 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3722 "in " << cfg_directive
<< ". Use 'tls-cafile=' instead.");
3723 s
->secure
.parse(token
);
3724 } else if (strncmp(token
, "capath=", 7) == 0) {
3725 s
->secure
.parse(token
);
3726 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3727 s
->secure
.parse(token
);
3728 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3729 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: '" << token
<< "' is deprecated " <<
3730 "in " << cfg_directive
<< ". Use 'tls-dh=' instead.");
3731 s
->secure
.parse(token
);
3732 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3733 // NP: deprecation warnings output by secure.parse() when relevant
3734 s
->secure
.parse(token
+3);
3735 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3736 // NP: deprecation warnings output by secure.parse() when relevant
3737 s
->secure
.parse(token
+3);
3738 } else if (strncmp(token
, "generate-host-certificates", 26) == 0) {
3739 s
->secure
.parse(token
);
3741 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3742 s
->secure
.parse(token
);
3743 } else if (strncmp(token
, "tls-", 4) == 0) {
3744 s
->secure
.parse(token
+4);
3745 } else if (strcmp(token
, "ftp-track-dirs") == 0) {
3746 s
->ftp_track_dirs
= true;
3748 debugs(3, DBG_CRITICAL
, "FATAL: Unknown " << cfg_directive
<< " option '" << token
<< "'.");
3754 add_http_port(char *portspec
)
3756 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3757 s
->transport
= parsePortProtocol(SBuf("HTTP"));
3758 parsePortSpecification(s
, portspec
);
3759 // we may need to merge better if the above returns a list with clones
3760 assert(s
->next
== NULL
);
3761 s
->next
= HttpPortList
;
3766 parsePortCfg(AnyP::PortCfgPointer
*head
, const char *optionName
)
3769 if (strcmp(optionName
, "http_port") == 0 ||
3770 strcmp(optionName
, "ascii_port") == 0)
3772 else if (strcmp(optionName
, "https_port") == 0)
3773 protoName
= "HTTPS";
3774 else if (strcmp(optionName
, "ftp_port") == 0)
3776 if (protoName
.isEmpty()) {
3781 char *token
= ConfigParser::NextToken();
3788 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3789 s
->transport
= parsePortProtocol(protoName
); // default; protocol=... overwrites
3790 parsePortSpecification(s
, token
);
3792 /* parse options ... */
3793 while ((token
= ConfigParser::NextToken())) {
3794 parse_port_option(s
, token
);
3797 s
->secure
.syncCaFiles();
3799 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3800 s
->secure
.encryptTransport
= true;
3802 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3803 const bool hijacked
= s
->flags
.isIntercepted();
3804 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3805 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3809 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3810 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3815 if (s
->flags
.proxySurrogate
) {
3816 debugs(3,DBG_CRITICAL
, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3820 } else if (protoName
.cmp("FTP") == 0) {
3821 /* ftp_port does not support ssl-bump */
3822 if (s
->flags
.tunnelSslBumping
) {
3823 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump is not supported for ftp_port.");
3827 if (s
->flags
.proxySurrogate
) {
3828 // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3829 debugs(3,DBG_CRITICAL
, "FATAL: require-proxy-header option is not supported on ftp_port.");
3835 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3836 // clone the port options from *s to *(s->next)
3837 s
->next
= s
->clone();
3838 s
->next
->s
.setIPv4();
3839 debugs(3, 3, AnyP::UriScheme(s
->transport
.protocol
).image() << "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3842 while (*head
!= NULL
)
3843 head
= &((*head
)->next
);
3849 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3851 char buf
[MAX_IPSTRLEN
];
3853 storeAppendPrintf(e
, "%s %s",
3855 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3857 // MODES and specific sub-options.
3858 if (s
->flags
.natIntercept
)
3859 storeAppendPrintf(e
, " intercept");
3861 else if (s
->flags
.tproxyIntercept
)
3862 storeAppendPrintf(e
, " tproxy");
3864 else if (s
->flags
.proxySurrogate
)
3865 storeAppendPrintf(e
, " require-proxy-header");
3867 else if (s
->flags
.accelSurrogate
) {
3868 storeAppendPrintf(e
, " accel");
3871 storeAppendPrintf(e
, " vhost");
3874 storeAppendPrintf(e
, " vport");
3875 else if (s
->vport
> 0)
3876 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3879 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3881 // TODO: compare against prefix of 'n' instead of assuming http_port
3882 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3883 storeAppendPrintf(e
, " protocol=%s", AnyP::ProtocolType_str
[s
->transport
.protocol
]);
3885 if (s
->allow_direct
)
3886 storeAppendPrintf(e
, " allow-direct");
3889 storeAppendPrintf(e
, " ignore-cc");
3893 // Generic independent options
3896 storeAppendPrintf(e
, " name=%s", s
->name
);
3898 #if USE_HTTP_VIOLATIONS
3899 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3900 storeAppendPrintf(e
, " ignore-cc");
3903 if (s
->connection_auth_disabled
)
3904 storeAppendPrintf(e
, " connection-auth=off");
3906 storeAppendPrintf(e
, " connection-auth=on");
3908 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3911 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3914 pmtu
= "transparent";
3916 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3919 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3920 storeAppendPrintf(e
, " ipv4");
3922 if (s
->tcp_keepalive
.enabled
) {
3923 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3924 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3926 storeAppendPrintf(e
, " tcpkeepalive");
3931 if (s
->flags
.tunnelSslBumping
)
3932 storeAppendPrintf(e
, " ssl-bump");
3935 s
->secure
.dumpCfg(e
, "tls-");
3939 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3941 for (AnyP::PortCfgPointer p
= s
; p
!= NULL
; p
= p
->next
) {
3942 dump_generic_port(e
, n
, p
);
3943 storeAppendPrintf(e
, "\n");
3948 configFreeMemory(void)
3951 Config
.ssl_client
.sslContext
.reset();
3953 Ssl::unloadSquidUntrusted();
3958 requirePathnameExists(const char *name
, const char *path
)
3962 char pathbuf
[BUFSIZ
];
3963 assert(path
!= NULL
);
3965 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3966 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3970 if (stat(path
, &sb
) < 0) {
3972 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL: ":"ERROR: ") << name
<< " " << path
<< ": " << xstrerr(xerrno
));
3973 // keep going to find more issues if we are only checking the config file with "-k parse"
3974 if (opt_parse_cfg_only
)
3976 // this is fatal if it is found during startup or reconfigure
3977 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3978 fatalf("%s %s: %s", name
, path
, xstrerr(xerrno
));
3982 #include "AccessLogEntry.h"
3985 * We support several access_log configuration styles:
3987 * #1: Deprecated ancient style without an explicit logging module:
3988 * access_log /var/log/access.log
3990 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
3991 * access_log none [acl ...]
3993 * #3: Configurable logging module without named options:
3994 * Logformat or the first ACL name, whichever comes first, may not contain '='.
3995 * If no explicit logformat name is given, the first ACL name, if any,
3996 * should not be an existing logformat name or it will be treated as such.
3997 * access_log module:place [logformat_name] [acl ...]
3999 * #4: Configurable logging module with name=value options such as logformat=x:
4000 * The first ACL name may not contain '='.
4001 * access_log module:place [option ...] [acl ...]
4005 parse_access_log(CustomLog
** logs
)
4007 const char *filename
= ConfigParser::NextToken();
4013 CustomLog
*cl
= (CustomLog
*)xcalloc(1, sizeof(*cl
));
4015 cl
->filename
= xstrdup(filename
);
4016 // default buffer size and fatal settings
4017 cl
->bufferSize
= 8*MAX_URL
;
4020 if (strcmp(filename
, "none") == 0) {
4021 cl
->type
= Log::Format::CLF_NONE
;
4022 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
4024 logs
= &(*logs
)->next
;
4029 cl
->type
= Log::Format::CLF_UNKNOWN
;
4030 cl
->rotateCount
= -1; // default: use global logfile_rotate setting.
4032 const char *token
= ConfigParser::PeekAtToken();
4033 if (!token
) { // style #1
4034 // no options to deal with
4035 } else if (!strchr(token
, '=')) { // style #3
4036 // if logformat name is recognized,
4037 // pop the previewed token; Else it must be an ACL name
4038 if (setLogformat(cl
, token
, false))
4039 (void)ConfigParser::NextToken();
4040 } else { // style #4
4042 if (strncasecmp(token
, "on-error=", 9) == 0) {
4043 if (strncasecmp(token
+9, "die", 3) == 0) {
4045 } else if (strncasecmp(token
+9, "drop", 4) == 0) {
4048 debugs(3, DBG_CRITICAL
, "Unknown value for on-error '" <<
4049 token
<< "' expected 'drop' or 'die'");
4050 xfree(cl
->filename
);
4055 } else if (strncasecmp(token
, "buffer-size=", 12) == 0) {
4056 parseBytesOptionValue(&cl
->bufferSize
, B_BYTES_STR
, token
+12);
4057 } else if (strncasecmp(token
, "rotate=", 7) == 0) {
4058 cl
->rotateCount
= xatoi(token
+ 7);
4059 } else if (strncasecmp(token
, "logformat=", 10) == 0) {
4060 setLogformat(cl
, token
+10, true);
4061 } else if (!strchr(token
, '=')) {
4062 // Do not pop the token; it must be an ACL name
4063 break; // done with name=value options, now to ACLs
4065 debugs(3, DBG_CRITICAL
, "Unknown access_log option " << token
);
4066 xfree(cl
->filename
);
4071 // Pop the token, it was a valid "name=value" option
4072 (void)ConfigParser::NextToken();
4073 // Get next with preview ConfigParser::NextToken call.
4074 } while ((token
= ConfigParser::PeekAtToken()) != NULL
);
4077 // set format if it has not been specified explicitly
4078 if (cl
->type
== Log::Format::CLF_UNKNOWN
)
4079 setLogformat(cl
, "squid", true);
4081 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4084 logs
= &(*logs
)->next
;
4089 /// sets CustomLog::type and, if needed, CustomLog::lf
4090 /// returns false iff there is no named log format
4092 setLogformat(CustomLog
*cl
, const char *logdef_name
, const bool dieWhenMissing
)
4095 assert(logdef_name
);
4097 debugs(3, 9, "possible " << cl
->filename
<< " logformat: " << logdef_name
);
4099 if (cl
->type
!= Log::Format::CLF_UNKNOWN
) {
4100 debugs(3, DBG_CRITICAL
, "FATAL: Second logformat name in one access_log: " <<
4101 logdef_name
<< " " << cl
->type
<< " ? " << Log::Format::CLF_NONE
);
4106 /* look for the definition pointer corresponding to this name */
4107 Format::Format
*lf
= Log::TheConfig
.logformats
;
4109 while (lf
!= NULL
) {
4110 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4112 if (strcmp(lf
->name
, logdef_name
) == 0)
4119 cl
->type
= Log::Format::CLF_CUSTOM
;
4121 } else if (strcmp(logdef_name
, "auto") == 0) {
4122 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4123 cl
->type
= Log::Format::CLF_SQUID
;
4124 } else if (strcmp(logdef_name
, "squid") == 0) {
4125 cl
->type
= Log::Format::CLF_SQUID
;
4126 } else if (strcmp(logdef_name
, "common") == 0) {
4127 cl
->type
= Log::Format::CLF_COMMON
;
4128 } else if (strcmp(logdef_name
, "combined") == 0) {
4129 cl
->type
= Log::Format::CLF_COMBINED
;
4131 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4132 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4134 } else if (strcmp(logdef_name
, "useragent") == 0) {
4135 cl
->type
= Log::Format::CLF_USERAGENT
;
4136 } else if (strcmp(logdef_name
, "referrer") == 0) {
4137 cl
->type
= Log::Format::CLF_REFERER
;
4138 } else if (dieWhenMissing
) {
4139 debugs(3, DBG_CRITICAL
, "FATAL: Log format '" << logdef_name
<< "' is not defined");
4150 check_null_access_log(CustomLog
*customlog_definitions
)
4152 return customlog_definitions
== NULL
;
4156 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4160 for (log
= logs
; log
; log
= log
->next
) {
4161 storeAppendPrintf(entry
, "%s ", name
);
4163 switch (log
->type
) {
4165 case Log::Format::CLF_CUSTOM
:
4166 storeAppendPrintf(entry
, "%s logformat=%s", log
->filename
, log
->logFormat
->name
);
4169 case Log::Format::CLF_NONE
:
4170 storeAppendPrintf(entry
, "logformat=none");
4173 case Log::Format::CLF_SQUID
:
4174 // this is the default, no need to add to the dump
4175 //storeAppendPrintf(entry, "%s logformat=squid", log->filename);
4178 case Log::Format::CLF_COMBINED
:
4179 storeAppendPrintf(entry
, "%s logformat=combined", log
->filename
);
4182 case Log::Format::CLF_COMMON
:
4183 storeAppendPrintf(entry
, "%s logformat=common", log
->filename
);
4187 case Log::Format::CLF_ICAP_SQUID
:
4188 storeAppendPrintf(entry
, "%s logformat=icap_squid", log
->filename
);
4191 case Log::Format::CLF_USERAGENT
:
4192 storeAppendPrintf(entry
, "%s logformat=useragent", log
->filename
);
4195 case Log::Format::CLF_REFERER
:
4196 storeAppendPrintf(entry
, "%s logformat=referrer", log
->filename
);
4199 case Log::Format::CLF_UNKNOWN
:
4203 // default is on-error=die
4205 storeAppendPrintf(entry
, " on-error=drop");
4208 if (log
->bufferSize
!= 64*1024)
4209 storeAppendPrintf(entry
, " buffer-size=%" PRIuSIZE
, log
->bufferSize
);
4211 if (log
->rotateCount
>= 0)
4212 storeAppendPrintf(entry
, " rotate=%d", log
->rotateCount
);
4215 dump_acl_list(entry
, log
->aclList
);
4217 storeAppendPrintf(entry
, "\n");
4222 free_access_log(CustomLog
** definitions
)
4224 while (*definitions
) {
4225 CustomLog
*log
= *definitions
;
4226 *definitions
= log
->next
;
4228 log
->logFormat
= NULL
;
4229 log
->type
= Log::Format::CLF_UNKNOWN
;
4232 aclDestroyAclList(&log
->aclList
);
4234 safe_free(log
->filename
);
4240 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4241 /// parses list of integers form name=N1,N2,N3,...
4243 parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
)
4245 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4246 data
+= name
.size();
4251 if (!StringToInt(data
, value
, &data
, 10))
4253 list
.push_back(value
);
4254 if (*data
== '\0' || *data
!= ',')
4259 return data
&& *data
== '\0';
4264 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4266 #if !HAVE_CPU_AFFINITY
4267 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4268 "support, do not set 'cpu_affinity_map'");
4271 #else /* HAVE_CPU_AFFINITY */
4272 if (!*cpuAffinityMap
)
4273 *cpuAffinityMap
= new CpuAffinityMap
;
4275 const char *const pToken
= ConfigParser::NextToken();
4276 const char *const cToken
= ConfigParser::NextToken();
4277 std::vector
<int> processes
, cores
;
4278 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4279 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4280 "in 'cpu_affinity_map'");
4282 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4283 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4284 "'cpu_affinity_map'");
4286 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4287 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4288 "process_numbers and cores lists differ in length or " <<
4289 "contain numbers <= 0");
4296 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4298 if (cpuAffinityMap
) {
4299 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4300 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4301 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4302 cpuAffinityMap
->processes()[i
]);
4304 storeAppendPrintf(entry
, " cores=");
4305 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4306 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4307 cpuAffinityMap
->cores()[i
]);
4309 storeAppendPrintf(entry
, "\n");
4314 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4316 delete *cpuAffinityMap
;
4317 *cpuAffinityMap
= NULL
;
4323 parse_adaptation_service_set_type()
4325 Adaptation::Config::ParseServiceSet();
4329 parse_adaptation_service_chain_type()
4331 Adaptation::Config::ParseServiceChain();
4335 parse_adaptation_access_type()
4337 Adaptation::Config::ParseAccess(LegacyParser
);
4339 #endif /* USE_ADAPTATION */
4344 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4346 cfg
->parseService();
4350 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4356 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4358 cfg
.dumpService(entry
, name
);
4362 parse_icap_class_type()
4364 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is deprecated. " <<
4365 "Use 'adaptation_service_set' instead");
4366 Adaptation::Config::ParseServiceSet();
4370 parse_icap_access_type()
4372 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is deprecated. " <<
4373 "Use 'adaptation_access' instead");
4374 Adaptation::Config::ParseAccess(LegacyParser
);
4382 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4384 cfg
->parseService();
4388 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4394 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4396 cfg
.dumpService(entry
, name
);
4399 #endif /* USE_ECAP */
4402 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4407 cfg
->service_failure_limit
= GetInteger();
4409 if ((token
= ConfigParser::NextToken()) == NULL
)
4412 if (strcmp(token
,"in") != 0) {
4413 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4418 if ((token
= ConfigParser::NextToken()) == NULL
) {
4423 d
= static_cast<time_t> (xatoi(token
));
4425 m
= static_cast<time_t> (1);
4429 else if ((token
= ConfigParser::NextToken()) == NULL
) {
4430 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4433 } else if ((m
= parseTimeUnits(token
, false)) == 0) {
4438 cfg
->oldest_service_failure
= (m
* d
);
4441 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4443 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4444 if (cfg
.oldest_service_failure
> 0) {
4445 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4447 storeAppendPrintf(entry
, "\n");
4450 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4452 cfg
->oldest_service_failure
= 0;
4453 cfg
->service_failure_limit
= 0;
4458 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4461 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4462 if ((al
= ConfigParser::NextToken()) == NULL
) {
4469 if ( char *s
= strchr(al
, '{')) {
4470 *s
= '\0'; // terminate the al string
4483 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4484 ca
->alg
= Ssl::algSetValidAfter
;
4485 ca
->param
= xstrdup("on");
4486 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4487 ca
->alg
= Ssl::algSetValidBefore
;
4488 ca
->param
= xstrdup("on");
4489 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4490 ca
->alg
= Ssl::algSetCommonName
;
4492 if (strlen(param
) > 64) {
4493 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4498 ca
->param
= xstrdup(param
);
4501 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4507 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4510 cert_adapt
= &(*cert_adapt
)->next
;
4515 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4517 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4518 storeAppendPrintf(entry
, "%s ", name
);
4519 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4521 dump_acl_list(entry
, ca
->aclList
);
4522 storeAppendPrintf(entry
, "\n");
4526 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4528 while (*cert_adapt
) {
4529 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4530 *cert_adapt
= ca
->next
;
4531 safe_free(ca
->param
);
4534 aclDestroyAclList(&ca
->aclList
);
4540 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4543 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4544 if ((al
= ConfigParser::NextToken()) == NULL
) {
4550 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4551 cs
->alg
= Ssl::algSignTrusted
;
4552 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4553 cs
->alg
= Ssl::algSignUntrusted
;
4554 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4555 cs
->alg
= Ssl::algSignSelf
;
4557 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4563 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4566 cert_sign
= &(*cert_sign
)->next
;
4571 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4573 sslproxy_cert_sign
*cs
;
4574 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4575 storeAppendPrintf(entry
, "%s ", name
);
4576 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4578 dump_acl_list(entry
, cs
->aclList
);
4579 storeAppendPrintf(entry
, "\n");
4583 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4585 while (*cert_sign
) {
4586 sslproxy_cert_sign
*cs
= *cert_sign
;
4587 *cert_sign
= cs
->next
;
4590 aclDestroyAclList(&cs
->aclList
);
4596 class sslBumpCfgRr
: public ::RegisteredRunner
4599 static Ssl::BumpMode lastDeprecatedRule
;
4600 /* RegisteredRunner API */
4601 virtual void finalizeConfig();
4604 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4606 RunnerRegistrationEntry(sslBumpCfgRr
);
4609 sslBumpCfgRr::finalizeConfig()
4611 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4612 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4613 static char buf
[1024];
4614 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4615 strcpy(buf
, "ssl_bump deny all");
4616 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4617 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4618 "must not use implicit rules. Update your ssl_bump rules.");
4620 strcpy(buf
, "ssl_bump allow all");
4621 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4622 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4623 "inferior to the newer server-first bumping mode. New ssl_bump"
4624 " configurations must not use implicit rules. Update your ssl_bump rules.");
4630 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4632 typedef const char *BumpCfgStyle
;
4633 BumpCfgStyle bcsNone
= NULL
;
4634 BumpCfgStyle bcsNew
= "new client/server-first/none";
4635 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4636 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4637 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4639 if ((bm
= ConfigParser::NextToken()) == NULL
) {
4644 // if this is the first rule proccessed
4645 if (*ssl_bump
== NULL
) {
4646 bumpCfgStyleLast
= bcsNone
;
4647 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4650 allow_t action
= allow_t(ACCESS_ALLOWED
);
4652 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4653 action
.kind
= Ssl::bumpClientFirst
;
4654 bumpCfgStyleNow
= bcsNew
;
4655 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4656 action
.kind
= Ssl::bumpServerFirst
;
4657 bumpCfgStyleNow
= bcsNew
;
4658 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpPeek
]) == 0) {
4659 action
.kind
= Ssl::bumpPeek
;
4660 bumpCfgStyleNow
= bcsNew
;
4661 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpStare
]) == 0) {
4662 action
.kind
= Ssl::bumpStare
;
4663 bumpCfgStyleNow
= bcsNew
;
4664 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpSplice
]) == 0) {
4665 action
.kind
= Ssl::bumpSplice
;
4666 bumpCfgStyleNow
= bcsNew
;
4667 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpBump
]) == 0) {
4668 action
.kind
= Ssl::bumpBump
;
4669 bumpCfgStyleNow
= bcsNew
;
4670 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpTerminate
]) == 0) {
4671 action
.kind
= Ssl::bumpTerminate
;
4672 bumpCfgStyleNow
= bcsNew
;
4673 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4674 action
.kind
= Ssl::bumpNone
;
4675 bumpCfgStyleNow
= bcsNew
;
4676 } else if (strcmp(bm
, "allow") == 0) {
4677 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4678 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4679 "is usually inferior to the newer server-first "
4680 "bumping mode. Update your ssl_bump rules.");
4681 action
.kind
= Ssl::bumpClientFirst
;
4682 bumpCfgStyleNow
= bcsOld
;
4683 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4684 } else if (strcmp(bm
, "deny") == 0) {
4685 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4686 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4687 "your ssl_bump rules.");
4688 action
.kind
= Ssl::bumpNone
;
4689 bumpCfgStyleNow
= bcsOld
;
4690 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4692 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4697 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4698 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4699 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4704 bumpCfgStyleLast
= bumpCfgStyleNow
;
4707 ParseAclWithAction(ssl_bump
, action
, "ssl_bump");
4710 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4713 dump_SBufList(entry
, ssl_bump
->treeDump(name
, [](const allow_t
&action
) {
4714 return Ssl::BumpModeStr
.at(action
.kind
);
4718 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4720 free_acl_access(ssl_bump
);
4725 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4730 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4731 storeAppendPrintf(entry
, "%s %s %s", name
, hwa
->fieldName
.c_str(), hwa
->fieldValue
.c_str());
4733 dump_acl_list(entry
, hwa
->aclList
);
4734 storeAppendPrintf(entry
, "\n");
4738 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4742 *headers
= new HeaderWithAclList
;
4744 if ((fn
= ConfigParser::NextToken()) == NULL
) {
4750 hwa
.fieldId
= Http::HeaderLookupTable
.lookup(hwa
.fieldName
).id
;
4751 if (hwa
.fieldId
== Http::HdrType::BAD_HDR
)
4752 hwa
.fieldId
= Http::HdrType::OTHER
;
4754 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4755 ConfigParser::EnableMacros();
4756 String buf
= ConfigParser::NextQuotedToken();
4757 ConfigParser::DisableMacros();
4758 hwa
.fieldValue
= buf
.termedBuf();
4759 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4761 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4765 hwa
.valueFormat
= nlf
;
4768 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4769 (*headers
)->push_back(hwa
);
4772 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4777 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4779 aclDestroyAclList(&hwa
->aclList
);
4781 if (hwa
->valueFormat
) {
4782 delete hwa
->valueFormat
;
4783 hwa
->valueFormat
= NULL
;
4790 static void parse_note(Notes
*notes
)
4793 notes
->parse(LegacyParser
);
4796 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4798 notes
.dump(entry
, name
);
4801 static void free_note(Notes
*notes
)
4806 static bool FtpEspvDeprecated
= false;
4807 static void parse_ftp_epsv(acl_access
**ftp_epsv
)
4809 allow_t ftpEpsvDeprecatedAction
;
4810 bool ftpEpsvIsDeprecatedRule
= false;
4812 char *t
= ConfigParser::PeekAtToken();
4818 if (!strcmp(t
, "off")) {
4819 (void)ConfigParser::NextToken();
4820 ftpEpsvIsDeprecatedRule
= true;
4821 ftpEpsvDeprecatedAction
= allow_t(ACCESS_DENIED
);
4822 } else if (!strcmp(t
, "on")) {
4823 (void)ConfigParser::NextToken();
4824 ftpEpsvIsDeprecatedRule
= true;
4825 ftpEpsvDeprecatedAction
= allow_t(ACCESS_ALLOWED
);
4828 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4829 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4830 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4832 if ((!ftpEpsvIsDeprecatedRule
&& FtpEspvDeprecated
) ||
4833 (ftpEpsvIsDeprecatedRule
&& !FtpEspvDeprecated
&& *ftp_epsv
!= NULL
)) {
4834 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.");
4839 if (ftpEpsvIsDeprecatedRule
) {
4840 // overwrite previous ftp_epsv lines
4842 *ftp_epsv
= nullptr;
4844 if (ftpEpsvDeprecatedAction
== allow_t(ACCESS_DENIED
)) {
4845 if (ACL
*a
= ACL::FindByName("all"))
4846 ParseAclWithAction(ftp_epsv
, ftpEpsvDeprecatedAction
, "ftp_epsv", a
);
4852 FtpEspvDeprecated
= true;
4854 aclParseAccessLine(cfg_directive
, LegacyParser
, ftp_epsv
);
4858 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
)
4861 dump_SBufList(entry
, ftp_epsv
->treeDump(name
, Acl::AllowOrDeny
));
4864 static void free_ftp_epsv(acl_access
**ftp_epsv
)
4866 free_acl_access(ftp_epsv
);
4867 FtpEspvDeprecated
= false;
4871 parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4874 parseTimeLine(&tval
, T_SECOND_STR
, false, true);
4875 Config
.Timeout
.urlRewrite
= static_cast<time_t>(tval
/1000);
4878 while(ConfigParser::NextKvPair(key
, value
)) {
4879 if (strcasecmp(key
, "on_timeout") == 0) {
4880 if (strcasecmp(value
, "bypass") == 0)
4881 config
->action
= toutActBypass
;
4882 else if (strcasecmp(value
, "fail") == 0)
4883 config
->action
= toutActFail
;
4884 else if (strcasecmp(value
, "retry") == 0)
4885 config
->action
= toutActRetry
;
4886 else if (strcasecmp(value
, "use_configured_response") == 0) {
4887 config
->action
= toutActUseConfiguredResponse
;
4889 debugs(3, DBG_CRITICAL
, "FATAL: unsupported \"on_timeout\" action: " << value
);
4893 } else if (strcasecmp(key
, "response") == 0) {
4894 config
->response
= xstrdup(value
);
4896 debugs(3, DBG_CRITICAL
, "FATAL: unsupported option " << key
);
4902 if (config
->action
== toutActUseConfiguredResponse
&& !config
->response
) {
4903 debugs(3, DBG_CRITICAL
, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4907 if (config
->action
!= toutActUseConfiguredResponse
&& config
->response
) {
4908 debugs(3, DBG_CRITICAL
, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4914 dump_UrlHelperTimeout(StoreEntry
*entry
, const char *name
, SquidConfig::UrlHelperTimeout
&config
)
4916 const char *onTimedOutActions
[] = {"bypass", "fail", "retry", "use_configured_response"};
4917 assert(config
.action
>= 0 && config
.action
<= toutActUseConfiguredResponse
);
4919 dump_time_t(entry
, name
, Config
.Timeout
.urlRewrite
);
4920 storeAppendPrintf(entry
, " on_timeout=%s", onTimedOutActions
[config
.action
]);
4922 if (config
.response
)
4923 storeAppendPrintf(entry
, " response=\"%s\"", config
.response
);
4925 storeAppendPrintf(entry
, "\n");
4929 free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4931 Config
.Timeout
.urlRewrite
= 0;
4933 safe_free(config
->response
);
4937 parse_configuration_includes_quoted_values(bool *)
4942 // If quoted values is set to on then enable new strict mode parsing
4944 ConfigParser::RecognizeQuotedValues
= true;
4945 ConfigParser::StrictMode
= true;
4947 ConfigParser::RecognizeQuotedValues
= false;
4948 ConfigParser::StrictMode
= false;
4953 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool)
4955 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4956 dump_onoff(entry
, name
, val
);
4960 free_configuration_includes_quoted_values(bool *)
4962 ConfigParser::RecognizeQuotedValues
= false;
4963 ConfigParser::StrictMode
= false;
4967 parse_on_unsupported_protocol(acl_access
**access
)
4970 if ((tm
= ConfigParser::NextToken()) == NULL
) {
4975 allow_t action
= allow_t(ACCESS_ALLOWED
);
4976 if (strcmp(tm
, "tunnel") == 0)
4978 else if (strcmp(tm
, "respond") == 0)
4981 debugs(3, DBG_CRITICAL
, "FATAL: unknown on_unsupported_protocol mode: " << tm
);
4987 ParseAclWithAction(access
, action
, "on_unsupported_protocol");
4991 dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
)
4993 static const std::vector
<const char *> onErrorTunnelMode
= {
4999 SBufList lines
= access
->treeDump(name
, [](const allow_t
&action
) {
5000 return onErrorTunnelMode
.at(action
.kind
);
5002 dump_SBufList(entry
, lines
);
5007 free_on_unsupported_protocol(acl_access
**access
)
5009 free_acl_access(access
);