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
);
184 static void update_maxobjsize(void);
185 static void configDoConfigure(void);
186 static void parse_refreshpattern(RefreshPattern
**);
187 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
188 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
189 static void parse_u_short(unsigned short * var
);
190 static void parse_string(char **);
191 static void default_all(void);
192 static void defaults_if_none(void);
193 static void defaults_postscriptum(void);
194 static int parse_line(char *);
195 static void parse_obsolete(const char *);
196 static void parseBytesLine(size_t * bptr
, const char *units
);
198 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
201 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
203 static size_t parseBytesUnits(const char *unit
);
204 static void free_all(void);
205 void requirePathnameExists(const char *name
, const char *path
);
206 static OBJH dump_config
;
207 #if USE_HTTP_VIOLATIONS
208 static void free_HeaderManglers(HeaderManglers
**pm
);
209 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
210 static void parse_http_header_access(HeaderManglers
**manglers
);
211 #define free_http_header_access free_HeaderManglers
212 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
213 static void parse_http_header_replace(HeaderManglers
**manglers
);
214 #define free_http_header_replace free_HeaderManglers
216 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
217 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
218 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
219 static void parse_note(Notes
*);
220 static void dump_note(StoreEntry
*, const char *, Notes
&);
221 static void free_note(Notes
*);
222 static void parse_denyinfo(AclDenyInfoList
** var
);
223 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
224 static void free_denyinfo(AclDenyInfoList
** var
);
227 static void parse_IpAddress_list(Ip::Address_list
**);
228 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
229 static void free_IpAddress_list(Ip::Address_list
**);
231 static int check_null_IpAddress_list(const Ip::Address_list
*);
232 #endif /* CURRENTLY_UNUSED */
233 #endif /* USE_WCCPv2 */
235 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
236 #define parse_PortCfg(l) parsePortCfg((l), token)
237 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
238 static void free_PortCfg(AnyP::PortCfg
**);
241 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
242 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
243 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
244 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
245 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
246 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
247 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
248 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
249 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
252 static void parse_b_size_t(size_t * var
);
253 static void parse_b_int64_t(int64_t * var
);
255 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
257 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
258 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
259 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
261 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
264 * LegacyParser is a parser for legacy code that uses the global
265 * approach. This is static so that it is only exposed to cache_cf.
266 * Other modules needing access to a ConfigParser should have it
267 * provided to them in their parserFOO methods.
269 static ConfigParser LegacyParser
= ConfigParser();
274 LegacyParser
.destruct();
278 update_maxobjsize(void)
282 // determine the maximum size object that can be stored to disk
283 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
284 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
286 const int64_t storeMax
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->maxObjectSize();
291 // Ensure that we do not discard objects which could be stored only in memory.
292 // It is governed by maximum_object_size_in_memory (for now)
293 // TODO: update this to check each in-memory location (SMP and local memory limits differ)
294 if (ms
< Config
.Store
.maxInMemObjSize
)
295 ms
= Config
.Store
.maxInMemObjSize
;
297 store_maxobjsize
= ms
;
301 SetConfigFilename(char const *file_name
, bool is_pipe
)
303 cfg_filename
= file_name
;
308 cfg_filename
= file_name
+ 1;
309 else if ((token
= strrchr(cfg_filename
, '/')))
310 cfg_filename
= token
+ 1;
314 skip_ws(const char* s
)
323 parseManyConfigFiles(char* files
, int depth
)
326 char* saveptr
= NULL
;
331 memset(&globbuf
, 0, sizeof(globbuf
));
332 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
333 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
334 fatalf("Unable to find configuration file: %s: %s",
338 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
339 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
343 char* file
= strwordtok(files
, &saveptr
);
344 while (file
!= NULL
) {
345 error_count
+= parseOneConfigFile(file
, depth
);
346 file
= strwordtok(NULL
, &saveptr
);
348 #endif /* HAVE_GLOB */
353 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
356 assert(newSubstr
!= NULL
);
358 unsigned newSubstrLen
= strlen(newSubstr
);
359 if (newSubstrLen
> substrLen
)
360 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
362 // move tail part including zero
363 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
364 // copy new substring in place
365 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
371 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
373 assert(line
!= NULL
);
374 assert(macroName
!= NULL
);
375 assert(substStr
!= NULL
);
376 unsigned macroNameLen
= strlen(macroName
);
377 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
378 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
382 ProcessMacros(char*& line
, int& len
)
384 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
385 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
389 trim_trailing_ws(char* str
)
392 unsigned i
= strlen(str
);
393 while ((i
> 0) && xisspace(str
[i
- 1]))
399 FindStatement(const char* line
, const char* statement
)
401 assert(line
!= NULL
);
402 assert(statement
!= NULL
);
404 const char* str
= skip_ws(line
);
405 unsigned len
= strlen(statement
);
406 if (strncmp(str
, statement
, len
) == 0) {
410 else if (xisspace(*str
))
418 StrToInt(const char* str
, long& number
)
423 number
= strtol(str
, &end
, 0);
425 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
429 EvalBoolExpr(const char* expr
)
431 assert(expr
!= NULL
);
432 if (strcmp(expr
, "true") == 0) {
434 } else if (strcmp(expr
, "false") == 0) {
436 } else if (const char* equation
= strchr(expr
, '=')) {
437 const char* rvalue
= skip_ws(equation
+ 1);
438 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
439 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
440 trim_trailing_ws(lvalue
);
443 if (!StrToInt(lvalue
, number1
))
444 fatalf("String is not a integer number: '%s'\n", lvalue
);
446 if (!StrToInt(rvalue
, number2
))
447 fatalf("String is not a integer number: '%s'\n", rvalue
);
450 return number1
== number2
;
452 fatalf("Unable to evaluate expression '%s'\n", expr
);
453 return false; // this place cannot be reached
457 parseOneConfigFile(const char *file_name
, unsigned int depth
)
460 const char *orig_cfg_filename
= cfg_filename
;
461 const int orig_config_lineno
= config_lineno
;
463 char *tmp_line
= NULL
;
464 int tmp_line_len
= 0;
468 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
470 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
474 if (file_name
[0] == '!' || file_name
[0] == '|') {
475 fp
= popen(file_name
+ 1, "r");
478 fp
= fopen(file_name
, "r");
482 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
485 setmode(fileno(fp
), O_TEXT
);
488 SetConfigFilename(file_name
, bool(is_pipe
));
490 memset(config_input_line
, '\0', BUFSIZ
);
494 Vector
<bool> if_states
;
495 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
498 if ((token
= strchr(config_input_line
, '\n')))
501 if ((token
= strchr(config_input_line
, '\r')))
504 // strip any prefix whitespace off the line.
505 const char *p
= skip_ws(config_input_line
);
506 if (config_input_line
!= p
)
507 memmove(config_input_line
, p
, strlen(p
)+1);
509 if (strncmp(config_input_line
, "#line ", 6) == 0) {
510 static char new_file_name
[1024];
512 static char new_lineno
;
513 token
= config_input_line
+ 6;
514 new_lineno
= strtol(token
, &file
, 0) - 1;
517 continue; /* Not a valid #line directive, may be a comment */
519 while (*file
&& xisspace((unsigned char) *file
))
524 continue; /* Not a valid #line directive, may be a comment */
526 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
528 if ((token
= strchr(new_file_name
, '"')))
531 cfg_filename
= new_file_name
;
534 config_lineno
= new_lineno
;
537 if (config_input_line
[0] == '#')
540 if (config_input_line
[0] == '\0')
543 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
545 size_t append_len
= strlen(append
);
547 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
549 strcpy(tmp_line
+ tmp_line_len
, append
);
551 tmp_line_len
+= append_len
;
553 if (tmp_line
[tmp_line_len
-1] == '\\') {
554 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
555 tmp_line
[--tmp_line_len
] = '\0';
559 trim_trailing_ws(tmp_line
);
560 ProcessMacros(tmp_line
, tmp_line_len
);
561 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
563 if (const char* expr
= FindStatement(tmp_line
, "if")) {
564 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
565 } else if (FindStatement(tmp_line
, "endif")) {
566 if (!if_states
.empty())
567 if_states
.pop_back(); // remove last if-statement meaning
569 fatalf("'endif' without 'if'\n");
570 } else if (FindStatement(tmp_line
, "else")) {
571 if (!if_states
.empty())
572 if_states
.back() = !if_states
.back();
574 fatalf("'else' without 'if'\n");
575 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
576 /* Handle includes here */
577 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
578 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
579 } else if (!parse_line(tmp_line
)) {
580 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
589 if (!if_states
.empty())
590 fatalf("if-statement without 'endif'\n");
593 int ret
= pclose(fp
);
596 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
601 cfg_filename
= orig_cfg_filename
;
602 config_lineno
= orig_config_lineno
;
609 parseConfigFile(const char *file_name
)
617 ACLMethodData::ThePurgeCount
= 0;
620 err_count
= parseOneConfigFile(file_name
, 0);
624 defaults_postscriptum();
627 * We must call configDoConfigure() before leave_suid() because
628 * configDoConfigure() is where we turn username strings into
633 if (!Config
.chroot_dir
) {
635 setUmask(Config
.umask
);
636 _db_init(Debug::cache_log
, Debug::debugOptions
);
640 if (opt_send_signal
== -1) {
641 Mgr::RegisterAction("config",
642 "Current Squid Configuration",
651 configDoConfigure(void)
653 memset(&Config2
, '\0', sizeof(SquidConfig2
));
654 /* init memory as early as possible */
658 if (Config
.cacheSwap
.swapDirs
== NULL
) {
659 /* Memory-only cache probably in effect. */
660 /* turn off the cache rebuild delays... */
661 StoreController::store_dirs_rebuilding
= 0;
662 } else if (InDaemonMode()) { // no diskers in non-daemon mode
663 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
664 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
665 if (sd
->needsDiskStrand())
666 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
670 if (Debug::rotateNumber
< 0) {
671 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
674 #if SIZEOF_OFF_T <= 4
675 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
676 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
677 Config
.Store
.maxObjectSize
= 0x7FFF0000;
680 if (0 == Store::Root().maxSize())
681 /* people might want a zero-sized cache on purpose */
683 else if (Store::Root().maxSize() < Config
.memMaxSize
)
684 /* This is bogus. folk with NULL caches will want this */
685 debugs(3, DBG_CRITICAL
, "WARNING cache_mem is larger than total disk cache space!");
687 if (Config
.Announce
.period
> 0) {
688 Config
.onoff
.announce
= 1;
690 Config
.Announce
.period
= 86400 * 365; /* one year */
691 Config
.onoff
.announce
= 0;
694 if (Config
.onoff
.httpd_suppress_version_string
)
695 visible_appname_string
= (char *)appname_string
;
697 visible_appname_string
= (char const *)APP_FULLNAME
;
700 if (Config
.dnsChildren
.n_max
< 1)
701 fatal("No DNS helpers allocated");
704 if (Config
.Program
.redirect
) {
705 if (Config
.redirectChildren
.n_max
< 1) {
706 Config
.redirectChildren
.n_max
= 0;
707 wordlistDestroy(&Config
.Program
.redirect
);
711 if (Config
.Program
.store_id
) {
712 if (Config
.storeIdChildren
.n_max
< 1) {
713 Config
.storeIdChildren
.n_max
= 0;
714 wordlistDestroy(&Config
.Program
.store_id
);
718 if (Config
.appendDomain
)
719 if (*Config
.appendDomain
!= '.')
720 fatal("append_domain must begin with a '.'");
722 if (Config
.errHtmlText
== NULL
)
723 Config
.errHtmlText
= xstrdup(null_string
);
725 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
726 if (Config
.max_filedescriptors
> 0) {
727 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
729 #elif USE_SELECT || USE_SELECT_WIN32
730 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
731 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
737 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
739 visible_appname_string
);
742 * the extra space is for loop detection in client_side.c -- we search
743 * for substrings in the Via header.
745 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
747 visible_appname_string
);
749 /* Use visible_hostname as default surrogate_id */
750 if (!Config
.Accel
.surrogate_id
) {
751 const char *t
= getMyHostname();
752 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
755 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
756 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
758 if (Config
.appendDomain
)
759 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
761 Config
.appendDomainLen
= 0;
763 if (Config
.connect_retries
> 10) {
764 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
765 Config
.connect_retries
= 10;
768 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
770 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
774 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
776 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
777 if (Config
.Program
.redirect
)
778 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
780 if (Config
.Program
.store_id
)
781 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
783 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
785 if (Config
.errorDirectory
)
786 requirePathnameExists("Error Directory", Config
.errorDirectory
);
788 #if USE_HTTP_VIOLATIONS
791 const RefreshPattern
*R
;
793 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
794 if (!R
->flags
.override_expire
)
797 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
802 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
803 if (!R
->flags
.override_lastmod
)
806 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
811 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
812 if (!R
->flags
.reload_into_ims
)
815 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
820 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
821 if (!R
->flags
.ignore_reload
)
824 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
829 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
830 if (!R
->flags
.ignore_no_store
)
833 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
838 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
839 if (!R
->flags
.ignore_must_revalidate
)
841 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
845 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
846 if (!R
->flags
.ignore_private
)
849 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
854 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
855 if (!R
->flags
.ignore_auth
)
858 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
865 #if !USE_HTTP_VIOLATIONS
866 Config
.onoff
.via
= 1;
869 if (!Config
.onoff
.via
)
870 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
874 // we enable runtime PURGE checks if there is at least one PURGE method ACL
875 // TODO: replace with a dedicated "purge" ACL option?
876 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
878 Config2
.onoff
.mangle_request_headers
= (Config
.request_header_access
!= NULL
);
880 if (geteuid() == 0) {
881 if (NULL
!= Config
.effectiveUser
) {
883 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
887 * Andres Kroonmaa <andre@online.ee>:
888 * Some getpwnam() implementations (Solaris?) require
889 * an available FD < 256 for opening a FILE* to the
892 * This should be safe at startup, but might still fail
893 * during reconfigure.
895 fatalf("getpwnam failed to find userid for effective user '%s'",
896 Config
.effectiveUser
);
900 Config2
.effectiveUserID
= pwd
->pw_uid
;
902 Config2
.effectiveGroupID
= pwd
->pw_gid
;
906 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
908 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
909 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
917 Config2
.effectiveUserID
= geteuid();
918 Config2
.effectiveGroupID
= getegid();
921 if (NULL
!= Config
.effectiveGroup
) {
923 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
926 fatalf("getgrnam failed to find groupid for effective group '%s'",
927 Config
.effectiveGroup
);
931 Config2
.effectiveGroupID
= grp
->gr_gid
;
936 debugs(3, DBG_IMPORTANT
, "Initializing https proxy context");
938 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
);
940 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
942 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " SSL context");
943 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
947 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
948 if (!s
->flags
.tunnelSslBumping
)
951 debugs(3, DBG_IMPORTANT
, "Initializing http_port " << s
->s
<< " SSL context");
952 s
->configureSslServerContext();
955 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
956 debugs(3, DBG_IMPORTANT
, "Initializing https_port " << s
->s
<< " SSL context");
957 s
->configureSslServerContext();
962 // prevent infinite fetch loops in the request parser
963 // due to buffer full but not enough data recived to finish parse
964 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
965 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
966 " Change client_request_buffer_max or request_header_max_size limits.",
967 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
972 * disable client side request pipelining. There is a race with
973 * Negotiate and NTLM when the client sends a second request on an
974 * connection before the authenticate challenge is sent. With
975 * pipelining OFF, the client may fail to authenticate, but squid's
976 * state will be preserved.
978 if (Config
.onoff
.pipeline_prefetch
) {
979 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
980 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
981 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
982 debugs(3, DBG_IMPORTANT
, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
983 Config
.onoff
.pipeline_prefetch
= 0;
989 /** Parse a line containing an obsolete directive.
990 * To upgrade it where possible instead of just "Bungled config" for
991 * directives which cannot be marked as simply aliases of the some name.
992 * For example if the parameter order and content has changed.
993 * Or if the directive has been completely removed.
996 parse_obsolete(const char *name
)
998 // Directives which have been radically changed rather than removed
999 if (!strcmp(name
, "url_rewrite_concurrency")) {
1002 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
1003 Config
.redirectChildren
.concurrency
= cval
;
1007 /* Parse a time specification from the config file. Store the
1008 * result in 'tptr', after converting it to 'units' */
1010 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
1017 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
1020 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1025 m
= u
; /* default to 'units' if none specified */
1029 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1030 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1031 config_input_line
<< "', assuming " <<
1032 d
<< " " << units
);
1033 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1036 *tptr
= static_cast<time_msec_t
>(m
* d
);
1038 if (static_cast<double>(*tptr
) * 2 != m
* d
* 2) {
1039 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1040 d
<< " " << token
<< ": integer overflow (time_msec_t).");
1046 parseTimeUnits(const char *unit
, bool allowMsec
)
1048 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1051 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1054 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1057 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1060 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1061 return 86400 * 1000;
1063 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1064 return 86400 * 7 * 1000;
1066 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1067 return 86400 * 14 * 1000;
1069 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1070 return static_cast<uint64_t>(86400) * 30 * 1000;
1072 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1073 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1075 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1076 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1078 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1084 parseBytesLine64(int64_t * bptr
, const char *units
)
1091 if ((u
= parseBytesUnits(units
)) == 0) {
1096 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1101 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1108 m
= u
; /* default to 'units' if none specified */
1112 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1113 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1114 config_input_line
<< "', assuming " <<
1115 d
<< " " << units
);
1116 else if ((m
= parseBytesUnits(token
)) == 0) {
1121 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1123 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1124 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1125 d
<< " " << token
<< ": integer overflow (int64_t).");
1131 parseBytesLine(size_t * bptr
, const char *units
)
1138 if ((u
= parseBytesUnits(units
)) == 0) {
1143 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1148 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1149 *bptr
= static_cast<size_t>(-1);
1155 m
= u
; /* default to 'units' if none specified */
1159 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1160 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1161 config_input_line
<< "', assuming " <<
1162 d
<< " " << units
);
1163 else if ((m
= parseBytesUnits(token
)) == 0) {
1168 *bptr
= static_cast<size_t>(m
* d
/ u
);
1170 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1171 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1172 d
<< " " << token
<< ": integer overflow (size_t).");
1179 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1186 if ((u
= parseBytesUnits(units
)) == 0) {
1191 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1196 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1203 m
= u
; /* default to 'units' if none specified */
1207 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1208 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1209 config_input_line
<< "', assuming " <<
1210 d
<< " " << units
);
1211 else if ((m
= parseBytesUnits(token
)) == 0) {
1216 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1218 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1219 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1220 d
<< " " << token
<< ": integer overflow (ssize_t).");
1228 * Parse bytes from a string.
1229 * Similar to the parseBytesLine function but parses the string value instead of
1230 * the current token value.
1232 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1235 if ((u
= parseBytesUnits(units
)) == 0) {
1240 // Find number from string beginning.
1241 char const * number_begin
= value
;
1242 char const * number_end
= value
;
1244 while ((*number_end
>= '0' && *number_end
<= '9')) {
1249 number
.limitInit(number_begin
, number_end
- number_begin
);
1251 int d
= xatoi(number
.termedBuf());
1253 if ((m
= parseBytesUnits(number_end
)) == 0) {
1258 *bptr
= static_cast<size_t>(m
* d
/ u
);
1259 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1265 parseBytesUnits(const char *unit
)
1267 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1270 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1273 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1276 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1279 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1284 /*****************************************************************************
1286 *****************************************************************************/
1289 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1294 while (ae
!= NULL
) {
1295 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1296 storeAppendPrintf(entry
, "%s %s %s %s ",
1300 ae
->flags
.flagsStr());
1304 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1305 storeAppendPrintf(entry
, "%s ", v
->key
);
1309 storeAppendPrintf(entry
, "\n");
1310 wordlistDestroy(&w
);
1316 parse_acl(ACL
** ae
)
1318 ACL::ParseAclLine(LegacyParser
, ae
);
1328 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1332 for (l
= head
; l
; l
= l
->next
) {
1333 storeAppendPrintf(entry
, " %s%s",
1334 l
->op
? null_string
: "!",
1340 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1344 for (l
= head
; l
; l
= l
->next
) {
1345 storeAppendPrintf(entry
, "%s %s",
1347 l
->allow
? "Allow" : "Deny");
1348 dump_acl_list(entry
, l
->aclList
);
1349 storeAppendPrintf(entry
, "\n");
1354 parse_acl_access(acl_access
** head
)
1356 aclParseAccessLine(LegacyParser
, head
);
1360 free_acl_access(acl_access
** head
)
1362 aclDestroyAccessList(head
);
1366 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1368 char buf
[MAX_IPSTRLEN
];
1369 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1373 parse_address(Ip::Address
*addr
)
1375 char *token
= strtok(NULL
, w_space
);
1382 if (!strcmp(token
,"any_addr"))
1384 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1386 else if ( (*addr
= token
) ) // try parse numeric/IPA
1389 addr
->GetHostByName(token
); // dont use ipcache
1393 free_address(Ip::Address
*addr
)
1398 CBDATA_TYPE(AclAddress
);
1401 dump_acl_address(StoreEntry
* entry
, const char *name
, AclAddress
* head
)
1403 char buf
[MAX_IPSTRLEN
];
1406 for (l
= head
; l
; l
= l
->next
) {
1407 if (!l
->addr
.IsAnyAddr())
1408 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1410 storeAppendPrintf(entry
, "%s autoselect", name
);
1412 dump_acl_list(entry
, l
->aclList
);
1414 storeAppendPrintf(entry
, "\n");
1419 freed_acl_address(void *data
)
1421 AclAddress
*l
= static_cast<AclAddress
*>(data
);
1422 aclDestroyAclList(&l
->aclList
);
1426 parse_acl_address(AclAddress
** head
)
1429 AclAddress
**tail
= head
; /* sane name below */
1430 CBDATA_INIT_TYPE_FREECB(AclAddress
, freed_acl_address
);
1431 l
= cbdataAlloc(AclAddress
);
1432 parse_address(&l
->addr
);
1433 aclParseAclList(LegacyParser
, &l
->aclList
);
1436 tail
= &(*tail
)->next
;
1442 free_acl_address(AclAddress
** head
)
1445 AclAddress
*l
= *head
;
1451 CBDATA_TYPE(acl_tos
);
1454 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1458 for (l
= head
; l
; l
= l
->next
) {
1460 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1462 storeAppendPrintf(entry
, "%s none", name
);
1464 dump_acl_list(entry
, l
->aclList
);
1466 storeAppendPrintf(entry
, "\n");
1471 freed_acl_tos(void *data
)
1473 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1474 aclDestroyAclList(&l
->aclList
);
1478 parse_acl_tos(acl_tos
** head
)
1481 acl_tos
**tail
= head
; /* sane name below */
1482 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1483 char *token
= strtok(NULL
, w_space
);
1490 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1495 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1497 l
= cbdataAlloc(acl_tos
);
1499 l
->tos
= (tos_t
)tos
;
1501 aclParseAclList(LegacyParser
, &l
->aclList
);
1504 tail
= &(*tail
)->next
;
1510 free_acl_tos(acl_tos
** head
)
1520 #if SO_MARK && USE_LIBCAP
1522 CBDATA_TYPE(acl_nfmark
);
1525 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1529 for (l
= head
; l
; l
= l
->next
) {
1531 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1533 storeAppendPrintf(entry
, "%s none", name
);
1535 dump_acl_list(entry
, l
->aclList
);
1537 storeAppendPrintf(entry
, "\n");
1542 freed_acl_nfmark(void *data
)
1544 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1545 aclDestroyAclList(&l
->aclList
);
1549 parse_acl_nfmark(acl_nfmark
** head
)
1552 acl_nfmark
**tail
= head
; /* sane name below */
1554 char *token
= strtok(NULL
, w_space
);
1561 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1566 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1568 l
= cbdataAlloc(acl_nfmark
);
1572 aclParseAclList(LegacyParser
, &l
->aclList
);
1575 tail
= &(*tail
)->next
;
1581 free_acl_nfmark(acl_nfmark
** head
)
1584 acl_nfmark
*l
= *head
;
1590 #endif /* SO_MARK */
1592 CBDATA_TYPE(AclSizeLimit
);
1595 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1599 for (l
= head
; l
; l
= l
->next
) {
1601 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1603 storeAppendPrintf(entry
, "%s none", name
);
1605 dump_acl_list(entry
, l
->aclList
);
1607 storeAppendPrintf(entry
, "\n");
1612 freed_acl_b_size_t(void *data
)
1614 AclSizeLimit
*l
= static_cast<AclSizeLimit
*>(data
);
1615 aclDestroyAclList(&l
->aclList
);
1619 parse_acl_b_size_t(AclSizeLimit
** head
)
1622 AclSizeLimit
**tail
= head
; /* sane name below */
1624 CBDATA_INIT_TYPE_FREECB(AclSizeLimit
, freed_acl_b_size_t
);
1626 l
= cbdataAlloc(AclSizeLimit
);
1628 parse_b_int64_t(&l
->size
);
1630 aclParseAclList(LegacyParser
, &l
->aclList
);
1633 tail
= &(*tail
)->next
;
1639 free_acl_b_size_t(AclSizeLimit
** head
)
1642 AclSizeLimit
*l
= *head
;
1651 #include "DelayPools.h"
1652 #include "DelayConfig.h"
1653 /* do nothing - free_delay_pool_count is the magic free function.
1654 * this is why delay_pool_count isn't just marked TYPE: u_short
1656 #define free_delay_pool_class(X)
1657 #define free_delay_pool_access(X)
1658 #define free_delay_pool_rates(X)
1659 #define dump_delay_pool_class(X, Y, Z)
1660 #define dump_delay_pool_access(X, Y, Z)
1661 #define dump_delay_pool_rates(X, Y, Z)
1664 free_delay_pool_count(DelayConfig
* cfg
)
1666 cfg
->freePoolCount();
1670 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1672 cfg
.dumpPoolCount (entry
, name
);
1676 parse_delay_pool_count(DelayConfig
* cfg
)
1678 cfg
->parsePoolCount();
1682 parse_delay_pool_class(DelayConfig
* cfg
)
1684 cfg
->parsePoolClass();
1688 parse_delay_pool_rates(DelayConfig
* cfg
)
1690 cfg
->parsePoolRates();
1694 parse_delay_pool_access(DelayConfig
* cfg
)
1696 cfg
->parsePoolAccess(LegacyParser
);
1702 #include "ClientDelayConfig.h"
1703 /* do nothing - free_client_delay_pool_count is the magic free function.
1704 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1707 #define free_client_delay_pool_access(X)
1708 #define free_client_delay_pool_rates(X)
1709 #define dump_client_delay_pool_access(X, Y, Z)
1710 #define dump_client_delay_pool_rates(X, Y, Z)
1713 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1715 cfg
->freePoolCount();
1719 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1721 cfg
.dumpPoolCount (entry
, name
);
1725 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1727 cfg
->parsePoolCount();
1731 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1733 cfg
->parsePoolRates();
1737 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1739 cfg
->parsePoolAccess(LegacyParser
);
1743 #if USE_HTTP_VIOLATIONS
1745 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1748 manglers
->dumpAccess(entry
, name
);
1752 parse_http_header_access(HeaderManglers
**pm
)
1756 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1757 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1758 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1763 *pm
= new HeaderManglers
;
1764 HeaderManglers
*manglers
= *pm
;
1765 headerMangler
*mangler
= manglers
->track(t
);
1767 parse_acl_access(&mangler
->access_list
);
1771 free_HeaderManglers(HeaderManglers
**pm
)
1773 // we delete the entire http_header_* mangler configuration at once
1774 if (const HeaderManglers
*manglers
= *pm
) {
1781 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1784 manglers
->dumpReplacement(entry
, name
);
1788 parse_http_header_replace(HeaderManglers
**pm
)
1792 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1793 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1794 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1798 const char *value
= t
+ strlen(t
) + 1;
1801 *pm
= new HeaderManglers
;
1802 HeaderManglers
*manglers
= *pm
;
1803 manglers
->setReplacement(t
, value
);
1809 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1815 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1816 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1818 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1820 storeAppendPrintf(entry
, "\n");
1825 check_null_string(char *s
)
1832 parse_authparam(Auth::ConfigVector
* config
)
1837 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1840 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1843 /* find a configuration for the scheme in the currently parsed configs... */
1844 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1846 if (schemeCfg
== NULL
) {
1847 /* Create a configuration based on the scheme info */
1848 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1850 if (theScheme
== NULL
) {
1851 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1855 config
->push_back(theScheme
->createConfig());
1856 schemeCfg
= Auth::Config::Find(type_str
);
1857 if (schemeCfg
== NULL
) {
1858 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1863 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1867 free_authparam(Auth::ConfigVector
* cfg
)
1869 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1872 /* remove our pointers to the probably-dead sub-configs */
1873 while (cfg
->size()) {
1877 /* on reconfigure initialize new auth schemes for the new config. */
1878 if (reconfiguring
) {
1884 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1886 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1887 (*i
)->dump(entry
, name
, (*i
));
1889 #endif /* USE_AUTH */
1891 /* TODO: just return the object, the # is irrelevant */
1893 find_fstype(char *type
)
1895 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1896 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1903 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1907 RefCount
<SwapDir
> sd
;
1911 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1914 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1917 fs
= find_fstype(type_str
);
1922 /* reconfigure existing dir */
1924 for (i
= 0; i
< swap
->n_configured
; ++i
) {
1925 assert (swap
->swapDirs
[i
].getRaw());
1927 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1928 /* this is specific to on-fs Stores. The right
1929 * way to handle this is probably to have a mapping
1930 * from paths to stores, and have on-fs stores
1931 * register with that, and lookip in that in their
1932 * own setup logic. RBC 20041225. TODO.
1935 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1937 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().items
[fs
]->type()) != 0) {
1938 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1939 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1945 update_maxobjsize();
1952 if (swap
->n_configured
> 63) {
1953 /* 7 bits, signed */
1954 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1955 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1960 allocate_new_swapdir(swap
);
1962 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1964 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1966 /* parse the FS parameters and options */
1967 sd
->parse(swap
->n_configured
, path_str
);
1969 ++swap
->n_configured
;
1971 /* Update the max object size */
1972 update_maxobjsize();
1976 peer_type_str(const peer_t type
)
1978 const char * result
;
1990 case PEER_MULTICAST
:
1991 result
= "multicast";
2003 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2005 CachePeerDomainList
*d
;
2006 NeighborTypeDomainList
*t
;
2007 LOCAL_ARRAY(char, xname
, 128);
2010 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2017 dump_peer_options(entry
, p
);
2019 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2020 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2022 d
->do_ping
? null_string
: "!",
2027 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2028 dump_acl_access(entry
, xname
, p
->access
);
2031 for (t
= p
->typelist
; t
; t
= t
->next
) {
2032 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2034 peer_type_str(t
->type
),
2043 * utility function to prevent getservbyname() being called with a numeric value
2044 * on Windows at least it returns garage results.
2047 isUnsignedNumeric(const char *str
, size_t len
)
2049 if (len
< 1) return false;
2051 for (; len
>0 && *str
; ++str
, --len
) {
2052 if (! isdigit(*str
))
2059 \param proto 'tcp' or 'udp' for protocol
2060 \returns Port the named service is supposed to be listening on.
2062 static unsigned short
2063 GetService(const char *proto
)
2065 struct servent
*port
= NULL
;
2066 /** Parses a port number or service name from the squid.conf */
2067 char *token
= strtok(NULL
, w_space
);
2068 if (token
== NULL
) {
2070 return 0; /* NEVER REACHED */
2072 /** Returns either the service port number from /etc/services */
2073 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2074 port
= getservbyname(token
, proto
);
2076 return ntohs((unsigned short)port
->s_port
);
2078 /** Or a numeric translation of the config text. */
2079 return xatos(token
);
2083 \returns Port the named TCP service is supposed to be listening on.
2084 \copydoc GetService(const char *proto)
2086 inline unsigned short
2089 return GetService("tcp");
2093 \returns Port the named UDP service is supposed to be listening on.
2094 \copydoc GetService(const char *proto)
2096 inline unsigned short
2099 return GetService("udp");
2103 parse_peer(CachePeer
** head
)
2107 CBDATA_INIT_TYPE_FREECB(CachePeer
, peerDestroy
);
2108 p
= cbdataAlloc(CachePeer
);
2109 p
->http_port
= CACHE_HTTP_PORT
;
2110 p
->icp
.port
= CACHE_ICP_PORT
;
2113 p
->stats
.logged_state
= PEER_ALIVE
;
2115 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2118 p
->host
= xstrdup(token
);
2120 p
->name
= xstrdup(token
);
2122 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2125 p
->type
= parseNeighborType(token
);
2127 if (p
->type
== PEER_MULTICAST
) {
2128 p
->options
.no_digest
= true;
2129 p
->options
.no_netdb_exchange
= true;
2132 p
->http_port
= GetTcpService();
2137 p
->icp
.port
= GetUdpService();
2138 p
->connection_auth
= 2; /* auto */
2140 while ((token
= strtok(NULL
, w_space
))) {
2141 if (!strcasecmp(token
, "proxy-only")) {
2142 p
->options
.proxy_only
= true;
2143 } else if (!strcasecmp(token
, "no-query")) {
2144 p
->options
.no_query
= true;
2145 } else if (!strcasecmp(token
, "background-ping")) {
2146 p
->options
.background_ping
= true;
2147 } else if (!strcasecmp(token
, "no-digest")) {
2148 p
->options
.no_digest
= true;
2149 } else if (!strcasecmp(token
, "no-tproxy")) {
2150 p
->options
.no_tproxy
= true;
2151 } else if (!strcasecmp(token
, "multicast-responder")) {
2152 p
->options
.mcast_responder
= true;
2153 #if PEER_MULTICAST_SIBLINGS
2154 } else if (!strcasecmp(token
, "multicast-siblings")) {
2155 p
->options
.mcast_siblings
= true;
2157 } else if (!strncasecmp(token
, "weight=", 7)) {
2158 p
->weight
= xatoi(token
+ 7);
2159 } else if (!strncasecmp(token
, "basetime=", 9)) {
2160 p
->basetime
= xatoi(token
+ 9);
2161 } else if (!strcasecmp(token
, "closest-only")) {
2162 p
->options
.closest_only
= true;
2163 } else if (!strncasecmp(token
, "ttl=", 4)) {
2164 p
->mcast
.ttl
= xatoi(token
+ 4);
2166 if (p
->mcast
.ttl
< 0)
2169 if (p
->mcast
.ttl
> 128)
2171 } else if (!strcasecmp(token
, "default")) {
2172 p
->options
.default_parent
= true;
2173 } else if (!strcasecmp(token
, "round-robin")) {
2174 p
->options
.roundrobin
= true;
2175 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2176 p
->options
.weighted_roundrobin
= true;
2178 } else if (!strcasecmp(token
, "htcp")) {
2179 p
->options
.htcp
= true;
2180 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2181 /* Note: The htcp- form is deprecated, replaced by htcp= */
2182 p
->options
.htcp
= true;
2183 char *tmp
= xstrdup(token
+5);
2184 char *mode
, *nextmode
;
2185 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2186 nextmode
= strchr(mode
, ',');
2191 if (!strcasecmp(mode
, "no-clr")) {
2192 if (p
->options
.htcp_only_clr
)
2193 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2194 p
->options
.htcp_no_clr
= true;
2195 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2196 p
->options
.htcp_no_purge_clr
= true;
2197 } else if (!strcasecmp(mode
, "only-clr")) {
2198 if (p
->options
.htcp_no_clr
)
2199 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2200 p
->options
.htcp_only_clr
= true;
2201 } else if (!strcasecmp(mode
, "forward-clr")) {
2202 p
->options
.htcp_forward_clr
= true;
2203 } else if (!strcasecmp(mode
, "oldsquid")) {
2204 p
->options
.htcp_oldsquid
= true;
2206 fatalf("invalid HTCP mode '%s'", mode
);
2211 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2212 p
->options
.no_netdb_exchange
= true;
2214 } else if (!strcasecmp(token
, "carp")) {
2215 if (p
->type
!= PEER_PARENT
)
2216 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2218 p
->options
.carp
= true;
2219 } else if (!strncasecmp(token
, "carp-key=", 9)) {
2220 if (p
->options
.carp
!= true)
2221 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2222 p
->options
.carp_key
.set
= true;
2223 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2224 for (; key
; key
= nextkey
) {
2225 nextkey
=strchr(key
,',');
2226 if (nextkey
) ++nextkey
; // skip the comma, any
2227 if (0==strncasecmp(key
,"scheme",6)) {
2228 p
->options
.carp_key
.scheme
= true;
2229 } else if (0==strncasecmp(key
,"host",4)) {
2230 p
->options
.carp_key
.host
= true;
2231 } else if (0==strncasecmp(key
,"port",4)) {
2232 p
->options
.carp_key
.port
= true;
2233 } else if (0==strncasecmp(key
,"path",4)) {
2234 p
->options
.carp_key
.path
= true;
2235 } else if (0==strncasecmp(key
,"params",6)) {
2236 p
->options
.carp_key
.params
= true;
2238 fatalf("invalid carp-key '%s'",key
);
2241 } else if (!strcasecmp(token
, "userhash")) {
2243 if (p
->type
!= PEER_PARENT
)
2244 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2246 p
->options
.userhash
= true;
2248 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2250 } else if (!strcasecmp(token
, "sourcehash")) {
2251 if (p
->type
!= PEER_PARENT
)
2252 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2254 p
->options
.sourcehash
= true;
2256 } else if (!strcasecmp(token
, "no-delay")) {
2258 p
->options
.no_delay
= true;
2260 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2262 } else if (!strncasecmp(token
, "login=", 6)) {
2263 p
->login
= xstrdup(token
+ 6);
2264 rfc1738_unescape(p
->login
);
2265 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2266 p
->connect_timeout
= xatoi(token
+ 16);
2267 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2268 p
->connect_fail_limit
= xatoi(token
+ 19);
2269 #if USE_CACHE_DIGESTS
2270 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2271 p
->digest_url
= xstrdup(token
+ 11);
2274 } else if (!strcasecmp(token
, "allow-miss")) {
2275 p
->options
.allow_miss
= true;
2276 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2277 p
->max_conn
= xatoi(token
+ 9);
2278 } else if (!strcasecmp(token
, "originserver")) {
2279 p
->options
.originserver
= true;
2280 } else if (!strncasecmp(token
, "name=", 5)) {
2284 p
->name
= xstrdup(token
+ 5);
2285 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2286 safe_free(p
->domain
);
2289 p
->domain
= xstrdup(token
+ 13);
2293 } else if (strcmp(token
, "ssl") == 0) {
2295 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2296 safe_free(p
->sslcert
);
2297 p
->sslcert
= xstrdup(token
+ 8);
2298 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2299 safe_free(p
->sslkey
);
2300 p
->sslkey
= xstrdup(token
+ 7);
2301 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2302 p
->sslversion
= xatoi(token
+ 11);
2303 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2304 safe_free(p
->ssloptions
);
2305 p
->ssloptions
= xstrdup(token
+ 11);
2306 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2307 safe_free(p
->sslcipher
);
2308 p
->sslcipher
= xstrdup(token
+ 10);
2309 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2310 safe_free(p
->sslcafile
);
2311 p
->sslcafile
= xstrdup(token
+ 10);
2312 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2313 safe_free(p
->sslcapath
);
2314 p
->sslcapath
= xstrdup(token
+ 10);
2315 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2316 safe_free(p
->sslcrlfile
);
2317 p
->sslcrlfile
= xstrdup(token
+ 11);
2318 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2319 safe_free(p
->sslflags
);
2320 p
->sslflags
= xstrdup(token
+ 9);
2321 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2322 safe_free(p
->ssldomain
);
2323 p
->ssldomain
= xstrdup(token
+ 10);
2326 } else if (strcmp(token
, "front-end-https") == 0) {
2327 p
->front_end_https
= 1;
2328 } else if (strcmp(token
, "front-end-https=on") == 0) {
2329 p
->front_end_https
= 1;
2330 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2331 p
->front_end_https
= 2;
2332 } else if (strcmp(token
, "connection-auth=off") == 0) {
2333 p
->connection_auth
= 0;
2334 } else if (strcmp(token
, "connection-auth") == 0) {
2335 p
->connection_auth
= 1;
2336 } else if (strcmp(token
, "connection-auth=on") == 0) {
2337 p
->connection_auth
= 1;
2338 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2339 p
->connection_auth
= 2;
2341 debugs(3, DBG_CRITICAL
, "parse_peer: token='" << token
<< "'");
2346 if (peerFindByName(p
->name
))
2347 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2352 if (p
->connect_fail_limit
< 1)
2353 p
->connect_fail_limit
= 10;
2355 p
->icp
.version
= ICP_VERSION_CURRENT
;
2357 p
->testing_now
= false;
2359 #if USE_CACHE_DIGESTS
2361 if (!p
->options
.no_digest
) {
2362 /* XXX This looks odd.. who has the original pointer
2365 PeerDigest
*pd
= peerDigestCreate(p
);
2366 p
->digest
= cbdataReference(pd
);
2371 p
->index
= ++Config
.npeers
;
2373 while (*head
!= NULL
)
2374 head
= &(*head
)->next
;
2382 free_peer(CachePeer
** P
)
2386 while ((p
= *P
) != NULL
) {
2388 #if USE_CACHE_DIGESTS
2390 cbdataReferenceDone(p
->digest
);
2400 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2404 while (list
!= NULL
) {
2405 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2406 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2408 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2410 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2411 storeAppendPrintf(entry
, " %s", w
->key
);
2414 storeAppendPrintf(entry
, "\n");
2420 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2422 char *passwd
= NULL
;
2423 wordlist
*actions
= NULL
;
2424 Mgr::ActionPasswordList
*p
;
2425 Mgr::ActionPasswordList
**P
;
2426 parse_string(&passwd
);
2427 parse_wordlist(&actions
);
2428 p
= new Mgr::ActionPasswordList
;
2430 p
->actions
= actions
;
2432 for (P
= head
; *P
; P
= &(*P
)->next
) {
2434 * See if any of the actions from this line already have a
2435 * password from previous lines. The password checking
2436 * routines in cache_manager.c take the the password from
2437 * the first Mgr::ActionPasswordList that contains the
2438 * requested action. Thus, we should warn users who might
2439 * think they can have two passwords for the same action.
2444 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2445 for (u
= actions
; u
; u
= u
->next
) {
2446 if (strcmp(w
->key
, u
->key
))
2449 debugs(0, DBG_CRITICAL
, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2458 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2460 Mgr::ActionPasswordList
*p
;
2462 while ((p
= *head
) != NULL
) {
2465 wordlistDestroy(&p
->actions
);
2471 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2475 while (var
!= NULL
) {
2476 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2478 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2479 storeAppendPrintf(entry
, " %s", a
->name
);
2481 storeAppendPrintf(entry
, "\n");
2488 parse_denyinfo(AclDenyInfoList
** var
)
2490 aclParseDenyInfoLine(var
);
2494 free_denyinfo(AclDenyInfoList
** list
)
2496 AclDenyInfoList
*a
= NULL
;
2497 AclDenyInfoList
*a_next
= NULL
;
2498 AclNameList
*l
= NULL
;
2499 AclNameList
*l_next
= NULL
;
2501 for (a
= *list
; a
; a
= a_next
) {
2502 for (l
= a
->acl_list
; l
; l
= l_next
) {
2504 memFree(l
, MEM_ACL_NAME_LIST
);
2509 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2517 parse_peer_access(void)
2522 if (!(host
= strtok(NULL
, w_space
)))
2525 if ((p
= peerFindByName(host
)) == NULL
) {
2526 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2530 aclParseAccessLine(LegacyParser
, &p
->access
);
2534 parse_hostdomain(void)
2537 char *domain
= NULL
;
2539 if (!(host
= strtok(NULL
, w_space
)))
2542 while ((domain
= strtok(NULL
, list_sep
))) {
2543 CachePeerDomainList
*l
= NULL
;
2544 CachePeerDomainList
**L
= NULL
;
2547 if ((p
= peerFindByName(host
)) == NULL
) {
2548 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2552 l
= static_cast<CachePeerDomainList
*>(xcalloc(1, sizeof(CachePeerDomainList
)));
2555 if (*domain
== '!') { /* check for !.edu */
2560 l
->domain
= xstrdup(domain
);
2562 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2568 parse_hostdomaintype(void)
2572 char *domain
= NULL
;
2574 if (!(host
= strtok(NULL
, w_space
)))
2577 if (!(type
= strtok(NULL
, w_space
)))
2580 while ((domain
= strtok(NULL
, list_sep
))) {
2581 NeighborTypeDomainList
*l
= NULL
;
2582 NeighborTypeDomainList
**L
= NULL
;
2585 if ((p
= peerFindByName(host
)) == NULL
) {
2586 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2590 l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2591 l
->type
= parseNeighborType(type
);
2592 l
->domain
= xstrdup(domain
);
2594 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2600 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2602 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2620 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2622 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2626 parse_onoff(int *var
)
2628 char *token
= strtok(NULL
, w_space
);
2633 if (!strcasecmp(token
, "on")) {
2635 } else if (!strcasecmp(token
, "enable")) {
2636 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2638 } else if (!strcasecmp(token
, "off")) {
2640 } else if (!strcasecmp(token
, "disable")) {
2641 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2644 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2649 #define free_onoff free_int
2652 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2663 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2667 parse_tristate(int *var
)
2669 char *token
= strtok(NULL
, w_space
);
2674 if (!strcasecmp(token
, "on")) {
2676 } else if (!strcasecmp(token
, "enable")) {
2677 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2679 } else if (!strcasecmp(token
, "warn")) {
2681 } else if (!strcasecmp(token
, "off")) {
2683 } else if (!strcasecmp(token
, "disable")) {
2684 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2687 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2692 #define free_tristate free_int
2695 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2697 while (head
!= NULL
) {
2698 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2700 head
->flags
.icase
? " -i" : null_string
,
2702 (int) head
->min
/ 60,
2703 (int) (100.0 * head
->pct
+ 0.5),
2704 (int) head
->max
/ 60);
2706 if (head
->max_stale
>= 0)
2707 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2709 if (head
->flags
.refresh_ims
)
2710 storeAppendPrintf(entry
, " refresh-ims");
2712 if (head
->flags
.store_stale
)
2713 storeAppendPrintf(entry
, " store-stale");
2715 #if USE_HTTP_VIOLATIONS
2717 if (head
->flags
.override_expire
)
2718 storeAppendPrintf(entry
, " override-expire");
2720 if (head
->flags
.override_lastmod
)
2721 storeAppendPrintf(entry
, " override-lastmod");
2723 if (head
->flags
.reload_into_ims
)
2724 storeAppendPrintf(entry
, " reload-into-ims");
2726 if (head
->flags
.ignore_reload
)
2727 storeAppendPrintf(entry
, " ignore-reload");
2729 if (head
->flags
.ignore_no_store
)
2730 storeAppendPrintf(entry
, " ignore-no-store");
2732 if (head
->flags
.ignore_must_revalidate
)
2733 storeAppendPrintf(entry
, " ignore-must-revalidate");
2735 if (head
->flags
.ignore_private
)
2736 storeAppendPrintf(entry
, " ignore-private");
2738 if (head
->flags
.ignore_auth
)
2739 storeAppendPrintf(entry
, " ignore-auth");
2743 storeAppendPrintf(entry
, "\n");
2750 parse_refreshpattern(RefreshPattern
** head
)
2757 int refresh_ims
= 0;
2758 int store_stale
= 0;
2761 #if USE_HTTP_VIOLATIONS
2763 int override_expire
= 0;
2764 int override_lastmod
= 0;
2765 int reload_into_ims
= 0;
2766 int ignore_reload
= 0;
2767 int ignore_no_store
= 0;
2768 int ignore_must_revalidate
= 0;
2769 int ignore_private
= 0;
2770 int ignore_auth
= 0;
2777 int flags
= REG_EXTENDED
| REG_NOSUB
;
2779 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2784 if (strcmp(token
, "-i") == 0) {
2786 token
= strtok(NULL
, w_space
);
2787 } else if (strcmp(token
, "+i") == 0) {
2788 flags
&= ~REG_ICASE
;
2789 token
= strtok(NULL
, w_space
);
2792 if (token
== NULL
) {
2797 pattern
= xstrdup(token
);
2799 i
= GetInteger(); /* token: min */
2801 /* catch negative and insanely huge values close to 32-bit wrap */
2803 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2806 if (i
> 60*24*365) {
2807 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2811 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2813 i
= GetPercentage(); /* token: pct */
2815 pct
= (double) i
/ 100.0;
2817 i
= GetInteger(); /* token: max */
2819 /* catch negative and insanely huge values close to 32-bit wrap */
2821 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2824 if (i
> 60*24*365) {
2825 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2829 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2832 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2833 if (!strcmp(token
, "refresh-ims")) {
2835 } else if (!strcmp(token
, "store-stale")) {
2837 } else if (!strncmp(token
, "max-stale=", 10)) {
2838 max_stale
= xatoi(token
+ 10);
2839 #if USE_HTTP_VIOLATIONS
2841 } else if (!strcmp(token
, "override-expire"))
2842 override_expire
= 1;
2843 else if (!strcmp(token
, "override-lastmod"))
2844 override_lastmod
= 1;
2845 else if (!strcmp(token
, "ignore-no-store"))
2846 ignore_no_store
= 1;
2847 else if (!strcmp(token
, "ignore-must-revalidate"))
2848 ignore_must_revalidate
= 1;
2849 else if (!strcmp(token
, "ignore-private"))
2851 else if (!strcmp(token
, "ignore-auth"))
2853 else if (!strcmp(token
, "reload-into-ims")) {
2854 reload_into_ims
= 1;
2855 refresh_nocache_hack
= 1;
2856 /* tell client_side.c that this is used */
2857 } else if (!strcmp(token
, "ignore-reload")) {
2859 refresh_nocache_hack
= 1;
2860 /* tell client_side.c that this is used */
2863 } else if (!strcmp(token
, "ignore-no-cache")) {
2864 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it.");
2866 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2869 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2871 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2872 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2873 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2877 pct
= pct
< 0.0 ? 0.0 : pct
;
2878 max
= max
< 0 ? 0 : max
;
2879 t
= static_cast<RefreshPattern
*>(xcalloc(1, sizeof(RefreshPattern
)));
2880 t
->pattern
= (char *) xstrdup(pattern
);
2881 t
->compiled_pattern
= comp
;
2886 if (flags
& REG_ICASE
)
2887 t
->flags
.icase
= true;
2890 t
->flags
.refresh_ims
= true;
2893 t
->flags
.store_stale
= true;
2895 t
->max_stale
= max_stale
;
2897 #if USE_HTTP_VIOLATIONS
2899 if (override_expire
)
2900 t
->flags
.override_expire
= true;
2902 if (override_lastmod
)
2903 t
->flags
.override_lastmod
= true;
2905 if (reload_into_ims
)
2906 t
->flags
.reload_into_ims
= true;
2909 t
->flags
.ignore_reload
= true;
2911 if (ignore_no_store
)
2912 t
->flags
.ignore_no_store
= true;
2914 if (ignore_must_revalidate
)
2915 t
->flags
.ignore_must_revalidate
= true;
2918 t
->flags
.ignore_private
= true;
2921 t
->flags
.ignore_auth
= true;
2928 head
= &(*head
)->next
;
2936 free_refreshpattern(RefreshPattern
** head
)
2940 while ((t
= *head
) != NULL
) {
2942 safe_free(t
->pattern
);
2943 regfree(&t
->compiled_pattern
);
2947 #if USE_HTTP_VIOLATIONS
2948 refresh_nocache_hack
= 0;
2954 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2957 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2961 parse_string(char **var
)
2963 char *token
= strtok(NULL
, w_space
);
2969 *var
= xstrdup(token
);
2973 ConfigParser::ParseString(char **var
)
2979 ConfigParser::ParseString(String
*var
)
2981 char *token
= strtok(NULL
, w_space
);
2990 free_string(char **var
)
2996 parse_eol(char *volatile *var
)
3003 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
3011 while (*token
&& xisspace(*token
))
3019 *var
= xstrdup((char *) token
);
3022 #define dump_eol dump_string
3023 #define free_eol free_string
3026 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3028 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3032 parse_time_t(time_t * var
)
3035 parseTimeLine(&tval
, T_SECOND_STR
, false);
3036 *var
= static_cast<time_t>(tval
/1000);
3040 free_time_t(time_t * var
)
3047 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3050 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3052 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3056 parse_time_msec(time_msec_t
* var
)
3058 parseTimeLine(var
, T_SECOND_STR
, true);
3062 free_time_msec(time_msec_t
* var
)
3070 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3072 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3077 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3079 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3084 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3086 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3092 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3094 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3099 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3101 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3105 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3107 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3112 parse_size_t(size_t * var
)
3121 parse_b_size_t(size_t * var
)
3123 parseBytesLine(var
, B_BYTES_STR
);
3128 parse_b_ssize_t(ssize_t
* var
)
3130 parseBytesLineSigned(var
, B_BYTES_STR
);
3136 parse_kb_size_t(size_t * var
)
3138 parseBytesLine(var
, B_KBYTES_STR
);
3143 parse_b_int64_t(int64_t * var
)
3145 parseBytesLine64(var
, B_BYTES_STR
);
3149 parse_kb_int64_t(int64_t * var
)
3151 parseBytesLine64(var
, B_KBYTES_STR
);
3155 free_size_t(size_t * var
)
3162 free_ssize_t(ssize_t
* var
)
3169 free_b_int64_t(int64_t * var
)
3174 #define free_b_size_t free_size_t
3175 #define free_b_ssize_t free_ssize_t
3176 #define free_kb_size_t free_size_t
3177 #define free_mb_size_t free_size_t
3178 #define free_gb_size_t free_size_t
3179 #define free_kb_int64_t free_b_int64_t
3182 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3184 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3188 free_u_short(unsigned short * u
)
3194 parse_u_short(unsigned short * var
)
3196 ConfigParser::ParseUShort(var
);
3200 ConfigParser::ParseUShort(unsigned short *var
)
3206 ConfigParser::ParseBool(bool *var
)
3208 int i
= GetInteger();
3219 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3221 while (list
!= NULL
) {
3222 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3228 ConfigParser::ParseWordList(wordlist
** list
)
3230 parse_wordlist(list
);
3234 parse_wordlist(wordlist
** list
)
3237 char *t
= strtok(NULL
, "");
3239 while ((token
= strwordtok(NULL
, &t
)))
3240 wordlistAdd(list
, token
);
3243 #if 0 /* now unused */
3245 check_null_wordlist(wordlist
* w
)
3252 check_null_acl_access(acl_access
* a
)
3257 #define free_wordlist wordlistDestroy
3259 #define free_uri_whitespace free_int
3262 parse_uri_whitespace(int *var
)
3264 char *token
= strtok(NULL
, w_space
);
3269 if (!strcasecmp(token
, "strip"))
3270 *var
= URI_WHITESPACE_STRIP
;
3271 else if (!strcasecmp(token
, "deny"))
3272 *var
= URI_WHITESPACE_DENY
;
3273 else if (!strcasecmp(token
, "allow"))
3274 *var
= URI_WHITESPACE_ALLOW
;
3275 else if (!strcasecmp(token
, "encode"))
3276 *var
= URI_WHITESPACE_ENCODE
;
3277 else if (!strcasecmp(token
, "chop"))
3278 *var
= URI_WHITESPACE_CHOP
;
3280 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3286 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3290 if (var
== URI_WHITESPACE_ALLOW
)
3292 else if (var
== URI_WHITESPACE_ENCODE
)
3294 else if (var
== URI_WHITESPACE_CHOP
)
3296 else if (var
== URI_WHITESPACE_DENY
)
3301 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3305 free_removalpolicy(RemovalPolicySettings
** settings
)
3310 free_string(&(*settings
)->type
);
3312 free_wordlist(&(*settings
)->args
);
3320 parse_removalpolicy(RemovalPolicySettings
** settings
)
3323 free_removalpolicy(settings
);
3325 *settings
= new RemovalPolicySettings
;
3327 parse_string(&(*settings
)->type
);
3329 parse_wordlist(&(*settings
)->args
);
3333 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3336 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3337 args
= settings
->args
;
3340 storeAppendPrintf(entry
, " %s", args
->key
);
3344 storeAppendPrintf(entry
, "\n");
3348 free_YesNoNone(YesNoNone
*)
3350 // do nothing: no explicit cleanup is required
3354 parse_YesNoNone(YesNoNone
*option
)
3357 parse_onoff(&value
);
3358 option
->configure(value
> 0);
3362 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3364 if (option
.configured())
3365 dump_onoff(entry
, name
, option
? 1 : 0);
3369 free_memcachemode(SquidConfig
* config
)
3375 parse_memcachemode(SquidConfig
* config
)
3377 char *token
= strtok(NULL
, w_space
);
3381 if (strcmp(token
, "always") == 0) {
3382 Config
.onoff
.memory_cache_first
= 1;
3383 Config
.onoff
.memory_cache_disk
= 1;
3384 } else if (strcmp(token
, "disk") == 0) {
3385 Config
.onoff
.memory_cache_first
= 0;
3386 Config
.onoff
.memory_cache_disk
= 1;
3387 } else if (strncmp(token
, "net", 3) == 0) {
3388 Config
.onoff
.memory_cache_first
= 1;
3389 Config
.onoff
.memory_cache_disk
= 0;
3390 } else if (strcmp(token
, "never") == 0) {
3391 Config
.onoff
.memory_cache_first
= 0;
3392 Config
.onoff
.memory_cache_disk
= 0;
3394 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3400 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3402 storeAppendPrintf(entry
, "%s ", name
);
3403 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3404 storeAppendPrintf(entry
, "always");
3405 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3406 storeAppendPrintf(entry
, "disk");
3407 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3408 storeAppendPrintf(entry
, "network");
3409 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3410 storeAppendPrintf(entry
, "none");
3411 storeAppendPrintf(entry
, "\n");
3414 #include "cf_parser.cci"
3417 parseNeighborType(const char *s
)
3419 if (!strcasecmp(s
, "parent"))
3422 if (!strcasecmp(s
, "neighbor"))
3423 return PEER_SIBLING
;
3425 if (!strcasecmp(s
, "neighbour"))
3426 return PEER_SIBLING
;
3428 if (!strcasecmp(s
, "sibling"))
3429 return PEER_SIBLING
;
3431 if (!strcasecmp(s
, "multicast"))
3432 return PEER_MULTICAST
;
3434 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3436 return PEER_SIBLING
;
3441 parse_IpAddress_list(Ip::Address_list
** head
)
3444 Ip::Address_list
*s
;
3447 while ((token
= strtok(NULL
, w_space
))) {
3448 if (GetHostWithPort(token
, &ipa
)) {
3451 head
= &(*head
)->next
;
3453 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3463 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3465 char ntoabuf
[MAX_IPSTRLEN
];
3468 storeAppendPrintf(e
, "%s %s\n",
3470 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3476 free_IpAddress_list(Ip::Address_list
** head
)
3478 if (*head
) delete *head
;
3482 #if CURRENTLY_UNUSED
3483 /* This code was previously used by http_port. Left as it really should
3484 * be used by icp_port and htcp_port
3487 check_null_IpAddress_list(const Ip::Address_list
* s
)
3492 #endif /* CURRENTLY_UNUSED */
3493 #endif /* USE_WCCPv2 */
3496 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3499 unsigned short port
= 0;
3503 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3504 s
->name
= xstrdup(token
);
3505 s
->connection_auth_disabled
= false;
3507 if (*token
== '[') {
3510 t
= strchr(host
, ']');
3512 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing ']' on IPv6 address: " << token
);
3518 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port in: " << token
);
3521 if (!Ip::EnableIpv6
) {
3522 debugs(3, DBG_CRITICAL
, "FATAL: " << s
->protocol
<< "_port: IPv6 is not available.");
3525 port
= xatos(t
+ 1);
3526 } else if ((t
= strchr(token
, ':'))) {
3531 port
= xatos(t
+ 1);
3533 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3534 port
= xatos(token
);
3535 debugs(3, 3, s
->protocol
<< "_port: found Listen on Port: " << port
);
3537 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port: " << token
);
3541 if (port
== 0 && host
!= NULL
) {
3542 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: Port cannot be 0: " << token
);
3549 if (!Ip::EnableIpv6
)
3551 debugs(3, 3, s
->protocol
<< "_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3552 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3554 if (!Ip::EnableIpv6
)
3556 debugs(3, 3, s
->protocol
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3557 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3558 /* dont use ipcache */
3559 s
->defaultsite
= xstrdup(host
);
3561 if (!Ip::EnableIpv6
)
3563 debugs(3, 3, s
->protocol
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3565 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: failed to resolve Host/IP: " << host
);
3571 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3575 if (strcmp(token
, "accel") == 0) {
3576 if (s
->flags
.isIntercepted()) {
3577 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3580 s
->flags
.accelSurrogate
= true;
3582 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3583 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3584 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3587 s
->flags
.natIntercept
= true;
3588 Ip::Interceptor
.StartInterception();
3589 /* Log information regarding the port modes under interception. */
3590 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3591 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3593 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3595 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3596 if ( !s
->s
.SetIPv4() ) {
3597 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s
->s
);
3600 } else if (strcmp(token
, "tproxy") == 0) {
3601 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3602 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3605 s
->flags
.tproxyIntercept
= true;
3606 Ip::Interceptor
.StartTransparency();
3607 /* Log information regarding the port modes under transparency. */
3608 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3609 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3611 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3612 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3616 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3617 if (!s
->flags
.accelSurrogate
) {
3618 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3621 safe_free(s
->defaultsite
);
3622 s
->defaultsite
= xstrdup(token
+ 12);
3623 } else if (strcmp(token
, "vhost") == 0) {
3624 if (!s
->flags
.accelSurrogate
) {
3625 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3627 s
->flags
.accelSurrogate
= true;
3629 } else if (strcmp(token
, "no-vhost") == 0) {
3630 if (!s
->flags
.accelSurrogate
) {
3631 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3634 } else if (strcmp(token
, "vport") == 0) {
3635 if (!s
->flags
.accelSurrogate
) {
3636 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3640 } else if (strncmp(token
, "vport=", 6) == 0) {
3641 if (!s
->flags
.accelSurrogate
) {
3642 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3645 s
->vport
= xatos(token
+ 6);
3646 } else if (strncmp(token
, "protocol=", 9) == 0) {
3647 if (!s
->flags
.accelSurrogate
) {
3648 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3651 s
->protocol
= xstrdup(token
+ 9);
3652 } else if (strcmp(token
, "allow-direct") == 0) {
3653 if (!s
->flags
.accelSurrogate
) {
3654 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3657 s
->allow_direct
= 1;
3658 } else if (strcmp(token
, "act-as-origin") == 0) {
3659 if (!s
->flags
.accelSurrogate
) {
3660 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3663 } else if (strcmp(token
, "ignore-cc") == 0) {
3664 #if !USE_HTTP_VIOLATIONS
3665 if (!s
->flags
.accelSurrogate
) {
3666 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Acceleration mode flag.");
3671 } else if (strncmp(token
, "name=", 5) == 0) {
3673 s
->name
= xstrdup(token
+ 5);
3674 } else if (strcmp(token
, "no-connection-auth") == 0) {
3675 s
->connection_auth_disabled
= true;
3676 } else if (strcmp(token
, "connection-auth=off") == 0) {
3677 s
->connection_auth_disabled
= true;
3678 } else if (strcmp(token
, "connection-auth") == 0) {
3679 s
->connection_auth_disabled
= false;
3680 } else if (strcmp(token
, "connection-auth=on") == 0) {
3681 s
->connection_auth_disabled
= false;
3682 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3683 if (!strcasecmp(token
+ 23, "off"))
3684 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3685 else if (!strcasecmp(token
+ 23, "transparent"))
3686 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3687 else if (!strcasecmp(token
+ 23, "always"))
3688 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3691 } else if (strcmp(token
, "ipv4") == 0) {
3692 if ( !s
->s
.SetIPv4() ) {
3693 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3696 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3697 s
->tcp_keepalive
.enabled
= 1;
3698 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3699 char *t
= token
+ 13;
3700 s
->tcp_keepalive
.enabled
= 1;
3701 s
->tcp_keepalive
.idle
= xatoui(t
);
3705 s
->tcp_keepalive
.interval
= xatoui(t
);
3710 s
->tcp_keepalive
.timeout
= xatoui(t
);
3711 // t = strchr(t, ','); // not really needed, left in as documentation
3714 } else if (strcasecmp(token
, "sslBump") == 0) {
3715 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3716 "in http_port. Use 'ssl-bump' instead.");
3717 s
->flags
.tunnelSslBumping
= true;
3718 } else if (strcmp(token
, "ssl-bump") == 0) {
3719 s
->flags
.tunnelSslBumping
= true;
3720 } else if (strncmp(token
, "cert=", 5) == 0) {
3722 s
->cert
= xstrdup(token
+ 5);
3723 } else if (strncmp(token
, "key=", 4) == 0) {
3725 s
->key
= xstrdup(token
+ 4);
3726 } else if (strncmp(token
, "version=", 8) == 0) {
3727 s
->version
= xatoi(token
+ 8);
3728 if (s
->version
< 1 || s
->version
> 4)
3730 } else if (strncmp(token
, "options=", 8) == 0) {
3731 safe_free(s
->options
);
3732 s
->options
= xstrdup(token
+ 8);
3733 } else if (strncmp(token
, "cipher=", 7) == 0) {
3734 safe_free(s
->cipher
);
3735 s
->cipher
= xstrdup(token
+ 7);
3736 } else if (strncmp(token
, "clientca=", 9) == 0) {
3737 safe_free(s
->clientca
);
3738 s
->clientca
= xstrdup(token
+ 9);
3739 } else if (strncmp(token
, "cafile=", 7) == 0) {
3740 safe_free(s
->cafile
);
3741 s
->cafile
= xstrdup(token
+ 7);
3742 } else if (strncmp(token
, "capath=", 7) == 0) {
3743 safe_free(s
->capath
);
3744 s
->capath
= xstrdup(token
+ 7);
3745 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3746 safe_free(s
->crlfile
);
3747 s
->crlfile
= xstrdup(token
+ 8);
3748 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3749 safe_free(s
->dhfile
);
3750 s
->dhfile
= xstrdup(token
+ 9);
3751 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3752 safe_free(s
->sslflags
);
3753 s
->sslflags
= xstrdup(token
+ 9);
3754 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3755 safe_free(s
->sslContextSessionId
);
3756 s
->sslContextSessionId
= xstrdup(token
+ 11);
3757 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3758 s
->generateHostCertificates
= true;
3759 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3760 s
->generateHostCertificates
= true;
3761 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3762 s
->generateHostCertificates
= false;
3763 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3764 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3767 debugs(3, DBG_CRITICAL
, "FATAL: Unknown http(s)_port option '" << token
<< "'.");
3773 add_http_port(char *portspec
)
3775 AnyP::PortCfg
*s
= new AnyP::PortCfg("http_port");
3776 parsePortSpecification(s
, portspec
);
3777 // we may need to merge better if the above returns a list with clones
3778 assert(s
->next
== NULL
);
3779 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3780 cbdataReferenceDone(Config
.Sockaddr
.http
);
3781 Config
.Sockaddr
.http
= cbdataReference(s
);
3785 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3787 const char *protocol
= NULL
;
3788 if (strcmp(optionName
, "http_port") == 0 ||
3789 strcmp(optionName
, "ascii_port") == 0)
3791 else if (strcmp(optionName
, "https_port") == 0)
3798 char *token
= strtok(NULL
, w_space
);
3805 AnyP::PortCfg
*s
= new AnyP::PortCfg(protocol
);
3806 parsePortSpecification(s
, token
);
3808 /* parse options ... */
3809 while ((token
= strtok(NULL
, w_space
))) {
3810 parse_port_option(s
, token
);
3814 if (strcasecmp(protocol
, "https") == 0) {
3815 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3816 const bool hijacked
= s
->flags
.isIntercepted();
3817 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3818 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3821 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3822 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3828 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3829 // clone the port options from *s to *(s->next)
3830 s
->next
= cbdataReference(s
->clone());
3831 s
->next
->s
.SetIPv4();
3832 debugs(3, 3, protocol
<< "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3836 head
= &(*head
)->next
;
3838 *head
= cbdataReference(s
);
3842 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3844 char buf
[MAX_IPSTRLEN
];
3846 storeAppendPrintf(e
, "%s %s",
3848 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3850 // MODES and specific sub-options.
3851 if (s
->flags
.natIntercept
)
3852 storeAppendPrintf(e
, " intercept");
3854 else if (s
->flags
.tproxyIntercept
)
3855 storeAppendPrintf(e
, " tproxy");
3857 else if (s
->flags
.accelSurrogate
) {
3858 storeAppendPrintf(e
, " accel");
3861 storeAppendPrintf(e
, " vhost");
3864 storeAppendPrintf(e
, " vport");
3865 else if (s
->vport
> 0)
3866 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3869 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3871 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3872 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3874 if (s
->allow_direct
)
3875 storeAppendPrintf(e
, " allow-direct");
3878 storeAppendPrintf(e
, " ignore-cc");
3882 // Generic independent options
3885 storeAppendPrintf(e
, " name=%s", s
->name
);
3887 #if USE_HTTP_VIOLATIONS
3888 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3889 storeAppendPrintf(e
, " ignore-cc");
3892 if (s
->connection_auth_disabled
)
3893 storeAppendPrintf(e
, " connection-auth=off");
3895 storeAppendPrintf(e
, " connection-auth=on");
3897 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3900 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3903 pmtu
= "transparent";
3905 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3908 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3909 storeAppendPrintf(e
, " ipv4");
3911 if (s
->tcp_keepalive
.enabled
) {
3912 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3913 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3915 storeAppendPrintf(e
, " tcpkeepalive");
3920 if (s
->flags
.tunnelSslBumping
)
3921 storeAppendPrintf(e
, " ssl-bump");
3924 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3927 storeAppendPrintf(e
, " key=%s", s
->key
);
3930 storeAppendPrintf(e
, " version=%d", s
->version
);
3933 storeAppendPrintf(e
, " options=%s", s
->options
);
3936 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3939 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3942 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3945 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3948 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3951 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3953 if (s
->sslContextSessionId
)
3954 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3956 if (s
->generateHostCertificates
)
3957 storeAppendPrintf(e
, " generate-host-certificates");
3959 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3960 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3965 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3968 dump_generic_port(e
, n
, s
);
3969 storeAppendPrintf(e
, "\n");
3975 free_PortCfg(AnyP::PortCfg
** head
)
3979 while ((s
= *head
) != NULL
) {
3981 cbdataReferenceDone(s
);
3986 configFreeMemory(void)
3990 SSL_CTX_free(Config
.ssl_client
.sslContext
);
3995 requirePathnameExists(const char *name
, const char *path
)
3999 char pathbuf
[BUFSIZ
];
4000 assert(path
!= NULL
);
4002 if (Config
.chroot_dir
&& (geteuid() == 0)) {
4003 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4007 if (stat(path
, &sb
) < 0) {
4008 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
4009 // keep going to find more issues if we are only checking the config file with "-k parse"
4010 if (opt_parse_cfg_only
)
4012 // this is fatal if it is found during startup or reconfigure
4013 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4014 fatalf("%s %s: %s", name
, path
, xstrerror());
4021 return ConfigParser::strtokFile();
4024 #include "AccessLogEntry.h"
4027 parse_access_log(CustomLog
** logs
)
4029 const char *filename
, *logdef_name
;
4031 CustomLog
*cl
= (CustomLog
*)xcalloc(1, sizeof(*cl
));
4033 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
4038 if (strcmp(filename
, "none") == 0) {
4039 cl
->type
= Log::Format::CLF_NONE
;
4040 aclParseAclList(LegacyParser
, &cl
->aclList
);
4042 logs
= &(*logs
)->next
;
4047 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
4048 logdef_name
= "squid";
4050 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
4052 cl
->filename
= xstrdup(filename
);
4054 /* look for the definition pointer corresponding to this name */
4055 Format::Format
*lf
= Log::TheConfig
.logformats
;
4057 while (lf
!= NULL
) {
4058 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4060 if (strcmp(lf
->name
, logdef_name
) == 0)
4067 cl
->type
= Log::Format::CLF_CUSTOM
;
4069 } else if (strcmp(logdef_name
, "auto") == 0) {
4070 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4071 cl
->type
= Log::Format::CLF_SQUID
;
4072 } else if (strcmp(logdef_name
, "squid") == 0) {
4073 cl
->type
= Log::Format::CLF_SQUID
;
4074 } else if (strcmp(logdef_name
, "common") == 0) {
4075 cl
->type
= Log::Format::CLF_COMMON
;
4076 } else if (strcmp(logdef_name
, "combined") == 0) {
4077 cl
->type
= Log::Format::CLF_COMBINED
;
4079 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4080 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4082 } else if (strcmp(logdef_name
, "useragent") == 0) {
4083 cl
->type
= Log::Format::CLF_USERAGENT
;
4084 } else if (strcmp(logdef_name
, "referrer") == 0) {
4085 cl
->type
= Log::Format::CLF_REFERER
;
4087 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4092 aclParseAclList(LegacyParser
, &cl
->aclList
);
4095 logs
= &(*logs
)->next
;
4101 check_null_access_log(CustomLog
*customlog_definitions
)
4103 return customlog_definitions
== NULL
;
4107 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4111 for (log
= logs
; log
; log
= log
->next
) {
4112 storeAppendPrintf(entry
, "%s ", name
);
4114 switch (log
->type
) {
4116 case Log::Format::CLF_CUSTOM
:
4117 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4120 case Log::Format::CLF_NONE
:
4121 storeAppendPrintf(entry
, "none");
4124 case Log::Format::CLF_SQUID
:
4125 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4128 case Log::Format::CLF_COMBINED
:
4129 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4132 case Log::Format::CLF_COMMON
:
4133 storeAppendPrintf(entry
, "%s common", log
->filename
);
4137 case Log::Format::CLF_ICAP_SQUID
:
4138 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4141 case Log::Format::CLF_USERAGENT
:
4142 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4145 case Log::Format::CLF_REFERER
:
4146 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4149 case Log::Format::CLF_UNKNOWN
:
4154 dump_acl_list(entry
, log
->aclList
);
4156 storeAppendPrintf(entry
, "\n");
4161 free_access_log(CustomLog
** definitions
)
4163 while (*definitions
) {
4164 CustomLog
*log
= *definitions
;
4165 *definitions
= log
->next
;
4167 log
->logFormat
= NULL
;
4168 log
->type
= Log::Format::CLF_UNKNOWN
;
4171 aclDestroyAclList(&log
->aclList
);
4173 safe_free(log
->filename
);
4179 /// parses list of integers form name=N1,N2,N3,...
4181 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4183 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4184 data
+= name
.size();
4189 if (!StringToInt(data
, value
, &data
, 10))
4191 list
.push_back(value
);
4192 if (*data
== '\0' || *data
!= ',')
4197 return data
&& *data
== '\0';
4201 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4203 #if !HAVE_CPU_AFFINITY
4204 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4205 "support, do not set 'cpu_affinity_map'");
4207 #endif /* HAVE_CPU_AFFINITY */
4209 if (!*cpuAffinityMap
)
4210 *cpuAffinityMap
= new CpuAffinityMap
;
4212 const char *const pToken
= strtok(NULL
, w_space
);
4213 const char *const cToken
= strtok(NULL
, w_space
);
4214 Vector
<int> processes
, cores
;
4215 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4216 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4217 "in 'cpu_affinity_map'");
4219 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4220 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4221 "'cpu_affinity_map'");
4223 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4224 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4225 "process_numbers and cores lists differ in length or " <<
4226 "contain numbers <= 0");
4232 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4234 if (cpuAffinityMap
) {
4235 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4236 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4237 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4238 cpuAffinityMap
->processes()[i
]);
4240 storeAppendPrintf(entry
, " cores=");
4241 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4242 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4243 cpuAffinityMap
->cores()[i
]);
4245 storeAppendPrintf(entry
, "\n");
4250 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4252 delete *cpuAffinityMap
;
4253 *cpuAffinityMap
= NULL
;
4259 parse_adaptation_service_set_type()
4261 Adaptation::Config::ParseServiceSet();
4265 parse_adaptation_service_chain_type()
4267 Adaptation::Config::ParseServiceChain();
4271 parse_adaptation_access_type()
4273 Adaptation::Config::ParseAccess(LegacyParser
);
4275 #endif /* USE_ADAPTATION */
4280 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4282 cfg
->parseService();
4286 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4292 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4294 cfg
.dumpService(entry
, name
);
4298 parse_icap_class_type()
4300 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4301 "Use 'adaptation_service_set' instead");
4302 Adaptation::Config::ParseServiceSet();
4306 parse_icap_access_type()
4308 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4309 "Use 'adaptation_access' instead");
4310 Adaptation::Config::ParseAccess(LegacyParser
);
4318 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4320 cfg
->parseService();
4324 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4330 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4332 cfg
.dumpService(entry
, name
);
4335 #endif /* USE_ECAP */
4338 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4343 cfg
->service_failure_limit
= GetInteger();
4345 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4348 if (strcmp(token
,"in") != 0) {
4349 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4353 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4357 d
= static_cast<time_t> (xatoi(token
));
4359 m
= static_cast<time_t> (1);
4363 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4364 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4366 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4369 cfg
->oldest_service_failure
= (m
* d
);
4372 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4374 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4375 if (cfg
.oldest_service_failure
> 0) {
4376 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4378 storeAppendPrintf(entry
, "\n");
4381 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4383 cfg
->oldest_service_failure
= 0;
4384 cfg
->service_failure_limit
= 0;
4389 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4392 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4393 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4399 if ( char *s
= strchr(al
, '{')) {
4400 *s
= '\0'; // terminate the al string
4412 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4413 ca
->alg
= Ssl::algSetValidAfter
;
4414 ca
->param
= strdup("on");
4415 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4416 ca
->alg
= Ssl::algSetValidBefore
;
4417 ca
->param
= strdup("on");
4418 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4419 ca
->alg
= Ssl::algSetCommonName
;
4421 if (strlen(param
) > 64) {
4422 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4426 ca
->param
= strdup(param
);
4429 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4434 aclParseAclList(LegacyParser
, &ca
->aclList
);
4437 cert_adapt
= &(*cert_adapt
)->next
;
4442 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4444 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4445 storeAppendPrintf(entry
, "%s ", name
);
4446 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4448 dump_acl_list(entry
, ca
->aclList
);
4449 storeAppendPrintf(entry
, "\n");
4453 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4455 while (*cert_adapt
) {
4456 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4457 *cert_adapt
= ca
->next
;
4458 safe_free(ca
->param
);
4461 aclDestroyAclList(&ca
->aclList
);
4467 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4470 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4471 if ((al
= strtok(NULL
, w_space
)) == NULL
) {
4476 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4477 cs
->alg
= Ssl::algSignTrusted
;
4478 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4479 cs
->alg
= Ssl::algSignUntrusted
;
4480 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4481 cs
->alg
= Ssl::algSignSelf
;
4483 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4488 aclParseAclList(LegacyParser
, &cs
->aclList
);
4491 cert_sign
= &(*cert_sign
)->next
;
4496 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4498 sslproxy_cert_sign
*cs
;
4499 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4500 storeAppendPrintf(entry
, "%s ", name
);
4501 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4503 dump_acl_list(entry
, cs
->aclList
);
4504 storeAppendPrintf(entry
, "\n");
4508 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4510 while (*cert_sign
) {
4511 sslproxy_cert_sign
*cs
= *cert_sign
;
4512 *cert_sign
= cs
->next
;
4515 aclDestroyAclList(&cs
->aclList
);
4521 class sslBumpCfgRr
: public ::RegisteredRunner
4524 static Ssl::BumpMode lastDeprecatedRule
;
4525 /* RegisteredRunner API */
4526 virtual void run(const RunnerRegistry
&);
4529 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4531 RunnerRegistrationEntry(rrFinalizeConfig
, sslBumpCfgRr
);
4533 void sslBumpCfgRr::run(const RunnerRegistry
&r
)
4535 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4536 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4537 static char buf
[1024];
4538 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4539 strcpy(buf
, "ssl_bump deny all");
4540 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4541 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4542 "must not use implicit rules. Update your ssl_bump rules.");
4544 strcpy(buf
, "ssl_bump allow all");
4545 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4546 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4547 "inferior to the newer server-first bumping mode. New ssl_bump"
4548 " configurations must not use implicit rules. Update your ssl_bump rules.");
4554 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4556 typedef const char *BumpCfgStyle
;
4557 BumpCfgStyle bcsNone
= NULL
;
4558 BumpCfgStyle bcsNew
= "new client/server-first/none";
4559 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4560 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4561 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4563 if ((bm
= strtok(NULL
, w_space
)) == NULL
) {
4568 // if this is the first rule proccessed
4569 if (*ssl_bump
== NULL
) {
4570 bumpCfgStyleLast
= bcsNone
;
4571 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4574 acl_access
*A
= new acl_access
;
4575 A
->allow
= allow_t(ACCESS_ALLOWED
);
4577 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4578 A
->allow
.kind
= Ssl::bumpClientFirst
;
4579 bumpCfgStyleNow
= bcsNew
;
4580 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4581 A
->allow
.kind
= Ssl::bumpServerFirst
;
4582 bumpCfgStyleNow
= bcsNew
;
4583 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4584 A
->allow
.kind
= Ssl::bumpNone
;
4585 bumpCfgStyleNow
= bcsNew
;
4586 } else if (strcmp(bm
, "allow") == 0) {
4587 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4588 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4589 "is usually inferior to the newer server-first "
4590 "bumping mode. Update your ssl_bump rules.");
4591 A
->allow
.kind
= Ssl::bumpClientFirst
;
4592 bumpCfgStyleNow
= bcsOld
;
4593 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4594 } else if (strcmp(bm
, "deny") == 0) {
4595 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4596 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4597 "your ssl_bump rules.");
4598 A
->allow
.kind
= Ssl::bumpNone
;
4599 bumpCfgStyleNow
= bcsOld
;
4600 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4602 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4607 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4608 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4609 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4614 bumpCfgStyleLast
= bumpCfgStyleNow
;
4616 aclParseAclList(LegacyParser
, &A
->aclList
);
4619 for (B
= *ssl_bump
, T
= ssl_bump
; B
; T
= &B
->next
, B
= B
->next
);
4623 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4626 for (sb
= ssl_bump
; sb
!= NULL
; sb
= sb
->next
) {
4627 storeAppendPrintf(entry
, "%s ", name
);
4628 storeAppendPrintf(entry
, "%s ", Ssl::bumpMode(sb
->allow
.kind
));
4630 dump_acl_list(entry
, sb
->aclList
);
4631 storeAppendPrintf(entry
, "\n");
4635 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4637 free_acl_access(ssl_bump
);
4642 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4647 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4648 storeAppendPrintf(entry
, "%s ", hwa
->fieldName
.c_str());
4649 storeAppendPrintf(entry
, "%s ", hwa
->fieldValue
.c_str());
4651 dump_acl_list(entry
, hwa
->aclList
);
4652 storeAppendPrintf(entry
, "\n");
4656 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4660 *headers
= new HeaderWithAclList
;
4662 if ((fn
= strtok(NULL
, w_space
)) == NULL
) {
4668 hwa
.fieldId
= httpHeaderIdByNameDef(fn
, strlen(fn
));
4669 if (hwa
.fieldId
== HDR_BAD_HDR
)
4670 hwa
.fieldId
= HDR_OTHER
;
4674 ConfigParser::ParseQuotedString(&buf
, &wasQuoted
);
4675 hwa
.fieldValue
= buf
.termedBuf();
4676 hwa
.quoted
= wasQuoted
;
4678 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4679 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4683 hwa
.valueFormat
= nlf
;
4685 aclParseAclList(LegacyParser
, &hwa
.aclList
);
4686 (*headers
)->push_back(hwa
);
4689 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4694 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4696 aclDestroyAclList(&hwa
->aclList
);
4698 if (hwa
->valueFormat
) {
4699 delete hwa
->valueFormat
;
4700 hwa
->valueFormat
= NULL
;
4707 static void parse_note(Notes
*notes
)
4710 notes
->parse(LegacyParser
);
4713 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4715 notes
.dump(entry
, name
);
4718 static void free_note(Notes
*notes
)