4 * DEBUG: section 03 Configuration File Parsing
5 * AUTHOR: Harvest Derived
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
37 #include "acl/Gadgets.h"
38 #include "acl/MethodData.h"
39 #include "anyp/PortCfg.h"
40 #include "base/RunnersRegistry.h"
42 #include "ConfigParser.h"
43 #include "CpuAffinityMap.h"
44 #include "DiskIO/DiskIOModule.h"
45 #include "eui/Config.h"
46 #include "ExternalACL.h"
47 #include "format/Format.h"
49 #include "HttpHeaderTools.h"
50 #include "HttpRequestMethod.h"
51 #include "ident/Config.h"
52 #include "ip/Intercept.h"
53 #include "ip/QosConfig.h"
56 #include "log/Config.h"
59 #include "mgr/Registration.h"
61 #include "PeerDigest.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
*);
152 static const char *const T_MILLISECOND_STR
= "millisecond";
153 static const char *const T_SECOND_STR
= "second";
154 static const char *const T_MINUTE_STR
= "minute";
155 static const char *const T_HOUR_STR
= "hour";
156 static const char *const T_DAY_STR
= "day";
157 static const char *const T_WEEK_STR
= "week";
158 static const char *const T_FORTNIGHT_STR
= "fortnight";
159 static const char *const T_MONTH_STR
= "month";
160 static const char *const T_YEAR_STR
= "year";
161 static const char *const T_DECADE_STR
= "decade";
163 static const char *const B_BYTES_STR
= "bytes";
164 static const char *const B_KBYTES_STR
= "KB";
165 static const char *const B_MBYTES_STR
= "MB";
166 static const char *const B_GBYTES_STR
= "GB";
168 static const char *const list_sep
= ", \t\n\r";
170 static void parse_access_log(customlog
** customlog_definitions
);
171 static int check_null_access_log(customlog
*customlog_definitions
);
172 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
173 static void free_access_log(customlog
** definitions
);
175 static void update_maxobjsize(void);
176 static void configDoConfigure(void);
177 static void parse_refreshpattern(refresh_t
**);
178 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
179 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
180 static void parse_u_short(unsigned short * var
);
181 static void parse_string(char **);
182 static void default_all(void);
183 static void defaults_if_none(void);
184 static void defaults_postscriptum(void);
185 static int parse_line(char *);
186 static void parse_obsolete(const char *);
187 static void parseBytesLine(size_t * bptr
, const char *units
);
189 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
192 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
194 static size_t parseBytesUnits(const char *unit
);
195 static void free_all(void);
196 void requirePathnameExists(const char *name
, const char *path
);
197 static OBJH dump_config
;
198 #if USE_HTTP_VIOLATIONS
199 static void free_HeaderManglers(HeaderManglers
**pm
);
200 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
201 static void parse_http_header_access(HeaderManglers
**manglers
);
202 #define free_http_header_access free_HeaderManglers
203 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
204 static void parse_http_header_replace(HeaderManglers
**manglers
);
205 #define free_http_header_replace free_HeaderManglers
207 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
208 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
209 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
210 static void parse_denyinfo(acl_deny_info_list
** var
);
211 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
212 static void free_denyinfo(acl_deny_info_list
** var
);
215 static void parse_IpAddress_list(Ip::Address_list
**);
216 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
217 static void free_IpAddress_list(Ip::Address_list
**);
219 static int check_null_IpAddress_list(const Ip::Address_list
*);
220 #endif /* CURRENTLY_UNUSED */
221 #endif /* USE_WCCPv2 */
223 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
224 #define parse_PortCfg(l) parsePortCfg((l), token)
225 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
226 static void free_PortCfg(AnyP::PortCfg
**);
229 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
230 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
231 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
232 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
233 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
234 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
235 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
236 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
237 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
240 static void parse_b_size_t(size_t * var
);
241 static void parse_b_int64_t(int64_t * var
);
243 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
245 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
246 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
247 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
249 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
252 * LegacyParser is a parser for legacy code that uses the global
253 * approach. This is static so that it is only exposed to cache_cf.
254 * Other modules needing access to a ConfigParser should have it
255 * provided to them in their parserFOO methods.
257 static ConfigParser LegacyParser
= ConfigParser();
262 LegacyParser
.destruct();
266 update_maxobjsize(void)
271 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
272 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
274 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
276 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
278 store_maxobjsize
= ms
;
282 SetConfigFilename(char const *file_name
, bool is_pipe
)
284 cfg_filename
= file_name
;
289 cfg_filename
= file_name
+ 1;
290 else if ((token
= strrchr(cfg_filename
, '/')))
291 cfg_filename
= token
+ 1;
295 skip_ws(const char* s
)
304 parseManyConfigFiles(char* files
, int depth
)
307 char* saveptr
= NULL
;
312 memset(&globbuf
, 0, sizeof(globbuf
));
313 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
314 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
315 fatalf("Unable to find configuration file: %s: %s",
319 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
320 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
324 char* file
= strwordtok(files
, &saveptr
);
325 while (file
!= NULL
) {
326 error_count
+= parseOneConfigFile(file
, depth
);
327 file
= strwordtok(NULL
, &saveptr
);
329 #endif /* HAVE_GLOB */
334 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
337 assert(newSubstr
!= NULL
);
339 unsigned newSubstrLen
= strlen(newSubstr
);
340 if (newSubstrLen
> substrLen
)
341 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
343 // move tail part including zero
344 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
345 // copy new substring in place
346 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
352 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
354 assert(line
!= NULL
);
355 assert(macroName
!= NULL
);
356 assert(substStr
!= NULL
);
357 unsigned macroNameLen
= strlen(macroName
);
358 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
359 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
363 ProcessMacros(char*& line
, int& len
)
365 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
366 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
370 trim_trailing_ws(char* str
)
373 unsigned i
= strlen(str
);
374 while ((i
> 0) && xisspace(str
[i
- 1]))
380 FindStatement(const char* line
, const char* statement
)
382 assert(line
!= NULL
);
383 assert(statement
!= NULL
);
385 const char* str
= skip_ws(line
);
386 unsigned len
= strlen(statement
);
387 if (strncmp(str
, statement
, len
) == 0) {
391 else if (xisspace(*str
))
399 StrToInt(const char* str
, long& number
)
404 number
= strtol(str
, &end
, 0);
406 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
410 EvalBoolExpr(const char* expr
)
412 assert(expr
!= NULL
);
413 if (strcmp(expr
, "true") == 0) {
415 } else if (strcmp(expr
, "false") == 0) {
417 } else if (const char* equation
= strchr(expr
, '=')) {
418 const char* rvalue
= skip_ws(equation
+ 1);
419 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
420 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
421 trim_trailing_ws(lvalue
);
424 if (!StrToInt(lvalue
, number1
))
425 fatalf("String is not a integer number: '%s'\n", lvalue
);
427 if (!StrToInt(rvalue
, number2
))
428 fatalf("String is not a integer number: '%s'\n", rvalue
);
431 return number1
== number2
;
433 fatalf("Unable to evaluate expression '%s'\n", expr
);
434 return false; // this place cannot be reached
438 parseOneConfigFile(const char *file_name
, unsigned int depth
)
441 const char *orig_cfg_filename
= cfg_filename
;
442 const int orig_config_lineno
= config_lineno
;
444 char *tmp_line
= NULL
;
445 int tmp_line_len
= 0;
449 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
451 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
455 if (file_name
[0] == '!' || file_name
[0] == '|') {
456 fp
= popen(file_name
+ 1, "r");
459 fp
= fopen(file_name
, "r");
463 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
466 setmode(fileno(fp
), O_TEXT
);
469 SetConfigFilename(file_name
, bool(is_pipe
));
471 memset(config_input_line
, '\0', BUFSIZ
);
475 Vector
<bool> if_states
;
476 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
479 if ((token
= strchr(config_input_line
, '\n')))
482 if ((token
= strchr(config_input_line
, '\r')))
485 // strip any prefix whitespace off the line.
486 const char *p
= skip_ws(config_input_line
);
487 if (config_input_line
!= p
)
488 memmove(config_input_line
, p
, strlen(p
)+1);
490 if (strncmp(config_input_line
, "#line ", 6) == 0) {
491 static char new_file_name
[1024];
493 static char new_lineno
;
494 token
= config_input_line
+ 6;
495 new_lineno
= strtol(token
, &file
, 0) - 1;
498 continue; /* Not a valid #line directive, may be a comment */
500 while (*file
&& xisspace((unsigned char) *file
))
505 continue; /* Not a valid #line directive, may be a comment */
507 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
509 if ((token
= strchr(new_file_name
, '"')))
512 cfg_filename
= new_file_name
;
515 config_lineno
= new_lineno
;
518 if (config_input_line
[0] == '#')
521 if (config_input_line
[0] == '\0')
524 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
526 size_t append_len
= strlen(append
);
528 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
530 strcpy(tmp_line
+ tmp_line_len
, append
);
532 tmp_line_len
+= append_len
;
534 if (tmp_line
[tmp_line_len
-1] == '\\') {
535 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
536 tmp_line
[--tmp_line_len
] = '\0';
540 trim_trailing_ws(tmp_line
);
541 ProcessMacros(tmp_line
, tmp_line_len
);
542 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
544 if (const char* expr
= FindStatement(tmp_line
, "if")) {
545 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
546 } else if (FindStatement(tmp_line
, "endif")) {
547 if (!if_states
.empty())
548 if_states
.pop_back(); // remove last if-statement meaning
550 fatalf("'endif' without 'if'\n");
551 } else if (FindStatement(tmp_line
, "else")) {
552 if (!if_states
.empty())
553 if_states
.back() = !if_states
.back();
555 fatalf("'else' without 'if'\n");
556 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
557 /* Handle includes here */
558 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
559 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
560 } else if (!parse_line(tmp_line
)) {
561 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
570 if (!if_states
.empty())
571 fatalf("if-statement without 'endif'\n");
574 int ret
= pclose(fp
);
577 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
582 cfg_filename
= orig_cfg_filename
;
583 config_lineno
= orig_config_lineno
;
589 parseConfigFile(const char *file_name
)
597 ACLMethodData::ThePurgeCount
= 0;
600 err_count
= parseOneConfigFile(file_name
, 0);
604 defaults_postscriptum();
607 * We must call configDoConfigure() before leave_suid() because
608 * configDoConfigure() is where we turn username strings into
613 if (!Config
.chroot_dir
) {
615 setUmask(Config
.umask
);
616 _db_init(Debug::cache_log
, Debug::debugOptions
);
620 if (opt_send_signal
== -1) {
621 Mgr::RegisterAction("config",
622 "Current Squid Configuration",
631 configDoConfigure(void)
633 memset(&Config2
, '\0', sizeof(SquidConfig2
));
634 /* init memory as early as possible */
638 if (Config
.cacheSwap
.swapDirs
== NULL
) {
639 /* Memory-only cache probably in effect. */
640 /* turn off the cache rebuild delays... */
641 StoreController::store_dirs_rebuilding
= 0;
642 } else if (InDaemonMode()) { // no diskers in non-daemon mode
643 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
644 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
645 if (sd
->needsDiskStrand())
646 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
650 if (Debug::rotateNumber
< 0) {
651 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
654 #if SIZEOF_OFF_T <= 4
655 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
656 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
657 Config
.Store
.maxObjectSize
= 0x7FFF0000;
660 if (0 == Store::Root().maxSize())
661 /* people might want a zero-sized cache on purpose */
663 else if (Store::Root().maxSize() < Config
.memMaxSize
)
664 /* This is bogus. folk with NULL caches will want this */
665 debugs(3, DBG_CRITICAL
, "WARNING cache_mem is larger than total disk cache space!");
667 if (Config
.Announce
.period
> 0) {
668 Config
.onoff
.announce
= 1;
669 } else if (Config
.Announce
.period
< 1) {
670 Config
.Announce
.period
= 86400 * 365; /* one year */
671 Config
.onoff
.announce
= 0;
674 if (Config
.onoff
.httpd_suppress_version_string
)
675 visible_appname_string
= (char *)appname_string
;
677 visible_appname_string
= (char const *)APP_FULLNAME
;
680 if (Config
.dnsChildren
.n_max
< 1)
681 fatal("No DNS helpers allocated");
684 if (Config
.Program
.redirect
) {
685 if (Config
.redirectChildren
.n_max
< 1) {
686 Config
.redirectChildren
.n_max
= 0;
687 wordlistDestroy(&Config
.Program
.redirect
);
691 if (Config
.appendDomain
)
692 if (*Config
.appendDomain
!= '.')
693 fatal("append_domain must begin with a '.'");
695 if (Config
.errHtmlText
== NULL
)
696 Config
.errHtmlText
= xstrdup(null_string
);
698 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
699 if (Config
.max_filedescriptors
> 0) {
700 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
702 #elif USE_SELECT || USE_SELECT_WIN32
703 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
704 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
710 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
712 visible_appname_string
);
715 * the extra space is for loop detection in client_side.c -- we search
716 * for substrings in the Via header.
718 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
720 visible_appname_string
);
722 /* Use visible_hostname as default surrogate_id */
723 if (!Config
.Accel
.surrogate_id
) {
724 const char *t
= getMyHostname();
725 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
728 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
729 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
731 if (Config
.appendDomain
)
732 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
734 Config
.appendDomainLen
= 0;
736 if (Config
.connect_retries
> 10) {
737 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
738 Config
.connect_retries
= 10;
741 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
743 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
747 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
749 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
750 if (Config
.Program
.redirect
)
751 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
753 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
755 if (Config
.errorDirectory
)
756 requirePathnameExists("Error Directory", Config
.errorDirectory
);
758 #if USE_HTTP_VIOLATIONS
763 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
764 if (!R
->flags
.override_expire
)
767 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
772 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
773 if (!R
->flags
.override_lastmod
)
776 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
781 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
782 if (!R
->flags
.reload_into_ims
)
785 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
790 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
791 if (!R
->flags
.ignore_reload
)
794 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
799 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
800 if (!R
->flags
.ignore_no_cache
)
803 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
808 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
809 if (!R
->flags
.ignore_no_store
)
812 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
817 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
818 if (!R
->flags
.ignore_must_revalidate
)
820 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
824 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
825 if (!R
->flags
.ignore_private
)
828 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
833 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
834 if (!R
->flags
.ignore_auth
)
837 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
844 #if !USE_HTTP_VIOLATIONS
845 Config
.onoff
.via
= 1;
848 if (!Config
.onoff
.via
)
849 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
853 // we enable runtime PURGE checks if there is at least one PURGE method ACL
854 // TODO: replace with a dedicated "purge" ACL option?
855 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
857 Config2
.onoff
.mangle_request_headers
= (Config
.request_header_access
!= NULL
);
859 if (geteuid() == 0) {
860 if (NULL
!= Config
.effectiveUser
) {
862 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
866 * Andres Kroonmaa <andre@online.ee>:
867 * Some getpwnam() implementations (Solaris?) require
868 * an available FD < 256 for opening a FILE* to the
871 * This should be safe at startup, but might still fail
872 * during reconfigure.
874 fatalf("getpwnam failed to find userid for effective user '%s'",
875 Config
.effectiveUser
);
879 Config2
.effectiveUserID
= pwd
->pw_uid
;
881 Config2
.effectiveGroupID
= pwd
->pw_gid
;
885 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
887 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
888 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
896 Config2
.effectiveUserID
= geteuid();
897 Config2
.effectiveGroupID
= getegid();
900 if (NULL
!= Config
.effectiveGroup
) {
902 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
905 fatalf("getgrnam failed to find groupid for effective group '%s'",
906 Config
.effectiveGroup
);
910 Config2
.effectiveGroupID
= grp
->gr_gid
;
913 HttpRequestMethod::Configure(Config
);
916 debugs(3, DBG_IMPORTANT
, "Initializing https proxy context");
918 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
);
920 for (peer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
922 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " SSL context");
923 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
927 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
931 debugs(3, DBG_IMPORTANT
, "Initializing http_port " << s
->s
<< " SSL context");
932 s
->configureSslServerContext();
935 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
936 debugs(3, DBG_IMPORTANT
, "Initializing https_port " << s
->s
<< " SSL context");
937 s
->configureSslServerContext();
942 // prevent infinite fetch loops in the request parser
943 // due to buffer full but not enough data recived to finish parse
944 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
945 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
946 " Change client_request_buffer_max or request_header_max_size limits.",
947 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
952 * disable client side request pipelining. There is a race with
953 * Negotiate and NTLM when the client sends a second request on an
954 * connection before the authenticate challenge is sent. With
955 * pipelining OFF, the client may fail to authenticate, but squid's
956 * state will be preserved.
958 if (Config
.onoff
.pipeline_prefetch
) {
959 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
960 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
961 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
962 debugs(3, DBG_IMPORTANT
, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
963 Config
.onoff
.pipeline_prefetch
= 0;
969 /** Parse a line containing an obsolete directive.
970 * To upgrade it where possible instead of just "Bungled config" for
971 * directives which cannot be marked as simply aliases of the some name.
972 * For example if the parameter order and content has changed.
973 * Or if the directive has been completely removed.
976 parse_obsolete(const char *name
)
978 // Directives which have been radically changed rather than removed
979 if (!strcmp(name
, "url_rewrite_concurrency")) {
982 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
983 Config
.redirectChildren
.concurrency
= cval
;
987 /* Parse a time specification from the config file. Store the
988 * result in 'tptr', after converting it to 'units' */
990 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
997 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
1000 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1005 m
= u
; /* default to 'units' if none specified */
1009 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1010 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1011 config_input_line
<< "', assuming " <<
1012 d
<< " " << units
);
1013 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1016 *tptr
= static_cast<time_msec_t
>(m
* d
);
1020 parseTimeUnits(const char *unit
, bool allowMsec
)
1022 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1025 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1028 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1031 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1034 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1035 return 86400 * 1000;
1037 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1038 return 86400 * 7 * 1000;
1040 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1041 return 86400 * 14 * 1000;
1043 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1044 return static_cast<uint64_t>(86400) * 30 * 1000;
1046 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1047 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1049 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1050 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1052 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1058 parseBytesLine64(int64_t * bptr
, const char *units
)
1065 if ((u
= parseBytesUnits(units
)) == 0) {
1070 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1075 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1082 m
= u
; /* default to 'units' if none specified */
1086 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1087 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1088 config_input_line
<< "', assuming " <<
1089 d
<< " " << units
);
1090 else if ((m
= parseBytesUnits(token
)) == 0) {
1095 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1097 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1102 parseBytesLine(size_t * bptr
, const char *units
)
1109 if ((u
= parseBytesUnits(units
)) == 0) {
1114 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1119 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1120 *bptr
= static_cast<size_t>(-1);
1126 m
= u
; /* default to 'units' if none specified */
1130 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1131 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1132 config_input_line
<< "', assuming " <<
1133 d
<< " " << units
);
1134 else if ((m
= parseBytesUnits(token
)) == 0) {
1139 *bptr
= static_cast<size_t>(m
* d
/ u
);
1141 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1147 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1154 if ((u
= parseBytesUnits(units
)) == 0) {
1159 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1164 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1171 m
= u
; /* default to 'units' if none specified */
1175 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1176 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1177 config_input_line
<< "', assuming " <<
1178 d
<< " " << units
);
1179 else if ((m
= parseBytesUnits(token
)) == 0) {
1184 *bptr
= static_cast<size_t>(m
* d
/ u
);
1186 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1193 * Parse bytes from a string.
1194 * Similar to the parseBytesLine function but parses the string value instead of
1195 * the current token value.
1197 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1200 if ((u
= parseBytesUnits(units
)) == 0) {
1205 // Find number from string beginning.
1206 char const * number_begin
= value
;
1207 char const * number_end
= value
;
1209 while ((*number_end
>= '0' && *number_end
<= '9')) {
1214 number
.limitInit(number_begin
, number_end
- number_begin
);
1216 int d
= xatoi(number
.termedBuf());
1218 if ((m
= parseBytesUnits(number_end
)) == 0) {
1223 *bptr
= static_cast<size_t>(m
* d
/ u
);
1224 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1230 parseBytesUnits(const char *unit
)
1232 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1235 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1238 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1241 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1244 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1249 /*****************************************************************************
1251 *****************************************************************************/
1254 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1259 while (ae
!= NULL
) {
1260 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1261 storeAppendPrintf(entry
, "%s %s %s ",
1268 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1269 storeAppendPrintf(entry
, "%s ", v
->key
);
1273 storeAppendPrintf(entry
, "\n");
1274 wordlistDestroy(&w
);
1280 parse_acl(ACL
** ae
)
1282 ACL::ParseAclLine(LegacyParser
, ae
);
1292 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1296 for (l
= head
; l
; l
= l
->next
) {
1297 storeAppendPrintf(entry
, " %s%s",
1298 l
->op
? null_string
: "!",
1304 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1308 for (l
= head
; l
; l
= l
->next
) {
1309 storeAppendPrintf(entry
, "%s %s",
1311 l
->allow
? "Allow" : "Deny");
1312 dump_acl_list(entry
, l
->aclList
);
1313 storeAppendPrintf(entry
, "\n");
1318 parse_acl_access(acl_access
** head
)
1320 aclParseAccessLine(LegacyParser
, head
);
1324 free_acl_access(acl_access
** head
)
1326 aclDestroyAccessList(head
);
1330 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1332 char buf
[MAX_IPSTRLEN
];
1333 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1337 parse_address(Ip::Address
*addr
)
1339 char *token
= strtok(NULL
, w_space
);
1346 if (!strcmp(token
,"any_addr"))
1348 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1350 else if ( (*addr
= token
) ) // try parse numeric/IPA
1353 addr
->GetHostByName(token
); // dont use ipcache
1357 free_address(Ip::Address
*addr
)
1362 CBDATA_TYPE(acl_address
);
1365 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1367 char buf
[MAX_IPSTRLEN
];
1370 for (l
= head
; l
; l
= l
->next
) {
1371 if (!l
->addr
.IsAnyAddr())
1372 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1374 storeAppendPrintf(entry
, "%s autoselect", name
);
1376 dump_acl_list(entry
, l
->aclList
);
1378 storeAppendPrintf(entry
, "\n");
1383 freed_acl_address(void *data
)
1385 acl_address
*l
= static_cast<acl_address
*>(data
);
1386 aclDestroyAclList(&l
->aclList
);
1390 parse_acl_address(acl_address
** head
)
1393 acl_address
**tail
= head
; /* sane name below */
1394 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1395 l
= cbdataAlloc(acl_address
);
1396 parse_address(&l
->addr
);
1397 aclParseAclList(LegacyParser
, &l
->aclList
);
1400 tail
= &(*tail
)->next
;
1406 free_acl_address(acl_address
** head
)
1409 acl_address
*l
= *head
;
1415 CBDATA_TYPE(acl_tos
);
1418 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1422 for (l
= head
; l
; l
= l
->next
) {
1424 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1426 storeAppendPrintf(entry
, "%s none", name
);
1428 dump_acl_list(entry
, l
->aclList
);
1430 storeAppendPrintf(entry
, "\n");
1435 freed_acl_tos(void *data
)
1437 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1438 aclDestroyAclList(&l
->aclList
);
1442 parse_acl_tos(acl_tos
** head
)
1445 acl_tos
**tail
= head
; /* sane name below */
1446 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1447 char *token
= strtok(NULL
, w_space
);
1454 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1459 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1461 l
= cbdataAlloc(acl_tos
);
1463 l
->tos
= (tos_t
)tos
;
1465 aclParseAclList(LegacyParser
, &l
->aclList
);
1468 tail
= &(*tail
)->next
;
1474 free_acl_tos(acl_tos
** head
)
1484 #if SO_MARK && USE_LIBCAP
1486 CBDATA_TYPE(acl_nfmark
);
1489 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1493 for (l
= head
; l
; l
= l
->next
) {
1495 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1497 storeAppendPrintf(entry
, "%s none", name
);
1499 dump_acl_list(entry
, l
->aclList
);
1501 storeAppendPrintf(entry
, "\n");
1506 freed_acl_nfmark(void *data
)
1508 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1509 aclDestroyAclList(&l
->aclList
);
1513 parse_acl_nfmark(acl_nfmark
** head
)
1516 acl_nfmark
**tail
= head
; /* sane name below */
1518 char *token
= strtok(NULL
, w_space
);
1525 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1530 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1532 l
= cbdataAlloc(acl_nfmark
);
1536 aclParseAclList(LegacyParser
, &l
->aclList
);
1539 tail
= &(*tail
)->next
;
1545 free_acl_nfmark(acl_nfmark
** head
)
1548 acl_nfmark
*l
= *head
;
1554 #endif /* SO_MARK */
1556 CBDATA_TYPE(acl_size_t
);
1559 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1563 for (l
= head
; l
; l
= l
->next
) {
1565 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1567 storeAppendPrintf(entry
, "%s none", name
);
1569 dump_acl_list(entry
, l
->aclList
);
1571 storeAppendPrintf(entry
, "\n");
1576 freed_acl_b_size_t(void *data
)
1578 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1579 aclDestroyAclList(&l
->aclList
);
1583 parse_acl_b_size_t(acl_size_t
** head
)
1586 acl_size_t
**tail
= head
; /* sane name below */
1588 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1590 l
= cbdataAlloc(acl_size_t
);
1592 parse_b_int64_t(&l
->size
);
1594 aclParseAclList(LegacyParser
, &l
->aclList
);
1597 tail
= &(*tail
)->next
;
1603 free_acl_b_size_t(acl_size_t
** head
)
1606 acl_size_t
*l
= *head
;
1615 #include "DelayPools.h"
1616 #include "DelayConfig.h"
1617 /* do nothing - free_delay_pool_count is the magic free function.
1618 * this is why delay_pool_count isn't just marked TYPE: u_short
1620 #define free_delay_pool_class(X)
1621 #define free_delay_pool_access(X)
1622 #define free_delay_pool_rates(X)
1623 #define dump_delay_pool_class(X, Y, Z)
1624 #define dump_delay_pool_access(X, Y, Z)
1625 #define dump_delay_pool_rates(X, Y, Z)
1628 free_delay_pool_count(DelayConfig
* cfg
)
1630 cfg
->freePoolCount();
1634 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1636 cfg
.dumpPoolCount (entry
, name
);
1640 parse_delay_pool_count(DelayConfig
* cfg
)
1642 cfg
->parsePoolCount();
1646 parse_delay_pool_class(DelayConfig
* cfg
)
1648 cfg
->parsePoolClass();
1652 parse_delay_pool_rates(DelayConfig
* cfg
)
1654 cfg
->parsePoolRates();
1658 parse_delay_pool_access(DelayConfig
* cfg
)
1660 cfg
->parsePoolAccess(LegacyParser
);
1666 #include "ClientDelayConfig.h"
1667 /* do nothing - free_client_delay_pool_count is the magic free function.
1668 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1671 #define free_client_delay_pool_access(X)
1672 #define free_client_delay_pool_rates(X)
1673 #define dump_client_delay_pool_access(X, Y, Z)
1674 #define dump_client_delay_pool_rates(X, Y, Z)
1677 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1679 cfg
->freePoolCount();
1683 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1685 cfg
.dumpPoolCount (entry
, name
);
1689 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1691 cfg
->parsePoolCount();
1695 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1697 cfg
->parsePoolRates();
1701 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1703 cfg
->parsePoolAccess(LegacyParser
);
1707 #if USE_HTTP_VIOLATIONS
1709 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1712 manglers
->dumpAccess(entry
, name
);
1716 parse_http_header_access(HeaderManglers
**pm
)
1720 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1721 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1722 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1727 *pm
= new HeaderManglers
;
1728 HeaderManglers
*manglers
= *pm
;
1729 header_mangler
*mangler
= manglers
->track(t
);
1731 parse_acl_access(&mangler
->access_list
);
1735 free_HeaderManglers(HeaderManglers
**pm
)
1737 // we delete the entire http_header_* mangler configuration at once
1738 if (const HeaderManglers
*manglers
= *pm
) {
1745 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1748 manglers
->dumpReplacement(entry
, name
);
1752 parse_http_header_replace(HeaderManglers
**pm
)
1756 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1757 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1758 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1762 const char *value
= t
+ strlen(t
) + 1;
1765 *pm
= new HeaderManglers
;
1766 HeaderManglers
*manglers
= *pm
;
1767 manglers
->setReplacement(t
, value
);
1773 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1779 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1780 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1782 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1784 storeAppendPrintf(entry
, "\n");
1789 check_null_string(char *s
)
1796 parse_authparam(Auth::ConfigVector
* config
)
1801 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1804 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1807 /* find a configuration for the scheme in the currently parsed configs... */
1808 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1810 if (schemeCfg
== NULL
) {
1811 /* Create a configuration based on the scheme info */
1812 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1814 if (theScheme
== NULL
) {
1815 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1819 config
->push_back(theScheme
->createConfig());
1820 schemeCfg
= Auth::Config::Find(type_str
);
1821 if (schemeCfg
== NULL
) {
1822 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1827 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1831 free_authparam(Auth::ConfigVector
* cfg
)
1833 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1836 /* remove our pointers to the probably-dead sub-configs */
1837 while (cfg
->size()) {
1841 /* on reconfigure initialize new auth schemes for the new config. */
1842 if (reconfiguring
) {
1848 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1850 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1851 (*i
)->dump(entry
, name
, (*i
));
1853 #endif /* USE_AUTH */
1855 /* TODO: just return the object, the # is irrelevant */
1857 find_fstype(char *type
)
1859 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1860 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1867 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1871 RefCount
<SwapDir
> sd
;
1875 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1878 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1881 fs
= find_fstype(type_str
);
1886 /* reconfigure existing dir */
1888 for (i
= 0; i
< swap
->n_configured
; ++i
) {
1889 assert (swap
->swapDirs
[i
].getRaw());
1891 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1892 /* this is specific to on-fs Stores. The right
1893 * way to handle this is probably to have a mapping
1894 * from paths to stores, and have on-fs stores
1895 * register with that, and lookip in that in their
1896 * own setup logic. RBC 20041225. TODO.
1899 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1901 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().items
[fs
]->type()) != 0) {
1902 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1903 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1909 update_maxobjsize();
1916 if (swap
->n_configured
> 63) {
1917 /* 7 bits, signed */
1918 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1919 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1924 allocate_new_swapdir(swap
);
1926 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1928 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1930 /* parse the FS parameters and options */
1931 sd
->parse(swap
->n_configured
, path_str
);
1933 ++swap
->n_configured
;
1935 /* Update the max object size */
1936 update_maxobjsize();
1940 peer_type_str(const peer_t type
)
1942 const char * result
;
1954 case PEER_MULTICAST
:
1955 result
= "multicast";
1967 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1971 LOCAL_ARRAY(char, xname
, 128);
1974 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1981 dump_peer_options(entry
, p
);
1983 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1984 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1986 d
->do_ping
? null_string
: "!",
1991 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1992 dump_acl_access(entry
, xname
, p
->access
);
1995 for (t
= p
->typelist
; t
; t
= t
->next
) {
1996 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1998 peer_type_str(t
->type
),
2007 * utility function to prevent getservbyname() being called with a numeric value
2008 * on Windows at least it returns garage results.
2011 isUnsignedNumeric(const char *str
, size_t len
)
2013 if (len
< 1) return false;
2015 for (; len
>0 && *str
; ++str
, --len
) {
2016 if (! isdigit(*str
))
2023 \param proto 'tcp' or 'udp' for protocol
2024 \returns Port the named service is supposed to be listening on.
2026 static unsigned short
2027 GetService(const char *proto
)
2029 struct servent
*port
= NULL
;
2030 /** Parses a port number or service name from the squid.conf */
2031 char *token
= strtok(NULL
, w_space
);
2032 if (token
== NULL
) {
2034 return 0; /* NEVER REACHED */
2036 /** Returns either the service port number from /etc/services */
2037 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2038 port
= getservbyname(token
, proto
);
2040 return ntohs((unsigned short)port
->s_port
);
2042 /** Or a numeric translation of the config text. */
2043 return xatos(token
);
2047 \returns Port the named TCP service is supposed to be listening on.
2048 \copydoc GetService(const char *proto)
2050 inline unsigned short
2053 return GetService("tcp");
2057 \returns Port the named UDP service is supposed to be listening on.
2058 \copydoc GetService(const char *proto)
2060 inline unsigned short
2063 return GetService("udp");
2067 parse_peer(peer
** head
)
2071 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
2072 p
= cbdataAlloc(peer
);
2073 p
->http_port
= CACHE_HTTP_PORT
;
2074 p
->icp
.port
= CACHE_ICP_PORT
;
2077 p
->stats
.logged_state
= PEER_ALIVE
;
2079 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2082 p
->host
= xstrdup(token
);
2084 p
->name
= xstrdup(token
);
2086 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2089 p
->type
= parseNeighborType(token
);
2091 if (p
->type
== PEER_MULTICAST
) {
2092 p
->options
.no_digest
= 1;
2093 p
->options
.no_netdb_exchange
= 1;
2096 p
->http_port
= GetTcpService();
2101 p
->icp
.port
= GetUdpService();
2102 p
->connection_auth
= 2; /* auto */
2104 while ((token
= strtok(NULL
, w_space
))) {
2105 if (!strcasecmp(token
, "proxy-only")) {
2106 p
->options
.proxy_only
= 1;
2107 } else if (!strcasecmp(token
, "no-query")) {
2108 p
->options
.no_query
= 1;
2109 } else if (!strcasecmp(token
, "background-ping")) {
2110 p
->options
.background_ping
= 1;
2111 } else if (!strcasecmp(token
, "no-digest")) {
2112 p
->options
.no_digest
= 1;
2113 } else if (!strcasecmp(token
, "no-tproxy")) {
2114 p
->options
.no_tproxy
= 1;
2115 } else if (!strcasecmp(token
, "multicast-responder")) {
2116 p
->options
.mcast_responder
= 1;
2117 #if PEER_MULTICAST_SIBLINGS
2118 } else if (!strcasecmp(token
, "multicast-siblings")) {
2119 p
->options
.mcast_siblings
= 1;
2121 } else if (!strncasecmp(token
, "weight=", 7)) {
2122 p
->weight
= xatoi(token
+ 7);
2123 } else if (!strncasecmp(token
, "basetime=", 9)) {
2124 p
->basetime
= xatoi(token
+ 9);
2125 } else if (!strcasecmp(token
, "closest-only")) {
2126 p
->options
.closest_only
= 1;
2127 } else if (!strncasecmp(token
, "ttl=", 4)) {
2128 p
->mcast
.ttl
= xatoi(token
+ 4);
2130 if (p
->mcast
.ttl
< 0)
2133 if (p
->mcast
.ttl
> 128)
2135 } else if (!strcasecmp(token
, "default")) {
2136 p
->options
.default_parent
= 1;
2137 } else if (!strcasecmp(token
, "round-robin")) {
2138 p
->options
.roundrobin
= 1;
2139 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2140 p
->options
.weighted_roundrobin
= 1;
2142 } else if (!strcasecmp(token
, "htcp")) {
2143 p
->options
.htcp
= 1;
2144 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2145 /* Note: The htcp- form is deprecated, replaced by htcp= */
2146 p
->options
.htcp
= 1;
2147 char *tmp
= xstrdup(token
+5);
2148 char *mode
, *nextmode
;
2149 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2150 nextmode
= strchr(mode
, ',');
2155 if (!strcasecmp(mode
, "no-clr")) {
2156 if (p
->options
.htcp_only_clr
)
2157 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2158 p
->options
.htcp_no_clr
= 1;
2159 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2160 p
->options
.htcp_no_purge_clr
= 1;
2161 } else if (!strcasecmp(mode
, "only-clr")) {
2162 if (p
->options
.htcp_no_clr
)
2163 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2164 p
->options
.htcp_only_clr
= 1;
2165 } else if (!strcasecmp(mode
, "forward-clr")) {
2166 p
->options
.htcp_forward_clr
= 1;
2167 } else if (!strcasecmp(mode
, "oldsquid")) {
2168 p
->options
.htcp_oldsquid
= 1;
2170 fatalf("invalid HTCP mode '%s'", mode
);
2175 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2176 p
->options
.no_netdb_exchange
= 1;
2178 } else if (!strcasecmp(token
, "carp")) {
2179 if (p
->type
!= PEER_PARENT
)
2180 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2182 p
->options
.carp
= 1;
2183 } else if (!strncasecmp(token
, "carp-key=", 9)) {
2184 if (p
->options
.carp
!= 1)
2185 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2186 p
->options
.carp_key
.set
=1;
2187 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2188 for (; key
; key
= nextkey
) {
2189 nextkey
=strchr(key
,',');
2190 if (nextkey
) ++nextkey
; // skip the comma, any
2191 if (0==strncasecmp(key
,"scheme",6)) {
2192 p
->options
.carp_key
.scheme
=1;
2193 } else if (0==strncasecmp(key
,"host",4)) {
2194 p
->options
.carp_key
.host
=1;
2195 } else if (0==strncasecmp(key
,"port",4)) {
2196 p
->options
.carp_key
.port
=1;
2197 } else if (0==strncasecmp(key
,"path",4)) {
2198 p
->options
.carp_key
.path
=1;
2199 } else if (0==strncasecmp(key
,"params",6)) {
2200 p
->options
.carp_key
.params
=1;
2202 fatalf("invalid carp-key '%s'",key
);
2205 } else if (!strcasecmp(token
, "userhash")) {
2207 if (p
->type
!= PEER_PARENT
)
2208 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2210 p
->options
.userhash
= 1;
2212 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2214 } else if (!strcasecmp(token
, "sourcehash")) {
2215 if (p
->type
!= PEER_PARENT
)
2216 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2218 p
->options
.sourcehash
= 1;
2220 } else if (!strcasecmp(token
, "no-delay")) {
2222 p
->options
.no_delay
= 1;
2224 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2226 } else if (!strncasecmp(token
, "login=", 6)) {
2227 p
->login
= xstrdup(token
+ 6);
2228 rfc1738_unescape(p
->login
);
2229 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2230 p
->connect_timeout
= xatoi(token
+ 16);
2231 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2232 p
->connect_fail_limit
= xatoi(token
+ 19);
2233 #if USE_CACHE_DIGESTS
2234 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2235 p
->digest_url
= xstrdup(token
+ 11);
2238 } else if (!strcasecmp(token
, "allow-miss")) {
2239 p
->options
.allow_miss
= 1;
2240 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2241 p
->max_conn
= xatoi(token
+ 9);
2242 } else if (!strcasecmp(token
, "originserver")) {
2243 p
->options
.originserver
= 1;
2244 } else if (!strncasecmp(token
, "name=", 5)) {
2248 p
->name
= xstrdup(token
+ 5);
2249 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2250 safe_free(p
->domain
);
2253 p
->domain
= xstrdup(token
+ 13);
2257 } else if (strcmp(token
, "ssl") == 0) {
2259 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2260 safe_free(p
->sslcert
);
2261 p
->sslcert
= xstrdup(token
+ 8);
2262 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2263 safe_free(p
->sslkey
);
2264 p
->sslkey
= xstrdup(token
+ 7);
2265 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2266 p
->sslversion
= atoi(token
+ 11);
2267 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2268 safe_free(p
->ssloptions
);
2269 p
->ssloptions
= xstrdup(token
+ 11);
2270 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2271 safe_free(p
->sslcipher
);
2272 p
->sslcipher
= xstrdup(token
+ 10);
2273 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2274 safe_free(p
->sslcafile
);
2275 p
->sslcafile
= xstrdup(token
+ 10);
2276 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2277 safe_free(p
->sslcapath
);
2278 p
->sslcapath
= xstrdup(token
+ 10);
2279 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2280 safe_free(p
->sslcrlfile
);
2281 p
->sslcapath
= xstrdup(token
+ 10);
2282 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2283 safe_free(p
->sslflags
);
2284 p
->sslflags
= xstrdup(token
+ 9);
2285 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2286 safe_free(p
->ssldomain
);
2287 p
->ssldomain
= xstrdup(token
+ 10);
2290 } else if (strcmp(token
, "front-end-https") == 0) {
2291 p
->front_end_https
= 1;
2292 } else if (strcmp(token
, "front-end-https=on") == 0) {
2293 p
->front_end_https
= 1;
2294 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2295 p
->front_end_https
= 2;
2296 } else if (strcmp(token
, "connection-auth=off") == 0) {
2297 p
->connection_auth
= 0;
2298 } else if (strcmp(token
, "connection-auth") == 0) {
2299 p
->connection_auth
= 1;
2300 } else if (strcmp(token
, "connection-auth=on") == 0) {
2301 p
->connection_auth
= 1;
2302 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2303 p
->connection_auth
= 2;
2305 debugs(3, DBG_CRITICAL
, "parse_peer: token='" << token
<< "'");
2310 if (peerFindByName(p
->name
))
2311 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2316 if (p
->connect_fail_limit
< 1)
2317 p
->connect_fail_limit
= 10;
2319 p
->icp
.version
= ICP_VERSION_CURRENT
;
2321 p
->testing_now
= false;
2323 #if USE_CACHE_DIGESTS
2325 if (!p
->options
.no_digest
) {
2326 /* XXX This looks odd.. who has the original pointer
2329 PeerDigest
*pd
= peerDigestCreate(p
);
2330 p
->digest
= cbdataReference(pd
);
2335 p
->index
= ++Config
.npeers
;
2337 while (*head
!= NULL
)
2338 head
= &(*head
)->next
;
2346 free_peer(peer
** P
)
2350 while ((p
= *P
) != NULL
) {
2352 #if USE_CACHE_DIGESTS
2354 cbdataReferenceDone(p
->digest
);
2364 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2368 while (list
!= NULL
) {
2369 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2370 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2372 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2374 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2375 storeAppendPrintf(entry
, " %s", w
->key
);
2378 storeAppendPrintf(entry
, "\n");
2384 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2386 char *passwd
= NULL
;
2387 wordlist
*actions
= NULL
;
2389 cachemgr_passwd
**P
;
2390 parse_string(&passwd
);
2391 parse_wordlist(&actions
);
2392 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2394 p
->actions
= actions
;
2396 for (P
= head
; *P
; P
= &(*P
)->next
) {
2398 * See if any of the actions from this line already have a
2399 * password from previous lines. The password checking
2400 * routines in cache_manager.c take the the password from
2401 * the first cachemgr_passwd struct that contains the
2402 * requested action. Thus, we should warn users who might
2403 * think they can have two passwords for the same action.
2408 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2409 for (u
= actions
; u
; u
= u
->next
) {
2410 if (strcmp(w
->key
, u
->key
))
2413 debugs(0, DBG_CRITICAL
, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2422 free_cachemgrpasswd(cachemgr_passwd
** head
)
2426 while ((p
= *head
) != NULL
) {
2429 wordlistDestroy(&p
->actions
);
2435 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2439 while (var
!= NULL
) {
2440 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2442 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2443 storeAppendPrintf(entry
, " %s", a
->name
);
2445 storeAppendPrintf(entry
, "\n");
2452 parse_denyinfo(acl_deny_info_list
** var
)
2454 aclParseDenyInfoLine(var
);
2458 free_denyinfo(acl_deny_info_list
** list
)
2460 acl_deny_info_list
*a
= NULL
;
2461 acl_deny_info_list
*a_next
= NULL
;
2462 acl_name_list
*l
= NULL
;
2463 acl_name_list
*l_next
= NULL
;
2465 for (a
= *list
; a
; a
= a_next
) {
2466 for (l
= a
->acl_list
; l
; l
= l_next
) {
2468 memFree(l
, MEM_ACL_NAME_LIST
);
2473 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2481 parse_peer_access(void)
2486 if (!(host
= strtok(NULL
, w_space
)))
2489 if ((p
= peerFindByName(host
)) == NULL
) {
2490 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2494 aclParseAccessLine(LegacyParser
, &p
->access
);
2498 parse_hostdomain(void)
2501 char *domain
= NULL
;
2503 if (!(host
= strtok(NULL
, w_space
)))
2506 while ((domain
= strtok(NULL
, list_sep
))) {
2507 domain_ping
*l
= NULL
;
2508 domain_ping
**L
= NULL
;
2511 if ((p
= peerFindByName(host
)) == NULL
) {
2512 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2516 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2519 if (*domain
== '!') { /* check for !.edu */
2524 l
->domain
= xstrdup(domain
);
2526 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2532 parse_hostdomaintype(void)
2536 char *domain
= NULL
;
2538 if (!(host
= strtok(NULL
, w_space
)))
2541 if (!(type
= strtok(NULL
, w_space
)))
2544 while ((domain
= strtok(NULL
, list_sep
))) {
2545 domain_type
*l
= NULL
;
2546 domain_type
**L
= NULL
;
2549 if ((p
= peerFindByName(host
)) == NULL
) {
2550 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2554 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2555 l
->type
= parseNeighborType(type
);
2556 l
->domain
= xstrdup(domain
);
2558 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2564 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2566 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2584 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2586 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2590 parse_onoff(int *var
)
2592 char *token
= strtok(NULL
, w_space
);
2597 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2603 #define free_onoff free_int
2606 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2617 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2621 parse_tristate(int *var
)
2623 char *token
= strtok(NULL
, w_space
);
2628 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2630 else if (!strcasecmp(token
, "warn"))
2636 #define free_tristate free_int
2639 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2641 while (head
!= NULL
) {
2642 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2644 head
->flags
.icase
? " -i" : null_string
,
2646 (int) head
->min
/ 60,
2647 (int) (100.0 * head
->pct
+ 0.5),
2648 (int) head
->max
/ 60);
2650 if (head
->max_stale
>= 0)
2651 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2653 if (head
->flags
.refresh_ims
)
2654 storeAppendPrintf(entry
, " refresh-ims");
2656 if (head
->flags
.store_stale
)
2657 storeAppendPrintf(entry
, " store-stale");
2659 #if USE_HTTP_VIOLATIONS
2661 if (head
->flags
.override_expire
)
2662 storeAppendPrintf(entry
, " override-expire");
2664 if (head
->flags
.override_lastmod
)
2665 storeAppendPrintf(entry
, " override-lastmod");
2667 if (head
->flags
.reload_into_ims
)
2668 storeAppendPrintf(entry
, " reload-into-ims");
2670 if (head
->flags
.ignore_reload
)
2671 storeAppendPrintf(entry
, " ignore-reload");
2673 if (head
->flags
.ignore_no_cache
)
2674 storeAppendPrintf(entry
, " ignore-no-cache");
2676 if (head
->flags
.ignore_no_store
)
2677 storeAppendPrintf(entry
, " ignore-no-store");
2679 if (head
->flags
.ignore_must_revalidate
)
2680 storeAppendPrintf(entry
, " ignore-must-revalidate");
2682 if (head
->flags
.ignore_private
)
2683 storeAppendPrintf(entry
, " ignore-private");
2685 if (head
->flags
.ignore_auth
)
2686 storeAppendPrintf(entry
, " ignore-auth");
2690 storeAppendPrintf(entry
, "\n");
2697 parse_refreshpattern(refresh_t
** head
)
2704 int refresh_ims
= 0;
2705 int store_stale
= 0;
2708 #if USE_HTTP_VIOLATIONS
2710 int override_expire
= 0;
2711 int override_lastmod
= 0;
2712 int reload_into_ims
= 0;
2713 int ignore_reload
= 0;
2714 int ignore_no_cache
= 0;
2715 int ignore_no_store
= 0;
2716 int ignore_must_revalidate
= 0;
2717 int ignore_private
= 0;
2718 int ignore_auth
= 0;
2725 int flags
= REG_EXTENDED
| REG_NOSUB
;
2727 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2732 if (strcmp(token
, "-i") == 0) {
2734 token
= strtok(NULL
, w_space
);
2735 } else if (strcmp(token
, "+i") == 0) {
2736 flags
&= ~REG_ICASE
;
2737 token
= strtok(NULL
, w_space
);
2740 if (token
== NULL
) {
2745 pattern
= xstrdup(token
);
2747 i
= GetInteger(); /* token: min */
2749 /* catch negative and insanely huge values close to 32-bit wrap */
2751 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2754 if (i
> 60*24*365) {
2755 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2759 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2761 i
= GetInteger(); /* token: pct */
2763 pct
= (double) i
/ 100.0;
2765 i
= GetInteger(); /* token: max */
2767 /* catch negative and insanely huge values close to 32-bit wrap */
2769 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2772 if (i
> 60*24*365) {
2773 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2777 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2780 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2781 if (!strcmp(token
, "refresh-ims")) {
2783 } else if (!strcmp(token
, "store-stale")) {
2785 } else if (!strncmp(token
, "max-stale=", 10)) {
2786 max_stale
= atoi(token
+ 10);
2787 #if USE_HTTP_VIOLATIONS
2789 } else if (!strcmp(token
, "override-expire"))
2790 override_expire
= 1;
2791 else if (!strcmp(token
, "override-lastmod"))
2792 override_lastmod
= 1;
2793 else if (!strcmp(token
, "ignore-no-cache"))
2794 ignore_no_cache
= 1;
2795 else if (!strcmp(token
, "ignore-no-store"))
2796 ignore_no_store
= 1;
2797 else if (!strcmp(token
, "ignore-must-revalidate"))
2798 ignore_must_revalidate
= 1;
2799 else if (!strcmp(token
, "ignore-private"))
2801 else if (!strcmp(token
, "ignore-auth"))
2803 else if (!strcmp(token
, "reload-into-ims")) {
2804 reload_into_ims
= 1;
2805 refresh_nocache_hack
= 1;
2806 /* tell client_side.c that this is used */
2807 } else if (!strcmp(token
, "ignore-reload")) {
2809 refresh_nocache_hack
= 1;
2810 /* tell client_side.c that this is used */
2814 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2817 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2819 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2820 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2821 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2825 pct
= pct
< 0.0 ? 0.0 : pct
;
2826 max
= max
< 0 ? 0 : max
;
2827 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2828 t
->pattern
= (char *) xstrdup(pattern
);
2829 t
->compiled_pattern
= comp
;
2834 if (flags
& REG_ICASE
)
2838 t
->flags
.refresh_ims
= 1;
2841 t
->flags
.store_stale
= 1;
2843 t
->max_stale
= max_stale
;
2845 #if USE_HTTP_VIOLATIONS
2847 if (override_expire
)
2848 t
->flags
.override_expire
= 1;
2850 if (override_lastmod
)
2851 t
->flags
.override_lastmod
= 1;
2853 if (reload_into_ims
)
2854 t
->flags
.reload_into_ims
= 1;
2857 t
->flags
.ignore_reload
= 1;
2859 if (ignore_no_cache
)
2860 t
->flags
.ignore_no_cache
= 1;
2862 if (ignore_no_store
)
2863 t
->flags
.ignore_no_store
= 1;
2865 if (ignore_must_revalidate
)
2866 t
->flags
.ignore_must_revalidate
= 1;
2869 t
->flags
.ignore_private
= 1;
2872 t
->flags
.ignore_auth
= 1;
2879 head
= &(*head
)->next
;
2887 free_refreshpattern(refresh_t
** head
)
2891 while ((t
= *head
) != NULL
) {
2893 safe_free(t
->pattern
);
2894 regfree(&t
->compiled_pattern
);
2898 #if USE_HTTP_VIOLATIONS
2899 refresh_nocache_hack
= 0;
2905 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2908 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2912 parse_string(char **var
)
2914 char *token
= strtok(NULL
, w_space
);
2920 *var
= xstrdup(token
);
2924 ConfigParser::ParseString(char **var
)
2930 ConfigParser::ParseString(String
*var
)
2932 char *token
= strtok(NULL
, w_space
);
2941 free_string(char **var
)
2947 parse_eol(char *volatile *var
)
2954 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2962 while (*token
&& xisspace(*token
))
2970 *var
= xstrdup((char *) token
);
2973 #define dump_eol dump_string
2974 #define free_eol free_string
2977 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2979 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2983 parse_time_t(time_t * var
)
2986 parseTimeLine(&tval
, T_SECOND_STR
, false);
2987 *var
= static_cast<time_t>(tval
/1000);
2991 free_time_t(time_t * var
)
2998 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3001 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3003 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3007 parse_time_msec(time_msec_t
* var
)
3009 parseTimeLine(var
, T_SECOND_STR
, true);
3013 free_time_msec(time_msec_t
* var
)
3021 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3023 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3028 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3030 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3035 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3037 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3043 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3045 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3050 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3052 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3056 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3058 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3063 parse_size_t(size_t * var
)
3072 parse_b_size_t(size_t * var
)
3074 parseBytesLine(var
, B_BYTES_STR
);
3079 parse_b_ssize_t(ssize_t
* var
)
3081 parseBytesLineSigned(var
, B_BYTES_STR
);
3087 parse_kb_size_t(size_t * var
)
3089 parseBytesLine(var
, B_KBYTES_STR
);
3094 parse_b_int64_t(int64_t * var
)
3096 parseBytesLine64(var
, B_BYTES_STR
);
3100 parse_kb_int64_t(int64_t * var
)
3102 parseBytesLine64(var
, B_KBYTES_STR
);
3106 free_size_t(size_t * var
)
3113 free_ssize_t(ssize_t
* var
)
3120 free_b_int64_t(int64_t * var
)
3125 #define free_b_size_t free_size_t
3126 #define free_b_ssize_t free_ssize_t
3127 #define free_kb_size_t free_size_t
3128 #define free_mb_size_t free_size_t
3129 #define free_gb_size_t free_size_t
3130 #define free_kb_int64_t free_b_int64_t
3133 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3135 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3139 free_u_short(unsigned short * u
)
3145 parse_u_short(unsigned short * var
)
3147 ConfigParser::ParseUShort(var
);
3151 ConfigParser::ParseUShort(unsigned short *var
)
3157 ConfigParser::ParseBool(bool *var
)
3159 int i
= GetInteger();
3170 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3172 while (list
!= NULL
) {
3173 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3179 ConfigParser::ParseWordList(wordlist
** list
)
3181 parse_wordlist(list
);
3185 parse_wordlist(wordlist
** list
)
3188 char *t
= strtok(NULL
, "");
3190 while ((token
= strwordtok(NULL
, &t
)))
3191 wordlistAdd(list
, token
);
3194 #if 0 /* now unused */
3196 check_null_wordlist(wordlist
* w
)
3203 check_null_acl_access(acl_access
* a
)
3208 #define free_wordlist wordlistDestroy
3210 #define free_uri_whitespace free_int
3213 parse_uri_whitespace(int *var
)
3215 char *token
= strtok(NULL
, w_space
);
3220 if (!strcasecmp(token
, "strip"))
3221 *var
= URI_WHITESPACE_STRIP
;
3222 else if (!strcasecmp(token
, "deny"))
3223 *var
= URI_WHITESPACE_DENY
;
3224 else if (!strcasecmp(token
, "allow"))
3225 *var
= URI_WHITESPACE_ALLOW
;
3226 else if (!strcasecmp(token
, "encode"))
3227 *var
= URI_WHITESPACE_ENCODE
;
3228 else if (!strcasecmp(token
, "chop"))
3229 *var
= URI_WHITESPACE_CHOP
;
3235 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3239 if (var
== URI_WHITESPACE_ALLOW
)
3241 else if (var
== URI_WHITESPACE_ENCODE
)
3243 else if (var
== URI_WHITESPACE_CHOP
)
3245 else if (var
== URI_WHITESPACE_DENY
)
3250 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3254 free_removalpolicy(RemovalPolicySettings
** settings
)
3259 free_string(&(*settings
)->type
);
3261 free_wordlist(&(*settings
)->args
);
3269 parse_removalpolicy(RemovalPolicySettings
** settings
)
3272 free_removalpolicy(settings
);
3274 *settings
= new RemovalPolicySettings
;
3276 parse_string(&(*settings
)->type
);
3278 parse_wordlist(&(*settings
)->args
);
3282 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3285 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3286 args
= settings
->args
;
3289 storeAppendPrintf(entry
, " %s", args
->key
);
3293 storeAppendPrintf(entry
, "\n");
3297 YesNoNone::configure(bool beSet
)
3299 option
= beSet
? +1 : -1;
3302 YesNoNone::operator void*() const
3304 assert(option
!= 0); // must call configure() first
3305 return option
> 0 ? (void*)this : NULL
;
3309 free_YesNoNone(YesNoNone
*)
3311 // do nothing: no explicit cleanup is required
3315 parse_YesNoNone(YesNoNone
*option
)
3318 parse_onoff(&value
);
3319 option
->configure(value
> 0);
3323 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3325 if (option
.configured())
3326 dump_onoff(entry
, name
, option
? 1 : 0);
3330 free_memcachemode(SquidConfig
* config
)
3336 parse_memcachemode(SquidConfig
* config
)
3338 char *token
= strtok(NULL
, w_space
);
3342 if (strcmp(token
, "always") == 0) {
3343 Config
.onoff
.memory_cache_first
= 1;
3344 Config
.onoff
.memory_cache_disk
= 1;
3345 } else if (strcmp(token
, "disk") == 0) {
3346 Config
.onoff
.memory_cache_first
= 0;
3347 Config
.onoff
.memory_cache_disk
= 1;
3348 } else if (strncmp(token
, "net", 3) == 0) {
3349 Config
.onoff
.memory_cache_first
= 1;
3350 Config
.onoff
.memory_cache_disk
= 0;
3351 } else if (strcmp(token
, "never") == 0) {
3352 Config
.onoff
.memory_cache_first
= 0;
3353 Config
.onoff
.memory_cache_disk
= 0;
3359 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3361 storeAppendPrintf(entry
, "%s ", name
);
3362 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3363 storeAppendPrintf(entry
, "always");
3364 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3365 storeAppendPrintf(entry
, "disk");
3366 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3367 storeAppendPrintf(entry
, "network");
3368 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3369 storeAppendPrintf(entry
, "none");
3370 storeAppendPrintf(entry
, "\n");
3373 #include "cf_parser.cci"
3376 parseNeighborType(const char *s
)
3378 if (!strcasecmp(s
, "parent"))
3381 if (!strcasecmp(s
, "neighbor"))
3382 return PEER_SIBLING
;
3384 if (!strcasecmp(s
, "neighbour"))
3385 return PEER_SIBLING
;
3387 if (!strcasecmp(s
, "sibling"))
3388 return PEER_SIBLING
;
3390 if (!strcasecmp(s
, "multicast"))
3391 return PEER_MULTICAST
;
3393 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3395 return PEER_SIBLING
;
3400 parse_IpAddress_list(Ip::Address_list
** head
)
3403 Ip::Address_list
*s
;
3406 while ((token
= strtok(NULL
, w_space
))) {
3407 if (GetHostWithPort(token
, &ipa
)) {
3410 head
= &(*head
)->next
;
3412 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3422 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3424 char ntoabuf
[MAX_IPSTRLEN
];
3427 storeAppendPrintf(e
, "%s %s\n",
3429 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3435 free_IpAddress_list(Ip::Address_list
** head
)
3437 if (*head
) delete *head
;
3441 #if CURRENTLY_UNUSED
3442 /* This code was previously used by http_port. Left as it really should
3443 * be used by icp_port and htcp_port
3446 check_null_IpAddress_list(const Ip::Address_list
* s
)
3451 #endif /* CURRENTLY_UNUSED */
3452 #endif /* USE_WCCPv2 */
3455 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3458 unsigned short port
= 0;
3462 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3463 s
->name
= xstrdup(token
);
3464 s
->connection_auth_disabled
= false;
3466 if (*token
== '[') {
3469 t
= strchr(host
, ']');
3471 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing ']' on IPv6 address: " << token
);
3477 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port in: " << token
);
3480 if (!Ip::EnableIpv6
) {
3481 debugs(3, DBG_CRITICAL
, "FATAL: " << s
->protocol
<< "_port: IPv6 is not available.");
3484 port
= xatos(t
+ 1);
3485 } else if ((t
= strchr(token
, ':'))) {
3490 port
= xatos(t
+ 1);
3492 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3494 debugs(3, 3, s
->protocol
<< "_port: found Listen on Port: " << port
);
3496 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port: " << token
);
3500 if (port
== 0 && host
!= NULL
) {
3501 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: Port cannot be 0: " << token
);
3508 if (!Ip::EnableIpv6
)
3510 debugs(3, 3, s
->protocol
<< "_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3511 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3513 if (!Ip::EnableIpv6
)
3515 debugs(3, 3, s
->protocol
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3516 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3517 /* dont use ipcache */
3518 s
->defaultsite
= xstrdup(host
);
3520 if (!Ip::EnableIpv6
)
3522 debugs(3, 3, s
->protocol
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3524 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: failed to resolve Host/IP: " << host
);
3530 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3534 if (strcmp(token
, "accel") == 0) {
3535 if (s
->intercepted
|| s
->spoof_client_ip
) {
3536 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3539 s
->accel
= s
->vhost
= 1;
3540 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3541 if (s
->accel
|| s
->spoof_client_ip
) {
3542 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3546 Ip::Interceptor
.StartInterception();
3547 /* Log information regarding the port modes under interception. */
3548 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3549 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3551 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3553 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3554 if ( !s
->s
.SetIPv4() ) {
3555 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s
->s
);
3558 } else if (strcmp(token
, "tproxy") == 0) {
3559 if (s
->intercepted
|| s
->accel
) {
3560 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3563 s
->spoof_client_ip
= 1;
3564 Ip::Interceptor
.StartTransparency();
3565 /* Log information regarding the port modes under transparency. */
3566 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3567 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3569 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3570 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3574 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3576 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3579 safe_free(s
->defaultsite
);
3580 s
->defaultsite
= xstrdup(token
+ 12);
3581 } else if (strcmp(token
, "vhost") == 0) {
3583 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3585 s
->accel
= s
->vhost
= 1;
3586 } else if (strcmp(token
, "no-vhost") == 0) {
3588 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3591 } else if (strcmp(token
, "vport") == 0) {
3593 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3597 } else if (strncmp(token
, "vport=", 6) == 0) {
3599 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3602 s
->vport
= xatos(token
+ 6);
3603 } else if (strncmp(token
, "protocol=", 9) == 0) {
3605 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3608 s
->protocol
= xstrdup(token
+ 9);
3609 } else if (strcmp(token
, "allow-direct") == 0) {
3611 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3614 s
->allow_direct
= 1;
3615 } else if (strcmp(token
, "act-as-origin") == 0) {
3617 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3620 } else if (strcmp(token
, "ignore-cc") == 0) {
3621 #if !USE_HTTP_VIOLATIONS
3623 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3628 } else if (strncmp(token
, "name=", 5) == 0) {
3630 s
->name
= xstrdup(token
+ 5);
3631 } else if (strcmp(token
, "no-connection-auth") == 0) {
3632 s
->connection_auth_disabled
= true;
3633 } else if (strcmp(token
, "connection-auth=off") == 0) {
3634 s
->connection_auth_disabled
= true;
3635 } else if (strcmp(token
, "connection-auth") == 0) {
3636 s
->connection_auth_disabled
= false;
3637 } else if (strcmp(token
, "connection-auth=on") == 0) {
3638 s
->connection_auth_disabled
= false;
3639 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3640 if (!strcasecmp(token
+ 23, "off"))
3641 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3642 else if (!strcasecmp(token
+ 23, "transparent"))
3643 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3644 else if (!strcasecmp(token
+ 23, "always"))
3645 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3648 } else if (strcmp(token
, "ipv4") == 0) {
3649 if ( !s
->s
.SetIPv4() ) {
3650 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3653 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3654 s
->tcp_keepalive
.enabled
= 1;
3655 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3656 char *t
= token
+ 13;
3657 s
->tcp_keepalive
.enabled
= 1;
3658 s
->tcp_keepalive
.idle
= atoi(t
);
3662 s
->tcp_keepalive
.interval
= atoi(t
);
3667 s
->tcp_keepalive
.timeout
= atoi(t
);
3671 } else if (strcasecmp(token
, "sslBump") == 0) {
3672 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3673 "in http_port. Use 'ssl-bump' instead.");
3674 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3675 } else if (strcmp(token
, "ssl-bump") == 0) {
3676 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3677 } else if (strncmp(token
, "cert=", 5) == 0) {
3679 s
->cert
= xstrdup(token
+ 5);
3680 } else if (strncmp(token
, "key=", 4) == 0) {
3682 s
->key
= xstrdup(token
+ 4);
3683 } else if (strncmp(token
, "version=", 8) == 0) {
3684 s
->version
= xatoi(token
+ 8);
3685 if (s
->version
< 1 || s
->version
> 4)
3687 } else if (strncmp(token
, "options=", 8) == 0) {
3688 safe_free(s
->options
);
3689 s
->options
= xstrdup(token
+ 8);
3690 } else if (strncmp(token
, "cipher=", 7) == 0) {
3691 safe_free(s
->cipher
);
3692 s
->cipher
= xstrdup(token
+ 7);
3693 } else if (strncmp(token
, "clientca=", 9) == 0) {
3694 safe_free(s
->clientca
);
3695 s
->clientca
= xstrdup(token
+ 9);
3696 } else if (strncmp(token
, "cafile=", 7) == 0) {
3697 safe_free(s
->cafile
);
3698 s
->cafile
= xstrdup(token
+ 7);
3699 } else if (strncmp(token
, "capath=", 7) == 0) {
3700 safe_free(s
->capath
);
3701 s
->capath
= xstrdup(token
+ 7);
3702 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3703 safe_free(s
->crlfile
);
3704 s
->crlfile
= xstrdup(token
+ 8);
3705 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3706 safe_free(s
->dhfile
);
3707 s
->dhfile
= xstrdup(token
+ 9);
3708 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3709 safe_free(s
->sslflags
);
3710 s
->sslflags
= xstrdup(token
+ 9);
3711 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3712 safe_free(s
->sslContextSessionId
);
3713 s
->sslContextSessionId
= xstrdup(token
+ 11);
3714 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3715 s
->generateHostCertificates
= true;
3716 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3717 s
->generateHostCertificates
= true;
3718 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3719 s
->generateHostCertificates
= false;
3720 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3721 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3729 add_http_port(char *portspec
)
3731 AnyP::PortCfg
*s
= new AnyP::PortCfg("http_port");
3732 parsePortSpecification(s
, portspec
);
3733 // we may need to merge better if the above returns a list with clones
3734 assert(s
->next
== NULL
);
3735 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3736 cbdataReferenceDone(Config
.Sockaddr
.http
);
3737 Config
.Sockaddr
.http
= cbdataReference(s
);
3741 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3743 const char *protocol
= NULL
;
3744 if (strcmp(optionName
, "http_port") == 0 ||
3745 strcmp(optionName
, "ascii_port") == 0)
3747 else if (strcmp(optionName
, "https_port") == 0)
3754 char *token
= strtok(NULL
, w_space
);
3761 AnyP::PortCfg
*s
= new AnyP::PortCfg(protocol
);
3762 parsePortSpecification(s
, token
);
3764 /* parse options ... */
3765 while ((token
= strtok(NULL
, w_space
))) {
3766 parse_port_option(s
, token
);
3770 if (strcasecmp(protocol
, "https") == 0) {
3771 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3772 const bool hijacked
= s
->spoof_client_ip
|| s
->intercepted
;
3773 if (s
->sslBump
&& !hijacked
) {
3774 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3777 if (hijacked
&& !s
->sslBump
) {
3778 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3784 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3785 // clone the port options from *s to *(s->next)
3786 s
->next
= cbdataReference(s
->clone());
3787 s
->next
->s
.SetIPv4();
3788 debugs(3, 3, protocol
<< "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3792 head
= &(*head
)->next
;
3794 *head
= cbdataReference(s
);
3798 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3800 char buf
[MAX_IPSTRLEN
];
3802 storeAppendPrintf(e
, "%s %s",
3804 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3806 // MODES and specific sub-options.
3808 storeAppendPrintf(e
, " intercept");
3810 else if (s
->spoof_client_ip
)
3811 storeAppendPrintf(e
, " tproxy");
3813 else if (s
->accel
) {
3814 storeAppendPrintf(e
, " accel");
3817 storeAppendPrintf(e
, " vhost");
3820 storeAppendPrintf(e
, " vport");
3821 else if (s
->vport
> 0)
3822 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3825 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3827 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3828 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3830 if (s
->allow_direct
)
3831 storeAppendPrintf(e
, " allow-direct");
3834 storeAppendPrintf(e
, " ignore-cc");
3838 // Generic independent options
3841 storeAppendPrintf(e
, " name=%s", s
->name
);
3843 #if USE_HTTP_VIOLATIONS
3844 if (!s
->accel
&& s
->ignore_cc
)
3845 storeAppendPrintf(e
, " ignore-cc");
3848 if (s
->connection_auth_disabled
)
3849 storeAppendPrintf(e
, " connection-auth=off");
3851 storeAppendPrintf(e
, " connection-auth=on");
3853 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3856 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3859 pmtu
= "transparent";
3861 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3864 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3865 storeAppendPrintf(e
, " ipv4");
3867 if (s
->tcp_keepalive
.enabled
) {
3868 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3869 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3871 storeAppendPrintf(e
, " tcpkeepalive");
3877 storeAppendPrintf(e
, " ssl-bump");
3880 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3883 storeAppendPrintf(e
, " key=%s", s
->key
);
3886 storeAppendPrintf(e
, " version=%d", s
->version
);
3889 storeAppendPrintf(e
, " options=%s", s
->options
);
3892 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3895 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3898 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3901 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3904 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3907 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3909 if (s
->sslContextSessionId
)
3910 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3912 if (s
->generateHostCertificates
)
3913 storeAppendPrintf(e
, " generate-host-certificates");
3915 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3916 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3921 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3924 dump_generic_port(e
, n
, s
);
3925 storeAppendPrintf(e
, "\n");
3931 free_PortCfg(AnyP::PortCfg
** head
)
3935 while ((s
= *head
) != NULL
) {
3937 cbdataReferenceDone(s
);
3942 configFreeMemory(void)
3946 SSL_CTX_free(Config
.ssl_client
.sslContext
);
3951 requirePathnameExists(const char *name
, const char *path
)
3955 char pathbuf
[BUFSIZ
];
3956 assert(path
!= NULL
);
3958 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3959 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3963 if (stat(path
, &sb
) < 0) {
3964 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
3965 // keep going to find more issues if we are only checking the config file with "-k parse"
3966 if (opt_parse_cfg_only
)
3968 // this is fatal if it is found during startup or reconfigure
3969 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3970 fatalf("%s %s: %s", name
, path
, xstrerror());
3977 return ConfigParser::strtokFile();
3980 #include "AccessLogEntry.h"
3983 parse_access_log(customlog
** logs
)
3985 const char *filename
, *logdef_name
;
3987 customlog
*cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3989 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3994 if (strcmp(filename
, "none") == 0) {
3995 cl
->type
= Log::Format::CLF_NONE
;
3996 aclParseAclList(LegacyParser
, &cl
->aclList
);
3998 logs
= &(*logs
)->next
;
4003 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
4004 logdef_name
= "squid";
4006 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
4008 cl
->filename
= xstrdup(filename
);
4010 /* look for the definition pointer corresponding to this name */
4011 Format::Format
*lf
= Log::TheConfig
.logformats
;
4013 while (lf
!= NULL
) {
4014 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4016 if (strcmp(lf
->name
, logdef_name
) == 0)
4023 cl
->type
= Log::Format::CLF_CUSTOM
;
4025 } else if (strcmp(logdef_name
, "auto") == 0) {
4026 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4027 cl
->type
= Log::Format::CLF_SQUID
;
4028 } else if (strcmp(logdef_name
, "squid") == 0) {
4029 cl
->type
= Log::Format::CLF_SQUID
;
4030 } else if (strcmp(logdef_name
, "common") == 0) {
4031 cl
->type
= Log::Format::CLF_COMMON
;
4032 } else if (strcmp(logdef_name
, "combined") == 0) {
4033 cl
->type
= Log::Format::CLF_COMBINED
;
4035 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4036 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4038 } else if (strcmp(logdef_name
, "useragent") == 0) {
4039 cl
->type
= Log::Format::CLF_USERAGENT
;
4040 } else if (strcmp(logdef_name
, "referrer") == 0) {
4041 cl
->type
= Log::Format::CLF_REFERER
;
4043 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4048 aclParseAclList(LegacyParser
, &cl
->aclList
);
4051 logs
= &(*logs
)->next
;
4057 check_null_access_log(customlog
*customlog_definitions
)
4059 return customlog_definitions
== NULL
;
4063 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
4067 for (log
= logs
; log
; log
= log
->next
) {
4068 storeAppendPrintf(entry
, "%s ", name
);
4070 switch (log
->type
) {
4072 case Log::Format::CLF_CUSTOM
:
4073 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4076 case Log::Format::CLF_NONE
:
4077 storeAppendPrintf(entry
, "none");
4080 case Log::Format::CLF_SQUID
:
4081 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4084 case Log::Format::CLF_COMBINED
:
4085 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4088 case Log::Format::CLF_COMMON
:
4089 storeAppendPrintf(entry
, "%s common", log
->filename
);
4093 case Log::Format::CLF_ICAP_SQUID
:
4094 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4097 case Log::Format::CLF_USERAGENT
:
4098 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4101 case Log::Format::CLF_REFERER
:
4102 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4105 case Log::Format::CLF_UNKNOWN
:
4110 dump_acl_list(entry
, log
->aclList
);
4112 storeAppendPrintf(entry
, "\n");
4117 free_access_log(customlog
** definitions
)
4119 while (*definitions
) {
4120 customlog
*log
= *definitions
;
4121 *definitions
= log
->next
;
4123 log
->logFormat
= NULL
;
4124 log
->type
= Log::Format::CLF_UNKNOWN
;
4127 aclDestroyAclList(&log
->aclList
);
4129 safe_free(log
->filename
);
4135 /// parses list of integers form name=N1,N2,N3,...
4137 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4139 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4140 data
+= name
.size();
4145 if (!StringToInt(data
, value
, &data
, 10))
4147 list
.push_back(value
);
4148 if (*data
== '\0' || *data
!= ',')
4153 return data
&& *data
== '\0';
4157 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4159 #if !HAVE_CPU_AFFINITY
4160 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4161 "support, do not set 'cpu_affinity_map'");
4163 #endif /* HAVE_CPU_AFFINITY */
4165 if (!*cpuAffinityMap
)
4166 *cpuAffinityMap
= new CpuAffinityMap
;
4168 const char *const pToken
= strtok(NULL
, w_space
);
4169 const char *const cToken
= strtok(NULL
, w_space
);
4170 Vector
<int> processes
, cores
;
4171 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4172 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4173 "in 'cpu_affinity_map'");
4175 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4176 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4177 "'cpu_affinity_map'");
4179 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4180 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4181 "process_numbers and cores lists differ in length or " <<
4182 "contain numbers <= 0");
4188 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4190 if (cpuAffinityMap
) {
4191 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4192 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4193 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4194 cpuAffinityMap
->processes()[i
]);
4196 storeAppendPrintf(entry
, " cores=");
4197 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4198 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4199 cpuAffinityMap
->cores()[i
]);
4201 storeAppendPrintf(entry
, "\n");
4206 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4208 delete *cpuAffinityMap
;
4209 *cpuAffinityMap
= NULL
;
4215 parse_adaptation_service_set_type()
4217 Adaptation::Config::ParseServiceSet();
4221 parse_adaptation_service_chain_type()
4223 Adaptation::Config::ParseServiceChain();
4227 parse_adaptation_access_type()
4229 Adaptation::Config::ParseAccess(LegacyParser
);
4233 parse_adaptation_meta_type(Adaptation::Config::MetaHeaders
*)
4235 Adaptation::Config::ParseMetaHeader(LegacyParser
);
4239 dump_adaptation_meta_type(StoreEntry
*entry
, const char *name
, Adaptation::Config::MetaHeaders
&)
4241 Adaptation::Config::DumpMetaHeader(entry
, name
);
4245 free_adaptation_meta_type(Adaptation::Config::MetaHeaders
*)
4247 // Nothing to do, it is released inside Adaptation::Config::freeService()
4249 #endif /* USE_ADAPTATION */
4254 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4256 cfg
->parseService();
4260 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4266 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4268 cfg
.dumpService(entry
, name
);
4272 parse_icap_class_type()
4274 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4275 "Use 'adaptation_service_set' instead");
4276 Adaptation::Config::ParseServiceSet();
4280 parse_icap_access_type()
4282 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4283 "Use 'adaptation_access' instead");
4284 Adaptation::Config::ParseAccess(LegacyParser
);
4292 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4294 cfg
->parseService();
4298 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4304 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4306 cfg
.dumpService(entry
, name
);
4309 #endif /* USE_ECAP */
4312 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4317 cfg
->service_failure_limit
= GetInteger();
4319 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4322 if (strcmp(token
,"in") != 0) {
4323 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4327 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4331 d
= static_cast<time_t> (xatoi(token
));
4333 m
= static_cast<time_t> (1);
4337 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4338 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4340 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4343 cfg
->oldest_service_failure
= (m
* d
);
4346 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4348 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4349 if (cfg
.oldest_service_failure
> 0) {
4350 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4352 storeAppendPrintf(entry
, "\n");
4355 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4357 cfg
->oldest_service_failure
= 0;
4358 cfg
->service_failure_limit
= 0;
4363 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4366 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4367 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4373 if ( char *s
= strchr(al
, '{')) {
4374 *s
= '\0'; // terminate the al string
4386 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4387 ca
->alg
= Ssl::algSetValidAfter
;
4388 ca
->param
= strdup("on");
4389 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4390 ca
->alg
= Ssl::algSetValidBefore
;
4391 ca
->param
= strdup("on");
4392 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4393 ca
->alg
= Ssl::algSetCommonName
;
4395 if (strlen(param
) > 64) {
4396 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4400 ca
->param
= strdup(param
);
4403 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4408 aclParseAclList(LegacyParser
, &ca
->aclList
);
4411 cert_adapt
= &(*cert_adapt
)->next
;
4416 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4418 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4419 storeAppendPrintf(entry
, "%s ", name
);
4420 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4422 dump_acl_list(entry
, ca
->aclList
);
4423 storeAppendPrintf(entry
, "\n");
4427 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4429 while (*cert_adapt
) {
4430 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4431 *cert_adapt
= ca
->next
;
4432 safe_free(ca
->param
);
4435 aclDestroyAclList(&ca
->aclList
);
4441 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4444 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4445 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4450 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4451 cs
->alg
= Ssl::algSignTrusted
;
4452 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4453 cs
->alg
= Ssl::algSignUntrusted
;
4454 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4455 cs
->alg
= Ssl::algSignSelf
;
4457 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4462 aclParseAclList(LegacyParser
, &cs
->aclList
);
4465 cert_sign
= &(*cert_sign
)->next
;
4470 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4472 sslproxy_cert_sign
*cs
;
4473 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4474 storeAppendPrintf(entry
, "%s ", name
);
4475 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4477 dump_acl_list(entry
, cs
->aclList
);
4478 storeAppendPrintf(entry
, "\n");
4482 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4484 while (*cert_sign
) {
4485 sslproxy_cert_sign
*cs
= *cert_sign
;
4486 *cert_sign
= cs
->next
;
4489 aclDestroyAclList(&cs
->aclList
);
4495 class sslBumpCfgRr
: public ::RegisteredRunner
4498 static Ssl::BumpMode lastDeprecatedRule
;
4499 /* RegisteredRunner API */
4500 virtual void run(const RunnerRegistry
&);
4503 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4505 RunnerRegistrationEntry(rrFinalizeConfig
, sslBumpCfgRr
);
4507 void sslBumpCfgRr::run(const RunnerRegistry
&r
)
4509 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4510 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4511 static char buf
[1024];
4512 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4513 strcpy(buf
, "ssl_bump deny all");
4514 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4515 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4516 "must not use implicit rules. Update your ssl_bump rules.");
4518 strcpy(buf
, "ssl_bump allow all");
4519 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4520 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4521 "inferior to the newer server-first bumping mode. New ssl_bump"
4522 " configurations must not use implicit rules. Update your ssl_bump rules.");
4528 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4530 typedef const char *BumpCfgStyle
;
4531 BumpCfgStyle bcsNone
= NULL
;
4532 BumpCfgStyle bcsNew
= "new client/server-first/none";
4533 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4534 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4535 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4537 if ((bm
= strtok(NULL
, w_space
)) == NULL
) {
4542 // if this is the first rule proccessed
4543 if (*ssl_bump
== NULL
) {
4544 bumpCfgStyleLast
= bcsNone
;
4545 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4548 acl_access
*A
= new acl_access
;
4549 A
->allow
= allow_t(ACCESS_ALLOWED
);
4551 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4552 A
->allow
.kind
= Ssl::bumpClientFirst
;
4553 bumpCfgStyleNow
= bcsNew
;
4554 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4555 A
->allow
.kind
= Ssl::bumpServerFirst
;
4556 bumpCfgStyleNow
= bcsNew
;
4557 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4558 A
->allow
.kind
= Ssl::bumpNone
;
4559 bumpCfgStyleNow
= bcsNew
;
4560 } else if (strcmp(bm
, "allow") == 0) {
4561 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4562 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4563 "is usually inferior to the newer server-first "
4564 "bumping mode. Update your ssl_bump rules.");
4565 A
->allow
.kind
= Ssl::bumpClientFirst
;
4566 bumpCfgStyleNow
= bcsOld
;
4567 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4568 } else if (strcmp(bm
, "deny") == 0) {
4569 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4570 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4571 "your ssl_bump rules.");
4572 A
->allow
.kind
= Ssl::bumpNone
;
4573 bumpCfgStyleNow
= bcsOld
;
4574 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4576 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4581 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4582 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4583 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4588 bumpCfgStyleLast
= bumpCfgStyleNow
;
4590 aclParseAclList(LegacyParser
, &A
->aclList
);
4593 for (B
= *ssl_bump
, T
= ssl_bump
; B
; T
= &B
->next
, B
= B
->next
);
4597 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4600 for (sb
= ssl_bump
; sb
!= NULL
; sb
= sb
->next
) {
4601 storeAppendPrintf(entry
, "%s ", name
);
4602 storeAppendPrintf(entry
, "%s ", Ssl::bumpMode(sb
->allow
.kind
));
4604 dump_acl_list(entry
, sb
->aclList
);
4605 storeAppendPrintf(entry
, "\n");
4609 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4611 free_acl_access(ssl_bump
);
4616 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4621 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4622 storeAppendPrintf(entry
, "%s ", hwa
->fieldName
.c_str());
4623 storeAppendPrintf(entry
, "%s ", hwa
->fieldValue
.c_str());
4625 dump_acl_list(entry
, hwa
->aclList
);
4626 storeAppendPrintf(entry
, "\n");
4630 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4634 *headers
= new HeaderWithAclList
;
4636 if ((fn
= strtok(NULL
, w_space
)) == NULL
) {
4642 hwa
.fieldId
= httpHeaderIdByNameDef(fn
, strlen(fn
));
4643 if (hwa
.fieldId
== HDR_BAD_HDR
)
4644 hwa
.fieldId
= HDR_OTHER
;
4648 ConfigParser::ParseQuotedString(&buf
, &wasQuoted
);
4649 hwa
.fieldValue
= buf
.termedBuf();
4650 hwa
.quoted
= wasQuoted
;
4652 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4653 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4657 hwa
.valueFormat
= nlf
;
4659 aclParseAclList(LegacyParser
, &hwa
.aclList
);
4660 (*headers
)->push_back(hwa
);
4663 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4668 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4670 aclDestroyAclList(&hwa
->aclList
);
4672 if (hwa
->valueFormat
) {
4673 delete hwa
->valueFormat
;
4674 hwa
->valueFormat
= NULL
;