4 * DEBUG: section 03 Configuration File Parsing
5 * AUTHOR: Harvest Derived
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 #include "acl/Gadgets.h"
39 #include "acl/MethodData.h"
41 #include "adaptation/Config.h"
44 #include "adaptation/icap/Config.h"
47 #include "adaptation/ecap/Config.h"
49 #include "auth/Config.h"
50 #include "auth/Scheme.h"
51 #include "ConfigParser.h"
52 #include "CpuAffinityMap.h"
53 #include "eui/Config.h"
55 #include "esi/Parser.h"
57 #include "HttpRequestMethod.h"
58 #include "ident/Config.h"
59 #include "ip/Intercept.h"
60 #include "ip/QosConfig.h"
62 #include "log/Config.h"
64 #include "mgr/Registration.h"
66 #include "ProtoPort.h"
72 #include "StoreFileSystem.h"
86 static void parse_adaptation_service_set_type();
87 static void parse_adaptation_service_chain_type();
88 static void parse_adaptation_access_type();
92 static void parse_icap_service_type(Adaptation::Icap::Config
*);
93 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
94 static void free_icap_service_type(Adaptation::Icap::Config
*);
95 static void parse_icap_class_type();
96 static void parse_icap_access_type();
98 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
99 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
100 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
104 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
105 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
106 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
111 static const char *const T_SECOND_STR
= "second";
112 static const char *const T_MINUTE_STR
= "minute";
113 static const char *const T_HOUR_STR
= "hour";
114 static const char *const T_DAY_STR
= "day";
115 static const char *const T_WEEK_STR
= "week";
116 static const char *const T_FORTNIGHT_STR
= "fortnight";
117 static const char *const T_MONTH_STR
= "month";
118 static const char *const T_YEAR_STR
= "year";
119 static const char *const T_DECADE_STR
= "decade";
121 static const char *const B_BYTES_STR
= "bytes";
122 static const char *const B_KBYTES_STR
= "KB";
123 static const char *const B_MBYTES_STR
= "MB";
124 static const char *const B_GBYTES_STR
= "GB";
126 static const char *const list_sep
= ", \t\n\r";
128 static void parse_logformat(logformat
** logformat_definitions
);
129 static void parse_access_log(customlog
** customlog_definitions
);
130 static int check_null_access_log(customlog
*customlog_definitions
);
132 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
133 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
134 static void free_logformat(logformat
** definitions
);
135 static void free_access_log(customlog
** definitions
);
137 static void update_maxobjsize(void);
138 static void configDoConfigure(void);
139 static void parse_refreshpattern(refresh_t
**);
140 static int parseTimeUnits(const char *unit
);
141 static void parseTimeLine(time_t * tptr
, const char *units
);
142 static void parse_ushort(u_short
* var
);
143 static void parse_string(char **);
144 static void default_all(void);
145 static void defaults_if_none(void);
146 static int parse_line(char *);
147 static void parse_obsolete(const char *);
148 static void parseBytesLine(size_t * bptr
, const char *units
);
150 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
152 static size_t parseBytesUnits(const char *unit
);
153 static void free_all(void);
154 void requirePathnameExists(const char *name
, const char *path
);
155 static OBJH dump_config
;
156 #if USE_HTTP_VIOLATIONS
157 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
158 static void parse_http_header_access(header_mangler header
[]);
159 static void free_http_header_access(header_mangler header
[]);
160 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
161 static void parse_http_header_replace(header_mangler
* header
);
162 static void free_http_header_replace(header_mangler
* header
);
164 static void parse_denyinfo(acl_deny_info_list
** var
);
165 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
166 static void free_denyinfo(acl_deny_info_list
** var
);
169 static void parse_IpAddress_list(Ip::Address_list
**);
170 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
171 static void free_IpAddress_list(Ip::Address_list
**);
173 static int check_null_IpAddress_list(const Ip::Address_list
*);
174 #endif /* CURRENTLY_UNUSED */
175 #endif /* USE_WCCPv2 */
177 static void parse_http_port_list(http_port_list
**);
178 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
179 static void free_http_port_list(http_port_list
**);
182 static void parse_https_port_list(https_port_list
**);
183 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
184 static void free_https_port_list(https_port_list
**);
186 static int check_null_https_port_list(const https_port_list
*);
190 static void parse_b_size_t(size_t * var
);
191 static void parse_b_int64_t(int64_t * var
);
193 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
195 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
196 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
197 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
199 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
202 * LegacyParser is a parser for legacy code that uses the global
203 * approach. This is static so that it is only exposed to cache_cf.
204 * Other modules needing access to a ConfigParser should have it
205 * provided to them in their parserFOO methods.
207 static ConfigParser LegacyParser
= ConfigParser();
212 LegacyParser
.destruct();
216 update_maxobjsize(void)
221 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
222 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
224 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
226 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
228 store_maxobjsize
= ms
;
232 SetConfigFilename(char const *file_name
, bool is_pipe
)
234 cfg_filename
= file_name
;
239 cfg_filename
= file_name
+ 1;
240 else if ((token
= strrchr(cfg_filename
, '/')))
241 cfg_filename
= token
+ 1;
245 skip_ws(const char* s
)
254 parseManyConfigFiles(char* files
, int depth
)
257 char* saveptr
= NULL
;
262 memset(&globbuf
, 0, sizeof(globbuf
));
263 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
264 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
265 fatalf("Unable to find configuration file: %s: %s",
269 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
270 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
274 char* file
= strwordtok(files
, &saveptr
);
275 while (file
!= NULL
) {
276 error_count
+= parseOneConfigFile(file
, depth
);
277 file
= strwordtok(NULL
, &saveptr
);
279 #endif /* HAVE_GLOB */
284 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
287 assert(newSubstr
!= NULL
);
289 unsigned newSubstrLen
= strlen(newSubstr
);
290 if (newSubstrLen
> substrLen
)
291 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
293 // move tail part including zero
294 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
295 // copy new substring in place
296 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
302 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
304 assert(line
!= NULL
);
305 assert(macroName
!= NULL
);
306 assert(substStr
!= NULL
);
307 unsigned macroNameLen
= strlen(macroName
);
308 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
309 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
313 ProcessMacros(char*& line
, int& len
)
315 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
316 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
320 trim_trailing_ws(char* str
)
323 unsigned i
= strlen(str
);
324 while ((i
> 0) && xisspace(str
[i
- 1]))
330 FindStatement(const char* line
, const char* statement
)
332 assert(line
!= NULL
);
333 assert(statement
!= NULL
);
335 const char* str
= skip_ws(line
);
336 unsigned len
= strlen(statement
);
337 if (strncmp(str
, statement
, len
) == 0) {
341 else if (xisspace(*str
))
349 StrToInt(const char* str
, long& number
)
354 number
= strtol(str
, &end
, 0);
356 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
360 EvalBoolExpr(const char* expr
)
362 assert(expr
!= NULL
);
363 if (strcmp(expr
, "true") == 0) {
365 } else if (strcmp(expr
, "false") == 0) {
367 } else if (const char* equation
= strchr(expr
, '=')) {
368 const char* rvalue
= skip_ws(equation
+ 1);
369 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
370 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
371 trim_trailing_ws(lvalue
);
374 if (!StrToInt(lvalue
, number1
))
375 fatalf("String is not a integer number: '%s'\n", lvalue
);
377 if (!StrToInt(rvalue
, number2
))
378 fatalf("String is not a integer number: '%s'\n", rvalue
);
381 return number1
== number2
;
383 fatalf("Unable to evaluate expression '%s'\n", expr
);
384 return false; // this place cannot be reached
388 parseOneConfigFile(const char *file_name
, unsigned int depth
)
391 const char *orig_cfg_filename
= cfg_filename
;
392 const int orig_config_lineno
= config_lineno
;
394 char *tmp_line
= NULL
;
395 int tmp_line_len
= 0;
399 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
401 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
405 if (file_name
[0] == '!' || file_name
[0] == '|') {
406 fp
= popen(file_name
+ 1, "r");
409 fp
= fopen(file_name
, "r");
413 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
417 setmode(fileno(fp
), O_TEXT
);
421 SetConfigFilename(file_name
, bool(is_pipe
));
423 memset(config_input_line
, '\0', BUFSIZ
);
427 Vector
<bool> if_states
;
428 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
431 if ((token
= strchr(config_input_line
, '\n')))
434 if ((token
= strchr(config_input_line
, '\r')))
437 if (strncmp(config_input_line
, "#line ", 6) == 0) {
438 static char new_file_name
[1024];
440 static char new_lineno
;
441 token
= config_input_line
+ 6;
442 new_lineno
= strtol(token
, &file
, 0) - 1;
445 continue; /* Not a valid #line directive, may be a comment */
447 while (*file
&& xisspace((unsigned char) *file
))
452 continue; /* Not a valid #line directive, may be a comment */
454 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
456 if ((token
= strchr(new_file_name
, '"')))
459 cfg_filename
= new_file_name
;
462 config_lineno
= new_lineno
;
465 if (config_input_line
[0] == '#')
468 if (config_input_line
[0] == '\0')
471 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
473 size_t append_len
= strlen(append
);
475 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
477 strcpy(tmp_line
+ tmp_line_len
, append
);
479 tmp_line_len
+= append_len
;
481 if (tmp_line
[tmp_line_len
-1] == '\\') {
482 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
483 tmp_line
[--tmp_line_len
] = '\0';
487 trim_trailing_ws(tmp_line
);
488 ProcessMacros(tmp_line
, tmp_line_len
);
489 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
491 if (const char* expr
= FindStatement(tmp_line
, "if")) {
492 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
493 } else if (FindStatement(tmp_line
, "endif")) {
494 if (!if_states
.empty())
495 if_states
.pop_back(); // remove last if-statement meaning
497 fatalf("'endif' without 'if'\n");
498 } else if (FindStatement(tmp_line
, "else")) {
499 if (!if_states
.empty())
500 if_states
.back() = !if_states
.back();
502 fatalf("'else' without 'if'\n");
503 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
504 /* Handle includes here */
505 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
506 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
507 } else if (!parse_line(tmp_line
)) {
508 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
517 if (!if_states
.empty())
518 fatalf("if-statement without 'endif'\n");
521 int ret
= pclose(fp
);
524 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
529 cfg_filename
= orig_cfg_filename
;
530 config_lineno
= orig_config_lineno
;
536 parseConfigFile(const char *file_name
)
544 ACLMethodData::ThePurgeCount
= 0;
547 err_count
= parseOneConfigFile(file_name
, 0);
552 * We must call configDoConfigure() before leave_suid() because
553 * configDoConfigure() is where we turn username strings into
558 if (!Config
.chroot_dir
) {
560 setUmask(Config
.umask
);
561 _db_init(Debug::cache_log
, Debug::debugOptions
);
565 if (opt_send_signal
== -1) {
566 Mgr::RegisterAction("config",
567 "Current Squid Configuration",
577 configDoConfigure(void)
579 memset(&Config2
, '\0', sizeof(SquidConfig2
));
580 /* init memory as early as possible */
584 if (Config
.cacheSwap
.swapDirs
== NULL
) {
585 /* Memory-only cache probably in effect. */
586 /* turn off the cache rebuild delays... */
587 StoreController::store_dirs_rebuilding
= 0;
590 if (Debug::rotateNumber
< 0) {
591 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
594 #if SIZEOF_OFF_T <= 4
595 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
596 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
597 Config
.Store
.maxObjectSize
= 0x7FFF0000;
600 if (0 == Store::Root().maxSize())
601 /* people might want a zero-sized cache on purpose */
603 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
604 /* This is bogus. folk with NULL caches will want this */
605 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
607 if (Config
.Announce
.period
> 0) {
608 Config
.onoff
.announce
= 1;
609 } else if (Config
.Announce
.period
< 1) {
610 Config
.Announce
.period
= 86400 * 365; /* one year */
611 Config
.onoff
.announce
= 0;
614 if (Config
.onoff
.httpd_suppress_version_string
)
615 visible_appname_string
= (char *)appname_string
;
617 visible_appname_string
= (char const *)APP_FULLNAME
;
621 if (Config
.dnsChildren
.n_max
< 1)
622 fatal("No dnsservers allocated");
626 if (Config
.Program
.redirect
) {
627 if (Config
.redirectChildren
.n_max
< 1) {
628 Config
.redirectChildren
.n_max
= 0;
629 wordlistDestroy(&Config
.Program
.redirect
);
633 if (Config
.appendDomain
)
634 if (*Config
.appendDomain
!= '.')
635 fatal("append_domain must begin with a '.'");
637 if (Config
.errHtmlText
== NULL
)
638 Config
.errHtmlText
= xstrdup(null_string
);
642 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
644 visible_appname_string
);
647 * the extra space is for loop detection in client_side.c -- we search
648 * for substrings in the Via header.
650 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
652 visible_appname_string
);
654 /* Use visible_hostname as default surrogate_id */
655 if (!Config
.Accel
.surrogate_id
) {
656 const char *t
= getMyHostname();
657 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
660 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
661 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
663 if (Config
.appendDomain
)
664 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
666 Config
.appendDomainLen
= 0;
668 if (Config
.connect_retries
> 10) {
669 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
670 Config
.connect_retries
= 10;
673 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
676 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
680 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
682 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
683 if (Config
.Program
.redirect
)
684 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
686 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
688 if (Config
.errorDirectory
)
689 requirePathnameExists("Error Directory", Config
.errorDirectory
);
691 #if USE_HTTP_VIOLATIONS
696 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
697 if (!R
->flags
.override_expire
)
700 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
705 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
706 if (!R
->flags
.override_lastmod
)
709 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
714 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
715 if (!R
->flags
.reload_into_ims
)
718 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
723 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
724 if (!R
->flags
.ignore_reload
)
727 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
732 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
733 if (!R
->flags
.ignore_no_cache
)
736 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
741 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
742 if (!R
->flags
.ignore_no_store
)
745 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
750 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
751 if (!R
->flags
.ignore_must_revalidate
)
753 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
757 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
758 if (!R
->flags
.ignore_private
)
761 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
766 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
767 if (!R
->flags
.ignore_auth
)
770 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
777 #if !USE_HTTP_VIOLATIONS
778 Config
.onoff
.via
= 1;
781 if (!Config
.onoff
.via
)
782 debugs(22, 1, "WARNING: HTTP requires the use of Via");
786 // we enable runtime PURGE checks if there is at least one PURGE method ACL
787 // TODO: replace with a dedicated "purge" ACL option?
788 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
790 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
792 if (geteuid() == 0) {
793 if (NULL
!= Config
.effectiveUser
) {
795 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
799 * Andres Kroonmaa <andre@online.ee>:
800 * Some getpwnam() implementations (Solaris?) require
801 * an available FD < 256 for opening a FILE* to the
804 * This should be safe at startup, but might still fail
805 * during reconfigure.
807 fatalf("getpwnam failed to find userid for effective user '%s'",
808 Config
.effectiveUser
);
812 Config2
.effectiveUserID
= pwd
->pw_uid
;
814 Config2
.effectiveGroupID
= pwd
->pw_gid
;
818 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
820 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
821 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
829 Config2
.effectiveUserID
= geteuid();
830 Config2
.effectiveGroupID
= getegid();
833 if (NULL
!= Config
.effectiveGroup
) {
835 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
838 fatalf("getgrnam failed to find groupid for effective group '%s'",
839 Config
.effectiveGroup
);
843 Config2
.effectiveGroupID
= grp
->gr_gid
;
846 HttpRequestMethod::Configure(Config
);
849 debugs(3, 1, "Initializing https proxy context");
851 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
);
857 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
859 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
860 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
869 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
870 if (!s
->cert
&& !s
->key
)
873 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
875 s
->sslContext
= sslCreateServerContext(s
->cert
, s
->key
, s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
, s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
, s
->sslcontext
);
883 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
884 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
886 s
->sslContext
= sslCreateServerContext(s
->cert
, s
->key
, s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
, s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
, s
->sslcontext
);
893 /** Parse a line containing an obsolete directive.
894 * To upgrade it where possible instead of just "Bungled config" for
895 * directives which cannot be marked as simply aliases of the some name.
896 * For example if the parameter order and content has changed.
897 * Or if the directive has been completely removed.
900 parse_obsolete(const char *name
)
902 // Directives which have been radically changed rather than removed
903 if (!strcmp(name
, "url_rewrite_concurrency")) {
906 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
907 Config
.redirectChildren
.concurrency
= cval
;
911 /* Parse a time specification from the config file. Store the
912 * result in 'tptr', after converting it to 'units' */
914 parseTimeLine(time_t * tptr
, const char *units
)
921 if ((u
= parseTimeUnits(units
)) == 0)
924 if ((token
= strtok(NULL
, w_space
)) == NULL
)
929 m
= u
; /* default to 'units' if none specified */
933 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
934 debugs(3, 0, "WARNING: No units on '" <<
935 config_input_line
<< "', assuming " <<
937 else if ((m
= parseTimeUnits(token
)) == 0)
940 *tptr
= static_cast<time_t> (m
* d
/ u
);
944 parseTimeUnits(const char *unit
)
946 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
949 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
952 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
955 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
958 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
961 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
964 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
967 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
968 return static_cast<int>(86400 * 365.2522);
970 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
971 return static_cast<int>(86400 * 365.2522 * 10);
973 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
979 parseBytesLine64(int64_t * bptr
, const char *units
)
986 if ((u
= parseBytesUnits(units
)) == 0) {
991 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
996 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1003 m
= u
; /* default to 'units' if none specified */
1007 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1008 debugs(3, 0, "WARNING: No units on '" <<
1009 config_input_line
<< "', assuming " <<
1010 d
<< " " << units
);
1011 else if ((m
= parseBytesUnits(token
)) == 0) {
1016 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1018 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1024 parseBytesLine(size_t * bptr
, const char *units
)
1031 if ((u
= parseBytesUnits(units
)) == 0) {
1036 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1041 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1042 *bptr
= static_cast<size_t>(-1);
1048 m
= u
; /* default to 'units' if none specified */
1052 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1053 debugs(3, 0, "WARNING: No units on '" <<
1054 config_input_line
<< "', assuming " <<
1055 d
<< " " << units
);
1056 else if ((m
= parseBytesUnits(token
)) == 0) {
1061 *bptr
= static_cast<size_t>(m
* d
/ u
);
1063 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1069 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1076 if ((u
= parseBytesUnits(units
)) == 0) {
1081 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1086 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1093 m
= u
; /* default to 'units' if none specified */
1097 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1098 debugs(3, 0, "WARNING: No units on '" <<
1099 config_input_line
<< "', assuming " <<
1100 d
<< " " << units
);
1101 else if ((m
= parseBytesUnits(token
)) == 0) {
1106 *bptr
= static_cast<size_t>(m
* d
/ u
);
1108 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1114 parseBytesUnits(const char *unit
)
1116 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1119 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1122 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1125 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1128 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1133 /*****************************************************************************
1135 *****************************************************************************/
1138 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1143 while (ae
!= NULL
) {
1144 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1145 storeAppendPrintf(entry
, "%s %s %s ",
1152 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1153 storeAppendPrintf(entry
, "%s ", v
->key
);
1157 storeAppendPrintf(entry
, "\n");
1158 wordlistDestroy(&w
);
1164 parse_acl(ACL
** ae
)
1166 ACL::ParseAclLine(LegacyParser
, ae
);
1176 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1180 for (l
= head
; l
; l
= l
->next
) {
1181 storeAppendPrintf(entry
, " %s%s",
1182 l
->op
? null_string
: "!",
1188 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1192 for (l
= head
; l
; l
= l
->next
) {
1193 storeAppendPrintf(entry
, "%s %s",
1195 l
->allow
? "Allow" : "Deny");
1196 dump_acl_list(entry
, l
->aclList
);
1197 storeAppendPrintf(entry
, "\n");
1202 parse_acl_access(acl_access
** head
)
1204 aclParseAccessLine(LegacyParser
, head
);
1208 free_acl_access(acl_access
** head
)
1210 aclDestroyAccessList(head
);
1214 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1216 char buf
[MAX_IPSTRLEN
];
1217 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1221 parse_address(Ip::Address
*addr
)
1223 char *token
= strtok(NULL
, w_space
);
1230 if (!strcmp(token
,"any_addr")) {
1233 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1241 free_address(Ip::Address
*addr
)
1246 CBDATA_TYPE(acl_address
);
1249 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1251 char buf
[MAX_IPSTRLEN
];
1254 for (l
= head
; l
; l
= l
->next
) {
1255 if (!l
->addr
.IsAnyAddr())
1256 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1258 storeAppendPrintf(entry
, "%s autoselect", name
);
1260 dump_acl_list(entry
, l
->aclList
);
1262 storeAppendPrintf(entry
, "\n");
1267 freed_acl_address(void *data
)
1269 acl_address
*l
= static_cast<acl_address
*>(data
);
1270 aclDestroyAclList(&l
->aclList
);
1274 parse_acl_address(acl_address
** head
)
1277 acl_address
**tail
= head
; /* sane name below */
1278 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1279 l
= cbdataAlloc(acl_address
);
1280 parse_address(&l
->addr
);
1281 aclParseAclList(LegacyParser
, &l
->aclList
);
1284 tail
= &(*tail
)->next
;
1290 free_acl_address(acl_address
** head
)
1293 acl_address
*l
= *head
;
1299 CBDATA_TYPE(acl_tos
);
1302 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1306 for (l
= head
; l
; l
= l
->next
) {
1308 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1310 storeAppendPrintf(entry
, "%s none", name
);
1312 dump_acl_list(entry
, l
->aclList
);
1314 storeAppendPrintf(entry
, "\n");
1319 freed_acl_tos(void *data
)
1321 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1322 aclDestroyAclList(&l
->aclList
);
1326 parse_acl_tos(acl_tos
** head
)
1329 acl_tos
**tail
= head
; /* sane name below */
1330 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1331 char *token
= strtok(NULL
, w_space
);
1338 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1343 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1345 l
= cbdataAlloc(acl_tos
);
1347 l
->tos
= (tos_t
)tos
;
1349 aclParseAclList(LegacyParser
, &l
->aclList
);
1352 tail
= &(*tail
)->next
;
1358 free_acl_tos(acl_tos
** head
)
1368 #if defined(SO_MARK)
1370 CBDATA_TYPE(acl_nfmark
);
1373 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1377 for (l
= head
; l
; l
= l
->next
) {
1379 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1381 storeAppendPrintf(entry
, "%s none", name
);
1383 dump_acl_list(entry
, l
->aclList
);
1385 storeAppendPrintf(entry
, "\n");
1390 freed_acl_nfmark(void *data
)
1392 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1393 aclDestroyAclList(&l
->aclList
);
1397 parse_acl_nfmark(acl_nfmark
** head
)
1400 acl_nfmark
**tail
= head
; /* sane name below */
1402 char *token
= strtok(NULL
, w_space
);
1409 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1414 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1416 l
= cbdataAlloc(acl_nfmark
);
1420 aclParseAclList(LegacyParser
, &l
->aclList
);
1423 tail
= &(*tail
)->next
;
1429 free_acl_nfmark(acl_nfmark
** head
)
1432 acl_nfmark
*l
= *head
;
1438 #endif /* SO_MARK */
1440 CBDATA_TYPE(acl_size_t
);
1443 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1447 for (l
= head
; l
; l
= l
->next
) {
1449 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1451 storeAppendPrintf(entry
, "%s none", name
);
1453 dump_acl_list(entry
, l
->aclList
);
1455 storeAppendPrintf(entry
, "\n");
1460 freed_acl_b_size_t(void *data
)
1462 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1463 aclDestroyAclList(&l
->aclList
);
1467 parse_acl_b_size_t(acl_size_t
** head
)
1470 acl_size_t
**tail
= head
; /* sane name below */
1472 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1474 l
= cbdataAlloc(acl_size_t
);
1476 parse_b_int64_t(&l
->size
);
1478 aclParseAclList(LegacyParser
, &l
->aclList
);
1481 tail
= &(*tail
)->next
;
1487 free_acl_b_size_t(acl_size_t
** head
)
1490 acl_size_t
*l
= *head
;
1499 #include "DelayPools.h"
1500 #include "DelayConfig.h"
1501 /* do nothing - free_delay_pool_count is the magic free function.
1502 * this is why delay_pool_count isn't just marked TYPE: ushort
1504 #define free_delay_pool_class(X)
1505 #define free_delay_pool_access(X)
1506 #define free_delay_pool_rates(X)
1507 #define dump_delay_pool_class(X, Y, Z)
1508 #define dump_delay_pool_access(X, Y, Z)
1509 #define dump_delay_pool_rates(X, Y, Z)
1512 free_delay_pool_count(DelayConfig
* cfg
)
1514 cfg
->freePoolCount();
1518 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1520 cfg
.dumpPoolCount (entry
, name
);
1524 parse_delay_pool_count(DelayConfig
* cfg
)
1526 cfg
->parsePoolCount();
1530 parse_delay_pool_class(DelayConfig
* cfg
)
1532 cfg
->parsePoolClass();
1536 parse_delay_pool_rates(DelayConfig
* cfg
)
1538 cfg
->parsePoolRates();
1542 parse_delay_pool_access(DelayConfig
* cfg
)
1544 cfg
->parsePoolAccess(LegacyParser
);
1550 #include "ClientDelayConfig.h"
1551 /* do nothing - free_client_delay_pool_count is the magic free function.
1552 * this is why client_delay_pool_count isn't just marked TYPE: ushort
1555 #define free_client_delay_pool_access(X)
1556 #define free_client_delay_pool_rates(X)
1557 #define dump_client_delay_pool_access(X, Y, Z)
1558 #define dump_client_delay_pool_rates(X, Y, Z)
1561 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1563 cfg
->freePoolCount();
1567 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1569 cfg
.dumpPoolCount (entry
, name
);
1573 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1575 cfg
->parsePoolCount();
1579 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1581 cfg
->parsePoolRates();
1585 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1587 cfg
->parsePoolAccess(LegacyParser
);
1591 #if USE_HTTP_VIOLATIONS
1593 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1597 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1598 if (header
[i
].access_list
!= NULL
) {
1599 storeAppendPrintf(entry
, "%s ", name
);
1600 dump_acl_access(entry
, httpHeaderNameById(i
),
1601 header
[i
].access_list
);
1607 parse_http_header_access(header_mangler header
[])
1612 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1613 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1614 debugs(3, 0, "parse_http_header_access: missing header name.");
1618 /* Now lookup index of header. */
1619 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1621 if (strcmp(t
, "All") == 0)
1623 else if (strcmp(t
, "Other") == 0)
1625 else if (id
== -1) {
1626 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1627 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1631 if (id
!= HDR_ENUM_END
) {
1632 parse_acl_access(&header
[id
].access_list
);
1634 char *next_string
= t
+ strlen(t
) - 1;
1636 *(next_string
+ 1) = ' ';
1638 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1639 char *new_string
= xstrdup(next_string
);
1640 strtok(new_string
, w_space
);
1641 parse_acl_access(&header
[i
].access_list
);
1642 safe_free(new_string
);
1648 free_http_header_access(header_mangler header
[])
1652 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1653 free_acl_access(&header
[i
].access_list
);
1658 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1663 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1664 if (NULL
== header
[i
].replacement
)
1667 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1668 header
[i
].replacement
);
1673 parse_http_header_replace(header_mangler header
[])
1678 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1679 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1680 debugs(3, 0, "parse_http_header_replace: missing header name.");
1684 /* Now lookup index of header. */
1685 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1687 if (strcmp(t
, "All") == 0)
1689 else if (strcmp(t
, "Other") == 0)
1691 else if (id
== -1) {
1692 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1693 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1698 if (id
!= HDR_ENUM_END
) {
1699 if (header
[id
].replacement
!= NULL
)
1700 safe_free(header
[id
].replacement
);
1702 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1704 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1705 if (header
[i
].replacement
!= NULL
)
1706 safe_free(header
[i
].replacement
);
1708 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1714 free_http_header_replace(header_mangler header
[])
1718 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1719 if (header
[i
].replacement
!= NULL
)
1720 safe_free(header
[i
].replacement
);
1727 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1733 for (i
= 0; i
< swap
.n_configured
; i
++) {
1734 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1736 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1738 storeAppendPrintf(entry
, "\n");
1743 check_null_string(char *s
)
1749 parse_authparam(Auth::authConfig
* config
)
1754 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1757 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1760 /* find a configuration for the scheme in the currently parsed configs... */
1761 AuthConfig
*schemeCfg
= AuthConfig::Find(type_str
);
1763 if (schemeCfg
== NULL
) {
1764 /* Create a configuration based on the scheme info */
1765 AuthScheme::Pointer theScheme
= AuthScheme::Find(type_str
);
1767 if (theScheme
== NULL
) {
1768 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1772 config
->push_back(theScheme
->createConfig());
1773 schemeCfg
= AuthConfig::Find(type_str
);
1774 if (schemeCfg
== NULL
) {
1775 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1780 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1784 free_authparam(Auth::authConfig
* cfg
)
1786 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1789 /* remove our pointers to the probably-dead sub-configs */
1790 while (cfg
->size()) {
1794 /* on reconfigure initialize new auth schemes for the new config. */
1795 if (reconfiguring
) {
1801 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1803 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1804 (*i
)->dump(entry
, name
, (*i
));
1807 /* TODO: just return the object, the # is irrelevant */
1809 find_fstype(char *type
)
1811 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1812 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1819 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1821 // The workers option must preceed cache_dir for the IamWorkerProcess check
1822 // below to work. TODO: Redo IamWorkerProcess to work w/o Config and remove
1823 if (KidIdentifier
> 1 && Config
.workers
== 1) {
1824 debugs(3, DBG_CRITICAL
,
1825 "FATAL: cache_dir found before the workers option. Reorder.");
1829 // Among all processes, only workers may need and can handle cache_dir.
1830 if (!IamWorkerProcess())
1835 RefCount
<SwapDir
> sd
;
1839 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1842 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1845 fs
= find_fstype(type_str
);
1850 /* reconfigure existing dir */
1852 for (i
= 0; i
< swap
->n_configured
; i
++) {
1853 assert (swap
->swapDirs
[i
].getRaw());
1855 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1856 /* this is specific to on-fs Stores. The right
1857 * way to handle this is probably to have a mapping
1858 * from paths to stores, and have on-fs stores
1859 * register with that, and lookip in that in their
1860 * own setup logic. RBC 20041225. TODO.
1863 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1865 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1866 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1867 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1871 sd
->reconfigure (i
, path_str
);
1873 update_maxobjsize();
1880 if (swap
->n_configured
> 63) {
1881 /* 7 bits, signed */
1882 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1883 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1888 allocate_new_swapdir(swap
);
1890 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1892 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1894 /* parse the FS parameters and options */
1895 sd
->parse(swap
->n_configured
, path_str
);
1897 ++swap
->n_configured
;
1899 /* Update the max object size */
1900 update_maxobjsize();
1904 peer_type_str(const peer_t type
)
1906 const char * result
;
1918 case PEER_MULTICAST
:
1919 result
= "multicast";
1931 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1935 LOCAL_ARRAY(char, xname
, 128);
1938 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1945 dump_peer_options(entry
, p
);
1947 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1948 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1950 d
->do_ping
? null_string
: "!",
1955 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1956 dump_acl_access(entry
, xname
, p
->access
);
1959 for (t
= p
->typelist
; t
; t
= t
->next
) {
1960 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1962 peer_type_str(t
->type
),
1971 * utility function to prevent getservbyname() being called with a numeric value
1972 * on Windows at least it returns garage results.
1975 isUnsignedNumeric(const char *str
, size_t len
)
1977 if (len
< 1) return false;
1979 for (; len
>0 && *str
; str
++, len
--) {
1980 if (! isdigit(*str
))
1987 \param proto 'tcp' or 'udp' for protocol
1988 \returns Port the named service is supposed to be listening on.
1991 GetService(const char *proto
)
1993 struct servent
*port
= NULL
;
1994 /** Parses a port number or service name from the squid.conf */
1995 char *token
= strtok(NULL
, w_space
);
1996 if (token
== NULL
) {
1998 return 0; /* NEVER REACHED */
2000 /** Returns either the service port number from /etc/services */
2001 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2002 port
= getservbyname(token
, proto
);
2004 return ntohs((u_short
)port
->s_port
);
2006 /** Or a numeric translation of the config text. */
2007 return xatos(token
);
2011 \returns Port the named TCP service is supposed to be listening on.
2012 \copydoc GetService(const char *proto)
2017 return GetService("tcp");
2021 \returns Port the named UDP service is supposed to be listening on.
2022 \copydoc GetService(const char *proto)
2027 return GetService("udp");
2031 parse_peer(peer
** head
)
2035 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
2036 p
= cbdataAlloc(peer
);
2037 p
->http_port
= CACHE_HTTP_PORT
;
2038 p
->icp
.port
= CACHE_ICP_PORT
;
2041 p
->stats
.logged_state
= PEER_ALIVE
;
2043 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2046 p
->host
= xstrdup(token
);
2048 p
->name
= xstrdup(token
);
2050 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2053 p
->type
= parseNeighborType(token
);
2055 if (p
->type
== PEER_MULTICAST
) {
2056 p
->options
.no_digest
= 1;
2057 p
->options
.no_netdb_exchange
= 1;
2060 p
->http_port
= GetTcpService();
2065 p
->icp
.port
= GetUdpService();
2066 p
->connection_auth
= 2; /* auto */
2068 while ((token
= strtok(NULL
, w_space
))) {
2069 if (!strcasecmp(token
, "proxy-only")) {
2070 p
->options
.proxy_only
= 1;
2071 } else if (!strcasecmp(token
, "no-query")) {
2072 p
->options
.no_query
= 1;
2073 } else if (!strcasecmp(token
, "background-ping")) {
2074 p
->options
.background_ping
= 1;
2075 } else if (!strcasecmp(token
, "no-digest")) {
2076 p
->options
.no_digest
= 1;
2077 } else if (!strcasecmp(token
, "no-tproxy")) {
2078 p
->options
.no_tproxy
= 1;
2079 } else if (!strcasecmp(token
, "multicast-responder")) {
2080 p
->options
.mcast_responder
= 1;
2081 #if PEER_MULTICAST_SIBLINGS
2082 } else if (!strcasecmp(token
, "multicast-siblings")) {
2083 p
->options
.mcast_siblings
= 1;
2085 } else if (!strncasecmp(token
, "weight=", 7)) {
2086 p
->weight
= xatoi(token
+ 7);
2087 } else if (!strncasecmp(token
, "basetime=", 9)) {
2088 p
->basetime
= xatoi(token
+ 9);
2089 } else if (!strcasecmp(token
, "closest-only")) {
2090 p
->options
.closest_only
= 1;
2091 } else if (!strncasecmp(token
, "ttl=", 4)) {
2092 p
->mcast
.ttl
= xatoi(token
+ 4);
2094 if (p
->mcast
.ttl
< 0)
2097 if (p
->mcast
.ttl
> 128)
2099 } else if (!strcasecmp(token
, "default")) {
2100 p
->options
.default_parent
= 1;
2101 } else if (!strcasecmp(token
, "round-robin")) {
2102 p
->options
.roundrobin
= 1;
2103 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2104 p
->options
.weighted_roundrobin
= 1;
2106 } else if (!strcasecmp(token
, "htcp")) {
2107 p
->options
.htcp
= 1;
2108 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2109 /* Note: The htcp- form is deprecated, replaced by htcp= */
2110 p
->options
.htcp
= 1;
2111 char *tmp
= xstrdup(token
+5);
2112 char *mode
, *nextmode
;
2113 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2114 nextmode
= strchr(mode
, ',');
2117 if (!strcasecmp(mode
, "no-clr")) {
2118 if (p
->options
.htcp_only_clr
)
2119 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2120 p
->options
.htcp_no_clr
= 1;
2121 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2122 p
->options
.htcp_no_purge_clr
= 1;
2123 } else if (!strcasecmp(mode
, "only-clr")) {
2124 if (p
->options
.htcp_no_clr
)
2125 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2126 p
->options
.htcp_only_clr
= 1;
2127 } else if (!strcasecmp(mode
, "forward-clr")) {
2128 p
->options
.htcp_forward_clr
= 1;
2129 } else if (!strcasecmp(mode
, "oldsquid")) {
2130 p
->options
.htcp_oldsquid
= 1;
2132 fatalf("invalid HTCP mode '%s'", mode
);
2137 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2138 p
->options
.no_netdb_exchange
= 1;
2140 } else if (!strcasecmp(token
, "carp")) {
2141 if (p
->type
!= PEER_PARENT
)
2142 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2144 p
->options
.carp
= 1;
2146 } else if (!strcasecmp(token
, "userhash")) {
2147 if (p
->type
!= PEER_PARENT
)
2148 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2150 p
->options
.userhash
= 1;
2152 } else if (!strcasecmp(token
, "sourcehash")) {
2153 if (p
->type
!= PEER_PARENT
)
2154 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2156 p
->options
.sourcehash
= 1;
2160 } else if (!strcasecmp(token
, "no-delay")) {
2161 p
->options
.no_delay
= 1;
2164 } else if (!strncasecmp(token
, "login=", 6)) {
2165 p
->login
= xstrdup(token
+ 6);
2166 rfc1738_unescape(p
->login
);
2167 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2168 p
->connect_timeout
= xatoi(token
+ 16);
2169 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2170 p
->connect_fail_limit
= xatoi(token
+ 19);
2171 #if USE_CACHE_DIGESTS
2172 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2173 p
->digest_url
= xstrdup(token
+ 11);
2176 } else if (!strcasecmp(token
, "allow-miss")) {
2177 p
->options
.allow_miss
= 1;
2178 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2179 p
->max_conn
= xatoi(token
+ 9);
2180 } else if (!strcasecmp(token
, "originserver")) {
2181 p
->options
.originserver
= 1;
2182 } else if (!strncasecmp(token
, "name=", 5)) {
2186 p
->name
= xstrdup(token
+ 5);
2187 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2188 safe_free(p
->domain
);
2191 p
->domain
= xstrdup(token
+ 13);
2195 } else if (strcmp(token
, "ssl") == 0) {
2197 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2198 safe_free(p
->sslcert
);
2199 p
->sslcert
= xstrdup(token
+ 8);
2200 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2201 safe_free(p
->sslkey
);
2202 p
->sslkey
= xstrdup(token
+ 7);
2203 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2204 p
->sslversion
= atoi(token
+ 11);
2205 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2206 safe_free(p
->ssloptions
);
2207 p
->ssloptions
= xstrdup(token
+ 11);
2208 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2209 safe_free(p
->sslcipher
);
2210 p
->sslcipher
= xstrdup(token
+ 10);
2211 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2212 safe_free(p
->sslcafile
);
2213 p
->sslcafile
= xstrdup(token
+ 10);
2214 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2215 safe_free(p
->sslcapath
);
2216 p
->sslcapath
= xstrdup(token
+ 10);
2217 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2218 safe_free(p
->sslcrlfile
);
2219 p
->sslcapath
= xstrdup(token
+ 10);
2220 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2221 safe_free(p
->sslflags
);
2222 p
->sslflags
= xstrdup(token
+ 9);
2223 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2224 safe_free(p
->ssldomain
);
2225 p
->ssldomain
= xstrdup(token
+ 10);
2228 } else if (strcmp(token
, "front-end-https") == 0) {
2229 p
->front_end_https
= 1;
2230 } else if (strcmp(token
, "front-end-https=on") == 0) {
2231 p
->front_end_https
= 1;
2232 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2233 p
->front_end_https
= 2;
2234 } else if (strcmp(token
, "connection-auth=off") == 0) {
2235 p
->connection_auth
= 0;
2236 } else if (strcmp(token
, "connection-auth") == 0) {
2237 p
->connection_auth
= 1;
2238 } else if (strcmp(token
, "connection-auth=on") == 0) {
2239 p
->connection_auth
= 1;
2240 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2241 p
->connection_auth
= 2;
2243 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2248 if (peerFindByName(p
->name
))
2249 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2254 if (p
->connect_fail_limit
< 1)
2255 p
->connect_fail_limit
= 10;
2257 p
->icp
.version
= ICP_VERSION_CURRENT
;
2259 p
->testing_now
= false;
2261 #if USE_CACHE_DIGESTS
2263 if (!p
->options
.no_digest
) {
2264 /* XXX This looks odd.. who has the original pointer
2267 PeerDigest
*pd
= peerDigestCreate(p
);
2268 p
->digest
= cbdataReference(pd
);
2273 p
->index
= ++Config
.npeers
;
2275 while (*head
!= NULL
)
2276 head
= &(*head
)->next
;
2284 free_peer(peer
** P
)
2288 while ((p
= *P
) != NULL
) {
2290 #if USE_CACHE_DIGESTS
2292 cbdataReferenceDone(p
->digest
);
2302 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2306 while (list
!= NULL
) {
2307 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2308 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2310 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2312 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2313 storeAppendPrintf(entry
, " %s", w
->key
);
2316 storeAppendPrintf(entry
, "\n");
2322 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2324 char *passwd
= NULL
;
2325 wordlist
*actions
= NULL
;
2327 cachemgr_passwd
**P
;
2328 parse_string(&passwd
);
2329 parse_wordlist(&actions
);
2330 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2332 p
->actions
= actions
;
2334 for (P
= head
; *P
; P
= &(*P
)->next
) {
2336 * See if any of the actions from this line already have a
2337 * password from previous lines. The password checking
2338 * routines in cache_manager.c take the the password from
2339 * the first cachemgr_passwd struct that contains the
2340 * requested action. Thus, we should warn users who might
2341 * think they can have two passwords for the same action.
2346 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2347 for (u
= actions
; u
; u
= u
->next
) {
2348 if (strcmp(w
->key
, u
->key
))
2351 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2360 free_cachemgrpasswd(cachemgr_passwd
** head
)
2364 while ((p
= *head
) != NULL
) {
2367 wordlistDestroy(&p
->actions
);
2373 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2377 while (var
!= NULL
) {
2378 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2380 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2381 storeAppendPrintf(entry
, " %s", a
->name
);
2383 storeAppendPrintf(entry
, "\n");
2390 parse_denyinfo(acl_deny_info_list
** var
)
2392 aclParseDenyInfoLine(var
);
2396 free_denyinfo(acl_deny_info_list
** list
)
2398 acl_deny_info_list
*a
= NULL
;
2399 acl_deny_info_list
*a_next
= NULL
;
2400 acl_name_list
*l
= NULL
;
2401 acl_name_list
*l_next
= NULL
;
2403 for (a
= *list
; a
; a
= a_next
) {
2404 for (l
= a
->acl_list
; l
; l
= l_next
) {
2406 memFree(l
, MEM_ACL_NAME_LIST
);
2411 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2419 parse_peer_access(void)
2424 if (!(host
= strtok(NULL
, w_space
)))
2427 if ((p
= peerFindByName(host
)) == NULL
) {
2428 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2432 aclParseAccessLine(LegacyParser
, &p
->access
);
2436 parse_hostdomain(void)
2439 char *domain
= NULL
;
2441 if (!(host
= strtok(NULL
, w_space
)))
2444 while ((domain
= strtok(NULL
, list_sep
))) {
2445 domain_ping
*l
= NULL
;
2446 domain_ping
**L
= NULL
;
2449 if ((p
= peerFindByName(host
)) == NULL
) {
2450 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2454 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2457 if (*domain
== '!') { /* check for !.edu */
2462 l
->domain
= xstrdup(domain
);
2464 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2470 parse_hostdomaintype(void)
2474 char *domain
= NULL
;
2476 if (!(host
= strtok(NULL
, w_space
)))
2479 if (!(type
= strtok(NULL
, w_space
)))
2482 while ((domain
= strtok(NULL
, list_sep
))) {
2483 domain_type
*l
= NULL
;
2484 domain_type
**L
= NULL
;
2487 if ((p
= peerFindByName(host
)) == NULL
) {
2488 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2492 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2493 l
->type
= parseNeighborType(type
);
2494 l
->domain
= xstrdup(domain
);
2496 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2502 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2504 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2522 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2524 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2528 parse_onoff(int *var
)
2530 char *token
= strtok(NULL
, w_space
);
2535 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2541 #define free_onoff free_int
2544 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2555 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2559 parse_tristate(int *var
)
2561 char *token
= strtok(NULL
, w_space
);
2566 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2568 else if (!strcasecmp(token
, "warn"))
2574 #define free_tristate free_int
2577 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2579 while (head
!= NULL
) {
2580 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2582 head
->flags
.icase
? " -i" : null_string
,
2584 (int) head
->min
/ 60,
2585 (int) (100.0 * head
->pct
+ 0.5),
2586 (int) head
->max
/ 60);
2588 if (head
->flags
.refresh_ims
)
2589 storeAppendPrintf(entry
, " refresh-ims");
2591 if (head
->flags
.store_stale
)
2592 storeAppendPrintf(entry
, " store-stale");
2594 #if USE_HTTP_VIOLATIONS
2596 if (head
->flags
.override_expire
)
2597 storeAppendPrintf(entry
, " override-expire");
2599 if (head
->flags
.override_lastmod
)
2600 storeAppendPrintf(entry
, " override-lastmod");
2602 if (head
->flags
.reload_into_ims
)
2603 storeAppendPrintf(entry
, " reload-into-ims");
2605 if (head
->flags
.ignore_reload
)
2606 storeAppendPrintf(entry
, " ignore-reload");
2608 if (head
->flags
.ignore_no_cache
)
2609 storeAppendPrintf(entry
, " ignore-no-cache");
2611 if (head
->flags
.ignore_no_store
)
2612 storeAppendPrintf(entry
, " ignore-no-store");
2614 if (head
->flags
.ignore_must_revalidate
)
2615 storeAppendPrintf(entry
, " ignore-must-revalidate");
2617 if (head
->flags
.ignore_private
)
2618 storeAppendPrintf(entry
, " ignore-private");
2620 if (head
->flags
.ignore_auth
)
2621 storeAppendPrintf(entry
, " ignore-auth");
2625 storeAppendPrintf(entry
, "\n");
2632 parse_refreshpattern(refresh_t
** head
)
2639 int refresh_ims
= 0;
2640 int store_stale
= 0;
2642 #if USE_HTTP_VIOLATIONS
2644 int override_expire
= 0;
2645 int override_lastmod
= 0;
2646 int reload_into_ims
= 0;
2647 int ignore_reload
= 0;
2648 int ignore_no_cache
= 0;
2649 int ignore_no_store
= 0;
2650 int ignore_must_revalidate
= 0;
2651 int ignore_private
= 0;
2652 int ignore_auth
= 0;
2659 int flags
= REG_EXTENDED
| REG_NOSUB
;
2661 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2666 if (strcmp(token
, "-i") == 0) {
2668 token
= strtok(NULL
, w_space
);
2669 } else if (strcmp(token
, "+i") == 0) {
2670 flags
&= ~REG_ICASE
;
2671 token
= strtok(NULL
, w_space
);
2674 if (token
== NULL
) {
2679 pattern
= xstrdup(token
);
2681 i
= GetInteger(); /* token: min */
2683 /* catch negative and insanely huge values close to 32-bit wrap */
2685 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2688 if (i
> 60*24*365) {
2689 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2693 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2695 i
= GetInteger(); /* token: pct */
2697 pct
= (double) i
/ 100.0;
2699 i
= GetInteger(); /* token: max */
2701 /* catch negative and insanely huge values close to 32-bit wrap */
2703 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2706 if (i
> 60*24*365) {
2707 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2711 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2714 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2715 if (!strcmp(token
, "refresh-ims")) {
2717 } else if (!strcmp(token
, "store-stale")) {
2719 #if USE_HTTP_VIOLATIONS
2721 } else if (!strcmp(token
, "override-expire"))
2722 override_expire
= 1;
2723 else if (!strcmp(token
, "override-lastmod"))
2724 override_lastmod
= 1;
2725 else if (!strcmp(token
, "ignore-no-cache"))
2726 ignore_no_cache
= 1;
2727 else if (!strcmp(token
, "ignore-no-store"))
2728 ignore_no_store
= 1;
2729 else if (!strcmp(token
, "ignore-must-revalidate"))
2730 ignore_must_revalidate
= 1;
2731 else if (!strcmp(token
, "ignore-private"))
2733 else if (!strcmp(token
, "ignore-auth"))
2735 else if (!strcmp(token
, "reload-into-ims")) {
2736 reload_into_ims
= 1;
2737 refresh_nocache_hack
= 1;
2738 /* tell client_side.c that this is used */
2739 } else if (!strcmp(token
, "ignore-reload")) {
2741 refresh_nocache_hack
= 1;
2742 /* tell client_side.c that this is used */
2746 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2749 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2751 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2752 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2753 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2757 pct
= pct
< 0.0 ? 0.0 : pct
;
2758 max
= max
< 0 ? 0 : max
;
2759 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2760 t
->pattern
= (char *) xstrdup(pattern
);
2761 t
->compiled_pattern
= comp
;
2766 if (flags
& REG_ICASE
)
2770 t
->flags
.refresh_ims
= 1;
2773 t
->flags
.store_stale
= 1;
2775 #if USE_HTTP_VIOLATIONS
2777 if (override_expire
)
2778 t
->flags
.override_expire
= 1;
2780 if (override_lastmod
)
2781 t
->flags
.override_lastmod
= 1;
2783 if (reload_into_ims
)
2784 t
->flags
.reload_into_ims
= 1;
2787 t
->flags
.ignore_reload
= 1;
2789 if (ignore_no_cache
)
2790 t
->flags
.ignore_no_cache
= 1;
2792 if (ignore_no_store
)
2793 t
->flags
.ignore_no_store
= 1;
2795 if (ignore_must_revalidate
)
2796 t
->flags
.ignore_must_revalidate
= 1;
2799 t
->flags
.ignore_private
= 1;
2802 t
->flags
.ignore_auth
= 1;
2809 head
= &(*head
)->next
;
2817 free_refreshpattern(refresh_t
** head
)
2821 while ((t
= *head
) != NULL
) {
2823 safe_free(t
->pattern
);
2824 regfree(&t
->compiled_pattern
);
2828 #if USE_HTTP_VIOLATIONS
2829 refresh_nocache_hack
= 0;
2835 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2838 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2842 parse_string(char **var
)
2844 char *token
= strtok(NULL
, w_space
);
2850 *var
= xstrdup(token
);
2854 ConfigParser::ParseString(char **var
)
2860 ConfigParser::ParseString(String
*var
)
2862 char *token
= strtok(NULL
, w_space
);
2871 free_string(char **var
)
2877 parse_eol(char *volatile *var
)
2879 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2887 while (*token
&& xisspace(*token
))
2895 *var
= xstrdup((char *) token
);
2898 #define dump_eol dump_string
2899 #define free_eol free_string
2902 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2904 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2908 parse_time_t(time_t * var
)
2910 parseTimeLine(var
, T_SECOND_STR
);
2914 free_time_t(time_t * var
)
2921 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2923 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2928 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2930 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2935 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
2937 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2943 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2945 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2950 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2952 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2956 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2958 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2963 parse_size_t(size_t * var
)
2972 parse_b_size_t(size_t * var
)
2974 parseBytesLine(var
, B_BYTES_STR
);
2979 parse_b_ssize_t(ssize_t
* var
)
2981 parseBytesLineSigned(var
, B_BYTES_STR
);
2987 parse_kb_size_t(size_t * var
)
2989 parseBytesLine(var
, B_KBYTES_STR
);
2994 parse_b_int64_t(int64_t * var
)
2996 parseBytesLine64(var
, B_BYTES_STR
);
3000 parse_kb_int64_t(int64_t * var
)
3002 parseBytesLine64(var
, B_KBYTES_STR
);
3006 free_size_t(size_t * var
)
3013 free_ssize_t(ssize_t
* var
)
3020 free_b_int64_t(int64_t * var
)
3025 #define free_b_size_t free_size_t
3026 #define free_b_ssize_t free_ssize_t
3027 #define free_kb_size_t free_size_t
3028 #define free_mb_size_t free_size_t
3029 #define free_gb_size_t free_size_t
3030 #define free_kb_int64_t free_b_int64_t
3033 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
3035 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3039 free_ushort(u_short
* u
)
3045 parse_ushort(u_short
* var
)
3047 ConfigParser::ParseUShort(var
);
3051 ConfigParser::ParseUShort(u_short
*var
)
3057 ConfigParser::ParseBool(bool *var
)
3059 int i
= GetInteger();
3070 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3072 while (list
!= NULL
) {
3073 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3079 ConfigParser::ParseWordList(wordlist
** list
)
3081 parse_wordlist(list
);
3085 parse_wordlist(wordlist
** list
)
3088 char *t
= strtok(NULL
, "");
3090 while ((token
= strwordtok(NULL
, &t
)))
3091 wordlistAdd(list
, token
);
3094 #if 0 /* now unused */
3096 check_null_wordlist(wordlist
* w
)
3103 check_null_acl_access(acl_access
* a
)
3108 #define free_wordlist wordlistDestroy
3110 #define free_uri_whitespace free_int
3113 parse_uri_whitespace(int *var
)
3115 char *token
= strtok(NULL
, w_space
);
3120 if (!strcasecmp(token
, "strip"))
3121 *var
= URI_WHITESPACE_STRIP
;
3122 else if (!strcasecmp(token
, "deny"))
3123 *var
= URI_WHITESPACE_DENY
;
3124 else if (!strcasecmp(token
, "allow"))
3125 *var
= URI_WHITESPACE_ALLOW
;
3126 else if (!strcasecmp(token
, "encode"))
3127 *var
= URI_WHITESPACE_ENCODE
;
3128 else if (!strcasecmp(token
, "chop"))
3129 *var
= URI_WHITESPACE_CHOP
;
3135 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3139 if (var
== URI_WHITESPACE_ALLOW
)
3141 else if (var
== URI_WHITESPACE_ENCODE
)
3143 else if (var
== URI_WHITESPACE_CHOP
)
3145 else if (var
== URI_WHITESPACE_DENY
)
3150 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3154 free_removalpolicy(RemovalPolicySettings
** settings
)
3159 free_string(&(*settings
)->type
);
3161 free_wordlist(&(*settings
)->args
);
3169 parse_removalpolicy(RemovalPolicySettings
** settings
)
3172 free_removalpolicy(settings
);
3174 *settings
= new RemovalPolicySettings
;
3176 parse_string(&(*settings
)->type
);
3178 parse_wordlist(&(*settings
)->args
);
3182 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3185 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3186 args
= settings
->args
;
3189 storeAppendPrintf(entry
, " %s", args
->key
);
3193 storeAppendPrintf(entry
, "\n");
3197 free_memcachemode(SquidConfig
* config
)
3203 parse_memcachemode(SquidConfig
* config
)
3205 char *token
= strtok(NULL
, w_space
);
3209 if (strcmp(token
, "always") == 0) {
3210 Config
.onoff
.memory_cache_first
= 1;
3211 Config
.onoff
.memory_cache_disk
= 1;
3212 } else if (strcmp(token
, "disk") == 0) {
3213 Config
.onoff
.memory_cache_first
= 0;
3214 Config
.onoff
.memory_cache_disk
= 1;
3215 } else if (strncmp(token
, "net", 3) == 0) {
3216 Config
.onoff
.memory_cache_first
= 1;
3217 Config
.onoff
.memory_cache_disk
= 0;
3218 } else if (strcmp(token
, "never") == 0) {
3219 Config
.onoff
.memory_cache_first
= 0;
3220 Config
.onoff
.memory_cache_disk
= 0;
3226 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3228 storeAppendPrintf(entry
, "%s ", name
);
3229 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3230 storeAppendPrintf(entry
, "always");
3231 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3232 storeAppendPrintf(entry
, "disk");
3233 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3234 storeAppendPrintf(entry
, "network");
3235 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3236 storeAppendPrintf(entry
, "none");
3237 storeAppendPrintf(entry
, "\n");
3240 #include "cf_parser.cci"
3243 parseNeighborType(const char *s
)
3245 if (!strcasecmp(s
, "parent"))
3248 if (!strcasecmp(s
, "neighbor"))
3249 return PEER_SIBLING
;
3251 if (!strcasecmp(s
, "neighbour"))
3252 return PEER_SIBLING
;
3254 if (!strcasecmp(s
, "sibling"))
3255 return PEER_SIBLING
;
3257 if (!strcasecmp(s
, "multicast"))
3258 return PEER_MULTICAST
;
3260 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3262 return PEER_SIBLING
;
3267 parse_IpAddress_list(Ip::Address_list
** head
)
3270 Ip::Address_list
*s
;
3273 while ((token
= strtok(NULL
, w_space
))) {
3274 if (GetHostWithPort(token
, &ipa
)) {
3277 head
= &(*head
)->next
;
3279 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3289 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3291 char ntoabuf
[MAX_IPSTRLEN
];
3294 storeAppendPrintf(e
, "%s %s\n",
3296 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3302 free_IpAddress_list(Ip::Address_list
** head
)
3304 if (*head
) delete *head
;
3308 #if CURRENTLY_UNUSED
3309 /* This code was previously used by http_port. Left as it really should
3310 * be used by icp_port and htcp_port
3313 check_null_IpAddress_list(const Ip::Address_list
* s
)
3318 #endif /* CURRENTLY_UNUSED */
3319 #endif /* USE_WCCPv2 */
3321 CBDATA_CLASS_INIT(http_port_list
);
3324 parse_http_port_specification(http_port_list
* s
, char *token
)
3327 unsigned short port
= 0;
3331 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3332 s
->name
= xstrdup(token
);
3333 s
->connection_auth_disabled
= false;
3335 if (*token
== '[') {
3338 t
= strchr(host
, ']');
3340 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
3345 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
3348 if (!Ip::EnableIpv6
) {
3349 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 is not available.");
3352 port
= xatos(t
+ 1);
3353 } else if ((t
= strchr(token
, ':'))) {
3358 port
= xatos(t
+ 1);
3360 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3362 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3364 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3369 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3376 if (!Ip::EnableIpv6
)
3378 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3379 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
3381 if (!Ip::EnableIpv6
)
3383 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3384 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3385 /* dont use ipcache */
3386 s
->defaultsite
= xstrdup(host
);
3388 if (!Ip::EnableIpv6
)
3390 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3392 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3398 parse_http_port_option(http_port_list
* s
, char *token
)
3402 if (strcmp(token
, "accel") == 0) {
3403 if (s
->intercepted
|| s
->spoof_client_ip
) {
3404 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3408 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3409 if (s
->accel
|| s
->spoof_client_ip
) {
3410 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3414 Ip::Interceptor
.StartInterception();
3415 /* Log information regarding the port modes under interception. */
3416 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3417 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3419 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3421 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3422 if ( !s
->s
.SetIPv4() ) {
3423 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3426 } else if (strcmp(token
, "tproxy") == 0) {
3427 if (s
->intercepted
|| s
->accel
) {
3428 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3431 s
->spoof_client_ip
= 1;
3432 Ip::Interceptor
.StartTransparency();
3433 /* Log information regarding the port modes under transparency. */
3434 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3435 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3437 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3438 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3442 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3444 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3447 safe_free(s
->defaultsite
);
3448 s
->defaultsite
= xstrdup(token
+ 12);
3449 } else if (strcmp(token
, "vhost") == 0) {
3451 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vhost option requires Acceleration mode flag.");
3455 } else if (strcmp(token
, "vport") == 0) {
3457 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3461 } else if (strncmp(token
, "vport=", 6) == 0) {
3463 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3466 s
->vport
= xatos(token
+ 6);
3467 } else if (strncmp(token
, "protocol=", 9) == 0) {
3469 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3472 s
->protocol
= xstrdup(token
+ 9);
3473 } else if (strcmp(token
, "allow-direct") == 0) {
3475 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3478 s
->allow_direct
= 1;
3479 } else if (strcmp(token
, "ignore-cc") == 0) {
3480 #if !USE_HTTP_VIOLATIONS
3482 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3487 } else if (strncmp(token
, "name=", 5) == 0) {
3489 s
->name
= xstrdup(token
+ 5);
3490 } else if (strcmp(token
, "no-connection-auth") == 0) {
3491 s
->connection_auth_disabled
= true;
3492 } else if (strcmp(token
, "connection-auth=off") == 0) {
3493 s
->connection_auth_disabled
= true;
3494 } else if (strcmp(token
, "connection-auth") == 0) {
3495 s
->connection_auth_disabled
= false;
3496 } else if (strcmp(token
, "connection-auth=on") == 0) {
3497 s
->connection_auth_disabled
= false;
3498 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3499 if (!strcasecmp(token
+ 23, "off"))
3500 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3501 else if (!strcasecmp(token
+ 23, "transparent"))
3502 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3503 else if (!strcasecmp(token
+ 23, "always"))
3504 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3507 } else if (strcmp(token
, "ipv4") == 0) {
3508 if ( !s
->s
.SetIPv4() ) {
3509 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3512 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3513 s
->tcp_keepalive
.enabled
= 1;
3514 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3515 char *t
= token
+ 13;
3516 s
->tcp_keepalive
.enabled
= 1;
3517 s
->tcp_keepalive
.idle
= atoi(t
);
3521 s
->tcp_keepalive
.interval
= atoi(t
);
3526 s
->tcp_keepalive
.timeout
= atoi(t
);
3530 } else if (strcasecmp(token
, "sslBump") == 0) {
3531 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3532 "in http_port. Use 'ssl-bump' instead.");
3533 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3534 } else if (strcmp(token
, "ssl-bump") == 0) {
3535 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3536 } else if (strncmp(token
, "cert=", 5) == 0) {
3538 s
->cert
= xstrdup(token
+ 5);
3539 } else if (strncmp(token
, "key=", 4) == 0) {
3541 s
->key
= xstrdup(token
+ 4);
3542 } else if (strncmp(token
, "version=", 8) == 0) {
3543 s
->version
= xatoi(token
+ 8);
3544 if (s
->version
< 1 || s
->version
> 4)
3546 } else if (strncmp(token
, "options=", 8) == 0) {
3547 safe_free(s
->options
);
3548 s
->options
= xstrdup(token
+ 8);
3549 } else if (strncmp(token
, "cipher=", 7) == 0) {
3550 safe_free(s
->cipher
);
3551 s
->cipher
= xstrdup(token
+ 7);
3552 } else if (strncmp(token
, "clientca=", 9) == 0) {
3553 safe_free(s
->clientca
);
3554 s
->clientca
= xstrdup(token
+ 9);
3555 } else if (strncmp(token
, "cafile=", 7) == 0) {
3556 safe_free(s
->cafile
);
3557 s
->cafile
= xstrdup(token
+ 7);
3558 } else if (strncmp(token
, "capath=", 7) == 0) {
3559 safe_free(s
->capath
);
3560 s
->capath
= xstrdup(token
+ 7);
3561 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3562 safe_free(s
->crlfile
);
3563 s
->crlfile
= xstrdup(token
+ 8);
3564 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3565 safe_free(s
->dhfile
);
3566 s
->dhfile
= xstrdup(token
+ 9);
3567 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3568 safe_free(s
->sslflags
);
3569 s
->sslflags
= xstrdup(token
+ 9);
3570 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3571 safe_free(s
->sslcontext
);
3572 s
->sslcontext
= xstrdup(token
+ 11);
3579 static http_port_list
*
3580 create_http_port(char *portspec
)
3582 http_port_list
*s
= new http_port_list("http");
3583 parse_http_port_specification(s
, portspec
);
3588 add_http_port(char *portspec
)
3590 http_port_list
*s
= create_http_port(portspec
);
3591 // we may need to merge better of the above returns a list with clones
3592 assert(s
->next
== NULL
);
3593 s
->next
= Config
.Sockaddr
.http
;
3594 Config
.Sockaddr
.http
= s
;
3598 clone_http_port_list(http_port_list
*a
)
3600 http_port_list
*b
= new http_port_list(a
->protocol
);
3604 b
->name
= xstrdup(a
->name
);
3606 b
->defaultsite
= xstrdup(a
->defaultsite
);
3608 b
->intercepted
= a
->intercepted
;
3609 b
->spoof_client_ip
= a
->spoof_client_ip
;
3610 b
->accel
= a
->accel
;
3611 b
->allow_direct
= a
->allow_direct
;
3612 b
->vhost
= a
->vhost
;
3613 b
->sslBump
= a
->sslBump
;
3614 b
->vport
= a
->vport
;
3615 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3616 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3618 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3621 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3624 // XXX: temporary hack to ease move of SSL options to http_port
3625 http_port_list
&http
;
3639 SSL_CTX
*sslContext
;
3648 parse_http_port_list(http_port_list
** head
)
3650 char *token
= strtok(NULL
, w_space
);
3657 http_port_list
*s
= create_http_port(token
);
3659 /* parse options ... */
3660 while ((token
= strtok(NULL
, w_space
))) {
3661 parse_http_port_option(s
, token
);
3664 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3665 // clone the port options from *s to *(s->next)
3666 s
->next
= clone_http_port_list(s
);
3667 s
->next
->s
.SetIPv4();
3668 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3672 head
= &(*head
)->next
;
3678 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3680 char buf
[MAX_IPSTRLEN
];
3682 storeAppendPrintf(e
, "%s %s",
3684 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3687 storeAppendPrintf(e
, " intercept");
3689 if (s
->spoof_client_ip
)
3690 storeAppendPrintf(e
, " tproxy");
3693 storeAppendPrintf(e
, " accel");
3696 storeAppendPrintf(e
, " vhost");
3699 storeAppendPrintf(e
, " vport");
3702 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3704 if (s
->connection_auth_disabled
)
3705 storeAppendPrintf(e
, " connection-auth=off");
3707 storeAppendPrintf(e
, " connection-auth=on");
3709 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3712 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3715 pmtu
= "transparent";
3717 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3720 if (s
->tcp_keepalive
.enabled
) {
3721 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3722 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3724 storeAppendPrintf(e
, " tcpkeepalive");
3730 storeAppendPrintf(e
, " sslBump");
3733 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3736 storeAppendPrintf(e
, " key=%s", s
->key
);
3739 storeAppendPrintf(e
, " version=%d", s
->version
);
3742 storeAppendPrintf(e
, " options=%s", s
->options
);
3745 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3748 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3751 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3754 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3757 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3760 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3763 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3768 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3771 dump_generic_http_port(e
, n
, s
);
3772 storeAppendPrintf(e
, "\n");
3778 free_http_port_list(http_port_list
** head
)
3782 while ((s
= *head
) != NULL
) {
3790 // TODO: merge better with parse_http_port_list
3792 parse_https_port_list(https_port_list
** head
)
3797 token
= strtok(NULL
, w_space
);
3802 s
= new https_port_list
;
3803 parse_http_port_specification(&s
->http
, token
);
3805 /* parse options ... */
3806 while ((token
= strtok(NULL
, w_space
))) {
3807 parse_http_port_option(s
, token
);
3811 http_port_list
** headTmp
= &(*head
)->http
.next
;
3812 head
= (https_port_list
**)headTmp
;
3819 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3821 dump_http_port_list(e
, n
, s
);
3825 free_https_port_list(https_port_list
** head
)
3827 free_http_port_list((http_port_list
**)head
);
3832 check_null_https_port_list(const https_port_list
* s
)
3839 #endif /* USE_SSL */
3842 configFreeMemory(void)
3848 requirePathnameExists(const char *name
, const char *path
)
3852 char pathbuf
[BUFSIZ
];
3853 assert(path
!= NULL
);
3855 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3856 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3860 if (stat(path
, &sb
) < 0) {
3861 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3862 fatalf("%s %s: %s", name
, path
, xstrerror());
3864 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3871 return ConfigParser::strtokFile();
3874 #include "AccessLogEntry.h"
3875 /* TODO: split out parsing somehow ...*/
3877 parse_logformat(logformat
** logformat_definitions
)
3882 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3885 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3890 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3892 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3894 nlf
->name
= xstrdup(name
);
3896 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3901 nlf
->next
= *logformat_definitions
;
3903 *logformat_definitions
= nlf
;
3907 parse_access_log(customlog
** logs
)
3909 const char *filename
, *logdef_name
;
3913 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3915 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3920 if (strcmp(filename
, "none") == 0) {
3921 cl
->type
= CLF_NONE
;
3925 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3926 logdef_name
= "auto";
3928 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3930 cl
->filename
= xstrdup(filename
);
3932 /* look for the definition pointer corresponding to this name */
3933 lf
= Config
.Log
.logformats
;
3935 while (lf
!= NULL
) {
3936 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3938 if (strcmp(lf
->name
, logdef_name
) == 0)
3945 cl
->type
= CLF_CUSTOM
;
3947 } else if (strcmp(logdef_name
, "auto") == 0) {
3948 cl
->type
= CLF_AUTO
;
3949 } else if (strcmp(logdef_name
, "squid") == 0) {
3950 cl
->type
= CLF_SQUID
;
3951 } else if (strcmp(logdef_name
, "common") == 0) {
3952 cl
->type
= CLF_COMMON
;
3954 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
3955 cl
->type
= CLF_ICAP_SQUID
;
3958 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3964 aclParseAclList(LegacyParser
, &cl
->aclList
);
3967 logs
= &(*logs
)->next
;
3973 check_null_access_log(customlog
*customlog_definitions
)
3975 return customlog_definitions
== NULL
;
3979 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3981 accessLogDumpLogFormat(entry
, name
, definitions
);
3985 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3989 for (log
= logs
; log
; log
= log
->next
) {
3990 storeAppendPrintf(entry
, "%s ", name
);
3992 switch (log
->type
) {
3995 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3999 storeAppendPrintf(entry
, "none");
4003 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4007 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4010 case CLF_ICAP_SQUID
:
4011 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4017 storeAppendPrintf(entry
, "%s auto", log
->filename
);
4019 storeAppendPrintf(entry
, "%s", log
->filename
);
4028 dump_acl_list(entry
, log
->aclList
);
4030 storeAppendPrintf(entry
, "\n");
4035 free_logformat(logformat
** definitions
)
4037 while (*definitions
) {
4038 logformat
*format
= *definitions
;
4039 *definitions
= format
->next
;
4040 safe_free(format
->name
);
4041 accessLogFreeLogFormat(&format
->format
);
4047 free_access_log(customlog
** definitions
)
4049 while (*definitions
) {
4050 customlog
*log
= *definitions
;
4051 *definitions
= log
->next
;
4053 log
->logFormat
= NULL
;
4054 log
->type
= CLF_UNKNOWN
;
4057 aclDestroyAclList(&log
->aclList
);
4059 safe_free(log
->filename
);
4065 /// parses list of integers form name=N1,N2,N3,...
4067 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4069 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4070 data
+= name
.size();
4075 if (!StringToInt(data
, value
, &data
, 10))
4077 list
.push_back(value
);
4078 if (*data
== '\0' || *data
!= ',')
4083 return data
&& *data
== '\0';
4087 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4089 #if !HAVE_CPU_AFFINITY
4090 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4091 "support, do not set 'cpu_affinity_map'");
4093 #endif /* HAVE_CPU_AFFINITY */
4095 if (!*cpuAffinityMap
)
4096 *cpuAffinityMap
= new CpuAffinityMap
;
4098 const char *const pToken
= strtok(NULL
, w_space
);
4099 const char *const cToken
= strtok(NULL
, w_space
);
4100 Vector
<int> processes
, cores
;
4101 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4102 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4103 "in 'cpu_affinity_map'");
4105 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4106 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4107 "'cpu_affinity_map'");
4109 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4110 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4111 "process_numbers and cores lists differ in length or " <<
4112 "contain numbers <= 0");
4118 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4120 if (cpuAffinityMap
) {
4121 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4122 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4123 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4124 cpuAffinityMap
->processes()[i
]);
4126 storeAppendPrintf(entry
, " cores=");
4127 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4128 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4129 cpuAffinityMap
->cores()[i
]);
4131 storeAppendPrintf(entry
, "\n");
4136 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4138 delete *cpuAffinityMap
;
4139 *cpuAffinityMap
= NULL
;
4145 parse_adaptation_service_set_type()
4147 Adaptation::Config::ParseServiceSet();
4151 parse_adaptation_service_chain_type()
4153 Adaptation::Config::ParseServiceChain();
4157 parse_adaptation_access_type()
4159 Adaptation::Config::ParseAccess(LegacyParser
);
4162 #endif /* USE_ADAPTATION */
4168 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4170 cfg
->parseService();
4174 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4180 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4182 cfg
.dumpService(entry
, name
);
4186 parse_icap_class_type()
4188 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
4189 "Use 'adaptation_service_set' instead");
4190 Adaptation::Config::ParseServiceSet();
4194 parse_icap_access_type()
4196 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
4197 "Use 'adaptation_access' instead");
4198 Adaptation::Config::ParseAccess(LegacyParser
);
4207 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4209 cfg
->parseService();
4213 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4219 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4221 cfg
.dumpService(entry
, name
);
4224 #endif /* USE_ECAP */
4227 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4232 cfg
->service_failure_limit
= GetInteger();
4234 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4237 if (strcmp(token
,"in") != 0) {
4238 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
4242 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4246 d
= static_cast<time_t> (xatoi(token
));
4248 m
= static_cast<time_t> (1);
4252 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4253 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
4255 } else if ((m
= parseTimeUnits(token
)) == 0)
4258 cfg
->oldest_service_failure
= (m
* d
);
4261 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4263 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4264 if (cfg
.oldest_service_failure
> 0) {
4265 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4267 storeAppendPrintf(entry
, "\n");
4270 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4272 cfg
->oldest_service_failure
= 0;
4273 cfg
->service_failure_limit
= 0;