2 * Copyright (C) 1996-2016 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"
22 #include "base/RunnersRegistry.h"
24 #include "CachePeer.h"
25 #include "ConfigParser.h"
26 #include "CpuAffinityMap.h"
27 #include "DiskIO/DiskIOModule.h"
28 #include "eui/Config.h"
29 #include "ExternalACL.h"
30 #include "format/Format.h"
31 #include "ftp/Elements.h"
33 #include "HttpHeaderTools.h"
34 #include "icmp/IcmpConfig.h"
35 #include "ident/Config.h"
36 #include "ip/Intercept.h"
37 #include "ip/QosConfig.h"
40 #include "log/Config.h"
41 #include "log/CustomLog.h"
43 #include "mgr/ActionPasswordList.h"
44 #include "mgr/Registration.h"
45 #include "neighbors.h"
46 #include "NeighborTypeDomainList.h"
49 #include "PeerDigest.h"
50 #include "PeerPoolMgr.h"
52 #include "RefreshPattern.h"
54 #include "sbuf/List.h"
55 #include "SquidConfig.h"
56 #include "SquidString.h"
57 #include "ssl/ProxyCerts.h"
59 #include "store/Disk.h"
60 #include "store/Disks.h"
61 #include "StoreFileSystem.h"
65 /* wccp2 has its own conditional definitions */
68 #include "adaptation/Config.h"
71 #include "adaptation/icap/Config.h"
74 #include "adaptation/ecap/Config.h"
77 #include "ssl/Config.h"
78 #include "ssl/support.h"
81 #include "auth/Config.h"
82 #include "auth/Scheme.h"
83 #include "auth/SchemesConfig.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
);
174 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
176 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
177 static size_t parseBytesUnits(const char *unit
);
178 static void free_all(void);
179 void requirePathnameExists(const char *name
, const char *path
);
180 static OBJH dump_config
;
181 #if USE_HTTP_VIOLATIONS
182 static void free_HeaderManglers(HeaderManglers
**pm
);
183 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
184 static void parse_http_header_access(HeaderManglers
**manglers
);
185 #define free_http_header_access free_HeaderManglers
186 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
187 static void parse_http_header_replace(HeaderManglers
**manglers
);
188 #define free_http_header_replace free_HeaderManglers
190 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
191 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
192 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
193 static void parse_note(Notes
*);
194 static void dump_note(StoreEntry
*, const char *, Notes
&);
195 static void free_note(Notes
*);
196 static void parse_denyinfo(AclDenyInfoList
** var
);
197 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
198 static void free_denyinfo(AclDenyInfoList
** var
);
201 static void parse_IpAddress_list(Ip::Address_list
**);
202 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
203 static void free_IpAddress_list(Ip::Address_list
**);
205 static int check_null_IpAddress_list(const Ip::Address_list
*);
206 #endif /* CURRENTLY_UNUSED */
207 #endif /* USE_WCCPv2 */
209 static void parsePortCfg(AnyP::PortCfgPointer
*, const char *protocol
);
210 #define parse_PortCfg(l) parsePortCfg((l), token)
211 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfgPointer
&);
212 #define free_PortCfg(h) *(h)=NULL
215 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
216 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
217 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
218 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
219 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
220 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
221 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
222 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
223 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
224 #endif /* USE_OPENSSL */
226 static void parse_ftp_epsv(acl_access
**ftp_epsv
);
227 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
);
228 static void free_ftp_epsv(acl_access
**ftp_epsv
);
230 static void parse_b_size_t(size_t * var
);
231 static void parse_b_int64_t(int64_t * var
);
233 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
234 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
235 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
237 static void parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
238 static void dump_UrlHelperTimeout(StoreEntry
*, const char *, SquidConfig::UrlHelperTimeout
&);
239 static void free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*);
241 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
243 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
244 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
245 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
246 static void parse_on_unsupported_protocol(acl_access
**access
);
247 static void dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
);
248 static void free_on_unsupported_protocol(acl_access
**access
);
249 static void ParseAclWithAction(acl_access
**access
, const allow_t
&action
, const char *desc
, ACL
*acl
= nullptr);
252 * LegacyParser is a parser for legacy code that uses the global
253 * approach. This is static so that it is only exposed to cache_cf.
254 * Other modules needing access to a ConfigParser should have it
255 * provided to them in their parserFOO methods.
257 static ConfigParser LegacyParser
= ConfigParser();
262 LegacyParser
.destruct();
266 SetConfigFilename(char const *file_name
, bool is_pipe
)
269 cfg_filename
= file_name
+ 1;
271 cfg_filename
= file_name
;
275 skip_ws(const char* s
)
284 parseManyConfigFiles(char* files
, int depth
)
287 char* saveptr
= NULL
;
292 memset(&globbuf
, 0, sizeof(globbuf
));
293 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
294 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
296 fatalf("Unable to find configuration file: %s: %s", path
, xstrerr(xerrno
));
299 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
300 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
304 char* file
= strwordtok(files
, &saveptr
);
305 while (file
!= NULL
) {
306 error_count
+= parseOneConfigFile(file
, depth
);
307 file
= strwordtok(NULL
, &saveptr
);
309 #endif /* HAVE_GLOB */
314 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
317 assert(newSubstr
!= NULL
);
319 unsigned newSubstrLen
= strlen(newSubstr
);
320 if (newSubstrLen
> substrLen
)
321 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
323 // move tail part including zero
324 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
325 // copy new substring in place
326 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
332 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
334 assert(line
!= NULL
);
335 assert(macroName
!= NULL
);
336 assert(substStr
!= NULL
);
337 unsigned macroNameLen
= strlen(macroName
);
338 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
339 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
343 ProcessMacros(char*& line
, int& len
)
345 SubstituteMacro(line
, len
, "${service_name}", service_name
.c_str());
346 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
347 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
351 trim_trailing_ws(char* str
)
354 unsigned i
= strlen(str
);
355 while ((i
> 0) && xisspace(str
[i
- 1]))
361 FindStatement(const char* line
, const char* statement
)
363 assert(line
!= NULL
);
364 assert(statement
!= NULL
);
366 const char* str
= skip_ws(line
);
367 unsigned len
= strlen(statement
);
368 if (strncmp(str
, statement
, len
) == 0) {
372 else if (xisspace(*str
))
380 StrToInt(const char* str
, long& number
)
385 number
= strtol(str
, &end
, 0);
387 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
391 EvalBoolExpr(const char* expr
)
393 assert(expr
!= NULL
);
394 if (strcmp(expr
, "true") == 0) {
396 } else if (strcmp(expr
, "false") == 0) {
398 } else if (const char* equation
= strchr(expr
, '=')) {
399 const char* rvalue
= skip_ws(equation
+ 1);
400 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
401 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
402 trim_trailing_ws(lvalue
);
405 if (!StrToInt(lvalue
, number1
))
406 fatalf("String is not a integer number: '%s'\n", lvalue
);
408 if (!StrToInt(rvalue
, number2
))
409 fatalf("String is not a integer number: '%s'\n", rvalue
);
412 return number1
== number2
;
414 fatalf("Unable to evaluate expression '%s'\n", expr
);
415 return false; // this place cannot be reached
419 parseOneConfigFile(const char *file_name
, unsigned int depth
)
422 const char *orig_cfg_filename
= cfg_filename
;
423 const int orig_config_lineno
= config_lineno
;
425 char *tmp_line
= NULL
;
426 int tmp_line_len
= 0;
430 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
432 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
436 if (file_name
[0] == '!' || file_name
[0] == '|') {
437 fp
= popen(file_name
+ 1, "r");
440 fp
= fopen(file_name
, "r");
445 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerr(xerrno
));
449 setmode(fileno(fp
), O_TEXT
);
452 SetConfigFilename(file_name
, bool(is_pipe
));
454 memset(config_input_line
, '\0', BUFSIZ
);
458 std::vector
<bool> if_states
;
459 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
462 if ((token
= strchr(config_input_line
, '\n')))
465 if ((token
= strchr(config_input_line
, '\r')))
468 // strip any prefix whitespace off the line.
469 const char *p
= skip_ws(config_input_line
);
470 if (config_input_line
!= p
)
471 memmove(config_input_line
, p
, strlen(p
)+1);
473 if (strncmp(config_input_line
, "#line ", 6) == 0) {
474 static char new_file_name
[1024];
476 static char new_lineno
;
477 token
= config_input_line
+ 6;
478 new_lineno
= strtol(token
, &file
, 0) - 1;
481 continue; /* Not a valid #line directive, may be a comment */
483 while (*file
&& xisspace((unsigned char) *file
))
488 continue; /* Not a valid #line directive, may be a comment */
490 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
492 if ((token
= strchr(new_file_name
, '"')))
495 SetConfigFilename(new_file_name
, false);
498 config_lineno
= new_lineno
;
501 if (config_input_line
[0] == '#')
504 if (config_input_line
[0] == '\0')
507 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
509 size_t append_len
= strlen(append
);
511 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
513 strcpy(tmp_line
+ tmp_line_len
, append
);
515 tmp_line_len
+= append_len
;
517 if (tmp_line
[tmp_line_len
-1] == '\\') {
518 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
519 tmp_line
[--tmp_line_len
] = '\0';
523 trim_trailing_ws(tmp_line
);
524 ProcessMacros(tmp_line
, tmp_line_len
);
525 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
527 if (const char* expr
= FindStatement(tmp_line
, "if")) {
528 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
529 } else if (FindStatement(tmp_line
, "endif")) {
530 if (!if_states
.empty())
531 if_states
.pop_back(); // remove last if-statement meaning
533 fatalf("'endif' without 'if'\n");
534 } else if (FindStatement(tmp_line
, "else")) {
535 if (!if_states
.empty())
536 if_states
.back() = !if_states
.back();
538 fatalf("'else' without 'if'\n");
539 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
540 /* Handle includes here */
541 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
542 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
543 } else if (!parse_line(tmp_line
)) {
544 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
553 if (!if_states
.empty())
554 fatalf("if-statement without 'endif'\n");
557 int ret
= pclose(fp
);
560 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
565 SetConfigFilename(orig_cfg_filename
, false);
566 config_lineno
= orig_config_lineno
;
573 parseConfigFile(const char *file_name
)
581 ACLMethodData::ThePurgeCount
= 0;
584 err_count
= parseOneConfigFile(file_name
, 0);
588 defaults_postscriptum();
591 * We must call configDoConfigure() before leave_suid() because
592 * configDoConfigure() is where we turn username strings into
597 if (!Config
.chroot_dir
) {
599 setUmask(Config
.umask
);
600 _db_init(Debug::cache_log
, Debug::debugOptions
);
604 if (opt_send_signal
== -1) {
605 Mgr::RegisterAction("config",
606 "Current Squid Configuration",
615 configDoConfigure(void)
618 /* init memory as early as possible */
622 Config
.cacheSwap
.n_strands
= 0; // no diskers by default
623 if (Config
.cacheSwap
.swapDirs
== NULL
) {
624 /* Memory-only cache probably in effect. */
625 /* turn off the cache rebuild delays... */
626 StoreController::store_dirs_rebuilding
= 0;
627 } else if (InDaemonMode()) { // no diskers in non-daemon mode
628 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
629 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
630 if (sd
->needsDiskStrand())
631 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
635 if (Debug::rotateNumber
< 0) {
636 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
639 #if SIZEOF_OFF_T <= 4
640 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
641 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
642 Config
.Store
.maxObjectSize
= 0x7FFF0000;
646 if (Config
.Announce
.period
> 0) {
647 Config
.onoff
.announce
= 1;
649 Config
.Announce
.period
= 86400 * 365; /* one year */
650 Config
.onoff
.announce
= 0;
653 if (Config
.onoff
.httpd_suppress_version_string
)
654 visible_appname_string
= (char *)appname_string
;
656 visible_appname_string
= (char const *)APP_FULLNAME
;
658 if (Config
.Program
.redirect
) {
659 if (Config
.redirectChildren
.n_max
< 1) {
660 Config
.redirectChildren
.n_max
= 0;
661 wordlistDestroy(&Config
.Program
.redirect
);
665 if (Config
.Program
.store_id
) {
666 if (Config
.storeIdChildren
.n_max
< 1) {
667 Config
.storeIdChildren
.n_max
= 0;
668 wordlistDestroy(&Config
.Program
.store_id
);
672 if (Config
.appendDomain
)
673 if (*Config
.appendDomain
!= '.')
674 fatal("append_domain must begin with a '.'");
676 if (Config
.errHtmlText
== NULL
)
677 Config
.errHtmlText
= xstrdup(null_string
);
679 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
680 if (Config
.max_filedescriptors
> 0) {
681 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
683 #elif USE_SELECT || USE_SELECT_WIN32
684 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
685 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
691 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
693 visible_appname_string
);
696 * the extra space is for loop detection in client_side.c -- we search
697 * for substrings in the Via header.
699 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
701 visible_appname_string
);
703 /* Use visible_hostname as default surrogate_id */
704 if (!Config
.Accel
.surrogate_id
) {
705 const char *t
= getMyHostname();
706 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
709 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
710 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
712 if (Config
.appendDomain
)
713 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
715 Config
.appendDomainLen
= 0;
717 if (Config
.connect_retries
> 10) {
718 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
719 Config
.connect_retries
= 10;
722 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
725 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
727 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
728 if (Config
.Program
.redirect
)
729 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
731 if (Config
.Program
.store_id
)
732 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
734 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
736 if (Config
.errorDirectory
)
737 requirePathnameExists("Error Directory", Config
.errorDirectory
);
739 #if USE_HTTP_VIOLATIONS
742 const RefreshPattern
*R
;
744 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
745 if (!R
->flags
.override_expire
)
748 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
753 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
754 if (!R
->flags
.override_lastmod
)
757 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
762 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
763 if (!R
->flags
.reload_into_ims
)
766 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
771 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
772 if (!R
->flags
.ignore_reload
)
775 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
780 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
781 if (!R
->flags
.ignore_no_store
)
784 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
789 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
790 if (!R
->flags
.ignore_private
)
793 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
799 #if !USE_HTTP_VIOLATIONS
800 Config
.onoff
.via
= 1;
803 if (!Config
.onoff
.via
)
804 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
808 // we enable runtime PURGE checks if there is at least one PURGE method ACL
809 // TODO: replace with a dedicated "purge" ACL option?
810 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
812 if (geteuid() == 0) {
813 if (NULL
!= Config
.effectiveUser
) {
815 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
819 * Andres Kroonmaa <andre@online.ee>:
820 * Some getpwnam() implementations (Solaris?) require
821 * an available FD < 256 for opening a FILE* to the
824 * This should be safe at startup, but might still fail
825 * during reconfigure.
827 fatalf("getpwnam failed to find userid for effective user '%s'",
828 Config
.effectiveUser
);
832 Config2
.effectiveUserID
= pwd
->pw_uid
;
834 Config2
.effectiveGroupID
= pwd
->pw_gid
;
837 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
838 // putenv() leaks by design; avoid leaks when nothing changes
840 if (lastDir
.isEmpty() || lastDir
.cmp(pwd
->pw_dir
) != 0) {
841 lastDir
= pwd
->pw_dir
;
842 int len
= strlen(pwd
->pw_dir
) + 6;
843 char *env_str
= (char *)xcalloc(len
, 1);
844 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
851 Config2
.effectiveUserID
= geteuid();
852 Config2
.effectiveGroupID
= getegid();
855 if (NULL
!= Config
.effectiveGroup
) {
857 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
860 fatalf("getgrnam failed to find groupid for effective group '%s'",
861 Config
.effectiveGroup
);
865 Config2
.effectiveGroupID
= grp
->gr_gid
;
869 if (Config
.ssl_client
.foreignIntermediateCertsPath
)
870 Ssl::loadSquidUntrusted(Config
.ssl_client
.foreignIntermediateCertsPath
);
873 if (Security::ProxyOutgoingConfig
.encryptTransport
) {
874 debugs(3, DBG_IMPORTANT
, "Initializing https:// proxy context");
875 Config
.ssl_client
.sslContext
= Security::ProxyOutgoingConfig
.createClientContext(false);
876 if (!Config
.ssl_client
.sslContext
) {
878 fatal("ERROR: Could not initialize https:// proxy context");
880 debugs(3, DBG_IMPORTANT
, "ERROR: proxying https:// currently still requires --with-openssl");
884 Ssl::useSquidUntrusted(Config
.ssl_client
.sslContext
.get());
888 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
890 // default value for ssldomain= is the peer host/IP
891 if (p
->secure
.sslDomain
.isEmpty())
892 p
->secure
.sslDomain
= p
->host
;
894 if (p
->secure
.encryptTransport
) {
895 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " TLS context");
896 p
->sslContext
= p
->secure
.createClientContext(true);
897 if (!p
->sslContext
) {
898 debugs(3, DBG_CRITICAL
, "ERROR: Could not initialize cache_peer " << p
->name
<< " TLS context");
906 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
907 if (!s
->secure
.encryptTransport
)
909 debugs(3, DBG_IMPORTANT
, "Initializing " << AnyP::UriScheme(s
->transport
.protocol
) << "_port " << s
->s
<< " TLS context");
910 s
->configureSslServerContext();
914 // prevent infinite fetch loops in the request parser
915 // due to buffer full but not enough data recived to finish parse
916 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
917 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
918 " Change client_request_buffer_max or request_header_max_size limits.",
919 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
923 * Disable client side request pipelining if client_persistent_connections OFF.
924 * Waste of resources queueing any pipelined requests when the first will close the connection.
926 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
927 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
928 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
929 Config
.pipeline_max_prefetch
= 0;
934 * disable client side request pipelining. There is a race with
935 * Negotiate and NTLM when the client sends a second request on an
936 * connection before the authenticate challenge is sent. With
937 * pipelining OFF, the client may fail to authenticate, but squid's
938 * state will be preserved.
940 if (Config
.pipeline_max_prefetch
> 0) {
941 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
942 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
943 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
944 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
945 Config
.pipeline_max_prefetch
= 0;
949 for (auto &authSchemes
: Config
.authSchemesConfigs
) {
950 authSchemes
.expand();
951 if (authSchemes
.authConfigs
.empty()) {
952 debugs(3, DBG_CRITICAL
, "auth_schemes: at least one scheme name is required; got: " << authSchemes
.rawSchemes
);
959 /** Parse a line containing an obsolete directive.
960 * To upgrade it where possible instead of just "Bungled config" for
961 * directives which cannot be marked as simply aliases of the some name.
962 * For example if the parameter order and content has changed.
963 * Or if the directive has been completely removed.
966 parse_obsolete(const char *name
)
968 // Directives which have been radically changed rather than removed
969 if (!strcmp(name
, "url_rewrite_concurrency")) {
972 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
973 Config
.redirectChildren
.concurrency
= cval
;
976 if (!strcmp(name
, "log_access")) {
981 if (!strcmp(name
, "log_icap")) {
986 if (!strcmp(name
, "ignore_ims_on_miss")) {
987 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
988 // than the 2.7 directive. We need to parse and invert the configured value.
991 Config
.onoff
.cache_miss_revalidate
= !temp
;
994 if (!strncmp(name
, "sslproxy_", 9)) {
995 // the replacement directive tls_outgoing_options uses options instead of whole-line input
997 if (!strcmp(name
, "sslproxy_cafile"))
998 tmp
.append("cafile=");
999 else if (!strcmp(name
, "sslproxy_capath"))
1000 tmp
.append("capath=");
1001 else if (!strcmp(name
, "sslproxy_cipher"))
1002 tmp
.append("cipher=");
1003 else if (!strcmp(name
, "sslproxy_client_certificate"))
1004 tmp
.append("cert=");
1005 else if (!strcmp(name
, "sslproxy_client_key"))
1007 else if (!strcmp(name
, "sslproxy_flags"))
1008 tmp
.append("flags=");
1009 else if (!strcmp(name
, "sslproxy_options"))
1010 tmp
.append("options=");
1011 else if (!strcmp(name
, "sslproxy_version"))
1012 tmp
.append("version=");
1014 debugs(3, DBG_CRITICAL
, "ERROR: unknown directive: " << name
);
1019 // add the value as unquoted-string because the old values did not support whitespace
1020 const char *token
= ConfigParser::NextQuotedOrToEol();
1021 tmp
.append(token
, strlen(token
));
1022 Security::ProxyOutgoingConfig
.parse(tmp
.c_str());
1026 /* Parse a time specification from the config file. Store the
1027 * result in 'tptr', after converting it to 'units' */
1029 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
, bool expectMoreArguments
= false)
1031 time_msec_t u
= parseTimeUnits(units
, allowMsec
);
1037 char *token
= ConfigParser::NextToken();;
1043 double d
= xatof(token
);
1045 time_msec_t m
= u
; /* default to 'units' if none specified */
1048 if ((token
= ConfigParser::PeekAtToken()) && (m
= parseTimeUnits(token
, allowMsec
))) {
1049 (void)ConfigParser::NextToken();
1051 } else if (!expectMoreArguments
) {
1056 token
= NULL
; // show default units if dying below
1057 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" << config_input_line
<< "', assuming " << d
<< " " << units
);
1060 token
= NULL
; // show default units if dying below.
1062 *tptr
= static_cast<time_msec_t
>(m
* d
);
1064 if (static_cast<double>(*tptr
) * 2 != m
* d
* 2) {
1065 debugs(3, DBG_CRITICAL
, "FATAL: Invalid value '" <<
1066 d
<< " " << (token
? token
: units
) << ": integer overflow (time_msec_t).");
1072 parseTimeUnits(const char *unit
, bool allowMsec
)
1074 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1077 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1080 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1083 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1086 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1087 return 86400 * 1000;
1089 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1090 return 86400 * 7 * 1000;
1092 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1093 return 86400 * 14 * 1000;
1095 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1096 return static_cast<uint64_t>(86400) * 30 * 1000;
1098 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1099 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1101 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1102 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1104 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1110 parseBytesLine64(int64_t * bptr
, const char *units
)
1117 if ((u
= parseBytesUnits(units
)) == 0) {
1122 if ((token
= ConfigParser::NextToken()) == NULL
) {
1127 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1134 m
= u
; /* default to 'units' if none specified */
1138 else if ((token
= ConfigParser::NextToken()) == NULL
)
1139 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1140 config_input_line
<< "', assuming " <<
1141 d
<< " " << units
);
1142 else if ((m
= parseBytesUnits(token
)) == 0) {
1147 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1149 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1150 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1151 d
<< " " << token
<< ": integer overflow (int64_t).");
1157 parseBytesLine(size_t * bptr
, const char *units
)
1164 if ((u
= parseBytesUnits(units
)) == 0) {
1169 if ((token
= ConfigParser::NextToken()) == NULL
) {
1174 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1175 *bptr
= static_cast<size_t>(-1);
1181 m
= u
; /* default to 'units' if none specified */
1185 else if ((token
= ConfigParser::NextToken()) == NULL
)
1186 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1187 config_input_line
<< "', assuming " <<
1188 d
<< " " << units
);
1189 else if ((m
= parseBytesUnits(token
)) == 0) {
1194 *bptr
= static_cast<size_t>(m
* d
/ u
);
1196 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1197 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1198 d
<< " " << token
<< ": integer overflow (size_t).");
1204 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1211 if ((u
= parseBytesUnits(units
)) == 0) {
1216 if ((token
= ConfigParser::NextToken()) == NULL
) {
1221 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1228 m
= u
; /* default to 'units' if none specified */
1232 else if ((token
= ConfigParser::NextToken()) == NULL
)
1233 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1234 config_input_line
<< "', assuming " <<
1235 d
<< " " << units
);
1236 else if ((m
= parseBytesUnits(token
)) == 0) {
1241 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1243 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1244 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1245 d
<< " " << token
<< ": integer overflow (ssize_t).");
1251 * Parse bytes from a string.
1252 * Similar to the parseBytesLine function but parses the string value instead of
1253 * the current token value.
1255 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1258 if ((u
= parseBytesUnits(units
)) == 0) {
1263 // Find number from string beginning.
1264 char const * number_begin
= value
;
1265 char const * number_end
= value
;
1267 while ((*number_end
>= '0' && *number_end
<= '9')) {
1272 number
.limitInit(number_begin
, number_end
- number_begin
);
1274 int d
= xatoi(number
.termedBuf());
1276 if ((m
= parseBytesUnits(number_end
)) == 0) {
1281 *bptr
= static_cast<size_t>(m
* d
/ u
);
1282 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1287 parseBytesUnits(const char *unit
)
1289 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1292 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1295 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1298 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1301 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1307 dump_SBufList(StoreEntry
* entry
, const SBufList
&words
)
1309 for (SBufList::const_iterator i
= words
.begin(); i
!= words
.end(); ++i
) {
1310 entry
->append(i
->rawContent(), i
->length());
1311 entry
->append(" ",1);
1313 entry
->append("\n",1);
1317 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1319 while (ae
!= NULL
) {
1320 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1321 storeAppendPrintf(entry
, "%s %s %s %s ",
1325 ae
->flags
.flagsStr());
1326 dump_SBufList(entry
, ae
->dump());
1332 parse_acl(ACL
** ae
)
1334 ACL::ParseAclLine(LegacyParser
, ae
);
1344 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1346 dump_SBufList(entry
, head
->dump());
1350 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1353 dump_SBufList(entry
, head
->treeDump(name
, &Acl::AllowOrDeny
));
1357 parse_acl_access(acl_access
** head
)
1359 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1363 free_acl_access(acl_access
** head
)
1365 aclDestroyAccessList(head
);
1369 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1371 char buf
[MAX_IPSTRLEN
];
1372 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1376 parse_address(Ip::Address
*addr
)
1378 char *token
= ConfigParser::NextToken();
1385 if (!strcmp(token
,"any_addr"))
1387 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1389 else if ( (*addr
= token
) ) // try parse numeric/IPA
1391 else if (addr
->GetHostByName(token
)) // dont use ipcache
1393 else { // not an IP and not a hostname
1394 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
1400 free_address(Ip::Address
*addr
)
1406 dump_acl_address(StoreEntry
* entry
, const char *name
, Acl::Address
* head
)
1408 char buf
[MAX_IPSTRLEN
];
1410 for (Acl::Address
*l
= head
; l
; l
= l
->next
) {
1411 if (!l
->addr
.isAnyAddr())
1412 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.toStr(buf
,MAX_IPSTRLEN
));
1414 storeAppendPrintf(entry
, "%s autoselect", name
);
1416 dump_acl_list(entry
, l
->aclList
);
1418 storeAppendPrintf(entry
, "\n");
1423 parse_acl_address(Acl::Address
** head
)
1425 Acl::Address
*l
= new Acl::Address
;
1426 parse_address(&l
->addr
);
1427 aclParseAclList(LegacyParser
, &l
->aclList
, l
->addr
);
1429 Acl::Address
**tail
= head
;
1431 tail
= &(*tail
)->next
;
1437 free_acl_address(Acl::Address
** head
)
1444 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1448 for (l
= head
; l
; l
= l
->next
) {
1450 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1452 storeAppendPrintf(entry
, "%s none", name
);
1454 dump_acl_list(entry
, l
->aclList
);
1456 storeAppendPrintf(entry
, "\n");
1461 parse_acl_tos(acl_tos
** head
)
1463 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1464 char *token
= ConfigParser::NextToken();
1471 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1476 const unsigned int chTos
= tos
& 0xFC;
1478 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: Tos value '" << tos
<< "' adjusted to '" << chTos
<< "'");
1482 acl_tos
*l
= new acl_tos
;
1484 l
->tos
= (tos_t
)tos
;
1486 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1488 acl_tos
**tail
= head
; /* sane name below */
1490 tail
= &(*tail
)->next
;
1496 free_acl_tos(acl_tos
** head
)
1502 #if SO_MARK && USE_LIBCAP
1505 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1507 for (acl_nfmark
*l
= head
; l
; l
= l
->next
) {
1509 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1511 storeAppendPrintf(entry
, "%s none", name
);
1513 dump_acl_list(entry
, l
->aclList
);
1515 storeAppendPrintf(entry
, "\n");
1520 parse_acl_nfmark(acl_nfmark
** head
)
1523 char *token
= ConfigParser::NextToken();
1530 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1535 acl_nfmark
*l
= new acl_nfmark
;
1539 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1541 acl_nfmark
**tail
= head
; /* sane name below */
1543 tail
= &(*tail
)->next
;
1549 free_acl_nfmark(acl_nfmark
** head
)
1554 #endif /* SO_MARK */
1557 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1559 for (AclSizeLimit
*l
= head
; l
; l
= l
->next
) {
1561 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1563 storeAppendPrintf(entry
, "%s none", name
);
1565 dump_acl_list(entry
, l
->aclList
);
1567 storeAppendPrintf(entry
, "\n");
1572 parse_acl_b_size_t(AclSizeLimit
** head
)
1574 AclSizeLimit
*l
= new AclSizeLimit
;
1576 parse_b_int64_t(&l
->size
);
1578 aclParseAclList(LegacyParser
, &l
->aclList
, l
->size
);
1580 AclSizeLimit
**tail
= head
; /* sane name below */
1582 tail
= &(*tail
)->next
;
1588 free_acl_b_size_t(AclSizeLimit
** head
)
1596 #include "DelayConfig.h"
1597 #include "DelayPools.h"
1598 /* do nothing - free_delay_pool_count is the magic free function.
1599 * this is why delay_pool_count isn't just marked TYPE: u_short
1601 #define free_delay_pool_class(X)
1602 #define free_delay_pool_access(X)
1603 #define free_delay_pool_rates(X)
1604 #define dump_delay_pool_class(X, Y, Z)
1605 #define dump_delay_pool_access(X, Y, Z)
1606 #define dump_delay_pool_rates(X, Y, Z)
1609 free_delay_pool_count(DelayConfig
* cfg
)
1611 cfg
->freePoolCount();
1615 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1617 cfg
.dumpPoolCount (entry
, name
);
1621 parse_delay_pool_count(DelayConfig
* cfg
)
1623 cfg
->parsePoolCount();
1627 parse_delay_pool_class(DelayConfig
* cfg
)
1629 cfg
->parsePoolClass();
1633 parse_delay_pool_rates(DelayConfig
* cfg
)
1635 cfg
->parsePoolRates();
1639 parse_delay_pool_access(DelayConfig
* cfg
)
1641 cfg
->parsePoolAccess(LegacyParser
);
1647 #include "ClientDelayConfig.h"
1648 /* do nothing - free_client_delay_pool_count is the magic free function.
1649 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1652 #define free_client_delay_pool_access(X)
1653 #define free_client_delay_pool_rates(X)
1654 #define dump_client_delay_pool_access(X, Y, Z)
1655 #define dump_client_delay_pool_rates(X, Y, Z)
1658 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1660 cfg
->freePoolCount();
1664 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1666 cfg
.dumpPoolCount (entry
, name
);
1670 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1672 cfg
->parsePoolCount();
1676 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1678 cfg
->parsePoolRates();
1682 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1684 cfg
->parsePoolAccess(LegacyParser
);
1688 #if USE_HTTP_VIOLATIONS
1690 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1693 manglers
->dumpAccess(entry
, name
);
1697 parse_http_header_access(HeaderManglers
**pm
)
1701 if ((t
= ConfigParser::NextToken()) == NULL
) {
1702 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1703 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1708 *pm
= new HeaderManglers
;
1709 HeaderManglers
*manglers
= *pm
;
1710 headerMangler
*mangler
= manglers
->track(t
);
1713 std::string directive
= "http_header_access ";
1715 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1719 free_HeaderManglers(HeaderManglers
**pm
)
1721 // we delete the entire http_header_* mangler configuration at once
1722 if (const HeaderManglers
*manglers
= *pm
) {
1729 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1732 manglers
->dumpReplacement(entry
, name
);
1736 parse_http_header_replace(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_replace: missing header name.");
1746 const char *value
= ConfigParser::NextQuotedOrToEol();
1749 *pm
= new HeaderManglers
;
1750 HeaderManglers
*manglers
= *pm
;
1751 manglers
->setReplacement(t
, value
);
1757 dump_cachedir(StoreEntry
* entry
, const char *name
, const Store::DiskConfig
&swap
)
1763 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1764 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1766 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1768 storeAppendPrintf(entry
, "\n");
1773 check_null_string(char *s
)
1780 parse_authparam(Auth::ConfigVector
* config
)
1782 char *type_str
= ConfigParser::NextToken();
1788 char *param_str
= ConfigParser::NextToken();
1794 /* find a configuration for the scheme in the currently parsed configs... */
1795 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1797 if (schemeCfg
== NULL
) {
1798 /* Create a configuration based on the scheme info */
1799 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1801 if (theScheme
== NULL
) {
1802 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1807 config
->push_back(theScheme
->createConfig());
1808 schemeCfg
= Auth::Config::Find(type_str
);
1809 if (schemeCfg
== NULL
) {
1810 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1816 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1820 free_authparam(Auth::ConfigVector
* cfg
)
1822 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1825 /* on reconfigure initialize new auth schemes for the new config. */
1826 if (reconfiguring
) {
1832 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1834 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1835 (*i
)->dump(entry
, name
, (*i
));
1839 parse_AuthSchemes(acl_access
**authSchemes
)
1841 const char *tok
= ConfigParser::NextQuotedToken();
1843 debugs(29, DBG_CRITICAL
, "FATAL: auth_schemes missing the parameter");
1847 Config
.authSchemesConfigs
.push_back(Auth::SchemesConfig(tok
, ConfigParser::LastTokenWasQuoted
));
1848 const allow_t action
= allow_t(ACCESS_ALLOWED
, Config
.authSchemesConfigs
.size() - 1);
1849 ParseAclWithAction(authSchemes
, action
, "auth_schemes");
1853 free_AuthSchemes(acl_access
**authSchemes
)
1855 Config
.authSchemesConfigs
.clear();
1856 free_acl_access(authSchemes
);
1860 dump_AuthSchemes(StoreEntry
*entry
, const char *name
, acl_access
*authSchemes
)
1863 dump_SBufList(entry
, authSchemes
->treeDump(name
, [](const allow_t
&action
) {
1864 return Config
.authSchemesConfigs
.at(action
.kind
).rawSchemes
;
1868 #endif /* USE_AUTH */
1871 ParseAclWithAction(acl_access
**access
, const allow_t
&action
, const char *desc
, ACL
*acl
)
1876 *access
= new Acl::Tree
;
1877 name
.Printf("(%s rules)", desc
);
1878 (*access
)->context(name
.c_str(), config_input_line
);
1880 Acl::AndNode
*rule
= new Acl::AndNode
;
1881 name
.Printf("(%s rule)", desc
);
1882 rule
->context(name
.c_str(), config_input_line
);
1883 acl
? rule
->add(acl
) : rule
->lineParse();
1884 (*access
)->add(rule
, action
);
1887 /* TODO: just return the object, the # is irrelevant */
1889 find_fstype(char *type
)
1891 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1892 if (strcasecmp(type
, StoreFileSystem::FileSystems().at(i
)->type()) == 0)
1899 parse_cachedir(Store::DiskConfig
*swap
)
1901 char *type_str
= ConfigParser::NextToken();
1907 char *path_str
= ConfigParser::NextToken();
1913 int fs
= find_fstype(type_str
);
1915 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: This proxy does not support the '" << type_str
<< "' cache type. Ignoring.");
1919 /* reconfigure existing dir */
1921 RefCount
<SwapDir
> sd
;
1922 for (int i
= 0; i
< swap
->n_configured
; ++i
) {
1923 assert (swap
->swapDirs
[i
].getRaw());
1925 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1926 /* this is specific to on-fs Stores. The right
1927 * way to handle this is probably to have a mapping
1928 * from paths to stores, and have on-fs stores
1929 * register with that, and lookip in that in their
1930 * own setup logic. RBC 20041225. TODO.
1933 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1935 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().at(fs
)->type()) != 0) {
1936 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1937 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1947 if (swap
->n_configured
> 63) {
1948 /* 7 bits, signed */
1949 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1950 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1955 allocate_new_swapdir(swap
);
1957 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().at(fs
)->createSwapDir();
1959 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1961 /* parse the FS parameters and options */
1962 sd
->parse(swap
->n_configured
, path_str
);
1964 ++swap
->n_configured
;
1968 peer_type_str(const peer_t type
)
1970 const char * result
;
1982 case PEER_MULTICAST
:
1983 result
= "multicast";
1995 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
1997 NeighborTypeDomainList
*t
;
1998 LOCAL_ARRAY(char, xname
, 128);
2001 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2008 dump_peer_options(entry
, p
);
2011 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2012 dump_acl_access(entry
, xname
, p
->access
);
2015 for (t
= p
->typelist
; t
; t
= t
->next
) {
2016 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2018 peer_type_str(t
->type
),
2027 * utility function to prevent getservbyname() being called with a numeric value
2028 * on Windows at least it returns garage results.
2031 isUnsignedNumeric(const char *str
, size_t len
)
2033 if (len
< 1) return false;
2035 for (; len
>0 && *str
; ++str
, --len
) {
2036 if (! isdigit(*str
))
2043 \param proto 'tcp' or 'udp' for protocol
2044 \returns Port the named service is supposed to be listening on.
2046 static unsigned short
2047 GetService(const char *proto
)
2049 struct servent
*port
= NULL
;
2050 /** Parses a port number or service name from the squid.conf */
2051 char *token
= ConfigParser::NextToken();
2052 if (token
== NULL
) {
2054 return 0; /* NEVER REACHED */
2056 /** Returns either the service port number from /etc/services */
2057 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2058 port
= getservbyname(token
, proto
);
2060 return ntohs((unsigned short)port
->s_port
);
2062 /** Or a numeric translation of the config text. */
2063 return xatos(token
);
2067 \returns Port the named TCP service is supposed to be listening on.
2068 \copydoc GetService(const char *proto)
2070 inline unsigned short
2073 return GetService("tcp");
2077 \returns Port the named UDP service is supposed to be listening on.
2078 \copydoc GetService(const char *proto)
2080 inline unsigned short
2083 return GetService("udp");
2087 parse_peer(CachePeer
** head
)
2089 char *host_str
= ConfigParser::NextToken();
2095 char *token
= ConfigParser::NextToken();
2101 CachePeer
*p
= new CachePeer
;
2102 p
->host
= xstrdup(host_str
);
2103 p
->name
= xstrdup(host_str
);
2104 p
->type
= parseNeighborType(token
);
2106 if (p
->type
== PEER_MULTICAST
) {
2107 p
->options
.no_digest
= true;
2108 p
->options
.no_netdb_exchange
= true;
2111 p
->http_port
= GetTcpService();
2113 if (!p
->http_port
) {
2119 p
->icp
.port
= GetUdpService();
2121 while ((token
= ConfigParser::NextToken())) {
2122 if (!strcmp(token
, "proxy-only")) {
2123 p
->options
.proxy_only
= true;
2124 } else if (!strcmp(token
, "no-query")) {
2125 p
->options
.no_query
= true;
2126 } else if (!strcmp(token
, "background-ping")) {
2127 p
->options
.background_ping
= true;
2128 } else if (!strcmp(token
, "no-digest")) {
2129 p
->options
.no_digest
= true;
2130 } else if (!strcmp(token
, "no-tproxy")) {
2131 p
->options
.no_tproxy
= true;
2132 } else if (!strcmp(token
, "multicast-responder")) {
2133 p
->options
.mcast_responder
= true;
2134 #if PEER_MULTICAST_SIBLINGS
2135 } else if (!strcmp(token
, "multicast-siblings")) {
2136 p
->options
.mcast_siblings
= true;
2138 } else if (!strncmp(token
, "weight=", 7)) {
2139 p
->weight
= xatoi(token
+ 7);
2140 } else if (!strncmp(token
, "basetime=", 9)) {
2141 p
->basetime
= xatoi(token
+ 9);
2142 } else if (!strcmp(token
, "closest-only")) {
2143 p
->options
.closest_only
= true;
2144 } else if (!strncmp(token
, "ttl=", 4)) {
2145 p
->mcast
.ttl
= xatoi(token
+ 4);
2147 if (p
->mcast
.ttl
< 0)
2150 if (p
->mcast
.ttl
> 128)
2152 } else if (!strcmp(token
, "default")) {
2153 p
->options
.default_parent
= true;
2154 } else if (!strcmp(token
, "round-robin")) {
2155 p
->options
.roundrobin
= true;
2156 } else if (!strcmp(token
, "weighted-round-robin")) {
2157 p
->options
.weighted_roundrobin
= true;
2159 } else if (!strcmp(token
, "htcp")) {
2160 p
->options
.htcp
= true;
2161 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2162 /* Note: The htcp- form is deprecated, replaced by htcp= */
2163 p
->options
.htcp
= true;
2164 char *tmp
= xstrdup(token
+5);
2165 char *mode
, *nextmode
;
2166 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2167 nextmode
= strchr(mode
, ',');
2172 if (!strcmp(mode
, "no-clr")) {
2173 if (p
->options
.htcp_only_clr
)
2174 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2175 p
->options
.htcp_no_clr
= true;
2176 } else if (!strcmp(mode
, "no-purge-clr")) {
2177 p
->options
.htcp_no_purge_clr
= true;
2178 } else if (!strcmp(mode
, "only-clr")) {
2179 if (p
->options
.htcp_no_clr
)
2180 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2181 p
->options
.htcp_only_clr
= true;
2182 } else if (!strcmp(mode
, "forward-clr")) {
2183 p
->options
.htcp_forward_clr
= true;
2184 } else if (!strcmp(mode
, "oldsquid")) {
2185 p
->options
.htcp_oldsquid
= true;
2187 fatalf("invalid HTCP mode '%s'", mode
);
2192 } else if (!strcmp(token
, "no-netdb-exchange")) {
2193 p
->options
.no_netdb_exchange
= true;
2195 } else if (!strcmp(token
, "carp")) {
2196 if (p
->type
!= PEER_PARENT
)
2197 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2199 p
->options
.carp
= true;
2200 } else if (!strncmp(token
, "carp-key=", 9)) {
2201 if (p
->options
.carp
!= true)
2202 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2203 p
->options
.carp_key
.set
= true;
2204 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2205 for (; key
; key
= nextkey
) {
2206 nextkey
=strchr(key
,',');
2207 if (nextkey
) ++nextkey
; // skip the comma, any
2208 if (0==strncmp(key
,"scheme",6)) {
2209 p
->options
.carp_key
.scheme
= true;
2210 } else if (0==strncmp(key
,"host",4)) {
2211 p
->options
.carp_key
.host
= true;
2212 } else if (0==strncmp(key
,"port",4)) {
2213 p
->options
.carp_key
.port
= true;
2214 } else if (0==strncmp(key
,"path",4)) {
2215 p
->options
.carp_key
.path
= true;
2216 } else if (0==strncmp(key
,"params",6)) {
2217 p
->options
.carp_key
.params
= true;
2219 fatalf("invalid carp-key '%s'",key
);
2222 } else if (!strcmp(token
, "userhash")) {
2224 if (p
->type
!= PEER_PARENT
)
2225 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2227 p
->options
.userhash
= true;
2229 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2231 } else if (!strcmp(token
, "sourcehash")) {
2232 if (p
->type
!= PEER_PARENT
)
2233 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2235 p
->options
.sourcehash
= true;
2237 } else if (!strcmp(token
, "no-delay")) {
2239 p
->options
.no_delay
= true;
2241 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2243 } else if (!strncmp(token
, "login=", 6)) {
2244 p
->login
= xstrdup(token
+ 6);
2245 rfc1738_unescape(p
->login
);
2246 } else if (!strcmp(token
, "auth-no-keytab")) {
2247 p
->options
.auth_no_keytab
= 1;
2248 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2249 p
->connect_timeout
= xatoi(token
+ 16);
2250 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2251 p
->connect_fail_limit
= xatoi(token
+ 19);
2252 #if USE_CACHE_DIGESTS
2253 } else if (!strncmp(token
, "digest-url=", 11)) {
2254 p
->digest_url
= xstrdup(token
+ 11);
2257 } else if (!strcmp(token
, "allow-miss")) {
2258 p
->options
.allow_miss
= true;
2259 } else if (!strncmp(token
, "max-conn=", 9)) {
2260 p
->max_conn
= xatoi(token
+ 9);
2261 } else if (!strncmp(token
, "standby=", 8)) {
2262 p
->standby
.limit
= xatoi(token
+ 8);
2263 } else if (!strcmp(token
, "originserver")) {
2264 p
->options
.originserver
= true;
2265 } else if (!strncmp(token
, "name=", 5)) {
2269 p
->name
= xstrdup(token
+ 5);
2270 } else if (!strncmp(token
, "forceddomain=", 13)) {
2271 safe_free(p
->domain
);
2273 p
->domain
= xstrdup(token
+ 13);
2275 } else if (strncmp(token
, "ssl", 3) == 0) {
2277 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option '" << token
<< "' requires --with-openssl");
2279 p
->secure
.parse(token
+3);
2281 } else if (strncmp(token
, "tls-", 4) == 0) {
2282 p
->secure
.parse(token
+4);
2283 } else if (strncmp(token
, "tls", 3) == 0) {
2284 p
->secure
.parse(token
+3);
2285 } else if (strcmp(token
, "front-end-https") == 0) {
2286 p
->front_end_https
= 1;
2287 } else if (strcmp(token
, "front-end-https=on") == 0) {
2288 p
->front_end_https
= 1;
2289 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2290 p
->front_end_https
= 2;
2291 } else if (strcmp(token
, "connection-auth=off") == 0) {
2292 p
->connection_auth
= 0;
2293 } else if (strcmp(token
, "connection-auth") == 0) {
2294 p
->connection_auth
= 1;
2295 } else if (strcmp(token
, "connection-auth=on") == 0) {
2296 p
->connection_auth
= 1;
2297 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2298 p
->connection_auth
= 2;
2299 } else if (token
[0] == '#') {
2300 // start of a text comment. stop reading this line.
2303 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2307 if (peerFindByName(p
->name
))
2308 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2310 if (p
->max_conn
> 0 && p
->max_conn
< p
->standby
.limit
)
2311 fatalf("ERROR: cache_peer %s max-conn=%d is lower than its standby=%d\n", p
->host
, p
->max_conn
, p
->standby
.limit
);
2316 if (p
->connect_fail_limit
< 1)
2317 p
->connect_fail_limit
= 10;
2319 #if USE_CACHE_DIGESTS
2321 if (!p
->options
.no_digest
) {
2322 /* XXX This looks odd.. who has the original pointer
2325 PeerDigest
*pd
= peerDigestCreate(p
);
2326 p
->digest
= cbdataReference(pd
);
2331 p
->index
= ++Config
.npeers
;
2333 while (*head
!= NULL
)
2334 head
= &(*head
)->next
;
2342 free_peer(CachePeer
** P
)
2350 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2353 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2354 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2356 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2358 for (auto w
: list
->actions
)
2359 entry
->appendf(" " SQUIDSBUFPH
, SQUIDSBUFPRINT(w
));
2361 storeAppendPrintf(entry
, "\n");
2367 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2369 char *passwd
= nullptr;
2370 parse_string(&passwd
);
2372 Mgr::ActionPasswordList
*p
= new Mgr::ActionPasswordList
;
2375 while (char *token
= ConfigParser::NextQuotedToken())
2376 p
->actions
.push_back(SBuf(token
));
2378 Mgr::ActionPasswordList
**P
;
2379 for (P
= head
; *P
; P
= &(*P
)->next
) {
2381 * See if any of the actions from this line already have a
2382 * password from previous lines. The password checking
2383 * routines in cache_manager.c take the the password from
2384 * the first Mgr::ActionPasswordList that contains the
2385 * requested action. Thus, we should warn users who might
2386 * think they can have two passwords for the same action.
2388 for (const auto &w
: (*P
)->actions
) {
2389 for (const auto &u
: p
->actions
) {
2393 debugs(0, DBG_PARSE_NOTE(1), "ERROR: action '" << u
<< "' (line " << config_lineno
<< ") already has a password");
2402 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2409 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2411 while (var
!= NULL
) {
2412 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2414 for (auto *a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2415 storeAppendPrintf(entry
, " %s", a
->name
);
2417 storeAppendPrintf(entry
, "\n");
2424 parse_denyinfo(AclDenyInfoList
** var
)
2426 aclParseDenyInfoLine(var
);
2430 free_denyinfo(AclDenyInfoList
** list
)
2437 parse_peer_access(void)
2439 char *host
= ConfigParser::NextToken();
2445 CachePeer
*p
= peerFindByName(host
);
2447 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2451 std::string directive
= "peer_access ";
2453 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
->access
);
2457 parse_hostdomaintype(void)
2459 char *host
= ConfigParser::NextToken();
2465 char *type
= ConfigParser::NextToken();
2471 char *domain
= nullptr;
2472 while ((domain
= ConfigParser::NextToken())) {
2473 CachePeer
*p
= peerFindByName(host
);
2475 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2479 auto *l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2480 l
->type
= parseNeighborType(type
);
2481 l
->domain
= xstrdup(domain
);
2483 NeighborTypeDomainList
**L
= nullptr;
2484 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2490 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2492 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2510 dump_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2512 storeAppendPrintf(entry
, "%s %" PRId64
"\n", name
, var
);
2516 parse_int64_t(int64_t *var
)
2524 free_int64_t(int64_t *var
)
2530 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2532 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2536 parse_onoff(int *var
)
2538 char *token
= ConfigParser::NextToken();
2544 if (!strcmp(token
, "on")) {
2546 } else if (!strcmp(token
, "enable")) {
2547 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2549 } else if (!strcmp(token
, "off")) {
2551 } else if (!strcmp(token
, "disable")) {
2552 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2555 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2560 #define free_onoff free_int
2563 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2574 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2578 parse_tristate(int *var
)
2580 char *token
= ConfigParser::NextToken();
2586 if (!strcmp(token
, "on")) {
2588 } else if (!strcmp(token
, "enable")) {
2589 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2591 } else if (!strcmp(token
, "warn")) {
2593 } else if (!strcmp(token
, "off")) {
2595 } else if (!strcmp(token
, "disable")) {
2596 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2599 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2604 #define free_tristate free_int
2607 parse_pipelinePrefetch(int *var
)
2609 char *token
= ConfigParser::PeekAtToken();
2615 if (!strcmp(token
, "on")) {
2616 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2619 (void)ConfigParser::NextToken();
2620 } else if (!strcmp(token
, "off")) {
2621 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2624 (void)ConfigParser::NextToken();
2629 #define free_pipelinePrefetch free_int
2630 #define dump_pipelinePrefetch dump_int
2633 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2635 while (head
!= NULL
) {
2636 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2638 head
->pattern
.flags
®_ICASE
? " -i" : null_string
,
2639 head
->pattern
.c_str(),
2640 (int) head
->min
/ 60,
2641 (int) (100.0 * head
->pct
+ 0.5),
2642 (int) head
->max
/ 60);
2644 if (head
->max_stale
>= 0)
2645 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2647 if (head
->flags
.refresh_ims
)
2648 storeAppendPrintf(entry
, " refresh-ims");
2650 if (head
->flags
.store_stale
)
2651 storeAppendPrintf(entry
, " store-stale");
2653 #if USE_HTTP_VIOLATIONS
2655 if (head
->flags
.override_expire
)
2656 storeAppendPrintf(entry
, " override-expire");
2658 if (head
->flags
.override_lastmod
)
2659 storeAppendPrintf(entry
, " override-lastmod");
2661 if (head
->flags
.reload_into_ims
)
2662 storeAppendPrintf(entry
, " reload-into-ims");
2664 if (head
->flags
.ignore_reload
)
2665 storeAppendPrintf(entry
, " ignore-reload");
2667 if (head
->flags
.ignore_no_store
)
2668 storeAppendPrintf(entry
, " ignore-no-store");
2670 if (head
->flags
.ignore_private
)
2671 storeAppendPrintf(entry
, " ignore-private");
2674 storeAppendPrintf(entry
, "\n");
2681 parse_refreshpattern(RefreshPattern
** head
)
2688 int refresh_ims
= 0;
2689 int store_stale
= 0;
2692 #if USE_HTTP_VIOLATIONS
2694 int override_expire
= 0;
2695 int override_lastmod
= 0;
2696 int reload_into_ims
= 0;
2697 int ignore_reload
= 0;
2698 int ignore_no_store
= 0;
2699 int ignore_private
= 0;
2706 int flags
= REG_EXTENDED
| REG_NOSUB
;
2708 if ((token
= ConfigParser::RegexPattern()) != NULL
) {
2710 if (strcmp(token
, "-i") == 0) {
2712 token
= ConfigParser::RegexPattern();
2713 } else if (strcmp(token
, "+i") == 0) {
2714 flags
&= ~REG_ICASE
;
2715 token
= ConfigParser::RegexPattern();
2720 if (token
== NULL
) {
2721 debugs(3, DBG_CRITICAL
, "FATAL: refresh_pattern missing the regex pattern parameter");
2726 pattern
= xstrdup(token
);
2728 i
= GetInteger(); /* token: min */
2730 /* catch negative and insanely huge values close to 32-bit wrap */
2732 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2735 if (i
> 60*24*365) {
2736 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2740 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2742 pct
= GetPercentage(false); /* token: pct . with no limit on size */
2744 i
= GetInteger(); /* token: max */
2746 /* catch negative and insanely huge values close to 32-bit wrap */
2748 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2751 if (i
> 60*24*365) {
2752 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2756 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2759 while ((token
= ConfigParser::NextToken()) != NULL
) {
2760 if (!strcmp(token
, "refresh-ims")) {
2762 } else if (!strcmp(token
, "store-stale")) {
2764 } else if (!strncmp(token
, "max-stale=", 10)) {
2765 max_stale
= xatoi(token
+ 10);
2767 #if USE_HTTP_VIOLATIONS
2769 } else if (!strcmp(token
, "override-expire"))
2770 override_expire
= 1;
2771 else if (!strcmp(token
, "override-lastmod"))
2772 override_lastmod
= 1;
2773 else if (!strcmp(token
, "ignore-no-store"))
2774 ignore_no_store
= 1;
2775 else if (!strcmp(token
, "ignore-private"))
2777 else if (!strcmp(token
, "reload-into-ims")) {
2778 reload_into_ims
= 1;
2779 refresh_nocache_hack
= 1;
2780 /* tell client_side.c that this is used */
2781 } else if (!strcmp(token
, "ignore-reload")) {
2783 refresh_nocache_hack
= 1;
2784 /* tell client_side.c that this is used */
2787 } else if (!strcmp(token
, "ignore-no-cache") ||
2788 !strcmp(token
, "ignore-must-revalidate") ||
2789 !strcmp(token
, "ignore-auth")
2791 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option '" << token
<< "' is obsolete. Remove it.");
2793 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2796 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2798 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2799 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2800 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2805 pct
= pct
< 0.0 ? 0.0 : pct
;
2806 max
= max
< 0 ? 0 : max
;
2807 t
= new RefreshPattern(pattern
, flags
);
2808 t
->pattern
.regex
= comp
;
2814 t
->flags
.refresh_ims
= true;
2817 t
->flags
.store_stale
= true;
2819 t
->max_stale
= max_stale
;
2821 #if USE_HTTP_VIOLATIONS
2823 if (override_expire
)
2824 t
->flags
.override_expire
= true;
2826 if (override_lastmod
)
2827 t
->flags
.override_lastmod
= true;
2829 if (reload_into_ims
)
2830 t
->flags
.reload_into_ims
= true;
2833 t
->flags
.ignore_reload
= true;
2835 if (ignore_no_store
)
2836 t
->flags
.ignore_no_store
= true;
2839 t
->flags
.ignore_private
= true;
2845 head
= &(*head
)->next
;
2853 free_refreshpattern(RefreshPattern
** head
)
2858 #if USE_HTTP_VIOLATIONS
2859 refresh_nocache_hack
= 0;
2865 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2868 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2872 parse_string(char **var
)
2876 char *token
= ConfigParser::NextToken();
2882 *var
= xstrdup(token
);
2886 free_string(char **var
)
2892 parse_eol(char *volatile *var
)
2899 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
2907 while (*token
&& xisspace(*token
))
2915 *var
= xstrdup((char *) token
);
2918 #define dump_eol dump_string
2919 #define free_eol free_string
2922 parse_TokenOrQuotedString(char **var
)
2926 char *token
= ConfigParser::NextQuotedToken();
2932 *var
= xstrdup(token
);
2935 #define dump_TokenOrQuotedString dump_string
2936 #define free_TokenOrQuotedString free_string
2939 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2941 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2945 parse_time_t(time_t * var
)
2948 parseTimeLine(&tval
, T_SECOND_STR
, false);
2949 *var
= static_cast<time_t>(tval
/1000);
2953 free_time_t(time_t * var
)
2959 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
2962 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
2964 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
2968 parse_time_msec(time_msec_t
* var
)
2970 parseTimeLine(var
, T_SECOND_STR
, true);
2974 free_time_msec(time_msec_t
* var
)
2981 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2983 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2988 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2990 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2994 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
2996 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3001 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3003 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3008 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3010 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3014 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3016 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3021 parse_size_t(size_t * var
)
3030 parse_b_size_t(size_t * var
)
3032 parseBytesLine(var
, B_BYTES_STR
);
3036 parse_b_ssize_t(ssize_t
* var
)
3038 parseBytesLineSigned(var
, B_BYTES_STR
);
3043 parse_kb_size_t(size_t * var
)
3045 parseBytesLine(var
, B_KBYTES_STR
);
3050 parse_b_int64_t(int64_t * var
)
3052 parseBytesLine64(var
, B_BYTES_STR
);
3056 parse_kb_int64_t(int64_t * var
)
3058 parseBytesLine64(var
, B_KBYTES_STR
);
3062 free_size_t(size_t * var
)
3068 free_ssize_t(ssize_t
* var
)
3074 free_b_int64_t(int64_t * var
)
3079 #define free_b_size_t free_size_t
3080 #define free_b_ssize_t free_ssize_t
3081 #define free_kb_size_t free_size_t
3082 #define free_mb_size_t free_size_t
3083 #define free_gb_size_t free_size_t
3084 #define free_kb_int64_t free_b_int64_t
3087 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3089 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3093 free_u_short(unsigned short * u
)
3099 parse_u_short(unsigned short * var
)
3101 ConfigParser::ParseUShort(var
);
3105 ConfigParser::ParseUShort(unsigned short *var
)
3111 ConfigParser::ParseBool(bool *var
)
3113 int i
= GetInteger();
3124 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3126 while (list
!= NULL
) {
3127 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3133 ConfigParser::ParseWordList(wordlist
** list
)
3135 parse_wordlist(list
);
3139 parse_wordlist(wordlist
** list
)
3142 while ((token
= ConfigParser::NextQuotedToken()))
3143 wordlistAdd(list
, token
);
3146 #if 0 /* now unused */
3148 check_null_wordlist(wordlist
* w
)
3155 check_null_acl_access(acl_access
* a
)
3160 #define free_wordlist wordlistDestroy
3162 #define free_uri_whitespace free_int
3165 parse_uri_whitespace(int *var
)
3167 char *token
= ConfigParser::NextToken();
3173 if (!strcmp(token
, "strip"))
3174 *var
= URI_WHITESPACE_STRIP
;
3175 else if (!strcmp(token
, "deny"))
3176 *var
= URI_WHITESPACE_DENY
;
3177 else if (!strcmp(token
, "allow"))
3178 *var
= URI_WHITESPACE_ALLOW
;
3179 else if (!strcmp(token
, "encode"))
3180 *var
= URI_WHITESPACE_ENCODE
;
3181 else if (!strcmp(token
, "chop"))
3182 *var
= URI_WHITESPACE_CHOP
;
3184 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3190 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3194 if (var
== URI_WHITESPACE_ALLOW
)
3196 else if (var
== URI_WHITESPACE_ENCODE
)
3198 else if (var
== URI_WHITESPACE_CHOP
)
3200 else if (var
== URI_WHITESPACE_DENY
)
3205 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3209 free_removalpolicy(RemovalPolicySettings
** settings
)
3214 free_string(&(*settings
)->type
);
3216 free_wordlist(&(*settings
)->args
);
3224 parse_removalpolicy(RemovalPolicySettings
** settings
)
3227 free_removalpolicy(settings
);
3229 *settings
= new RemovalPolicySettings
;
3231 parse_string(&(*settings
)->type
);
3233 parse_wordlist(&(*settings
)->args
);
3237 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3240 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3241 args
= settings
->args
;
3244 storeAppendPrintf(entry
, " %s", args
->key
);
3248 storeAppendPrintf(entry
, "\n");
3252 free_YesNoNone(YesNoNone
*)
3256 parse_YesNoNone(YesNoNone
*option
)
3259 parse_onoff(&value
);
3260 option
->configure(value
> 0);
3264 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3266 if (option
.configured())
3267 dump_onoff(entry
, name
, option
? 1 : 0);
3271 free_memcachemode(SquidConfig
*)
3275 parse_memcachemode(SquidConfig
*)
3277 char *token
= ConfigParser::NextToken();
3283 if (strcmp(token
, "always") == 0) {
3284 Config
.onoff
.memory_cache_first
= 1;
3285 Config
.onoff
.memory_cache_disk
= 1;
3286 } else if (strcmp(token
, "disk") == 0) {
3287 Config
.onoff
.memory_cache_first
= 0;
3288 Config
.onoff
.memory_cache_disk
= 1;
3289 } else if (strncmp(token
, "net", 3) == 0) {
3290 Config
.onoff
.memory_cache_first
= 1;
3291 Config
.onoff
.memory_cache_disk
= 0;
3292 } else if (strcmp(token
, "never") == 0) {
3293 Config
.onoff
.memory_cache_first
= 0;
3294 Config
.onoff
.memory_cache_disk
= 0;
3296 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3302 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&)
3304 storeAppendPrintf(entry
, "%s ", name
);
3305 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3306 storeAppendPrintf(entry
, "always");
3307 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3308 storeAppendPrintf(entry
, "disk");
3309 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3310 storeAppendPrintf(entry
, "network");
3311 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3312 storeAppendPrintf(entry
, "none");
3313 storeAppendPrintf(entry
, "\n");
3316 #include "cf_parser.cci"
3319 parseNeighborType(const char *s
)
3321 if (!strcmp(s
, "parent"))
3324 if (!strcmp(s
, "neighbor"))
3325 return PEER_SIBLING
;
3327 if (!strcmp(s
, "neighbour"))
3328 return PEER_SIBLING
;
3330 if (!strcmp(s
, "sibling"))
3331 return PEER_SIBLING
;
3333 if (!strcmp(s
, "multicast"))
3334 return PEER_MULTICAST
;
3336 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3338 return PEER_SIBLING
;
3343 parse_IpAddress_list(Ip::Address_list
** head
)
3346 Ip::Address_list
*s
;
3349 while ((token
= ConfigParser::NextToken())) {
3350 if (GetHostWithPort(token
, &ipa
)) {
3353 head
= &(*head
)->next
;
3355 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3367 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3369 char ntoabuf
[MAX_IPSTRLEN
];
3372 storeAppendPrintf(e
, "%s %s\n",
3374 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3380 free_IpAddress_list(Ip::Address_list
** head
)
3382 if (*head
) delete *head
;
3386 #if CURRENTLY_UNUSED
3387 /* This code was previously used by http_port. Left as it really should
3388 * be used by icp_port and htcp_port
3391 check_null_IpAddress_list(const Ip::Address_list
* s
)
3396 #endif /* CURRENTLY_UNUSED */
3397 #endif /* USE_WCCPv2 */
3400 parsePortSpecification(const AnyP::PortCfgPointer
&s
, char *token
)
3403 unsigned short port
= 0;
3407 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3408 s
->name
= xstrdup(token
);
3409 s
->connection_auth_disabled
= false;
3411 const SBuf
&portType
= AnyP::UriScheme(s
->transport
.protocol
).image();
3413 if (*token
== '[') {
3416 t
= strchr(host
, ']');
3418 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3425 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3429 if (!Ip::EnableIpv6
) {
3430 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3434 port
= xatos(t
+ 1);
3435 } else if ((t
= strchr(token
, ':'))) {
3440 port
= xatos(t
+ 1);
3442 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3443 port
= xatos(token
);
3444 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3446 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3451 if (port
== 0 && host
!= NULL
) {
3452 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3460 if (!Ip::EnableIpv6
)
3462 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3463 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3465 if (!Ip::EnableIpv6
)
3467 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3468 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3469 /* dont use ipcache */
3470 s
->defaultsite
= xstrdup(host
);
3472 if (!Ip::EnableIpv6
)
3474 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3476 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3481 /// parses the protocol= option of the *_port directive, returning parsed value
3482 /// unsupported option values result in a fatal error message
3483 /// upper case values required; caller may convert for backward compatibility
3484 static AnyP::ProtocolVersion
3485 parsePortProtocol(const SBuf
&value
)
3487 // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
3488 // and RFC 2616 requires us to upgrade 1.0 to 1.1
3489 if (value
.cmp("HTTP") == 0 || value
.cmp("HTTP/1.1") == 0)
3490 return AnyP::ProtocolVersion(AnyP::PROTO_HTTP
, 1,1);
3492 if (value
.cmp("HTTPS") == 0 || value
.cmp("HTTPS/1.1") == 0)
3493 return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS
, 1,1);
3495 if (value
.cmp("FTP") == 0)
3496 return Ftp::ProtocolVersion();
3498 fatalf("%s directive does not support protocol=" SQUIDSBUFPH
"\n", cfg_directive
, SQUIDSBUFPRINT(value
));
3499 return AnyP::ProtocolVersion(); // not reached
3503 parse_port_option(AnyP::PortCfgPointer
&s
, char *token
)
3507 if (strcmp(token
, "accel") == 0) {
3508 if (s
->flags
.isIntercepted()) {
3509 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Accelerator mode requires its own port. It cannot be shared with other modes.");
3513 s
->flags
.accelSurrogate
= true;
3515 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3516 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3517 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": Intercept mode requires its own interception port. It cannot be shared with other modes.");
3521 s
->flags
.natIntercept
= true;
3522 Ip::Interceptor
.StartInterception();
3523 /* Log information regarding the port modes under interception. */
3524 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3525 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3526 } else if (strcmp(token
, "tproxy") == 0) {
3527 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3528 debugs(3,DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY option requires its own interception port. It cannot be shared with other modes.");
3532 s
->flags
.tproxyIntercept
= true;
3533 Ip::Interceptor
.StartTransparency();
3534 /* Log information regarding the port modes under transparency. */
3535 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3537 if (s
->flags
.proxySurrogate
) {
3538 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3541 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3542 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": TPROXY support in the system does not work.");
3547 } else if (strcmp(token
, "require-proxy-header") == 0) {
3548 s
->flags
.proxySurrogate
= true;
3549 if (s
->flags
.tproxyIntercept
) {
3550 // receiving is still permitted, so we do not unset the TPROXY flag
3551 // spoofing access control override takes care of the spoof disable later
3552 debugs(3, DBG_IMPORTANT
, "Disabling TPROXY Spoofing on port " << s
->s
<< " (require-proxy-header enabled)");
3555 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3556 if (!s
->flags
.accelSurrogate
) {
3557 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": defaultsite option requires Acceleration mode flag.");
3561 safe_free(s
->defaultsite
);
3562 s
->defaultsite
= xstrdup(token
+ 12);
3563 } else if (strcmp(token
, "vhost") == 0) {
3564 if (!s
->flags
.accelSurrogate
) {
3565 debugs(3, DBG_CRITICAL
, "WARNING: " << cfg_directive
<< ": vhost option is deprecated. Use 'accel' mode flag instead.");
3567 s
->flags
.accelSurrogate
= true;
3569 } else if (strcmp(token
, "no-vhost") == 0) {
3570 if (!s
->flags
.accelSurrogate
) {
3571 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": no-vhost option requires Acceleration mode flag.");
3574 } else if (strcmp(token
, "vport") == 0) {
3575 if (!s
->flags
.accelSurrogate
) {
3576 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3581 } else if (strncmp(token
, "vport=", 6) == 0) {
3582 if (!s
->flags
.accelSurrogate
) {
3583 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": vport option requires Acceleration mode flag.");
3587 s
->vport
= xatos(token
+ 6);
3588 } else if (strncmp(token
, "protocol=", 9) == 0) {
3589 if (!s
->flags
.accelSurrogate
) {
3590 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": protocol option requires Acceleration mode flag.");
3594 s
->transport
= parsePortProtocol(ToUpper(SBuf(token
+ 9)));
3595 } else if (strcmp(token
, "allow-direct") == 0) {
3596 if (!s
->flags
.accelSurrogate
) {
3597 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": allow-direct option requires Acceleration mode flag.");
3601 s
->allow_direct
= true;
3602 } else if (strcmp(token
, "act-as-origin") == 0) {
3603 if (!s
->flags
.accelSurrogate
) {
3604 debugs(3, DBG_IMPORTANT
, "ERROR: " << cfg_directive
<< ": act-as-origin option requires Acceleration mode flag.");
3606 s
->actAsOrigin
= true;
3607 } else if (strcmp(token
, "ignore-cc") == 0) {
3608 #if !USE_HTTP_VIOLATIONS
3609 if (!s
->flags
.accelSurrogate
) {
3610 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": ignore-cc option requires Acceleration mode flag.");
3615 s
->ignore_cc
= true;
3616 } else if (strncmp(token
, "name=", 5) == 0) {
3618 s
->name
= xstrdup(token
+ 5);
3619 } else if (strcmp(token
, "no-connection-auth") == 0) {
3620 s
->connection_auth_disabled
= true;
3621 } else if (strcmp(token
, "connection-auth=off") == 0) {
3622 s
->connection_auth_disabled
= true;
3623 } else if (strcmp(token
, "connection-auth") == 0) {
3624 s
->connection_auth_disabled
= false;
3625 } else if (strcmp(token
, "connection-auth=on") == 0) {
3626 s
->connection_auth_disabled
= false;
3627 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3628 if (!strcmp(token
+ 23, "off"))
3629 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3630 else if (!strcmp(token
+ 23, "transparent"))
3631 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3632 else if (!strcmp(token
+ 23, "always"))
3633 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3638 } else if (strcmp(token
, "ipv4") == 0) {
3639 if ( !s
->s
.setIPv4() ) {
3640 debugs(3, DBG_CRITICAL
, "FATAL: " << cfg_directive
<< ": IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3644 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3645 s
->tcp_keepalive
.enabled
= true;
3646 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3647 char *t
= token
+ 13;
3648 s
->tcp_keepalive
.enabled
= true;
3649 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3653 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3658 s
->tcp_keepalive
.timeout
= xatoui(t
);
3661 } else if (strcmp(token
, "sslBump") == 0) {
3662 debugs(3, DBG_PARSE_NOTE(1), "WARNING: '" << token
<< "' is deprecated " <<
3663 "in " << cfg_directive
<< ". Use 'ssl-bump' instead.");
3664 s
->flags
.tunnelSslBumping
= true;
3665 } else if (strcmp(token
, "ssl-bump") == 0) {
3666 s
->flags
.tunnelSslBumping
= true;
3667 } else if (strncmp(token
, "cert=", 5) == 0) {
3668 s
->secure
.parse(token
);
3669 } else if (strncmp(token
, "key=", 4) == 0) {
3670 s
->secure
.parse(token
);
3671 } else if (strncmp(token
, "version=", 8) == 0) {
3672 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3673 "in " << cfg_directive
<< ". Use 'options=' instead.");
3674 s
->secure
.parse(token
);
3675 } else if (strncmp(token
, "options=", 8) == 0) {
3676 s
->secure
.parse(token
);
3677 } else if (strncmp(token
, "cipher=", 7) == 0) {
3678 s
->secure
.parse(token
);
3679 } else if (strncmp(token
, "clientca=", 9) == 0) {
3680 safe_free(s
->clientca
);
3681 s
->clientca
= xstrdup(token
+ 9);
3682 } else if (strncmp(token
, "cafile=", 7) == 0) {
3683 debugs(3, DBG_PARSE_NOTE(1), "UPGRADE WARNING: '" << token
<< "' is deprecated " <<
3684 "in " << cfg_directive
<< ". Use 'tls-cafile=' instead.");
3685 s
->secure
.parse(token
);
3686 } else if (strncmp(token
, "capath=", 7) == 0) {
3687 s
->secure
.parse(token
);
3688 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3689 s
->secure
.parse(token
);
3690 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3691 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: '" << token
<< "' is deprecated " <<
3692 "in " << cfg_directive
<< ". Use 'tls-dh=' instead.");
3693 s
->secure
.parse(token
);
3694 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3695 // NP: deprecation warnings output by secure.parse() when relevant
3696 s
->secure
.parse(token
+3);
3697 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3698 safe_free(s
->sslContextSessionId
);
3699 s
->sslContextSessionId
= xstrdup(token
+ 11);
3700 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3701 s
->generateHostCertificates
= true;
3702 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3703 s
->generateHostCertificates
= true;
3704 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3705 s
->generateHostCertificates
= false;
3706 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3707 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3709 } else if (strncmp(token
, "tls-", 4) == 0) {
3710 s
->secure
.parse(token
+4);
3711 } else if (strcmp(token
, "ftp-track-dirs") == 0) {
3712 s
->ftp_track_dirs
= true;
3714 debugs(3, DBG_CRITICAL
, "FATAL: Unknown " << cfg_directive
<< " option '" << token
<< "'.");
3720 add_http_port(char *portspec
)
3722 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3723 s
->transport
= parsePortProtocol(SBuf("HTTP"));
3724 parsePortSpecification(s
, portspec
);
3725 // we may need to merge better if the above returns a list with clones
3726 assert(s
->next
== NULL
);
3727 s
->next
= HttpPortList
;
3732 parsePortCfg(AnyP::PortCfgPointer
*head
, const char *optionName
)
3735 if (strcmp(optionName
, "http_port") == 0 ||
3736 strcmp(optionName
, "ascii_port") == 0)
3738 else if (strcmp(optionName
, "https_port") == 0)
3739 protoName
= "HTTPS";
3740 else if (strcmp(optionName
, "ftp_port") == 0)
3742 if (protoName
.isEmpty()) {
3747 char *token
= ConfigParser::NextToken();
3754 AnyP::PortCfgPointer s
= new AnyP::PortCfg();
3755 s
->transport
= parsePortProtocol(protoName
); // default; protocol=... overwrites
3756 parsePortSpecification(s
, token
);
3758 /* parse options ... */
3759 while ((token
= ConfigParser::NextToken())) {
3760 parse_port_option(s
, token
);
3764 // if clientca has been defined but not cafile, then use it to verify
3765 // but if cafile has been defined, only use that to verify
3766 if (s
->clientca
&& !s
->secure
.caFiles
.size())
3767 s
->secure
.caFiles
.emplace_back(SBuf(s
->clientca
));
3770 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3771 s
->secure
.encryptTransport
= true;
3773 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3774 const bool hijacked
= s
->flags
.isIntercepted();
3775 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3776 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3780 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3781 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3786 if (s
->flags
.proxySurrogate
) {
3787 debugs(3,DBG_CRITICAL
, "FATAL: https_port: require-proxy-header option is not supported on HTTPS ports.");
3791 } else if (protoName
.cmp("FTP") == 0) {
3792 /* ftp_port does not support ssl-bump */
3793 if (s
->flags
.tunnelSslBumping
) {
3794 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump is not supported for ftp_port.");
3798 if (s
->flags
.proxySurrogate
) {
3799 // Passive FTP data channel does not work without deep protocol inspection in the frontend.
3800 debugs(3,DBG_CRITICAL
, "FATAL: require-proxy-header option is not supported on ftp_port.");
3806 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3807 // clone the port options from *s to *(s->next)
3808 s
->next
= s
->clone();
3809 s
->next
->s
.setIPv4();
3810 debugs(3, 3, AnyP::UriScheme(s
->transport
.protocol
).image() << "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3813 while (*head
!= NULL
)
3814 head
= &((*head
)->next
);
3820 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3822 char buf
[MAX_IPSTRLEN
];
3824 storeAppendPrintf(e
, "%s %s",
3826 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3828 // MODES and specific sub-options.
3829 if (s
->flags
.natIntercept
)
3830 storeAppendPrintf(e
, " intercept");
3832 else if (s
->flags
.tproxyIntercept
)
3833 storeAppendPrintf(e
, " tproxy");
3835 else if (s
->flags
.proxySurrogate
)
3836 storeAppendPrintf(e
, " require-proxy-header");
3838 else if (s
->flags
.accelSurrogate
) {
3839 storeAppendPrintf(e
, " accel");
3842 storeAppendPrintf(e
, " vhost");
3845 storeAppendPrintf(e
, " vport");
3846 else if (s
->vport
> 0)
3847 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3850 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3852 // TODO: compare against prefix of 'n' instead of assuming http_port
3853 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3854 storeAppendPrintf(e
, " protocol=%s", AnyP::ProtocolType_str
[s
->transport
.protocol
]);
3856 if (s
->allow_direct
)
3857 storeAppendPrintf(e
, " allow-direct");
3860 storeAppendPrintf(e
, " ignore-cc");
3864 // Generic independent options
3867 storeAppendPrintf(e
, " name=%s", s
->name
);
3869 #if USE_HTTP_VIOLATIONS
3870 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3871 storeAppendPrintf(e
, " ignore-cc");
3874 if (s
->connection_auth_disabled
)
3875 storeAppendPrintf(e
, " connection-auth=off");
3877 storeAppendPrintf(e
, " connection-auth=on");
3879 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3882 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3885 pmtu
= "transparent";
3887 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3890 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3891 storeAppendPrintf(e
, " ipv4");
3893 if (s
->tcp_keepalive
.enabled
) {
3894 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3895 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3897 storeAppendPrintf(e
, " tcpkeepalive");
3902 if (s
->flags
.tunnelSslBumping
)
3903 storeAppendPrintf(e
, " ssl-bump");
3906 s
->secure
.dumpCfg(e
, "tls-");
3909 if (s
->sslContextSessionId
)
3910 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3912 if (!s
->generateHostCertificates
)
3913 storeAppendPrintf(e
, " generate-host-certificates=off");
3915 if (s
->dynamicCertMemCacheSize
!= 4*1024*1024) // 4MB default
3916 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%" PRIuSIZE
"%s\n", s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3921 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfgPointer
&s
)
3923 for (AnyP::PortCfgPointer p
= s
; p
!= NULL
; p
= p
->next
) {
3924 dump_generic_port(e
, n
, p
);
3925 storeAppendPrintf(e
, "\n");
3930 configFreeMemory(void)
3933 Config
.ssl_client
.sslContext
.reset();
3935 Ssl::unloadSquidUntrusted();
3940 requirePathnameExists(const char *name
, const char *path
)
3944 char pathbuf
[BUFSIZ
];
3945 assert(path
!= NULL
);
3947 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3948 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3952 if (stat(path
, &sb
) < 0) {
3954 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL: ":"ERROR: ") << name
<< " " << path
<< ": " << xstrerr(xerrno
));
3955 // keep going to find more issues if we are only checking the config file with "-k parse"
3956 if (opt_parse_cfg_only
)
3958 // this is fatal if it is found during startup or reconfigure
3959 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3960 fatalf("%s %s: %s", name
, path
, xstrerr(xerrno
));
3964 #include "AccessLogEntry.h"
3967 * We support several access_log configuration styles:
3969 * #1: Deprecated ancient style without an explicit logging module:
3970 * access_log /var/log/access.log
3972 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
3973 * access_log none [acl ...]
3975 * #3: Configurable logging module without named options:
3976 * Logformat or the first ACL name, whichever comes first, may not contain '='.
3977 * If no explicit logformat name is given, the first ACL name, if any,
3978 * should not be an existing logformat name or it will be treated as such.
3979 * access_log module:place [logformat_name] [acl ...]
3981 * #4: Configurable logging module with name=value options such as logformat=x:
3982 * The first ACL name may not contain '='.
3983 * access_log module:place [option ...] [acl ...]
3987 parse_access_log(CustomLog
** logs
)
3989 const char *filename
= ConfigParser::NextToken();
3995 CustomLog
*cl
= (CustomLog
*)xcalloc(1, sizeof(*cl
));
3997 cl
->filename
= xstrdup(filename
);
3998 // default buffer size and fatal settings
3999 cl
->bufferSize
= 8*MAX_URL
;
4002 if (strcmp(filename
, "none") == 0) {
4003 cl
->type
= Log::Format::CLF_NONE
;
4004 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
4006 logs
= &(*logs
)->next
;
4011 cl
->type
= Log::Format::CLF_UNKNOWN
;
4012 cl
->rotateCount
= -1; // default: use global logfile_rotate setting.
4014 const char *token
= ConfigParser::PeekAtToken();
4015 if (!token
) { // style #1
4016 // no options to deal with
4017 } else if (!strchr(token
, '=')) { // style #3
4018 // if logformat name is recognized,
4019 // pop the previewed token; Else it must be an ACL name
4020 if (setLogformat(cl
, token
, false))
4021 (void)ConfigParser::NextToken();
4022 } else { // style #4
4024 if (strncasecmp(token
, "on-error=", 9) == 0) {
4025 if (strncasecmp(token
+9, "die", 3) == 0) {
4027 } else if (strncasecmp(token
+9, "drop", 4) == 0) {
4030 debugs(3, DBG_CRITICAL
, "Unknown value for on-error '" <<
4031 token
<< "' expected 'drop' or 'die'");
4032 xfree(cl
->filename
);
4037 } else if (strncasecmp(token
, "buffer-size=", 12) == 0) {
4038 parseBytesOptionValue(&cl
->bufferSize
, B_BYTES_STR
, token
+12);
4039 } else if (strncasecmp(token
, "rotate=", 7) == 0) {
4040 cl
->rotateCount
= xatoi(token
+ 7);
4041 } else if (strncasecmp(token
, "logformat=", 10) == 0) {
4042 setLogformat(cl
, token
+10, true);
4043 } else if (!strchr(token
, '=')) {
4044 // Do not pop the token; it must be an ACL name
4045 break; // done with name=value options, now to ACLs
4047 debugs(3, DBG_CRITICAL
, "Unknown access_log option " << token
);
4048 xfree(cl
->filename
);
4053 // Pop the token, it was a valid "name=value" option
4054 (void)ConfigParser::NextToken();
4055 // Get next with preview ConfigParser::NextToken call.
4056 } while ((token
= ConfigParser::PeekAtToken()) != NULL
);
4059 // set format if it has not been specified explicitly
4060 if (cl
->type
== Log::Format::CLF_UNKNOWN
)
4061 setLogformat(cl
, "squid", true);
4063 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4066 logs
= &(*logs
)->next
;
4071 /// sets CustomLog::type and, if needed, CustomLog::lf
4072 /// returns false iff there is no named log format
4074 setLogformat(CustomLog
*cl
, const char *logdef_name
, const bool dieWhenMissing
)
4077 assert(logdef_name
);
4079 debugs(3, 9, "possible " << cl
->filename
<< " logformat: " << logdef_name
);
4081 if (cl
->type
!= Log::Format::CLF_UNKNOWN
) {
4082 debugs(3, DBG_CRITICAL
, "Second logformat name in one access_log: " <<
4083 logdef_name
<< " " << cl
->type
<< " ? " << Log::Format::CLF_NONE
);
4088 /* look for the definition pointer corresponding to this name */
4089 Format::Format
*lf
= Log::TheConfig
.logformats
;
4091 while (lf
!= NULL
) {
4092 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4094 if (strcmp(lf
->name
, logdef_name
) == 0)
4101 cl
->type
= Log::Format::CLF_CUSTOM
;
4103 } else if (strcmp(logdef_name
, "auto") == 0) {
4104 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4105 cl
->type
= Log::Format::CLF_SQUID
;
4106 } else if (strcmp(logdef_name
, "squid") == 0) {
4107 cl
->type
= Log::Format::CLF_SQUID
;
4108 } else if (strcmp(logdef_name
, "common") == 0) {
4109 cl
->type
= Log::Format::CLF_COMMON
;
4110 } else if (strcmp(logdef_name
, "combined") == 0) {
4111 cl
->type
= Log::Format::CLF_COMBINED
;
4113 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4114 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4116 } else if (strcmp(logdef_name
, "useragent") == 0) {
4117 cl
->type
= Log::Format::CLF_USERAGENT
;
4118 } else if (strcmp(logdef_name
, "referrer") == 0) {
4119 cl
->type
= Log::Format::CLF_REFERER
;
4120 } else if (dieWhenMissing
) {
4121 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4132 check_null_access_log(CustomLog
*customlog_definitions
)
4134 return customlog_definitions
== NULL
;
4138 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4142 for (log
= logs
; log
; log
= log
->next
) {
4143 storeAppendPrintf(entry
, "%s ", name
);
4145 switch (log
->type
) {
4147 case Log::Format::CLF_CUSTOM
:
4148 storeAppendPrintf(entry
, "%s logformat=%s", log
->filename
, log
->logFormat
->name
);
4151 case Log::Format::CLF_NONE
:
4152 storeAppendPrintf(entry
, "logformat=none");
4155 case Log::Format::CLF_SQUID
:
4156 storeAppendPrintf(entry
, "%s logformat=squid", log
->filename
);
4159 case Log::Format::CLF_COMBINED
:
4160 storeAppendPrintf(entry
, "%s logformat=combined", log
->filename
);
4163 case Log::Format::CLF_COMMON
:
4164 storeAppendPrintf(entry
, "%s logformat=common", log
->filename
);
4168 case Log::Format::CLF_ICAP_SQUID
:
4169 storeAppendPrintf(entry
, "%s logformat=icap_squid", log
->filename
);
4172 case Log::Format::CLF_USERAGENT
:
4173 storeAppendPrintf(entry
, "%s logformat=useragent", log
->filename
);
4176 case Log::Format::CLF_REFERER
:
4177 storeAppendPrintf(entry
, "%s logformat=referrer", log
->filename
);
4180 case Log::Format::CLF_UNKNOWN
:
4184 // default is on-error=die
4186 storeAppendPrintf(entry
, " on-error=drop");
4189 if (log
->bufferSize
!= 64*1024)
4190 storeAppendPrintf(entry
, " buffer-size=%" PRIuSIZE
, log
->bufferSize
);
4192 if (log
->rotateCount
>= 0)
4193 storeAppendPrintf(entry
, " rotate=%d", log
->rotateCount
);
4196 dump_acl_list(entry
, log
->aclList
);
4198 storeAppendPrintf(entry
, "\n");
4203 free_access_log(CustomLog
** definitions
)
4205 while (*definitions
) {
4206 CustomLog
*log
= *definitions
;
4207 *definitions
= log
->next
;
4209 log
->logFormat
= NULL
;
4210 log
->type
= Log::Format::CLF_UNKNOWN
;
4213 aclDestroyAclList(&log
->aclList
);
4215 safe_free(log
->filename
);
4221 #if HAVE_CPU_AFFINITY /* until somebody else needs this general code */
4222 /// parses list of integers form name=N1,N2,N3,...
4224 parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
)
4226 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4227 data
+= name
.size();
4232 if (!StringToInt(data
, value
, &data
, 10))
4234 list
.push_back(value
);
4235 if (*data
== '\0' || *data
!= ',')
4240 return data
&& *data
== '\0';
4245 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4247 #if !HAVE_CPU_AFFINITY
4248 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4249 "support, do not set 'cpu_affinity_map'");
4252 #else /* HAVE_CPU_AFFINITY */
4253 if (!*cpuAffinityMap
)
4254 *cpuAffinityMap
= new CpuAffinityMap
;
4256 const char *const pToken
= ConfigParser::NextToken();
4257 const char *const cToken
= ConfigParser::NextToken();
4258 std::vector
<int> processes
, cores
;
4259 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4260 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4261 "in 'cpu_affinity_map'");
4263 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4264 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4265 "'cpu_affinity_map'");
4267 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4268 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4269 "process_numbers and cores lists differ in length or " <<
4270 "contain numbers <= 0");
4277 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4279 if (cpuAffinityMap
) {
4280 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4281 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4282 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4283 cpuAffinityMap
->processes()[i
]);
4285 storeAppendPrintf(entry
, " cores=");
4286 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4287 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4288 cpuAffinityMap
->cores()[i
]);
4290 storeAppendPrintf(entry
, "\n");
4295 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4297 delete *cpuAffinityMap
;
4298 *cpuAffinityMap
= NULL
;
4304 parse_adaptation_service_set_type()
4306 Adaptation::Config::ParseServiceSet();
4310 parse_adaptation_service_chain_type()
4312 Adaptation::Config::ParseServiceChain();
4316 parse_adaptation_access_type()
4318 Adaptation::Config::ParseAccess(LegacyParser
);
4320 #endif /* USE_ADAPTATION */
4325 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4327 cfg
->parseService();
4331 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4337 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4339 cfg
.dumpService(entry
, name
);
4343 parse_icap_class_type()
4345 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4346 "Use 'adaptation_service_set' instead");
4347 Adaptation::Config::ParseServiceSet();
4351 parse_icap_access_type()
4353 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4354 "Use 'adaptation_access' instead");
4355 Adaptation::Config::ParseAccess(LegacyParser
);
4363 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4365 cfg
->parseService();
4369 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4375 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4377 cfg
.dumpService(entry
, name
);
4380 #endif /* USE_ECAP */
4383 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4388 cfg
->service_failure_limit
= GetInteger();
4390 if ((token
= ConfigParser::NextToken()) == NULL
)
4393 if (strcmp(token
,"in") != 0) {
4394 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4399 if ((token
= ConfigParser::NextToken()) == NULL
) {
4404 d
= static_cast<time_t> (xatoi(token
));
4406 m
= static_cast<time_t> (1);
4410 else if ((token
= ConfigParser::NextToken()) == NULL
) {
4411 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4414 } else if ((m
= parseTimeUnits(token
, false)) == 0) {
4419 cfg
->oldest_service_failure
= (m
* d
);
4422 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4424 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4425 if (cfg
.oldest_service_failure
> 0) {
4426 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4428 storeAppendPrintf(entry
, "\n");
4431 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4433 cfg
->oldest_service_failure
= 0;
4434 cfg
->service_failure_limit
= 0;
4439 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4442 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4443 if ((al
= ConfigParser::NextToken()) == NULL
) {
4450 if ( char *s
= strchr(al
, '{')) {
4451 *s
= '\0'; // terminate the al string
4464 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4465 ca
->alg
= Ssl::algSetValidAfter
;
4466 ca
->param
= xstrdup("on");
4467 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4468 ca
->alg
= Ssl::algSetValidBefore
;
4469 ca
->param
= xstrdup("on");
4470 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4471 ca
->alg
= Ssl::algSetCommonName
;
4473 if (strlen(param
) > 64) {
4474 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4479 ca
->param
= xstrdup(param
);
4482 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4488 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4491 cert_adapt
= &(*cert_adapt
)->next
;
4496 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4498 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4499 storeAppendPrintf(entry
, "%s ", name
);
4500 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4502 dump_acl_list(entry
, ca
->aclList
);
4503 storeAppendPrintf(entry
, "\n");
4507 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4509 while (*cert_adapt
) {
4510 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4511 *cert_adapt
= ca
->next
;
4512 safe_free(ca
->param
);
4515 aclDestroyAclList(&ca
->aclList
);
4521 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4524 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4525 if ((al
= ConfigParser::NextToken()) == NULL
) {
4531 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4532 cs
->alg
= Ssl::algSignTrusted
;
4533 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4534 cs
->alg
= Ssl::algSignUntrusted
;
4535 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4536 cs
->alg
= Ssl::algSignSelf
;
4538 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4544 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4547 cert_sign
= &(*cert_sign
)->next
;
4552 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4554 sslproxy_cert_sign
*cs
;
4555 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4556 storeAppendPrintf(entry
, "%s ", name
);
4557 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4559 dump_acl_list(entry
, cs
->aclList
);
4560 storeAppendPrintf(entry
, "\n");
4564 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4566 while (*cert_sign
) {
4567 sslproxy_cert_sign
*cs
= *cert_sign
;
4568 *cert_sign
= cs
->next
;
4571 aclDestroyAclList(&cs
->aclList
);
4577 class sslBumpCfgRr
: public ::RegisteredRunner
4580 static Ssl::BumpMode lastDeprecatedRule
;
4581 /* RegisteredRunner API */
4582 virtual void finalizeConfig();
4585 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4587 RunnerRegistrationEntry(sslBumpCfgRr
);
4590 sslBumpCfgRr::finalizeConfig()
4592 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4593 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4594 static char buf
[1024];
4595 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4596 strcpy(buf
, "ssl_bump deny all");
4597 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4598 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4599 "must not use implicit rules. Update your ssl_bump rules.");
4601 strcpy(buf
, "ssl_bump allow all");
4602 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4603 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4604 "inferior to the newer server-first bumping mode. New ssl_bump"
4605 " configurations must not use implicit rules. Update your ssl_bump rules.");
4611 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4613 typedef const char *BumpCfgStyle
;
4614 BumpCfgStyle bcsNone
= NULL
;
4615 BumpCfgStyle bcsNew
= "new client/server-first/none";
4616 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4617 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4618 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4620 if ((bm
= ConfigParser::NextToken()) == NULL
) {
4625 // if this is the first rule proccessed
4626 if (*ssl_bump
== NULL
) {
4627 bumpCfgStyleLast
= bcsNone
;
4628 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4631 allow_t action
= allow_t(ACCESS_ALLOWED
);
4633 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4634 action
.kind
= Ssl::bumpClientFirst
;
4635 bumpCfgStyleNow
= bcsNew
;
4636 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4637 action
.kind
= Ssl::bumpServerFirst
;
4638 bumpCfgStyleNow
= bcsNew
;
4639 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpPeek
]) == 0) {
4640 action
.kind
= Ssl::bumpPeek
;
4641 bumpCfgStyleNow
= bcsNew
;
4642 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpStare
]) == 0) {
4643 action
.kind
= Ssl::bumpStare
;
4644 bumpCfgStyleNow
= bcsNew
;
4645 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpSplice
]) == 0) {
4646 action
.kind
= Ssl::bumpSplice
;
4647 bumpCfgStyleNow
= bcsNew
;
4648 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpBump
]) == 0) {
4649 action
.kind
= Ssl::bumpBump
;
4650 bumpCfgStyleNow
= bcsNew
;
4651 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpTerminate
]) == 0) {
4652 action
.kind
= Ssl::bumpTerminate
;
4653 bumpCfgStyleNow
= bcsNew
;
4654 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4655 action
.kind
= Ssl::bumpNone
;
4656 bumpCfgStyleNow
= bcsNew
;
4657 } else if (strcmp(bm
, "allow") == 0) {
4658 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4659 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4660 "is usually inferior to the newer server-first "
4661 "bumping mode. Update your ssl_bump rules.");
4662 action
.kind
= Ssl::bumpClientFirst
;
4663 bumpCfgStyleNow
= bcsOld
;
4664 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4665 } else if (strcmp(bm
, "deny") == 0) {
4666 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4667 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4668 "your ssl_bump rules.");
4669 action
.kind
= Ssl::bumpNone
;
4670 bumpCfgStyleNow
= bcsOld
;
4671 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4673 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4678 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4679 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4680 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4685 bumpCfgStyleLast
= bumpCfgStyleNow
;
4688 ParseAclWithAction(ssl_bump
, action
, "ssl_bump");
4691 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4694 dump_SBufList(entry
, ssl_bump
->treeDump(name
, [](const allow_t
&action
) {
4695 return Ssl::BumpModeStr
.at(action
.kind
);
4699 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4701 free_acl_access(ssl_bump
);
4706 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4711 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4712 storeAppendPrintf(entry
, "%s %s %s", name
, hwa
->fieldName
.c_str(), hwa
->fieldValue
.c_str());
4714 dump_acl_list(entry
, hwa
->aclList
);
4715 storeAppendPrintf(entry
, "\n");
4719 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4723 *headers
= new HeaderWithAclList
;
4725 if ((fn
= ConfigParser::NextToken()) == NULL
) {
4731 hwa
.fieldId
= Http::HeaderLookupTable
.lookup(hwa
.fieldName
).id
;
4732 if (hwa
.fieldId
== Http::HdrType::BAD_HDR
)
4733 hwa
.fieldId
= Http::HdrType::OTHER
;
4735 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4736 ConfigParser::EnableMacros();
4737 String buf
= ConfigParser::NextQuotedToken();
4738 ConfigParser::DisableMacros();
4739 hwa
.fieldValue
= buf
.termedBuf();
4740 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4742 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4746 hwa
.valueFormat
= nlf
;
4749 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4750 (*headers
)->push_back(hwa
);
4753 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4758 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4760 aclDestroyAclList(&hwa
->aclList
);
4762 if (hwa
->valueFormat
) {
4763 delete hwa
->valueFormat
;
4764 hwa
->valueFormat
= NULL
;
4771 static void parse_note(Notes
*notes
)
4774 notes
->parse(LegacyParser
);
4777 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4779 notes
.dump(entry
, name
);
4782 static void free_note(Notes
*notes
)
4787 static bool FtpEspvDeprecated
= false;
4788 static void parse_ftp_epsv(acl_access
**ftp_epsv
)
4790 allow_t ftpEpsvDeprecatedAction
;
4791 bool ftpEpsvIsDeprecatedRule
= false;
4793 char *t
= ConfigParser::PeekAtToken();
4799 if (!strcmp(t
, "off")) {
4800 (void)ConfigParser::NextToken();
4801 ftpEpsvIsDeprecatedRule
= true;
4802 ftpEpsvDeprecatedAction
= allow_t(ACCESS_DENIED
);
4803 } else if (!strcmp(t
, "on")) {
4804 (void)ConfigParser::NextToken();
4805 ftpEpsvIsDeprecatedRule
= true;
4806 ftpEpsvDeprecatedAction
= allow_t(ACCESS_ALLOWED
);
4809 // Check for mixing "ftp_epsv on|off" and "ftp_epsv allow|deny .." rules:
4810 // 1) if this line is "ftp_epsv allow|deny ..." and already exist rules of "ftp_epsv on|off"
4811 // 2) if this line is "ftp_epsv on|off" and already exist rules of "ftp_epsv allow|deny ..."
4813 if ((!ftpEpsvIsDeprecatedRule
&& FtpEspvDeprecated
) ||
4814 (ftpEpsvIsDeprecatedRule
&& !FtpEspvDeprecated
&& *ftp_epsv
!= NULL
)) {
4815 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.");
4820 if (ftpEpsvIsDeprecatedRule
) {
4821 // overwrite previous ftp_epsv lines
4823 *ftp_epsv
= nullptr;
4825 if (ftpEpsvDeprecatedAction
== allow_t(ACCESS_DENIED
)) {
4826 if (ACL
*a
= ACL::FindByName("all"))
4827 ParseAclWithAction(ftp_epsv
, ftpEpsvDeprecatedAction
, "ftp_epsv", a
);
4833 FtpEspvDeprecated
= true;
4835 aclParseAccessLine(cfg_directive
, LegacyParser
, ftp_epsv
);
4839 static void dump_ftp_epsv(StoreEntry
*entry
, const char *name
, acl_access
*ftp_epsv
)
4842 dump_SBufList(entry
, ftp_epsv
->treeDump(name
, Acl::AllowOrDeny
));
4845 static void free_ftp_epsv(acl_access
**ftp_epsv
)
4847 free_acl_access(ftp_epsv
);
4848 FtpEspvDeprecated
= false;
4852 parse_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4855 parseTimeLine(&tval
, T_SECOND_STR
, false, true);
4856 Config
.Timeout
.urlRewrite
= static_cast<time_t>(tval
/1000);
4859 while(ConfigParser::NextKvPair(key
, value
)) {
4860 if (strcasecmp(key
, "on_timeout") == 0) {
4861 if (strcasecmp(value
, "bypass") == 0)
4862 config
->action
= toutActBypass
;
4863 else if (strcasecmp(value
, "fail") == 0)
4864 config
->action
= toutActFail
;
4865 else if (strcasecmp(value
, "retry") == 0)
4866 config
->action
= toutActRetry
;
4867 else if (strcasecmp(value
, "use_configured_response") == 0) {
4868 config
->action
= toutActUseConfiguredResponse
;
4870 debugs(3, DBG_CRITICAL
, "FATAL: unsuported \"on_timeout\" action:" << value
);
4874 } else if (strcasecmp(key
, "response") == 0) {
4875 config
->response
= xstrdup(value
);
4877 debugs(3, DBG_CRITICAL
, "FATAL: unsuported option " << key
);
4883 if (config
->action
== toutActUseConfiguredResponse
&& !config
->response
) {
4884 debugs(3, DBG_CRITICAL
, "FATAL: Expected 'response=' option after 'on_timeout=use_configured_response' option");
4888 if (config
->action
!= toutActUseConfiguredResponse
&& config
->response
) {
4889 debugs(3, DBG_CRITICAL
, "FATAL: 'response=' option is valid only when used with the 'on_timeout=use_configured_response' option");
4895 dump_UrlHelperTimeout(StoreEntry
*entry
, const char *name
, SquidConfig::UrlHelperTimeout
&config
)
4897 const char *onTimedOutActions
[] = {"bypass", "fail", "retry", "use_configured_response"};
4898 assert(config
.action
>= 0 && config
.action
<= toutActUseConfiguredResponse
);
4900 dump_time_t(entry
, name
, Config
.Timeout
.urlRewrite
);
4901 storeAppendPrintf(entry
, " on_timeout=%s", onTimedOutActions
[config
.action
]);
4903 if (config
.response
)
4904 storeAppendPrintf(entry
, " response=\"%s\"", config
.response
);
4906 storeAppendPrintf(entry
, "\n");
4910 free_UrlHelperTimeout(SquidConfig::UrlHelperTimeout
*config
)
4912 Config
.Timeout
.urlRewrite
= 0;
4914 safe_free(config
->response
);
4918 parse_configuration_includes_quoted_values(bool *)
4923 // If quoted values is set to on then enable new strict mode parsing
4925 ConfigParser::RecognizeQuotedValues
= true;
4926 ConfigParser::StrictMode
= true;
4928 ConfigParser::RecognizeQuotedValues
= false;
4929 ConfigParser::StrictMode
= false;
4934 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool)
4936 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4937 dump_onoff(entry
, name
, val
);
4941 free_configuration_includes_quoted_values(bool *)
4943 ConfigParser::RecognizeQuotedValues
= false;
4944 ConfigParser::StrictMode
= false;
4948 parse_on_unsupported_protocol(acl_access
**access
)
4951 if ((tm
= ConfigParser::NextToken()) == NULL
) {
4956 allow_t action
= allow_t(ACCESS_ALLOWED
);
4957 if (strcmp(tm
, "tunnel") == 0)
4959 else if (strcmp(tm
, "respond") == 0)
4962 debugs(3, DBG_CRITICAL
, "FATAL: unknown on_unsupported_protocol mode: " << tm
);
4968 ParseAclWithAction(access
, action
, "on_unsupported_protocol");
4972 dump_on_unsupported_protocol(StoreEntry
*entry
, const char *name
, acl_access
*access
)
4974 static const std::vector
<const char *> onErrorTunnelMode
= {
4980 SBufList lines
= access
->treeDump(name
, [](const allow_t
&action
) {
4981 return onErrorTunnelMode
.at(action
.kind
);
4983 dump_SBufList(entry
, lines
);
4988 free_on_unsupported_protocol(acl_access
**access
)
4990 free_acl_access(access
);