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"
42 #include "anyp/PortCfg.h"
44 #include "base/RunnersRegistry.h"
46 #include "CachePeer.h"
47 #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/ActionPasswordList.h"
67 #include "mgr/Registration.h"
68 #include "neighbors.h"
69 #include "NeighborTypeDomainList.h"
71 #include "PeerDigest.h"
72 #include "RefreshPattern.h"
74 #include "SquidConfig.h"
75 #include "SquidString.h"
76 #include "ssl/ProxyCerts.h"
78 #include "StoreFileSystem.h"
81 #include "URLScheme.h"
83 /* wccp2 has its own conditional definitions */
86 #include "adaptation/Config.h"
89 #include "adaptation/icap/Config.h"
92 #include "adaptation/ecap/Config.h"
95 #include "ssl/Config.h"
96 #include "ssl/support.h"
99 #include "auth/Config.h"
100 #include "auth/Scheme.h"
103 #include "esi/Parser.h"
125 #include <sys/stat.h>
129 #include "ssl/gadgets.h"
133 static void parse_adaptation_service_set_type();
134 static void parse_adaptation_service_chain_type();
135 static void parse_adaptation_access_type();
139 static void parse_icap_service_type(Adaptation::Icap::Config
*);
140 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
141 static void free_icap_service_type(Adaptation::Icap::Config
*);
142 static void parse_icap_class_type();
143 static void parse_icap_access_type();
145 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
146 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
147 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
151 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
152 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
153 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
156 static peer_t
parseNeighborType(const char *s
);
158 CBDATA_TYPE(CachePeer
);
160 static const char *const T_MILLISECOND_STR
= "millisecond";
161 static const char *const T_SECOND_STR
= "second";
162 static const char *const T_MINUTE_STR
= "minute";
163 static const char *const T_HOUR_STR
= "hour";
164 static const char *const T_DAY_STR
= "day";
165 static const char *const T_WEEK_STR
= "week";
166 static const char *const T_FORTNIGHT_STR
= "fortnight";
167 static const char *const T_MONTH_STR
= "month";
168 static const char *const T_YEAR_STR
= "year";
169 static const char *const T_DECADE_STR
= "decade";
171 static const char *const B_BYTES_STR
= "bytes";
172 static const char *const B_KBYTES_STR
= "KB";
173 static const char *const B_MBYTES_STR
= "MB";
174 static const char *const B_GBYTES_STR
= "GB";
176 static const char *const list_sep
= ", \t\n\r";
178 static void parse_access_log(CustomLog
** customlog_definitions
);
179 static int check_null_access_log(CustomLog
*customlog_definitions
);
180 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
181 static void free_access_log(CustomLog
** definitions
);
182 static bool setLogformat(CustomLog
*cl
, const char *name
, const bool dieWhenMissing
);
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
);
200 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
201 static size_t parseBytesUnits(const char *unit
);
202 static void free_all(void);
203 void requirePathnameExists(const char *name
, const char *path
);
204 static OBJH dump_config
;
205 #if USE_HTTP_VIOLATIONS
206 static void free_HeaderManglers(HeaderManglers
**pm
);
207 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
208 static void parse_http_header_access(HeaderManglers
**manglers
);
209 #define free_http_header_access free_HeaderManglers
210 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
211 static void parse_http_header_replace(HeaderManglers
**manglers
);
212 #define free_http_header_replace free_HeaderManglers
214 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
215 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
216 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
217 static void parse_note(Notes
*);
218 static void dump_note(StoreEntry
*, const char *, Notes
&);
219 static void free_note(Notes
*);
220 static void parse_denyinfo(AclDenyInfoList
** var
);
221 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
222 static void free_denyinfo(AclDenyInfoList
** var
);
225 static void parse_IpAddress_list(Ip::Address_list
**);
226 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
227 static void free_IpAddress_list(Ip::Address_list
**);
229 static int check_null_IpAddress_list(const Ip::Address_list
*);
230 #endif /* CURRENTLY_UNUSED */
231 #endif /* USE_WCCPv2 */
233 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
234 #define parse_PortCfg(l) parsePortCfg((l), token)
235 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
236 static void free_PortCfg(AnyP::PortCfg
**);
239 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
240 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
241 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
242 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
243 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
244 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
245 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
246 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
247 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
250 static void parse_b_size_t(size_t * var
);
251 static void parse_b_int64_t(int64_t * var
);
253 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
255 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
256 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
257 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
259 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
261 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
262 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
263 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
266 * LegacyParser is a parser for legacy code that uses the global
267 * approach. This is static so that it is only exposed to cache_cf.
268 * Other modules needing access to a ConfigParser should have it
269 * provided to them in their parserFOO methods.
271 static ConfigParser LegacyParser
= ConfigParser();
276 LegacyParser
.destruct();
280 update_maxobjsize(void)
284 // determine the maximum size object that can be stored to disk
285 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
286 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
288 const int64_t storeMax
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->maxObjectSize();
293 // Ensure that we do not discard objects which could be stored only in memory.
294 // It is governed by maximum_object_size_in_memory (for now)
295 // TODO: update this to check each in-memory location (SMP and local memory limits differ)
296 if (ms
< static_cast<int64_t>(Config
.Store
.maxInMemObjSize
))
297 ms
= Config
.Store
.maxInMemObjSize
;
299 store_maxobjsize
= ms
;
303 SetConfigFilename(char const *file_name
, bool is_pipe
)
306 cfg_filename
= file_name
+ 1;
308 cfg_filename
= file_name
;
312 skip_ws(const char* s
)
321 parseManyConfigFiles(char* files
, int depth
)
324 char* saveptr
= NULL
;
329 memset(&globbuf
, 0, sizeof(globbuf
));
330 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
331 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
332 fatalf("Unable to find configuration file: %s: %s",
336 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
337 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
341 char* file
= strwordtok(files
, &saveptr
);
342 while (file
!= NULL
) {
343 error_count
+= parseOneConfigFile(file
, depth
);
344 file
= strwordtok(NULL
, &saveptr
);
346 #endif /* HAVE_GLOB */
351 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
354 assert(newSubstr
!= NULL
);
356 unsigned newSubstrLen
= strlen(newSubstr
);
357 if (newSubstrLen
> substrLen
)
358 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
360 // move tail part including zero
361 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
362 // copy new substring in place
363 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
369 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
371 assert(line
!= NULL
);
372 assert(macroName
!= NULL
);
373 assert(substStr
!= NULL
);
374 unsigned macroNameLen
= strlen(macroName
);
375 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
376 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
380 ProcessMacros(char*& line
, int& len
)
382 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
383 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
387 trim_trailing_ws(char* str
)
390 unsigned i
= strlen(str
);
391 while ((i
> 0) && xisspace(str
[i
- 1]))
397 FindStatement(const char* line
, const char* statement
)
399 assert(line
!= NULL
);
400 assert(statement
!= NULL
);
402 const char* str
= skip_ws(line
);
403 unsigned len
= strlen(statement
);
404 if (strncmp(str
, statement
, len
) == 0) {
408 else if (xisspace(*str
))
416 StrToInt(const char* str
, long& number
)
421 number
= strtol(str
, &end
, 0);
423 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
427 EvalBoolExpr(const char* expr
)
429 assert(expr
!= NULL
);
430 if (strcmp(expr
, "true") == 0) {
432 } else if (strcmp(expr
, "false") == 0) {
434 } else if (const char* equation
= strchr(expr
, '=')) {
435 const char* rvalue
= skip_ws(equation
+ 1);
436 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
437 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
438 trim_trailing_ws(lvalue
);
441 if (!StrToInt(lvalue
, number1
))
442 fatalf("String is not a integer number: '%s'\n", lvalue
);
444 if (!StrToInt(rvalue
, number2
))
445 fatalf("String is not a integer number: '%s'\n", rvalue
);
448 return number1
== number2
;
450 fatalf("Unable to evaluate expression '%s'\n", expr
);
451 return false; // this place cannot be reached
455 parseOneConfigFile(const char *file_name
, unsigned int depth
)
458 const char *orig_cfg_filename
= cfg_filename
;
459 const int orig_config_lineno
= config_lineno
;
461 char *tmp_line
= NULL
;
462 int tmp_line_len
= 0;
466 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
468 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
472 if (file_name
[0] == '!' || file_name
[0] == '|') {
473 fp
= popen(file_name
+ 1, "r");
476 fp
= fopen(file_name
, "r");
480 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
483 setmode(fileno(fp
), O_TEXT
);
486 SetConfigFilename(file_name
, bool(is_pipe
));
488 memset(config_input_line
, '\0', BUFSIZ
);
492 Vector
<bool> if_states
;
493 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
496 if ((token
= strchr(config_input_line
, '\n')))
499 if ((token
= strchr(config_input_line
, '\r')))
502 // strip any prefix whitespace off the line.
503 const char *p
= skip_ws(config_input_line
);
504 if (config_input_line
!= p
)
505 memmove(config_input_line
, p
, strlen(p
)+1);
507 if (strncmp(config_input_line
, "#line ", 6) == 0) {
508 static char new_file_name
[1024];
510 static char new_lineno
;
511 token
= config_input_line
+ 6;
512 new_lineno
= strtol(token
, &file
, 0) - 1;
515 continue; /* Not a valid #line directive, may be a comment */
517 while (*file
&& xisspace((unsigned char) *file
))
522 continue; /* Not a valid #line directive, may be a comment */
524 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
526 if ((token
= strchr(new_file_name
, '"')))
529 SetConfigFilename(new_file_name
, false);
532 config_lineno
= new_lineno
;
535 if (config_input_line
[0] == '#')
538 if (config_input_line
[0] == '\0')
541 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
543 size_t append_len
= strlen(append
);
545 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
547 strcpy(tmp_line
+ tmp_line_len
, append
);
549 tmp_line_len
+= append_len
;
551 if (tmp_line
[tmp_line_len
-1] == '\\') {
552 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
553 tmp_line
[--tmp_line_len
] = '\0';
557 trim_trailing_ws(tmp_line
);
558 ProcessMacros(tmp_line
, tmp_line_len
);
559 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
561 if (const char* expr
= FindStatement(tmp_line
, "if")) {
562 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
563 } else if (FindStatement(tmp_line
, "endif")) {
564 if (!if_states
.empty())
565 if_states
.pop_back(); // remove last if-statement meaning
567 fatalf("'endif' without 'if'\n");
568 } else if (FindStatement(tmp_line
, "else")) {
569 if (!if_states
.empty())
570 if_states
.back() = !if_states
.back();
572 fatalf("'else' without 'if'\n");
573 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
574 /* Handle includes here */
575 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
576 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
577 } else if (!parse_line(tmp_line
)) {
578 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
587 if (!if_states
.empty())
588 fatalf("if-statement without 'endif'\n");
591 int ret
= pclose(fp
);
594 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
599 SetConfigFilename(orig_cfg_filename
, false);
600 config_lineno
= orig_config_lineno
;
607 parseConfigFile(const char *file_name
)
615 ACLMethodData::ThePurgeCount
= 0;
618 err_count
= parseOneConfigFile(file_name
, 0);
622 defaults_postscriptum();
625 * We must call configDoConfigure() before leave_suid() because
626 * configDoConfigure() is where we turn username strings into
631 if (!Config
.chroot_dir
) {
633 setUmask(Config
.umask
);
634 _db_init(Debug::cache_log
, Debug::debugOptions
);
638 if (opt_send_signal
== -1) {
639 Mgr::RegisterAction("config",
640 "Current Squid Configuration",
649 configDoConfigure(void)
651 memset(&Config2
, '\0', sizeof(SquidConfig2
));
652 /* init memory as early as possible */
656 Config
.cacheSwap
.n_strands
= 0; // no diskers by default
657 if (Config
.cacheSwap
.swapDirs
== NULL
) {
658 /* Memory-only cache probably in effect. */
659 /* turn off the cache rebuild delays... */
660 StoreController::store_dirs_rebuilding
= 0;
661 } else if (InDaemonMode()) { // no diskers in non-daemon mode
662 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
663 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
664 if (sd
->needsDiskStrand())
665 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
669 if (Debug::rotateNumber
< 0) {
670 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
673 #if SIZEOF_OFF_T <= 4
674 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
675 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
676 Config
.Store
.maxObjectSize
= 0x7FFF0000;
680 if (Config
.Announce
.period
> 0) {
681 Config
.onoff
.announce
= 1;
683 Config
.Announce
.period
= 86400 * 365; /* one year */
684 Config
.onoff
.announce
= 0;
687 if (Config
.onoff
.httpd_suppress_version_string
)
688 visible_appname_string
= (char *)appname_string
;
690 visible_appname_string
= (char const *)APP_FULLNAME
;
692 if (Config
.Program
.redirect
) {
693 if (Config
.redirectChildren
.n_max
< 1) {
694 Config
.redirectChildren
.n_max
= 0;
695 wordlistDestroy(&Config
.Program
.redirect
);
699 if (Config
.Program
.store_id
) {
700 if (Config
.storeIdChildren
.n_max
< 1) {
701 Config
.storeIdChildren
.n_max
= 0;
702 wordlistDestroy(&Config
.Program
.store_id
);
706 if (Config
.appendDomain
)
707 if (*Config
.appendDomain
!= '.')
708 fatal("append_domain must begin with a '.'");
710 if (Config
.errHtmlText
== NULL
)
711 Config
.errHtmlText
= xstrdup(null_string
);
713 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
714 if (Config
.max_filedescriptors
> 0) {
715 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
717 #elif USE_SELECT || USE_SELECT_WIN32
718 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
719 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
725 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
727 visible_appname_string
);
730 * the extra space is for loop detection in client_side.c -- we search
731 * for substrings in the Via header.
733 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
735 visible_appname_string
);
737 /* Use visible_hostname as default surrogate_id */
738 if (!Config
.Accel
.surrogate_id
) {
739 const char *t
= getMyHostname();
740 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
743 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
744 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
746 if (Config
.appendDomain
)
747 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
749 Config
.appendDomainLen
= 0;
751 if (Config
.connect_retries
> 10) {
752 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
753 Config
.connect_retries
= 10;
756 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
759 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
761 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
762 if (Config
.Program
.redirect
)
763 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
765 if (Config
.Program
.store_id
)
766 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
768 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
770 if (Config
.errorDirectory
)
771 requirePathnameExists("Error Directory", Config
.errorDirectory
);
773 #if USE_HTTP_VIOLATIONS
776 const RefreshPattern
*R
;
778 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
779 if (!R
->flags
.override_expire
)
782 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
787 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
788 if (!R
->flags
.override_lastmod
)
791 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
796 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
797 if (!R
->flags
.reload_into_ims
)
800 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
805 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
806 if (!R
->flags
.ignore_reload
)
809 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
814 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
815 if (!R
->flags
.ignore_no_store
)
818 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
823 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
824 if (!R
->flags
.ignore_must_revalidate
)
826 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
830 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
831 if (!R
->flags
.ignore_private
)
834 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
839 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
840 if (!R
->flags
.ignore_auth
)
843 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
850 #if !USE_HTTP_VIOLATIONS
851 Config
.onoff
.via
= 1;
854 if (!Config
.onoff
.via
)
855 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
859 // we enable runtime PURGE checks if there is at least one PURGE method ACL
860 // TODO: replace with a dedicated "purge" ACL option?
861 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
863 Config2
.onoff
.mangle_request_headers
= (Config
.request_header_access
!= NULL
);
865 if (geteuid() == 0) {
866 if (NULL
!= Config
.effectiveUser
) {
868 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
872 * Andres Kroonmaa <andre@online.ee>:
873 * Some getpwnam() implementations (Solaris?) require
874 * an available FD < 256 for opening a FILE* to the
877 * This should be safe at startup, but might still fail
878 * during reconfigure.
880 fatalf("getpwnam failed to find userid for effective user '%s'",
881 Config
.effectiveUser
);
885 Config2
.effectiveUserID
= pwd
->pw_uid
;
887 Config2
.effectiveGroupID
= pwd
->pw_gid
;
891 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
893 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
894 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
902 Config2
.effectiveUserID
= geteuid();
903 Config2
.effectiveGroupID
= getegid();
906 if (NULL
!= Config
.effectiveGroup
) {
908 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
911 fatalf("getgrnam failed to find groupid for effective group '%s'",
912 Config
.effectiveGroup
);
916 Config2
.effectiveGroupID
= grp
->gr_gid
;
921 debugs(3, DBG_IMPORTANT
, "Initializing https proxy context");
923 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
);
925 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
927 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " SSL context");
928 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
932 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
933 if (!s
->flags
.tunnelSslBumping
)
936 debugs(3, DBG_IMPORTANT
, "Initializing http_port " << s
->s
<< " SSL context");
937 s
->configureSslServerContext();
940 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
941 debugs(3, DBG_IMPORTANT
, "Initializing https_port " << s
->s
<< " SSL context");
942 s
->configureSslServerContext();
947 // prevent infinite fetch loops in the request parser
948 // due to buffer full but not enough data recived to finish parse
949 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
950 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
951 " Change client_request_buffer_max or request_header_max_size limits.",
952 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
956 * Disable client side request pipelining if client_persistent_connections OFF.
957 * Waste of resources queueing any pipelined requests when the first will close the connection.
959 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
960 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
961 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
962 Config
.pipeline_max_prefetch
= 0;
967 * disable client side request pipelining. There is a race with
968 * Negotiate and NTLM when the client sends a second request on an
969 * connection before the authenticate challenge is sent. With
970 * pipelining OFF, the client may fail to authenticate, but squid's
971 * state will be preserved.
973 if (Config
.pipeline_max_prefetch
> 0) {
974 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
975 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
976 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
977 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
978 Config
.pipeline_max_prefetch
= 0;
984 /** Parse a line containing an obsolete directive.
985 * To upgrade it where possible instead of just "Bungled config" for
986 * directives which cannot be marked as simply aliases of the some name.
987 * For example if the parameter order and content has changed.
988 * Or if the directive has been completely removed.
991 parse_obsolete(const char *name
)
993 // Directives which have been radically changed rather than removed
994 if (!strcmp(name
, "url_rewrite_concurrency")) {
997 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
998 Config
.redirectChildren
.concurrency
= cval
;
1001 if (!strcmp(name
, "log_access"))
1004 if (!strcmp(name
, "log_icap"))
1007 if (!strcmp(name
, "ignore_ims_on_miss")) {
1008 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1009 // than the 2.7 directive. We need to parse and invert the configured value.
1012 Config
.onoff
.cache_miss_revalidate
= !temp
;
1016 /* Parse a time specification from the config file. Store the
1017 * result in 'tptr', after converting it to 'units' */
1019 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
1026 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
1029 if ((token
= ConfigParser::NextToken()) == NULL
)
1034 m
= u
; /* default to 'units' if none specified */
1038 else if ((token
= ConfigParser::NextToken()) == NULL
)
1039 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1040 config_input_line
<< "', assuming " <<
1041 d
<< " " << units
);
1042 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1045 *tptr
= static_cast<time_msec_t
>(m
* d
);
1047 if (static_cast<double>(*tptr
) * 2 != m
* d
* 2) {
1048 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1049 d
<< " " << token
<< ": integer overflow (time_msec_t).");
1055 parseTimeUnits(const char *unit
, bool allowMsec
)
1057 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1060 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1063 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1066 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1069 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1070 return 86400 * 1000;
1072 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1073 return 86400 * 7 * 1000;
1075 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1076 return 86400 * 14 * 1000;
1078 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1079 return static_cast<uint64_t>(86400) * 30 * 1000;
1081 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1082 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1084 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1085 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1087 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1093 parseBytesLine64(int64_t * bptr
, const char *units
)
1100 if ((u
= parseBytesUnits(units
)) == 0) {
1105 if ((token
= ConfigParser::NextToken()) == NULL
) {
1110 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1117 m
= u
; /* default to 'units' if none specified */
1121 else if ((token
= ConfigParser::NextToken()) == NULL
)
1122 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1123 config_input_line
<< "', assuming " <<
1124 d
<< " " << units
);
1125 else if ((m
= parseBytesUnits(token
)) == 0) {
1130 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1132 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1133 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1134 d
<< " " << token
<< ": integer overflow (int64_t).");
1140 parseBytesLine(size_t * bptr
, const char *units
)
1147 if ((u
= parseBytesUnits(units
)) == 0) {
1152 if ((token
= ConfigParser::NextToken()) == NULL
) {
1157 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1158 *bptr
= static_cast<size_t>(-1);
1164 m
= u
; /* default to 'units' if none specified */
1168 else if ((token
= ConfigParser::NextToken()) == NULL
)
1169 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1170 config_input_line
<< "', assuming " <<
1171 d
<< " " << units
);
1172 else if ((m
= parseBytesUnits(token
)) == 0) {
1177 *bptr
= static_cast<size_t>(m
* d
/ u
);
1179 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1180 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1181 d
<< " " << token
<< ": integer overflow (size_t).");
1187 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1194 if ((u
= parseBytesUnits(units
)) == 0) {
1199 if ((token
= ConfigParser::NextToken()) == NULL
) {
1204 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1211 m
= u
; /* default to 'units' if none specified */
1215 else if ((token
= ConfigParser::NextToken()) == NULL
)
1216 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1217 config_input_line
<< "', assuming " <<
1218 d
<< " " << units
);
1219 else if ((m
= parseBytesUnits(token
)) == 0) {
1224 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1226 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1227 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1228 d
<< " " << token
<< ": integer overflow (ssize_t).");
1234 * Parse bytes from a string.
1235 * Similar to the parseBytesLine function but parses the string value instead of
1236 * the current token value.
1238 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1241 if ((u
= parseBytesUnits(units
)) == 0) {
1246 // Find number from string beginning.
1247 char const * number_begin
= value
;
1248 char const * number_end
= value
;
1250 while ((*number_end
>= '0' && *number_end
<= '9')) {
1255 number
.limitInit(number_begin
, number_end
- number_begin
);
1257 int d
= xatoi(number
.termedBuf());
1259 if ((m
= parseBytesUnits(number_end
)) == 0) {
1264 *bptr
= static_cast<size_t>(m
* d
/ u
);
1265 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1270 parseBytesUnits(const char *unit
)
1272 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1275 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1278 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1281 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1284 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1289 /*****************************************************************************
1291 *****************************************************************************/
1294 dump_wordlist(StoreEntry
* entry
, wordlist
*words
)
1296 for (wordlist
*word
= words
; word
; word
= word
->next
)
1297 storeAppendPrintf(entry
, "%s ", word
->key
);
1301 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1303 while (ae
!= NULL
) {
1304 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1305 storeAppendPrintf(entry
, "%s %s %s %s ",
1309 ae
->flags
.flagsStr());
1310 wordlist
*w
= ae
->dump();
1311 dump_wordlist(entry
, w
);
1313 storeAppendPrintf(entry
, "\n");
1314 wordlistDestroy(&w
);
1320 parse_acl(ACL
** ae
)
1322 ACL::ParseAclLine(LegacyParser
, ae
);
1332 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1334 wordlist
*values
= head
->dump();
1335 dump_wordlist(entry
, values
);
1336 wordlistDestroy(&values
);
1340 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1343 wordlist
*lines
= head
->treeDump(name
, NULL
);
1344 dump_wordlist(entry
, lines
);
1345 wordlistDestroy(&lines
);
1350 parse_acl_access(acl_access
** head
)
1352 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1356 free_acl_access(acl_access
** head
)
1358 aclDestroyAccessList(head
);
1362 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1364 char buf
[MAX_IPSTRLEN
];
1365 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1369 parse_address(Ip::Address
*addr
)
1371 char *token
= ConfigParser::NextToken();
1378 if (!strcmp(token
,"any_addr"))
1380 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1382 else if ( (*addr
= token
) ) // try parse numeric/IPA
1384 else if (addr
->GetHostByName(token
)) // dont use ipcache
1386 else { // not an IP and not a hostname
1387 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
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
.toStr(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
, l
->addr
);
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
= ConfigParser::NextToken();
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
, token
);
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
= ConfigParser::NextToken();
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
, token
);
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
, l
->size
);
1633 tail
= &(*tail
)->next
;
1639 free_acl_b_size_t(AclSizeLimit
** head
)
1642 AclSizeLimit
*l
= *head
;
1651 #include "DelayConfig.h"
1652 #include "DelayPools.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
= ConfigParser::NextToken()) == 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
);
1768 std::string directive
= "http_header_access ";
1770 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1774 free_HeaderManglers(HeaderManglers
**pm
)
1776 // we delete the entire http_header_* mangler configuration at once
1777 if (const HeaderManglers
*manglers
= *pm
) {
1784 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1787 manglers
->dumpReplacement(entry
, name
);
1791 parse_http_header_replace(HeaderManglers
**pm
)
1795 if ((t
= ConfigParser::NextToken()) == NULL
) {
1796 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1797 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1801 const char *value
= ConfigParser::NextQuotedOrToEol();
1804 *pm
= new HeaderManglers
;
1805 HeaderManglers
*manglers
= *pm
;
1806 manglers
->setReplacement(t
, value
);
1812 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1818 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1819 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1821 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1823 storeAppendPrintf(entry
, "\n");
1828 check_null_string(char *s
)
1835 parse_authparam(Auth::ConfigVector
* config
)
1840 if ((type_str
= ConfigParser::NextToken()) == NULL
)
1843 if ((param_str
= ConfigParser::NextToken()) == NULL
)
1846 /* find a configuration for the scheme in the currently parsed configs... */
1847 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1849 if (schemeCfg
== NULL
) {
1850 /* Create a configuration based on the scheme info */
1851 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1853 if (theScheme
== NULL
) {
1854 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1858 config
->push_back(theScheme
->createConfig());
1859 schemeCfg
= Auth::Config::Find(type_str
);
1860 if (schemeCfg
== NULL
) {
1861 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1866 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1870 free_authparam(Auth::ConfigVector
* cfg
)
1872 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1875 /* remove our pointers to the probably-dead sub-configs */
1876 while (cfg
->size()) {
1880 /* on reconfigure initialize new auth schemes for the new config. */
1881 if (reconfiguring
) {
1887 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1889 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1890 (*i
)->dump(entry
, name
, (*i
));
1892 #endif /* USE_AUTH */
1894 /* TODO: just return the object, the # is irrelevant */
1896 find_fstype(char *type
)
1898 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1899 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1906 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1910 RefCount
<SwapDir
> sd
;
1914 if ((type_str
= ConfigParser::NextToken()) == NULL
)
1917 if ((path_str
= ConfigParser::NextToken()) == NULL
)
1920 fs
= find_fstype(type_str
);
1923 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: This proxy does not support the '" << type_str
<< "' cache type. Ignoring.");
1927 /* reconfigure existing dir */
1929 for (i
= 0; i
< swap
->n_configured
; ++i
) {
1930 assert (swap
->swapDirs
[i
].getRaw());
1932 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1933 /* this is specific to on-fs Stores. The right
1934 * way to handle this is probably to have a mapping
1935 * from paths to stores, and have on-fs stores
1936 * register with that, and lookip in that in their
1937 * own setup logic. RBC 20041225. TODO.
1940 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1942 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().items
[fs
]->type()) != 0) {
1943 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1944 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1950 update_maxobjsize();
1957 if (swap
->n_configured
> 63) {
1958 /* 7 bits, signed */
1959 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1960 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1965 allocate_new_swapdir(swap
);
1967 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1969 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1971 /* parse the FS parameters and options */
1972 sd
->parse(swap
->n_configured
, path_str
);
1974 ++swap
->n_configured
;
1976 /* Update the max object size */
1977 update_maxobjsize();
1981 peer_type_str(const peer_t type
)
1983 const char * result
;
1995 case PEER_MULTICAST
:
1996 result
= "multicast";
2008 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2010 CachePeerDomainList
*d
;
2011 NeighborTypeDomainList
*t
;
2012 LOCAL_ARRAY(char, xname
, 128);
2015 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2022 dump_peer_options(entry
, p
);
2024 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2025 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2027 d
->do_ping
? null_string
: "!",
2032 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2033 dump_acl_access(entry
, xname
, p
->access
);
2036 for (t
= p
->typelist
; t
; t
= t
->next
) {
2037 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2039 peer_type_str(t
->type
),
2048 * utility function to prevent getservbyname() being called with a numeric value
2049 * on Windows at least it returns garage results.
2052 isUnsignedNumeric(const char *str
, size_t len
)
2054 if (len
< 1) return false;
2056 for (; len
>0 && *str
; ++str
, --len
) {
2057 if (! isdigit(*str
))
2064 \param proto 'tcp' or 'udp' for protocol
2065 \returns Port the named service is supposed to be listening on.
2067 static unsigned short
2068 GetService(const char *proto
)
2070 struct servent
*port
= NULL
;
2071 /** Parses a port number or service name from the squid.conf */
2072 char *token
= ConfigParser::NextToken();
2073 if (token
== NULL
) {
2075 return 0; /* NEVER REACHED */
2077 /** Returns either the service port number from /etc/services */
2078 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2079 port
= getservbyname(token
, proto
);
2081 return ntohs((unsigned short)port
->s_port
);
2083 /** Or a numeric translation of the config text. */
2084 return xatos(token
);
2088 \returns Port the named TCP service is supposed to be listening on.
2089 \copydoc GetService(const char *proto)
2091 inline unsigned short
2094 return GetService("tcp");
2098 \returns Port the named UDP service is supposed to be listening on.
2099 \copydoc GetService(const char *proto)
2101 inline unsigned short
2104 return GetService("udp");
2108 parse_peer(CachePeer
** head
)
2112 CBDATA_INIT_TYPE_FREECB(CachePeer
, peerDestroy
);
2113 p
= cbdataAlloc(CachePeer
);
2114 p
->http_port
= CACHE_HTTP_PORT
;
2115 p
->icp
.port
= CACHE_ICP_PORT
;
2118 p
->stats
.logged_state
= PEER_ALIVE
;
2120 if ((token
= ConfigParser::NextToken()) == NULL
)
2123 p
->host
= xstrdup(token
);
2125 p
->name
= xstrdup(token
);
2127 if ((token
= ConfigParser::NextToken()) == NULL
)
2130 p
->type
= parseNeighborType(token
);
2132 if (p
->type
== PEER_MULTICAST
) {
2133 p
->options
.no_digest
= true;
2134 p
->options
.no_netdb_exchange
= true;
2137 p
->http_port
= GetTcpService();
2142 p
->icp
.port
= GetUdpService();
2143 p
->connection_auth
= 2; /* auto */
2145 while ((token
= ConfigParser::NextToken())) {
2146 if (!strcmp(token
, "proxy-only")) {
2147 p
->options
.proxy_only
= true;
2148 } else if (!strcmp(token
, "no-query")) {
2149 p
->options
.no_query
= true;
2150 } else if (!strcmp(token
, "background-ping")) {
2151 p
->options
.background_ping
= true;
2152 } else if (!strcmp(token
, "no-digest")) {
2153 p
->options
.no_digest
= true;
2154 } else if (!strcmp(token
, "no-tproxy")) {
2155 p
->options
.no_tproxy
= true;
2156 } else if (!strcmp(token
, "multicast-responder")) {
2157 p
->options
.mcast_responder
= true;
2158 #if PEER_MULTICAST_SIBLINGS
2159 } else if (!strcmp(token
, "multicast-siblings")) {
2160 p
->options
.mcast_siblings
= true;
2162 } else if (!strncmp(token
, "weight=", 7)) {
2163 p
->weight
= xatoi(token
+ 7);
2164 } else if (!strncmp(token
, "basetime=", 9)) {
2165 p
->basetime
= xatoi(token
+ 9);
2166 } else if (!strcmp(token
, "closest-only")) {
2167 p
->options
.closest_only
= true;
2168 } else if (!strncmp(token
, "ttl=", 4)) {
2169 p
->mcast
.ttl
= xatoi(token
+ 4);
2171 if (p
->mcast
.ttl
< 0)
2174 if (p
->mcast
.ttl
> 128)
2176 } else if (!strcmp(token
, "default")) {
2177 p
->options
.default_parent
= true;
2178 } else if (!strcmp(token
, "round-robin")) {
2179 p
->options
.roundrobin
= true;
2180 } else if (!strcmp(token
, "weighted-round-robin")) {
2181 p
->options
.weighted_roundrobin
= true;
2183 } else if (!strcmp(token
, "htcp")) {
2184 p
->options
.htcp
= true;
2185 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2186 /* Note: The htcp- form is deprecated, replaced by htcp= */
2187 p
->options
.htcp
= true;
2188 char *tmp
= xstrdup(token
+5);
2189 char *mode
, *nextmode
;
2190 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2191 nextmode
= strchr(mode
, ',');
2196 if (!strcmp(mode
, "no-clr")) {
2197 if (p
->options
.htcp_only_clr
)
2198 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2199 p
->options
.htcp_no_clr
= true;
2200 } else if (!strcmp(mode
, "no-purge-clr")) {
2201 p
->options
.htcp_no_purge_clr
= true;
2202 } else if (!strcmp(mode
, "only-clr")) {
2203 if (p
->options
.htcp_no_clr
)
2204 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2205 p
->options
.htcp_only_clr
= true;
2206 } else if (!strcmp(mode
, "forward-clr")) {
2207 p
->options
.htcp_forward_clr
= true;
2208 } else if (!strcmp(mode
, "oldsquid")) {
2209 p
->options
.htcp_oldsquid
= true;
2211 fatalf("invalid HTCP mode '%s'", mode
);
2216 } else if (!strcmp(token
, "no-netdb-exchange")) {
2217 p
->options
.no_netdb_exchange
= true;
2219 } else if (!strcmp(token
, "carp")) {
2220 if (p
->type
!= PEER_PARENT
)
2221 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2223 p
->options
.carp
= true;
2224 } else if (!strncmp(token
, "carp-key=", 9)) {
2225 if (p
->options
.carp
!= true)
2226 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2227 p
->options
.carp_key
.set
= true;
2228 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2229 for (; key
; key
= nextkey
) {
2230 nextkey
=strchr(key
,',');
2231 if (nextkey
) ++nextkey
; // skip the comma, any
2232 if (0==strncmp(key
,"scheme",6)) {
2233 p
->options
.carp_key
.scheme
= true;
2234 } else if (0==strncmp(key
,"host",4)) {
2235 p
->options
.carp_key
.host
= true;
2236 } else if (0==strncmp(key
,"port",4)) {
2237 p
->options
.carp_key
.port
= true;
2238 } else if (0==strncmp(key
,"path",4)) {
2239 p
->options
.carp_key
.path
= true;
2240 } else if (0==strncmp(key
,"params",6)) {
2241 p
->options
.carp_key
.params
= true;
2243 fatalf("invalid carp-key '%s'",key
);
2246 } else if (!strcmp(token
, "userhash")) {
2248 if (p
->type
!= PEER_PARENT
)
2249 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2251 p
->options
.userhash
= true;
2253 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2255 } else if (!strcmp(token
, "sourcehash")) {
2256 if (p
->type
!= PEER_PARENT
)
2257 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2259 p
->options
.sourcehash
= true;
2261 } else if (!strcmp(token
, "no-delay")) {
2263 p
->options
.no_delay
= true;
2265 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2267 } else if (!strncmp(token
, "login=", 6)) {
2268 p
->login
= xstrdup(token
+ 6);
2269 rfc1738_unescape(p
->login
);
2270 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2271 p
->connect_timeout
= xatoi(token
+ 16);
2272 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2273 p
->connect_fail_limit
= xatoi(token
+ 19);
2274 #if USE_CACHE_DIGESTS
2275 } else if (!strncmp(token
, "digest-url=", 11)) {
2276 p
->digest_url
= xstrdup(token
+ 11);
2279 } else if (!strcmp(token
, "allow-miss")) {
2280 p
->options
.allow_miss
= true;
2281 } else if (!strncmp(token
, "max-conn=", 9)) {
2282 p
->max_conn
= xatoi(token
+ 9);
2283 } else if (!strcmp(token
, "originserver")) {
2284 p
->options
.originserver
= true;
2285 } else if (!strncmp(token
, "name=", 5)) {
2289 p
->name
= xstrdup(token
+ 5);
2290 } else if (!strncmp(token
, "forceddomain=", 13)) {
2291 safe_free(p
->domain
);
2294 p
->domain
= xstrdup(token
+ 13);
2298 } else if (strcmp(token
, "ssl") == 0) {
2300 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2301 safe_free(p
->sslcert
);
2302 p
->sslcert
= xstrdup(token
+ 8);
2303 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2304 safe_free(p
->sslkey
);
2305 p
->sslkey
= xstrdup(token
+ 7);
2306 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2307 p
->sslversion
= xatoi(token
+ 11);
2308 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2309 safe_free(p
->ssloptions
);
2310 p
->ssloptions
= xstrdup(token
+ 11);
2311 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2312 safe_free(p
->sslcipher
);
2313 p
->sslcipher
= xstrdup(token
+ 10);
2314 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2315 safe_free(p
->sslcafile
);
2316 p
->sslcafile
= xstrdup(token
+ 10);
2317 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2318 safe_free(p
->sslcapath
);
2319 p
->sslcapath
= xstrdup(token
+ 10);
2320 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2321 safe_free(p
->sslcrlfile
);
2322 p
->sslcrlfile
= xstrdup(token
+ 11);
2323 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2324 safe_free(p
->sslflags
);
2325 p
->sslflags
= xstrdup(token
+ 9);
2326 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2327 safe_free(p
->ssldomain
);
2328 p
->ssldomain
= xstrdup(token
+ 10);
2331 } else if (strcmp(token
, "front-end-https") == 0) {
2332 p
->front_end_https
= 1;
2333 } else if (strcmp(token
, "front-end-https=on") == 0) {
2334 p
->front_end_https
= 1;
2335 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2336 p
->front_end_https
= 2;
2337 } else if (strcmp(token
, "connection-auth=off") == 0) {
2338 p
->connection_auth
= 0;
2339 } else if (strcmp(token
, "connection-auth") == 0) {
2340 p
->connection_auth
= 1;
2341 } else if (strcmp(token
, "connection-auth=on") == 0) {
2342 p
->connection_auth
= 1;
2343 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2344 p
->connection_auth
= 2;
2345 } else if (token
[0] == '#') {
2346 // start of a text comment. stop reading this line.
2349 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2353 if (peerFindByName(p
->name
))
2354 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2359 if (p
->connect_fail_limit
< 1)
2360 p
->connect_fail_limit
= 10;
2362 p
->icp
.version
= ICP_VERSION_CURRENT
;
2364 p
->testing_now
= false;
2366 #if USE_CACHE_DIGESTS
2368 if (!p
->options
.no_digest
) {
2369 /* XXX This looks odd.. who has the original pointer
2372 PeerDigest
*pd
= peerDigestCreate(p
);
2373 p
->digest
= cbdataReference(pd
);
2378 p
->index
= ++Config
.npeers
;
2380 while (*head
!= NULL
)
2381 head
= &(*head
)->next
;
2389 free_peer(CachePeer
** P
)
2393 while ((p
= *P
) != NULL
) {
2395 #if USE_CACHE_DIGESTS
2397 cbdataReferenceDone(p
->digest
);
2407 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2411 while (list
!= NULL
) {
2412 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2413 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2415 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2417 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2418 storeAppendPrintf(entry
, " %s", w
->key
);
2421 storeAppendPrintf(entry
, "\n");
2427 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2429 char *passwd
= NULL
;
2430 wordlist
*actions
= NULL
;
2431 Mgr::ActionPasswordList
*p
;
2432 Mgr::ActionPasswordList
**P
;
2433 parse_string(&passwd
);
2434 parse_wordlist(&actions
);
2435 p
= new Mgr::ActionPasswordList
;
2437 p
->actions
= actions
;
2439 for (P
= head
; *P
; P
= &(*P
)->next
) {
2441 * See if any of the actions from this line already have a
2442 * password from previous lines. The password checking
2443 * routines in cache_manager.c take the the password from
2444 * the first Mgr::ActionPasswordList that contains the
2445 * requested action. Thus, we should warn users who might
2446 * think they can have two passwords for the same action.
2451 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2452 for (u
= actions
; u
; u
= u
->next
) {
2453 if (strcmp(w
->key
, u
->key
))
2456 debugs(0, DBG_CRITICAL
, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2465 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2467 Mgr::ActionPasswordList
*p
;
2469 while ((p
= *head
) != NULL
) {
2472 wordlistDestroy(&p
->actions
);
2478 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2482 while (var
!= NULL
) {
2483 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2485 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2486 storeAppendPrintf(entry
, " %s", a
->name
);
2488 storeAppendPrintf(entry
, "\n");
2495 parse_denyinfo(AclDenyInfoList
** var
)
2497 aclParseDenyInfoLine(var
);
2501 free_denyinfo(AclDenyInfoList
** list
)
2503 AclDenyInfoList
*a
= NULL
;
2504 AclDenyInfoList
*a_next
= NULL
;
2505 AclNameList
*l
= NULL
;
2506 AclNameList
*l_next
= NULL
;
2508 for (a
= *list
; a
; a
= a_next
) {
2509 for (l
= a
->acl_list
; l
; l
= l_next
) {
2511 memFree(l
, MEM_ACL_NAME_LIST
);
2516 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2524 parse_peer_access(void)
2529 if (!(host
= ConfigParser::NextToken()))
2532 if ((p
= peerFindByName(host
)) == NULL
) {
2533 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2537 std::string directive
= "peer_access ";
2539 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
->access
);
2543 parse_hostdomain(void)
2546 char *domain
= NULL
;
2548 if (!(host
= ConfigParser::NextToken()))
2551 while ((domain
= ConfigParser::NextToken())) {
2552 CachePeerDomainList
*l
= NULL
;
2553 CachePeerDomainList
**L
= NULL
;
2556 if ((p
= peerFindByName(host
)) == NULL
) {
2557 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2561 l
= static_cast<CachePeerDomainList
*>(xcalloc(1, sizeof(CachePeerDomainList
)));
2564 if (*domain
== '!') { /* check for !.edu */
2569 l
->domain
= xstrdup(domain
);
2571 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2577 parse_hostdomaintype(void)
2581 char *domain
= NULL
;
2583 if (!(host
= ConfigParser::NextToken()))
2586 if (!(type
= ConfigParser::NextToken()))
2589 while ((domain
= ConfigParser::NextToken())) {
2590 NeighborTypeDomainList
*l
= NULL
;
2591 NeighborTypeDomainList
**L
= NULL
;
2594 if ((p
= peerFindByName(host
)) == NULL
) {
2595 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2599 l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2600 l
->type
= parseNeighborType(type
);
2601 l
->domain
= xstrdup(domain
);
2603 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2609 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2611 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2629 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2631 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2635 parse_onoff(int *var
)
2637 char *token
= ConfigParser::NextToken();
2642 if (!strcmp(token
, "on")) {
2644 } else if (!strcmp(token
, "enable")) {
2645 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2647 } else if (!strcmp(token
, "off")) {
2649 } else if (!strcmp(token
, "disable")) {
2650 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2653 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2658 #define free_onoff free_int
2661 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2672 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2676 parse_tristate(int *var
)
2678 char *token
= ConfigParser::NextToken();
2683 if (!strcmp(token
, "on")) {
2685 } else if (!strcmp(token
, "enable")) {
2686 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2688 } else if (!strcmp(token
, "warn")) {
2690 } else if (!strcmp(token
, "off")) {
2692 } else if (!strcmp(token
, "disable")) {
2693 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2696 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2701 #define free_tristate free_int
2704 parse_pipelinePrefetch(int *var
)
2706 char *token
= ConfigParser::PeekAtToken();
2711 if (!strcmp(token
, "on")) {
2712 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2715 (void)ConfigParser::NextToken();
2716 } else if (!strcmp(token
, "off")) {
2717 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2720 (void)ConfigParser::NextToken();
2725 #define free_pipelinePrefetch free_int
2726 #define dump_pipelinePrefetch dump_int
2729 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2731 while (head
!= NULL
) {
2732 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2734 head
->flags
.icase
? " -i" : null_string
,
2736 (int) head
->min
/ 60,
2737 (int) (100.0 * head
->pct
+ 0.5),
2738 (int) head
->max
/ 60);
2740 if (head
->max_stale
>= 0)
2741 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2743 if (head
->flags
.refresh_ims
)
2744 storeAppendPrintf(entry
, " refresh-ims");
2746 if (head
->flags
.store_stale
)
2747 storeAppendPrintf(entry
, " store-stale");
2749 #if USE_HTTP_VIOLATIONS
2751 if (head
->flags
.override_expire
)
2752 storeAppendPrintf(entry
, " override-expire");
2754 if (head
->flags
.override_lastmod
)
2755 storeAppendPrintf(entry
, " override-lastmod");
2757 if (head
->flags
.reload_into_ims
)
2758 storeAppendPrintf(entry
, " reload-into-ims");
2760 if (head
->flags
.ignore_reload
)
2761 storeAppendPrintf(entry
, " ignore-reload");
2763 if (head
->flags
.ignore_no_store
)
2764 storeAppendPrintf(entry
, " ignore-no-store");
2766 if (head
->flags
.ignore_must_revalidate
)
2767 storeAppendPrintf(entry
, " ignore-must-revalidate");
2769 if (head
->flags
.ignore_private
)
2770 storeAppendPrintf(entry
, " ignore-private");
2772 if (head
->flags
.ignore_auth
)
2773 storeAppendPrintf(entry
, " ignore-auth");
2777 storeAppendPrintf(entry
, "\n");
2784 parse_refreshpattern(RefreshPattern
** head
)
2791 int refresh_ims
= 0;
2792 int store_stale
= 0;
2795 #if USE_HTTP_VIOLATIONS
2797 int override_expire
= 0;
2798 int override_lastmod
= 0;
2799 int reload_into_ims
= 0;
2800 int ignore_reload
= 0;
2801 int ignore_no_store
= 0;
2802 int ignore_must_revalidate
= 0;
2803 int ignore_private
= 0;
2804 int ignore_auth
= 0;
2811 int flags
= REG_EXTENDED
| REG_NOSUB
;
2813 if ((token
= ConfigParser::RegexPattern()) != NULL
) {
2815 if (strcmp(token
, "-i") == 0) {
2817 token
= ConfigParser::RegexPattern();
2818 } else if (strcmp(token
, "+i") == 0) {
2819 flags
&= ~REG_ICASE
;
2820 token
= ConfigParser::RegexPattern();
2825 if (token
== NULL
) {
2826 debugs(3, DBG_CRITICAL
, "FATAL: refresh_pattern missing the regex pattern parameter");
2831 pattern
= xstrdup(token
);
2833 i
= GetInteger(); /* token: min */
2835 /* catch negative and insanely huge values close to 32-bit wrap */
2837 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2840 if (i
> 60*24*365) {
2841 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2845 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2847 i
= GetPercentage(); /* token: pct */
2849 pct
= (double) i
/ 100.0;
2851 i
= GetInteger(); /* token: max */
2853 /* catch negative and insanely huge values close to 32-bit wrap */
2855 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2858 if (i
> 60*24*365) {
2859 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2863 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2866 while ((token
= ConfigParser::NextToken()) != NULL
) {
2867 if (!strcmp(token
, "refresh-ims")) {
2869 } else if (!strcmp(token
, "store-stale")) {
2871 } else if (!strncmp(token
, "max-stale=", 10)) {
2872 max_stale
= xatoi(token
+ 10);
2873 #if USE_HTTP_VIOLATIONS
2875 } else if (!strcmp(token
, "override-expire"))
2876 override_expire
= 1;
2877 else if (!strcmp(token
, "override-lastmod"))
2878 override_lastmod
= 1;
2879 else if (!strcmp(token
, "ignore-no-store"))
2880 ignore_no_store
= 1;
2881 else if (!strcmp(token
, "ignore-must-revalidate"))
2882 ignore_must_revalidate
= 1;
2883 else if (!strcmp(token
, "ignore-private"))
2885 else if (!strcmp(token
, "ignore-auth"))
2887 else if (!strcmp(token
, "reload-into-ims")) {
2888 reload_into_ims
= 1;
2889 refresh_nocache_hack
= 1;
2890 /* tell client_side.c that this is used */
2891 } else if (!strcmp(token
, "ignore-reload")) {
2893 refresh_nocache_hack
= 1;
2894 /* tell client_side.c that this is used */
2897 } else if (!strcmp(token
, "ignore-no-cache")) {
2898 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it.");
2900 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2903 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2905 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2906 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2907 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2912 pct
= pct
< 0.0 ? 0.0 : pct
;
2913 max
= max
< 0 ? 0 : max
;
2914 t
= static_cast<RefreshPattern
*>(xcalloc(1, sizeof(RefreshPattern
)));
2915 t
->pattern
= (char *) xstrdup(pattern
);
2916 t
->compiled_pattern
= comp
;
2921 if (flags
& REG_ICASE
)
2922 t
->flags
.icase
= true;
2925 t
->flags
.refresh_ims
= true;
2928 t
->flags
.store_stale
= true;
2930 t
->max_stale
= max_stale
;
2932 #if USE_HTTP_VIOLATIONS
2934 if (override_expire
)
2935 t
->flags
.override_expire
= true;
2937 if (override_lastmod
)
2938 t
->flags
.override_lastmod
= true;
2940 if (reload_into_ims
)
2941 t
->flags
.reload_into_ims
= true;
2944 t
->flags
.ignore_reload
= true;
2946 if (ignore_no_store
)
2947 t
->flags
.ignore_no_store
= true;
2949 if (ignore_must_revalidate
)
2950 t
->flags
.ignore_must_revalidate
= true;
2953 t
->flags
.ignore_private
= true;
2956 t
->flags
.ignore_auth
= true;
2963 head
= &(*head
)->next
;
2971 free_refreshpattern(RefreshPattern
** head
)
2975 while ((t
= *head
) != NULL
) {
2977 safe_free(t
->pattern
);
2978 regfree(&t
->compiled_pattern
);
2982 #if USE_HTTP_VIOLATIONS
2983 refresh_nocache_hack
= 0;
2989 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2992 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2996 parse_string(char **var
)
2998 char *token
= ConfigParser::NextToken();
3004 *var
= xstrdup(token
);
3008 free_string(char **var
)
3014 parse_eol(char *volatile *var
)
3021 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
3029 while (*token
&& xisspace(*token
))
3037 *var
= xstrdup((char *) token
);
3040 #define dump_eol dump_string
3041 #define free_eol free_string
3044 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3046 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3050 parse_time_t(time_t * var
)
3053 parseTimeLine(&tval
, T_SECOND_STR
, false);
3054 *var
= static_cast<time_t>(tval
/1000);
3058 free_time_t(time_t * var
)
3064 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3067 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3069 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3073 parse_time_msec(time_msec_t
* var
)
3075 parseTimeLine(var
, T_SECOND_STR
, true);
3079 free_time_msec(time_msec_t
* var
)
3086 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3088 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3093 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3095 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3099 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3101 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3106 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3108 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3113 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3115 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3119 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3121 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3126 parse_size_t(size_t * var
)
3135 parse_b_size_t(size_t * var
)
3137 parseBytesLine(var
, B_BYTES_STR
);
3141 parse_b_ssize_t(ssize_t
* var
)
3143 parseBytesLineSigned(var
, B_BYTES_STR
);
3148 parse_kb_size_t(size_t * var
)
3150 parseBytesLine(var
, B_KBYTES_STR
);
3155 parse_b_int64_t(int64_t * var
)
3157 parseBytesLine64(var
, B_BYTES_STR
);
3161 parse_kb_int64_t(int64_t * var
)
3163 parseBytesLine64(var
, B_KBYTES_STR
);
3167 free_size_t(size_t * var
)
3173 free_ssize_t(ssize_t
* var
)
3179 free_b_int64_t(int64_t * var
)
3184 #define free_b_size_t free_size_t
3185 #define free_b_ssize_t free_ssize_t
3186 #define free_kb_size_t free_size_t
3187 #define free_mb_size_t free_size_t
3188 #define free_gb_size_t free_size_t
3189 #define free_kb_int64_t free_b_int64_t
3192 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3194 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3198 free_u_short(unsigned short * u
)
3204 parse_u_short(unsigned short * var
)
3206 ConfigParser::ParseUShort(var
);
3210 ConfigParser::ParseUShort(unsigned short *var
)
3216 ConfigParser::ParseBool(bool *var
)
3218 int i
= GetInteger();
3229 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3231 while (list
!= NULL
) {
3232 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3238 ConfigParser::ParseWordList(wordlist
** list
)
3240 parse_wordlist(list
);
3244 parse_wordlist(wordlist
** list
)
3247 while ((token
= ConfigParser::NextQuotedToken()))
3248 wordlistAdd(list
, token
);
3251 #if 0 /* now unused */
3253 check_null_wordlist(wordlist
* w
)
3260 check_null_acl_access(acl_access
* a
)
3265 #define free_wordlist wordlistDestroy
3267 #define free_uri_whitespace free_int
3270 parse_uri_whitespace(int *var
)
3272 char *token
= ConfigParser::NextToken();
3277 if (!strcmp(token
, "strip"))
3278 *var
= URI_WHITESPACE_STRIP
;
3279 else if (!strcmp(token
, "deny"))
3280 *var
= URI_WHITESPACE_DENY
;
3281 else if (!strcmp(token
, "allow"))
3282 *var
= URI_WHITESPACE_ALLOW
;
3283 else if (!strcmp(token
, "encode"))
3284 *var
= URI_WHITESPACE_ENCODE
;
3285 else if (!strcmp(token
, "chop"))
3286 *var
= URI_WHITESPACE_CHOP
;
3288 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3294 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3298 if (var
== URI_WHITESPACE_ALLOW
)
3300 else if (var
== URI_WHITESPACE_ENCODE
)
3302 else if (var
== URI_WHITESPACE_CHOP
)
3304 else if (var
== URI_WHITESPACE_DENY
)
3309 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3313 free_removalpolicy(RemovalPolicySettings
** settings
)
3318 free_string(&(*settings
)->type
);
3320 free_wordlist(&(*settings
)->args
);
3328 parse_removalpolicy(RemovalPolicySettings
** settings
)
3331 free_removalpolicy(settings
);
3333 *settings
= new RemovalPolicySettings
;
3335 parse_string(&(*settings
)->type
);
3337 parse_wordlist(&(*settings
)->args
);
3341 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3344 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3345 args
= settings
->args
;
3348 storeAppendPrintf(entry
, " %s", args
->key
);
3352 storeAppendPrintf(entry
, "\n");
3356 free_YesNoNone(YesNoNone
*)
3358 // do nothing: no explicit cleanup is required
3362 parse_YesNoNone(YesNoNone
*option
)
3365 parse_onoff(&value
);
3366 option
->configure(value
> 0);
3370 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3372 if (option
.configured())
3373 dump_onoff(entry
, name
, option
? 1 : 0);
3377 free_memcachemode(SquidConfig
* config
)
3383 parse_memcachemode(SquidConfig
* config
)
3385 char *token
= ConfigParser::NextToken();
3389 if (strcmp(token
, "always") == 0) {
3390 Config
.onoff
.memory_cache_first
= 1;
3391 Config
.onoff
.memory_cache_disk
= 1;
3392 } else if (strcmp(token
, "disk") == 0) {
3393 Config
.onoff
.memory_cache_first
= 0;
3394 Config
.onoff
.memory_cache_disk
= 1;
3395 } else if (strncmp(token
, "net", 3) == 0) {
3396 Config
.onoff
.memory_cache_first
= 1;
3397 Config
.onoff
.memory_cache_disk
= 0;
3398 } else if (strcmp(token
, "never") == 0) {
3399 Config
.onoff
.memory_cache_first
= 0;
3400 Config
.onoff
.memory_cache_disk
= 0;
3402 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3408 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3410 storeAppendPrintf(entry
, "%s ", name
);
3411 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3412 storeAppendPrintf(entry
, "always");
3413 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3414 storeAppendPrintf(entry
, "disk");
3415 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3416 storeAppendPrintf(entry
, "network");
3417 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3418 storeAppendPrintf(entry
, "none");
3419 storeAppendPrintf(entry
, "\n");
3422 #include "cf_parser.cci"
3425 parseNeighborType(const char *s
)
3427 if (!strcmp(s
, "parent"))
3430 if (!strcmp(s
, "neighbor"))
3431 return PEER_SIBLING
;
3433 if (!strcmp(s
, "neighbour"))
3434 return PEER_SIBLING
;
3436 if (!strcmp(s
, "sibling"))
3437 return PEER_SIBLING
;
3439 if (!strcmp(s
, "multicast"))
3440 return PEER_MULTICAST
;
3442 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3444 return PEER_SIBLING
;
3449 parse_IpAddress_list(Ip::Address_list
** head
)
3452 Ip::Address_list
*s
;
3455 while ((token
= ConfigParser::NextToken())) {
3456 if (GetHostWithPort(token
, &ipa
)) {
3459 head
= &(*head
)->next
;
3461 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3471 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3473 char ntoabuf
[MAX_IPSTRLEN
];
3476 storeAppendPrintf(e
, "%s %s\n",
3478 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3484 free_IpAddress_list(Ip::Address_list
** head
)
3486 if (*head
) delete *head
;
3490 #if CURRENTLY_UNUSED
3491 /* This code was previously used by http_port. Left as it really should
3492 * be used by icp_port and htcp_port
3495 check_null_IpAddress_list(const Ip::Address_list
* s
)
3500 #endif /* CURRENTLY_UNUSED */
3501 #endif /* USE_WCCPv2 */
3504 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3507 unsigned short port
= 0;
3511 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3512 s
->name
= xstrdup(token
);
3513 s
->connection_auth_disabled
= false;
3515 const char *portType
= URLScheme(s
->transport
.protocol
).const_str();
3517 if (*token
== '[') {
3520 t
= strchr(host
, ']');
3522 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3528 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3531 if (!Ip::EnableIpv6
) {
3532 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3535 port
= xatos(t
+ 1);
3536 } else if ((t
= strchr(token
, ':'))) {
3541 port
= xatos(t
+ 1);
3543 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3544 port
= xatos(token
);
3545 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3547 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3551 if (port
== 0 && host
!= NULL
) {
3552 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3559 if (!Ip::EnableIpv6
)
3561 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3562 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3564 if (!Ip::EnableIpv6
)
3566 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3567 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3568 /* dont use ipcache */
3569 s
->defaultsite
= xstrdup(host
);
3571 if (!Ip::EnableIpv6
)
3573 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3575 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3581 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3585 if (strcmp(token
, "accel") == 0) {
3586 if (s
->flags
.isIntercepted()) {
3587 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3590 s
->flags
.accelSurrogate
= true;
3592 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3593 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3594 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3597 s
->flags
.natIntercept
= true;
3598 Ip::Interceptor
.StartInterception();
3599 /* Log information regarding the port modes under interception. */
3600 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3601 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3602 } else if (strcmp(token
, "tproxy") == 0) {
3603 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3604 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3607 s
->flags
.tproxyIntercept
= true;
3608 Ip::Interceptor
.StartTransparency();
3609 /* Log information regarding the port modes under transparency. */
3610 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3612 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3613 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3617 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3618 if (!s
->flags
.accelSurrogate
) {
3619 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3622 safe_free(s
->defaultsite
);
3623 s
->defaultsite
= xstrdup(token
+ 12);
3624 } else if (strcmp(token
, "vhost") == 0) {
3625 if (!s
->flags
.accelSurrogate
) {
3626 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3628 s
->flags
.accelSurrogate
= true;
3630 } else if (strcmp(token
, "no-vhost") == 0) {
3631 if (!s
->flags
.accelSurrogate
) {
3632 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3635 } else if (strcmp(token
, "vport") == 0) {
3636 if (!s
->flags
.accelSurrogate
) {
3637 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3641 } else if (strncmp(token
, "vport=", 6) == 0) {
3642 if (!s
->flags
.accelSurrogate
) {
3643 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3646 s
->vport
= xatos(token
+ 6);
3647 } else if (strncmp(token
, "protocol=", 9) == 0) {
3648 if (!s
->flags
.accelSurrogate
) {
3649 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3652 s
->setTransport(token
+ 9);
3653 } else if (strcmp(token
, "allow-direct") == 0) {
3654 if (!s
->flags
.accelSurrogate
) {
3655 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3658 s
->allow_direct
= true;
3659 } else if (strcmp(token
, "act-as-origin") == 0) {
3660 if (!s
->flags
.accelSurrogate
) {
3661 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3663 s
->actAsOrigin
= true;
3664 } else if (strcmp(token
, "ignore-cc") == 0) {
3665 #if !USE_HTTP_VIOLATIONS
3666 if (!s
->flags
.accelSurrogate
) {
3667 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Acceleration mode flag.");
3671 s
->ignore_cc
= true;
3672 } else if (strncmp(token
, "name=", 5) == 0) {
3674 s
->name
= xstrdup(token
+ 5);
3675 } else if (strcmp(token
, "no-connection-auth") == 0) {
3676 s
->connection_auth_disabled
= true;
3677 } else if (strcmp(token
, "connection-auth=off") == 0) {
3678 s
->connection_auth_disabled
= true;
3679 } else if (strcmp(token
, "connection-auth") == 0) {
3680 s
->connection_auth_disabled
= false;
3681 } else if (strcmp(token
, "connection-auth=on") == 0) {
3682 s
->connection_auth_disabled
= false;
3683 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3684 if (!strcmp(token
+ 23, "off"))
3685 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3686 else if (!strcmp(token
+ 23, "transparent"))
3687 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3688 else if (!strcmp(token
+ 23, "always"))
3689 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3692 } else if (strcmp(token
, "ipv4") == 0) {
3693 if ( !s
->s
.setIPv4() ) {
3694 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3697 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3698 s
->tcp_keepalive
.enabled
= true;
3699 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3700 char *t
= token
+ 13;
3701 s
->tcp_keepalive
.enabled
= true;
3702 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3706 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3711 s
->tcp_keepalive
.timeout
= xatoui(t
);
3714 } else if (strcmp(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();
3776 s
->setTransport("HTTP");
3777 parsePortSpecification(s
, portspec
);
3778 // we may need to merge better if the above returns a list with clones
3779 assert(s
->next
== NULL
);
3780 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3781 cbdataReferenceDone(Config
.Sockaddr
.http
);
3782 Config
.Sockaddr
.http
= cbdataReference(s
);
3786 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3788 const char *protocol
= NULL
;
3789 if (strcmp(optionName
, "http_port") == 0 ||
3790 strcmp(optionName
, "ascii_port") == 0)
3792 else if (strcmp(optionName
, "https_port") == 0)
3799 char *token
= ConfigParser::NextToken();
3806 AnyP::PortCfg
*s
= new AnyP::PortCfg();
3807 s
->setTransport(protocol
);
3808 parsePortSpecification(s
, token
);
3810 /* parse options ... */
3811 while ((token
= ConfigParser::NextToken())) {
3812 parse_port_option(s
, token
);
3816 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3817 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3818 const bool hijacked
= s
->flags
.isIntercepted();
3819 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3820 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3823 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3824 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3830 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3831 // clone the port options from *s to *(s->next)
3832 s
->next
= cbdataReference(s
->clone());
3833 s
->next
->s
.setIPv4();
3834 debugs(3, 3, URLScheme(s
->transport
.protocol
) << "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3838 head
= &(*head
)->next
;
3840 *head
= cbdataReference(s
);
3844 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3846 char buf
[MAX_IPSTRLEN
];
3848 storeAppendPrintf(e
, "%s %s",
3850 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3852 // MODES and specific sub-options.
3853 if (s
->flags
.natIntercept
)
3854 storeAppendPrintf(e
, " intercept");
3856 else if (s
->flags
.tproxyIntercept
)
3857 storeAppendPrintf(e
, " tproxy");
3859 else if (s
->flags
.accelSurrogate
) {
3860 storeAppendPrintf(e
, " accel");
3863 storeAppendPrintf(e
, " vhost");
3866 storeAppendPrintf(e
, " vport");
3867 else if (s
->vport
> 0)
3868 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3871 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3873 // TODO: compare against prefix of 'n' instead of assuming http_port
3874 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3875 storeAppendPrintf(e
, " protocol=%s", URLScheme(s
->transport
.protocol
).const_str());
3877 if (s
->allow_direct
)
3878 storeAppendPrintf(e
, " allow-direct");
3881 storeAppendPrintf(e
, " ignore-cc");
3885 // Generic independent options
3888 storeAppendPrintf(e
, " name=%s", s
->name
);
3890 #if USE_HTTP_VIOLATIONS
3891 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3892 storeAppendPrintf(e
, " ignore-cc");
3895 if (s
->connection_auth_disabled
)
3896 storeAppendPrintf(e
, " connection-auth=off");
3898 storeAppendPrintf(e
, " connection-auth=on");
3900 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3903 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3906 pmtu
= "transparent";
3908 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3911 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3912 storeAppendPrintf(e
, " ipv4");
3914 if (s
->tcp_keepalive
.enabled
) {
3915 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3916 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3918 storeAppendPrintf(e
, " tcpkeepalive");
3923 if (s
->flags
.tunnelSslBumping
)
3924 storeAppendPrintf(e
, " ssl-bump");
3927 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3930 storeAppendPrintf(e
, " key=%s", s
->key
);
3933 storeAppendPrintf(e
, " version=%d", s
->version
);
3936 storeAppendPrintf(e
, " options=%s", s
->options
);
3939 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3942 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3945 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3948 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3951 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3954 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3956 if (s
->sslContextSessionId
)
3957 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3959 if (s
->generateHostCertificates
)
3960 storeAppendPrintf(e
, " generate-host-certificates");
3962 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3963 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3968 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3971 dump_generic_port(e
, n
, s
);
3972 storeAppendPrintf(e
, "\n");
3978 free_PortCfg(AnyP::PortCfg
** head
)
3982 while ((s
= *head
) != NULL
) {
3984 cbdataReferenceDone(s
);
3989 configFreeMemory(void)
3993 SSL_CTX_free(Config
.ssl_client
.sslContext
);
3998 requirePathnameExists(const char *name
, const char *path
)
4002 char pathbuf
[BUFSIZ
];
4003 assert(path
!= NULL
);
4005 if (Config
.chroot_dir
&& (geteuid() == 0)) {
4006 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4010 if (stat(path
, &sb
) < 0) {
4011 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
4012 // keep going to find more issues if we are only checking the config file with "-k parse"
4013 if (opt_parse_cfg_only
)
4015 // this is fatal if it is found during startup or reconfigure
4016 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4017 fatalf("%s %s: %s", name
, path
, xstrerror());
4024 return ConfigParser::strtokFile();
4027 #include "AccessLogEntry.h"
4030 * We support several access_log configuration styles:
4032 * #1: Deprecated ancient style without an explicit logging module:
4033 * access_log /var/log/access.log
4035 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
4036 * access_log none [acl ...]
4038 * #3: Configurable logging module without named options:
4039 * Logformat or the first ACL name, whichever comes first, may not contain '='.
4040 * If no explicit logformat name is given, the first ACL name, if any,
4041 * should not be an existing logformat name or it will be treated as such.
4042 * access_log module:place [logformat_name] [acl ...]
4044 * #4: Configurable logging module with name=value options such as logformat=x:
4045 * The first ACL name may not contain '='.
4046 * access_log module:place [option ...] [acl ...]
4050 parse_access_log(CustomLog
** logs
)
4052 CustomLog
*cl
= (CustomLog
*)xcalloc(1, sizeof(*cl
));
4054 // default buffer size and fatal settings
4055 cl
->bufferSize
= 8*MAX_URL
;
4058 /* determine configuration style */
4060 const char *filename
= ConfigParser::NextToken();
4066 if (strcmp(filename
, "none") == 0) {
4067 cl
->type
= Log::Format::CLF_NONE
;
4068 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
4070 logs
= &(*logs
)->next
;
4075 cl
->filename
= xstrdup(filename
);
4076 cl
->type
= Log::Format::CLF_UNKNOWN
;
4078 const char *token
= ConfigParser::PeekAtToken();
4079 if (!token
) { // style #1
4080 // no options to deal with
4081 } else if (!strchr(token
, '=')) { // style #3
4082 // if logformat name is recognized,
4083 // pop the previewed token; Else it must be an ACL name
4084 if (setLogformat(cl
, token
, false))
4085 (void)ConfigParser::NextToken();
4086 } else { // style #4
4088 if (strncasecmp(token
, "on-error=", 9) == 0) {
4089 if (strncasecmp(token
+9, "die", 3) == 0) {
4091 } else if (strncasecmp(token
+9, "drop", 4) == 0) {
4094 debugs(3, DBG_CRITICAL
, "Unknown value for on-error '" <<
4095 token
<< "' expected 'drop' or 'die'");
4098 } else if (strncasecmp(token
, "buffer-size=", 12) == 0) {
4099 parseBytesOptionValue(&cl
->bufferSize
, B_BYTES_STR
, token
+12);
4100 } else if (strncasecmp(token
, "logformat=", 10) == 0) {
4101 setLogformat(cl
, token
+10, true);
4102 } else if (!strchr(token
, '=')) {
4103 // Do not pop the token; it must be an ACL name
4104 break; // done with name=value options, now to ACLs
4106 debugs(3, DBG_CRITICAL
, "Unknown access_log option " << token
);
4109 // Pop the token, it was a valid "name=value" option
4110 (void)ConfigParser::NextToken();
4111 // Get next with preview ConfigParser::NextToken call.
4112 } while ((token
= ConfigParser::PeekAtToken()) != NULL
);
4115 // set format if it has not been specified explicitly
4116 if (cl
->type
== Log::Format::CLF_UNKNOWN
)
4117 setLogformat(cl
, "squid", true);
4119 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4122 logs
= &(*logs
)->next
;
4127 /// sets CustomLog::type and, if needed, CustomLog::lf
4128 /// returns false iff there is no named log format
4130 setLogformat(CustomLog
*cl
, const char *logdef_name
, const bool dieWhenMissing
)
4133 assert(logdef_name
);
4135 debugs(3, 9, "possible " << cl
->filename
<< " logformat: " << logdef_name
);
4137 if (cl
->type
!= Log::Format::CLF_UNKNOWN
) {
4138 debugs(3, DBG_CRITICAL
, "Second logformat name in one access_log: " <<
4139 logdef_name
<< " " << cl
->type
<< " ? " << Log::Format::CLF_NONE
);
4144 /* look for the definition pointer corresponding to this name */
4145 Format::Format
*lf
= Log::TheConfig
.logformats
;
4147 while (lf
!= NULL
) {
4148 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4150 if (strcmp(lf
->name
, logdef_name
) == 0)
4157 cl
->type
= Log::Format::CLF_CUSTOM
;
4159 } else if (strcmp(logdef_name
, "auto") == 0) {
4160 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4161 cl
->type
= Log::Format::CLF_SQUID
;
4162 } else if (strcmp(logdef_name
, "squid") == 0) {
4163 cl
->type
= Log::Format::CLF_SQUID
;
4164 } else if (strcmp(logdef_name
, "common") == 0) {
4165 cl
->type
= Log::Format::CLF_COMMON
;
4166 } else if (strcmp(logdef_name
, "combined") == 0) {
4167 cl
->type
= Log::Format::CLF_COMBINED
;
4169 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4170 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4172 } else if (strcmp(logdef_name
, "useragent") == 0) {
4173 cl
->type
= Log::Format::CLF_USERAGENT
;
4174 } else if (strcmp(logdef_name
, "referrer") == 0) {
4175 cl
->type
= Log::Format::CLF_REFERER
;
4176 } else if (dieWhenMissing
) {
4177 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4188 check_null_access_log(CustomLog
*customlog_definitions
)
4190 return customlog_definitions
== NULL
;
4194 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4198 for (log
= logs
; log
; log
= log
->next
) {
4199 storeAppendPrintf(entry
, "%s ", name
);
4201 switch (log
->type
) {
4203 case Log::Format::CLF_CUSTOM
:
4204 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4207 case Log::Format::CLF_NONE
:
4208 storeAppendPrintf(entry
, "none");
4211 case Log::Format::CLF_SQUID
:
4212 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4215 case Log::Format::CLF_COMBINED
:
4216 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4219 case Log::Format::CLF_COMMON
:
4220 storeAppendPrintf(entry
, "%s common", log
->filename
);
4224 case Log::Format::CLF_ICAP_SQUID
:
4225 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4228 case Log::Format::CLF_USERAGENT
:
4229 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4232 case Log::Format::CLF_REFERER
:
4233 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4236 case Log::Format::CLF_UNKNOWN
:
4241 dump_acl_list(entry
, log
->aclList
);
4243 storeAppendPrintf(entry
, "\n");
4248 free_access_log(CustomLog
** definitions
)
4250 while (*definitions
) {
4251 CustomLog
*log
= *definitions
;
4252 *definitions
= log
->next
;
4254 log
->logFormat
= NULL
;
4255 log
->type
= Log::Format::CLF_UNKNOWN
;
4258 aclDestroyAclList(&log
->aclList
);
4260 safe_free(log
->filename
);
4266 /// parses list of integers form name=N1,N2,N3,...
4268 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4270 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4271 data
+= name
.size();
4276 if (!StringToInt(data
, value
, &data
, 10))
4278 list
.push_back(value
);
4279 if (*data
== '\0' || *data
!= ',')
4284 return data
&& *data
== '\0';
4288 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4290 #if !HAVE_CPU_AFFINITY
4291 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4292 "support, do not set 'cpu_affinity_map'");
4294 #endif /* HAVE_CPU_AFFINITY */
4296 if (!*cpuAffinityMap
)
4297 *cpuAffinityMap
= new CpuAffinityMap
;
4299 const char *const pToken
= ConfigParser::NextToken();
4300 const char *const cToken
= ConfigParser::NextToken();
4301 Vector
<int> processes
, cores
;
4302 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4303 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4304 "in 'cpu_affinity_map'");
4306 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4307 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4308 "'cpu_affinity_map'");
4310 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4311 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4312 "process_numbers and cores lists differ in length or " <<
4313 "contain numbers <= 0");
4319 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4321 if (cpuAffinityMap
) {
4322 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4323 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4324 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4325 cpuAffinityMap
->processes()[i
]);
4327 storeAppendPrintf(entry
, " cores=");
4328 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4329 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4330 cpuAffinityMap
->cores()[i
]);
4332 storeAppendPrintf(entry
, "\n");
4337 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4339 delete *cpuAffinityMap
;
4340 *cpuAffinityMap
= NULL
;
4346 parse_adaptation_service_set_type()
4348 Adaptation::Config::ParseServiceSet();
4352 parse_adaptation_service_chain_type()
4354 Adaptation::Config::ParseServiceChain();
4358 parse_adaptation_access_type()
4360 Adaptation::Config::ParseAccess(LegacyParser
);
4362 #endif /* USE_ADAPTATION */
4367 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4369 cfg
->parseService();
4373 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4379 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4381 cfg
.dumpService(entry
, name
);
4385 parse_icap_class_type()
4387 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4388 "Use 'adaptation_service_set' instead");
4389 Adaptation::Config::ParseServiceSet();
4393 parse_icap_access_type()
4395 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4396 "Use 'adaptation_access' instead");
4397 Adaptation::Config::ParseAccess(LegacyParser
);
4405 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4407 cfg
->parseService();
4411 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4417 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4419 cfg
.dumpService(entry
, name
);
4422 #endif /* USE_ECAP */
4425 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4430 cfg
->service_failure_limit
= GetInteger();
4432 if ((token
= ConfigParser::NextToken()) == NULL
)
4435 if (strcmp(token
,"in") != 0) {
4436 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4440 if ((token
= ConfigParser::NextToken()) == NULL
) {
4444 d
= static_cast<time_t> (xatoi(token
));
4446 m
= static_cast<time_t> (1);
4450 else if ((token
= ConfigParser::NextToken()) == NULL
) {
4451 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4453 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4456 cfg
->oldest_service_failure
= (m
* d
);
4459 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4461 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4462 if (cfg
.oldest_service_failure
> 0) {
4463 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4465 storeAppendPrintf(entry
, "\n");
4468 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4470 cfg
->oldest_service_failure
= 0;
4471 cfg
->service_failure_limit
= 0;
4476 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4479 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4480 if ((al
= ConfigParser::NextToken()) == NULL
) {
4486 if ( char *s
= strchr(al
, '{')) {
4487 *s
= '\0'; // terminate the al string
4499 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4500 ca
->alg
= Ssl::algSetValidAfter
;
4501 ca
->param
= strdup("on");
4502 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4503 ca
->alg
= Ssl::algSetValidBefore
;
4504 ca
->param
= strdup("on");
4505 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4506 ca
->alg
= Ssl::algSetCommonName
;
4508 if (strlen(param
) > 64) {
4509 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4513 ca
->param
= strdup(param
);
4516 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4521 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4524 cert_adapt
= &(*cert_adapt
)->next
;
4529 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4531 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4532 storeAppendPrintf(entry
, "%s ", name
);
4533 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4535 dump_acl_list(entry
, ca
->aclList
);
4536 storeAppendPrintf(entry
, "\n");
4540 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4542 while (*cert_adapt
) {
4543 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4544 *cert_adapt
= ca
->next
;
4545 safe_free(ca
->param
);
4548 aclDestroyAclList(&ca
->aclList
);
4554 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4557 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4558 if ((al
= ConfigParser::NextToken()) == NULL
) {
4563 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4564 cs
->alg
= Ssl::algSignTrusted
;
4565 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4566 cs
->alg
= Ssl::algSignUntrusted
;
4567 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4568 cs
->alg
= Ssl::algSignSelf
;
4570 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4575 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4578 cert_sign
= &(*cert_sign
)->next
;
4583 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4585 sslproxy_cert_sign
*cs
;
4586 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4587 storeAppendPrintf(entry
, "%s ", name
);
4588 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4590 dump_acl_list(entry
, cs
->aclList
);
4591 storeAppendPrintf(entry
, "\n");
4595 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4597 while (*cert_sign
) {
4598 sslproxy_cert_sign
*cs
= *cert_sign
;
4599 *cert_sign
= cs
->next
;
4602 aclDestroyAclList(&cs
->aclList
);
4608 class sslBumpCfgRr
: public ::RegisteredRunner
4611 static Ssl::BumpMode lastDeprecatedRule
;
4612 /* RegisteredRunner API */
4613 virtual void run(const RunnerRegistry
&);
4616 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4618 RunnerRegistrationEntry(rrFinalizeConfig
, sslBumpCfgRr
);
4620 void sslBumpCfgRr::run(const RunnerRegistry
&r
)
4622 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4623 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4624 static char buf
[1024];
4625 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4626 strcpy(buf
, "ssl_bump deny all");
4627 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4628 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4629 "must not use implicit rules. Update your ssl_bump rules.");
4631 strcpy(buf
, "ssl_bump allow all");
4632 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4633 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4634 "inferior to the newer server-first bumping mode. New ssl_bump"
4635 " configurations must not use implicit rules. Update your ssl_bump rules.");
4641 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4643 typedef const char *BumpCfgStyle
;
4644 BumpCfgStyle bcsNone
= NULL
;
4645 BumpCfgStyle bcsNew
= "new client/server-first/none";
4646 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4647 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4648 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4650 if ((bm
= ConfigParser::NextToken()) == NULL
) {
4655 // if this is the first rule proccessed
4656 if (*ssl_bump
== NULL
) {
4657 bumpCfgStyleLast
= bcsNone
;
4658 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4661 allow_t action
= allow_t(ACCESS_ALLOWED
);
4663 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4664 action
.kind
= Ssl::bumpClientFirst
;
4665 bumpCfgStyleNow
= bcsNew
;
4666 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4667 action
.kind
= Ssl::bumpServerFirst
;
4668 bumpCfgStyleNow
= bcsNew
;
4669 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4670 action
.kind
= Ssl::bumpNone
;
4671 bumpCfgStyleNow
= bcsNew
;
4672 } else if (strcmp(bm
, "allow") == 0) {
4673 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4674 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4675 "is usually inferior to the newer server-first "
4676 "bumping mode. Update your ssl_bump rules.");
4677 action
.kind
= Ssl::bumpClientFirst
;
4678 bumpCfgStyleNow
= bcsOld
;
4679 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4680 } else if (strcmp(bm
, "deny") == 0) {
4681 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4682 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4683 "your ssl_bump rules.");
4684 action
.kind
= Ssl::bumpNone
;
4685 bumpCfgStyleNow
= bcsOld
;
4686 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4688 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4693 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4694 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4695 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4700 bumpCfgStyleLast
= bumpCfgStyleNow
;
4702 Acl::AndNode
*rule
= new Acl::AndNode
;
4703 rule
->context("(ssl_bump rule)", config_input_line
);
4709 *ssl_bump
= new Acl::Tree
;
4710 (*ssl_bump
)->context("(ssl_bump rules)", config_input_line
);
4713 (*ssl_bump
)->add(rule
, action
);
4716 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4719 wordlist
*lines
= ssl_bump
->treeDump(name
, Ssl::BumpModeStr
);
4720 dump_wordlist(entry
, lines
);
4721 wordlistDestroy(&lines
);
4725 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4727 free_acl_access(ssl_bump
);
4732 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4737 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4738 storeAppendPrintf(entry
, "%s ", hwa
->fieldName
.c_str());
4739 storeAppendPrintf(entry
, "%s ", hwa
->fieldValue
.c_str());
4741 dump_acl_list(entry
, hwa
->aclList
);
4742 storeAppendPrintf(entry
, "\n");
4746 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4750 *headers
= new HeaderWithAclList
;
4752 if ((fn
= ConfigParser::NextToken()) == NULL
) {
4758 hwa
.fieldId
= httpHeaderIdByNameDef(fn
, strlen(fn
));
4759 if (hwa
.fieldId
== HDR_BAD_HDR
)
4760 hwa
.fieldId
= HDR_OTHER
;
4762 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4763 ConfigParser::EnableMacros();
4764 String buf
= ConfigParser::NextQuotedToken();
4765 ConfigParser::DisableMacros();
4766 hwa
.fieldValue
= buf
.termedBuf();
4767 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4769 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4773 hwa
.valueFormat
= nlf
;
4776 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4777 (*headers
)->push_back(hwa
);
4780 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4785 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4787 aclDestroyAclList(&hwa
->aclList
);
4789 if (hwa
->valueFormat
) {
4790 delete hwa
->valueFormat
;
4791 hwa
->valueFormat
= NULL
;
4798 static void parse_note(Notes
*notes
)
4801 notes
->parse(LegacyParser
);
4804 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4806 notes
.dump(entry
, name
);
4809 static void free_note(Notes
*notes
)
4815 parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
)
4820 // If quoted values is set to on then enable new strict mode parsing
4822 ConfigParser::RecognizeQuotedValues
= true;
4823 ConfigParser::StrictMode
= true;
4825 ConfigParser::RecognizeQuotedValues
= false;
4826 ConfigParser::StrictMode
= false;
4831 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
)
4833 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4834 dump_onoff(entry
, name
, val
);
4838 free_configuration_includes_quoted_values(bool *recognizeQuotedValues
)
4840 ConfigParser::RecognizeQuotedValues
= false;
4841 ConfigParser::StrictMode
= false;