2 * DEBUG: section 03 Configuration File Parsing
3 * AUTHOR: Harvest Derived
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
35 #include "acl/Gadgets.h"
36 #include "acl/MethodData.h"
37 #include "anyp/PortCfg.h"
39 #include "base/RunnersRegistry.h"
41 #include "ConfigParser.h"
42 #include "CpuAffinityMap.h"
43 #include "DiskIO/DiskIOModule.h"
44 #include "eui/Config.h"
45 #include "ExternalACL.h"
46 #include "format/Format.h"
48 #include "HttpHeaderTools.h"
49 #include "HttpRequestMethod.h"
50 #include "ident/Config.h"
51 #include "ip/Intercept.h"
52 #include "ip/QosConfig.h"
55 #include "log/Config.h"
58 #include "mgr/Registration.h"
60 #include "PeerDigest.h"
62 #include "SquidConfig.h"
63 #include "SquidString.h"
65 #include "StoreFileSystem.h"
69 #include "neighbors.h"
71 /* wccp2 has its own conditional definitions */
74 #include "adaptation/Config.h"
77 #include "adaptation/icap/Config.h"
80 #include "adaptation/ecap/Config.h"
83 #include "ssl/support.h"
84 #include "ssl/Config.h"
87 #include "auth/Config.h"
88 #include "auth/Scheme.h"
91 #include "esi/Parser.h"
107 #include <sys/types.h>
116 #include <sys/stat.h>
120 #include "ssl/gadgets.h"
124 static void parse_adaptation_service_set_type();
125 static void parse_adaptation_service_chain_type();
126 static void parse_adaptation_access_type();
127 static void parse_adaptation_meta_type(Adaptation::Config::MetaHeaders
*);
128 static void dump_adaptation_meta_type(StoreEntry
*, const char *, Adaptation::Config::MetaHeaders
&);
129 static void free_adaptation_meta_type(Adaptation::Config::MetaHeaders
*);
133 static void parse_icap_service_type(Adaptation::Icap::Config
*);
134 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
135 static void free_icap_service_type(Adaptation::Icap::Config
*);
136 static void parse_icap_class_type();
137 static void parse_icap_access_type();
139 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
140 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
141 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
145 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
146 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
147 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
150 static peer_t
parseNeighborType(const char *s
);
152 CBDATA_TYPE(CachePeer
);
154 static const char *const T_MILLISECOND_STR
= "millisecond";
155 static const char *const T_SECOND_STR
= "second";
156 static const char *const T_MINUTE_STR
= "minute";
157 static const char *const T_HOUR_STR
= "hour";
158 static const char *const T_DAY_STR
= "day";
159 static const char *const T_WEEK_STR
= "week";
160 static const char *const T_FORTNIGHT_STR
= "fortnight";
161 static const char *const T_MONTH_STR
= "month";
162 static const char *const T_YEAR_STR
= "year";
163 static const char *const T_DECADE_STR
= "decade";
165 static const char *const B_BYTES_STR
= "bytes";
166 static const char *const B_KBYTES_STR
= "KB";
167 static const char *const B_MBYTES_STR
= "MB";
168 static const char *const B_GBYTES_STR
= "GB";
170 static const char *const list_sep
= ", \t\n\r";
172 static void parse_access_log(customlog
** customlog_definitions
);
173 static int check_null_access_log(customlog
*customlog_definitions
);
174 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
175 static void free_access_log(customlog
** definitions
);
177 static void update_maxobjsize(void);
178 static void configDoConfigure(void);
179 static void parse_refreshpattern(refresh_t
**);
180 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
181 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
182 static void parse_u_short(unsigned short * var
);
183 static void parse_string(char **);
184 static void default_all(void);
185 static void defaults_if_none(void);
186 static void defaults_postscriptum(void);
187 static int parse_line(char *);
188 static void parse_obsolete(const char *);
189 static void parseBytesLine(size_t * bptr
, const char *units
);
191 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
194 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
196 static size_t parseBytesUnits(const char *unit
);
197 static void free_all(void);
198 void requirePathnameExists(const char *name
, const char *path
);
199 static OBJH dump_config
;
200 #if USE_HTTP_VIOLATIONS
201 static void free_HeaderManglers(HeaderManglers
**pm
);
202 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
203 static void parse_http_header_access(HeaderManglers
**manglers
);
204 #define free_http_header_access free_HeaderManglers
205 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
206 static void parse_http_header_replace(HeaderManglers
**manglers
);
207 #define free_http_header_replace free_HeaderManglers
209 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
210 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
211 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
212 static void parse_denyinfo(acl_deny_info_list
** var
);
213 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
214 static void free_denyinfo(acl_deny_info_list
** var
);
217 static void parse_IpAddress_list(Ip::Address_list
**);
218 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
219 static void free_IpAddress_list(Ip::Address_list
**);
221 static int check_null_IpAddress_list(const Ip::Address_list
*);
222 #endif /* CURRENTLY_UNUSED */
223 #endif /* USE_WCCPv2 */
225 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
226 #define parse_PortCfg(l) parsePortCfg((l), token)
227 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
228 static void free_PortCfg(AnyP::PortCfg
**);
231 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
232 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
233 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
234 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
235 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
236 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
237 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
238 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
239 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
242 static void parse_b_size_t(size_t * var
);
243 static void parse_b_int64_t(int64_t * var
);
245 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
247 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
248 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
249 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
251 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
254 * LegacyParser is a parser for legacy code that uses the global
255 * approach. This is static so that it is only exposed to cache_cf.
256 * Other modules needing access to a ConfigParser should have it
257 * provided to them in their parserFOO methods.
259 static ConfigParser LegacyParser
= ConfigParser();
264 LegacyParser
.destruct();
268 update_maxobjsize(void)
273 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
274 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
276 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
278 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
280 store_maxobjsize
= ms
;
284 SetConfigFilename(char const *file_name
, bool is_pipe
)
286 cfg_filename
= file_name
;
291 cfg_filename
= file_name
+ 1;
292 else if ((token
= strrchr(cfg_filename
, '/')))
293 cfg_filename
= token
+ 1;
297 skip_ws(const char* s
)
306 parseManyConfigFiles(char* files
, int depth
)
309 char* saveptr
= NULL
;
314 memset(&globbuf
, 0, sizeof(globbuf
));
315 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
316 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
317 fatalf("Unable to find configuration file: %s: %s",
321 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
322 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
326 char* file
= strwordtok(files
, &saveptr
);
327 while (file
!= NULL
) {
328 error_count
+= parseOneConfigFile(file
, depth
);
329 file
= strwordtok(NULL
, &saveptr
);
331 #endif /* HAVE_GLOB */
336 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
339 assert(newSubstr
!= NULL
);
341 unsigned newSubstrLen
= strlen(newSubstr
);
342 if (newSubstrLen
> substrLen
)
343 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
345 // move tail part including zero
346 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
347 // copy new substring in place
348 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
354 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
356 assert(line
!= NULL
);
357 assert(macroName
!= NULL
);
358 assert(substStr
!= NULL
);
359 unsigned macroNameLen
= strlen(macroName
);
360 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
361 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
365 ProcessMacros(char*& line
, int& len
)
367 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
368 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
372 trim_trailing_ws(char* str
)
375 unsigned i
= strlen(str
);
376 while ((i
> 0) && xisspace(str
[i
- 1]))
382 FindStatement(const char* line
, const char* statement
)
384 assert(line
!= NULL
);
385 assert(statement
!= NULL
);
387 const char* str
= skip_ws(line
);
388 unsigned len
= strlen(statement
);
389 if (strncmp(str
, statement
, len
) == 0) {
393 else if (xisspace(*str
))
401 StrToInt(const char* str
, long& number
)
406 number
= strtol(str
, &end
, 0);
408 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
412 EvalBoolExpr(const char* expr
)
414 assert(expr
!= NULL
);
415 if (strcmp(expr
, "true") == 0) {
417 } else if (strcmp(expr
, "false") == 0) {
419 } else if (const char* equation
= strchr(expr
, '=')) {
420 const char* rvalue
= skip_ws(equation
+ 1);
421 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
422 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
423 trim_trailing_ws(lvalue
);
426 if (!StrToInt(lvalue
, number1
))
427 fatalf("String is not a integer number: '%s'\n", lvalue
);
429 if (!StrToInt(rvalue
, number2
))
430 fatalf("String is not a integer number: '%s'\n", rvalue
);
433 return number1
== number2
;
435 fatalf("Unable to evaluate expression '%s'\n", expr
);
436 return false; // this place cannot be reached
440 parseOneConfigFile(const char *file_name
, unsigned int depth
)
443 const char *orig_cfg_filename
= cfg_filename
;
444 const int orig_config_lineno
= config_lineno
;
446 char *tmp_line
= NULL
;
447 int tmp_line_len
= 0;
451 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
453 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
457 if (file_name
[0] == '!' || file_name
[0] == '|') {
458 fp
= popen(file_name
+ 1, "r");
461 fp
= fopen(file_name
, "r");
465 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
468 setmode(fileno(fp
), O_TEXT
);
471 SetConfigFilename(file_name
, bool(is_pipe
));
473 memset(config_input_line
, '\0', BUFSIZ
);
477 Vector
<bool> if_states
;
478 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
481 if ((token
= strchr(config_input_line
, '\n')))
484 if ((token
= strchr(config_input_line
, '\r')))
487 // strip any prefix whitespace off the line.
488 const char *p
= skip_ws(config_input_line
);
489 if (config_input_line
!= p
)
490 memmove(config_input_line
, p
, strlen(p
)+1);
492 if (strncmp(config_input_line
, "#line ", 6) == 0) {
493 static char new_file_name
[1024];
495 static char new_lineno
;
496 token
= config_input_line
+ 6;
497 new_lineno
= strtol(token
, &file
, 0) - 1;
500 continue; /* Not a valid #line directive, may be a comment */
502 while (*file
&& xisspace((unsigned char) *file
))
507 continue; /* Not a valid #line directive, may be a comment */
509 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
511 if ((token
= strchr(new_file_name
, '"')))
514 cfg_filename
= new_file_name
;
517 config_lineno
= new_lineno
;
520 if (config_input_line
[0] == '#')
523 if (config_input_line
[0] == '\0')
526 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
528 size_t append_len
= strlen(append
);
530 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
532 strcpy(tmp_line
+ tmp_line_len
, append
);
534 tmp_line_len
+= append_len
;
536 if (tmp_line
[tmp_line_len
-1] == '\\') {
537 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
538 tmp_line
[--tmp_line_len
] = '\0';
542 trim_trailing_ws(tmp_line
);
543 ProcessMacros(tmp_line
, tmp_line_len
);
544 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
546 if (const char* expr
= FindStatement(tmp_line
, "if")) {
547 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
548 } else if (FindStatement(tmp_line
, "endif")) {
549 if (!if_states
.empty())
550 if_states
.pop_back(); // remove last if-statement meaning
552 fatalf("'endif' without 'if'\n");
553 } else if (FindStatement(tmp_line
, "else")) {
554 if (!if_states
.empty())
555 if_states
.back() = !if_states
.back();
557 fatalf("'else' without 'if'\n");
558 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
559 /* Handle includes here */
560 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
561 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
562 } else if (!parse_line(tmp_line
)) {
563 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
572 if (!if_states
.empty())
573 fatalf("if-statement without 'endif'\n");
576 int ret
= pclose(fp
);
579 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
584 cfg_filename
= orig_cfg_filename
;
585 config_lineno
= orig_config_lineno
;
591 parseConfigFile(const char *file_name
)
599 ACLMethodData::ThePurgeCount
= 0;
602 err_count
= parseOneConfigFile(file_name
, 0);
606 defaults_postscriptum();
609 * We must call configDoConfigure() before leave_suid() because
610 * configDoConfigure() is where we turn username strings into
615 if (!Config
.chroot_dir
) {
617 setUmask(Config
.umask
);
618 _db_init(Debug::cache_log
, Debug::debugOptions
);
622 if (opt_send_signal
== -1) {
623 Mgr::RegisterAction("config",
624 "Current Squid Configuration",
633 configDoConfigure(void)
635 memset(&Config2
, '\0', sizeof(SquidConfig2
));
636 /* init memory as early as possible */
640 if (Config
.cacheSwap
.swapDirs
== NULL
) {
641 /* Memory-only cache probably in effect. */
642 /* turn off the cache rebuild delays... */
643 StoreController::store_dirs_rebuilding
= 0;
644 } else if (InDaemonMode()) { // no diskers in non-daemon mode
645 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
646 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
647 if (sd
->needsDiskStrand())
648 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
652 if (Debug::rotateNumber
< 0) {
653 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
656 #if SIZEOF_OFF_T <= 4
657 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
658 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
659 Config
.Store
.maxObjectSize
= 0x7FFF0000;
662 if (0 == Store::Root().maxSize())
663 /* people might want a zero-sized cache on purpose */
665 else if (Store::Root().maxSize() < Config
.memMaxSize
)
666 /* This is bogus. folk with NULL caches will want this */
667 debugs(3, DBG_CRITICAL
, "WARNING cache_mem is larger than total disk cache space!");
669 if (Config
.Announce
.period
> 0) {
670 Config
.onoff
.announce
= 1;
671 } else if (Config
.Announce
.period
< 1) {
672 Config
.Announce
.period
= 86400 * 365; /* one year */
673 Config
.onoff
.announce
= 0;
676 if (Config
.onoff
.httpd_suppress_version_string
)
677 visible_appname_string
= (char *)appname_string
;
679 visible_appname_string
= (char const *)APP_FULLNAME
;
682 if (Config
.dnsChildren
.n_max
< 1)
683 fatal("No DNS helpers allocated");
686 if (Config
.Program
.redirect
) {
687 if (Config
.redirectChildren
.n_max
< 1) {
688 Config
.redirectChildren
.n_max
= 0;
689 wordlistDestroy(&Config
.Program
.redirect
);
693 if (Config
.appendDomain
)
694 if (*Config
.appendDomain
!= '.')
695 fatal("append_domain must begin with a '.'");
697 if (Config
.errHtmlText
== NULL
)
698 Config
.errHtmlText
= xstrdup(null_string
);
700 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
701 if (Config
.max_filedescriptors
> 0) {
702 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
704 #elif USE_SELECT || USE_SELECT_WIN32
705 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
706 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
712 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
714 visible_appname_string
);
717 * the extra space is for loop detection in client_side.c -- we search
718 * for substrings in the Via header.
720 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
722 visible_appname_string
);
724 /* Use visible_hostname as default surrogate_id */
725 if (!Config
.Accel
.surrogate_id
) {
726 const char *t
= getMyHostname();
727 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
730 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
731 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
733 if (Config
.appendDomain
)
734 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
736 Config
.appendDomainLen
= 0;
738 if (Config
.connect_retries
> 10) {
739 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
740 Config
.connect_retries
= 10;
743 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
745 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
749 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
751 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
752 if (Config
.Program
.redirect
)
753 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
755 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
757 if (Config
.errorDirectory
)
758 requirePathnameExists("Error Directory", Config
.errorDirectory
);
760 #if USE_HTTP_VIOLATIONS
765 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
766 if (!R
->flags
.override_expire
)
769 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
774 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
775 if (!R
->flags
.override_lastmod
)
778 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
783 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
784 if (!R
->flags
.reload_into_ims
)
787 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
792 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
793 if (!R
->flags
.ignore_reload
)
796 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
801 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
802 if (!R
->flags
.ignore_no_cache
)
805 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
810 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
811 if (!R
->flags
.ignore_no_store
)
814 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
819 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
820 if (!R
->flags
.ignore_must_revalidate
)
822 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
826 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
827 if (!R
->flags
.ignore_private
)
830 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
835 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
836 if (!R
->flags
.ignore_auth
)
839 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
846 #if !USE_HTTP_VIOLATIONS
847 Config
.onoff
.via
= 1;
850 if (!Config
.onoff
.via
)
851 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
855 // we enable runtime PURGE checks if there is at least one PURGE method ACL
856 // TODO: replace with a dedicated "purge" ACL option?
857 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
859 Config2
.onoff
.mangle_request_headers
= (Config
.request_header_access
!= NULL
);
861 if (geteuid() == 0) {
862 if (NULL
!= Config
.effectiveUser
) {
864 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
868 * Andres Kroonmaa <andre@online.ee>:
869 * Some getpwnam() implementations (Solaris?) require
870 * an available FD < 256 for opening a FILE* to the
873 * This should be safe at startup, but might still fail
874 * during reconfigure.
876 fatalf("getpwnam failed to find userid for effective user '%s'",
877 Config
.effectiveUser
);
881 Config2
.effectiveUserID
= pwd
->pw_uid
;
883 Config2
.effectiveGroupID
= pwd
->pw_gid
;
887 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
889 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
890 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
898 Config2
.effectiveUserID
= geteuid();
899 Config2
.effectiveGroupID
= getegid();
902 if (NULL
!= Config
.effectiveGroup
) {
904 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
907 fatalf("getgrnam failed to find groupid for effective group '%s'",
908 Config
.effectiveGroup
);
912 Config2
.effectiveGroupID
= grp
->gr_gid
;
915 HttpRequestMethod::Configure(Config
);
918 debugs(3, DBG_IMPORTANT
, "Initializing https proxy context");
920 Config
.ssl_client
.sslContext
= sslCreateClientContext(Config
.ssl_client
.cert
, Config
.ssl_client
.key
, Config
.ssl_client
.version
, Config
.ssl_client
.cipher
, Config
.ssl_client
.options
, Config
.ssl_client
.flags
, Config
.ssl_client
.cafile
, Config
.ssl_client
.capath
, Config
.ssl_client
.crlfile
);
922 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
924 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " SSL context");
925 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
929 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
933 debugs(3, DBG_IMPORTANT
, "Initializing http_port " << s
->s
<< " SSL context");
934 s
->configureSslServerContext();
937 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
938 debugs(3, DBG_IMPORTANT
, "Initializing https_port " << s
->s
<< " SSL context");
939 s
->configureSslServerContext();
944 // prevent infinite fetch loops in the request parser
945 // due to buffer full but not enough data recived to finish parse
946 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
947 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
948 " Change client_request_buffer_max or request_header_max_size limits.",
949 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
954 * disable client side request pipelining. There is a race with
955 * Negotiate and NTLM when the client sends a second request on an
956 * connection before the authenticate challenge is sent. With
957 * pipelining OFF, the client may fail to authenticate, but squid's
958 * state will be preserved.
960 if (Config
.onoff
.pipeline_prefetch
) {
961 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
962 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
963 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
964 debugs(3, DBG_IMPORTANT
, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
965 Config
.onoff
.pipeline_prefetch
= 0;
971 /** Parse a line containing an obsolete directive.
972 * To upgrade it where possible instead of just "Bungled config" for
973 * directives which cannot be marked as simply aliases of the some name.
974 * For example if the parameter order and content has changed.
975 * Or if the directive has been completely removed.
978 parse_obsolete(const char *name
)
980 // Directives which have been radically changed rather than removed
981 if (!strcmp(name
, "url_rewrite_concurrency")) {
984 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
985 Config
.redirectChildren
.concurrency
= cval
;
989 /* Parse a time specification from the config file. Store the
990 * result in 'tptr', after converting it to 'units' */
992 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
999 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
1002 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1007 m
= u
; /* default to 'units' if none specified */
1011 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1012 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1013 config_input_line
<< "', assuming " <<
1014 d
<< " " << units
);
1015 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1018 *tptr
= static_cast<time_msec_t
>(m
* d
);
1022 parseTimeUnits(const char *unit
, bool allowMsec
)
1024 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1027 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1030 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1033 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1036 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1037 return 86400 * 1000;
1039 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1040 return 86400 * 7 * 1000;
1042 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1043 return 86400 * 14 * 1000;
1045 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1046 return static_cast<uint64_t>(86400) * 30 * 1000;
1048 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1049 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1051 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1052 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1054 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1060 parseBytesLine64(int64_t * bptr
, const char *units
)
1067 if ((u
= parseBytesUnits(units
)) == 0) {
1072 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1077 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1084 m
= u
; /* default to 'units' if none specified */
1088 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1089 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1090 config_input_line
<< "', assuming " <<
1091 d
<< " " << units
);
1092 else if ((m
= parseBytesUnits(token
)) == 0) {
1097 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1099 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1104 parseBytesLine(size_t * bptr
, const char *units
)
1111 if ((u
= parseBytesUnits(units
)) == 0) {
1116 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1121 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1122 *bptr
= static_cast<size_t>(-1);
1128 m
= u
; /* default to 'units' if none specified */
1132 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1133 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1134 config_input_line
<< "', assuming " <<
1135 d
<< " " << units
);
1136 else if ((m
= parseBytesUnits(token
)) == 0) {
1141 *bptr
= static_cast<size_t>(m
* d
/ u
);
1143 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1149 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1156 if ((u
= parseBytesUnits(units
)) == 0) {
1161 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1166 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1173 m
= u
; /* default to 'units' if none specified */
1177 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1178 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1179 config_input_line
<< "', assuming " <<
1180 d
<< " " << units
);
1181 else if ((m
= parseBytesUnits(token
)) == 0) {
1186 *bptr
= static_cast<size_t>(m
* d
/ u
);
1188 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1195 * Parse bytes from a string.
1196 * Similar to the parseBytesLine function but parses the string value instead of
1197 * the current token value.
1199 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1202 if ((u
= parseBytesUnits(units
)) == 0) {
1207 // Find number from string beginning.
1208 char const * number_begin
= value
;
1209 char const * number_end
= value
;
1211 while ((*number_end
>= '0' && *number_end
<= '9')) {
1216 number
.limitInit(number_begin
, number_end
- number_begin
);
1218 int d
= xatoi(number
.termedBuf());
1220 if ((m
= parseBytesUnits(number_end
)) == 0) {
1225 *bptr
= static_cast<size_t>(m
* d
/ u
);
1226 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1232 parseBytesUnits(const char *unit
)
1234 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1237 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1240 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1243 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1246 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1251 /*****************************************************************************
1253 *****************************************************************************/
1256 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1261 while (ae
!= NULL
) {
1262 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1263 storeAppendPrintf(entry
, "%s %s %s ",
1270 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1271 storeAppendPrintf(entry
, "%s ", v
->key
);
1275 storeAppendPrintf(entry
, "\n");
1276 wordlistDestroy(&w
);
1282 parse_acl(ACL
** ae
)
1284 ACL::ParseAclLine(LegacyParser
, ae
);
1294 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1298 for (l
= head
; l
; l
= l
->next
) {
1299 storeAppendPrintf(entry
, " %s%s",
1300 l
->op
? null_string
: "!",
1306 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1310 for (l
= head
; l
; l
= l
->next
) {
1311 storeAppendPrintf(entry
, "%s %s",
1313 l
->allow
? "Allow" : "Deny");
1314 dump_acl_list(entry
, l
->aclList
);
1315 storeAppendPrintf(entry
, "\n");
1320 parse_acl_access(acl_access
** head
)
1322 aclParseAccessLine(LegacyParser
, head
);
1326 free_acl_access(acl_access
** head
)
1328 aclDestroyAccessList(head
);
1332 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1334 char buf
[MAX_IPSTRLEN
];
1335 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1339 parse_address(Ip::Address
*addr
)
1341 char *token
= strtok(NULL
, w_space
);
1348 if (!strcmp(token
,"any_addr"))
1350 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1352 else if ( (*addr
= token
) ) // try parse numeric/IPA
1355 addr
->GetHostByName(token
); // dont use ipcache
1359 free_address(Ip::Address
*addr
)
1364 CBDATA_TYPE(acl_address
);
1367 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1369 char buf
[MAX_IPSTRLEN
];
1372 for (l
= head
; l
; l
= l
->next
) {
1373 if (!l
->addr
.IsAnyAddr())
1374 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1376 storeAppendPrintf(entry
, "%s autoselect", name
);
1378 dump_acl_list(entry
, l
->aclList
);
1380 storeAppendPrintf(entry
, "\n");
1385 freed_acl_address(void *data
)
1387 acl_address
*l
= static_cast<acl_address
*>(data
);
1388 aclDestroyAclList(&l
->aclList
);
1392 parse_acl_address(acl_address
** head
)
1395 acl_address
**tail
= head
; /* sane name below */
1396 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1397 l
= cbdataAlloc(acl_address
);
1398 parse_address(&l
->addr
);
1399 aclParseAclList(LegacyParser
, &l
->aclList
);
1402 tail
= &(*tail
)->next
;
1408 free_acl_address(acl_address
** head
)
1411 acl_address
*l
= *head
;
1417 CBDATA_TYPE(acl_tos
);
1420 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1424 for (l
= head
; l
; l
= l
->next
) {
1426 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1428 storeAppendPrintf(entry
, "%s none", name
);
1430 dump_acl_list(entry
, l
->aclList
);
1432 storeAppendPrintf(entry
, "\n");
1437 freed_acl_tos(void *data
)
1439 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1440 aclDestroyAclList(&l
->aclList
);
1444 parse_acl_tos(acl_tos
** head
)
1447 acl_tos
**tail
= head
; /* sane name below */
1448 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1449 char *token
= strtok(NULL
, w_space
);
1456 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1461 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1463 l
= cbdataAlloc(acl_tos
);
1465 l
->tos
= (tos_t
)tos
;
1467 aclParseAclList(LegacyParser
, &l
->aclList
);
1470 tail
= &(*tail
)->next
;
1476 free_acl_tos(acl_tos
** head
)
1486 #if SO_MARK && USE_LIBCAP
1488 CBDATA_TYPE(acl_nfmark
);
1491 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1495 for (l
= head
; l
; l
= l
->next
) {
1497 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1499 storeAppendPrintf(entry
, "%s none", name
);
1501 dump_acl_list(entry
, l
->aclList
);
1503 storeAppendPrintf(entry
, "\n");
1508 freed_acl_nfmark(void *data
)
1510 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1511 aclDestroyAclList(&l
->aclList
);
1515 parse_acl_nfmark(acl_nfmark
** head
)
1518 acl_nfmark
**tail
= head
; /* sane name below */
1520 char *token
= strtok(NULL
, w_space
);
1527 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1532 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1534 l
= cbdataAlloc(acl_nfmark
);
1538 aclParseAclList(LegacyParser
, &l
->aclList
);
1541 tail
= &(*tail
)->next
;
1547 free_acl_nfmark(acl_nfmark
** head
)
1550 acl_nfmark
*l
= *head
;
1556 #endif /* SO_MARK */
1558 CBDATA_TYPE(acl_size_t
);
1561 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1565 for (l
= head
; l
; l
= l
->next
) {
1567 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1569 storeAppendPrintf(entry
, "%s none", name
);
1571 dump_acl_list(entry
, l
->aclList
);
1573 storeAppendPrintf(entry
, "\n");
1578 freed_acl_b_size_t(void *data
)
1580 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1581 aclDestroyAclList(&l
->aclList
);
1585 parse_acl_b_size_t(acl_size_t
** head
)
1588 acl_size_t
**tail
= head
; /* sane name below */
1590 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1592 l
= cbdataAlloc(acl_size_t
);
1594 parse_b_int64_t(&l
->size
);
1596 aclParseAclList(LegacyParser
, &l
->aclList
);
1599 tail
= &(*tail
)->next
;
1605 free_acl_b_size_t(acl_size_t
** head
)
1608 acl_size_t
*l
= *head
;
1617 #include "DelayPools.h"
1618 #include "DelayConfig.h"
1619 /* do nothing - free_delay_pool_count is the magic free function.
1620 * this is why delay_pool_count isn't just marked TYPE: u_short
1622 #define free_delay_pool_class(X)
1623 #define free_delay_pool_access(X)
1624 #define free_delay_pool_rates(X)
1625 #define dump_delay_pool_class(X, Y, Z)
1626 #define dump_delay_pool_access(X, Y, Z)
1627 #define dump_delay_pool_rates(X, Y, Z)
1630 free_delay_pool_count(DelayConfig
* cfg
)
1632 cfg
->freePoolCount();
1636 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1638 cfg
.dumpPoolCount (entry
, name
);
1642 parse_delay_pool_count(DelayConfig
* cfg
)
1644 cfg
->parsePoolCount();
1648 parse_delay_pool_class(DelayConfig
* cfg
)
1650 cfg
->parsePoolClass();
1654 parse_delay_pool_rates(DelayConfig
* cfg
)
1656 cfg
->parsePoolRates();
1660 parse_delay_pool_access(DelayConfig
* cfg
)
1662 cfg
->parsePoolAccess(LegacyParser
);
1668 #include "ClientDelayConfig.h"
1669 /* do nothing - free_client_delay_pool_count is the magic free function.
1670 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1673 #define free_client_delay_pool_access(X)
1674 #define free_client_delay_pool_rates(X)
1675 #define dump_client_delay_pool_access(X, Y, Z)
1676 #define dump_client_delay_pool_rates(X, Y, Z)
1679 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1681 cfg
->freePoolCount();
1685 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1687 cfg
.dumpPoolCount (entry
, name
);
1691 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1693 cfg
->parsePoolCount();
1697 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1699 cfg
->parsePoolRates();
1703 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1705 cfg
->parsePoolAccess(LegacyParser
);
1709 #if USE_HTTP_VIOLATIONS
1711 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1714 manglers
->dumpAccess(entry
, name
);
1718 parse_http_header_access(HeaderManglers
**pm
)
1722 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1723 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1724 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1729 *pm
= new HeaderManglers
;
1730 HeaderManglers
*manglers
= *pm
;
1731 header_mangler
*mangler
= manglers
->track(t
);
1733 parse_acl_access(&mangler
->access_list
);
1737 free_HeaderManglers(HeaderManglers
**pm
)
1739 // we delete the entire http_header_* mangler configuration at once
1740 if (const HeaderManglers
*manglers
= *pm
) {
1747 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1750 manglers
->dumpReplacement(entry
, name
);
1754 parse_http_header_replace(HeaderManglers
**pm
)
1758 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1759 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1760 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1764 const char *value
= t
+ strlen(t
) + 1;
1767 *pm
= new HeaderManglers
;
1768 HeaderManglers
*manglers
= *pm
;
1769 manglers
->setReplacement(t
, value
);
1775 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1781 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1782 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1784 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1786 storeAppendPrintf(entry
, "\n");
1791 check_null_string(char *s
)
1798 parse_authparam(Auth::ConfigVector
* config
)
1803 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1806 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1809 /* find a configuration for the scheme in the currently parsed configs... */
1810 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1812 if (schemeCfg
== NULL
) {
1813 /* Create a configuration based on the scheme info */
1814 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1816 if (theScheme
== NULL
) {
1817 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1821 config
->push_back(theScheme
->createConfig());
1822 schemeCfg
= Auth::Config::Find(type_str
);
1823 if (schemeCfg
== NULL
) {
1824 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1829 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1833 free_authparam(Auth::ConfigVector
* cfg
)
1835 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1838 /* remove our pointers to the probably-dead sub-configs */
1839 while (cfg
->size()) {
1843 /* on reconfigure initialize new auth schemes for the new config. */
1844 if (reconfiguring
) {
1850 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1852 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1853 (*i
)->dump(entry
, name
, (*i
));
1855 #endif /* USE_AUTH */
1857 /* TODO: just return the object, the # is irrelevant */
1859 find_fstype(char *type
)
1861 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1862 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1869 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1873 RefCount
<SwapDir
> sd
;
1877 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1880 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1883 fs
= find_fstype(type_str
);
1888 /* reconfigure existing dir */
1890 for (i
= 0; i
< swap
->n_configured
; ++i
) {
1891 assert (swap
->swapDirs
[i
].getRaw());
1893 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1894 /* this is specific to on-fs Stores. The right
1895 * way to handle this is probably to have a mapping
1896 * from paths to stores, and have on-fs stores
1897 * register with that, and lookip in that in their
1898 * own setup logic. RBC 20041225. TODO.
1901 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1903 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().items
[fs
]->type()) != 0) {
1904 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1905 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1911 update_maxobjsize();
1918 if (swap
->n_configured
> 63) {
1919 /* 7 bits, signed */
1920 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1921 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1926 allocate_new_swapdir(swap
);
1928 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1930 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1932 /* parse the FS parameters and options */
1933 sd
->parse(swap
->n_configured
, path_str
);
1935 ++swap
->n_configured
;
1937 /* Update the max object size */
1938 update_maxobjsize();
1942 peer_type_str(const peer_t type
)
1944 const char * result
;
1956 case PEER_MULTICAST
:
1957 result
= "multicast";
1969 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
1973 LOCAL_ARRAY(char, xname
, 128);
1976 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1983 dump_peer_options(entry
, p
);
1985 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1986 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1988 d
->do_ping
? null_string
: "!",
1993 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1994 dump_acl_access(entry
, xname
, p
->access
);
1997 for (t
= p
->typelist
; t
; t
= t
->next
) {
1998 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2000 peer_type_str(t
->type
),
2009 * utility function to prevent getservbyname() being called with a numeric value
2010 * on Windows at least it returns garage results.
2013 isUnsignedNumeric(const char *str
, size_t len
)
2015 if (len
< 1) return false;
2017 for (; len
>0 && *str
; ++str
, --len
) {
2018 if (! isdigit(*str
))
2025 \param proto 'tcp' or 'udp' for protocol
2026 \returns Port the named service is supposed to be listening on.
2028 static unsigned short
2029 GetService(const char *proto
)
2031 struct servent
*port
= NULL
;
2032 /** Parses a port number or service name from the squid.conf */
2033 char *token
= strtok(NULL
, w_space
);
2034 if (token
== NULL
) {
2036 return 0; /* NEVER REACHED */
2038 /** Returns either the service port number from /etc/services */
2039 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2040 port
= getservbyname(token
, proto
);
2042 return ntohs((unsigned short)port
->s_port
);
2044 /** Or a numeric translation of the config text. */
2045 return xatos(token
);
2049 \returns Port the named TCP service is supposed to be listening on.
2050 \copydoc GetService(const char *proto)
2052 inline unsigned short
2055 return GetService("tcp");
2059 \returns Port the named UDP service is supposed to be listening on.
2060 \copydoc GetService(const char *proto)
2062 inline unsigned short
2065 return GetService("udp");
2069 parse_peer(CachePeer
** head
)
2073 CBDATA_INIT_TYPE_FREECB(CachePeer
, peerDestroy
);
2074 p
= cbdataAlloc(CachePeer
);
2075 p
->http_port
= CACHE_HTTP_PORT
;
2076 p
->icp
.port
= CACHE_ICP_PORT
;
2079 p
->stats
.logged_state
= PEER_ALIVE
;
2081 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2084 p
->host
= xstrdup(token
);
2086 p
->name
= xstrdup(token
);
2088 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2091 p
->type
= parseNeighborType(token
);
2093 if (p
->type
== PEER_MULTICAST
) {
2094 p
->options
.no_digest
= 1;
2095 p
->options
.no_netdb_exchange
= 1;
2098 p
->http_port
= GetTcpService();
2103 p
->icp
.port
= GetUdpService();
2104 p
->connection_auth
= 2; /* auto */
2106 while ((token
= strtok(NULL
, w_space
))) {
2107 if (!strcasecmp(token
, "proxy-only")) {
2108 p
->options
.proxy_only
= 1;
2109 } else if (!strcasecmp(token
, "no-query")) {
2110 p
->options
.no_query
= 1;
2111 } else if (!strcasecmp(token
, "background-ping")) {
2112 p
->options
.background_ping
= 1;
2113 } else if (!strcasecmp(token
, "no-digest")) {
2114 p
->options
.no_digest
= 1;
2115 } else if (!strcasecmp(token
, "no-tproxy")) {
2116 p
->options
.no_tproxy
= 1;
2117 } else if (!strcasecmp(token
, "multicast-responder")) {
2118 p
->options
.mcast_responder
= 1;
2119 #if PEER_MULTICAST_SIBLINGS
2120 } else if (!strcasecmp(token
, "multicast-siblings")) {
2121 p
->options
.mcast_siblings
= 1;
2123 } else if (!strncasecmp(token
, "weight=", 7)) {
2124 p
->weight
= xatoi(token
+ 7);
2125 } else if (!strncasecmp(token
, "basetime=", 9)) {
2126 p
->basetime
= xatoi(token
+ 9);
2127 } else if (!strcasecmp(token
, "closest-only")) {
2128 p
->options
.closest_only
= 1;
2129 } else if (!strncasecmp(token
, "ttl=", 4)) {
2130 p
->mcast
.ttl
= xatoi(token
+ 4);
2132 if (p
->mcast
.ttl
< 0)
2135 if (p
->mcast
.ttl
> 128)
2137 } else if (!strcasecmp(token
, "default")) {
2138 p
->options
.default_parent
= 1;
2139 } else if (!strcasecmp(token
, "round-robin")) {
2140 p
->options
.roundrobin
= 1;
2141 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2142 p
->options
.weighted_roundrobin
= 1;
2144 } else if (!strcasecmp(token
, "htcp")) {
2145 p
->options
.htcp
= 1;
2146 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2147 /* Note: The htcp- form is deprecated, replaced by htcp= */
2148 p
->options
.htcp
= 1;
2149 char *tmp
= xstrdup(token
+5);
2150 char *mode
, *nextmode
;
2151 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2152 nextmode
= strchr(mode
, ',');
2157 if (!strcasecmp(mode
, "no-clr")) {
2158 if (p
->options
.htcp_only_clr
)
2159 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2160 p
->options
.htcp_no_clr
= 1;
2161 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2162 p
->options
.htcp_no_purge_clr
= 1;
2163 } else if (!strcasecmp(mode
, "only-clr")) {
2164 if (p
->options
.htcp_no_clr
)
2165 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2166 p
->options
.htcp_only_clr
= 1;
2167 } else if (!strcasecmp(mode
, "forward-clr")) {
2168 p
->options
.htcp_forward_clr
= 1;
2169 } else if (!strcasecmp(mode
, "oldsquid")) {
2170 p
->options
.htcp_oldsquid
= 1;
2172 fatalf("invalid HTCP mode '%s'", mode
);
2177 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2178 p
->options
.no_netdb_exchange
= 1;
2180 } else if (!strcasecmp(token
, "carp")) {
2181 if (p
->type
!= PEER_PARENT
)
2182 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2184 p
->options
.carp
= 1;
2185 } else if (!strncasecmp(token
, "carp-key=", 9)) {
2186 if (p
->options
.carp
!= 1)
2187 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2188 p
->options
.carp_key
.set
=1;
2189 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2190 for (; key
; key
= nextkey
) {
2191 nextkey
=strchr(key
,',');
2192 if (nextkey
) ++nextkey
; // skip the comma, any
2193 if (0==strncasecmp(key
,"scheme",6)) {
2194 p
->options
.carp_key
.scheme
=1;
2195 } else if (0==strncasecmp(key
,"host",4)) {
2196 p
->options
.carp_key
.host
=1;
2197 } else if (0==strncasecmp(key
,"port",4)) {
2198 p
->options
.carp_key
.port
=1;
2199 } else if (0==strncasecmp(key
,"path",4)) {
2200 p
->options
.carp_key
.path
=1;
2201 } else if (0==strncasecmp(key
,"params",6)) {
2202 p
->options
.carp_key
.params
=1;
2204 fatalf("invalid carp-key '%s'",key
);
2207 } else if (!strcasecmp(token
, "userhash")) {
2209 if (p
->type
!= PEER_PARENT
)
2210 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2212 p
->options
.userhash
= 1;
2214 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2216 } else if (!strcasecmp(token
, "sourcehash")) {
2217 if (p
->type
!= PEER_PARENT
)
2218 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2220 p
->options
.sourcehash
= 1;
2222 } else if (!strcasecmp(token
, "no-delay")) {
2224 p
->options
.no_delay
= 1;
2226 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2228 } else if (!strncasecmp(token
, "login=", 6)) {
2229 p
->login
= xstrdup(token
+ 6);
2230 rfc1738_unescape(p
->login
);
2231 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2232 p
->connect_timeout
= xatoi(token
+ 16);
2233 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2234 p
->connect_fail_limit
= xatoi(token
+ 19);
2235 #if USE_CACHE_DIGESTS
2236 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2237 p
->digest_url
= xstrdup(token
+ 11);
2240 } else if (!strcasecmp(token
, "allow-miss")) {
2241 p
->options
.allow_miss
= 1;
2242 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2243 p
->max_conn
= xatoi(token
+ 9);
2244 } else if (!strcasecmp(token
, "originserver")) {
2245 p
->options
.originserver
= 1;
2246 } else if (!strncasecmp(token
, "name=", 5)) {
2250 p
->name
= xstrdup(token
+ 5);
2251 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2252 safe_free(p
->domain
);
2255 p
->domain
= xstrdup(token
+ 13);
2259 } else if (strcmp(token
, "ssl") == 0) {
2261 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2262 safe_free(p
->sslcert
);
2263 p
->sslcert
= xstrdup(token
+ 8);
2264 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2265 safe_free(p
->sslkey
);
2266 p
->sslkey
= xstrdup(token
+ 7);
2267 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2268 p
->sslversion
= atoi(token
+ 11);
2269 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2270 safe_free(p
->ssloptions
);
2271 p
->ssloptions
= xstrdup(token
+ 11);
2272 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2273 safe_free(p
->sslcipher
);
2274 p
->sslcipher
= xstrdup(token
+ 10);
2275 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2276 safe_free(p
->sslcafile
);
2277 p
->sslcafile
= xstrdup(token
+ 10);
2278 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2279 safe_free(p
->sslcapath
);
2280 p
->sslcapath
= xstrdup(token
+ 10);
2281 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2282 safe_free(p
->sslcrlfile
);
2283 p
->sslcapath
= xstrdup(token
+ 10);
2284 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2285 safe_free(p
->sslflags
);
2286 p
->sslflags
= xstrdup(token
+ 9);
2287 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2288 safe_free(p
->ssldomain
);
2289 p
->ssldomain
= xstrdup(token
+ 10);
2292 } else if (strcmp(token
, "front-end-https") == 0) {
2293 p
->front_end_https
= 1;
2294 } else if (strcmp(token
, "front-end-https=on") == 0) {
2295 p
->front_end_https
= 1;
2296 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2297 p
->front_end_https
= 2;
2298 } else if (strcmp(token
, "connection-auth=off") == 0) {
2299 p
->connection_auth
= 0;
2300 } else if (strcmp(token
, "connection-auth") == 0) {
2301 p
->connection_auth
= 1;
2302 } else if (strcmp(token
, "connection-auth=on") == 0) {
2303 p
->connection_auth
= 1;
2304 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2305 p
->connection_auth
= 2;
2307 debugs(3, DBG_CRITICAL
, "parse_peer: token='" << token
<< "'");
2312 if (peerFindByName(p
->name
))
2313 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2318 if (p
->connect_fail_limit
< 1)
2319 p
->connect_fail_limit
= 10;
2321 p
->icp
.version
= ICP_VERSION_CURRENT
;
2323 p
->testing_now
= false;
2325 #if USE_CACHE_DIGESTS
2327 if (!p
->options
.no_digest
) {
2328 /* XXX This looks odd.. who has the original pointer
2331 PeerDigest
*pd
= peerDigestCreate(p
);
2332 p
->digest
= cbdataReference(pd
);
2337 p
->index
= ++Config
.npeers
;
2339 while (*head
!= NULL
)
2340 head
= &(*head
)->next
;
2348 free_peer(CachePeer
** P
)
2352 while ((p
= *P
) != NULL
) {
2354 #if USE_CACHE_DIGESTS
2356 cbdataReferenceDone(p
->digest
);
2366 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2370 while (list
!= NULL
) {
2371 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2372 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2374 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2376 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2377 storeAppendPrintf(entry
, " %s", w
->key
);
2380 storeAppendPrintf(entry
, "\n");
2386 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2388 char *passwd
= NULL
;
2389 wordlist
*actions
= NULL
;
2391 cachemgr_passwd
**P
;
2392 parse_string(&passwd
);
2393 parse_wordlist(&actions
);
2394 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2396 p
->actions
= actions
;
2398 for (P
= head
; *P
; P
= &(*P
)->next
) {
2400 * See if any of the actions from this line already have a
2401 * password from previous lines. The password checking
2402 * routines in cache_manager.c take the the password from
2403 * the first cachemgr_passwd struct that contains the
2404 * requested action. Thus, we should warn users who might
2405 * think they can have two passwords for the same action.
2410 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2411 for (u
= actions
; u
; u
= u
->next
) {
2412 if (strcmp(w
->key
, u
->key
))
2415 debugs(0, DBG_CRITICAL
, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2424 free_cachemgrpasswd(cachemgr_passwd
** head
)
2428 while ((p
= *head
) != NULL
) {
2431 wordlistDestroy(&p
->actions
);
2437 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2441 while (var
!= NULL
) {
2442 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2444 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2445 storeAppendPrintf(entry
, " %s", a
->name
);
2447 storeAppendPrintf(entry
, "\n");
2454 parse_denyinfo(acl_deny_info_list
** var
)
2456 aclParseDenyInfoLine(var
);
2460 free_denyinfo(acl_deny_info_list
** list
)
2462 acl_deny_info_list
*a
= NULL
;
2463 acl_deny_info_list
*a_next
= NULL
;
2464 acl_name_list
*l
= NULL
;
2465 acl_name_list
*l_next
= NULL
;
2467 for (a
= *list
; a
; a
= a_next
) {
2468 for (l
= a
->acl_list
; l
; l
= l_next
) {
2470 memFree(l
, MEM_ACL_NAME_LIST
);
2475 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2483 parse_peer_access(void)
2488 if (!(host
= strtok(NULL
, w_space
)))
2491 if ((p
= peerFindByName(host
)) == NULL
) {
2492 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2496 aclParseAccessLine(LegacyParser
, &p
->access
);
2500 parse_hostdomain(void)
2503 char *domain
= NULL
;
2505 if (!(host
= strtok(NULL
, w_space
)))
2508 while ((domain
= strtok(NULL
, list_sep
))) {
2509 domain_ping
*l
= NULL
;
2510 domain_ping
**L
= NULL
;
2513 if ((p
= peerFindByName(host
)) == NULL
) {
2514 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2518 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2521 if (*domain
== '!') { /* check for !.edu */
2526 l
->domain
= xstrdup(domain
);
2528 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2534 parse_hostdomaintype(void)
2538 char *domain
= NULL
;
2540 if (!(host
= strtok(NULL
, w_space
)))
2543 if (!(type
= strtok(NULL
, w_space
)))
2546 while ((domain
= strtok(NULL
, list_sep
))) {
2547 domain_type
*l
= NULL
;
2548 domain_type
**L
= NULL
;
2551 if ((p
= peerFindByName(host
)) == NULL
) {
2552 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2556 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2557 l
->type
= parseNeighborType(type
);
2558 l
->domain
= xstrdup(domain
);
2560 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2566 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2568 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2586 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2588 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2592 parse_onoff(int *var
)
2594 char *token
= strtok(NULL
, w_space
);
2599 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2605 #define free_onoff free_int
2608 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2619 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2623 parse_tristate(int *var
)
2625 char *token
= strtok(NULL
, w_space
);
2630 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2632 else if (!strcasecmp(token
, "warn"))
2638 #define free_tristate free_int
2641 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2643 while (head
!= NULL
) {
2644 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2646 head
->flags
.icase
? " -i" : null_string
,
2648 (int) head
->min
/ 60,
2649 (int) (100.0 * head
->pct
+ 0.5),
2650 (int) head
->max
/ 60);
2652 if (head
->max_stale
>= 0)
2653 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2655 if (head
->flags
.refresh_ims
)
2656 storeAppendPrintf(entry
, " refresh-ims");
2658 if (head
->flags
.store_stale
)
2659 storeAppendPrintf(entry
, " store-stale");
2661 #if USE_HTTP_VIOLATIONS
2663 if (head
->flags
.override_expire
)
2664 storeAppendPrintf(entry
, " override-expire");
2666 if (head
->flags
.override_lastmod
)
2667 storeAppendPrintf(entry
, " override-lastmod");
2669 if (head
->flags
.reload_into_ims
)
2670 storeAppendPrintf(entry
, " reload-into-ims");
2672 if (head
->flags
.ignore_reload
)
2673 storeAppendPrintf(entry
, " ignore-reload");
2675 if (head
->flags
.ignore_no_cache
)
2676 storeAppendPrintf(entry
, " ignore-no-cache");
2678 if (head
->flags
.ignore_no_store
)
2679 storeAppendPrintf(entry
, " ignore-no-store");
2681 if (head
->flags
.ignore_must_revalidate
)
2682 storeAppendPrintf(entry
, " ignore-must-revalidate");
2684 if (head
->flags
.ignore_private
)
2685 storeAppendPrintf(entry
, " ignore-private");
2687 if (head
->flags
.ignore_auth
)
2688 storeAppendPrintf(entry
, " ignore-auth");
2692 storeAppendPrintf(entry
, "\n");
2699 parse_refreshpattern(refresh_t
** head
)
2706 int refresh_ims
= 0;
2707 int store_stale
= 0;
2710 #if USE_HTTP_VIOLATIONS
2712 int override_expire
= 0;
2713 int override_lastmod
= 0;
2714 int reload_into_ims
= 0;
2715 int ignore_reload
= 0;
2716 int ignore_no_cache
= 0;
2717 int ignore_no_store
= 0;
2718 int ignore_must_revalidate
= 0;
2719 int ignore_private
= 0;
2720 int ignore_auth
= 0;
2727 int flags
= REG_EXTENDED
| REG_NOSUB
;
2729 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2734 if (strcmp(token
, "-i") == 0) {
2736 token
= strtok(NULL
, w_space
);
2737 } else if (strcmp(token
, "+i") == 0) {
2738 flags
&= ~REG_ICASE
;
2739 token
= strtok(NULL
, w_space
);
2742 if (token
== NULL
) {
2747 pattern
= xstrdup(token
);
2749 i
= GetInteger(); /* token: min */
2751 /* catch negative and insanely huge values close to 32-bit wrap */
2753 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2756 if (i
> 60*24*365) {
2757 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2761 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2763 i
= GetInteger(); /* token: pct */
2765 pct
= (double) i
/ 100.0;
2767 i
= GetInteger(); /* token: max */
2769 /* catch negative and insanely huge values close to 32-bit wrap */
2771 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2774 if (i
> 60*24*365) {
2775 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2779 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2782 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2783 if (!strcmp(token
, "refresh-ims")) {
2785 } else if (!strcmp(token
, "store-stale")) {
2787 } else if (!strncmp(token
, "max-stale=", 10)) {
2788 max_stale
= atoi(token
+ 10);
2789 #if USE_HTTP_VIOLATIONS
2791 } else if (!strcmp(token
, "override-expire"))
2792 override_expire
= 1;
2793 else if (!strcmp(token
, "override-lastmod"))
2794 override_lastmod
= 1;
2795 else if (!strcmp(token
, "ignore-no-cache"))
2796 ignore_no_cache
= 1;
2797 else if (!strcmp(token
, "ignore-no-store"))
2798 ignore_no_store
= 1;
2799 else if (!strcmp(token
, "ignore-must-revalidate"))
2800 ignore_must_revalidate
= 1;
2801 else if (!strcmp(token
, "ignore-private"))
2803 else if (!strcmp(token
, "ignore-auth"))
2805 else if (!strcmp(token
, "reload-into-ims")) {
2806 reload_into_ims
= 1;
2807 refresh_nocache_hack
= 1;
2808 /* tell client_side.c that this is used */
2809 } else if (!strcmp(token
, "ignore-reload")) {
2811 refresh_nocache_hack
= 1;
2812 /* tell client_side.c that this is used */
2816 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2819 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2821 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2822 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2823 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2827 pct
= pct
< 0.0 ? 0.0 : pct
;
2828 max
= max
< 0 ? 0 : max
;
2829 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2830 t
->pattern
= (char *) xstrdup(pattern
);
2831 t
->compiled_pattern
= comp
;
2836 if (flags
& REG_ICASE
)
2840 t
->flags
.refresh_ims
= 1;
2843 t
->flags
.store_stale
= 1;
2845 t
->max_stale
= max_stale
;
2847 #if USE_HTTP_VIOLATIONS
2849 if (override_expire
)
2850 t
->flags
.override_expire
= 1;
2852 if (override_lastmod
)
2853 t
->flags
.override_lastmod
= 1;
2855 if (reload_into_ims
)
2856 t
->flags
.reload_into_ims
= 1;
2859 t
->flags
.ignore_reload
= 1;
2861 if (ignore_no_cache
)
2862 t
->flags
.ignore_no_cache
= 1;
2864 if (ignore_no_store
)
2865 t
->flags
.ignore_no_store
= 1;
2867 if (ignore_must_revalidate
)
2868 t
->flags
.ignore_must_revalidate
= 1;
2871 t
->flags
.ignore_private
= 1;
2874 t
->flags
.ignore_auth
= 1;
2881 head
= &(*head
)->next
;
2889 free_refreshpattern(refresh_t
** head
)
2893 while ((t
= *head
) != NULL
) {
2895 safe_free(t
->pattern
);
2896 regfree(&t
->compiled_pattern
);
2900 #if USE_HTTP_VIOLATIONS
2901 refresh_nocache_hack
= 0;
2907 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2910 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2914 parse_string(char **var
)
2916 char *token
= strtok(NULL
, w_space
);
2922 *var
= xstrdup(token
);
2926 ConfigParser::ParseString(char **var
)
2932 ConfigParser::ParseString(String
*var
)
2934 char *token
= strtok(NULL
, w_space
);
2943 free_string(char **var
)
2949 parse_eol(char *volatile *var
)
2956 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2964 while (*token
&& xisspace(*token
))
2972 *var
= xstrdup((char *) token
);
2975 #define dump_eol dump_string
2976 #define free_eol free_string
2979 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2981 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2985 parse_time_t(time_t * var
)
2988 parseTimeLine(&tval
, T_SECOND_STR
, false);
2989 *var
= static_cast<time_t>(tval
/1000);
2993 free_time_t(time_t * var
)
3000 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3003 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3005 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3009 parse_time_msec(time_msec_t
* var
)
3011 parseTimeLine(var
, T_SECOND_STR
, true);
3015 free_time_msec(time_msec_t
* var
)
3023 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3025 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3030 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3032 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3037 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3039 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3045 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3047 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3052 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3054 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3058 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3060 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3065 parse_size_t(size_t * var
)
3074 parse_b_size_t(size_t * var
)
3076 parseBytesLine(var
, B_BYTES_STR
);
3081 parse_b_ssize_t(ssize_t
* var
)
3083 parseBytesLineSigned(var
, B_BYTES_STR
);
3089 parse_kb_size_t(size_t * var
)
3091 parseBytesLine(var
, B_KBYTES_STR
);
3096 parse_b_int64_t(int64_t * var
)
3098 parseBytesLine64(var
, B_BYTES_STR
);
3102 parse_kb_int64_t(int64_t * var
)
3104 parseBytesLine64(var
, B_KBYTES_STR
);
3108 free_size_t(size_t * var
)
3115 free_ssize_t(ssize_t
* var
)
3122 free_b_int64_t(int64_t * var
)
3127 #define free_b_size_t free_size_t
3128 #define free_b_ssize_t free_ssize_t
3129 #define free_kb_size_t free_size_t
3130 #define free_mb_size_t free_size_t
3131 #define free_gb_size_t free_size_t
3132 #define free_kb_int64_t free_b_int64_t
3135 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3137 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3141 free_u_short(unsigned short * u
)
3147 parse_u_short(unsigned short * var
)
3149 ConfigParser::ParseUShort(var
);
3153 ConfigParser::ParseUShort(unsigned short *var
)
3159 ConfigParser::ParseBool(bool *var
)
3161 int i
= GetInteger();
3172 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3174 while (list
!= NULL
) {
3175 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3181 ConfigParser::ParseWordList(wordlist
** list
)
3183 parse_wordlist(list
);
3187 parse_wordlist(wordlist
** list
)
3190 char *t
= strtok(NULL
, "");
3192 while ((token
= strwordtok(NULL
, &t
)))
3193 wordlistAdd(list
, token
);
3196 #if 0 /* now unused */
3198 check_null_wordlist(wordlist
* w
)
3205 check_null_acl_access(acl_access
* a
)
3210 #define free_wordlist wordlistDestroy
3212 #define free_uri_whitespace free_int
3215 parse_uri_whitespace(int *var
)
3217 char *token
= strtok(NULL
, w_space
);
3222 if (!strcasecmp(token
, "strip"))
3223 *var
= URI_WHITESPACE_STRIP
;
3224 else if (!strcasecmp(token
, "deny"))
3225 *var
= URI_WHITESPACE_DENY
;
3226 else if (!strcasecmp(token
, "allow"))
3227 *var
= URI_WHITESPACE_ALLOW
;
3228 else if (!strcasecmp(token
, "encode"))
3229 *var
= URI_WHITESPACE_ENCODE
;
3230 else if (!strcasecmp(token
, "chop"))
3231 *var
= URI_WHITESPACE_CHOP
;
3237 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3241 if (var
== URI_WHITESPACE_ALLOW
)
3243 else if (var
== URI_WHITESPACE_ENCODE
)
3245 else if (var
== URI_WHITESPACE_CHOP
)
3247 else if (var
== URI_WHITESPACE_DENY
)
3252 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3256 free_removalpolicy(RemovalPolicySettings
** settings
)
3261 free_string(&(*settings
)->type
);
3263 free_wordlist(&(*settings
)->args
);
3271 parse_removalpolicy(RemovalPolicySettings
** settings
)
3274 free_removalpolicy(settings
);
3276 *settings
= new RemovalPolicySettings
;
3278 parse_string(&(*settings
)->type
);
3280 parse_wordlist(&(*settings
)->args
);
3284 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3287 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3288 args
= settings
->args
;
3291 storeAppendPrintf(entry
, " %s", args
->key
);
3295 storeAppendPrintf(entry
, "\n");
3299 free_YesNoNone(YesNoNone
*)
3301 // do nothing: no explicit cleanup is required
3305 parse_YesNoNone(YesNoNone
*option
)
3308 parse_onoff(&value
);
3309 option
->configure(value
> 0);
3313 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3315 if (option
.configured())
3316 dump_onoff(entry
, name
, option
? 1 : 0);
3320 free_memcachemode(SquidConfig
* config
)
3326 parse_memcachemode(SquidConfig
* config
)
3328 char *token
= strtok(NULL
, w_space
);
3332 if (strcmp(token
, "always") == 0) {
3333 Config
.onoff
.memory_cache_first
= 1;
3334 Config
.onoff
.memory_cache_disk
= 1;
3335 } else if (strcmp(token
, "disk") == 0) {
3336 Config
.onoff
.memory_cache_first
= 0;
3337 Config
.onoff
.memory_cache_disk
= 1;
3338 } else if (strncmp(token
, "net", 3) == 0) {
3339 Config
.onoff
.memory_cache_first
= 1;
3340 Config
.onoff
.memory_cache_disk
= 0;
3341 } else if (strcmp(token
, "never") == 0) {
3342 Config
.onoff
.memory_cache_first
= 0;
3343 Config
.onoff
.memory_cache_disk
= 0;
3349 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3351 storeAppendPrintf(entry
, "%s ", name
);
3352 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3353 storeAppendPrintf(entry
, "always");
3354 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3355 storeAppendPrintf(entry
, "disk");
3356 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3357 storeAppendPrintf(entry
, "network");
3358 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3359 storeAppendPrintf(entry
, "none");
3360 storeAppendPrintf(entry
, "\n");
3363 #include "cf_parser.cci"
3366 parseNeighborType(const char *s
)
3368 if (!strcasecmp(s
, "parent"))
3371 if (!strcasecmp(s
, "neighbor"))
3372 return PEER_SIBLING
;
3374 if (!strcasecmp(s
, "neighbour"))
3375 return PEER_SIBLING
;
3377 if (!strcasecmp(s
, "sibling"))
3378 return PEER_SIBLING
;
3380 if (!strcasecmp(s
, "multicast"))
3381 return PEER_MULTICAST
;
3383 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3385 return PEER_SIBLING
;
3390 parse_IpAddress_list(Ip::Address_list
** head
)
3393 Ip::Address_list
*s
;
3396 while ((token
= strtok(NULL
, w_space
))) {
3397 if (GetHostWithPort(token
, &ipa
)) {
3400 head
= &(*head
)->next
;
3402 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3412 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3414 char ntoabuf
[MAX_IPSTRLEN
];
3417 storeAppendPrintf(e
, "%s %s\n",
3419 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3425 free_IpAddress_list(Ip::Address_list
** head
)
3427 if (*head
) delete *head
;
3431 #if CURRENTLY_UNUSED
3432 /* This code was previously used by http_port. Left as it really should
3433 * be used by icp_port and htcp_port
3436 check_null_IpAddress_list(const Ip::Address_list
* s
)
3441 #endif /* CURRENTLY_UNUSED */
3442 #endif /* USE_WCCPv2 */
3445 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3448 unsigned short port
= 0;
3452 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3453 s
->name
= xstrdup(token
);
3454 s
->connection_auth_disabled
= false;
3456 if (*token
== '[') {
3459 t
= strchr(host
, ']');
3461 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing ']' on IPv6 address: " << token
);
3467 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port in: " << token
);
3470 if (!Ip::EnableIpv6
) {
3471 debugs(3, DBG_CRITICAL
, "FATAL: " << s
->protocol
<< "_port: IPv6 is not available.");
3474 port
= xatos(t
+ 1);
3475 } else if ((t
= strchr(token
, ':'))) {
3480 port
= xatos(t
+ 1);
3482 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3484 debugs(3, 3, s
->protocol
<< "_port: found Listen on Port: " << port
);
3486 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port: " << token
);
3490 if (port
== 0 && host
!= NULL
) {
3491 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: Port cannot be 0: " << token
);
3498 if (!Ip::EnableIpv6
)
3500 debugs(3, 3, s
->protocol
<< "_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3501 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3503 if (!Ip::EnableIpv6
)
3505 debugs(3, 3, s
->protocol
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3506 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3507 /* dont use ipcache */
3508 s
->defaultsite
= xstrdup(host
);
3510 if (!Ip::EnableIpv6
)
3512 debugs(3, 3, s
->protocol
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3514 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: failed to resolve Host/IP: " << host
);
3520 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3524 if (strcmp(token
, "accel") == 0) {
3525 if (s
->intercepted
|| s
->spoof_client_ip
) {
3526 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3529 s
->accel
= s
->vhost
= 1;
3530 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3531 if (s
->accel
|| s
->spoof_client_ip
) {
3532 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3536 Ip::Interceptor
.StartInterception();
3537 /* Log information regarding the port modes under interception. */
3538 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3539 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3541 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3543 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3544 if ( !s
->s
.SetIPv4() ) {
3545 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s
->s
);
3548 } else if (strcmp(token
, "tproxy") == 0) {
3549 if (s
->intercepted
|| s
->accel
) {
3550 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3553 s
->spoof_client_ip
= 1;
3554 Ip::Interceptor
.StartTransparency();
3555 /* Log information regarding the port modes under transparency. */
3556 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3557 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3559 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3560 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3564 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3566 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3569 safe_free(s
->defaultsite
);
3570 s
->defaultsite
= xstrdup(token
+ 12);
3571 } else if (strcmp(token
, "vhost") == 0) {
3573 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3575 s
->accel
= s
->vhost
= 1;
3576 } else if (strcmp(token
, "no-vhost") == 0) {
3578 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3581 } else if (strcmp(token
, "vport") == 0) {
3583 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3587 } else if (strncmp(token
, "vport=", 6) == 0) {
3589 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3592 s
->vport
= xatos(token
+ 6);
3593 } else if (strncmp(token
, "protocol=", 9) == 0) {
3595 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3598 s
->protocol
= xstrdup(token
+ 9);
3599 } else if (strcmp(token
, "allow-direct") == 0) {
3601 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3604 s
->allow_direct
= 1;
3605 } else if (strcmp(token
, "act-as-origin") == 0) {
3607 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3610 } else if (strcmp(token
, "ignore-cc") == 0) {
3611 #if !USE_HTTP_VIOLATIONS
3613 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3618 } else if (strncmp(token
, "name=", 5) == 0) {
3620 s
->name
= xstrdup(token
+ 5);
3621 } else if (strcmp(token
, "no-connection-auth") == 0) {
3622 s
->connection_auth_disabled
= true;
3623 } else if (strcmp(token
, "connection-auth=off") == 0) {
3624 s
->connection_auth_disabled
= true;
3625 } else if (strcmp(token
, "connection-auth") == 0) {
3626 s
->connection_auth_disabled
= false;
3627 } else if (strcmp(token
, "connection-auth=on") == 0) {
3628 s
->connection_auth_disabled
= false;
3629 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3630 if (!strcasecmp(token
+ 23, "off"))
3631 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3632 else if (!strcasecmp(token
+ 23, "transparent"))
3633 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3634 else if (!strcasecmp(token
+ 23, "always"))
3635 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: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3643 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3644 s
->tcp_keepalive
.enabled
= 1;
3645 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3646 char *t
= token
+ 13;
3647 s
->tcp_keepalive
.enabled
= 1;
3648 s
->tcp_keepalive
.idle
= atoi(t
);
3652 s
->tcp_keepalive
.interval
= atoi(t
);
3657 s
->tcp_keepalive
.timeout
= atoi(t
);
3661 } else if (strcasecmp(token
, "sslBump") == 0) {
3662 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3663 "in http_port. Use 'ssl-bump' instead.");
3664 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3665 } else if (strcmp(token
, "ssl-bump") == 0) {
3666 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3667 } else if (strncmp(token
, "cert=", 5) == 0) {
3669 s
->cert
= xstrdup(token
+ 5);
3670 } else if (strncmp(token
, "key=", 4) == 0) {
3672 s
->key
= xstrdup(token
+ 4);
3673 } else if (strncmp(token
, "version=", 8) == 0) {
3674 s
->version
= xatoi(token
+ 8);
3675 if (s
->version
< 1 || s
->version
> 4)
3677 } else if (strncmp(token
, "options=", 8) == 0) {
3678 safe_free(s
->options
);
3679 s
->options
= xstrdup(token
+ 8);
3680 } else if (strncmp(token
, "cipher=", 7) == 0) {
3681 safe_free(s
->cipher
);
3682 s
->cipher
= xstrdup(token
+ 7);
3683 } else if (strncmp(token
, "clientca=", 9) == 0) {
3684 safe_free(s
->clientca
);
3685 s
->clientca
= xstrdup(token
+ 9);
3686 } else if (strncmp(token
, "cafile=", 7) == 0) {
3687 safe_free(s
->cafile
);
3688 s
->cafile
= xstrdup(token
+ 7);
3689 } else if (strncmp(token
, "capath=", 7) == 0) {
3690 safe_free(s
->capath
);
3691 s
->capath
= xstrdup(token
+ 7);
3692 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3693 safe_free(s
->crlfile
);
3694 s
->crlfile
= xstrdup(token
+ 8);
3695 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3696 safe_free(s
->dhfile
);
3697 s
->dhfile
= xstrdup(token
+ 9);
3698 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3699 safe_free(s
->sslflags
);
3700 s
->sslflags
= xstrdup(token
+ 9);
3701 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3702 safe_free(s
->sslContextSessionId
);
3703 s
->sslContextSessionId
= xstrdup(token
+ 11);
3704 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3705 s
->generateHostCertificates
= true;
3706 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3707 s
->generateHostCertificates
= true;
3708 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3709 s
->generateHostCertificates
= false;
3710 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3711 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3719 add_http_port(char *portspec
)
3721 AnyP::PortCfg
*s
= new AnyP::PortCfg("http_port");
3722 parsePortSpecification(s
, portspec
);
3723 // we may need to merge better if the above returns a list with clones
3724 assert(s
->next
== NULL
);
3725 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3726 cbdataReferenceDone(Config
.Sockaddr
.http
);
3727 Config
.Sockaddr
.http
= cbdataReference(s
);
3731 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3733 const char *protocol
= NULL
;
3734 if (strcmp(optionName
, "http_port") == 0 ||
3735 strcmp(optionName
, "ascii_port") == 0)
3737 else if (strcmp(optionName
, "https_port") == 0)
3744 char *token
= strtok(NULL
, w_space
);
3751 AnyP::PortCfg
*s
= new AnyP::PortCfg(protocol
);
3752 parsePortSpecification(s
, token
);
3754 /* parse options ... */
3755 while ((token
= strtok(NULL
, w_space
))) {
3756 parse_port_option(s
, token
);
3760 if (strcasecmp(protocol
, "https") == 0) {
3761 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3762 const bool hijacked
= s
->spoof_client_ip
|| s
->intercepted
;
3763 if (s
->sslBump
&& !hijacked
) {
3764 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3767 if (hijacked
&& !s
->sslBump
) {
3768 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3774 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3775 // clone the port options from *s to *(s->next)
3776 s
->next
= cbdataReference(s
->clone());
3777 s
->next
->s
.SetIPv4();
3778 debugs(3, 3, protocol
<< "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3782 head
= &(*head
)->next
;
3784 *head
= cbdataReference(s
);
3788 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3790 char buf
[MAX_IPSTRLEN
];
3792 storeAppendPrintf(e
, "%s %s",
3794 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3796 // MODES and specific sub-options.
3798 storeAppendPrintf(e
, " intercept");
3800 else if (s
->spoof_client_ip
)
3801 storeAppendPrintf(e
, " tproxy");
3803 else if (s
->accel
) {
3804 storeAppendPrintf(e
, " accel");
3807 storeAppendPrintf(e
, " vhost");
3810 storeAppendPrintf(e
, " vport");
3811 else if (s
->vport
> 0)
3812 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3815 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3817 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3818 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3820 if (s
->allow_direct
)
3821 storeAppendPrintf(e
, " allow-direct");
3824 storeAppendPrintf(e
, " ignore-cc");
3828 // Generic independent options
3831 storeAppendPrintf(e
, " name=%s", s
->name
);
3833 #if USE_HTTP_VIOLATIONS
3834 if (!s
->accel
&& s
->ignore_cc
)
3835 storeAppendPrintf(e
, " ignore-cc");
3838 if (s
->connection_auth_disabled
)
3839 storeAppendPrintf(e
, " connection-auth=off");
3841 storeAppendPrintf(e
, " connection-auth=on");
3843 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3846 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3849 pmtu
= "transparent";
3851 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3854 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3855 storeAppendPrintf(e
, " ipv4");
3857 if (s
->tcp_keepalive
.enabled
) {
3858 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3859 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3861 storeAppendPrintf(e
, " tcpkeepalive");
3867 storeAppendPrintf(e
, " ssl-bump");
3870 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3873 storeAppendPrintf(e
, " key=%s", s
->key
);
3876 storeAppendPrintf(e
, " version=%d", s
->version
);
3879 storeAppendPrintf(e
, " options=%s", s
->options
);
3882 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3885 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3888 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3891 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3894 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3897 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3899 if (s
->sslContextSessionId
)
3900 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3902 if (s
->generateHostCertificates
)
3903 storeAppendPrintf(e
, " generate-host-certificates");
3905 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3906 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3911 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3914 dump_generic_port(e
, n
, s
);
3915 storeAppendPrintf(e
, "\n");
3921 free_PortCfg(AnyP::PortCfg
** head
)
3925 while ((s
= *head
) != NULL
) {
3927 cbdataReferenceDone(s
);
3932 configFreeMemory(void)
3936 SSL_CTX_free(Config
.ssl_client
.sslContext
);
3941 requirePathnameExists(const char *name
, const char *path
)
3945 char pathbuf
[BUFSIZ
];
3946 assert(path
!= NULL
);
3948 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3949 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3953 if (stat(path
, &sb
) < 0) {
3954 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
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
, xstrerror());
3967 return ConfigParser::strtokFile();
3970 #include "AccessLogEntry.h"
3973 parse_access_log(customlog
** logs
)
3975 const char *filename
, *logdef_name
;
3977 customlog
*cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3979 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3984 if (strcmp(filename
, "none") == 0) {
3985 cl
->type
= Log::Format::CLF_NONE
;
3986 aclParseAclList(LegacyParser
, &cl
->aclList
);
3988 logs
= &(*logs
)->next
;
3993 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3994 logdef_name
= "squid";
3996 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3998 cl
->filename
= xstrdup(filename
);
4000 /* look for the definition pointer corresponding to this name */
4001 Format::Format
*lf
= Log::TheConfig
.logformats
;
4003 while (lf
!= NULL
) {
4004 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4006 if (strcmp(lf
->name
, logdef_name
) == 0)
4013 cl
->type
= Log::Format::CLF_CUSTOM
;
4015 } else if (strcmp(logdef_name
, "auto") == 0) {
4016 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4017 cl
->type
= Log::Format::CLF_SQUID
;
4018 } else if (strcmp(logdef_name
, "squid") == 0) {
4019 cl
->type
= Log::Format::CLF_SQUID
;
4020 } else if (strcmp(logdef_name
, "common") == 0) {
4021 cl
->type
= Log::Format::CLF_COMMON
;
4022 } else if (strcmp(logdef_name
, "combined") == 0) {
4023 cl
->type
= Log::Format::CLF_COMBINED
;
4025 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4026 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4028 } else if (strcmp(logdef_name
, "useragent") == 0) {
4029 cl
->type
= Log::Format::CLF_USERAGENT
;
4030 } else if (strcmp(logdef_name
, "referrer") == 0) {
4031 cl
->type
= Log::Format::CLF_REFERER
;
4033 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4038 aclParseAclList(LegacyParser
, &cl
->aclList
);
4041 logs
= &(*logs
)->next
;
4047 check_null_access_log(customlog
*customlog_definitions
)
4049 return customlog_definitions
== NULL
;
4053 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
4057 for (log
= logs
; log
; log
= log
->next
) {
4058 storeAppendPrintf(entry
, "%s ", name
);
4060 switch (log
->type
) {
4062 case Log::Format::CLF_CUSTOM
:
4063 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4066 case Log::Format::CLF_NONE
:
4067 storeAppendPrintf(entry
, "none");
4070 case Log::Format::CLF_SQUID
:
4071 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4074 case Log::Format::CLF_COMBINED
:
4075 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4078 case Log::Format::CLF_COMMON
:
4079 storeAppendPrintf(entry
, "%s common", log
->filename
);
4083 case Log::Format::CLF_ICAP_SQUID
:
4084 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4087 case Log::Format::CLF_USERAGENT
:
4088 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4091 case Log::Format::CLF_REFERER
:
4092 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4095 case Log::Format::CLF_UNKNOWN
:
4100 dump_acl_list(entry
, log
->aclList
);
4102 storeAppendPrintf(entry
, "\n");
4107 free_access_log(customlog
** definitions
)
4109 while (*definitions
) {
4110 customlog
*log
= *definitions
;
4111 *definitions
= log
->next
;
4113 log
->logFormat
= NULL
;
4114 log
->type
= Log::Format::CLF_UNKNOWN
;
4117 aclDestroyAclList(&log
->aclList
);
4119 safe_free(log
->filename
);
4125 /// parses list of integers form name=N1,N2,N3,...
4127 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4129 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4130 data
+= name
.size();
4135 if (!StringToInt(data
, value
, &data
, 10))
4137 list
.push_back(value
);
4138 if (*data
== '\0' || *data
!= ',')
4143 return data
&& *data
== '\0';
4147 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4149 #if !HAVE_CPU_AFFINITY
4150 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4151 "support, do not set 'cpu_affinity_map'");
4153 #endif /* HAVE_CPU_AFFINITY */
4155 if (!*cpuAffinityMap
)
4156 *cpuAffinityMap
= new CpuAffinityMap
;
4158 const char *const pToken
= strtok(NULL
, w_space
);
4159 const char *const cToken
= strtok(NULL
, w_space
);
4160 Vector
<int> processes
, cores
;
4161 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4162 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4163 "in 'cpu_affinity_map'");
4165 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4166 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4167 "'cpu_affinity_map'");
4169 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4170 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4171 "process_numbers and cores lists differ in length or " <<
4172 "contain numbers <= 0");
4178 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4180 if (cpuAffinityMap
) {
4181 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4182 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4183 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4184 cpuAffinityMap
->processes()[i
]);
4186 storeAppendPrintf(entry
, " cores=");
4187 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4188 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4189 cpuAffinityMap
->cores()[i
]);
4191 storeAppendPrintf(entry
, "\n");
4196 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4198 delete *cpuAffinityMap
;
4199 *cpuAffinityMap
= NULL
;
4205 parse_adaptation_service_set_type()
4207 Adaptation::Config::ParseServiceSet();
4211 parse_adaptation_service_chain_type()
4213 Adaptation::Config::ParseServiceChain();
4217 parse_adaptation_access_type()
4219 Adaptation::Config::ParseAccess(LegacyParser
);
4223 parse_adaptation_meta_type(Adaptation::Config::MetaHeaders
*)
4225 Adaptation::Config::ParseMetaHeader(LegacyParser
);
4229 dump_adaptation_meta_type(StoreEntry
*entry
, const char *name
, Adaptation::Config::MetaHeaders
&)
4231 Adaptation::Config::DumpMetaHeader(entry
, name
);
4235 free_adaptation_meta_type(Adaptation::Config::MetaHeaders
*)
4237 // Nothing to do, it is released inside Adaptation::Config::freeService()
4239 #endif /* USE_ADAPTATION */
4244 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4246 cfg
->parseService();
4250 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4256 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4258 cfg
.dumpService(entry
, name
);
4262 parse_icap_class_type()
4264 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4265 "Use 'adaptation_service_set' instead");
4266 Adaptation::Config::ParseServiceSet();
4270 parse_icap_access_type()
4272 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4273 "Use 'adaptation_access' instead");
4274 Adaptation::Config::ParseAccess(LegacyParser
);
4282 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4284 cfg
->parseService();
4288 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4294 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4296 cfg
.dumpService(entry
, name
);
4299 #endif /* USE_ECAP */
4302 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4307 cfg
->service_failure_limit
= GetInteger();
4309 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4312 if (strcmp(token
,"in") != 0) {
4313 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4317 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4321 d
= static_cast<time_t> (xatoi(token
));
4323 m
= static_cast<time_t> (1);
4327 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4328 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4330 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4333 cfg
->oldest_service_failure
= (m
* d
);
4336 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4338 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4339 if (cfg
.oldest_service_failure
> 0) {
4340 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4342 storeAppendPrintf(entry
, "\n");
4345 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4347 cfg
->oldest_service_failure
= 0;
4348 cfg
->service_failure_limit
= 0;
4353 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4356 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4357 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4363 if ( char *s
= strchr(al
, '{')) {
4364 *s
= '\0'; // terminate the al string
4376 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4377 ca
->alg
= Ssl::algSetValidAfter
;
4378 ca
->param
= strdup("on");
4379 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4380 ca
->alg
= Ssl::algSetValidBefore
;
4381 ca
->param
= strdup("on");
4382 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4383 ca
->alg
= Ssl::algSetCommonName
;
4385 if (strlen(param
) > 64) {
4386 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4390 ca
->param
= strdup(param
);
4393 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4398 aclParseAclList(LegacyParser
, &ca
->aclList
);
4401 cert_adapt
= &(*cert_adapt
)->next
;
4406 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4408 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4409 storeAppendPrintf(entry
, "%s ", name
);
4410 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4412 dump_acl_list(entry
, ca
->aclList
);
4413 storeAppendPrintf(entry
, "\n");
4417 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4419 while (*cert_adapt
) {
4420 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4421 *cert_adapt
= ca
->next
;
4422 safe_free(ca
->param
);
4425 aclDestroyAclList(&ca
->aclList
);
4431 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4434 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4435 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4440 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4441 cs
->alg
= Ssl::algSignTrusted
;
4442 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4443 cs
->alg
= Ssl::algSignUntrusted
;
4444 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4445 cs
->alg
= Ssl::algSignSelf
;
4447 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4452 aclParseAclList(LegacyParser
, &cs
->aclList
);
4455 cert_sign
= &(*cert_sign
)->next
;
4460 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4462 sslproxy_cert_sign
*cs
;
4463 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4464 storeAppendPrintf(entry
, "%s ", name
);
4465 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4467 dump_acl_list(entry
, cs
->aclList
);
4468 storeAppendPrintf(entry
, "\n");
4472 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4474 while (*cert_sign
) {
4475 sslproxy_cert_sign
*cs
= *cert_sign
;
4476 *cert_sign
= cs
->next
;
4479 aclDestroyAclList(&cs
->aclList
);
4485 class sslBumpCfgRr
: public ::RegisteredRunner
4488 static Ssl::BumpMode lastDeprecatedRule
;
4489 /* RegisteredRunner API */
4490 virtual void run(const RunnerRegistry
&);
4493 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4495 RunnerRegistrationEntry(rrFinalizeConfig
, sslBumpCfgRr
);
4497 void sslBumpCfgRr::run(const RunnerRegistry
&r
)
4499 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4500 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4501 static char buf
[1024];
4502 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4503 strcpy(buf
, "ssl_bump deny all");
4504 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4505 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4506 "must not use implicit rules. Update your ssl_bump rules.");
4508 strcpy(buf
, "ssl_bump allow all");
4509 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4510 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4511 "inferior to the newer server-first bumping mode. New ssl_bump"
4512 " configurations must not use implicit rules. Update your ssl_bump rules.");
4518 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4520 typedef const char *BumpCfgStyle
;
4521 BumpCfgStyle bcsNone
= NULL
;
4522 BumpCfgStyle bcsNew
= "new client/server-first/none";
4523 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4524 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4525 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4527 if ((bm
= strtok(NULL
, w_space
)) == NULL
) {
4532 // if this is the first rule proccessed
4533 if (*ssl_bump
== NULL
) {
4534 bumpCfgStyleLast
= bcsNone
;
4535 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4538 acl_access
*A
= new acl_access
;
4539 A
->allow
= allow_t(ACCESS_ALLOWED
);
4541 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4542 A
->allow
.kind
= Ssl::bumpClientFirst
;
4543 bumpCfgStyleNow
= bcsNew
;
4544 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4545 A
->allow
.kind
= Ssl::bumpServerFirst
;
4546 bumpCfgStyleNow
= bcsNew
;
4547 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4548 A
->allow
.kind
= Ssl::bumpNone
;
4549 bumpCfgStyleNow
= bcsNew
;
4550 } else if (strcmp(bm
, "allow") == 0) {
4551 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4552 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4553 "is usually inferior to the newer server-first "
4554 "bumping mode. Update your ssl_bump rules.");
4555 A
->allow
.kind
= Ssl::bumpClientFirst
;
4556 bumpCfgStyleNow
= bcsOld
;
4557 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4558 } else if (strcmp(bm
, "deny") == 0) {
4559 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4560 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4561 "your ssl_bump rules.");
4562 A
->allow
.kind
= Ssl::bumpNone
;
4563 bumpCfgStyleNow
= bcsOld
;
4564 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4566 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4571 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4572 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4573 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4578 bumpCfgStyleLast
= bumpCfgStyleNow
;
4580 aclParseAclList(LegacyParser
, &A
->aclList
);
4583 for (B
= *ssl_bump
, T
= ssl_bump
; B
; T
= &B
->next
, B
= B
->next
);
4587 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4590 for (sb
= ssl_bump
; sb
!= NULL
; sb
= sb
->next
) {
4591 storeAppendPrintf(entry
, "%s ", name
);
4592 storeAppendPrintf(entry
, "%s ", Ssl::bumpMode(sb
->allow
.kind
));
4594 dump_acl_list(entry
, sb
->aclList
);
4595 storeAppendPrintf(entry
, "\n");
4599 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4601 free_acl_access(ssl_bump
);
4606 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4611 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4612 storeAppendPrintf(entry
, "%s ", hwa
->fieldName
.c_str());
4613 storeAppendPrintf(entry
, "%s ", hwa
->fieldValue
.c_str());
4615 dump_acl_list(entry
, hwa
->aclList
);
4616 storeAppendPrintf(entry
, "\n");
4620 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4624 *headers
= new HeaderWithAclList
;
4626 if ((fn
= strtok(NULL
, w_space
)) == NULL
) {
4632 hwa
.fieldId
= httpHeaderIdByNameDef(fn
, strlen(fn
));
4633 if (hwa
.fieldId
== HDR_BAD_HDR
)
4634 hwa
.fieldId
= HDR_OTHER
;
4638 ConfigParser::ParseQuotedString(&buf
, &wasQuoted
);
4639 hwa
.fieldValue
= buf
.termedBuf();
4640 hwa
.quoted
= wasQuoted
;
4642 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4643 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4647 hwa
.valueFormat
= nlf
;
4649 aclParseAclList(LegacyParser
, &hwa
.aclList
);
4650 (*headers
)->push_back(hwa
);
4653 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4658 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4660 aclDestroyAclList(&hwa
->aclList
);
4662 if (hwa
->valueFormat
) {
4663 delete hwa
->valueFormat
;
4664 hwa
->valueFormat
= NULL
;