2 * DEBUG: section 03 Configuration File Parsing
3 * AUTHOR: Harvest Derived
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
35 #include "acl/AclAddress.h"
36 #include "acl/AclDenyInfoList.h"
37 #include "acl/AclNameList.h"
38 #include "acl/AclSizeLimit.h"
39 #include "acl/Gadgets.h"
40 #include "acl/MethodData.h"
41 #include "anyp/PortCfg.h"
43 #include "base/RunnersRegistry.h"
44 #include "mgr/ActionPasswordList.h"
45 #include "CachePeer.h"
46 #include "CachePeerDomainList.h"
48 #include "ConfigParser.h"
49 #include "CpuAffinityMap.h"
50 #include "DiskIO/DiskIOModule.h"
51 #include "eui/Config.h"
52 #include "ExternalACL.h"
53 #include "format/Format.h"
55 #include "HttpHeaderTools.h"
56 #include "HttpRequestMethod.h"
57 #include "ident/Config.h"
58 #include "ip/Intercept.h"
59 #include "ip/QosConfig.h"
62 #include "log/Config.h"
63 #include "log/CustomLog.h"
66 #include "mgr/Registration.h"
67 #include "NeighborTypeDomainList.h"
69 #include "PeerDigest.h"
70 #include "RefreshPattern.h"
72 #include "SquidConfig.h"
73 #include "SquidString.h"
74 #include "ssl/ProxyCerts.h"
76 #include "StoreFileSystem.h"
79 #include "neighbors.h"
81 /* wccp2 has its own conditional definitions */
84 #include "adaptation/Config.h"
87 #include "adaptation/icap/Config.h"
90 #include "adaptation/ecap/Config.h"
93 #include "ssl/support.h"
94 #include "ssl/Config.h"
97 #include "auth/Config.h"
98 #include "auth/Scheme.h"
101 #include "esi/Parser.h"
117 #include <sys/types.h>
126 #include <sys/stat.h>
130 #include "ssl/gadgets.h"
134 static void parse_adaptation_service_set_type();
135 static void parse_adaptation_service_chain_type();
136 static void parse_adaptation_access_type();
140 static void parse_icap_service_type(Adaptation::Icap::Config
*);
141 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
142 static void free_icap_service_type(Adaptation::Icap::Config
*);
143 static void parse_icap_class_type();
144 static void parse_icap_access_type();
146 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
147 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
148 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
152 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
153 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
154 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
157 static peer_t
parseNeighborType(const char *s
);
159 CBDATA_TYPE(CachePeer
);
161 static const char *const T_MILLISECOND_STR
= "millisecond";
162 static const char *const T_SECOND_STR
= "second";
163 static const char *const T_MINUTE_STR
= "minute";
164 static const char *const T_HOUR_STR
= "hour";
165 static const char *const T_DAY_STR
= "day";
166 static const char *const T_WEEK_STR
= "week";
167 static const char *const T_FORTNIGHT_STR
= "fortnight";
168 static const char *const T_MONTH_STR
= "month";
169 static const char *const T_YEAR_STR
= "year";
170 static const char *const T_DECADE_STR
= "decade";
172 static const char *const B_BYTES_STR
= "bytes";
173 static const char *const B_KBYTES_STR
= "KB";
174 static const char *const B_MBYTES_STR
= "MB";
175 static const char *const B_GBYTES_STR
= "GB";
177 static const char *const list_sep
= ", \t\n\r";
179 static void parse_access_log(CustomLog
** customlog_definitions
);
180 static int check_null_access_log(CustomLog
*customlog_definitions
);
181 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
182 static void free_access_log(CustomLog
** definitions
);
183 static bool setLogformat(CustomLog
*cl
, const char *name
, const bool dieWhenMissing
);
185 static void update_maxobjsize(void);
186 static void configDoConfigure(void);
187 static void parse_refreshpattern(RefreshPattern
**);
188 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
189 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
190 static void parse_u_short(unsigned short * var
);
191 static void parse_string(char **);
192 static void default_all(void);
193 static void defaults_if_none(void);
194 static void defaults_postscriptum(void);
195 static int parse_line(char *);
196 static void parse_obsolete(const char *);
197 static void parseBytesLine(size_t * bptr
, const char *units
);
199 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
202 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
204 static size_t parseBytesUnits(const char *unit
);
205 static void free_all(void);
206 void requirePathnameExists(const char *name
, const char *path
);
207 static OBJH dump_config
;
208 #if USE_HTTP_VIOLATIONS
209 static void free_HeaderManglers(HeaderManglers
**pm
);
210 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
211 static void parse_http_header_access(HeaderManglers
**manglers
);
212 #define free_http_header_access free_HeaderManglers
213 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
214 static void parse_http_header_replace(HeaderManglers
**manglers
);
215 #define free_http_header_replace free_HeaderManglers
217 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
218 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
219 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
220 static void parse_note(Notes
*);
221 static void dump_note(StoreEntry
*, const char *, Notes
&);
222 static void free_note(Notes
*);
223 static void parse_denyinfo(AclDenyInfoList
** var
);
224 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
225 static void free_denyinfo(AclDenyInfoList
** var
);
228 static void parse_IpAddress_list(Ip::Address_list
**);
229 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
230 static void free_IpAddress_list(Ip::Address_list
**);
232 static int check_null_IpAddress_list(const Ip::Address_list
*);
233 #endif /* CURRENTLY_UNUSED */
234 #endif /* USE_WCCPv2 */
236 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
237 #define parse_PortCfg(l) parsePortCfg((l), token)
238 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
239 static void free_PortCfg(AnyP::PortCfg
**);
242 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
243 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
244 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
245 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
246 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
247 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
248 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
249 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
250 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
253 static void parse_b_size_t(size_t * var
);
254 static void parse_b_int64_t(int64_t * var
);
256 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
258 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
259 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
260 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
262 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
265 * LegacyParser is a parser for legacy code that uses the global
266 * approach. This is static so that it is only exposed to cache_cf.
267 * Other modules needing access to a ConfigParser should have it
268 * provided to them in their parserFOO methods.
270 static ConfigParser LegacyParser
= ConfigParser();
275 LegacyParser
.destruct();
279 update_maxobjsize(void)
283 // determine the maximum size object that can be stored to disk
284 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
285 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
287 const int64_t storeMax
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->maxObjectSize();
292 // Ensure that we do not discard objects which could be stored only in memory.
293 // It is governed by maximum_object_size_in_memory (for now)
294 // TODO: update this to check each in-memory location (SMP and local memory limits differ)
295 if (ms
< static_cast<int64_t>(Config
.Store
.maxInMemObjSize
))
296 ms
= Config
.Store
.maxInMemObjSize
;
298 store_maxobjsize
= ms
;
302 SetConfigFilename(char const *file_name
, bool is_pipe
)
305 cfg_filename
= file_name
+ 1;
307 cfg_filename
= file_name
;
311 skip_ws(const char* s
)
320 parseManyConfigFiles(char* files
, int depth
)
323 char* saveptr
= NULL
;
328 memset(&globbuf
, 0, sizeof(globbuf
));
329 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
330 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
331 fatalf("Unable to find configuration file: %s: %s",
335 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
336 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
340 char* file
= strwordtok(files
, &saveptr
);
341 while (file
!= NULL
) {
342 error_count
+= parseOneConfigFile(file
, depth
);
343 file
= strwordtok(NULL
, &saveptr
);
345 #endif /* HAVE_GLOB */
350 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
353 assert(newSubstr
!= NULL
);
355 unsigned newSubstrLen
= strlen(newSubstr
);
356 if (newSubstrLen
> substrLen
)
357 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
359 // move tail part including zero
360 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
361 // copy new substring in place
362 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
368 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
370 assert(line
!= NULL
);
371 assert(macroName
!= NULL
);
372 assert(substStr
!= NULL
);
373 unsigned macroNameLen
= strlen(macroName
);
374 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
375 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
379 ProcessMacros(char*& line
, int& len
)
381 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
382 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
386 trim_trailing_ws(char* str
)
389 unsigned i
= strlen(str
);
390 while ((i
> 0) && xisspace(str
[i
- 1]))
396 FindStatement(const char* line
, const char* statement
)
398 assert(line
!= NULL
);
399 assert(statement
!= NULL
);
401 const char* str
= skip_ws(line
);
402 unsigned len
= strlen(statement
);
403 if (strncmp(str
, statement
, len
) == 0) {
407 else if (xisspace(*str
))
415 StrToInt(const char* str
, long& number
)
420 number
= strtol(str
, &end
, 0);
422 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
426 EvalBoolExpr(const char* expr
)
428 assert(expr
!= NULL
);
429 if (strcmp(expr
, "true") == 0) {
431 } else if (strcmp(expr
, "false") == 0) {
433 } else if (const char* equation
= strchr(expr
, '=')) {
434 const char* rvalue
= skip_ws(equation
+ 1);
435 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
436 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
437 trim_trailing_ws(lvalue
);
440 if (!StrToInt(lvalue
, number1
))
441 fatalf("String is not a integer number: '%s'\n", lvalue
);
443 if (!StrToInt(rvalue
, number2
))
444 fatalf("String is not a integer number: '%s'\n", rvalue
);
447 return number1
== number2
;
449 fatalf("Unable to evaluate expression '%s'\n", expr
);
450 return false; // this place cannot be reached
454 parseOneConfigFile(const char *file_name
, unsigned int depth
)
457 const char *orig_cfg_filename
= cfg_filename
;
458 const int orig_config_lineno
= config_lineno
;
460 char *tmp_line
= NULL
;
461 int tmp_line_len
= 0;
465 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
467 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
471 if (file_name
[0] == '!' || file_name
[0] == '|') {
472 fp
= popen(file_name
+ 1, "r");
475 fp
= fopen(file_name
, "r");
479 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
482 setmode(fileno(fp
), O_TEXT
);
485 SetConfigFilename(file_name
, bool(is_pipe
));
487 memset(config_input_line
, '\0', BUFSIZ
);
491 Vector
<bool> if_states
;
492 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
495 if ((token
= strchr(config_input_line
, '\n')))
498 if ((token
= strchr(config_input_line
, '\r')))
501 // strip any prefix whitespace off the line.
502 const char *p
= skip_ws(config_input_line
);
503 if (config_input_line
!= p
)
504 memmove(config_input_line
, p
, strlen(p
)+1);
506 if (strncmp(config_input_line
, "#line ", 6) == 0) {
507 static char new_file_name
[1024];
509 static char new_lineno
;
510 token
= config_input_line
+ 6;
511 new_lineno
= strtol(token
, &file
, 0) - 1;
514 continue; /* Not a valid #line directive, may be a comment */
516 while (*file
&& xisspace((unsigned char) *file
))
521 continue; /* Not a valid #line directive, may be a comment */
523 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
525 if ((token
= strchr(new_file_name
, '"')))
528 SetConfigFilename(new_file_name
, false);
531 config_lineno
= new_lineno
;
534 if (config_input_line
[0] == '#')
537 if (config_input_line
[0] == '\0')
540 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
542 size_t append_len
= strlen(append
);
544 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
546 strcpy(tmp_line
+ tmp_line_len
, append
);
548 tmp_line_len
+= append_len
;
550 if (tmp_line
[tmp_line_len
-1] == '\\') {
551 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
552 tmp_line
[--tmp_line_len
] = '\0';
556 trim_trailing_ws(tmp_line
);
557 ProcessMacros(tmp_line
, tmp_line_len
);
558 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
560 if (const char* expr
= FindStatement(tmp_line
, "if")) {
561 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
562 } else if (FindStatement(tmp_line
, "endif")) {
563 if (!if_states
.empty())
564 if_states
.pop_back(); // remove last if-statement meaning
566 fatalf("'endif' without 'if'\n");
567 } else if (FindStatement(tmp_line
, "else")) {
568 if (!if_states
.empty())
569 if_states
.back() = !if_states
.back();
571 fatalf("'else' without 'if'\n");
572 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
573 /* Handle includes here */
574 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
575 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
576 } else if (!parse_line(tmp_line
)) {
577 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
586 if (!if_states
.empty())
587 fatalf("if-statement without 'endif'\n");
590 int ret
= pclose(fp
);
593 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
598 SetConfigFilename(orig_cfg_filename
, false);
599 config_lineno
= orig_config_lineno
;
606 parseConfigFile(const char *file_name
)
614 ACLMethodData::ThePurgeCount
= 0;
617 err_count
= parseOneConfigFile(file_name
, 0);
621 defaults_postscriptum();
624 * We must call configDoConfigure() before leave_suid() because
625 * configDoConfigure() is where we turn username strings into
630 if (!Config
.chroot_dir
) {
632 setUmask(Config
.umask
);
633 _db_init(Debug::cache_log
, Debug::debugOptions
);
637 if (opt_send_signal
== -1) {
638 Mgr::RegisterAction("config",
639 "Current Squid Configuration",
648 configDoConfigure(void)
650 memset(&Config2
, '\0', sizeof(SquidConfig2
));
651 /* init memory as early as possible */
655 Config
.cacheSwap
.n_strands
= 0; // no diskers by default
656 if (Config
.cacheSwap
.swapDirs
== NULL
) {
657 /* Memory-only cache probably in effect. */
658 /* turn off the cache rebuild delays... */
659 StoreController::store_dirs_rebuilding
= 0;
660 } else if (InDaemonMode()) { // no diskers in non-daemon mode
661 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
662 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
663 if (sd
->needsDiskStrand())
664 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
668 if (Debug::rotateNumber
< 0) {
669 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
672 #if SIZEOF_OFF_T <= 4
673 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
674 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
675 Config
.Store
.maxObjectSize
= 0x7FFF0000;
678 if (0 == Store::Root().maxSize())
679 /* people might want a zero-sized cache on purpose */
681 else if (Store::Root().maxSize() < Config
.memMaxSize
)
682 /* This is bogus. folk with NULL caches will want this */
683 debugs(3, DBG_CRITICAL
, "WARNING cache_mem is larger than total disk cache space!");
685 if (Config
.Announce
.period
> 0) {
686 Config
.onoff
.announce
= 1;
688 Config
.Announce
.period
= 86400 * 365; /* one year */
689 Config
.onoff
.announce
= 0;
692 if (Config
.onoff
.httpd_suppress_version_string
)
693 visible_appname_string
= (char *)appname_string
;
695 visible_appname_string
= (char const *)APP_FULLNAME
;
698 if (Config
.dnsChildren
.n_max
< 1)
699 fatal("No DNS helpers allocated");
702 if (Config
.Program
.redirect
) {
703 if (Config
.redirectChildren
.n_max
< 1) {
704 Config
.redirectChildren
.n_max
= 0;
705 wordlistDestroy(&Config
.Program
.redirect
);
709 if (Config
.Program
.store_id
) {
710 if (Config
.storeIdChildren
.n_max
< 1) {
711 Config
.storeIdChildren
.n_max
= 0;
712 wordlistDestroy(&Config
.Program
.store_id
);
716 if (Config
.appendDomain
)
717 if (*Config
.appendDomain
!= '.')
718 fatal("append_domain must begin with a '.'");
720 if (Config
.errHtmlText
== NULL
)
721 Config
.errHtmlText
= xstrdup(null_string
);
723 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
724 if (Config
.max_filedescriptors
> 0) {
725 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
727 #elif USE_SELECT || USE_SELECT_WIN32
728 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
729 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
735 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
737 visible_appname_string
);
740 * the extra space is for loop detection in client_side.c -- we search
741 * for substrings in the Via header.
743 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
745 visible_appname_string
);
747 /* Use visible_hostname as default surrogate_id */
748 if (!Config
.Accel
.surrogate_id
) {
749 const char *t
= getMyHostname();
750 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
753 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
754 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
756 if (Config
.appendDomain
)
757 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
759 Config
.appendDomainLen
= 0;
761 if (Config
.connect_retries
> 10) {
762 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
763 Config
.connect_retries
= 10;
766 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
768 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
772 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
774 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
775 if (Config
.Program
.redirect
)
776 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
778 if (Config
.Program
.store_id
)
779 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
781 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
783 if (Config
.errorDirectory
)
784 requirePathnameExists("Error Directory", Config
.errorDirectory
);
786 #if USE_HTTP_VIOLATIONS
789 const RefreshPattern
*R
;
791 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
792 if (!R
->flags
.override_expire
)
795 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
800 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
801 if (!R
->flags
.override_lastmod
)
804 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
809 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
810 if (!R
->flags
.reload_into_ims
)
813 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
818 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
819 if (!R
->flags
.ignore_reload
)
822 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
827 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
828 if (!R
->flags
.ignore_no_store
)
831 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
836 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
837 if (!R
->flags
.ignore_must_revalidate
)
839 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
843 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
844 if (!R
->flags
.ignore_private
)
847 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
852 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
853 if (!R
->flags
.ignore_auth
)
856 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
863 #if !USE_HTTP_VIOLATIONS
864 Config
.onoff
.via
= 1;
867 if (!Config
.onoff
.via
)
868 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
872 // we enable runtime PURGE checks if there is at least one PURGE method ACL
873 // TODO: replace with a dedicated "purge" ACL option?
874 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
876 Config2
.onoff
.mangle_request_headers
= (Config
.request_header_access
!= NULL
);
878 if (geteuid() == 0) {
879 if (NULL
!= Config
.effectiveUser
) {
881 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
885 * Andres Kroonmaa <andre@online.ee>:
886 * Some getpwnam() implementations (Solaris?) require
887 * an available FD < 256 for opening a FILE* to the
890 * This should be safe at startup, but might still fail
891 * during reconfigure.
893 fatalf("getpwnam failed to find userid for effective user '%s'",
894 Config
.effectiveUser
);
898 Config2
.effectiveUserID
= pwd
->pw_uid
;
900 Config2
.effectiveGroupID
= pwd
->pw_gid
;
904 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
906 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
907 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
915 Config2
.effectiveUserID
= geteuid();
916 Config2
.effectiveGroupID
= getegid();
919 if (NULL
!= Config
.effectiveGroup
) {
921 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
924 fatalf("getgrnam failed to find groupid for effective group '%s'",
925 Config
.effectiveGroup
);
929 Config2
.effectiveGroupID
= grp
->gr_gid
;
934 debugs(3, DBG_IMPORTANT
, "Initializing https proxy context");
936 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
);
938 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
940 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " SSL context");
941 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
945 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
946 if (!s
->flags
.tunnelSslBumping
)
949 debugs(3, DBG_IMPORTANT
, "Initializing http_port " << s
->s
<< " SSL context");
950 s
->configureSslServerContext();
953 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
954 debugs(3, DBG_IMPORTANT
, "Initializing https_port " << s
->s
<< " SSL context");
955 s
->configureSslServerContext();
960 // prevent infinite fetch loops in the request parser
961 // due to buffer full but not enough data recived to finish parse
962 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
963 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
964 " Change client_request_buffer_max or request_header_max_size limits.",
965 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
969 * Disable client side request pipelining if client_persistent_connections OFF.
970 * Waste of resources queueing any pipelined requests when the first will close the connection.
972 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
973 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
974 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
975 Config
.pipeline_max_prefetch
= 0;
980 * disable client side request pipelining. There is a race with
981 * Negotiate and NTLM when the client sends a second request on an
982 * connection before the authenticate challenge is sent. With
983 * pipelining OFF, the client may fail to authenticate, but squid's
984 * state will be preserved.
986 if (Config
.pipeline_max_prefetch
> 0) {
987 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
988 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
989 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
990 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
991 Config
.pipeline_max_prefetch
= 0;
997 /** Parse a line containing an obsolete directive.
998 * To upgrade it where possible instead of just "Bungled config" for
999 * directives which cannot be marked as simply aliases of the some name.
1000 * For example if the parameter order and content has changed.
1001 * Or if the directive has been completely removed.
1004 parse_obsolete(const char *name
)
1006 // Directives which have been radically changed rather than removed
1007 if (!strcmp(name
, "url_rewrite_concurrency")) {
1010 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
1011 Config
.redirectChildren
.concurrency
= cval
;
1015 /* Parse a time specification from the config file. Store the
1016 * result in 'tptr', after converting it to 'units' */
1018 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
1025 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
1028 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1033 m
= u
; /* default to 'units' if none specified */
1037 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1038 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1039 config_input_line
<< "', assuming " <<
1040 d
<< " " << units
);
1041 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1044 *tptr
= static_cast<time_msec_t
>(m
* d
);
1046 if (static_cast<double>(*tptr
) * 2 != m
* d
* 2) {
1047 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1048 d
<< " " << token
<< ": integer overflow (time_msec_t).");
1054 parseTimeUnits(const char *unit
, bool allowMsec
)
1056 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1059 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1062 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1065 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1068 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1069 return 86400 * 1000;
1071 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1072 return 86400 * 7 * 1000;
1074 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1075 return 86400 * 14 * 1000;
1077 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1078 return static_cast<uint64_t>(86400) * 30 * 1000;
1080 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1081 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1083 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1084 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1086 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1092 parseBytesLine64(int64_t * bptr
, const char *units
)
1099 if ((u
= parseBytesUnits(units
)) == 0) {
1104 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1109 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1116 m
= u
; /* default to 'units' if none specified */
1120 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1121 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1122 config_input_line
<< "', assuming " <<
1123 d
<< " " << units
);
1124 else if ((m
= parseBytesUnits(token
)) == 0) {
1129 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1131 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1132 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1133 d
<< " " << token
<< ": integer overflow (int64_t).");
1139 parseBytesLine(size_t * bptr
, const char *units
)
1146 if ((u
= parseBytesUnits(units
)) == 0) {
1151 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1156 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1157 *bptr
= static_cast<size_t>(-1);
1163 m
= u
; /* default to 'units' if none specified */
1167 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1168 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1169 config_input_line
<< "', assuming " <<
1170 d
<< " " << units
);
1171 else if ((m
= parseBytesUnits(token
)) == 0) {
1176 *bptr
= static_cast<size_t>(m
* d
/ u
);
1178 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1179 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1180 d
<< " " << token
<< ": integer overflow (size_t).");
1187 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1194 if ((u
= parseBytesUnits(units
)) == 0) {
1199 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1204 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1211 m
= u
; /* default to 'units' if none specified */
1215 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1216 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1217 config_input_line
<< "', assuming " <<
1218 d
<< " " << units
);
1219 else if ((m
= parseBytesUnits(token
)) == 0) {
1224 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1226 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1227 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1228 d
<< " " << token
<< ": integer overflow (ssize_t).");
1235 * Parse bytes from a string.
1236 * Similar to the parseBytesLine function but parses the string value instead of
1237 * the current token value.
1239 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1242 if ((u
= parseBytesUnits(units
)) == 0) {
1247 // Find number from string beginning.
1248 char const * number_begin
= value
;
1249 char const * number_end
= value
;
1251 while ((*number_end
>= '0' && *number_end
<= '9')) {
1256 number
.limitInit(number_begin
, number_end
- number_begin
);
1258 int d
= xatoi(number
.termedBuf());
1260 if ((m
= parseBytesUnits(number_end
)) == 0) {
1265 *bptr
= static_cast<size_t>(m
* d
/ u
);
1266 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1271 parseBytesUnits(const char *unit
)
1273 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1276 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1279 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1282 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1285 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1290 /*****************************************************************************
1292 *****************************************************************************/
1295 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1300 while (ae
!= NULL
) {
1301 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1302 storeAppendPrintf(entry
, "%s %s %s %s ",
1306 ae
->flags
.flagsStr());
1310 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1311 storeAppendPrintf(entry
, "%s ", v
->key
);
1315 storeAppendPrintf(entry
, "\n");
1316 wordlistDestroy(&w
);
1322 parse_acl(ACL
** ae
)
1324 ACL::ParseAclLine(LegacyParser
, ae
);
1334 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1338 for (l
= head
; l
; l
= l
->next
) {
1339 storeAppendPrintf(entry
, " %s%s",
1340 l
->op
? null_string
: "!",
1346 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1350 for (l
= head
; l
; l
= l
->next
) {
1351 storeAppendPrintf(entry
, "%s %s",
1353 l
->allow
? "Allow" : "Deny");
1354 dump_acl_list(entry
, l
->aclList
);
1355 storeAppendPrintf(entry
, "\n");
1360 parse_acl_access(acl_access
** head
)
1362 aclParseAccessLine(LegacyParser
, head
);
1366 free_acl_access(acl_access
** head
)
1368 aclDestroyAccessList(head
);
1372 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1374 char buf
[MAX_IPSTRLEN
];
1375 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1379 parse_address(Ip::Address
*addr
)
1381 char *token
= strtok(NULL
, w_space
);
1388 if (!strcmp(token
,"any_addr"))
1390 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1392 else if ( (*addr
= token
) ) // try parse numeric/IPA
1395 addr
->GetHostByName(token
); // dont use ipcache
1399 free_address(Ip::Address
*addr
)
1404 CBDATA_TYPE(AclAddress
);
1407 dump_acl_address(StoreEntry
* entry
, const char *name
, AclAddress
* head
)
1409 char buf
[MAX_IPSTRLEN
];
1412 for (l
= head
; l
; l
= l
->next
) {
1413 if (!l
->addr
.IsAnyAddr())
1414 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1416 storeAppendPrintf(entry
, "%s autoselect", name
);
1418 dump_acl_list(entry
, l
->aclList
);
1420 storeAppendPrintf(entry
, "\n");
1425 freed_acl_address(void *data
)
1427 AclAddress
*l
= static_cast<AclAddress
*>(data
);
1428 aclDestroyAclList(&l
->aclList
);
1432 parse_acl_address(AclAddress
** head
)
1435 AclAddress
**tail
= head
; /* sane name below */
1436 CBDATA_INIT_TYPE_FREECB(AclAddress
, freed_acl_address
);
1437 l
= cbdataAlloc(AclAddress
);
1438 parse_address(&l
->addr
);
1439 aclParseAclList(LegacyParser
, &l
->aclList
);
1442 tail
= &(*tail
)->next
;
1448 free_acl_address(AclAddress
** head
)
1451 AclAddress
*l
= *head
;
1457 CBDATA_TYPE(acl_tos
);
1460 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1464 for (l
= head
; l
; l
= l
->next
) {
1466 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1468 storeAppendPrintf(entry
, "%s none", name
);
1470 dump_acl_list(entry
, l
->aclList
);
1472 storeAppendPrintf(entry
, "\n");
1477 freed_acl_tos(void *data
)
1479 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1480 aclDestroyAclList(&l
->aclList
);
1484 parse_acl_tos(acl_tos
** head
)
1487 acl_tos
**tail
= head
; /* sane name below */
1488 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1489 char *token
= strtok(NULL
, w_space
);
1496 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1501 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1503 l
= cbdataAlloc(acl_tos
);
1505 l
->tos
= (tos_t
)tos
;
1507 aclParseAclList(LegacyParser
, &l
->aclList
);
1510 tail
= &(*tail
)->next
;
1516 free_acl_tos(acl_tos
** head
)
1526 #if SO_MARK && USE_LIBCAP
1528 CBDATA_TYPE(acl_nfmark
);
1531 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1535 for (l
= head
; l
; l
= l
->next
) {
1537 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1539 storeAppendPrintf(entry
, "%s none", name
);
1541 dump_acl_list(entry
, l
->aclList
);
1543 storeAppendPrintf(entry
, "\n");
1548 freed_acl_nfmark(void *data
)
1550 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1551 aclDestroyAclList(&l
->aclList
);
1555 parse_acl_nfmark(acl_nfmark
** head
)
1558 acl_nfmark
**tail
= head
; /* sane name below */
1560 char *token
= strtok(NULL
, w_space
);
1567 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1572 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1574 l
= cbdataAlloc(acl_nfmark
);
1578 aclParseAclList(LegacyParser
, &l
->aclList
);
1581 tail
= &(*tail
)->next
;
1587 free_acl_nfmark(acl_nfmark
** head
)
1590 acl_nfmark
*l
= *head
;
1596 #endif /* SO_MARK */
1598 CBDATA_TYPE(AclSizeLimit
);
1601 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1605 for (l
= head
; l
; l
= l
->next
) {
1607 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1609 storeAppendPrintf(entry
, "%s none", name
);
1611 dump_acl_list(entry
, l
->aclList
);
1613 storeAppendPrintf(entry
, "\n");
1618 freed_acl_b_size_t(void *data
)
1620 AclSizeLimit
*l
= static_cast<AclSizeLimit
*>(data
);
1621 aclDestroyAclList(&l
->aclList
);
1625 parse_acl_b_size_t(AclSizeLimit
** head
)
1628 AclSizeLimit
**tail
= head
; /* sane name below */
1630 CBDATA_INIT_TYPE_FREECB(AclSizeLimit
, freed_acl_b_size_t
);
1632 l
= cbdataAlloc(AclSizeLimit
);
1634 parse_b_int64_t(&l
->size
);
1636 aclParseAclList(LegacyParser
, &l
->aclList
);
1639 tail
= &(*tail
)->next
;
1645 free_acl_b_size_t(AclSizeLimit
** head
)
1648 AclSizeLimit
*l
= *head
;
1657 #include "DelayPools.h"
1658 #include "DelayConfig.h"
1659 /* do nothing - free_delay_pool_count is the magic free function.
1660 * this is why delay_pool_count isn't just marked TYPE: u_short
1662 #define free_delay_pool_class(X)
1663 #define free_delay_pool_access(X)
1664 #define free_delay_pool_rates(X)
1665 #define dump_delay_pool_class(X, Y, Z)
1666 #define dump_delay_pool_access(X, Y, Z)
1667 #define dump_delay_pool_rates(X, Y, Z)
1670 free_delay_pool_count(DelayConfig
* cfg
)
1672 cfg
->freePoolCount();
1676 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1678 cfg
.dumpPoolCount (entry
, name
);
1682 parse_delay_pool_count(DelayConfig
* cfg
)
1684 cfg
->parsePoolCount();
1688 parse_delay_pool_class(DelayConfig
* cfg
)
1690 cfg
->parsePoolClass();
1694 parse_delay_pool_rates(DelayConfig
* cfg
)
1696 cfg
->parsePoolRates();
1700 parse_delay_pool_access(DelayConfig
* cfg
)
1702 cfg
->parsePoolAccess(LegacyParser
);
1708 #include "ClientDelayConfig.h"
1709 /* do nothing - free_client_delay_pool_count is the magic free function.
1710 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1713 #define free_client_delay_pool_access(X)
1714 #define free_client_delay_pool_rates(X)
1715 #define dump_client_delay_pool_access(X, Y, Z)
1716 #define dump_client_delay_pool_rates(X, Y, Z)
1719 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1721 cfg
->freePoolCount();
1725 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1727 cfg
.dumpPoolCount (entry
, name
);
1731 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1733 cfg
->parsePoolCount();
1737 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1739 cfg
->parsePoolRates();
1743 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1745 cfg
->parsePoolAccess(LegacyParser
);
1749 #if USE_HTTP_VIOLATIONS
1751 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1754 manglers
->dumpAccess(entry
, name
);
1758 parse_http_header_access(HeaderManglers
**pm
)
1762 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1763 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1764 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1769 *pm
= new HeaderManglers
;
1770 HeaderManglers
*manglers
= *pm
;
1771 headerMangler
*mangler
= manglers
->track(t
);
1773 parse_acl_access(&mangler
->access_list
);
1777 free_HeaderManglers(HeaderManglers
**pm
)
1779 // we delete the entire http_header_* mangler configuration at once
1780 if (const HeaderManglers
*manglers
= *pm
) {
1787 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1790 manglers
->dumpReplacement(entry
, name
);
1794 parse_http_header_replace(HeaderManglers
**pm
)
1798 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1799 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1800 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1804 const char *value
= t
+ strlen(t
) + 1;
1807 *pm
= new HeaderManglers
;
1808 HeaderManglers
*manglers
= *pm
;
1809 manglers
->setReplacement(t
, value
);
1815 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1821 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1822 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1824 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1826 storeAppendPrintf(entry
, "\n");
1831 check_null_string(char *s
)
1838 parse_authparam(Auth::ConfigVector
* config
)
1843 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1846 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1849 /* find a configuration for the scheme in the currently parsed configs... */
1850 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1852 if (schemeCfg
== NULL
) {
1853 /* Create a configuration based on the scheme info */
1854 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1856 if (theScheme
== NULL
) {
1857 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1861 config
->push_back(theScheme
->createConfig());
1862 schemeCfg
= Auth::Config::Find(type_str
);
1863 if (schemeCfg
== NULL
) {
1864 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1869 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1873 free_authparam(Auth::ConfigVector
* cfg
)
1875 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1878 /* remove our pointers to the probably-dead sub-configs */
1879 while (cfg
->size()) {
1883 /* on reconfigure initialize new auth schemes for the new config. */
1884 if (reconfiguring
) {
1890 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1892 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1893 (*i
)->dump(entry
, name
, (*i
));
1895 #endif /* USE_AUTH */
1897 /* TODO: just return the object, the # is irrelevant */
1899 find_fstype(char *type
)
1901 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1902 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1909 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1913 RefCount
<SwapDir
> sd
;
1917 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1920 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1923 fs
= find_fstype(type_str
);
1926 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: This proxy does not support the '" << type_str
<< "' cache type. Ignoring.");
1930 /* reconfigure existing dir */
1932 for (i
= 0; i
< swap
->n_configured
; ++i
) {
1933 assert (swap
->swapDirs
[i
].getRaw());
1935 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1936 /* this is specific to on-fs Stores. The right
1937 * way to handle this is probably to have a mapping
1938 * from paths to stores, and have on-fs stores
1939 * register with that, and lookip in that in their
1940 * own setup logic. RBC 20041225. TODO.
1943 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1945 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().items
[fs
]->type()) != 0) {
1946 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1947 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1953 update_maxobjsize();
1960 if (swap
->n_configured
> 63) {
1961 /* 7 bits, signed */
1962 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1963 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1968 allocate_new_swapdir(swap
);
1970 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1972 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1974 /* parse the FS parameters and options */
1975 sd
->parse(swap
->n_configured
, path_str
);
1977 ++swap
->n_configured
;
1979 /* Update the max object size */
1980 update_maxobjsize();
1984 peer_type_str(const peer_t type
)
1986 const char * result
;
1998 case PEER_MULTICAST
:
1999 result
= "multicast";
2011 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2013 CachePeerDomainList
*d
;
2014 NeighborTypeDomainList
*t
;
2015 LOCAL_ARRAY(char, xname
, 128);
2018 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2025 dump_peer_options(entry
, p
);
2027 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2028 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2030 d
->do_ping
? null_string
: "!",
2035 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2036 dump_acl_access(entry
, xname
, p
->access
);
2039 for (t
= p
->typelist
; t
; t
= t
->next
) {
2040 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2042 peer_type_str(t
->type
),
2051 * utility function to prevent getservbyname() being called with a numeric value
2052 * on Windows at least it returns garage results.
2055 isUnsignedNumeric(const char *str
, size_t len
)
2057 if (len
< 1) return false;
2059 for (; len
>0 && *str
; ++str
, --len
) {
2060 if (! isdigit(*str
))
2067 \param proto 'tcp' or 'udp' for protocol
2068 \returns Port the named service is supposed to be listening on.
2070 static unsigned short
2071 GetService(const char *proto
)
2073 struct servent
*port
= NULL
;
2074 /** Parses a port number or service name from the squid.conf */
2075 char *token
= strtok(NULL
, w_space
);
2076 if (token
== NULL
) {
2078 return 0; /* NEVER REACHED */
2080 /** Returns either the service port number from /etc/services */
2081 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2082 port
= getservbyname(token
, proto
);
2084 return ntohs((unsigned short)port
->s_port
);
2086 /** Or a numeric translation of the config text. */
2087 return xatos(token
);
2091 \returns Port the named TCP service is supposed to be listening on.
2092 \copydoc GetService(const char *proto)
2094 inline unsigned short
2097 return GetService("tcp");
2101 \returns Port the named UDP service is supposed to be listening on.
2102 \copydoc GetService(const char *proto)
2104 inline unsigned short
2107 return GetService("udp");
2111 parse_peer(CachePeer
** head
)
2115 CBDATA_INIT_TYPE_FREECB(CachePeer
, peerDestroy
);
2116 p
= cbdataAlloc(CachePeer
);
2117 p
->http_port
= CACHE_HTTP_PORT
;
2118 p
->icp
.port
= CACHE_ICP_PORT
;
2121 p
->stats
.logged_state
= PEER_ALIVE
;
2123 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2126 p
->host
= xstrdup(token
);
2128 p
->name
= xstrdup(token
);
2130 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2133 p
->type
= parseNeighborType(token
);
2135 if (p
->type
== PEER_MULTICAST
) {
2136 p
->options
.no_digest
= true;
2137 p
->options
.no_netdb_exchange
= true;
2140 p
->http_port
= GetTcpService();
2145 p
->icp
.port
= GetUdpService();
2146 p
->connection_auth
= 2; /* auto */
2148 while ((token
= strtok(NULL
, w_space
))) {
2149 if (!strcmp(token
, "proxy-only")) {
2150 p
->options
.proxy_only
= true;
2151 } else if (!strcmp(token
, "no-query")) {
2152 p
->options
.no_query
= true;
2153 } else if (!strcmp(token
, "background-ping")) {
2154 p
->options
.background_ping
= true;
2155 } else if (!strcmp(token
, "no-digest")) {
2156 p
->options
.no_digest
= true;
2157 } else if (!strcmp(token
, "no-tproxy")) {
2158 p
->options
.no_tproxy
= true;
2159 } else if (!strcmp(token
, "multicast-responder")) {
2160 p
->options
.mcast_responder
= true;
2161 #if PEER_MULTICAST_SIBLINGS
2162 } else if (!strcmp(token
, "multicast-siblings")) {
2163 p
->options
.mcast_siblings
= true;
2165 } else if (!strncmp(token
, "weight=", 7)) {
2166 p
->weight
= xatoi(token
+ 7);
2167 } else if (!strncmp(token
, "basetime=", 9)) {
2168 p
->basetime
= xatoi(token
+ 9);
2169 } else if (!strcmp(token
, "closest-only")) {
2170 p
->options
.closest_only
= true;
2171 } else if (!strncmp(token
, "ttl=", 4)) {
2172 p
->mcast
.ttl
= xatoi(token
+ 4);
2174 if (p
->mcast
.ttl
< 0)
2177 if (p
->mcast
.ttl
> 128)
2179 } else if (!strcmp(token
, "default")) {
2180 p
->options
.default_parent
= true;
2181 } else if (!strcmp(token
, "round-robin")) {
2182 p
->options
.roundrobin
= true;
2183 } else if (!strcmp(token
, "weighted-round-robin")) {
2184 p
->options
.weighted_roundrobin
= true;
2186 } else if (!strcmp(token
, "htcp")) {
2187 p
->options
.htcp
= true;
2188 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2189 /* Note: The htcp- form is deprecated, replaced by htcp= */
2190 p
->options
.htcp
= true;
2191 char *tmp
= xstrdup(token
+5);
2192 char *mode
, *nextmode
;
2193 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2194 nextmode
= strchr(mode
, ',');
2199 if (!strcmp(mode
, "no-clr")) {
2200 if (p
->options
.htcp_only_clr
)
2201 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2202 p
->options
.htcp_no_clr
= true;
2203 } else if (!strcmp(mode
, "no-purge-clr")) {
2204 p
->options
.htcp_no_purge_clr
= true;
2205 } else if (!strcmp(mode
, "only-clr")) {
2206 if (p
->options
.htcp_no_clr
)
2207 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2208 p
->options
.htcp_only_clr
= true;
2209 } else if (!strcmp(mode
, "forward-clr")) {
2210 p
->options
.htcp_forward_clr
= true;
2211 } else if (!strcmp(mode
, "oldsquid")) {
2212 p
->options
.htcp_oldsquid
= true;
2214 fatalf("invalid HTCP mode '%s'", mode
);
2219 } else if (!strcmp(token
, "no-netdb-exchange")) {
2220 p
->options
.no_netdb_exchange
= true;
2222 } else if (!strcmp(token
, "carp")) {
2223 if (p
->type
!= PEER_PARENT
)
2224 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2226 p
->options
.carp
= true;
2227 } else if (!strncmp(token
, "carp-key=", 9)) {
2228 if (p
->options
.carp
!= true)
2229 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2230 p
->options
.carp_key
.set
= true;
2231 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2232 for (; key
; key
= nextkey
) {
2233 nextkey
=strchr(key
,',');
2234 if (nextkey
) ++nextkey
; // skip the comma, any
2235 if (0==strncmp(key
,"scheme",6)) {
2236 p
->options
.carp_key
.scheme
= true;
2237 } else if (0==strncmp(key
,"host",4)) {
2238 p
->options
.carp_key
.host
= true;
2239 } else if (0==strncmp(key
,"port",4)) {
2240 p
->options
.carp_key
.port
= true;
2241 } else if (0==strncmp(key
,"path",4)) {
2242 p
->options
.carp_key
.path
= true;
2243 } else if (0==strncmp(key
,"params",6)) {
2244 p
->options
.carp_key
.params
= true;
2246 fatalf("invalid carp-key '%s'",key
);
2249 } else if (!strcmp(token
, "userhash")) {
2251 if (p
->type
!= PEER_PARENT
)
2252 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2254 p
->options
.userhash
= true;
2256 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2258 } else if (!strcmp(token
, "sourcehash")) {
2259 if (p
->type
!= PEER_PARENT
)
2260 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2262 p
->options
.sourcehash
= true;
2264 } else if (!strcmp(token
, "no-delay")) {
2266 p
->options
.no_delay
= true;
2268 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2270 } else if (!strncmp(token
, "login=", 6)) {
2271 p
->login
= xstrdup(token
+ 6);
2272 rfc1738_unescape(p
->login
);
2273 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2274 p
->connect_timeout
= xatoi(token
+ 16);
2275 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2276 p
->connect_fail_limit
= xatoi(token
+ 19);
2277 #if USE_CACHE_DIGESTS
2278 } else if (!strncmp(token
, "digest-url=", 11)) {
2279 p
->digest_url
= xstrdup(token
+ 11);
2282 } else if (!strcmp(token
, "allow-miss")) {
2283 p
->options
.allow_miss
= true;
2284 } else if (!strncmp(token
, "max-conn=", 9)) {
2285 p
->max_conn
= xatoi(token
+ 9);
2286 } else if (!strcmp(token
, "originserver")) {
2287 p
->options
.originserver
= true;
2288 } else if (!strncmp(token
, "name=", 5)) {
2292 p
->name
= xstrdup(token
+ 5);
2293 } else if (!strncmp(token
, "forceddomain=", 13)) {
2294 safe_free(p
->domain
);
2297 p
->domain
= xstrdup(token
+ 13);
2301 } else if (strcmp(token
, "ssl") == 0) {
2303 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2304 safe_free(p
->sslcert
);
2305 p
->sslcert
= xstrdup(token
+ 8);
2306 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2307 safe_free(p
->sslkey
);
2308 p
->sslkey
= xstrdup(token
+ 7);
2309 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2310 p
->sslversion
= xatoi(token
+ 11);
2311 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2312 safe_free(p
->ssloptions
);
2313 p
->ssloptions
= xstrdup(token
+ 11);
2314 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2315 safe_free(p
->sslcipher
);
2316 p
->sslcipher
= xstrdup(token
+ 10);
2317 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2318 safe_free(p
->sslcafile
);
2319 p
->sslcafile
= xstrdup(token
+ 10);
2320 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2321 safe_free(p
->sslcapath
);
2322 p
->sslcapath
= xstrdup(token
+ 10);
2323 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2324 safe_free(p
->sslcrlfile
);
2325 p
->sslcrlfile
= xstrdup(token
+ 11);
2326 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2327 safe_free(p
->sslflags
);
2328 p
->sslflags
= xstrdup(token
+ 9);
2329 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2330 safe_free(p
->ssldomain
);
2331 p
->ssldomain
= xstrdup(token
+ 10);
2334 } else if (strcmp(token
, "front-end-https") == 0) {
2335 p
->front_end_https
= 1;
2336 } else if (strcmp(token
, "front-end-https=on") == 0) {
2337 p
->front_end_https
= 1;
2338 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2339 p
->front_end_https
= 2;
2340 } else if (strcmp(token
, "connection-auth=off") == 0) {
2341 p
->connection_auth
= 0;
2342 } else if (strcmp(token
, "connection-auth") == 0) {
2343 p
->connection_auth
= 1;
2344 } else if (strcmp(token
, "connection-auth=on") == 0) {
2345 p
->connection_auth
= 1;
2346 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2347 p
->connection_auth
= 2;
2348 } else if (token
[0] == '#') {
2349 // start of a text comment. stop reading this line.
2352 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2356 if (peerFindByName(p
->name
))
2357 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2362 if (p
->connect_fail_limit
< 1)
2363 p
->connect_fail_limit
= 10;
2365 p
->icp
.version
= ICP_VERSION_CURRENT
;
2367 p
->testing_now
= false;
2369 #if USE_CACHE_DIGESTS
2371 if (!p
->options
.no_digest
) {
2372 /* XXX This looks odd.. who has the original pointer
2375 PeerDigest
*pd
= peerDigestCreate(p
);
2376 p
->digest
= cbdataReference(pd
);
2381 p
->index
= ++Config
.npeers
;
2383 while (*head
!= NULL
)
2384 head
= &(*head
)->next
;
2392 free_peer(CachePeer
** P
)
2396 while ((p
= *P
) != NULL
) {
2398 #if USE_CACHE_DIGESTS
2400 cbdataReferenceDone(p
->digest
);
2410 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2414 while (list
!= NULL
) {
2415 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2416 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2418 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2420 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2421 storeAppendPrintf(entry
, " %s", w
->key
);
2424 storeAppendPrintf(entry
, "\n");
2430 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2432 char *passwd
= NULL
;
2433 wordlist
*actions
= NULL
;
2434 Mgr::ActionPasswordList
*p
;
2435 Mgr::ActionPasswordList
**P
;
2436 parse_string(&passwd
);
2437 parse_wordlist(&actions
);
2438 p
= new Mgr::ActionPasswordList
;
2440 p
->actions
= actions
;
2442 for (P
= head
; *P
; P
= &(*P
)->next
) {
2444 * See if any of the actions from this line already have a
2445 * password from previous lines. The password checking
2446 * routines in cache_manager.c take the the password from
2447 * the first Mgr::ActionPasswordList that contains the
2448 * requested action. Thus, we should warn users who might
2449 * think they can have two passwords for the same action.
2454 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2455 for (u
= actions
; u
; u
= u
->next
) {
2456 if (strcmp(w
->key
, u
->key
))
2459 debugs(0, DBG_CRITICAL
, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2468 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2470 Mgr::ActionPasswordList
*p
;
2472 while ((p
= *head
) != NULL
) {
2475 wordlistDestroy(&p
->actions
);
2481 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2485 while (var
!= NULL
) {
2486 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2488 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2489 storeAppendPrintf(entry
, " %s", a
->name
);
2491 storeAppendPrintf(entry
, "\n");
2498 parse_denyinfo(AclDenyInfoList
** var
)
2500 aclParseDenyInfoLine(var
);
2504 free_denyinfo(AclDenyInfoList
** list
)
2506 AclDenyInfoList
*a
= NULL
;
2507 AclDenyInfoList
*a_next
= NULL
;
2508 AclNameList
*l
= NULL
;
2509 AclNameList
*l_next
= NULL
;
2511 for (a
= *list
; a
; a
= a_next
) {
2512 for (l
= a
->acl_list
; l
; l
= l_next
) {
2514 memFree(l
, MEM_ACL_NAME_LIST
);
2519 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2527 parse_peer_access(void)
2532 if (!(host
= strtok(NULL
, w_space
)))
2535 if ((p
= peerFindByName(host
)) == NULL
) {
2536 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2540 aclParseAccessLine(LegacyParser
, &p
->access
);
2544 parse_hostdomain(void)
2547 char *domain
= NULL
;
2549 if (!(host
= strtok(NULL
, w_space
)))
2552 while ((domain
= strtok(NULL
, list_sep
))) {
2553 CachePeerDomainList
*l
= NULL
;
2554 CachePeerDomainList
**L
= NULL
;
2557 if ((p
= peerFindByName(host
)) == NULL
) {
2558 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2562 l
= static_cast<CachePeerDomainList
*>(xcalloc(1, sizeof(CachePeerDomainList
)));
2565 if (*domain
== '!') { /* check for !.edu */
2570 l
->domain
= xstrdup(domain
);
2572 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2578 parse_hostdomaintype(void)
2582 char *domain
= NULL
;
2584 if (!(host
= strtok(NULL
, w_space
)))
2587 if (!(type
= strtok(NULL
, w_space
)))
2590 while ((domain
= strtok(NULL
, list_sep
))) {
2591 NeighborTypeDomainList
*l
= NULL
;
2592 NeighborTypeDomainList
**L
= NULL
;
2595 if ((p
= peerFindByName(host
)) == NULL
) {
2596 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2600 l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2601 l
->type
= parseNeighborType(type
);
2602 l
->domain
= xstrdup(domain
);
2604 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2610 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2612 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2630 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2632 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2636 parse_onoff(int *var
)
2638 char *token
= strtok(NULL
, w_space
);
2643 if (!strcmp(token
, "on")) {
2645 } else if (!strcmp(token
, "enable")) {
2646 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2648 } else if (!strcmp(token
, "off")) {
2650 } else if (!strcmp(token
, "disable")) {
2651 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2654 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2659 #define free_onoff free_int
2662 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2673 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2677 parse_tristate(int *var
)
2679 char *token
= strtok(NULL
, w_space
);
2684 if (!strcmp(token
, "on")) {
2686 } else if (!strcmp(token
, "enable")) {
2687 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2689 } else if (!strcmp(token
, "warn")) {
2691 } else if (!strcmp(token
, "off")) {
2693 } else if (!strcmp(token
, "disable")) {
2694 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2697 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2702 #define free_tristate free_int
2705 parse_pipelinePrefetch(int *var
)
2707 char *token
= ConfigParser::strtokFile();
2712 if (!strcmp(token
, "on")) {
2713 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2715 } else if (!strcmp(token
, "off")) {
2716 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2719 ConfigParser::strtokFileUndo();
2724 #define free_pipelinePrefetch free_int
2725 #define dump_pipelinePrefetch dump_int
2728 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2730 while (head
!= NULL
) {
2731 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2733 head
->flags
.icase
? " -i" : null_string
,
2735 (int) head
->min
/ 60,
2736 (int) (100.0 * head
->pct
+ 0.5),
2737 (int) head
->max
/ 60);
2739 if (head
->max_stale
>= 0)
2740 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2742 if (head
->flags
.refresh_ims
)
2743 storeAppendPrintf(entry
, " refresh-ims");
2745 if (head
->flags
.store_stale
)
2746 storeAppendPrintf(entry
, " store-stale");
2748 #if USE_HTTP_VIOLATIONS
2750 if (head
->flags
.override_expire
)
2751 storeAppendPrintf(entry
, " override-expire");
2753 if (head
->flags
.override_lastmod
)
2754 storeAppendPrintf(entry
, " override-lastmod");
2756 if (head
->flags
.reload_into_ims
)
2757 storeAppendPrintf(entry
, " reload-into-ims");
2759 if (head
->flags
.ignore_reload
)
2760 storeAppendPrintf(entry
, " ignore-reload");
2762 if (head
->flags
.ignore_no_store
)
2763 storeAppendPrintf(entry
, " ignore-no-store");
2765 if (head
->flags
.ignore_must_revalidate
)
2766 storeAppendPrintf(entry
, " ignore-must-revalidate");
2768 if (head
->flags
.ignore_private
)
2769 storeAppendPrintf(entry
, " ignore-private");
2771 if (head
->flags
.ignore_auth
)
2772 storeAppendPrintf(entry
, " ignore-auth");
2776 storeAppendPrintf(entry
, "\n");
2783 parse_refreshpattern(RefreshPattern
** head
)
2790 int refresh_ims
= 0;
2791 int store_stale
= 0;
2794 #if USE_HTTP_VIOLATIONS
2796 int override_expire
= 0;
2797 int override_lastmod
= 0;
2798 int reload_into_ims
= 0;
2799 int ignore_reload
= 0;
2800 int ignore_no_store
= 0;
2801 int ignore_must_revalidate
= 0;
2802 int ignore_private
= 0;
2803 int ignore_auth
= 0;
2810 int flags
= REG_EXTENDED
| REG_NOSUB
;
2812 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2817 if (strcmp(token
, "-i") == 0) {
2819 token
= strtok(NULL
, w_space
);
2820 } else if (strcmp(token
, "+i") == 0) {
2821 flags
&= ~REG_ICASE
;
2822 token
= strtok(NULL
, w_space
);
2825 if (token
== NULL
) {
2830 pattern
= xstrdup(token
);
2832 i
= GetInteger(); /* token: min */
2834 /* catch negative and insanely huge values close to 32-bit wrap */
2836 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2839 if (i
> 60*24*365) {
2840 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2844 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2846 i
= GetPercentage(); /* token: pct */
2848 pct
= (double) i
/ 100.0;
2850 i
= GetInteger(); /* token: max */
2852 /* catch negative and insanely huge values close to 32-bit wrap */
2854 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2857 if (i
> 60*24*365) {
2858 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2862 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2865 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2866 if (!strcmp(token
, "refresh-ims")) {
2868 } else if (!strcmp(token
, "store-stale")) {
2870 } else if (!strncmp(token
, "max-stale=", 10)) {
2871 max_stale
= xatoi(token
+ 10);
2872 #if USE_HTTP_VIOLATIONS
2874 } else if (!strcmp(token
, "override-expire"))
2875 override_expire
= 1;
2876 else if (!strcmp(token
, "override-lastmod"))
2877 override_lastmod
= 1;
2878 else if (!strcmp(token
, "ignore-no-store"))
2879 ignore_no_store
= 1;
2880 else if (!strcmp(token
, "ignore-must-revalidate"))
2881 ignore_must_revalidate
= 1;
2882 else if (!strcmp(token
, "ignore-private"))
2884 else if (!strcmp(token
, "ignore-auth"))
2886 else if (!strcmp(token
, "reload-into-ims")) {
2887 reload_into_ims
= 1;
2888 refresh_nocache_hack
= 1;
2889 /* tell client_side.c that this is used */
2890 } else if (!strcmp(token
, "ignore-reload")) {
2892 refresh_nocache_hack
= 1;
2893 /* tell client_side.c that this is used */
2896 } else if (!strcmp(token
, "ignore-no-cache")) {
2897 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it.");
2899 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2902 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2904 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2905 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2906 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2910 pct
= pct
< 0.0 ? 0.0 : pct
;
2911 max
= max
< 0 ? 0 : max
;
2912 t
= static_cast<RefreshPattern
*>(xcalloc(1, sizeof(RefreshPattern
)));
2913 t
->pattern
= (char *) xstrdup(pattern
);
2914 t
->compiled_pattern
= comp
;
2919 if (flags
& REG_ICASE
)
2920 t
->flags
.icase
= true;
2923 t
->flags
.refresh_ims
= true;
2926 t
->flags
.store_stale
= true;
2928 t
->max_stale
= max_stale
;
2930 #if USE_HTTP_VIOLATIONS
2932 if (override_expire
)
2933 t
->flags
.override_expire
= true;
2935 if (override_lastmod
)
2936 t
->flags
.override_lastmod
= true;
2938 if (reload_into_ims
)
2939 t
->flags
.reload_into_ims
= true;
2942 t
->flags
.ignore_reload
= true;
2944 if (ignore_no_store
)
2945 t
->flags
.ignore_no_store
= true;
2947 if (ignore_must_revalidate
)
2948 t
->flags
.ignore_must_revalidate
= true;
2951 t
->flags
.ignore_private
= true;
2954 t
->flags
.ignore_auth
= true;
2961 head
= &(*head
)->next
;
2969 free_refreshpattern(RefreshPattern
** head
)
2973 while ((t
= *head
) != NULL
) {
2975 safe_free(t
->pattern
);
2976 regfree(&t
->compiled_pattern
);
2980 #if USE_HTTP_VIOLATIONS
2981 refresh_nocache_hack
= 0;
2987 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2990 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2994 parse_string(char **var
)
2996 char *token
= strtok(NULL
, w_space
);
3002 *var
= xstrdup(token
);
3006 ConfigParser::ParseString(char **var
)
3012 ConfigParser::ParseString(String
*var
)
3014 char *token
= strtok(NULL
, w_space
);
3023 free_string(char **var
)
3029 parse_eol(char *volatile *var
)
3036 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
3044 while (*token
&& xisspace(*token
))
3052 *var
= xstrdup((char *) token
);
3055 #define dump_eol dump_string
3056 #define free_eol free_string
3059 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3061 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3065 parse_time_t(time_t * var
)
3068 parseTimeLine(&tval
, T_SECOND_STR
, false);
3069 *var
= static_cast<time_t>(tval
/1000);
3073 free_time_t(time_t * var
)
3080 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3083 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3085 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3089 parse_time_msec(time_msec_t
* var
)
3091 parseTimeLine(var
, T_SECOND_STR
, true);
3095 free_time_msec(time_msec_t
* var
)
3103 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3105 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3110 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3112 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3117 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3119 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3125 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3127 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3132 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3134 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3138 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3140 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3145 parse_size_t(size_t * var
)
3154 parse_b_size_t(size_t * var
)
3156 parseBytesLine(var
, B_BYTES_STR
);
3161 parse_b_ssize_t(ssize_t
* var
)
3163 parseBytesLineSigned(var
, B_BYTES_STR
);
3169 parse_kb_size_t(size_t * var
)
3171 parseBytesLine(var
, B_KBYTES_STR
);
3176 parse_b_int64_t(int64_t * var
)
3178 parseBytesLine64(var
, B_BYTES_STR
);
3182 parse_kb_int64_t(int64_t * var
)
3184 parseBytesLine64(var
, B_KBYTES_STR
);
3188 free_size_t(size_t * var
)
3195 free_ssize_t(ssize_t
* var
)
3202 free_b_int64_t(int64_t * var
)
3207 #define free_b_size_t free_size_t
3208 #define free_b_ssize_t free_ssize_t
3209 #define free_kb_size_t free_size_t
3210 #define free_mb_size_t free_size_t
3211 #define free_gb_size_t free_size_t
3212 #define free_kb_int64_t free_b_int64_t
3215 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3217 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3221 free_u_short(unsigned short * u
)
3227 parse_u_short(unsigned short * var
)
3229 ConfigParser::ParseUShort(var
);
3233 ConfigParser::ParseUShort(unsigned short *var
)
3239 ConfigParser::ParseBool(bool *var
)
3241 int i
= GetInteger();
3252 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3254 while (list
!= NULL
) {
3255 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3261 ConfigParser::ParseWordList(wordlist
** list
)
3263 parse_wordlist(list
);
3267 parse_wordlist(wordlist
** list
)
3270 char *t
= strtok(NULL
, "");
3272 while ((token
= strwordtok(NULL
, &t
)))
3273 wordlistAdd(list
, token
);
3276 #if 0 /* now unused */
3278 check_null_wordlist(wordlist
* w
)
3285 check_null_acl_access(acl_access
* a
)
3290 #define free_wordlist wordlistDestroy
3292 #define free_uri_whitespace free_int
3295 parse_uri_whitespace(int *var
)
3297 char *token
= strtok(NULL
, w_space
);
3302 if (!strcmp(token
, "strip"))
3303 *var
= URI_WHITESPACE_STRIP
;
3304 else if (!strcmp(token
, "deny"))
3305 *var
= URI_WHITESPACE_DENY
;
3306 else if (!strcmp(token
, "allow"))
3307 *var
= URI_WHITESPACE_ALLOW
;
3308 else if (!strcmp(token
, "encode"))
3309 *var
= URI_WHITESPACE_ENCODE
;
3310 else if (!strcmp(token
, "chop"))
3311 *var
= URI_WHITESPACE_CHOP
;
3313 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3319 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3323 if (var
== URI_WHITESPACE_ALLOW
)
3325 else if (var
== URI_WHITESPACE_ENCODE
)
3327 else if (var
== URI_WHITESPACE_CHOP
)
3329 else if (var
== URI_WHITESPACE_DENY
)
3334 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3338 free_removalpolicy(RemovalPolicySettings
** settings
)
3343 free_string(&(*settings
)->type
);
3345 free_wordlist(&(*settings
)->args
);
3353 parse_removalpolicy(RemovalPolicySettings
** settings
)
3356 free_removalpolicy(settings
);
3358 *settings
= new RemovalPolicySettings
;
3360 parse_string(&(*settings
)->type
);
3362 parse_wordlist(&(*settings
)->args
);
3366 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3369 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3370 args
= settings
->args
;
3373 storeAppendPrintf(entry
, " %s", args
->key
);
3377 storeAppendPrintf(entry
, "\n");
3381 free_YesNoNone(YesNoNone
*)
3383 // do nothing: no explicit cleanup is required
3387 parse_YesNoNone(YesNoNone
*option
)
3390 parse_onoff(&value
);
3391 option
->configure(value
> 0);
3395 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3397 if (option
.configured())
3398 dump_onoff(entry
, name
, option
? 1 : 0);
3402 free_memcachemode(SquidConfig
* config
)
3408 parse_memcachemode(SquidConfig
* config
)
3410 char *token
= strtok(NULL
, w_space
);
3414 if (strcmp(token
, "always") == 0) {
3415 Config
.onoff
.memory_cache_first
= 1;
3416 Config
.onoff
.memory_cache_disk
= 1;
3417 } else if (strcmp(token
, "disk") == 0) {
3418 Config
.onoff
.memory_cache_first
= 0;
3419 Config
.onoff
.memory_cache_disk
= 1;
3420 } else if (strncmp(token
, "net", 3) == 0) {
3421 Config
.onoff
.memory_cache_first
= 1;
3422 Config
.onoff
.memory_cache_disk
= 0;
3423 } else if (strcmp(token
, "never") == 0) {
3424 Config
.onoff
.memory_cache_first
= 0;
3425 Config
.onoff
.memory_cache_disk
= 0;
3427 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3433 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3435 storeAppendPrintf(entry
, "%s ", name
);
3436 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3437 storeAppendPrintf(entry
, "always");
3438 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3439 storeAppendPrintf(entry
, "disk");
3440 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3441 storeAppendPrintf(entry
, "network");
3442 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3443 storeAppendPrintf(entry
, "none");
3444 storeAppendPrintf(entry
, "\n");
3447 #include "cf_parser.cci"
3450 parseNeighborType(const char *s
)
3452 if (!strcmp(s
, "parent"))
3455 if (!strcmp(s
, "neighbor"))
3456 return PEER_SIBLING
;
3458 if (!strcmp(s
, "neighbour"))
3459 return PEER_SIBLING
;
3461 if (!strcmp(s
, "sibling"))
3462 return PEER_SIBLING
;
3464 if (!strcmp(s
, "multicast"))
3465 return PEER_MULTICAST
;
3467 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3469 return PEER_SIBLING
;
3474 parse_IpAddress_list(Ip::Address_list
** head
)
3477 Ip::Address_list
*s
;
3480 while ((token
= strtok(NULL
, w_space
))) {
3481 if (GetHostWithPort(token
, &ipa
)) {
3484 head
= &(*head
)->next
;
3486 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3496 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3498 char ntoabuf
[MAX_IPSTRLEN
];
3501 storeAppendPrintf(e
, "%s %s\n",
3503 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3509 free_IpAddress_list(Ip::Address_list
** head
)
3511 if (*head
) delete *head
;
3515 #if CURRENTLY_UNUSED
3516 /* This code was previously used by http_port. Left as it really should
3517 * be used by icp_port and htcp_port
3520 check_null_IpAddress_list(const Ip::Address_list
* s
)
3525 #endif /* CURRENTLY_UNUSED */
3526 #endif /* USE_WCCPv2 */
3529 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3532 unsigned short port
= 0;
3536 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3537 s
->name
= xstrdup(token
);
3538 s
->connection_auth_disabled
= false;
3540 if (*token
== '[') {
3543 t
= strchr(host
, ']');
3545 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing ']' on IPv6 address: " << token
);
3551 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port in: " << token
);
3554 if (!Ip::EnableIpv6
) {
3555 debugs(3, DBG_CRITICAL
, "FATAL: " << s
->protocol
<< "_port: IPv6 is not available.");
3558 port
= xatos(t
+ 1);
3559 } else if ((t
= strchr(token
, ':'))) {
3564 port
= xatos(t
+ 1);
3566 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3567 port
= xatos(token
);
3568 debugs(3, 3, s
->protocol
<< "_port: found Listen on Port: " << port
);
3570 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port: " << token
);
3574 if (port
== 0 && host
!= NULL
) {
3575 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: Port cannot be 0: " << token
);
3582 if (!Ip::EnableIpv6
)
3584 debugs(3, 3, s
->protocol
<< "_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3585 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3587 if (!Ip::EnableIpv6
)
3589 debugs(3, 3, s
->protocol
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3590 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3591 /* dont use ipcache */
3592 s
->defaultsite
= xstrdup(host
);
3594 if (!Ip::EnableIpv6
)
3596 debugs(3, 3, s
->protocol
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3598 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: failed to resolve Host/IP: " << host
);
3604 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3608 if (strcmp(token
, "accel") == 0) {
3609 if (s
->flags
.isIntercepted()) {
3610 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3613 s
->flags
.accelSurrogate
= true;
3615 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3616 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3617 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3620 s
->flags
.natIntercept
= true;
3621 Ip::Interceptor
.StartInterception();
3622 /* Log information regarding the port modes under interception. */
3623 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3624 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3626 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3628 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3629 if ( !s
->s
.SetIPv4() ) {
3630 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s
->s
);
3633 } else if (strcmp(token
, "tproxy") == 0) {
3634 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3635 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3638 s
->flags
.tproxyIntercept
= true;
3639 Ip::Interceptor
.StartTransparency();
3640 /* Log information regarding the port modes under transparency. */
3641 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3643 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3644 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3648 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3649 if (!s
->flags
.accelSurrogate
) {
3650 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3653 safe_free(s
->defaultsite
);
3654 s
->defaultsite
= xstrdup(token
+ 12);
3655 } else if (strcmp(token
, "vhost") == 0) {
3656 if (!s
->flags
.accelSurrogate
) {
3657 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3659 s
->flags
.accelSurrogate
= true;
3661 } else if (strcmp(token
, "no-vhost") == 0) {
3662 if (!s
->flags
.accelSurrogate
) {
3663 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3666 } else if (strcmp(token
, "vport") == 0) {
3667 if (!s
->flags
.accelSurrogate
) {
3668 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3672 } else if (strncmp(token
, "vport=", 6) == 0) {
3673 if (!s
->flags
.accelSurrogate
) {
3674 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3677 s
->vport
= xatos(token
+ 6);
3678 } else if (strncmp(token
, "protocol=", 9) == 0) {
3679 if (!s
->flags
.accelSurrogate
) {
3680 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3683 s
->protocol
= xstrdup(token
+ 9);
3684 } else if (strcmp(token
, "allow-direct") == 0) {
3685 if (!s
->flags
.accelSurrogate
) {
3686 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3689 s
->allow_direct
= true;
3690 } else if (strcmp(token
, "act-as-origin") == 0) {
3691 if (!s
->flags
.accelSurrogate
) {
3692 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3694 s
->actAsOrigin
= true;
3695 } else if (strcmp(token
, "ignore-cc") == 0) {
3696 #if !USE_HTTP_VIOLATIONS
3697 if (!s
->flags
.accelSurrogate
) {
3698 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Acceleration mode flag.");
3702 s
->ignore_cc
= true;
3703 } else if (strncmp(token
, "name=", 5) == 0) {
3705 s
->name
= xstrdup(token
+ 5);
3706 } else if (strcmp(token
, "no-connection-auth") == 0) {
3707 s
->connection_auth_disabled
= true;
3708 } else if (strcmp(token
, "connection-auth=off") == 0) {
3709 s
->connection_auth_disabled
= true;
3710 } else if (strcmp(token
, "connection-auth") == 0) {
3711 s
->connection_auth_disabled
= false;
3712 } else if (strcmp(token
, "connection-auth=on") == 0) {
3713 s
->connection_auth_disabled
= false;
3714 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3715 if (!strcmp(token
+ 23, "off"))
3716 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3717 else if (!strcmp(token
+ 23, "transparent"))
3718 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3719 else if (!strcmp(token
+ 23, "always"))
3720 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3723 } else if (strcmp(token
, "ipv4") == 0) {
3724 if ( !s
->s
.SetIPv4() ) {
3725 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3728 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3729 s
->tcp_keepalive
.enabled
= true;
3730 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3731 char *t
= token
+ 13;
3732 s
->tcp_keepalive
.enabled
= true;
3733 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3737 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3742 s
->tcp_keepalive
.timeout
= xatoui(t
);
3745 } else if (strcmp(token
, "sslBump") == 0) {
3746 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3747 "in http_port. Use 'ssl-bump' instead.");
3748 s
->flags
.tunnelSslBumping
= true;
3749 } else if (strcmp(token
, "ssl-bump") == 0) {
3750 s
->flags
.tunnelSslBumping
= true;
3751 } else if (strncmp(token
, "cert=", 5) == 0) {
3753 s
->cert
= xstrdup(token
+ 5);
3754 } else if (strncmp(token
, "key=", 4) == 0) {
3756 s
->key
= xstrdup(token
+ 4);
3757 } else if (strncmp(token
, "version=", 8) == 0) {
3758 s
->version
= xatoi(token
+ 8);
3759 if (s
->version
< 1 || s
->version
> 4)
3761 } else if (strncmp(token
, "options=", 8) == 0) {
3762 safe_free(s
->options
);
3763 s
->options
= xstrdup(token
+ 8);
3764 } else if (strncmp(token
, "cipher=", 7) == 0) {
3765 safe_free(s
->cipher
);
3766 s
->cipher
= xstrdup(token
+ 7);
3767 } else if (strncmp(token
, "clientca=", 9) == 0) {
3768 safe_free(s
->clientca
);
3769 s
->clientca
= xstrdup(token
+ 9);
3770 } else if (strncmp(token
, "cafile=", 7) == 0) {
3771 safe_free(s
->cafile
);
3772 s
->cafile
= xstrdup(token
+ 7);
3773 } else if (strncmp(token
, "capath=", 7) == 0) {
3774 safe_free(s
->capath
);
3775 s
->capath
= xstrdup(token
+ 7);
3776 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3777 safe_free(s
->crlfile
);
3778 s
->crlfile
= xstrdup(token
+ 8);
3779 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3780 safe_free(s
->dhfile
);
3781 s
->dhfile
= xstrdup(token
+ 9);
3782 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3783 safe_free(s
->sslflags
);
3784 s
->sslflags
= xstrdup(token
+ 9);
3785 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3786 safe_free(s
->sslContextSessionId
);
3787 s
->sslContextSessionId
= xstrdup(token
+ 11);
3788 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3789 s
->generateHostCertificates
= true;
3790 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3791 s
->generateHostCertificates
= true;
3792 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3793 s
->generateHostCertificates
= false;
3794 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3795 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3798 debugs(3, DBG_CRITICAL
, "FATAL: Unknown http(s)_port option '" << token
<< "'.");
3804 add_http_port(char *portspec
)
3806 AnyP::PortCfg
*s
= new AnyP::PortCfg("http_port");
3807 parsePortSpecification(s
, portspec
);
3808 // we may need to merge better if the above returns a list with clones
3809 assert(s
->next
== NULL
);
3810 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3811 cbdataReferenceDone(Config
.Sockaddr
.http
);
3812 Config
.Sockaddr
.http
= cbdataReference(s
);
3816 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3818 const char *protocol
= NULL
;
3819 if (strcmp(optionName
, "http_port") == 0 ||
3820 strcmp(optionName
, "ascii_port") == 0)
3822 else if (strcmp(optionName
, "https_port") == 0)
3829 char *token
= strtok(NULL
, w_space
);
3836 AnyP::PortCfg
*s
= new AnyP::PortCfg(protocol
);
3837 parsePortSpecification(s
, token
);
3839 /* parse options ... */
3840 while ((token
= strtok(NULL
, w_space
))) {
3841 parse_port_option(s
, token
);
3845 if (strcmp(protocol
, "https") == 0) {
3846 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3847 const bool hijacked
= s
->flags
.isIntercepted();
3848 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3849 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3852 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3853 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3859 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3860 // clone the port options from *s to *(s->next)
3861 s
->next
= cbdataReference(s
->clone());
3862 s
->next
->s
.SetIPv4();
3863 debugs(3, 3, protocol
<< "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3867 head
= &(*head
)->next
;
3869 *head
= cbdataReference(s
);
3873 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3875 char buf
[MAX_IPSTRLEN
];
3877 storeAppendPrintf(e
, "%s %s",
3879 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3881 // MODES and specific sub-options.
3882 if (s
->flags
.natIntercept
)
3883 storeAppendPrintf(e
, " intercept");
3885 else if (s
->flags
.tproxyIntercept
)
3886 storeAppendPrintf(e
, " tproxy");
3888 else if (s
->flags
.accelSurrogate
) {
3889 storeAppendPrintf(e
, " accel");
3892 storeAppendPrintf(e
, " vhost");
3895 storeAppendPrintf(e
, " vport");
3896 else if (s
->vport
> 0)
3897 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3900 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3902 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3903 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3905 if (s
->allow_direct
)
3906 storeAppendPrintf(e
, " allow-direct");
3909 storeAppendPrintf(e
, " ignore-cc");
3913 // Generic independent options
3916 storeAppendPrintf(e
, " name=%s", s
->name
);
3918 #if USE_HTTP_VIOLATIONS
3919 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3920 storeAppendPrintf(e
, " ignore-cc");
3923 if (s
->connection_auth_disabled
)
3924 storeAppendPrintf(e
, " connection-auth=off");
3926 storeAppendPrintf(e
, " connection-auth=on");
3928 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3931 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3934 pmtu
= "transparent";
3936 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3939 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3940 storeAppendPrintf(e
, " ipv4");
3942 if (s
->tcp_keepalive
.enabled
) {
3943 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3944 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3946 storeAppendPrintf(e
, " tcpkeepalive");
3951 if (s
->flags
.tunnelSslBumping
)
3952 storeAppendPrintf(e
, " ssl-bump");
3955 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3958 storeAppendPrintf(e
, " key=%s", s
->key
);
3961 storeAppendPrintf(e
, " version=%d", s
->version
);
3964 storeAppendPrintf(e
, " options=%s", s
->options
);
3967 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3970 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3973 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3976 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3979 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3982 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3984 if (s
->sslContextSessionId
)
3985 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3987 if (s
->generateHostCertificates
)
3988 storeAppendPrintf(e
, " generate-host-certificates");
3990 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3991 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3996 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3999 dump_generic_port(e
, n
, s
);
4000 storeAppendPrintf(e
, "\n");
4006 free_PortCfg(AnyP::PortCfg
** head
)
4010 while ((s
= *head
) != NULL
) {
4012 cbdataReferenceDone(s
);
4017 configFreeMemory(void)
4021 SSL_CTX_free(Config
.ssl_client
.sslContext
);
4026 requirePathnameExists(const char *name
, const char *path
)
4030 char pathbuf
[BUFSIZ
];
4031 assert(path
!= NULL
);
4033 if (Config
.chroot_dir
&& (geteuid() == 0)) {
4034 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4038 if (stat(path
, &sb
) < 0) {
4039 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
4040 // keep going to find more issues if we are only checking the config file with "-k parse"
4041 if (opt_parse_cfg_only
)
4043 // this is fatal if it is found during startup or reconfigure
4044 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4045 fatalf("%s %s: %s", name
, path
, xstrerror());
4052 return ConfigParser::strtokFile();
4055 #include "AccessLogEntry.h"
4058 * We support several access_log configuration styles:
4060 * #1: Deprecated ancient style without an explicit logging module:
4061 * access_log /var/log/access.log
4063 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
4064 * access_log none [acl ...]
4066 * #3: Configurable logging module without named options:
4067 * Logformat or the first ACL name, whichever comes first, may not contain '='.
4068 * If no explicit logformat name is given, the first ACL name, if any,
4069 * should not be an existing logformat name or it will be treated as such.
4070 * access_log module:place [logformat_name] [acl ...]
4072 * #4: Configurable logging module with name=value options such as logformat=x:
4073 * The first ACL name may not contain '='.
4074 * access_log module:place [option ...] [acl ...]
4078 parse_access_log(CustomLog
** logs
)
4080 CustomLog
*cl
= (CustomLog
*)xcalloc(1, sizeof(*cl
));
4082 // default buffer size and fatal settings
4083 cl
->bufferSize
= 8*MAX_URL
;
4086 /* determine configuration style */
4088 const char *filename
= strtok(NULL
, w_space
);
4094 if (strcmp(filename
, "none") == 0) {
4095 cl
->type
= Log::Format::CLF_NONE
;
4096 aclParseAclList(LegacyParser
, &cl
->aclList
);
4098 logs
= &(*logs
)->next
;
4103 cl
->filename
= xstrdup(filename
);
4104 cl
->type
= Log::Format::CLF_UNKNOWN
;
4106 const char *token
= ConfigParser::strtokFile();
4107 if (!token
) { // style #1
4108 // no options to deal with
4109 } else if (!strchr(token
, '=')) { // style #3
4110 // if logformat name is not recognized,
4111 // put back the token; it must be an ACL name
4112 if (!setLogformat(cl
, token
, false))
4113 ConfigParser::strtokFileUndo();
4114 } else { // style #4
4116 if (strncasecmp(token
, "on-error=", 9) == 0) {
4117 if (strncasecmp(token
+9, "die", 3) == 0) {
4119 } else if (strncasecmp(token
+9, "drop", 4) == 0) {
4122 debugs(3, DBG_CRITICAL
, "Unknown value for on-error '" <<
4123 token
<< "' expected 'drop' or 'die'");
4126 } else if (strncasecmp(token
, "buffer-size=", 12) == 0) {
4127 parseBytesOptionValue(&cl
->bufferSize
, B_BYTES_STR
, token
+12);
4128 } else if (strncasecmp(token
, "logformat=", 10) == 0) {
4129 setLogformat(cl
, token
+10, true);
4130 } else if (!strchr(token
, '=')) {
4131 // put back the token; it must be an ACL name
4132 ConfigParser::strtokFileUndo();
4133 break; // done with name=value options, now to ACLs
4135 debugs(3, DBG_CRITICAL
, "Unknown access_log option " << token
);
4138 } while ((token
= ConfigParser::strtokFile()) != NULL
);
4141 // set format if it has not been specified explicitly
4142 if (cl
->type
== Log::Format::CLF_UNKNOWN
)
4143 setLogformat(cl
, "squid", true);
4145 aclParseAclList(LegacyParser
, &cl
->aclList
);
4148 logs
= &(*logs
)->next
;
4153 /// sets CustomLog::type and, if needed, CustomLog::lf
4154 /// returns false iff there is no named log format
4156 setLogformat(CustomLog
*cl
, const char *logdef_name
, const bool dieWhenMissing
)
4159 assert(logdef_name
);
4161 debugs(3, 9, "possible " << cl
->filename
<< " logformat: " << logdef_name
);
4163 if (cl
->type
!= Log::Format::CLF_UNKNOWN
) {
4164 debugs(3, DBG_CRITICAL
, "Second logformat name in one access_log: " <<
4165 logdef_name
<< " " << cl
->type
<< " ? " << Log::Format::CLF_NONE
);
4170 /* look for the definition pointer corresponding to this name */
4171 Format::Format
*lf
= Log::TheConfig
.logformats
;
4173 while (lf
!= NULL
) {
4174 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4176 if (strcmp(lf
->name
, logdef_name
) == 0)
4183 cl
->type
= Log::Format::CLF_CUSTOM
;
4185 } else if (strcmp(logdef_name
, "auto") == 0) {
4186 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4187 cl
->type
= Log::Format::CLF_SQUID
;
4188 } else if (strcmp(logdef_name
, "squid") == 0) {
4189 cl
->type
= Log::Format::CLF_SQUID
;
4190 } else if (strcmp(logdef_name
, "common") == 0) {
4191 cl
->type
= Log::Format::CLF_COMMON
;
4192 } else if (strcmp(logdef_name
, "combined") == 0) {
4193 cl
->type
= Log::Format::CLF_COMBINED
;
4195 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4196 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4198 } else if (strcmp(logdef_name
, "useragent") == 0) {
4199 cl
->type
= Log::Format::CLF_USERAGENT
;
4200 } else if (strcmp(logdef_name
, "referrer") == 0) {
4201 cl
->type
= Log::Format::CLF_REFERER
;
4202 } else if (dieWhenMissing
) {
4203 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4214 check_null_access_log(CustomLog
*customlog_definitions
)
4216 return customlog_definitions
== NULL
;
4220 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4224 for (log
= logs
; log
; log
= log
->next
) {
4225 storeAppendPrintf(entry
, "%s ", name
);
4227 switch (log
->type
) {
4229 case Log::Format::CLF_CUSTOM
:
4230 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4233 case Log::Format::CLF_NONE
:
4234 storeAppendPrintf(entry
, "none");
4237 case Log::Format::CLF_SQUID
:
4238 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4241 case Log::Format::CLF_COMBINED
:
4242 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4245 case Log::Format::CLF_COMMON
:
4246 storeAppendPrintf(entry
, "%s common", log
->filename
);
4250 case Log::Format::CLF_ICAP_SQUID
:
4251 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4254 case Log::Format::CLF_USERAGENT
:
4255 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4258 case Log::Format::CLF_REFERER
:
4259 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4262 case Log::Format::CLF_UNKNOWN
:
4267 dump_acl_list(entry
, log
->aclList
);
4269 storeAppendPrintf(entry
, "\n");
4274 free_access_log(CustomLog
** definitions
)
4276 while (*definitions
) {
4277 CustomLog
*log
= *definitions
;
4278 *definitions
= log
->next
;
4280 log
->logFormat
= NULL
;
4281 log
->type
= Log::Format::CLF_UNKNOWN
;
4284 aclDestroyAclList(&log
->aclList
);
4286 safe_free(log
->filename
);
4292 /// parses list of integers form name=N1,N2,N3,...
4294 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4296 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4297 data
+= name
.size();
4302 if (!StringToInt(data
, value
, &data
, 10))
4304 list
.push_back(value
);
4305 if (*data
== '\0' || *data
!= ',')
4310 return data
&& *data
== '\0';
4314 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4316 #if !HAVE_CPU_AFFINITY
4317 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4318 "support, do not set 'cpu_affinity_map'");
4320 #endif /* HAVE_CPU_AFFINITY */
4322 if (!*cpuAffinityMap
)
4323 *cpuAffinityMap
= new CpuAffinityMap
;
4325 const char *const pToken
= strtok(NULL
, w_space
);
4326 const char *const cToken
= strtok(NULL
, w_space
);
4327 Vector
<int> processes
, cores
;
4328 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4329 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4330 "in 'cpu_affinity_map'");
4332 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4333 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4334 "'cpu_affinity_map'");
4336 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4337 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4338 "process_numbers and cores lists differ in length or " <<
4339 "contain numbers <= 0");
4345 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4347 if (cpuAffinityMap
) {
4348 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4349 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4350 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4351 cpuAffinityMap
->processes()[i
]);
4353 storeAppendPrintf(entry
, " cores=");
4354 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4355 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4356 cpuAffinityMap
->cores()[i
]);
4358 storeAppendPrintf(entry
, "\n");
4363 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4365 delete *cpuAffinityMap
;
4366 *cpuAffinityMap
= NULL
;
4372 parse_adaptation_service_set_type()
4374 Adaptation::Config::ParseServiceSet();
4378 parse_adaptation_service_chain_type()
4380 Adaptation::Config::ParseServiceChain();
4384 parse_adaptation_access_type()
4386 Adaptation::Config::ParseAccess(LegacyParser
);
4388 #endif /* USE_ADAPTATION */
4393 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4395 cfg
->parseService();
4399 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4405 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4407 cfg
.dumpService(entry
, name
);
4411 parse_icap_class_type()
4413 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4414 "Use 'adaptation_service_set' instead");
4415 Adaptation::Config::ParseServiceSet();
4419 parse_icap_access_type()
4421 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4422 "Use 'adaptation_access' instead");
4423 Adaptation::Config::ParseAccess(LegacyParser
);
4431 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4433 cfg
->parseService();
4437 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4443 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4445 cfg
.dumpService(entry
, name
);
4448 #endif /* USE_ECAP */
4451 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4456 cfg
->service_failure_limit
= GetInteger();
4458 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4461 if (strcmp(token
,"in") != 0) {
4462 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4466 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4470 d
= static_cast<time_t> (xatoi(token
));
4472 m
= static_cast<time_t> (1);
4476 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4477 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4479 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4482 cfg
->oldest_service_failure
= (m
* d
);
4485 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4487 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4488 if (cfg
.oldest_service_failure
> 0) {
4489 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4491 storeAppendPrintf(entry
, "\n");
4494 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4496 cfg
->oldest_service_failure
= 0;
4497 cfg
->service_failure_limit
= 0;
4502 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4505 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4506 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4512 if ( char *s
= strchr(al
, '{')) {
4513 *s
= '\0'; // terminate the al string
4525 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4526 ca
->alg
= Ssl::algSetValidAfter
;
4527 ca
->param
= strdup("on");
4528 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4529 ca
->alg
= Ssl::algSetValidBefore
;
4530 ca
->param
= strdup("on");
4531 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4532 ca
->alg
= Ssl::algSetCommonName
;
4534 if (strlen(param
) > 64) {
4535 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4539 ca
->param
= strdup(param
);
4542 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4547 aclParseAclList(LegacyParser
, &ca
->aclList
);
4550 cert_adapt
= &(*cert_adapt
)->next
;
4555 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4557 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4558 storeAppendPrintf(entry
, "%s ", name
);
4559 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4561 dump_acl_list(entry
, ca
->aclList
);
4562 storeAppendPrintf(entry
, "\n");
4566 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4568 while (*cert_adapt
) {
4569 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4570 *cert_adapt
= ca
->next
;
4571 safe_free(ca
->param
);
4574 aclDestroyAclList(&ca
->aclList
);
4580 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4583 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4584 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4589 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4590 cs
->alg
= Ssl::algSignTrusted
;
4591 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4592 cs
->alg
= Ssl::algSignUntrusted
;
4593 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4594 cs
->alg
= Ssl::algSignSelf
;
4596 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4601 aclParseAclList(LegacyParser
, &cs
->aclList
);
4604 cert_sign
= &(*cert_sign
)->next
;
4609 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4611 sslproxy_cert_sign
*cs
;
4612 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4613 storeAppendPrintf(entry
, "%s ", name
);
4614 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4616 dump_acl_list(entry
, cs
->aclList
);
4617 storeAppendPrintf(entry
, "\n");
4621 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4623 while (*cert_sign
) {
4624 sslproxy_cert_sign
*cs
= *cert_sign
;
4625 *cert_sign
= cs
->next
;
4628 aclDestroyAclList(&cs
->aclList
);
4634 class sslBumpCfgRr
: public ::RegisteredRunner
4637 static Ssl::BumpMode lastDeprecatedRule
;
4638 /* RegisteredRunner API */
4639 virtual void run(const RunnerRegistry
&);
4642 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4644 RunnerRegistrationEntry(rrFinalizeConfig
, sslBumpCfgRr
);
4646 void sslBumpCfgRr::run(const RunnerRegistry
&r
)
4648 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4649 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4650 static char buf
[1024];
4651 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4652 strcpy(buf
, "ssl_bump deny all");
4653 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4654 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4655 "must not use implicit rules. Update your ssl_bump rules.");
4657 strcpy(buf
, "ssl_bump allow all");
4658 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4659 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4660 "inferior to the newer server-first bumping mode. New ssl_bump"
4661 " configurations must not use implicit rules. Update your ssl_bump rules.");
4667 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4669 typedef const char *BumpCfgStyle
;
4670 BumpCfgStyle bcsNone
= NULL
;
4671 BumpCfgStyle bcsNew
= "new client/server-first/none";
4672 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4673 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4674 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4676 if ((bm
= strtok(NULL
, w_space
)) == NULL
) {
4681 // if this is the first rule proccessed
4682 if (*ssl_bump
== NULL
) {
4683 bumpCfgStyleLast
= bcsNone
;
4684 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4687 acl_access
*A
= new acl_access
;
4688 A
->allow
= allow_t(ACCESS_ALLOWED
);
4690 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4691 A
->allow
.kind
= Ssl::bumpClientFirst
;
4692 bumpCfgStyleNow
= bcsNew
;
4693 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4694 A
->allow
.kind
= Ssl::bumpServerFirst
;
4695 bumpCfgStyleNow
= bcsNew
;
4696 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4697 A
->allow
.kind
= Ssl::bumpNone
;
4698 bumpCfgStyleNow
= bcsNew
;
4699 } else if (strcmp(bm
, "allow") == 0) {
4700 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4701 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4702 "is usually inferior to the newer server-first "
4703 "bumping mode. Update your ssl_bump rules.");
4704 A
->allow
.kind
= Ssl::bumpClientFirst
;
4705 bumpCfgStyleNow
= bcsOld
;
4706 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4707 } else if (strcmp(bm
, "deny") == 0) {
4708 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4709 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4710 "your ssl_bump rules.");
4711 A
->allow
.kind
= Ssl::bumpNone
;
4712 bumpCfgStyleNow
= bcsOld
;
4713 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4715 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4720 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4721 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4722 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4727 bumpCfgStyleLast
= bumpCfgStyleNow
;
4729 aclParseAclList(LegacyParser
, &A
->aclList
);
4732 for (B
= *ssl_bump
, T
= ssl_bump
; B
; T
= &B
->next
, B
= B
->next
);
4736 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4739 for (sb
= ssl_bump
; sb
!= NULL
; sb
= sb
->next
) {
4740 storeAppendPrintf(entry
, "%s ", name
);
4741 storeAppendPrintf(entry
, "%s ", Ssl::bumpMode(sb
->allow
.kind
));
4743 dump_acl_list(entry
, sb
->aclList
);
4744 storeAppendPrintf(entry
, "\n");
4748 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4750 free_acl_access(ssl_bump
);
4755 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4760 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4761 storeAppendPrintf(entry
, "%s ", hwa
->fieldName
.c_str());
4762 storeAppendPrintf(entry
, "%s ", hwa
->fieldValue
.c_str());
4764 dump_acl_list(entry
, hwa
->aclList
);
4765 storeAppendPrintf(entry
, "\n");
4769 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4773 *headers
= new HeaderWithAclList
;
4775 if ((fn
= strtok(NULL
, w_space
)) == NULL
) {
4781 hwa
.fieldId
= httpHeaderIdByNameDef(fn
, strlen(fn
));
4782 if (hwa
.fieldId
== HDR_BAD_HDR
)
4783 hwa
.fieldId
= HDR_OTHER
;
4787 ConfigParser::ParseQuotedString(&buf
, &wasQuoted
);
4788 hwa
.fieldValue
= buf
.termedBuf();
4789 hwa
.quoted
= wasQuoted
;
4791 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4792 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4796 hwa
.valueFormat
= nlf
;
4798 aclParseAclList(LegacyParser
, &hwa
.aclList
);
4799 (*headers
)->push_back(hwa
);
4802 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4807 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4809 aclDestroyAclList(&hwa
->aclList
);
4811 if (hwa
->valueFormat
) {
4812 delete hwa
->valueFormat
;
4813 hwa
->valueFormat
= NULL
;
4820 static void parse_note(Notes
*notes
)
4823 notes
->parse(LegacyParser
);
4826 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4828 notes
.dump(entry
, name
);
4831 static void free_note(Notes
*notes
)