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"
43 #include "anyp/UriScheme.h"
45 #include "base/RunnersRegistry.h"
47 #include "CachePeer.h"
48 #include "CachePeerDomainList.h"
49 #include "ConfigParser.h"
50 #include "CpuAffinityMap.h"
51 #include "DiskIO/DiskIOModule.h"
52 #include "eui/Config.h"
53 #include "ExternalACL.h"
54 #include "format/Format.h"
56 #include "HttpHeaderTools.h"
57 #include "HttpRequestMethod.h"
58 #include "ident/Config.h"
59 #include "ip/Intercept.h"
60 #include "ip/QosConfig.h"
63 #include "log/Config.h"
64 #include "log/CustomLog.h"
67 #include "mgr/ActionPasswordList.h"
68 #include "mgr/Registration.h"
69 #include "neighbors.h"
70 #include "NeighborTypeDomainList.h"
72 #include "PeerDigest.h"
73 #include "RefreshPattern.h"
75 #include "SquidConfig.h"
76 #include "SquidString.h"
77 #include "ssl/ProxyCerts.h"
79 #include "StoreFileSystem.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"
121 #include <sys/stat.h>
125 #include "ssl/gadgets.h"
129 static void parse_adaptation_service_set_type();
130 static void parse_adaptation_service_chain_type();
131 static void parse_adaptation_access_type();
135 static void parse_icap_service_type(Adaptation::Icap::Config
*);
136 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
137 static void free_icap_service_type(Adaptation::Icap::Config
*);
138 static void parse_icap_class_type();
139 static void parse_icap_access_type();
141 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
142 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
143 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
147 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
148 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
149 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
152 static peer_t
parseNeighborType(const char *s
);
154 CBDATA_TYPE(CachePeer
);
156 static const char *const T_MILLISECOND_STR
= "millisecond";
157 static const char *const T_SECOND_STR
= "second";
158 static const char *const T_MINUTE_STR
= "minute";
159 static const char *const T_HOUR_STR
= "hour";
160 static const char *const T_DAY_STR
= "day";
161 static const char *const T_WEEK_STR
= "week";
162 static const char *const T_FORTNIGHT_STR
= "fortnight";
163 static const char *const T_MONTH_STR
= "month";
164 static const char *const T_YEAR_STR
= "year";
165 static const char *const T_DECADE_STR
= "decade";
167 static const char *const B_BYTES_STR
= "bytes";
168 static const char *const B_KBYTES_STR
= "KB";
169 static const char *const B_MBYTES_STR
= "MB";
170 static const char *const B_GBYTES_STR
= "GB";
172 static const char *const list_sep
= ", \t\n\r";
174 static void parse_access_log(CustomLog
** customlog_definitions
);
175 static int check_null_access_log(CustomLog
*customlog_definitions
);
176 static void dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* definitions
);
177 static void free_access_log(CustomLog
** definitions
);
178 static bool setLogformat(CustomLog
*cl
, const char *name
, const bool dieWhenMissing
);
180 static void update_maxobjsize(void);
181 static void configDoConfigure(void);
182 static void parse_refreshpattern(RefreshPattern
**);
183 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
184 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
185 static void parse_u_short(unsigned short * var
);
186 static void parse_string(char **);
187 static void default_all(void);
188 static void defaults_if_none(void);
189 static void defaults_postscriptum(void);
190 static int parse_line(char *);
191 static void parse_obsolete(const char *);
192 static void parseBytesLine(size_t * bptr
, const char *units
);
194 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
196 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
197 static size_t parseBytesUnits(const char *unit
);
198 static void free_all(void);
199 void requirePathnameExists(const char *name
, const char *path
);
200 static OBJH dump_config
;
201 #if USE_HTTP_VIOLATIONS
202 static void free_HeaderManglers(HeaderManglers
**pm
);
203 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
204 static void parse_http_header_access(HeaderManglers
**manglers
);
205 #define free_http_header_access free_HeaderManglers
206 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
);
207 static void parse_http_header_replace(HeaderManglers
**manglers
);
208 #define free_http_header_replace free_HeaderManglers
210 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
);
211 static void parse_HeaderWithAclList(HeaderWithAclList
**header
);
212 static void free_HeaderWithAclList(HeaderWithAclList
**header
);
213 static void parse_note(Notes
*);
214 static void dump_note(StoreEntry
*, const char *, Notes
&);
215 static void free_note(Notes
*);
216 static void parse_denyinfo(AclDenyInfoList
** var
);
217 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
);
218 static void free_denyinfo(AclDenyInfoList
** var
);
221 static void parse_IpAddress_list(Ip::Address_list
**);
222 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
223 static void free_IpAddress_list(Ip::Address_list
**);
225 static int check_null_IpAddress_list(const Ip::Address_list
*);
226 #endif /* CURRENTLY_UNUSED */
227 #endif /* USE_WCCPv2 */
229 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
230 #define parse_PortCfg(l) parsePortCfg((l), token)
231 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
232 static void free_PortCfg(AnyP::PortCfg
**);
235 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
236 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
);
237 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
);
238 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
239 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
);
240 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
);
241 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
);
242 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
);
243 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
);
246 static void parse_b_size_t(size_t * var
);
247 static void parse_b_int64_t(int64_t * var
);
249 static bool parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
);
251 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
252 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
253 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
255 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
257 static void parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
258 static void dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
);
259 static void free_configuration_includes_quoted_values(bool *recognizeQuotedValues
);
262 * LegacyParser is a parser for legacy code that uses the global
263 * approach. This is static so that it is only exposed to cache_cf.
264 * Other modules needing access to a ConfigParser should have it
265 * provided to them in their parserFOO methods.
267 static ConfigParser LegacyParser
= ConfigParser();
272 LegacyParser
.destruct();
276 update_maxobjsize(void)
280 // determine the maximum size object that can be stored to disk
281 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
282 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
284 const int64_t storeMax
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->maxObjectSize();
289 // Ensure that we do not discard objects which could be stored only in memory.
290 // It is governed by maximum_object_size_in_memory (for now)
291 // TODO: update this to check each in-memory location (SMP and local memory limits differ)
292 if (ms
< static_cast<int64_t>(Config
.Store
.maxInMemObjSize
))
293 ms
= Config
.Store
.maxInMemObjSize
;
295 store_maxobjsize
= ms
;
299 SetConfigFilename(char const *file_name
, bool is_pipe
)
302 cfg_filename
= file_name
+ 1;
304 cfg_filename
= file_name
;
308 skip_ws(const char* s
)
317 parseManyConfigFiles(char* files
, int depth
)
320 char* saveptr
= NULL
;
325 memset(&globbuf
, 0, sizeof(globbuf
));
326 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
327 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
328 fatalf("Unable to find configuration file: %s: %s",
332 for (i
= 0; i
< (int)globbuf
.gl_pathc
; ++i
) {
333 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
337 char* file
= strwordtok(files
, &saveptr
);
338 while (file
!= NULL
) {
339 error_count
+= parseOneConfigFile(file
, depth
);
340 file
= strwordtok(NULL
, &saveptr
);
342 #endif /* HAVE_GLOB */
347 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
350 assert(newSubstr
!= NULL
);
352 unsigned newSubstrLen
= strlen(newSubstr
);
353 if (newSubstrLen
> substrLen
)
354 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
356 // move tail part including zero
357 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
358 // copy new substring in place
359 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
365 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
367 assert(line
!= NULL
);
368 assert(macroName
!= NULL
);
369 assert(substStr
!= NULL
);
370 unsigned macroNameLen
= strlen(macroName
);
371 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
372 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
376 ProcessMacros(char*& line
, int& len
)
378 SubstituteMacro(line
, len
, "${service_name}", service_name
);
379 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
380 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
384 trim_trailing_ws(char* str
)
387 unsigned i
= strlen(str
);
388 while ((i
> 0) && xisspace(str
[i
- 1]))
394 FindStatement(const char* line
, const char* statement
)
396 assert(line
!= NULL
);
397 assert(statement
!= NULL
);
399 const char* str
= skip_ws(line
);
400 unsigned len
= strlen(statement
);
401 if (strncmp(str
, statement
, len
) == 0) {
405 else if (xisspace(*str
))
413 StrToInt(const char* str
, long& number
)
418 number
= strtol(str
, &end
, 0);
420 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
424 EvalBoolExpr(const char* expr
)
426 assert(expr
!= NULL
);
427 if (strcmp(expr
, "true") == 0) {
429 } else if (strcmp(expr
, "false") == 0) {
431 } else if (const char* equation
= strchr(expr
, '=')) {
432 const char* rvalue
= skip_ws(equation
+ 1);
433 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
434 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
435 trim_trailing_ws(lvalue
);
438 if (!StrToInt(lvalue
, number1
))
439 fatalf("String is not a integer number: '%s'\n", lvalue
);
441 if (!StrToInt(rvalue
, number2
))
442 fatalf("String is not a integer number: '%s'\n", rvalue
);
445 return number1
== number2
;
447 fatalf("Unable to evaluate expression '%s'\n", expr
);
448 return false; // this place cannot be reached
452 parseOneConfigFile(const char *file_name
, unsigned int depth
)
455 const char *orig_cfg_filename
= cfg_filename
;
456 const int orig_config_lineno
= config_lineno
;
458 char *tmp_line
= NULL
;
459 int tmp_line_len
= 0;
463 debugs(3, DBG_IMPORTANT
, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
465 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
469 if (file_name
[0] == '!' || file_name
[0] == '|') {
470 fp
= popen(file_name
+ 1, "r");
473 fp
= fopen(file_name
, "r");
477 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
480 setmode(fileno(fp
), O_TEXT
);
483 SetConfigFilename(file_name
, bool(is_pipe
));
485 memset(config_input_line
, '\0', BUFSIZ
);
489 std::vector
<bool> if_states
;
490 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
493 if ((token
= strchr(config_input_line
, '\n')))
496 if ((token
= strchr(config_input_line
, '\r')))
499 // strip any prefix whitespace off the line.
500 const char *p
= skip_ws(config_input_line
);
501 if (config_input_line
!= p
)
502 memmove(config_input_line
, p
, strlen(p
)+1);
504 if (strncmp(config_input_line
, "#line ", 6) == 0) {
505 static char new_file_name
[1024];
507 static char new_lineno
;
508 token
= config_input_line
+ 6;
509 new_lineno
= strtol(token
, &file
, 0) - 1;
512 continue; /* Not a valid #line directive, may be a comment */
514 while (*file
&& xisspace((unsigned char) *file
))
519 continue; /* Not a valid #line directive, may be a comment */
521 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
523 if ((token
= strchr(new_file_name
, '"')))
526 SetConfigFilename(new_file_name
, false);
529 config_lineno
= new_lineno
;
532 if (config_input_line
[0] == '#')
535 if (config_input_line
[0] == '\0')
538 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
540 size_t append_len
= strlen(append
);
542 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
544 strcpy(tmp_line
+ tmp_line_len
, append
);
546 tmp_line_len
+= append_len
;
548 if (tmp_line
[tmp_line_len
-1] == '\\') {
549 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
550 tmp_line
[--tmp_line_len
] = '\0';
554 trim_trailing_ws(tmp_line
);
555 ProcessMacros(tmp_line
, tmp_line_len
);
556 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
558 if (const char* expr
= FindStatement(tmp_line
, "if")) {
559 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
560 } else if (FindStatement(tmp_line
, "endif")) {
561 if (!if_states
.empty())
562 if_states
.pop_back(); // remove last if-statement meaning
564 fatalf("'endif' without 'if'\n");
565 } else if (FindStatement(tmp_line
, "else")) {
566 if (!if_states
.empty())
567 if_states
.back() = !if_states
.back();
569 fatalf("'else' without 'if'\n");
570 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
571 /* Handle includes here */
572 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
573 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
574 } else if (!parse_line(tmp_line
)) {
575 debugs(3, DBG_CRITICAL
, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
584 if (!if_states
.empty())
585 fatalf("if-statement without 'endif'\n");
588 int ret
= pclose(fp
);
591 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
596 SetConfigFilename(orig_cfg_filename
, false);
597 config_lineno
= orig_config_lineno
;
604 parseConfigFile(const char *file_name
)
612 ACLMethodData::ThePurgeCount
= 0;
615 err_count
= parseOneConfigFile(file_name
, 0);
619 defaults_postscriptum();
622 * We must call configDoConfigure() before leave_suid() because
623 * configDoConfigure() is where we turn username strings into
628 if (!Config
.chroot_dir
) {
630 setUmask(Config
.umask
);
631 _db_init(Debug::cache_log
, Debug::debugOptions
);
635 if (opt_send_signal
== -1) {
636 Mgr::RegisterAction("config",
637 "Current Squid Configuration",
646 configDoConfigure(void)
648 memset(&Config2
, '\0', sizeof(SquidConfig2
));
649 /* init memory as early as possible */
653 Config
.cacheSwap
.n_strands
= 0; // no diskers by default
654 if (Config
.cacheSwap
.swapDirs
== NULL
) {
655 /* Memory-only cache probably in effect. */
656 /* turn off the cache rebuild delays... */
657 StoreController::store_dirs_rebuilding
= 0;
658 } else if (InDaemonMode()) { // no diskers in non-daemon mode
659 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
660 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
661 if (sd
->needsDiskStrand())
662 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
666 if (Debug::rotateNumber
< 0) {
667 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
670 #if SIZEOF_OFF_T <= 4
671 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
672 debugs(3, DBG_CRITICAL
, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
673 Config
.Store
.maxObjectSize
= 0x7FFF0000;
677 if (Config
.Announce
.period
> 0) {
678 Config
.onoff
.announce
= 1;
680 Config
.Announce
.period
= 86400 * 365; /* one year */
681 Config
.onoff
.announce
= 0;
684 if (Config
.onoff
.httpd_suppress_version_string
)
685 visible_appname_string
= (char *)appname_string
;
687 visible_appname_string
= (char const *)APP_FULLNAME
;
689 if (Config
.Program
.redirect
) {
690 if (Config
.redirectChildren
.n_max
< 1) {
691 Config
.redirectChildren
.n_max
= 0;
692 wordlistDestroy(&Config
.Program
.redirect
);
696 if (Config
.Program
.store_id
) {
697 if (Config
.storeIdChildren
.n_max
< 1) {
698 Config
.storeIdChildren
.n_max
= 0;
699 wordlistDestroy(&Config
.Program
.store_id
);
703 if (Config
.appendDomain
)
704 if (*Config
.appendDomain
!= '.')
705 fatal("append_domain must begin with a '.'");
707 if (Config
.errHtmlText
== NULL
)
708 Config
.errHtmlText
= xstrdup(null_string
);
710 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
711 if (Config
.max_filedescriptors
> 0) {
712 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
714 #elif USE_SELECT || USE_SELECT_WIN32
715 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
716 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
722 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
724 visible_appname_string
);
727 * the extra space is for loop detection in client_side.c -- we search
728 * for substrings in the Via header.
730 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
732 visible_appname_string
);
734 /* Use visible_hostname as default surrogate_id */
735 if (!Config
.Accel
.surrogate_id
) {
736 const char *t
= getMyHostname();
737 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
740 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
741 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
743 if (Config
.appendDomain
)
744 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
746 Config
.appendDomainLen
= 0;
748 if (Config
.connect_retries
> 10) {
749 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
750 Config
.connect_retries
= 10;
753 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
756 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
758 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
759 if (Config
.Program
.redirect
)
760 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
762 if (Config
.Program
.store_id
)
763 requirePathnameExists("store_id_program", Config
.Program
.store_id
->key
);
765 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
767 if (Config
.errorDirectory
)
768 requirePathnameExists("Error Directory", Config
.errorDirectory
);
770 #if USE_HTTP_VIOLATIONS
773 const RefreshPattern
*R
;
775 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
776 if (!R
->flags
.override_expire
)
779 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
784 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
785 if (!R
->flags
.override_lastmod
)
788 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
793 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
794 if (!R
->flags
.reload_into_ims
)
797 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
802 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
803 if (!R
->flags
.ignore_reload
)
806 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
811 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
812 if (!R
->flags
.ignore_no_store
)
815 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
820 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
821 if (!R
->flags
.ignore_must_revalidate
)
823 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
827 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
828 if (!R
->flags
.ignore_private
)
831 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
836 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
837 if (!R
->flags
.ignore_auth
)
840 debugs(22, DBG_IMPORTANT
, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
847 #if !USE_HTTP_VIOLATIONS
848 Config
.onoff
.via
= 1;
851 if (!Config
.onoff
.via
)
852 debugs(22, DBG_IMPORTANT
, "WARNING: HTTP requires the use of Via");
856 // we enable runtime PURGE checks if there is at least one PURGE method ACL
857 // TODO: replace with a dedicated "purge" ACL option?
858 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
860 Config2
.onoff
.mangle_request_headers
= (Config
.request_header_access
!= NULL
);
862 if (geteuid() == 0) {
863 if (NULL
!= Config
.effectiveUser
) {
865 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
869 * Andres Kroonmaa <andre@online.ee>:
870 * Some getpwnam() implementations (Solaris?) require
871 * an available FD < 256 for opening a FILE* to the
874 * This should be safe at startup, but might still fail
875 * during reconfigure.
877 fatalf("getpwnam failed to find userid for effective user '%s'",
878 Config
.effectiveUser
);
882 Config2
.effectiveUserID
= pwd
->pw_uid
;
884 Config2
.effectiveGroupID
= pwd
->pw_gid
;
888 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
890 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
891 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
899 Config2
.effectiveUserID
= geteuid();
900 Config2
.effectiveGroupID
= getegid();
903 if (NULL
!= Config
.effectiveGroup
) {
905 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
908 fatalf("getgrnam failed to find groupid for effective group '%s'",
909 Config
.effectiveGroup
);
913 Config2
.effectiveGroupID
= grp
->gr_gid
;
918 debugs(3, DBG_IMPORTANT
, "Initializing https proxy context");
920 Config
.ssl_client
.sslContext
= sslCreateClientContext(Config
.ssl_client
.cert
, Config
.ssl_client
.key
, Config
.ssl_client
.version
, Config
.ssl_client
.cipher
, Config
.ssl_client
.options
, Config
.ssl_client
.flags
, Config
.ssl_client
.cafile
, Config
.ssl_client
.capath
, Config
.ssl_client
.crlfile
);
922 for (CachePeer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
924 debugs(3, DBG_IMPORTANT
, "Initializing cache_peer " << p
->name
<< " SSL context");
925 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
929 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
930 if (!s
->flags
.tunnelSslBumping
)
933 debugs(3, DBG_IMPORTANT
, "Initializing http_port " << s
->s
<< " SSL context");
934 s
->configureSslServerContext();
937 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
938 debugs(3, DBG_IMPORTANT
, "Initializing https_port " << s
->s
<< " SSL context");
939 s
->configureSslServerContext();
944 // prevent infinite fetch loops in the request parser
945 // due to buffer full but not enough data recived to finish parse
946 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
947 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
948 " Change client_request_buffer_max or request_header_max_size limits.",
949 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
953 * Disable client side request pipelining if client_persistent_connections OFF.
954 * Waste of resources queueing any pipelined requests when the first will close the connection.
956 if (Config
.pipeline_max_prefetch
> 0 && !Config
.onoff
.client_pconns
) {
957 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch " << Config
.pipeline_max_prefetch
<<
958 " requires client_persistent_connections ON. Forced pipeline_prefetch 0.");
959 Config
.pipeline_max_prefetch
= 0;
964 * disable client side request pipelining. There is a race with
965 * Negotiate and NTLM when the client sends a second request on an
966 * connection before the authenticate challenge is sent. With
967 * pipelining OFF, the client may fail to authenticate, but squid's
968 * state will be preserved.
970 if (Config
.pipeline_max_prefetch
> 0) {
971 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
972 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
973 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
974 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced pipeline_prefetch 0.");
975 Config
.pipeline_max_prefetch
= 0;
981 /** Parse a line containing an obsolete directive.
982 * To upgrade it where possible instead of just "Bungled config" for
983 * directives which cannot be marked as simply aliases of the some name.
984 * For example if the parameter order and content has changed.
985 * Or if the directive has been completely removed.
988 parse_obsolete(const char *name
)
990 // Directives which have been radically changed rather than removed
991 if (!strcmp(name
, "url_rewrite_concurrency")) {
994 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
995 Config
.redirectChildren
.concurrency
= cval
;
998 if (!strcmp(name
, "log_access"))
1001 if (!strcmp(name
, "log_icap"))
1004 if (!strcmp(name
, "ignore_ims_on_miss")) {
1005 // the replacement directive cache_revalidate_on_miss has opposite meanings for ON/OFF value
1006 // than the 2.7 directive. We need to parse and invert the configured value.
1009 Config
.onoff
.cache_miss_revalidate
= !temp
;
1013 /* Parse a time specification from the config file. Store the
1014 * result in 'tptr', after converting it to 'units' */
1016 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
1023 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
1026 if ((token
= ConfigParser::NextToken()) == NULL
)
1031 m
= u
; /* default to 'units' if none specified */
1035 else if ((token
= ConfigParser::NextToken()) == NULL
)
1036 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1037 config_input_line
<< "', assuming " <<
1038 d
<< " " << units
);
1039 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1042 *tptr
= static_cast<time_msec_t
>(m
* d
);
1044 if (static_cast<double>(*tptr
) * 2 != m
* d
* 2) {
1045 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1046 d
<< " " << token
<< ": integer overflow (time_msec_t).");
1052 parseTimeUnits(const char *unit
, bool allowMsec
)
1054 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1057 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1060 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1063 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1066 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1067 return 86400 * 1000;
1069 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1070 return 86400 * 7 * 1000;
1072 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1073 return 86400 * 14 * 1000;
1075 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1076 return static_cast<uint64_t>(86400) * 30 * 1000;
1078 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1079 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1081 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1082 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1084 debugs(3, DBG_IMPORTANT
, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1090 parseBytesLine64(int64_t * bptr
, const char *units
)
1097 if ((u
= parseBytesUnits(units
)) == 0) {
1102 if ((token
= ConfigParser::NextToken()) == NULL
) {
1107 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1114 m
= u
; /* default to 'units' if none specified */
1118 else if ((token
= ConfigParser::NextToken()) == NULL
)
1119 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1120 config_input_line
<< "', assuming " <<
1121 d
<< " " << units
);
1122 else if ((m
= parseBytesUnits(token
)) == 0) {
1127 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1129 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1130 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1131 d
<< " " << token
<< ": integer overflow (int64_t).");
1137 parseBytesLine(size_t * bptr
, const char *units
)
1144 if ((u
= parseBytesUnits(units
)) == 0) {
1149 if ((token
= ConfigParser::NextToken()) == NULL
) {
1154 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1155 *bptr
= static_cast<size_t>(-1);
1161 m
= u
; /* default to 'units' if none specified */
1165 else if ((token
= ConfigParser::NextToken()) == NULL
)
1166 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1167 config_input_line
<< "', assuming " <<
1168 d
<< " " << units
);
1169 else if ((m
= parseBytesUnits(token
)) == 0) {
1174 *bptr
= static_cast<size_t>(m
* d
/ u
);
1176 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1177 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1178 d
<< " " << token
<< ": integer overflow (size_t).");
1184 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1191 if ((u
= parseBytesUnits(units
)) == 0) {
1196 if ((token
= ConfigParser::NextToken()) == NULL
) {
1201 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1208 m
= u
; /* default to 'units' if none specified */
1212 else if ((token
= ConfigParser::NextToken()) == NULL
)
1213 debugs(3, DBG_CRITICAL
, "WARNING: No units on '" <<
1214 config_input_line
<< "', assuming " <<
1215 d
<< " " << units
);
1216 else if ((m
= parseBytesUnits(token
)) == 0) {
1221 *bptr
= static_cast<ssize_t
>(m
* d
/ u
);
1223 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2) {
1224 debugs(3, DBG_CRITICAL
, "ERROR: Invalid value '" <<
1225 d
<< " " << token
<< ": integer overflow (ssize_t).");
1231 * Parse bytes from a string.
1232 * Similar to the parseBytesLine function but parses the string value instead of
1233 * the current token value.
1235 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1238 if ((u
= parseBytesUnits(units
)) == 0) {
1243 // Find number from string beginning.
1244 char const * number_begin
= value
;
1245 char const * number_end
= value
;
1247 while ((*number_end
>= '0' && *number_end
<= '9')) {
1252 number
.limitInit(number_begin
, number_end
- number_begin
);
1254 int d
= xatoi(number
.termedBuf());
1256 if ((m
= parseBytesUnits(number_end
)) == 0) {
1261 *bptr
= static_cast<size_t>(m
* d
/ u
);
1262 if (static_cast<double>(*bptr
) * 2 != (m
* d
/ u
) * 2)
1267 parseBytesUnits(const char *unit
)
1269 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1272 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1275 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1278 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1281 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1286 /*****************************************************************************
1288 *****************************************************************************/
1291 dump_wordlist(StoreEntry
* entry
, wordlist
*words
)
1293 for (wordlist
*word
= words
; word
; word
= word
->next
)
1294 storeAppendPrintf(entry
, "%s ", word
->key
);
1298 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1300 while (ae
!= NULL
) {
1301 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1302 storeAppendPrintf(entry
, "%s %s %s %s ",
1306 ae
->flags
.flagsStr());
1307 wordlist
*w
= ae
->dump();
1308 dump_wordlist(entry
, w
);
1310 storeAppendPrintf(entry
, "\n");
1311 wordlistDestroy(&w
);
1317 parse_acl(ACL
** ae
)
1319 ACL::ParseAclLine(LegacyParser
, ae
);
1329 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1331 wordlist
*values
= head
->dump();
1332 dump_wordlist(entry
, values
);
1333 wordlistDestroy(&values
);
1337 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1340 wordlist
*lines
= head
->treeDump(name
, NULL
);
1341 dump_wordlist(entry
, lines
);
1342 wordlistDestroy(&lines
);
1347 parse_acl_access(acl_access
** head
)
1349 aclParseAccessLine(cfg_directive
, LegacyParser
, head
);
1353 free_acl_access(acl_access
** head
)
1355 aclDestroyAccessList(head
);
1359 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1361 char buf
[MAX_IPSTRLEN
];
1362 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.toStr(buf
,MAX_IPSTRLEN
) );
1366 parse_address(Ip::Address
*addr
)
1368 char *token
= ConfigParser::NextToken();
1375 if (!strcmp(token
,"any_addr"))
1377 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1379 else if ( (*addr
= token
) ) // try parse numeric/IPA
1381 else if (addr
->GetHostByName(token
)) // dont use ipcache
1383 else { // not an IP and not a hostname
1384 debugs(3, DBG_CRITICAL
, "FATAL: invalid IP address or domain name '" << token
<< "'");
1390 free_address(Ip::Address
*addr
)
1395 CBDATA_TYPE(AclAddress
);
1398 dump_acl_address(StoreEntry
* entry
, const char *name
, AclAddress
* head
)
1400 char buf
[MAX_IPSTRLEN
];
1403 for (l
= head
; l
; l
= l
->next
) {
1404 if (!l
->addr
.isAnyAddr())
1405 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.toStr(buf
,MAX_IPSTRLEN
));
1407 storeAppendPrintf(entry
, "%s autoselect", name
);
1409 dump_acl_list(entry
, l
->aclList
);
1411 storeAppendPrintf(entry
, "\n");
1416 freed_acl_address(void *data
)
1418 AclAddress
*l
= static_cast<AclAddress
*>(data
);
1419 aclDestroyAclList(&l
->aclList
);
1423 parse_acl_address(AclAddress
** head
)
1426 AclAddress
**tail
= head
; /* sane name below */
1427 CBDATA_INIT_TYPE_FREECB(AclAddress
, freed_acl_address
);
1428 l
= cbdataAlloc(AclAddress
);
1429 parse_address(&l
->addr
);
1430 aclParseAclList(LegacyParser
, &l
->aclList
, l
->addr
);
1433 tail
= &(*tail
)->next
;
1439 free_acl_address(AclAddress
** head
)
1442 AclAddress
*l
= *head
;
1448 CBDATA_TYPE(acl_tos
);
1451 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1455 for (l
= head
; l
; l
= l
->next
) {
1457 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1459 storeAppendPrintf(entry
, "%s none", name
);
1461 dump_acl_list(entry
, l
->aclList
);
1463 storeAppendPrintf(entry
, "\n");
1468 freed_acl_tos(void *data
)
1470 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1471 aclDestroyAclList(&l
->aclList
);
1475 parse_acl_tos(acl_tos
** head
)
1478 acl_tos
**tail
= head
; /* sane name below */
1479 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1480 char *token
= ConfigParser::NextToken();
1487 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1492 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1494 l
= cbdataAlloc(acl_tos
);
1496 l
->tos
= (tos_t
)tos
;
1498 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1501 tail
= &(*tail
)->next
;
1507 free_acl_tos(acl_tos
** head
)
1517 #if SO_MARK && USE_LIBCAP
1519 CBDATA_TYPE(acl_nfmark
);
1522 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1526 for (l
= head
; l
; l
= l
->next
) {
1528 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1530 storeAppendPrintf(entry
, "%s none", name
);
1532 dump_acl_list(entry
, l
->aclList
);
1534 storeAppendPrintf(entry
, "\n");
1539 freed_acl_nfmark(void *data
)
1541 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1542 aclDestroyAclList(&l
->aclList
);
1546 parse_acl_nfmark(acl_nfmark
** head
)
1549 acl_nfmark
**tail
= head
; /* sane name below */
1551 char *token
= ConfigParser::NextToken();
1558 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1563 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1565 l
= cbdataAlloc(acl_nfmark
);
1569 aclParseAclList(LegacyParser
, &l
->aclList
, token
);
1572 tail
= &(*tail
)->next
;
1578 free_acl_nfmark(acl_nfmark
** head
)
1581 acl_nfmark
*l
= *head
;
1587 #endif /* SO_MARK */
1589 CBDATA_TYPE(AclSizeLimit
);
1592 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, AclSizeLimit
* head
)
1596 for (l
= head
; l
; l
= l
->next
) {
1598 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1600 storeAppendPrintf(entry
, "%s none", name
);
1602 dump_acl_list(entry
, l
->aclList
);
1604 storeAppendPrintf(entry
, "\n");
1609 freed_acl_b_size_t(void *data
)
1611 AclSizeLimit
*l
= static_cast<AclSizeLimit
*>(data
);
1612 aclDestroyAclList(&l
->aclList
);
1616 parse_acl_b_size_t(AclSizeLimit
** head
)
1619 AclSizeLimit
**tail
= head
; /* sane name below */
1621 CBDATA_INIT_TYPE_FREECB(AclSizeLimit
, freed_acl_b_size_t
);
1623 l
= cbdataAlloc(AclSizeLimit
);
1625 parse_b_int64_t(&l
->size
);
1627 aclParseAclList(LegacyParser
, &l
->aclList
, l
->size
);
1630 tail
= &(*tail
)->next
;
1636 free_acl_b_size_t(AclSizeLimit
** head
)
1639 AclSizeLimit
*l
= *head
;
1648 #include "DelayConfig.h"
1649 #include "DelayPools.h"
1650 /* do nothing - free_delay_pool_count is the magic free function.
1651 * this is why delay_pool_count isn't just marked TYPE: u_short
1653 #define free_delay_pool_class(X)
1654 #define free_delay_pool_access(X)
1655 #define free_delay_pool_rates(X)
1656 #define dump_delay_pool_class(X, Y, Z)
1657 #define dump_delay_pool_access(X, Y, Z)
1658 #define dump_delay_pool_rates(X, Y, Z)
1661 free_delay_pool_count(DelayConfig
* cfg
)
1663 cfg
->freePoolCount();
1667 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1669 cfg
.dumpPoolCount (entry
, name
);
1673 parse_delay_pool_count(DelayConfig
* cfg
)
1675 cfg
->parsePoolCount();
1679 parse_delay_pool_class(DelayConfig
* cfg
)
1681 cfg
->parsePoolClass();
1685 parse_delay_pool_rates(DelayConfig
* cfg
)
1687 cfg
->parsePoolRates();
1691 parse_delay_pool_access(DelayConfig
* cfg
)
1693 cfg
->parsePoolAccess(LegacyParser
);
1699 #include "ClientDelayConfig.h"
1700 /* do nothing - free_client_delay_pool_count is the magic free function.
1701 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1704 #define free_client_delay_pool_access(X)
1705 #define free_client_delay_pool_rates(X)
1706 #define dump_client_delay_pool_access(X, Y, Z)
1707 #define dump_client_delay_pool_rates(X, Y, Z)
1710 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1712 cfg
->freePoolCount();
1716 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1718 cfg
.dumpPoolCount (entry
, name
);
1722 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1724 cfg
->parsePoolCount();
1728 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1730 cfg
->parsePoolRates();
1734 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1736 cfg
->parsePoolAccess(LegacyParser
);
1740 #if USE_HTTP_VIOLATIONS
1742 dump_http_header_access(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1745 manglers
->dumpAccess(entry
, name
);
1749 parse_http_header_access(HeaderManglers
**pm
)
1753 if ((t
= ConfigParser::NextToken()) == NULL
) {
1754 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1755 debugs(3, DBG_CRITICAL
, "parse_http_header_access: missing header name.");
1760 *pm
= new HeaderManglers
;
1761 HeaderManglers
*manglers
= *pm
;
1762 headerMangler
*mangler
= manglers
->track(t
);
1765 std::string directive
= "http_header_access ";
1767 aclParseAccessLine(directive
.c_str(), LegacyParser
, &mangler
->access_list
);
1771 free_HeaderManglers(HeaderManglers
**pm
)
1773 // we delete the entire http_header_* mangler configuration at once
1774 if (const HeaderManglers
*manglers
= *pm
) {
1781 dump_http_header_replace(StoreEntry
* entry
, const char *name
, const HeaderManglers
*manglers
)
1784 manglers
->dumpReplacement(entry
, name
);
1788 parse_http_header_replace(HeaderManglers
**pm
)
1792 if ((t
= ConfigParser::NextToken()) == NULL
) {
1793 debugs(3, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1794 debugs(3, DBG_CRITICAL
, "parse_http_header_replace: missing header name.");
1798 const char *value
= ConfigParser::NextQuotedOrToEol();
1801 *pm
= new HeaderManglers
;
1802 HeaderManglers
*manglers
= *pm
;
1803 manglers
->setReplacement(t
, value
);
1809 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1815 for (i
= 0; i
< swap
.n_configured
; ++i
) {
1816 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1818 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1820 storeAppendPrintf(entry
, "\n");
1825 check_null_string(char *s
)
1832 parse_authparam(Auth::ConfigVector
* config
)
1837 if ((type_str
= ConfigParser::NextToken()) == NULL
)
1840 if ((param_str
= ConfigParser::NextToken()) == NULL
)
1843 /* find a configuration for the scheme in the currently parsed configs... */
1844 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1846 if (schemeCfg
== NULL
) {
1847 /* Create a configuration based on the scheme info */
1848 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1850 if (theScheme
== NULL
) {
1851 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1855 config
->push_back(theScheme
->createConfig());
1856 schemeCfg
= Auth::Config::Find(type_str
);
1857 if (schemeCfg
== NULL
) {
1858 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1863 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1867 free_authparam(Auth::ConfigVector
* cfg
)
1869 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1872 /* on reconfigure initialize new auth schemes for the new config. */
1873 if (reconfiguring
) {
1879 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1881 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1882 (*i
)->dump(entry
, name
, (*i
));
1884 #endif /* USE_AUTH */
1886 /* TODO: just return the object, the # is irrelevant */
1888 find_fstype(char *type
)
1890 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1891 if (strcasecmp(type
, StoreFileSystem::FileSystems().at(i
)->type()) == 0)
1898 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1902 RefCount
<SwapDir
> sd
;
1906 if ((type_str
= ConfigParser::NextToken()) == NULL
)
1909 if ((path_str
= ConfigParser::NextToken()) == NULL
)
1912 fs
= find_fstype(type_str
);
1915 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: This proxy does not support the '" << type_str
<< "' cache type. Ignoring.");
1919 /* reconfigure existing dir */
1921 for (i
= 0; i
< swap
->n_configured
; ++i
) {
1922 assert (swap
->swapDirs
[i
].getRaw());
1924 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1925 /* this is specific to on-fs Stores. The right
1926 * way to handle this is probably to have a mapping
1927 * from paths to stores, and have on-fs stores
1928 * register with that, and lookip in that in their
1929 * own setup logic. RBC 20041225. TODO.
1932 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1934 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().at(fs
)->type()) != 0) {
1935 debugs(3, DBG_CRITICAL
, "ERROR: Can't change type of existing cache_dir " <<
1936 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1942 update_maxobjsize();
1949 if (swap
->n_configured
> 63) {
1950 /* 7 bits, signed */
1951 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1952 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1957 allocate_new_swapdir(swap
);
1959 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().at(fs
)->createSwapDir();
1961 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1963 /* parse the FS parameters and options */
1964 sd
->parse(swap
->n_configured
, path_str
);
1966 ++swap
->n_configured
;
1968 /* Update the max object size */
1969 update_maxobjsize();
1973 peer_type_str(const peer_t type
)
1975 const char * result
;
1987 case PEER_MULTICAST
:
1988 result
= "multicast";
2000 dump_peer(StoreEntry
* entry
, const char *name
, CachePeer
* p
)
2002 CachePeerDomainList
*d
;
2003 NeighborTypeDomainList
*t
;
2004 LOCAL_ARRAY(char, xname
, 128);
2007 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2014 dump_peer_options(entry
, p
);
2016 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2017 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2019 d
->do_ping
? null_string
: "!",
2024 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2025 dump_acl_access(entry
, xname
, p
->access
);
2028 for (t
= p
->typelist
; t
; t
= t
->next
) {
2029 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2031 peer_type_str(t
->type
),
2040 * utility function to prevent getservbyname() being called with a numeric value
2041 * on Windows at least it returns garage results.
2044 isUnsignedNumeric(const char *str
, size_t len
)
2046 if (len
< 1) return false;
2048 for (; len
>0 && *str
; ++str
, --len
) {
2049 if (! isdigit(*str
))
2056 \param proto 'tcp' or 'udp' for protocol
2057 \returns Port the named service is supposed to be listening on.
2059 static unsigned short
2060 GetService(const char *proto
)
2062 struct servent
*port
= NULL
;
2063 /** Parses a port number or service name from the squid.conf */
2064 char *token
= ConfigParser::NextToken();
2065 if (token
== NULL
) {
2067 return 0; /* NEVER REACHED */
2069 /** Returns either the service port number from /etc/services */
2070 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2071 port
= getservbyname(token
, proto
);
2073 return ntohs((unsigned short)port
->s_port
);
2075 /** Or a numeric translation of the config text. */
2076 return xatos(token
);
2080 \returns Port the named TCP service is supposed to be listening on.
2081 \copydoc GetService(const char *proto)
2083 inline unsigned short
2086 return GetService("tcp");
2090 \returns Port the named UDP service is supposed to be listening on.
2091 \copydoc GetService(const char *proto)
2093 inline unsigned short
2096 return GetService("udp");
2100 parse_peer(CachePeer
** head
)
2104 CBDATA_INIT_TYPE_FREECB(CachePeer
, peerDestroy
);
2105 p
= cbdataAlloc(CachePeer
);
2106 p
->http_port
= CACHE_HTTP_PORT
;
2107 p
->icp
.port
= CACHE_ICP_PORT
;
2110 p
->stats
.logged_state
= PEER_ALIVE
;
2112 if ((token
= ConfigParser::NextToken()) == NULL
)
2115 p
->host
= xstrdup(token
);
2117 p
->name
= xstrdup(token
);
2119 if ((token
= ConfigParser::NextToken()) == NULL
)
2122 p
->type
= parseNeighborType(token
);
2124 if (p
->type
== PEER_MULTICAST
) {
2125 p
->options
.no_digest
= true;
2126 p
->options
.no_netdb_exchange
= true;
2129 p
->http_port
= GetTcpService();
2134 p
->icp
.port
= GetUdpService();
2135 p
->connection_auth
= 2; /* auto */
2137 while ((token
= ConfigParser::NextToken())) {
2138 if (!strcmp(token
, "proxy-only")) {
2139 p
->options
.proxy_only
= true;
2140 } else if (!strcmp(token
, "no-query")) {
2141 p
->options
.no_query
= true;
2142 } else if (!strcmp(token
, "background-ping")) {
2143 p
->options
.background_ping
= true;
2144 } else if (!strcmp(token
, "no-digest")) {
2145 p
->options
.no_digest
= true;
2146 } else if (!strcmp(token
, "no-tproxy")) {
2147 p
->options
.no_tproxy
= true;
2148 } else if (!strcmp(token
, "multicast-responder")) {
2149 p
->options
.mcast_responder
= true;
2150 #if PEER_MULTICAST_SIBLINGS
2151 } else if (!strcmp(token
, "multicast-siblings")) {
2152 p
->options
.mcast_siblings
= true;
2154 } else if (!strncmp(token
, "weight=", 7)) {
2155 p
->weight
= xatoi(token
+ 7);
2156 } else if (!strncmp(token
, "basetime=", 9)) {
2157 p
->basetime
= xatoi(token
+ 9);
2158 } else if (!strcmp(token
, "closest-only")) {
2159 p
->options
.closest_only
= true;
2160 } else if (!strncmp(token
, "ttl=", 4)) {
2161 p
->mcast
.ttl
= xatoi(token
+ 4);
2163 if (p
->mcast
.ttl
< 0)
2166 if (p
->mcast
.ttl
> 128)
2168 } else if (!strcmp(token
, "default")) {
2169 p
->options
.default_parent
= true;
2170 } else if (!strcmp(token
, "round-robin")) {
2171 p
->options
.roundrobin
= true;
2172 } else if (!strcmp(token
, "weighted-round-robin")) {
2173 p
->options
.weighted_roundrobin
= true;
2175 } else if (!strcmp(token
, "htcp")) {
2176 p
->options
.htcp
= true;
2177 } else if (!strncmp(token
, "htcp=", 5) || !strncmp(token
, "htcp-", 5)) {
2178 /* Note: The htcp- form is deprecated, replaced by htcp= */
2179 p
->options
.htcp
= true;
2180 char *tmp
= xstrdup(token
+5);
2181 char *mode
, *nextmode
;
2182 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2183 nextmode
= strchr(mode
, ',');
2188 if (!strcmp(mode
, "no-clr")) {
2189 if (p
->options
.htcp_only_clr
)
2190 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2191 p
->options
.htcp_no_clr
= true;
2192 } else if (!strcmp(mode
, "no-purge-clr")) {
2193 p
->options
.htcp_no_purge_clr
= true;
2194 } else if (!strcmp(mode
, "only-clr")) {
2195 if (p
->options
.htcp_no_clr
)
2196 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2197 p
->options
.htcp_only_clr
= true;
2198 } else if (!strcmp(mode
, "forward-clr")) {
2199 p
->options
.htcp_forward_clr
= true;
2200 } else if (!strcmp(mode
, "oldsquid")) {
2201 p
->options
.htcp_oldsquid
= true;
2203 fatalf("invalid HTCP mode '%s'", mode
);
2208 } else if (!strcmp(token
, "no-netdb-exchange")) {
2209 p
->options
.no_netdb_exchange
= true;
2211 } else if (!strcmp(token
, "carp")) {
2212 if (p
->type
!= PEER_PARENT
)
2213 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2215 p
->options
.carp
= true;
2216 } else if (!strncmp(token
, "carp-key=", 9)) {
2217 if (p
->options
.carp
!= true)
2218 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2219 p
->options
.carp_key
.set
= true;
2220 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2221 for (; key
; key
= nextkey
) {
2222 nextkey
=strchr(key
,',');
2223 if (nextkey
) ++nextkey
; // skip the comma, any
2224 if (0==strncmp(key
,"scheme",6)) {
2225 p
->options
.carp_key
.scheme
= true;
2226 } else if (0==strncmp(key
,"host",4)) {
2227 p
->options
.carp_key
.host
= true;
2228 } else if (0==strncmp(key
,"port",4)) {
2229 p
->options
.carp_key
.port
= true;
2230 } else if (0==strncmp(key
,"path",4)) {
2231 p
->options
.carp_key
.path
= true;
2232 } else if (0==strncmp(key
,"params",6)) {
2233 p
->options
.carp_key
.params
= true;
2235 fatalf("invalid carp-key '%s'",key
);
2238 } else if (!strcmp(token
, "userhash")) {
2240 if (p
->type
!= PEER_PARENT
)
2241 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2243 p
->options
.userhash
= true;
2245 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2247 } else if (!strcmp(token
, "sourcehash")) {
2248 if (p
->type
!= PEER_PARENT
)
2249 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2251 p
->options
.sourcehash
= true;
2253 } else if (!strcmp(token
, "no-delay")) {
2255 p
->options
.no_delay
= true;
2257 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2259 } else if (!strncmp(token
, "login=", 6)) {
2260 p
->login
= xstrdup(token
+ 6);
2261 rfc1738_unescape(p
->login
);
2262 } else if (!strncmp(token
, "connect-timeout=", 16)) {
2263 p
->connect_timeout
= xatoi(token
+ 16);
2264 } else if (!strncmp(token
, "connect-fail-limit=", 19)) {
2265 p
->connect_fail_limit
= xatoi(token
+ 19);
2266 #if USE_CACHE_DIGESTS
2267 } else if (!strncmp(token
, "digest-url=", 11)) {
2268 p
->digest_url
= xstrdup(token
+ 11);
2271 } else if (!strcmp(token
, "allow-miss")) {
2272 p
->options
.allow_miss
= true;
2273 } else if (!strncmp(token
, "max-conn=", 9)) {
2274 p
->max_conn
= xatoi(token
+ 9);
2275 } else if (!strcmp(token
, "originserver")) {
2276 p
->options
.originserver
= true;
2277 } else if (!strncmp(token
, "name=", 5)) {
2281 p
->name
= xstrdup(token
+ 5);
2282 } else if (!strncmp(token
, "forceddomain=", 13)) {
2283 safe_free(p
->domain
);
2286 p
->domain
= xstrdup(token
+ 13);
2290 } else if (strcmp(token
, "ssl") == 0) {
2292 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2293 safe_free(p
->sslcert
);
2294 p
->sslcert
= xstrdup(token
+ 8);
2295 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2296 safe_free(p
->sslkey
);
2297 p
->sslkey
= xstrdup(token
+ 7);
2298 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2299 p
->sslversion
= xatoi(token
+ 11);
2300 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2301 safe_free(p
->ssloptions
);
2302 p
->ssloptions
= xstrdup(token
+ 11);
2303 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2304 safe_free(p
->sslcipher
);
2305 p
->sslcipher
= xstrdup(token
+ 10);
2306 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2307 safe_free(p
->sslcafile
);
2308 p
->sslcafile
= xstrdup(token
+ 10);
2309 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2310 safe_free(p
->sslcapath
);
2311 p
->sslcapath
= xstrdup(token
+ 10);
2312 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2313 safe_free(p
->sslcrlfile
);
2314 p
->sslcrlfile
= xstrdup(token
+ 11);
2315 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2316 safe_free(p
->sslflags
);
2317 p
->sslflags
= xstrdup(token
+ 9);
2318 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2319 safe_free(p
->ssldomain
);
2320 p
->ssldomain
= xstrdup(token
+ 10);
2323 } else if (strcmp(token
, "front-end-https") == 0) {
2324 p
->front_end_https
= 1;
2325 } else if (strcmp(token
, "front-end-https=on") == 0) {
2326 p
->front_end_https
= 1;
2327 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2328 p
->front_end_https
= 2;
2329 } else if (strcmp(token
, "connection-auth=off") == 0) {
2330 p
->connection_auth
= 0;
2331 } else if (strcmp(token
, "connection-auth") == 0) {
2332 p
->connection_auth
= 1;
2333 } else if (strcmp(token
, "connection-auth=on") == 0) {
2334 p
->connection_auth
= 1;
2335 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2336 p
->connection_auth
= 2;
2337 } else if (token
[0] == '#') {
2338 // start of a text comment. stop reading this line.
2341 debugs(3, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Ignoring unknown cache_peer option '" << token
<< "'");
2345 if (peerFindByName(p
->name
))
2346 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2351 if (p
->connect_fail_limit
< 1)
2352 p
->connect_fail_limit
= 10;
2354 p
->icp
.version
= ICP_VERSION_CURRENT
;
2356 p
->testing_now
= false;
2358 #if USE_CACHE_DIGESTS
2360 if (!p
->options
.no_digest
) {
2361 /* XXX This looks odd.. who has the original pointer
2364 PeerDigest
*pd
= peerDigestCreate(p
);
2365 p
->digest
= cbdataReference(pd
);
2370 p
->index
= ++Config
.npeers
;
2372 while (*head
!= NULL
)
2373 head
= &(*head
)->next
;
2381 free_peer(CachePeer
** P
)
2385 while ((p
= *P
) != NULL
) {
2387 #if USE_CACHE_DIGESTS
2389 cbdataReferenceDone(p
->digest
);
2399 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, Mgr::ActionPasswordList
* list
)
2403 while (list
!= NULL
) {
2404 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2405 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2407 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2409 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2410 storeAppendPrintf(entry
, " %s", w
->key
);
2413 storeAppendPrintf(entry
, "\n");
2419 parse_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2421 char *passwd
= NULL
;
2422 wordlist
*actions
= NULL
;
2423 Mgr::ActionPasswordList
*p
;
2424 Mgr::ActionPasswordList
**P
;
2425 parse_string(&passwd
);
2426 parse_wordlist(&actions
);
2427 p
= new Mgr::ActionPasswordList
;
2429 p
->actions
= actions
;
2431 for (P
= head
; *P
; P
= &(*P
)->next
) {
2433 * See if any of the actions from this line already have a
2434 * password from previous lines. The password checking
2435 * routines in cache_manager.c take the the password from
2436 * the first Mgr::ActionPasswordList that contains the
2437 * requested action. Thus, we should warn users who might
2438 * think they can have two passwords for the same action.
2443 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2444 for (u
= actions
; u
; u
= u
->next
) {
2445 if (strcmp(w
->key
, u
->key
))
2448 debugs(0, DBG_CRITICAL
, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2457 free_cachemgrpasswd(Mgr::ActionPasswordList
** head
)
2459 Mgr::ActionPasswordList
*p
;
2461 while ((p
= *head
) != NULL
) {
2464 wordlistDestroy(&p
->actions
);
2470 dump_denyinfo(StoreEntry
* entry
, const char *name
, AclDenyInfoList
* var
)
2474 while (var
!= NULL
) {
2475 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2477 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2478 storeAppendPrintf(entry
, " %s", a
->name
);
2480 storeAppendPrintf(entry
, "\n");
2487 parse_denyinfo(AclDenyInfoList
** var
)
2489 aclParseDenyInfoLine(var
);
2493 free_denyinfo(AclDenyInfoList
** list
)
2495 AclDenyInfoList
*a
= NULL
;
2496 AclDenyInfoList
*a_next
= NULL
;
2497 AclNameList
*l
= NULL
;
2498 AclNameList
*l_next
= NULL
;
2500 for (a
= *list
; a
; a
= a_next
) {
2501 for (l
= a
->acl_list
; l
; l
= l_next
) {
2503 memFree(l
, MEM_ACL_NAME_LIST
);
2508 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2516 parse_peer_access(void)
2521 if (!(host
= ConfigParser::NextToken()))
2524 if ((p
= peerFindByName(host
)) == NULL
) {
2525 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2529 std::string directive
= "peer_access ";
2531 aclParseAccessLine(directive
.c_str(), LegacyParser
, &p
->access
);
2535 parse_hostdomain(void)
2538 char *domain
= NULL
;
2540 if (!(host
= ConfigParser::NextToken()))
2543 while ((domain
= ConfigParser::NextToken())) {
2544 CachePeerDomainList
*l
= NULL
;
2545 CachePeerDomainList
**L
= NULL
;
2548 if ((p
= peerFindByName(host
)) == NULL
) {
2549 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2553 l
= static_cast<CachePeerDomainList
*>(xcalloc(1, sizeof(CachePeerDomainList
)));
2556 if (*domain
== '!') { /* check for !.edu */
2561 l
->domain
= xstrdup(domain
);
2563 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2569 parse_hostdomaintype(void)
2573 char *domain
= NULL
;
2575 if (!(host
= ConfigParser::NextToken()))
2578 if (!(type
= ConfigParser::NextToken()))
2581 while ((domain
= ConfigParser::NextToken())) {
2582 NeighborTypeDomainList
*l
= NULL
;
2583 NeighborTypeDomainList
**L
= NULL
;
2586 if ((p
= peerFindByName(host
)) == NULL
) {
2587 debugs(15, DBG_CRITICAL
, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2591 l
= static_cast<NeighborTypeDomainList
*>(xcalloc(1, sizeof(NeighborTypeDomainList
)));
2592 l
->type
= parseNeighborType(type
);
2593 l
->domain
= xstrdup(domain
);
2595 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2601 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2603 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2621 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2623 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2627 parse_onoff(int *var
)
2629 char *token
= ConfigParser::NextToken();
2634 if (!strcmp(token
, "on")) {
2636 } else if (!strcmp(token
, "enable")) {
2637 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use 'on'.");
2639 } else if (!strcmp(token
, "off")) {
2641 } else if (!strcmp(token
, "disable")) {
2642 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use 'off'.");
2645 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Boolean options can only be 'on' or 'off'.");
2650 #define free_onoff free_int
2653 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2664 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2668 parse_tristate(int *var
)
2670 char *token
= ConfigParser::NextToken();
2675 if (!strcmp(token
, "on")) {
2677 } else if (!strcmp(token
, "enable")) {
2678 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'enable' is deprecated. Please update to use value 'on'.");
2680 } else if (!strcmp(token
, "warn")) {
2682 } else if (!strcmp(token
, "off")) {
2684 } else if (!strcmp(token
, "disable")) {
2685 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'disable' is deprecated. Please update to use value 'off'.");
2688 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "ERROR: Invalid option: Tristate options can only be 'on', 'off', or 'warn'.");
2693 #define free_tristate free_int
2696 parse_pipelinePrefetch(int *var
)
2698 char *token
= ConfigParser::PeekAtToken();
2703 if (!strcmp(token
, "on")) {
2704 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT
), "WARNING: 'pipeline_prefetch on' is deprecated. Please update to use 1 (or a higher number).");
2707 (void)ConfigParser::NextToken();
2708 } else if (!strcmp(token
, "off")) {
2709 debugs(0, DBG_PARSE_NOTE(2), "WARNING: 'pipeline_prefetch off' is deprecated. Please update to use '0'.");
2712 (void)ConfigParser::NextToken();
2717 #define free_pipelinePrefetch free_int
2718 #define dump_pipelinePrefetch dump_int
2721 dump_refreshpattern(StoreEntry
* entry
, const char *name
, RefreshPattern
* head
)
2723 while (head
!= NULL
) {
2724 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2726 head
->flags
.icase
? " -i" : null_string
,
2728 (int) head
->min
/ 60,
2729 (int) (100.0 * head
->pct
+ 0.5),
2730 (int) head
->max
/ 60);
2732 if (head
->max_stale
>= 0)
2733 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2735 if (head
->flags
.refresh_ims
)
2736 storeAppendPrintf(entry
, " refresh-ims");
2738 if (head
->flags
.store_stale
)
2739 storeAppendPrintf(entry
, " store-stale");
2741 #if USE_HTTP_VIOLATIONS
2743 if (head
->flags
.override_expire
)
2744 storeAppendPrintf(entry
, " override-expire");
2746 if (head
->flags
.override_lastmod
)
2747 storeAppendPrintf(entry
, " override-lastmod");
2749 if (head
->flags
.reload_into_ims
)
2750 storeAppendPrintf(entry
, " reload-into-ims");
2752 if (head
->flags
.ignore_reload
)
2753 storeAppendPrintf(entry
, " ignore-reload");
2755 if (head
->flags
.ignore_no_store
)
2756 storeAppendPrintf(entry
, " ignore-no-store");
2758 if (head
->flags
.ignore_must_revalidate
)
2759 storeAppendPrintf(entry
, " ignore-must-revalidate");
2761 if (head
->flags
.ignore_private
)
2762 storeAppendPrintf(entry
, " ignore-private");
2764 if (head
->flags
.ignore_auth
)
2765 storeAppendPrintf(entry
, " ignore-auth");
2769 storeAppendPrintf(entry
, "\n");
2776 parse_refreshpattern(RefreshPattern
** head
)
2783 int refresh_ims
= 0;
2784 int store_stale
= 0;
2787 #if USE_HTTP_VIOLATIONS
2789 int override_expire
= 0;
2790 int override_lastmod
= 0;
2791 int reload_into_ims
= 0;
2792 int ignore_reload
= 0;
2793 int ignore_no_store
= 0;
2794 int ignore_must_revalidate
= 0;
2795 int ignore_private
= 0;
2796 int ignore_auth
= 0;
2803 int flags
= REG_EXTENDED
| REG_NOSUB
;
2805 if ((token
= ConfigParser::RegexPattern()) != NULL
) {
2807 if (strcmp(token
, "-i") == 0) {
2809 token
= ConfigParser::RegexPattern();
2810 } else if (strcmp(token
, "+i") == 0) {
2811 flags
&= ~REG_ICASE
;
2812 token
= ConfigParser::RegexPattern();
2817 if (token
== NULL
) {
2818 debugs(3, DBG_CRITICAL
, "FATAL: refresh_pattern missing the regex pattern parameter");
2823 pattern
= xstrdup(token
);
2825 i
= GetInteger(); /* token: min */
2827 /* catch negative and insanely huge values close to 32-bit wrap */
2829 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2832 if (i
> 60*24*365) {
2833 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2837 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2839 i
= GetPercentage(); /* token: pct */
2841 pct
= (double) i
/ 100.0;
2843 i
= GetInteger(); /* token: max */
2845 /* catch negative and insanely huge values close to 32-bit wrap */
2847 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2850 if (i
> 60*24*365) {
2851 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2855 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2858 while ((token
= ConfigParser::NextToken()) != NULL
) {
2859 if (!strcmp(token
, "refresh-ims")) {
2861 } else if (!strcmp(token
, "store-stale")) {
2863 } else if (!strncmp(token
, "max-stale=", 10)) {
2864 max_stale
= xatoi(token
+ 10);
2865 #if USE_HTTP_VIOLATIONS
2867 } else if (!strcmp(token
, "override-expire"))
2868 override_expire
= 1;
2869 else if (!strcmp(token
, "override-lastmod"))
2870 override_lastmod
= 1;
2871 else if (!strcmp(token
, "ignore-no-store"))
2872 ignore_no_store
= 1;
2873 else if (!strcmp(token
, "ignore-must-revalidate"))
2874 ignore_must_revalidate
= 1;
2875 else if (!strcmp(token
, "ignore-private"))
2877 else if (!strcmp(token
, "ignore-auth"))
2879 else if (!strcmp(token
, "reload-into-ims")) {
2880 reload_into_ims
= 1;
2881 refresh_nocache_hack
= 1;
2882 /* tell client_side.c that this is used */
2883 } else if (!strcmp(token
, "ignore-reload")) {
2885 refresh_nocache_hack
= 1;
2886 /* tell client_side.c that this is used */
2889 } else if (!strcmp(token
, "ignore-no-cache")) {
2890 debugs(22, DBG_PARSE_NOTE(2), "UPGRADE: refresh_pattern option 'ignore-no-cache' is obsolete. Remove it.");
2892 debugs(22, DBG_CRITICAL
, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2895 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2897 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2898 debugs(22, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2899 debugs(22, DBG_CRITICAL
, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2904 pct
= pct
< 0.0 ? 0.0 : pct
;
2905 max
= max
< 0 ? 0 : max
;
2906 t
= static_cast<RefreshPattern
*>(xcalloc(1, sizeof(RefreshPattern
)));
2907 t
->pattern
= (char *) xstrdup(pattern
);
2908 t
->compiled_pattern
= comp
;
2913 if (flags
& REG_ICASE
)
2914 t
->flags
.icase
= true;
2917 t
->flags
.refresh_ims
= true;
2920 t
->flags
.store_stale
= true;
2922 t
->max_stale
= max_stale
;
2924 #if USE_HTTP_VIOLATIONS
2926 if (override_expire
)
2927 t
->flags
.override_expire
= true;
2929 if (override_lastmod
)
2930 t
->flags
.override_lastmod
= true;
2932 if (reload_into_ims
)
2933 t
->flags
.reload_into_ims
= true;
2936 t
->flags
.ignore_reload
= true;
2938 if (ignore_no_store
)
2939 t
->flags
.ignore_no_store
= true;
2941 if (ignore_must_revalidate
)
2942 t
->flags
.ignore_must_revalidate
= true;
2945 t
->flags
.ignore_private
= true;
2948 t
->flags
.ignore_auth
= true;
2955 head
= &(*head
)->next
;
2963 free_refreshpattern(RefreshPattern
** head
)
2967 while ((t
= *head
) != NULL
) {
2969 safe_free(t
->pattern
);
2970 regfree(&t
->compiled_pattern
);
2974 #if USE_HTTP_VIOLATIONS
2975 refresh_nocache_hack
= 0;
2981 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2984 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2988 parse_string(char **var
)
2990 char *token
= ConfigParser::NextToken();
2996 *var
= xstrdup(token
);
3000 free_string(char **var
)
3006 parse_eol(char *volatile *var
)
3013 unsigned char *token
= (unsigned char *) ConfigParser::NextQuotedOrToEol();
3021 while (*token
&& xisspace(*token
))
3029 *var
= xstrdup((char *) token
);
3032 #define dump_eol dump_string
3033 #define free_eol free_string
3036 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3038 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3042 parse_time_t(time_t * var
)
3045 parseTimeLine(&tval
, T_SECOND_STR
, false);
3046 *var
= static_cast<time_t>(tval
/1000);
3050 free_time_t(time_t * var
)
3056 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3059 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3061 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3065 parse_time_msec(time_msec_t
* var
)
3067 parseTimeLine(var
, T_SECOND_STR
, true);
3071 free_time_msec(time_msec_t
* var
)
3078 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3080 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3085 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3087 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3091 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3093 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3098 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3100 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3105 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3107 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3111 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3113 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3118 parse_size_t(size_t * var
)
3127 parse_b_size_t(size_t * var
)
3129 parseBytesLine(var
, B_BYTES_STR
);
3133 parse_b_ssize_t(ssize_t
* var
)
3135 parseBytesLineSigned(var
, B_BYTES_STR
);
3140 parse_kb_size_t(size_t * var
)
3142 parseBytesLine(var
, B_KBYTES_STR
);
3147 parse_b_int64_t(int64_t * var
)
3149 parseBytesLine64(var
, B_BYTES_STR
);
3153 parse_kb_int64_t(int64_t * var
)
3155 parseBytesLine64(var
, B_KBYTES_STR
);
3159 free_size_t(size_t * var
)
3165 free_ssize_t(ssize_t
* var
)
3171 free_b_int64_t(int64_t * var
)
3176 #define free_b_size_t free_size_t
3177 #define free_b_ssize_t free_ssize_t
3178 #define free_kb_size_t free_size_t
3179 #define free_mb_size_t free_size_t
3180 #define free_gb_size_t free_size_t
3181 #define free_kb_int64_t free_b_int64_t
3184 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3186 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3190 free_u_short(unsigned short * u
)
3196 parse_u_short(unsigned short * var
)
3198 ConfigParser::ParseUShort(var
);
3202 ConfigParser::ParseUShort(unsigned short *var
)
3208 ConfigParser::ParseBool(bool *var
)
3210 int i
= GetInteger();
3221 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3223 while (list
!= NULL
) {
3224 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3230 ConfigParser::ParseWordList(wordlist
** list
)
3232 parse_wordlist(list
);
3236 parse_wordlist(wordlist
** list
)
3239 while ((token
= ConfigParser::NextQuotedToken()))
3240 wordlistAdd(list
, token
);
3243 #if 0 /* now unused */
3245 check_null_wordlist(wordlist
* w
)
3252 check_null_acl_access(acl_access
* a
)
3257 #define free_wordlist wordlistDestroy
3259 #define free_uri_whitespace free_int
3262 parse_uri_whitespace(int *var
)
3264 char *token
= ConfigParser::NextToken();
3269 if (!strcmp(token
, "strip"))
3270 *var
= URI_WHITESPACE_STRIP
;
3271 else if (!strcmp(token
, "deny"))
3272 *var
= URI_WHITESPACE_DENY
;
3273 else if (!strcmp(token
, "allow"))
3274 *var
= URI_WHITESPACE_ALLOW
;
3275 else if (!strcmp(token
, "encode"))
3276 *var
= URI_WHITESPACE_ENCODE
;
3277 else if (!strcmp(token
, "chop"))
3278 *var
= URI_WHITESPACE_CHOP
;
3280 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'uri_whitespace' accepts 'strip', 'deny', 'allow', 'encode', and 'chop'.");
3286 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3290 if (var
== URI_WHITESPACE_ALLOW
)
3292 else if (var
== URI_WHITESPACE_ENCODE
)
3294 else if (var
== URI_WHITESPACE_CHOP
)
3296 else if (var
== URI_WHITESPACE_DENY
)
3301 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3305 free_removalpolicy(RemovalPolicySettings
** settings
)
3310 free_string(&(*settings
)->type
);
3312 free_wordlist(&(*settings
)->args
);
3320 parse_removalpolicy(RemovalPolicySettings
** settings
)
3323 free_removalpolicy(settings
);
3325 *settings
= new RemovalPolicySettings
;
3327 parse_string(&(*settings
)->type
);
3329 parse_wordlist(&(*settings
)->args
);
3333 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3336 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3337 args
= settings
->args
;
3340 storeAppendPrintf(entry
, " %s", args
->key
);
3344 storeAppendPrintf(entry
, "\n");
3348 free_YesNoNone(YesNoNone
*)
3350 // do nothing: no explicit cleanup is required
3354 parse_YesNoNone(YesNoNone
*option
)
3357 parse_onoff(&value
);
3358 option
->configure(value
> 0);
3362 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3364 if (option
.configured())
3365 dump_onoff(entry
, name
, option
? 1 : 0);
3369 free_memcachemode(SquidConfig
* config
)
3375 parse_memcachemode(SquidConfig
* config
)
3377 char *token
= ConfigParser::NextToken();
3381 if (strcmp(token
, "always") == 0) {
3382 Config
.onoff
.memory_cache_first
= 1;
3383 Config
.onoff
.memory_cache_disk
= 1;
3384 } else if (strcmp(token
, "disk") == 0) {
3385 Config
.onoff
.memory_cache_first
= 0;
3386 Config
.onoff
.memory_cache_disk
= 1;
3387 } else if (strncmp(token
, "net", 3) == 0) {
3388 Config
.onoff
.memory_cache_first
= 1;
3389 Config
.onoff
.memory_cache_disk
= 0;
3390 } else if (strcmp(token
, "never") == 0) {
3391 Config
.onoff
.memory_cache_first
= 0;
3392 Config
.onoff
.memory_cache_disk
= 0;
3394 debugs(0, DBG_PARSE_NOTE(2), "ERROR: Invalid option '" << token
<< "': 'memory_cache_mode' accepts 'always', 'disk', 'network', and 'never'.");
3400 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3402 storeAppendPrintf(entry
, "%s ", name
);
3403 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3404 storeAppendPrintf(entry
, "always");
3405 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3406 storeAppendPrintf(entry
, "disk");
3407 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3408 storeAppendPrintf(entry
, "network");
3409 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3410 storeAppendPrintf(entry
, "none");
3411 storeAppendPrintf(entry
, "\n");
3414 #include "cf_parser.cci"
3417 parseNeighborType(const char *s
)
3419 if (!strcmp(s
, "parent"))
3422 if (!strcmp(s
, "neighbor"))
3423 return PEER_SIBLING
;
3425 if (!strcmp(s
, "neighbour"))
3426 return PEER_SIBLING
;
3428 if (!strcmp(s
, "sibling"))
3429 return PEER_SIBLING
;
3431 if (!strcmp(s
, "multicast"))
3432 return PEER_MULTICAST
;
3434 debugs(15, DBG_CRITICAL
, "WARNING: Unknown neighbor type: " << s
);
3436 return PEER_SIBLING
;
3441 parse_IpAddress_list(Ip::Address_list
** head
)
3444 Ip::Address_list
*s
;
3447 while ((token
= ConfigParser::NextToken())) {
3448 if (GetHostWithPort(token
, &ipa
)) {
3451 head
= &(*head
)->next
;
3453 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3463 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3465 char ntoabuf
[MAX_IPSTRLEN
];
3468 storeAppendPrintf(e
, "%s %s\n",
3470 s
->s
.toStr(ntoabuf
,MAX_IPSTRLEN
));
3476 free_IpAddress_list(Ip::Address_list
** head
)
3478 if (*head
) delete *head
;
3482 #if CURRENTLY_UNUSED
3483 /* This code was previously used by http_port. Left as it really should
3484 * be used by icp_port and htcp_port
3487 check_null_IpAddress_list(const Ip::Address_list
* s
)
3492 #endif /* CURRENTLY_UNUSED */
3493 #endif /* USE_WCCPv2 */
3496 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3499 unsigned short port
= 0;
3503 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3504 s
->name
= xstrdup(token
);
3505 s
->connection_auth_disabled
= false;
3507 const char *portType
= AnyP::UriScheme(s
->transport
.protocol
).c_str();
3509 if (*token
== '[') {
3512 t
= strchr(host
, ']');
3514 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing ']' on IPv6 address: " << token
);
3520 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port in: " << token
);
3523 if (!Ip::EnableIpv6
) {
3524 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: IPv6 is not available.");
3527 port
= xatos(t
+ 1);
3528 } else if ((t
= strchr(token
, ':'))) {
3533 port
= xatos(t
+ 1);
3535 } else if (strtol(token
, &junk
, 10) && !*junk
) {
3536 port
= xatos(token
);
3537 debugs(3, 3, portType
<< "_port: found Listen on Port: " << port
);
3539 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: missing Port: " << token
);
3543 if (port
== 0 && host
!= NULL
) {
3544 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: Port cannot be 0: " << token
);
3551 if (!Ip::EnableIpv6
)
3553 debugs(3, 3, portType
<< "_port: found Listen on wildcard address: *:" << s
->s
.port());
3554 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3556 if (!Ip::EnableIpv6
)
3558 debugs(3, 3, portType
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3559 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3560 /* dont use ipcache */
3561 s
->defaultsite
= xstrdup(host
);
3563 if (!Ip::EnableIpv6
)
3565 debugs(3, 3, portType
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3567 debugs(3, DBG_CRITICAL
, "FATAL: " << portType
<< "_port: failed to resolve Host/IP: " << host
);
3573 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3577 if (strcmp(token
, "accel") == 0) {
3578 if (s
->flags
.isIntercepted()) {
3579 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3582 s
->flags
.accelSurrogate
= true;
3584 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3585 if (s
->flags
.accelSurrogate
|| s
->flags
.tproxyIntercept
) {
3586 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3589 s
->flags
.natIntercept
= true;
3590 Ip::Interceptor
.StartInterception();
3591 /* Log information regarding the port modes under interception. */
3592 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3593 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3594 } else if (strcmp(token
, "tproxy") == 0) {
3595 if (s
->flags
.natIntercept
|| s
->flags
.accelSurrogate
) {
3596 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3599 s
->flags
.tproxyIntercept
= true;
3600 Ip::Interceptor
.StartTransparency();
3601 /* Log information regarding the port modes under transparency. */
3602 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (TPROXY enabled)");
3604 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3605 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3609 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3610 if (!s
->flags
.accelSurrogate
) {
3611 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3614 safe_free(s
->defaultsite
);
3615 s
->defaultsite
= xstrdup(token
+ 12);
3616 } else if (strcmp(token
, "vhost") == 0) {
3617 if (!s
->flags
.accelSurrogate
) {
3618 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3620 s
->flags
.accelSurrogate
= true;
3622 } else if (strcmp(token
, "no-vhost") == 0) {
3623 if (!s
->flags
.accelSurrogate
) {
3624 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3627 } else if (strcmp(token
, "vport") == 0) {
3628 if (!s
->flags
.accelSurrogate
) {
3629 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3633 } else if (strncmp(token
, "vport=", 6) == 0) {
3634 if (!s
->flags
.accelSurrogate
) {
3635 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3638 s
->vport
= xatos(token
+ 6);
3639 } else if (strncmp(token
, "protocol=", 9) == 0) {
3640 if (!s
->flags
.accelSurrogate
) {
3641 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3644 s
->setTransport(token
+ 9);
3645 } else if (strcmp(token
, "allow-direct") == 0) {
3646 if (!s
->flags
.accelSurrogate
) {
3647 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3650 s
->allow_direct
= true;
3651 } else if (strcmp(token
, "act-as-origin") == 0) {
3652 if (!s
->flags
.accelSurrogate
) {
3653 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3655 s
->actAsOrigin
= true;
3656 } else if (strcmp(token
, "ignore-cc") == 0) {
3657 #if !USE_HTTP_VIOLATIONS
3658 if (!s
->flags
.accelSurrogate
) {
3659 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Acceleration mode flag.");
3663 s
->ignore_cc
= true;
3664 } else if (strncmp(token
, "name=", 5) == 0) {
3666 s
->name
= xstrdup(token
+ 5);
3667 } else if (strcmp(token
, "no-connection-auth") == 0) {
3668 s
->connection_auth_disabled
= true;
3669 } else if (strcmp(token
, "connection-auth=off") == 0) {
3670 s
->connection_auth_disabled
= true;
3671 } else if (strcmp(token
, "connection-auth") == 0) {
3672 s
->connection_auth_disabled
= false;
3673 } else if (strcmp(token
, "connection-auth=on") == 0) {
3674 s
->connection_auth_disabled
= false;
3675 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3676 if (!strcmp(token
+ 23, "off"))
3677 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3678 else if (!strcmp(token
+ 23, "transparent"))
3679 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3680 else if (!strcmp(token
+ 23, "always"))
3681 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3684 } else if (strcmp(token
, "ipv4") == 0) {
3685 if ( !s
->s
.setIPv4() ) {
3686 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3689 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3690 s
->tcp_keepalive
.enabled
= true;
3691 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3692 char *t
= token
+ 13;
3693 s
->tcp_keepalive
.enabled
= true;
3694 s
->tcp_keepalive
.idle
= xatoui(t
,',');
3698 s
->tcp_keepalive
.interval
= xatoui(t
,',');
3703 s
->tcp_keepalive
.timeout
= xatoui(t
);
3706 } else if (strcmp(token
, "sslBump") == 0) {
3707 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3708 "in http_port. Use 'ssl-bump' instead.");
3709 s
->flags
.tunnelSslBumping
= true;
3710 } else if (strcmp(token
, "ssl-bump") == 0) {
3711 s
->flags
.tunnelSslBumping
= true;
3712 } else if (strncmp(token
, "cert=", 5) == 0) {
3714 s
->cert
= xstrdup(token
+ 5);
3715 } else if (strncmp(token
, "key=", 4) == 0) {
3717 s
->key
= xstrdup(token
+ 4);
3718 } else if (strncmp(token
, "version=", 8) == 0) {
3719 s
->version
= xatoi(token
+ 8);
3720 if (s
->version
< 1 || s
->version
> 4)
3722 } else if (strncmp(token
, "options=", 8) == 0) {
3723 safe_free(s
->options
);
3724 s
->options
= xstrdup(token
+ 8);
3725 } else if (strncmp(token
, "cipher=", 7) == 0) {
3726 safe_free(s
->cipher
);
3727 s
->cipher
= xstrdup(token
+ 7);
3728 } else if (strncmp(token
, "clientca=", 9) == 0) {
3729 safe_free(s
->clientca
);
3730 s
->clientca
= xstrdup(token
+ 9);
3731 } else if (strncmp(token
, "cafile=", 7) == 0) {
3732 safe_free(s
->cafile
);
3733 s
->cafile
= xstrdup(token
+ 7);
3734 } else if (strncmp(token
, "capath=", 7) == 0) {
3735 safe_free(s
->capath
);
3736 s
->capath
= xstrdup(token
+ 7);
3737 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3738 safe_free(s
->crlfile
);
3739 s
->crlfile
= xstrdup(token
+ 8);
3740 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3741 safe_free(s
->dhfile
);
3742 s
->dhfile
= xstrdup(token
+ 9);
3743 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3744 safe_free(s
->sslflags
);
3745 s
->sslflags
= xstrdup(token
+ 9);
3746 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3747 safe_free(s
->sslContextSessionId
);
3748 s
->sslContextSessionId
= xstrdup(token
+ 11);
3749 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3750 s
->generateHostCertificates
= true;
3751 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3752 s
->generateHostCertificates
= true;
3753 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3754 s
->generateHostCertificates
= false;
3755 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3756 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3759 debugs(3, DBG_CRITICAL
, "FATAL: Unknown http(s)_port option '" << token
<< "'.");
3765 add_http_port(char *portspec
)
3767 AnyP::PortCfg
*s
= new AnyP::PortCfg();
3768 s
->setTransport("HTTP");
3769 parsePortSpecification(s
, portspec
);
3770 // we may need to merge better if the above returns a list with clones
3771 assert(s
->next
== NULL
);
3772 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3773 cbdataReferenceDone(Config
.Sockaddr
.http
);
3774 Config
.Sockaddr
.http
= cbdataReference(s
);
3778 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3780 const char *protocol
= NULL
;
3781 if (strcmp(optionName
, "http_port") == 0 ||
3782 strcmp(optionName
, "ascii_port") == 0)
3784 else if (strcmp(optionName
, "https_port") == 0)
3791 char *token
= ConfigParser::NextToken();
3798 AnyP::PortCfg
*s
= new AnyP::PortCfg();
3799 s
->setTransport(protocol
);
3800 parsePortSpecification(s
, token
);
3802 /* parse options ... */
3803 while ((token
= ConfigParser::NextToken())) {
3804 parse_port_option(s
, token
);
3808 if (s
->transport
.protocol
== AnyP::PROTO_HTTPS
) {
3809 /* ssl-bump on https_port configuration requires either tproxy or intercept, and vice versa */
3810 const bool hijacked
= s
->flags
.isIntercepted();
3811 if (s
->flags
.tunnelSslBumping
&& !hijacked
) {
3812 debugs(3, DBG_CRITICAL
, "FATAL: ssl-bump on https_port requires tproxy/intercept which is missing.");
3815 if (hijacked
&& !s
->flags
.tunnelSslBumping
) {
3816 debugs(3, DBG_CRITICAL
, "FATAL: tproxy/intercept on https_port requires ssl-bump which is missing.");
3822 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.isAnyAddr()) {
3823 // clone the port options from *s to *(s->next)
3824 s
->next
= cbdataReference(s
->clone());
3825 s
->next
->s
.setIPv4();
3826 debugs(3, 3, AnyP::UriScheme(s
->transport
.protocol
).c_str() << "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3830 head
= &(*head
)->next
;
3832 *head
= cbdataReference(s
);
3836 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3838 char buf
[MAX_IPSTRLEN
];
3840 storeAppendPrintf(e
, "%s %s",
3842 s
->s
.toUrl(buf
,MAX_IPSTRLEN
));
3844 // MODES and specific sub-options.
3845 if (s
->flags
.natIntercept
)
3846 storeAppendPrintf(e
, " intercept");
3848 else if (s
->flags
.tproxyIntercept
)
3849 storeAppendPrintf(e
, " tproxy");
3851 else if (s
->flags
.accelSurrogate
) {
3852 storeAppendPrintf(e
, " accel");
3855 storeAppendPrintf(e
, " vhost");
3858 storeAppendPrintf(e
, " vport");
3859 else if (s
->vport
> 0)
3860 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3863 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3865 // TODO: compare against prefix of 'n' instead of assuming http_port
3866 if (s
->transport
.protocol
!= AnyP::PROTO_HTTP
)
3867 storeAppendPrintf(e
, " protocol=%s", AnyP::UriScheme(s
->transport
.protocol
).c_str());
3869 if (s
->allow_direct
)
3870 storeAppendPrintf(e
, " allow-direct");
3873 storeAppendPrintf(e
, " ignore-cc");
3877 // Generic independent options
3880 storeAppendPrintf(e
, " name=%s", s
->name
);
3882 #if USE_HTTP_VIOLATIONS
3883 if (!s
->flags
.accelSurrogate
&& s
->ignore_cc
)
3884 storeAppendPrintf(e
, " ignore-cc");
3887 if (s
->connection_auth_disabled
)
3888 storeAppendPrintf(e
, " connection-auth=off");
3890 storeAppendPrintf(e
, " connection-auth=on");
3892 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3895 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3898 pmtu
= "transparent";
3900 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3903 if (s
->s
.isAnyAddr() && !s
->s
.isIPv6())
3904 storeAppendPrintf(e
, " ipv4");
3906 if (s
->tcp_keepalive
.enabled
) {
3907 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3908 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3910 storeAppendPrintf(e
, " tcpkeepalive");
3915 if (s
->flags
.tunnelSslBumping
)
3916 storeAppendPrintf(e
, " ssl-bump");
3919 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3922 storeAppendPrintf(e
, " key=%s", s
->key
);
3925 storeAppendPrintf(e
, " version=%d", s
->version
);
3928 storeAppendPrintf(e
, " options=%s", s
->options
);
3931 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3934 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3937 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3940 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3943 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3946 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3948 if (s
->sslContextSessionId
)
3949 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3951 if (s
->generateHostCertificates
)
3952 storeAppendPrintf(e
, " generate-host-certificates");
3954 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3955 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3960 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3963 dump_generic_port(e
, n
, s
);
3964 storeAppendPrintf(e
, "\n");
3970 free_PortCfg(AnyP::PortCfg
** head
)
3974 while ((s
= *head
) != NULL
) {
3976 cbdataReferenceDone(s
);
3981 configFreeMemory(void)
3985 SSL_CTX_free(Config
.ssl_client
.sslContext
);
3990 requirePathnameExists(const char *name
, const char *path
)
3994 char pathbuf
[BUFSIZ
];
3995 assert(path
!= NULL
);
3997 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3998 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4002 if (stat(path
, &sb
) < 0) {
4003 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
4004 // keep going to find more issues if we are only checking the config file with "-k parse"
4005 if (opt_parse_cfg_only
)
4007 // this is fatal if it is found during startup or reconfigure
4008 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4009 fatalf("%s %s: %s", name
, path
, xstrerror());
4016 return ConfigParser::strtokFile();
4019 #include "AccessLogEntry.h"
4022 * We support several access_log configuration styles:
4024 * #1: Deprecated ancient style without an explicit logging module:
4025 * access_log /var/log/access.log
4027 * #2: The "none" logging module (i.e., no logging [of matching transactions]):
4028 * access_log none [acl ...]
4030 * #3: Configurable logging module without named options:
4031 * Logformat or the first ACL name, whichever comes first, may not contain '='.
4032 * If no explicit logformat name is given, the first ACL name, if any,
4033 * should not be an existing logformat name or it will be treated as such.
4034 * access_log module:place [logformat_name] [acl ...]
4036 * #4: Configurable logging module with name=value options such as logformat=x:
4037 * The first ACL name may not contain '='.
4038 * access_log module:place [option ...] [acl ...]
4042 parse_access_log(CustomLog
** logs
)
4044 CustomLog
*cl
= (CustomLog
*)xcalloc(1, sizeof(*cl
));
4046 // default buffer size and fatal settings
4047 cl
->bufferSize
= 8*MAX_URL
;
4050 /* determine configuration style */
4052 const char *filename
= ConfigParser::NextToken();
4058 if (strcmp(filename
, "none") == 0) {
4059 cl
->type
= Log::Format::CLF_NONE
;
4060 aclParseAclList(LegacyParser
, &cl
->aclList
, filename
);
4062 logs
= &(*logs
)->next
;
4067 cl
->filename
= xstrdup(filename
);
4068 cl
->type
= Log::Format::CLF_UNKNOWN
;
4070 const char *token
= ConfigParser::PeekAtToken();
4071 if (!token
) { // style #1
4072 // no options to deal with
4073 } else if (!strchr(token
, '=')) { // style #3
4074 // if logformat name is recognized,
4075 // pop the previewed token; Else it must be an ACL name
4076 if (setLogformat(cl
, token
, false))
4077 (void)ConfigParser::NextToken();
4078 } else { // style #4
4080 if (strncasecmp(token
, "on-error=", 9) == 0) {
4081 if (strncasecmp(token
+9, "die", 3) == 0) {
4083 } else if (strncasecmp(token
+9, "drop", 4) == 0) {
4086 debugs(3, DBG_CRITICAL
, "Unknown value for on-error '" <<
4087 token
<< "' expected 'drop' or 'die'");
4090 } else if (strncasecmp(token
, "buffer-size=", 12) == 0) {
4091 parseBytesOptionValue(&cl
->bufferSize
, B_BYTES_STR
, token
+12);
4092 } else if (strncasecmp(token
, "logformat=", 10) == 0) {
4093 setLogformat(cl
, token
+10, true);
4094 } else if (!strchr(token
, '=')) {
4095 // Do not pop the token; it must be an ACL name
4096 break; // done with name=value options, now to ACLs
4098 debugs(3, DBG_CRITICAL
, "Unknown access_log option " << token
);
4101 // Pop the token, it was a valid "name=value" option
4102 (void)ConfigParser::NextToken();
4103 // Get next with preview ConfigParser::NextToken call.
4104 } while ((token
= ConfigParser::PeekAtToken()) != NULL
);
4107 // set format if it has not been specified explicitly
4108 if (cl
->type
== Log::Format::CLF_UNKNOWN
)
4109 setLogformat(cl
, "squid", true);
4111 aclParseAclList(LegacyParser
, &cl
->aclList
, cl
->filename
);
4114 logs
= &(*logs
)->next
;
4119 /// sets CustomLog::type and, if needed, CustomLog::lf
4120 /// returns false iff there is no named log format
4122 setLogformat(CustomLog
*cl
, const char *logdef_name
, const bool dieWhenMissing
)
4125 assert(logdef_name
);
4127 debugs(3, 9, "possible " << cl
->filename
<< " logformat: " << logdef_name
);
4129 if (cl
->type
!= Log::Format::CLF_UNKNOWN
) {
4130 debugs(3, DBG_CRITICAL
, "Second logformat name in one access_log: " <<
4131 logdef_name
<< " " << cl
->type
<< " ? " << Log::Format::CLF_NONE
);
4136 /* look for the definition pointer corresponding to this name */
4137 Format::Format
*lf
= Log::TheConfig
.logformats
;
4139 while (lf
!= NULL
) {
4140 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4142 if (strcmp(lf
->name
, logdef_name
) == 0)
4149 cl
->type
= Log::Format::CLF_CUSTOM
;
4151 } else if (strcmp(logdef_name
, "auto") == 0) {
4152 debugs(0, DBG_CRITICAL
, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4153 cl
->type
= Log::Format::CLF_SQUID
;
4154 } else if (strcmp(logdef_name
, "squid") == 0) {
4155 cl
->type
= Log::Format::CLF_SQUID
;
4156 } else if (strcmp(logdef_name
, "common") == 0) {
4157 cl
->type
= Log::Format::CLF_COMMON
;
4158 } else if (strcmp(logdef_name
, "combined") == 0) {
4159 cl
->type
= Log::Format::CLF_COMBINED
;
4161 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4162 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4164 } else if (strcmp(logdef_name
, "useragent") == 0) {
4165 cl
->type
= Log::Format::CLF_USERAGENT
;
4166 } else if (strcmp(logdef_name
, "referrer") == 0) {
4167 cl
->type
= Log::Format::CLF_REFERER
;
4168 } else if (dieWhenMissing
) {
4169 debugs(3, DBG_CRITICAL
, "Log format '" << logdef_name
<< "' is not defined");
4180 check_null_access_log(CustomLog
*customlog_definitions
)
4182 return customlog_definitions
== NULL
;
4186 dump_access_log(StoreEntry
* entry
, const char *name
, CustomLog
* logs
)
4190 for (log
= logs
; log
; log
= log
->next
) {
4191 storeAppendPrintf(entry
, "%s ", name
);
4193 switch (log
->type
) {
4195 case Log::Format::CLF_CUSTOM
:
4196 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4199 case Log::Format::CLF_NONE
:
4200 storeAppendPrintf(entry
, "none");
4203 case Log::Format::CLF_SQUID
:
4204 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4207 case Log::Format::CLF_COMBINED
:
4208 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4211 case Log::Format::CLF_COMMON
:
4212 storeAppendPrintf(entry
, "%s common", log
->filename
);
4216 case Log::Format::CLF_ICAP_SQUID
:
4217 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4220 case Log::Format::CLF_USERAGENT
:
4221 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4224 case Log::Format::CLF_REFERER
:
4225 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4228 case Log::Format::CLF_UNKNOWN
:
4233 dump_acl_list(entry
, log
->aclList
);
4235 storeAppendPrintf(entry
, "\n");
4240 free_access_log(CustomLog
** definitions
)
4242 while (*definitions
) {
4243 CustomLog
*log
= *definitions
;
4244 *definitions
= log
->next
;
4246 log
->logFormat
= NULL
;
4247 log
->type
= Log::Format::CLF_UNKNOWN
;
4250 aclDestroyAclList(&log
->aclList
);
4252 safe_free(log
->filename
);
4258 /// parses list of integers form name=N1,N2,N3,...
4260 parseNamedIntList(const char *data
, const String
&name
, std::vector
<int> &list
)
4262 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4263 data
+= name
.size();
4268 if (!StringToInt(data
, value
, &data
, 10))
4270 list
.push_back(value
);
4271 if (*data
== '\0' || *data
!= ',')
4276 return data
&& *data
== '\0';
4280 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4282 #if !HAVE_CPU_AFFINITY
4283 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4284 "support, do not set 'cpu_affinity_map'");
4286 #endif /* HAVE_CPU_AFFINITY */
4288 if (!*cpuAffinityMap
)
4289 *cpuAffinityMap
= new CpuAffinityMap
;
4291 const char *const pToken
= ConfigParser::NextToken();
4292 const char *const cToken
= ConfigParser::NextToken();
4293 std::vector
<int> processes
, cores
;
4294 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4295 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4296 "in 'cpu_affinity_map'");
4298 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4299 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4300 "'cpu_affinity_map'");
4302 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4303 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4304 "process_numbers and cores lists differ in length or " <<
4305 "contain numbers <= 0");
4311 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4313 if (cpuAffinityMap
) {
4314 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4315 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4316 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4317 cpuAffinityMap
->processes()[i
]);
4319 storeAppendPrintf(entry
, " cores=");
4320 for (size_t i
= 0; i
< cpuAffinityMap
->cores().size(); ++i
) {
4321 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4322 cpuAffinityMap
->cores()[i
]);
4324 storeAppendPrintf(entry
, "\n");
4329 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4331 delete *cpuAffinityMap
;
4332 *cpuAffinityMap
= NULL
;
4338 parse_adaptation_service_set_type()
4340 Adaptation::Config::ParseServiceSet();
4344 parse_adaptation_service_chain_type()
4346 Adaptation::Config::ParseServiceChain();
4350 parse_adaptation_access_type()
4352 Adaptation::Config::ParseAccess(LegacyParser
);
4354 #endif /* USE_ADAPTATION */
4359 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4361 cfg
->parseService();
4365 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4371 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4373 cfg
.dumpService(entry
, name
);
4377 parse_icap_class_type()
4379 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_class' is depricated. " <<
4380 "Use 'adaptation_service_set' instead");
4381 Adaptation::Config::ParseServiceSet();
4385 parse_icap_access_type()
4387 debugs(93, DBG_CRITICAL
, "WARNING: 'icap_access' is depricated. " <<
4388 "Use 'adaptation_access' instead");
4389 Adaptation::Config::ParseAccess(LegacyParser
);
4397 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4399 cfg
->parseService();
4403 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4409 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4411 cfg
.dumpService(entry
, name
);
4414 #endif /* USE_ECAP */
4417 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4422 cfg
->service_failure_limit
= GetInteger();
4424 if ((token
= ConfigParser::NextToken()) == NULL
)
4427 if (strcmp(token
,"in") != 0) {
4428 debugs(3, DBG_CRITICAL
, "expecting 'in' on'" << config_input_line
<< "'");
4432 if ((token
= ConfigParser::NextToken()) == NULL
) {
4436 d
= static_cast<time_t> (xatoi(token
));
4438 m
= static_cast<time_t> (1);
4442 else if ((token
= ConfigParser::NextToken()) == NULL
) {
4443 debugs(3, DBG_CRITICAL
, "No time-units on '" << config_input_line
<< "'");
4445 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4448 cfg
->oldest_service_failure
= (m
* d
);
4451 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4453 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4454 if (cfg
.oldest_service_failure
> 0) {
4455 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4457 storeAppendPrintf(entry
, "\n");
4460 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4462 cfg
->oldest_service_failure
= 0;
4463 cfg
->service_failure_limit
= 0;
4468 static void parse_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4471 sslproxy_cert_adapt
*ca
= (sslproxy_cert_adapt
*) xcalloc(1, sizeof(sslproxy_cert_adapt
));
4472 if ((al
= ConfigParser::NextToken()) == NULL
) {
4478 if ( char *s
= strchr(al
, '{')) {
4479 *s
= '\0'; // terminate the al string
4491 if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidAfter
]) == 0) {
4492 ca
->alg
= Ssl::algSetValidAfter
;
4493 ca
->param
= xstrdup("on");
4494 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetValidBefore
]) == 0) {
4495 ca
->alg
= Ssl::algSetValidBefore
;
4496 ca
->param
= xstrdup("on");
4497 } else if (strcmp(al
, Ssl::CertAdaptAlgorithmStr
[Ssl::algSetCommonName
]) == 0) {
4498 ca
->alg
= Ssl::algSetCommonName
;
4500 if (strlen(param
) > 64) {
4501 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: setCommonName{" <<param
<< "} : using common name longer than 64 bytes is not supported");
4505 ca
->param
= xstrdup(param
);
4508 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_adapt: unknown cert adaptation algorithm: " << al
);
4513 aclParseAclList(LegacyParser
, &ca
->aclList
, al
);
4516 cert_adapt
= &(*cert_adapt
)->next
;
4521 static void dump_sslproxy_cert_adapt(StoreEntry
*entry
, const char *name
, sslproxy_cert_adapt
*cert_adapt
)
4523 for (sslproxy_cert_adapt
*ca
= cert_adapt
; ca
!= NULL
; ca
= ca
->next
) {
4524 storeAppendPrintf(entry
, "%s ", name
);
4525 storeAppendPrintf(entry
, "%s{%s} ", Ssl::sslCertAdaptAlgoritm(ca
->alg
), ca
->param
);
4527 dump_acl_list(entry
, ca
->aclList
);
4528 storeAppendPrintf(entry
, "\n");
4532 static void free_sslproxy_cert_adapt(sslproxy_cert_adapt
**cert_adapt
)
4534 while (*cert_adapt
) {
4535 sslproxy_cert_adapt
*ca
= *cert_adapt
;
4536 *cert_adapt
= ca
->next
;
4537 safe_free(ca
->param
);
4540 aclDestroyAclList(&ca
->aclList
);
4546 static void parse_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4549 sslproxy_cert_sign
*cs
= (sslproxy_cert_sign
*) xcalloc(1, sizeof(sslproxy_cert_sign
));
4550 if ((al
= ConfigParser::NextToken()) == NULL
) {
4555 if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignTrusted
]) == 0)
4556 cs
->alg
= Ssl::algSignTrusted
;
4557 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignUntrusted
]) == 0)
4558 cs
->alg
= Ssl::algSignUntrusted
;
4559 else if (strcmp(al
, Ssl::CertSignAlgorithmStr
[Ssl::algSignSelf
]) == 0)
4560 cs
->alg
= Ssl::algSignSelf
;
4562 debugs(3, DBG_CRITICAL
, "FATAL: sslproxy_cert_sign: unknown cert signing algorithm: " << al
);
4567 aclParseAclList(LegacyParser
, &cs
->aclList
, al
);
4570 cert_sign
= &(*cert_sign
)->next
;
4575 static void dump_sslproxy_cert_sign(StoreEntry
*entry
, const char *name
, sslproxy_cert_sign
*cert_sign
)
4577 sslproxy_cert_sign
*cs
;
4578 for (cs
= cert_sign
; cs
!= NULL
; cs
= cs
->next
) {
4579 storeAppendPrintf(entry
, "%s ", name
);
4580 storeAppendPrintf(entry
, "%s ", Ssl::certSignAlgorithm(cs
->alg
));
4582 dump_acl_list(entry
, cs
->aclList
);
4583 storeAppendPrintf(entry
, "\n");
4587 static void free_sslproxy_cert_sign(sslproxy_cert_sign
**cert_sign
)
4589 while (*cert_sign
) {
4590 sslproxy_cert_sign
*cs
= *cert_sign
;
4591 *cert_sign
= cs
->next
;
4594 aclDestroyAclList(&cs
->aclList
);
4600 class sslBumpCfgRr
: public ::RegisteredRunner
4603 static Ssl::BumpMode lastDeprecatedRule
;
4604 /* RegisteredRunner API */
4605 virtual void finalizeConfig();
4608 Ssl::BumpMode
sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4610 RunnerRegistrationEntry(sslBumpCfgRr
);
4613 sslBumpCfgRr::finalizeConfig()
4615 if (lastDeprecatedRule
!= Ssl::bumpEnd
) {
4616 assert( lastDeprecatedRule
== Ssl::bumpClientFirst
|| lastDeprecatedRule
== Ssl::bumpNone
);
4617 static char buf
[1024];
4618 if (lastDeprecatedRule
== Ssl::bumpClientFirst
) {
4619 strcpy(buf
, "ssl_bump deny all");
4620 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated implicit "
4621 "\"ssl_bump deny all\" to \"ssl_bump none all\". New ssl_bump configurations "
4622 "must not use implicit rules. Update your ssl_bump rules.");
4624 strcpy(buf
, "ssl_bump allow all");
4625 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated implicit "
4626 "\"ssl_bump allow all\" to \"ssl_bump client-first all\" which is usually "
4627 "inferior to the newer server-first bumping mode. New ssl_bump"
4628 " configurations must not use implicit rules. Update your ssl_bump rules.");
4634 static void parse_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4636 typedef const char *BumpCfgStyle
;
4637 BumpCfgStyle bcsNone
= NULL
;
4638 BumpCfgStyle bcsNew
= "new client/server-first/none";
4639 BumpCfgStyle bcsOld
= "deprecated allow/deny";
4640 static BumpCfgStyle bumpCfgStyleLast
= bcsNone
;
4641 BumpCfgStyle bumpCfgStyleNow
= bcsNone
;
4643 if ((bm
= ConfigParser::NextToken()) == NULL
) {
4648 // if this is the first rule proccessed
4649 if (*ssl_bump
== NULL
) {
4650 bumpCfgStyleLast
= bcsNone
;
4651 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpEnd
;
4654 allow_t action
= allow_t(ACCESS_ALLOWED
);
4656 if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpClientFirst
]) == 0) {
4657 action
.kind
= Ssl::bumpClientFirst
;
4658 bumpCfgStyleNow
= bcsNew
;
4659 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpServerFirst
]) == 0) {
4660 action
.kind
= Ssl::bumpServerFirst
;
4661 bumpCfgStyleNow
= bcsNew
;
4662 } else if (strcmp(bm
, Ssl::BumpModeStr
[Ssl::bumpNone
]) == 0) {
4663 action
.kind
= Ssl::bumpNone
;
4664 bumpCfgStyleNow
= bcsNew
;
4665 } else if (strcmp(bm
, "allow") == 0) {
4666 debugs(3, DBG_CRITICAL
, "SECURITY NOTICE: auto-converting deprecated "
4667 "\"ssl_bump allow <acl>\" to \"ssl_bump client-first <acl>\" which "
4668 "is usually inferior to the newer server-first "
4669 "bumping mode. Update your ssl_bump rules.");
4670 action
.kind
= Ssl::bumpClientFirst
;
4671 bumpCfgStyleNow
= bcsOld
;
4672 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpClientFirst
;
4673 } else if (strcmp(bm
, "deny") == 0) {
4674 debugs(3, DBG_CRITICAL
, "WARNING: auto-converting deprecated "
4675 "\"ssl_bump deny <acl>\" to \"ssl_bump none <acl>\". Update "
4676 "your ssl_bump rules.");
4677 action
.kind
= Ssl::bumpNone
;
4678 bumpCfgStyleNow
= bcsOld
;
4679 sslBumpCfgRr::lastDeprecatedRule
= Ssl::bumpNone
;
4681 debugs(3, DBG_CRITICAL
, "FATAL: unknown ssl_bump mode: " << bm
);
4686 if (bumpCfgStyleLast
!= bcsNone
&& bumpCfgStyleNow
!= bumpCfgStyleLast
) {
4687 debugs(3, DBG_CRITICAL
, "FATAL: do not mix " << bumpCfgStyleNow
<< " actions with " <<
4688 bumpCfgStyleLast
<< " actions. Update your ssl_bump rules.");
4693 bumpCfgStyleLast
= bumpCfgStyleNow
;
4695 Acl::AndNode
*rule
= new Acl::AndNode
;
4696 rule
->context("(ssl_bump rule)", config_input_line
);
4702 *ssl_bump
= new Acl::Tree
;
4703 (*ssl_bump
)->context("(ssl_bump rules)", config_input_line
);
4706 (*ssl_bump
)->add(rule
, action
);
4709 static void dump_sslproxy_ssl_bump(StoreEntry
*entry
, const char *name
, acl_access
*ssl_bump
)
4712 wordlist
*lines
= ssl_bump
->treeDump(name
, Ssl::BumpModeStr
);
4713 dump_wordlist(entry
, lines
);
4714 wordlistDestroy(&lines
);
4718 static void free_sslproxy_ssl_bump(acl_access
**ssl_bump
)
4720 free_acl_access(ssl_bump
);
4725 static void dump_HeaderWithAclList(StoreEntry
* entry
, const char *name
, HeaderWithAclList
*headers
)
4730 for (HeaderWithAclList::iterator hwa
= headers
->begin(); hwa
!= headers
->end(); ++hwa
) {
4731 storeAppendPrintf(entry
, "%s ", hwa
->fieldName
.c_str());
4732 storeAppendPrintf(entry
, "%s ", hwa
->fieldValue
.c_str());
4734 dump_acl_list(entry
, hwa
->aclList
);
4735 storeAppendPrintf(entry
, "\n");
4739 static void parse_HeaderWithAclList(HeaderWithAclList
**headers
)
4743 *headers
= new HeaderWithAclList
;
4745 if ((fn
= ConfigParser::NextToken()) == NULL
) {
4751 hwa
.fieldId
= httpHeaderIdByNameDef(fn
, strlen(fn
));
4752 if (hwa
.fieldId
== HDR_BAD_HDR
)
4753 hwa
.fieldId
= HDR_OTHER
;
4755 Format::Format
*nlf
= new ::Format::Format("hdrWithAcl");
4756 ConfigParser::EnableMacros();
4757 String buf
= ConfigParser::NextQuotedToken();
4758 ConfigParser::DisableMacros();
4759 hwa
.fieldValue
= buf
.termedBuf();
4760 hwa
.quoted
= ConfigParser::LastTokenWasQuoted();
4762 if (!nlf
->parse(hwa
.fieldValue
.c_str())) {
4766 hwa
.valueFormat
= nlf
;
4769 aclParseAclList(LegacyParser
, &hwa
.aclList
, (hwa
.fieldName
+ ':' + hwa
.fieldValue
).c_str());
4770 (*headers
)->push_back(hwa
);
4773 static void free_HeaderWithAclList(HeaderWithAclList
**header
)
4778 for (HeaderWithAclList::iterator hwa
= (*header
)->begin(); hwa
!= (*header
)->end(); ++hwa
) {
4780 aclDestroyAclList(&hwa
->aclList
);
4782 if (hwa
->valueFormat
) {
4783 delete hwa
->valueFormat
;
4784 hwa
->valueFormat
= NULL
;
4791 static void parse_note(Notes
*notes
)
4794 notes
->parse(LegacyParser
);
4797 static void dump_note(StoreEntry
*entry
, const char *name
, Notes
¬es
)
4799 notes
.dump(entry
, name
);
4802 static void free_note(Notes
*notes
)
4808 parse_configuration_includes_quoted_values(bool *recognizeQuotedValues
)
4813 // If quoted values is set to on then enable new strict mode parsing
4815 ConfigParser::RecognizeQuotedValues
= true;
4816 ConfigParser::StrictMode
= true;
4818 ConfigParser::RecognizeQuotedValues
= false;
4819 ConfigParser::StrictMode
= false;
4824 dump_configuration_includes_quoted_values(StoreEntry
*const entry
, const char *const name
, bool recognizeQuotedValues
)
4826 int val
= ConfigParser::RecognizeQuotedValues
? 1 : 0;
4827 dump_onoff(entry
, name
, val
);
4831 free_configuration_includes_quoted_values(bool *recognizeQuotedValues
)
4833 ConfigParser::RecognizeQuotedValues
= false;
4834 ConfigParser::StrictMode
= false;