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"
50 #include "ssl/support.h"
51 #include "ssl/Config.h"
54 #include "auth/Config.h"
55 #include "auth/Scheme.h"
57 #include "ConfigParser.h"
58 #include "CpuAffinityMap.h"
59 #include "eui/Config.h"
61 #include "esi/Parser.h"
63 #include "HttpRequestMethod.h"
64 #include "ident/Config.h"
65 #include "ip/Intercept.h"
66 #include "ip/QosConfig.h"
68 #include "log/Config.h"
70 #include "mgr/Registration.h"
72 #include "ProtoPort.h"
78 #include "StoreFileSystem.h"
92 #include "ssl/gadgets.h"
96 static void parse_adaptation_service_set_type();
97 static void parse_adaptation_service_chain_type();
98 static void parse_adaptation_access_type();
102 static void parse_icap_service_type(Adaptation::Icap::Config
*);
103 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
104 static void free_icap_service_type(Adaptation::Icap::Config
*);
105 static void parse_icap_class_type();
106 static void parse_icap_access_type();
108 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
109 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
110 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
114 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
115 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
116 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
121 static const char *const T_MILLISECOND_STR
= "millisecond";
122 static const char *const T_SECOND_STR
= "second";
123 static const char *const T_MINUTE_STR
= "minute";
124 static const char *const T_HOUR_STR
= "hour";
125 static const char *const T_DAY_STR
= "day";
126 static const char *const T_WEEK_STR
= "week";
127 static const char *const T_FORTNIGHT_STR
= "fortnight";
128 static const char *const T_MONTH_STR
= "month";
129 static const char *const T_YEAR_STR
= "year";
130 static const char *const T_DECADE_STR
= "decade";
132 static const char *const B_BYTES_STR
= "bytes";
133 static const char *const B_KBYTES_STR
= "KB";
134 static const char *const B_MBYTES_STR
= "MB";
135 static const char *const B_GBYTES_STR
= "GB";
137 static const char *const list_sep
= ", \t\n\r";
139 static void parse_access_log(customlog
** customlog_definitions
);
140 static int check_null_access_log(customlog
*customlog_definitions
);
141 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
142 static void free_access_log(customlog
** definitions
);
144 static void update_maxobjsize(void);
145 static void configDoConfigure(void);
146 static void parse_refreshpattern(refresh_t
**);
147 static uint64_t parseTimeUnits(const char *unit
);
148 static void parseTimeLine(time_msec_t
* tptr
, const char *units
);
149 static void parse_ushort(u_short
* var
);
150 static void parse_string(char **);
151 static void default_all(void);
152 static void defaults_if_none(void);
153 static int parse_line(char *);
154 static void parse_obsolete(const char *);
155 static void parseBytesLine(size_t * bptr
, const char *units
);
157 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
160 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
162 static size_t parseBytesUnits(const char *unit
);
163 static void free_all(void);
164 void requirePathnameExists(const char *name
, const char *path
);
165 static OBJH dump_config
;
166 #if USE_HTTP_VIOLATIONS
167 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
168 static void parse_http_header_access(header_mangler header
[]);
169 static void free_http_header_access(header_mangler header
[]);
170 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
171 static void parse_http_header_replace(header_mangler
* header
);
172 static void free_http_header_replace(header_mangler
* header
);
174 static void parse_denyinfo(acl_deny_info_list
** var
);
175 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
176 static void free_denyinfo(acl_deny_info_list
** var
);
179 static void parse_IpAddress_list(Ip::Address_list
**);
180 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
181 static void free_IpAddress_list(Ip::Address_list
**);
183 static int check_null_IpAddress_list(const Ip::Address_list
*);
184 #endif /* CURRENTLY_UNUSED */
185 #endif /* USE_WCCPv2 */
187 static void parse_http_port_list(http_port_list
**);
188 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
189 static void free_http_port_list(http_port_list
**);
192 static void parse_https_port_list(https_port_list
**);
193 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
194 static void free_https_port_list(https_port_list
**);
196 static int check_null_https_port_list(const https_port_list
*);
200 static void parse_b_size_t(size_t * var
);
201 static void parse_b_int64_t(int64_t * var
);
203 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
205 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
206 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
207 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
209 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
212 * LegacyParser is a parser for legacy code that uses the global
213 * approach. This is static so that it is only exposed to cache_cf.
214 * Other modules needing access to a ConfigParser should have it
215 * provided to them in their parserFOO methods.
217 static ConfigParser LegacyParser
= ConfigParser();
222 LegacyParser
.destruct();
226 update_maxobjsize(void)
231 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
232 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
234 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
236 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
238 store_maxobjsize
= ms
;
242 SetConfigFilename(char const *file_name
, bool is_pipe
)
244 cfg_filename
= file_name
;
249 cfg_filename
= file_name
+ 1;
250 else if ((token
= strrchr(cfg_filename
, '/')))
251 cfg_filename
= token
+ 1;
255 skip_ws(const char* s
)
264 parseManyConfigFiles(char* files
, int depth
)
267 char* saveptr
= NULL
;
272 memset(&globbuf
, 0, sizeof(globbuf
));
273 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
274 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
275 fatalf("Unable to find configuration file: %s: %s",
279 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
280 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
284 char* file
= strwordtok(files
, &saveptr
);
285 while (file
!= NULL
) {
286 error_count
+= parseOneConfigFile(file
, depth
);
287 file
= strwordtok(NULL
, &saveptr
);
289 #endif /* HAVE_GLOB */
294 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
297 assert(newSubstr
!= NULL
);
299 unsigned newSubstrLen
= strlen(newSubstr
);
300 if (newSubstrLen
> substrLen
)
301 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
303 // move tail part including zero
304 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
305 // copy new substring in place
306 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
312 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
314 assert(line
!= NULL
);
315 assert(macroName
!= NULL
);
316 assert(substStr
!= NULL
);
317 unsigned macroNameLen
= strlen(macroName
);
318 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
319 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
323 ProcessMacros(char*& line
, int& len
)
325 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
326 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
330 trim_trailing_ws(char* str
)
333 unsigned i
= strlen(str
);
334 while ((i
> 0) && xisspace(str
[i
- 1]))
340 FindStatement(const char* line
, const char* statement
)
342 assert(line
!= NULL
);
343 assert(statement
!= NULL
);
345 const char* str
= skip_ws(line
);
346 unsigned len
= strlen(statement
);
347 if (strncmp(str
, statement
, len
) == 0) {
351 else if (xisspace(*str
))
359 StrToInt(const char* str
, long& number
)
364 number
= strtol(str
, &end
, 0);
366 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
370 EvalBoolExpr(const char* expr
)
372 assert(expr
!= NULL
);
373 if (strcmp(expr
, "true") == 0) {
375 } else if (strcmp(expr
, "false") == 0) {
377 } else if (const char* equation
= strchr(expr
, '=')) {
378 const char* rvalue
= skip_ws(equation
+ 1);
379 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
380 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
381 trim_trailing_ws(lvalue
);
384 if (!StrToInt(lvalue
, number1
))
385 fatalf("String is not a integer number: '%s'\n", lvalue
);
387 if (!StrToInt(rvalue
, number2
))
388 fatalf("String is not a integer number: '%s'\n", rvalue
);
391 return number1
== number2
;
393 fatalf("Unable to evaluate expression '%s'\n", expr
);
394 return false; // this place cannot be reached
398 parseOneConfigFile(const char *file_name
, unsigned int depth
)
401 const char *orig_cfg_filename
= cfg_filename
;
402 const int orig_config_lineno
= config_lineno
;
404 char *tmp_line
= NULL
;
405 int tmp_line_len
= 0;
409 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
411 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
415 if (file_name
[0] == '!' || file_name
[0] == '|') {
416 fp
= popen(file_name
+ 1, "r");
419 fp
= fopen(file_name
, "r");
423 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
426 setmode(fileno(fp
), O_TEXT
);
429 SetConfigFilename(file_name
, bool(is_pipe
));
431 memset(config_input_line
, '\0', BUFSIZ
);
435 Vector
<bool> if_states
;
436 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
439 if ((token
= strchr(config_input_line
, '\n')))
442 if ((token
= strchr(config_input_line
, '\r')))
445 if (strncmp(config_input_line
, "#line ", 6) == 0) {
446 static char new_file_name
[1024];
448 static char new_lineno
;
449 token
= config_input_line
+ 6;
450 new_lineno
= strtol(token
, &file
, 0) - 1;
453 continue; /* Not a valid #line directive, may be a comment */
455 while (*file
&& xisspace((unsigned char) *file
))
460 continue; /* Not a valid #line directive, may be a comment */
462 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
464 if ((token
= strchr(new_file_name
, '"')))
467 cfg_filename
= new_file_name
;
470 config_lineno
= new_lineno
;
473 if (config_input_line
[0] == '#')
476 if (config_input_line
[0] == '\0')
479 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
481 size_t append_len
= strlen(append
);
483 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
485 strcpy(tmp_line
+ tmp_line_len
, append
);
487 tmp_line_len
+= append_len
;
489 if (tmp_line
[tmp_line_len
-1] == '\\') {
490 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
491 tmp_line
[--tmp_line_len
] = '\0';
495 trim_trailing_ws(tmp_line
);
496 ProcessMacros(tmp_line
, tmp_line_len
);
497 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
499 if (const char* expr
= FindStatement(tmp_line
, "if")) {
500 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
501 } else if (FindStatement(tmp_line
, "endif")) {
502 if (!if_states
.empty())
503 if_states
.pop_back(); // remove last if-statement meaning
505 fatalf("'endif' without 'if'\n");
506 } else if (FindStatement(tmp_line
, "else")) {
507 if (!if_states
.empty())
508 if_states
.back() = !if_states
.back();
510 fatalf("'else' without 'if'\n");
511 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
512 /* Handle includes here */
513 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
514 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
515 } else if (!parse_line(tmp_line
)) {
516 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
525 if (!if_states
.empty())
526 fatalf("if-statement without 'endif'\n");
529 int ret
= pclose(fp
);
532 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
537 cfg_filename
= orig_cfg_filename
;
538 config_lineno
= orig_config_lineno
;
544 parseConfigFile(const char *file_name
)
552 ACLMethodData::ThePurgeCount
= 0;
555 err_count
= parseOneConfigFile(file_name
, 0);
560 * We must call configDoConfigure() before leave_suid() because
561 * configDoConfigure() is where we turn username strings into
566 if (!Config
.chroot_dir
) {
568 setUmask(Config
.umask
);
569 _db_init(Debug::cache_log
, Debug::debugOptions
);
573 if (opt_send_signal
== -1) {
574 Mgr::RegisterAction("config",
575 "Current Squid Configuration",
585 configDoConfigure(void)
587 memset(&Config2
, '\0', sizeof(SquidConfig2
));
588 /* init memory as early as possible */
592 if (Config
.cacheSwap
.swapDirs
== NULL
) {
593 /* Memory-only cache probably in effect. */
594 /* turn off the cache rebuild delays... */
595 StoreController::store_dirs_rebuilding
= 0;
598 if (Debug::rotateNumber
< 0) {
599 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
602 #if SIZEOF_OFF_T <= 4
603 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
604 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
605 Config
.Store
.maxObjectSize
= 0x7FFF0000;
608 if (0 == Store::Root().maxSize())
609 /* people might want a zero-sized cache on purpose */
611 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
612 /* This is bogus. folk with NULL caches will want this */
613 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
615 if (Config
.Announce
.period
> 0) {
616 Config
.onoff
.announce
= 1;
617 } else if (Config
.Announce
.period
< 1) {
618 Config
.Announce
.period
= 86400 * 365; /* one year */
619 Config
.onoff
.announce
= 0;
622 if (Config
.onoff
.httpd_suppress_version_string
)
623 visible_appname_string
= (char *)appname_string
;
625 visible_appname_string
= (char const *)APP_FULLNAME
;
629 if (Config
.dnsChildren
.n_max
< 1)
630 fatal("No dnsservers allocated");
634 if (Config
.Program
.redirect
) {
635 if (Config
.redirectChildren
.n_max
< 1) {
636 Config
.redirectChildren
.n_max
= 0;
637 wordlistDestroy(&Config
.Program
.redirect
);
641 if (Config
.appendDomain
)
642 if (*Config
.appendDomain
!= '.')
643 fatal("append_domain must begin with a '.'");
645 if (Config
.errHtmlText
== NULL
)
646 Config
.errHtmlText
= xstrdup(null_string
);
650 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
652 visible_appname_string
);
655 * the extra space is for loop detection in client_side.c -- we search
656 * for substrings in the Via header.
658 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
660 visible_appname_string
);
662 /* Use visible_hostname as default surrogate_id */
663 if (!Config
.Accel
.surrogate_id
) {
664 const char *t
= getMyHostname();
665 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
668 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
669 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
671 if (Config
.appendDomain
)
672 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
674 Config
.appendDomainLen
= 0;
676 if (Config
.retry
.maxtries
> 10)
677 fatal("maximum_single_addr_tries cannot be larger than 10");
679 if (Config
.retry
.maxtries
< 1) {
680 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
681 Config
.retry
.maxtries
= 1;
684 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
687 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
691 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
693 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
694 if (Config
.Program
.redirect
)
695 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
697 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
699 if (Config
.errorDirectory
)
700 requirePathnameExists("Error Directory", Config
.errorDirectory
);
702 #if USE_HTTP_VIOLATIONS
707 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
708 if (!R
->flags
.override_expire
)
711 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
716 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
717 if (!R
->flags
.override_lastmod
)
720 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
725 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
726 if (!R
->flags
.reload_into_ims
)
729 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
734 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
735 if (!R
->flags
.ignore_reload
)
738 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
743 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
744 if (!R
->flags
.ignore_no_cache
)
747 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
752 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
753 if (!R
->flags
.ignore_no_store
)
756 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
761 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
762 if (!R
->flags
.ignore_must_revalidate
)
764 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
768 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
769 if (!R
->flags
.ignore_private
)
772 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
777 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
778 if (!R
->flags
.ignore_auth
)
781 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
788 #if !USE_HTTP_VIOLATIONS
789 Config
.onoff
.via
= 1;
792 if (!Config
.onoff
.via
)
793 debugs(22, 1, "WARNING: HTTP requires the use of Via");
797 // we enable runtime PURGE checks if there is at least one PURGE method ACL
798 // TODO: replace with a dedicated "purge" ACL option?
799 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
801 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
803 if (geteuid() == 0) {
804 if (NULL
!= Config
.effectiveUser
) {
806 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
810 * Andres Kroonmaa <andre@online.ee>:
811 * Some getpwnam() implementations (Solaris?) require
812 * an available FD < 256 for opening a FILE* to the
815 * This should be safe at startup, but might still fail
816 * during reconfigure.
818 fatalf("getpwnam failed to find userid for effective user '%s'",
819 Config
.effectiveUser
);
823 Config2
.effectiveUserID
= pwd
->pw_uid
;
825 Config2
.effectiveGroupID
= pwd
->pw_gid
;
829 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
831 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
832 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
840 Config2
.effectiveUserID
= geteuid();
841 Config2
.effectiveGroupID
= getegid();
844 if (NULL
!= Config
.effectiveGroup
) {
846 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
849 fatalf("getgrnam failed to find groupid for effective group '%s'",
850 Config
.effectiveGroup
);
854 Config2
.effectiveGroupID
= grp
->gr_gid
;
857 HttpRequestMethod::Configure(Config
);
860 debugs(3, 1, "Initializing https proxy context");
862 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
);
868 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
870 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
871 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
880 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
881 if (!s
->cert
&& !s
->key
)
884 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
886 s
->staticSslContext
.reset(
887 sslCreateServerContext(s
->cert
, s
->key
,
888 s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
,
889 s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
,
890 s
->sslContextSessionId
));
892 Ssl::readCertAndPrivateKeyFromFiles(s
->signingCert
, s
->signPkey
, s
->cert
, s
->key
);
900 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
901 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
903 s
->staticSslContext
.reset(
904 sslCreateServerContext(s
->cert
, s
->key
,
905 s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
,
906 s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
,
907 s
->sslContextSessionId
));
913 // prevent infinite fetch loops in the request parser
914 // due to buffer full but not enough data recived to finish parse
915 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
916 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
917 " Change client_request_buffer_max or request_header_max_size limits.",
918 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
923 * disable client side request pipelining. There is a race with
924 * Negotiate and NTLM when the client sends a second request on an
925 * connection before the authenticate challenge is sent. With
926 * pipelining OFF, the client may fail to authenticate, but squid's
927 * state will be preserved.
929 if (Config
.onoff
.pipeline_prefetch
) {
930 AuthConfig
*nego
= AuthConfig::Find("Negotiate");
931 AuthConfig
*ntlm
= AuthConfig::Find("NTLM");
932 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
933 debugs(3, DBG_IMPORTANT
, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
934 Config
.onoff
.pipeline_prefetch
= 0;
940 /** Parse a line containing an obsolete directive.
941 * To upgrade it where possible instead of just "Bungled config" for
942 * directives which cannot be marked as simply aliases of the some name.
943 * For example if the parameter order and content has changed.
944 * Or if the directive has been completely removed.
947 parse_obsolete(const char *name
)
949 // Directives which have been radically changed rather than removed
950 if (!strcmp(name
, "url_rewrite_concurrency")) {
953 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
954 Config
.redirectChildren
.concurrency
= cval
;
958 /* Parse a time specification from the config file. Store the
959 * result in 'tptr', after converting it to 'units' */
961 parseTimeLine(time_msec_t
* tptr
, const char *units
)
968 if ((u
= parseTimeUnits(units
)) == 0)
971 if ((token
= strtok(NULL
, w_space
)) == NULL
)
976 m
= u
; /* default to 'units' if none specified */
980 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
981 debugs(3, 0, "WARNING: No units on '" <<
982 config_input_line
<< "', assuming " <<
984 else if ((m
= parseTimeUnits(token
)) == 0)
987 *tptr
= static_cast<time_msec_t
>(m
* d
);
991 parseTimeUnits(const char *unit
)
993 if (!strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
996 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
999 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1002 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1005 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1006 return 86400 * 1000;
1008 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1009 return 86400 * 7 * 1000;
1011 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1012 return 86400 * 14 * 1000;
1014 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1015 return static_cast<uint64_t>(86400) * 30 * 1000;
1017 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1018 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1020 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1021 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1023 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1029 parseBytesLine64(int64_t * bptr
, const char *units
)
1036 if ((u
= parseBytesUnits(units
)) == 0) {
1041 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1046 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1053 m
= u
; /* default to 'units' if none specified */
1057 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1058 debugs(3, 0, "WARNING: No units on '" <<
1059 config_input_line
<< "', assuming " <<
1060 d
<< " " << units
);
1061 else if ((m
= parseBytesUnits(token
)) == 0) {
1066 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1068 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1074 parseBytesLine(size_t * bptr
, const char *units
)
1081 if ((u
= parseBytesUnits(units
)) == 0) {
1086 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1091 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1092 *bptr
= static_cast<size_t>(-1);
1098 m
= u
; /* default to 'units' if none specified */
1102 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1103 debugs(3, 0, "WARNING: No units on '" <<
1104 config_input_line
<< "', assuming " <<
1105 d
<< " " << units
);
1106 else if ((m
= parseBytesUnits(token
)) == 0) {
1111 *bptr
= static_cast<size_t>(m
* d
/ u
);
1113 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1119 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1126 if ((u
= parseBytesUnits(units
)) == 0) {
1131 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1136 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1143 m
= u
; /* default to 'units' if none specified */
1147 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1148 debugs(3, 0, "WARNING: No units on '" <<
1149 config_input_line
<< "', assuming " <<
1150 d
<< " " << units
);
1151 else if ((m
= parseBytesUnits(token
)) == 0) {
1156 *bptr
= static_cast<size_t>(m
* d
/ u
);
1158 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1165 * Parse bytes from a string.
1166 * Similar to the parseBytesLine function but parses the string value instead of
1167 * the current token value.
1169 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1172 if ((u
= parseBytesUnits(units
)) == 0) {
1177 // Find number from string beginning.
1178 char const * number_begin
= value
;
1179 char const * number_end
= value
;
1181 while ((*number_end
>= '0' && *number_end
<= '9')) {
1186 number
.limitInit(number_begin
, number_end
- number_begin
);
1188 int d
= xatoi(number
.termedBuf());
1190 if ((m
= parseBytesUnits(number_end
)) == 0) {
1195 *bptr
= static_cast<size_t>(m
* d
/ u
);
1196 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1202 parseBytesUnits(const char *unit
)
1204 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1207 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1210 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1213 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1216 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1221 /*****************************************************************************
1223 *****************************************************************************/
1226 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1231 while (ae
!= NULL
) {
1232 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1233 storeAppendPrintf(entry
, "%s %s %s ",
1240 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1241 storeAppendPrintf(entry
, "%s ", v
->key
);
1245 storeAppendPrintf(entry
, "\n");
1246 wordlistDestroy(&w
);
1252 parse_acl(ACL
** ae
)
1254 ACL::ParseAclLine(LegacyParser
, ae
);
1264 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1268 for (l
= head
; l
; l
= l
->next
) {
1269 storeAppendPrintf(entry
, " %s%s",
1270 l
->op
? null_string
: "!",
1276 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1280 for (l
= head
; l
; l
= l
->next
) {
1281 storeAppendPrintf(entry
, "%s %s",
1283 l
->allow
? "Allow" : "Deny");
1284 dump_acl_list(entry
, l
->aclList
);
1285 storeAppendPrintf(entry
, "\n");
1290 parse_acl_access(acl_access
** head
)
1292 aclParseAccessLine(LegacyParser
, head
);
1296 free_acl_access(acl_access
** head
)
1298 aclDestroyAccessList(head
);
1302 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1304 char buf
[MAX_IPSTRLEN
];
1305 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1309 parse_address(Ip::Address
*addr
)
1311 char *token
= strtok(NULL
, w_space
);
1318 if (!strcmp(token
,"any_addr")) {
1321 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1329 free_address(Ip::Address
*addr
)
1334 CBDATA_TYPE(acl_address
);
1337 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1339 char buf
[MAX_IPSTRLEN
];
1342 for (l
= head
; l
; l
= l
->next
) {
1343 if (!l
->addr
.IsAnyAddr())
1344 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1346 storeAppendPrintf(entry
, "%s autoselect", name
);
1348 dump_acl_list(entry
, l
->aclList
);
1350 storeAppendPrintf(entry
, "\n");
1355 freed_acl_address(void *data
)
1357 acl_address
*l
= static_cast<acl_address
*>(data
);
1358 aclDestroyAclList(&l
->aclList
);
1362 parse_acl_address(acl_address
** head
)
1365 acl_address
**tail
= head
; /* sane name below */
1366 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1367 l
= cbdataAlloc(acl_address
);
1368 parse_address(&l
->addr
);
1369 aclParseAclList(LegacyParser
, &l
->aclList
);
1372 tail
= &(*tail
)->next
;
1378 free_acl_address(acl_address
** head
)
1381 acl_address
*l
= *head
;
1387 CBDATA_TYPE(acl_tos
);
1390 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1394 for (l
= head
; l
; l
= l
->next
) {
1396 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1398 storeAppendPrintf(entry
, "%s none", name
);
1400 dump_acl_list(entry
, l
->aclList
);
1402 storeAppendPrintf(entry
, "\n");
1407 freed_acl_tos(void *data
)
1409 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1410 aclDestroyAclList(&l
->aclList
);
1414 parse_acl_tos(acl_tos
** head
)
1417 acl_tos
**tail
= head
; /* sane name below */
1418 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1419 char *token
= strtok(NULL
, w_space
);
1426 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1431 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1433 l
= cbdataAlloc(acl_tos
);
1435 l
->tos
= (tos_t
)tos
;
1437 aclParseAclList(LegacyParser
, &l
->aclList
);
1440 tail
= &(*tail
)->next
;
1446 free_acl_tos(acl_tos
** head
)
1456 #if defined(SO_MARK)
1458 CBDATA_TYPE(acl_nfmark
);
1461 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1465 for (l
= head
; l
; l
= l
->next
) {
1467 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1469 storeAppendPrintf(entry
, "%s none", name
);
1471 dump_acl_list(entry
, l
->aclList
);
1473 storeAppendPrintf(entry
, "\n");
1478 freed_acl_nfmark(void *data
)
1480 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1481 aclDestroyAclList(&l
->aclList
);
1485 parse_acl_nfmark(acl_nfmark
** head
)
1488 acl_nfmark
**tail
= head
; /* sane name below */
1490 char *token
= strtok(NULL
, w_space
);
1497 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1502 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1504 l
= cbdataAlloc(acl_nfmark
);
1508 aclParseAclList(LegacyParser
, &l
->aclList
);
1511 tail
= &(*tail
)->next
;
1517 free_acl_nfmark(acl_nfmark
** head
)
1520 acl_nfmark
*l
= *head
;
1526 #endif /* SO_MARK */
1528 CBDATA_TYPE(acl_size_t
);
1531 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1535 for (l
= head
; l
; l
= l
->next
) {
1537 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1539 storeAppendPrintf(entry
, "%s none", name
);
1541 dump_acl_list(entry
, l
->aclList
);
1543 storeAppendPrintf(entry
, "\n");
1548 freed_acl_b_size_t(void *data
)
1550 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1551 aclDestroyAclList(&l
->aclList
);
1555 parse_acl_b_size_t(acl_size_t
** head
)
1558 acl_size_t
**tail
= head
; /* sane name below */
1560 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1562 l
= cbdataAlloc(acl_size_t
);
1564 parse_b_int64_t(&l
->size
);
1566 aclParseAclList(LegacyParser
, &l
->aclList
);
1569 tail
= &(*tail
)->next
;
1575 free_acl_b_size_t(acl_size_t
** head
)
1578 acl_size_t
*l
= *head
;
1587 #include "DelayPools.h"
1588 #include "DelayConfig.h"
1589 /* do nothing - free_delay_pool_count is the magic free function.
1590 * this is why delay_pool_count isn't just marked TYPE: ushort
1592 #define free_delay_pool_class(X)
1593 #define free_delay_pool_access(X)
1594 #define free_delay_pool_rates(X)
1595 #define dump_delay_pool_class(X, Y, Z)
1596 #define dump_delay_pool_access(X, Y, Z)
1597 #define dump_delay_pool_rates(X, Y, Z)
1600 free_delay_pool_count(DelayConfig
* cfg
)
1602 cfg
->freePoolCount();
1606 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1608 cfg
.dumpPoolCount (entry
, name
);
1612 parse_delay_pool_count(DelayConfig
* cfg
)
1614 cfg
->parsePoolCount();
1618 parse_delay_pool_class(DelayConfig
* cfg
)
1620 cfg
->parsePoolClass();
1624 parse_delay_pool_rates(DelayConfig
* cfg
)
1626 cfg
->parsePoolRates();
1630 parse_delay_pool_access(DelayConfig
* cfg
)
1632 cfg
->parsePoolAccess(LegacyParser
);
1638 #include "ClientDelayConfig.h"
1639 /* do nothing - free_client_delay_pool_count is the magic free function.
1640 * this is why client_delay_pool_count isn't just marked TYPE: ushort
1643 #define free_client_delay_pool_access(X)
1644 #define free_client_delay_pool_rates(X)
1645 #define dump_client_delay_pool_access(X, Y, Z)
1646 #define dump_client_delay_pool_rates(X, Y, Z)
1649 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1651 cfg
->freePoolCount();
1655 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1657 cfg
.dumpPoolCount (entry
, name
);
1661 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1663 cfg
->parsePoolCount();
1667 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1669 cfg
->parsePoolRates();
1673 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1675 cfg
->parsePoolAccess(LegacyParser
);
1679 #if USE_HTTP_VIOLATIONS
1681 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1685 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1686 if (header
[i
].access_list
!= NULL
) {
1687 storeAppendPrintf(entry
, "%s ", name
);
1688 dump_acl_access(entry
, httpHeaderNameById(i
),
1689 header
[i
].access_list
);
1695 parse_http_header_access(header_mangler header
[])
1700 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1701 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1702 debugs(3, 0, "parse_http_header_access: missing header name.");
1706 /* Now lookup index of header. */
1707 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1709 if (strcmp(t
, "All") == 0)
1711 else if (strcmp(t
, "Other") == 0)
1713 else if (id
== -1) {
1714 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1715 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1719 if (id
!= HDR_ENUM_END
) {
1720 parse_acl_access(&header
[id
].access_list
);
1722 char *next_string
= t
+ strlen(t
) - 1;
1724 *(next_string
+ 1) = ' ';
1726 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1727 char *new_string
= xstrdup(next_string
);
1728 strtok(new_string
, w_space
);
1729 parse_acl_access(&header
[i
].access_list
);
1730 safe_free(new_string
);
1736 free_http_header_access(header_mangler header
[])
1740 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1741 free_acl_access(&header
[i
].access_list
);
1746 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1751 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1752 if (NULL
== header
[i
].replacement
)
1755 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1756 header
[i
].replacement
);
1761 parse_http_header_replace(header_mangler header
[])
1766 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1767 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1768 debugs(3, 0, "parse_http_header_replace: missing header name.");
1772 /* Now lookup index of header. */
1773 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1775 if (strcmp(t
, "All") == 0)
1777 else if (strcmp(t
, "Other") == 0)
1779 else if (id
== -1) {
1780 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1781 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1786 if (id
!= HDR_ENUM_END
) {
1787 if (header
[id
].replacement
!= NULL
)
1788 safe_free(header
[id
].replacement
);
1790 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1792 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1793 if (header
[i
].replacement
!= NULL
)
1794 safe_free(header
[i
].replacement
);
1796 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1802 free_http_header_replace(header_mangler header
[])
1806 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1807 if (header
[i
].replacement
!= NULL
)
1808 safe_free(header
[i
].replacement
);
1815 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1821 for (i
= 0; i
< swap
.n_configured
; i
++) {
1822 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1824 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1826 storeAppendPrintf(entry
, "\n");
1831 check_null_string(char *s
)
1838 parse_authparam(Auth::authConfig
* config
)
1843 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1846 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1849 /* find a configuration for the scheme in the currently parsed configs... */
1850 AuthConfig
*schemeCfg
= AuthConfig::Find(type_str
);
1852 if (schemeCfg
== NULL
) {
1853 /* Create a configuration based on the scheme info */
1854 AuthScheme::Pointer theScheme
= AuthScheme::Find(type_str
);
1856 if (theScheme
== NULL
) {
1857 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1861 config
->push_back(theScheme
->createConfig());
1862 schemeCfg
= AuthConfig::Find(type_str
);
1863 if (schemeCfg
== NULL
) {
1864 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1869 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1873 free_authparam(Auth::authConfig
* cfg
)
1875 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1878 /* remove our pointers to the probably-dead sub-configs */
1879 while (cfg
->size()) {
1883 /* on reconfigure initialize new auth schemes for the new config. */
1884 if (reconfiguring
) {
1890 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1892 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1893 (*i
)->dump(entry
, name
, (*i
));
1895 #endif /* USE_AUTH */
1897 /* TODO: just return the object, the # is irrelevant */
1899 find_fstype(char *type
)
1901 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1902 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1909 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1911 // The workers option must preceed cache_dir for the IamWorkerProcess check
1912 // below to work. TODO: Redo IamWorkerProcess to work w/o Config and remove
1913 if (KidIdentifier
> 1 && Config
.workers
== 1) {
1914 debugs(3, DBG_CRITICAL
,
1915 "FATAL: cache_dir found before the workers option. Reorder.");
1919 // Among all processes, only workers may need and can handle cache_dir.
1920 if (!IamWorkerProcess())
1925 RefCount
<SwapDir
> sd
;
1929 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1932 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1935 fs
= find_fstype(type_str
);
1940 /* reconfigure existing dir */
1942 for (i
= 0; i
< swap
->n_configured
; i
++) {
1943 assert (swap
->swapDirs
[i
].getRaw());
1945 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1946 /* this is specific to on-fs Stores. The right
1947 * way to handle this is probably to have a mapping
1948 * from paths to stores, and have on-fs stores
1949 * register with that, and lookip in that in their
1950 * own setup logic. RBC 20041225. TODO.
1953 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1955 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1956 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1957 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1961 sd
->reconfigure (i
, path_str
);
1963 update_maxobjsize();
1970 if (swap
->n_configured
> 63) {
1971 /* 7 bits, signed */
1972 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1973 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1978 allocate_new_swapdir(swap
);
1980 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1982 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1984 /* parse the FS parameters and options */
1985 sd
->parse(swap
->n_configured
, path_str
);
1987 ++swap
->n_configured
;
1989 /* Update the max object size */
1990 update_maxobjsize();
1994 peer_type_str(const peer_t type
)
1996 const char * result
;
2008 case PEER_MULTICAST
:
2009 result
= "multicast";
2021 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
2025 LOCAL_ARRAY(char, xname
, 128);
2028 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2035 dump_peer_options(entry
, p
);
2037 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2038 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2040 d
->do_ping
? null_string
: "!",
2045 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2046 dump_acl_access(entry
, xname
, p
->access
);
2049 for (t
= p
->typelist
; t
; t
= t
->next
) {
2050 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2052 peer_type_str(t
->type
),
2061 * utility function to prevent getservbyname() being called with a numeric value
2062 * on Windows at least it returns garage results.
2065 isUnsignedNumeric(const char *str
, size_t len
)
2067 if (len
< 1) return false;
2069 for (; len
>0 && *str
; str
++, len
--) {
2070 if (! isdigit(*str
))
2077 \param proto 'tcp' or 'udp' for protocol
2078 \returns Port the named service is supposed to be listening on.
2081 GetService(const char *proto
)
2083 struct servent
*port
= NULL
;
2084 /** Parses a port number or service name from the squid.conf */
2085 char *token
= strtok(NULL
, w_space
);
2086 if (token
== NULL
) {
2088 return 0; /* NEVER REACHED */
2090 /** Returns either the service port number from /etc/services */
2091 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2092 port
= getservbyname(token
, proto
);
2094 return ntohs((u_short
)port
->s_port
);
2096 /** Or a numeric translation of the config text. */
2097 return xatos(token
);
2101 \returns Port the named TCP service is supposed to be listening on.
2102 \copydoc GetService(const char *proto)
2107 return GetService("tcp");
2111 \returns Port the named UDP service is supposed to be listening on.
2112 \copydoc GetService(const char *proto)
2117 return GetService("udp");
2121 parse_peer(peer
** head
)
2125 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
2126 p
= cbdataAlloc(peer
);
2127 p
->http_port
= CACHE_HTTP_PORT
;
2128 p
->icp
.port
= CACHE_ICP_PORT
;
2131 p
->stats
.logged_state
= PEER_ALIVE
;
2133 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2136 p
->host
= xstrdup(token
);
2138 p
->name
= xstrdup(token
);
2140 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2143 p
->type
= parseNeighborType(token
);
2145 if (p
->type
== PEER_MULTICAST
) {
2146 p
->options
.no_digest
= 1;
2147 p
->options
.no_netdb_exchange
= 1;
2150 p
->http_port
= GetTcpService();
2155 p
->icp
.port
= GetUdpService();
2156 p
->connection_auth
= 2; /* auto */
2158 while ((token
= strtok(NULL
, w_space
))) {
2159 if (!strcasecmp(token
, "proxy-only")) {
2160 p
->options
.proxy_only
= 1;
2161 } else if (!strcasecmp(token
, "no-query")) {
2162 p
->options
.no_query
= 1;
2163 } else if (!strcasecmp(token
, "background-ping")) {
2164 p
->options
.background_ping
= 1;
2165 } else if (!strcasecmp(token
, "no-digest")) {
2166 p
->options
.no_digest
= 1;
2167 } else if (!strcasecmp(token
, "no-tproxy")) {
2168 p
->options
.no_tproxy
= 1;
2169 } else if (!strcasecmp(token
, "multicast-responder")) {
2170 p
->options
.mcast_responder
= 1;
2171 #if PEER_MULTICAST_SIBLINGS
2172 } else if (!strcasecmp(token
, "multicast-siblings")) {
2173 p
->options
.mcast_siblings
= 1;
2175 } else if (!strncasecmp(token
, "weight=", 7)) {
2176 p
->weight
= xatoi(token
+ 7);
2177 } else if (!strncasecmp(token
, "basetime=", 9)) {
2178 p
->basetime
= xatoi(token
+ 9);
2179 } else if (!strcasecmp(token
, "closest-only")) {
2180 p
->options
.closest_only
= 1;
2181 } else if (!strncasecmp(token
, "ttl=", 4)) {
2182 p
->mcast
.ttl
= xatoi(token
+ 4);
2184 if (p
->mcast
.ttl
< 0)
2187 if (p
->mcast
.ttl
> 128)
2189 } else if (!strcasecmp(token
, "default")) {
2190 p
->options
.default_parent
= 1;
2191 } else if (!strcasecmp(token
, "round-robin")) {
2192 p
->options
.roundrobin
= 1;
2193 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2194 p
->options
.weighted_roundrobin
= 1;
2196 } else if (!strcasecmp(token
, "htcp")) {
2197 p
->options
.htcp
= 1;
2198 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2199 /* Note: The htcp- form is deprecated, replaced by htcp= */
2200 p
->options
.htcp
= 1;
2201 char *tmp
= xstrdup(token
+5);
2202 char *mode
, *nextmode
;
2203 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2204 nextmode
= strchr(mode
, ',');
2207 if (!strcasecmp(mode
, "no-clr")) {
2208 if (p
->options
.htcp_only_clr
)
2209 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2210 p
->options
.htcp_no_clr
= 1;
2211 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2212 p
->options
.htcp_no_purge_clr
= 1;
2213 } else if (!strcasecmp(mode
, "only-clr")) {
2214 if (p
->options
.htcp_no_clr
)
2215 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2216 p
->options
.htcp_only_clr
= 1;
2217 } else if (!strcasecmp(mode
, "forward-clr")) {
2218 p
->options
.htcp_forward_clr
= 1;
2219 } else if (!strcasecmp(mode
, "oldsquid")) {
2220 p
->options
.htcp_oldsquid
= 1;
2222 fatalf("invalid HTCP mode '%s'", mode
);
2227 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2228 p
->options
.no_netdb_exchange
= 1;
2230 } else if (!strcasecmp(token
, "carp")) {
2231 if (p
->type
!= PEER_PARENT
)
2232 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2234 p
->options
.carp
= 1;
2235 } else if (!strcasecmp(token
, "userhash")) {
2237 if (p
->type
!= PEER_PARENT
)
2238 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2240 p
->options
.userhash
= 1;
2242 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2244 } else if (!strcasecmp(token
, "sourcehash")) {
2245 if (p
->type
!= PEER_PARENT
)
2246 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2248 p
->options
.sourcehash
= 1;
2250 } else if (!strcasecmp(token
, "no-delay")) {
2252 p
->options
.no_delay
= 1;
2254 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2256 } else if (!strncasecmp(token
, "login=", 6)) {
2257 p
->login
= xstrdup(token
+ 6);
2258 rfc1738_unescape(p
->login
);
2259 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2260 p
->connect_timeout
= xatoi(token
+ 16);
2261 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2262 p
->connect_fail_limit
= xatoi(token
+ 19);
2263 #if USE_CACHE_DIGESTS
2264 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2265 p
->digest_url
= xstrdup(token
+ 11);
2268 } else if (!strcasecmp(token
, "allow-miss")) {
2269 p
->options
.allow_miss
= 1;
2270 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2271 p
->max_conn
= xatoi(token
+ 9);
2272 } else if (!strcasecmp(token
, "originserver")) {
2273 p
->options
.originserver
= 1;
2274 } else if (!strncasecmp(token
, "name=", 5)) {
2278 p
->name
= xstrdup(token
+ 5);
2279 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2280 safe_free(p
->domain
);
2283 p
->domain
= xstrdup(token
+ 13);
2287 } else if (strcmp(token
, "ssl") == 0) {
2289 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2290 safe_free(p
->sslcert
);
2291 p
->sslcert
= xstrdup(token
+ 8);
2292 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2293 safe_free(p
->sslkey
);
2294 p
->sslkey
= xstrdup(token
+ 7);
2295 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2296 p
->sslversion
= atoi(token
+ 11);
2297 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2298 safe_free(p
->ssloptions
);
2299 p
->ssloptions
= xstrdup(token
+ 11);
2300 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2301 safe_free(p
->sslcipher
);
2302 p
->sslcipher
= xstrdup(token
+ 10);
2303 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2304 safe_free(p
->sslcafile
);
2305 p
->sslcafile
= xstrdup(token
+ 10);
2306 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2307 safe_free(p
->sslcapath
);
2308 p
->sslcapath
= xstrdup(token
+ 10);
2309 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2310 safe_free(p
->sslcrlfile
);
2311 p
->sslcapath
= xstrdup(token
+ 10);
2312 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2313 safe_free(p
->sslflags
);
2314 p
->sslflags
= xstrdup(token
+ 9);
2315 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2316 safe_free(p
->ssldomain
);
2317 p
->ssldomain
= xstrdup(token
+ 10);
2320 } else if (strcmp(token
, "front-end-https") == 0) {
2321 p
->front_end_https
= 1;
2322 } else if (strcmp(token
, "front-end-https=on") == 0) {
2323 p
->front_end_https
= 1;
2324 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2325 p
->front_end_https
= 2;
2326 } else if (strcmp(token
, "connection-auth=off") == 0) {
2327 p
->connection_auth
= 0;
2328 } else if (strcmp(token
, "connection-auth") == 0) {
2329 p
->connection_auth
= 1;
2330 } else if (strcmp(token
, "connection-auth=on") == 0) {
2331 p
->connection_auth
= 1;
2332 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2333 p
->connection_auth
= 2;
2335 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2340 if (peerFindByName(p
->name
))
2341 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2346 if (p
->connect_fail_limit
< 1)
2347 p
->connect_fail_limit
= 10;
2349 p
->icp
.version
= ICP_VERSION_CURRENT
;
2353 #if USE_CACHE_DIGESTS
2355 if (!p
->options
.no_digest
) {
2356 /* XXX This looks odd.. who has the original pointer
2359 PeerDigest
*pd
= peerDigestCreate(p
);
2360 p
->digest
= cbdataReference(pd
);
2365 p
->index
= ++Config
.npeers
;
2367 while (*head
!= NULL
)
2368 head
= &(*head
)->next
;
2376 free_peer(peer
** P
)
2380 while ((p
= *P
) != NULL
) {
2382 #if USE_CACHE_DIGESTS
2384 cbdataReferenceDone(p
->digest
);
2394 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2398 while (list
!= NULL
) {
2399 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2400 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2402 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2404 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2405 storeAppendPrintf(entry
, " %s", w
->key
);
2408 storeAppendPrintf(entry
, "\n");
2414 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2416 char *passwd
= NULL
;
2417 wordlist
*actions
= NULL
;
2419 cachemgr_passwd
**P
;
2420 parse_string(&passwd
);
2421 parse_wordlist(&actions
);
2422 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2424 p
->actions
= actions
;
2426 for (P
= head
; *P
; P
= &(*P
)->next
) {
2428 * See if any of the actions from this line already have a
2429 * password from previous lines. The password checking
2430 * routines in cache_manager.c take the the password from
2431 * the first cachemgr_passwd struct that contains the
2432 * requested action. Thus, we should warn users who might
2433 * think they can have two passwords for the same action.
2438 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2439 for (u
= actions
; u
; u
= u
->next
) {
2440 if (strcmp(w
->key
, u
->key
))
2443 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2452 free_cachemgrpasswd(cachemgr_passwd
** head
)
2456 while ((p
= *head
) != NULL
) {
2459 wordlistDestroy(&p
->actions
);
2465 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2469 while (var
!= NULL
) {
2470 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2472 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2473 storeAppendPrintf(entry
, " %s", a
->name
);
2475 storeAppendPrintf(entry
, "\n");
2482 parse_denyinfo(acl_deny_info_list
** var
)
2484 aclParseDenyInfoLine(var
);
2488 free_denyinfo(acl_deny_info_list
** list
)
2490 acl_deny_info_list
*a
= NULL
;
2491 acl_deny_info_list
*a_next
= NULL
;
2492 acl_name_list
*l
= NULL
;
2493 acl_name_list
*l_next
= NULL
;
2495 for (a
= *list
; a
; a
= a_next
) {
2496 for (l
= a
->acl_list
; l
; l
= l_next
) {
2498 memFree(l
, MEM_ACL_NAME_LIST
);
2503 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2511 parse_peer_access(void)
2516 if (!(host
= strtok(NULL
, w_space
)))
2519 if ((p
= peerFindByName(host
)) == NULL
) {
2520 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2524 aclParseAccessLine(LegacyParser
, &p
->access
);
2528 parse_hostdomain(void)
2531 char *domain
= NULL
;
2533 if (!(host
= strtok(NULL
, w_space
)))
2536 while ((domain
= strtok(NULL
, list_sep
))) {
2537 domain_ping
*l
= NULL
;
2538 domain_ping
**L
= NULL
;
2541 if ((p
= peerFindByName(host
)) == NULL
) {
2542 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2546 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2549 if (*domain
== '!') { /* check for !.edu */
2554 l
->domain
= xstrdup(domain
);
2556 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2562 parse_hostdomaintype(void)
2566 char *domain
= NULL
;
2568 if (!(host
= strtok(NULL
, w_space
)))
2571 if (!(type
= strtok(NULL
, w_space
)))
2574 while ((domain
= strtok(NULL
, list_sep
))) {
2575 domain_type
*l
= NULL
;
2576 domain_type
**L
= NULL
;
2579 if ((p
= peerFindByName(host
)) == NULL
) {
2580 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2584 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2585 l
->type
= parseNeighborType(type
);
2586 l
->domain
= xstrdup(domain
);
2588 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2594 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2596 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2614 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2616 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2620 parse_onoff(int *var
)
2622 char *token
= strtok(NULL
, w_space
);
2627 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2633 #define free_onoff free_int
2636 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2647 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2651 parse_tristate(int *var
)
2653 char *token
= strtok(NULL
, w_space
);
2658 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2660 else if (!strcasecmp(token
, "warn"))
2666 #define free_tristate free_int
2669 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2671 while (head
!= NULL
) {
2672 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2674 head
->flags
.icase
? " -i" : null_string
,
2676 (int) head
->min
/ 60,
2677 (int) (100.0 * head
->pct
+ 0.5),
2678 (int) head
->max
/ 60);
2680 if (head
->max_stale
>= 0)
2681 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2683 if (head
->flags
.refresh_ims
)
2684 storeAppendPrintf(entry
, " refresh-ims");
2686 if (head
->flags
.store_stale
)
2687 storeAppendPrintf(entry
, " store-stale");
2689 #if USE_HTTP_VIOLATIONS
2691 if (head
->flags
.override_expire
)
2692 storeAppendPrintf(entry
, " override-expire");
2694 if (head
->flags
.override_lastmod
)
2695 storeAppendPrintf(entry
, " override-lastmod");
2697 if (head
->flags
.reload_into_ims
)
2698 storeAppendPrintf(entry
, " reload-into-ims");
2700 if (head
->flags
.ignore_reload
)
2701 storeAppendPrintf(entry
, " ignore-reload");
2703 if (head
->flags
.ignore_no_cache
)
2704 storeAppendPrintf(entry
, " ignore-no-cache");
2706 if (head
->flags
.ignore_no_store
)
2707 storeAppendPrintf(entry
, " ignore-no-store");
2709 if (head
->flags
.ignore_must_revalidate
)
2710 storeAppendPrintf(entry
, " ignore-must-revalidate");
2712 if (head
->flags
.ignore_private
)
2713 storeAppendPrintf(entry
, " ignore-private");
2715 if (head
->flags
.ignore_auth
)
2716 storeAppendPrintf(entry
, " ignore-auth");
2720 storeAppendPrintf(entry
, "\n");
2727 parse_refreshpattern(refresh_t
** head
)
2734 int refresh_ims
= 0;
2735 int store_stale
= 0;
2738 #if USE_HTTP_VIOLATIONS
2740 int override_expire
= 0;
2741 int override_lastmod
= 0;
2742 int reload_into_ims
= 0;
2743 int ignore_reload
= 0;
2744 int ignore_no_cache
= 0;
2745 int ignore_no_store
= 0;
2746 int ignore_must_revalidate
= 0;
2747 int ignore_private
= 0;
2748 int ignore_auth
= 0;
2755 int flags
= REG_EXTENDED
| REG_NOSUB
;
2757 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2762 if (strcmp(token
, "-i") == 0) {
2764 token
= strtok(NULL
, w_space
);
2765 } else if (strcmp(token
, "+i") == 0) {
2766 flags
&= ~REG_ICASE
;
2767 token
= strtok(NULL
, w_space
);
2770 if (token
== NULL
) {
2775 pattern
= xstrdup(token
);
2777 i
= GetInteger(); /* token: min */
2779 /* catch negative and insanely huge values close to 32-bit wrap */
2781 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2784 if (i
> 60*24*365) {
2785 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2789 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2791 i
= GetInteger(); /* token: pct */
2793 pct
= (double) i
/ 100.0;
2795 i
= GetInteger(); /* token: max */
2797 /* catch negative and insanely huge values close to 32-bit wrap */
2799 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2802 if (i
> 60*24*365) {
2803 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2807 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2810 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2811 if (!strcmp(token
, "refresh-ims")) {
2813 } else if (!strcmp(token
, "store-stale")) {
2815 } else if (!strncmp(token
, "max-stale=", 10)) {
2816 max_stale
= atoi(token
+ 10);
2817 #if USE_HTTP_VIOLATIONS
2819 } else if (!strcmp(token
, "override-expire"))
2820 override_expire
= 1;
2821 else if (!strcmp(token
, "override-lastmod"))
2822 override_lastmod
= 1;
2823 else if (!strcmp(token
, "ignore-no-cache"))
2824 ignore_no_cache
= 1;
2825 else if (!strcmp(token
, "ignore-no-store"))
2826 ignore_no_store
= 1;
2827 else if (!strcmp(token
, "ignore-must-revalidate"))
2828 ignore_must_revalidate
= 1;
2829 else if (!strcmp(token
, "ignore-private"))
2831 else if (!strcmp(token
, "ignore-auth"))
2833 else if (!strcmp(token
, "reload-into-ims")) {
2834 reload_into_ims
= 1;
2835 refresh_nocache_hack
= 1;
2836 /* tell client_side.c that this is used */
2837 } else if (!strcmp(token
, "ignore-reload")) {
2839 refresh_nocache_hack
= 1;
2840 /* tell client_side.c that this is used */
2844 debugs(22, 0, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2847 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2849 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2850 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2851 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2855 pct
= pct
< 0.0 ? 0.0 : pct
;
2856 max
= max
< 0 ? 0 : max
;
2857 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2858 t
->pattern
= (char *) xstrdup(pattern
);
2859 t
->compiled_pattern
= comp
;
2864 if (flags
& REG_ICASE
)
2868 t
->flags
.refresh_ims
= 1;
2871 t
->flags
.store_stale
= 1;
2873 t
->max_stale
= max_stale
;
2875 #if USE_HTTP_VIOLATIONS
2877 if (override_expire
)
2878 t
->flags
.override_expire
= 1;
2880 if (override_lastmod
)
2881 t
->flags
.override_lastmod
= 1;
2883 if (reload_into_ims
)
2884 t
->flags
.reload_into_ims
= 1;
2887 t
->flags
.ignore_reload
= 1;
2889 if (ignore_no_cache
)
2890 t
->flags
.ignore_no_cache
= 1;
2892 if (ignore_no_store
)
2893 t
->flags
.ignore_no_store
= 1;
2895 if (ignore_must_revalidate
)
2896 t
->flags
.ignore_must_revalidate
= 1;
2899 t
->flags
.ignore_private
= 1;
2902 t
->flags
.ignore_auth
= 1;
2909 head
= &(*head
)->next
;
2917 free_refreshpattern(refresh_t
** head
)
2921 while ((t
= *head
) != NULL
) {
2923 safe_free(t
->pattern
);
2924 regfree(&t
->compiled_pattern
);
2928 #if USE_HTTP_VIOLATIONS
2929 refresh_nocache_hack
= 0;
2935 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2938 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2942 parse_string(char **var
)
2944 char *token
= strtok(NULL
, w_space
);
2950 *var
= xstrdup(token
);
2954 ConfigParser::ParseString(char **var
)
2960 ConfigParser::ParseString(String
*var
)
2962 char *token
= strtok(NULL
, w_space
);
2971 free_string(char **var
)
2977 parse_eol(char *volatile *var
)
2979 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2987 while (*token
&& xisspace(*token
))
2995 *var
= xstrdup((char *) token
);
2998 #define dump_eol dump_string
2999 #define free_eol free_string
3002 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3004 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3008 parse_time_t(time_t * var
)
3011 parseTimeLine(&tval
, T_SECOND_STR
);
3012 *var
= static_cast<time_t>(tval
/1000);
3016 free_time_t(time_t * var
)
3023 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3026 storeAppendPrintf(entry
, "%s %"PRId64
" milliseconds\n", name
, var
);
3028 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3032 parse_time_msec(time_msec_t
* var
)
3034 parseTimeLine(var
, T_SECOND_STR
);
3038 free_time_msec(time_msec_t
* var
)
3046 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3048 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3053 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3055 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3060 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3062 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3068 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3070 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3075 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3077 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3081 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3083 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3088 parse_size_t(size_t * var
)
3097 parse_b_size_t(size_t * var
)
3099 parseBytesLine(var
, B_BYTES_STR
);
3104 parse_b_ssize_t(ssize_t
* var
)
3106 parseBytesLineSigned(var
, B_BYTES_STR
);
3112 parse_kb_size_t(size_t * var
)
3114 parseBytesLine(var
, B_KBYTES_STR
);
3119 parse_b_int64_t(int64_t * var
)
3121 parseBytesLine64(var
, B_BYTES_STR
);
3125 parse_kb_int64_t(int64_t * var
)
3127 parseBytesLine64(var
, B_KBYTES_STR
);
3131 free_size_t(size_t * var
)
3138 free_ssize_t(ssize_t
* var
)
3145 free_b_int64_t(int64_t * var
)
3150 #define free_b_size_t free_size_t
3151 #define free_b_ssize_t free_ssize_t
3152 #define free_kb_size_t free_size_t
3153 #define free_mb_size_t free_size_t
3154 #define free_gb_size_t free_size_t
3155 #define free_kb_int64_t free_b_int64_t
3158 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
3160 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3164 free_ushort(u_short
* u
)
3170 parse_ushort(u_short
* var
)
3172 ConfigParser::ParseUShort(var
);
3176 ConfigParser::ParseUShort(u_short
*var
)
3182 ConfigParser::ParseBool(bool *var
)
3184 int i
= GetInteger();
3195 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3197 while (list
!= NULL
) {
3198 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3204 ConfigParser::ParseWordList(wordlist
** list
)
3206 parse_wordlist(list
);
3210 parse_wordlist(wordlist
** list
)
3213 char *t
= strtok(NULL
, "");
3215 while ((token
= strwordtok(NULL
, &t
)))
3216 wordlistAdd(list
, token
);
3219 #if 0 /* now unused */
3221 check_null_wordlist(wordlist
* w
)
3228 check_null_acl_access(acl_access
* a
)
3233 #define free_wordlist wordlistDestroy
3235 #define free_uri_whitespace free_int
3238 parse_uri_whitespace(int *var
)
3240 char *token
= strtok(NULL
, w_space
);
3245 if (!strcasecmp(token
, "strip"))
3246 *var
= URI_WHITESPACE_STRIP
;
3247 else if (!strcasecmp(token
, "deny"))
3248 *var
= URI_WHITESPACE_DENY
;
3249 else if (!strcasecmp(token
, "allow"))
3250 *var
= URI_WHITESPACE_ALLOW
;
3251 else if (!strcasecmp(token
, "encode"))
3252 *var
= URI_WHITESPACE_ENCODE
;
3253 else if (!strcasecmp(token
, "chop"))
3254 *var
= URI_WHITESPACE_CHOP
;
3260 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3264 if (var
== URI_WHITESPACE_ALLOW
)
3266 else if (var
== URI_WHITESPACE_ENCODE
)
3268 else if (var
== URI_WHITESPACE_CHOP
)
3270 else if (var
== URI_WHITESPACE_DENY
)
3275 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3279 free_removalpolicy(RemovalPolicySettings
** settings
)
3284 free_string(&(*settings
)->type
);
3286 free_wordlist(&(*settings
)->args
);
3294 parse_removalpolicy(RemovalPolicySettings
** settings
)
3297 free_removalpolicy(settings
);
3299 *settings
= new RemovalPolicySettings
;
3301 parse_string(&(*settings
)->type
);
3303 parse_wordlist(&(*settings
)->args
);
3307 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3310 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3311 args
= settings
->args
;
3314 storeAppendPrintf(entry
, " %s", args
->key
);
3318 storeAppendPrintf(entry
, "\n");
3322 free_memcachemode(SquidConfig
* config
)
3328 parse_memcachemode(SquidConfig
* config
)
3330 char *token
= strtok(NULL
, w_space
);
3334 if (strcmp(token
, "always") == 0) {
3335 Config
.onoff
.memory_cache_first
= 1;
3336 Config
.onoff
.memory_cache_disk
= 1;
3337 } else if (strcmp(token
, "disk") == 0) {
3338 Config
.onoff
.memory_cache_first
= 0;
3339 Config
.onoff
.memory_cache_disk
= 1;
3340 } else if (strncmp(token
, "net", 3) == 0) {
3341 Config
.onoff
.memory_cache_first
= 1;
3342 Config
.onoff
.memory_cache_disk
= 0;
3343 } else if (strcmp(token
, "never") == 0) {
3344 Config
.onoff
.memory_cache_first
= 0;
3345 Config
.onoff
.memory_cache_disk
= 0;
3351 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3353 storeAppendPrintf(entry
, "%s ", name
);
3354 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3355 storeAppendPrintf(entry
, "always");
3356 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3357 storeAppendPrintf(entry
, "disk");
3358 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3359 storeAppendPrintf(entry
, "network");
3360 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3361 storeAppendPrintf(entry
, "none");
3362 storeAppendPrintf(entry
, "\n");
3365 #include "cf_parser.cci"
3368 parseNeighborType(const char *s
)
3370 if (!strcasecmp(s
, "parent"))
3373 if (!strcasecmp(s
, "neighbor"))
3374 return PEER_SIBLING
;
3376 if (!strcasecmp(s
, "neighbour"))
3377 return PEER_SIBLING
;
3379 if (!strcasecmp(s
, "sibling"))
3380 return PEER_SIBLING
;
3382 if (!strcasecmp(s
, "multicast"))
3383 return PEER_MULTICAST
;
3385 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3387 return PEER_SIBLING
;
3392 parse_IpAddress_list(Ip::Address_list
** head
)
3395 Ip::Address_list
*s
;
3398 while ((token
= strtok(NULL
, w_space
))) {
3399 if (GetHostWithPort(token
, &ipa
)) {
3402 head
= &(*head
)->next
;
3404 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3414 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3416 char ntoabuf
[MAX_IPSTRLEN
];
3419 storeAppendPrintf(e
, "%s %s\n",
3421 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3427 free_IpAddress_list(Ip::Address_list
** head
)
3429 if (*head
) delete *head
;
3433 #if CURRENTLY_UNUSED
3434 /* This code was previously used by http_port. Left as it really should
3435 * be used by icp_port and htcp_port
3438 check_null_IpAddress_list(const Ip::Address_list
* s
)
3443 #endif /* CURRENTLY_UNUSED */
3444 #endif /* USE_WCCPv2 */
3446 CBDATA_CLASS_INIT(http_port_list
);
3449 parse_http_port_specification(http_port_list
* s
, char *token
)
3452 unsigned short port
= 0;
3456 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3457 s
->name
= xstrdup(token
);
3458 s
->connection_auth_disabled
= false;
3460 if (*token
== '[') {
3463 t
= strchr(host
, ']');
3465 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
3470 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
3473 if (!Ip::EnableIpv6
) {
3474 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 is not available.");
3477 port
= xatos(t
+ 1);
3478 } else if ((t
= strchr(token
, ':'))) {
3483 port
= xatos(t
+ 1);
3485 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3487 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3489 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3494 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3501 if (!Ip::EnableIpv6
)
3503 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3504 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
3506 if (!Ip::EnableIpv6
)
3508 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3509 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3510 /* dont use ipcache */
3511 s
->defaultsite
= xstrdup(host
);
3513 if (!Ip::EnableIpv6
)
3515 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3517 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3523 parse_http_port_option(http_port_list
* s
, char *token
)
3527 if (strcmp(token
, "accel") == 0) {
3528 if (s
->intercepted
|| s
->spoof_client_ip
) {
3529 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3533 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3534 if (s
->accel
|| s
->spoof_client_ip
) {
3535 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3539 Ip::Interceptor
.StartInterception();
3540 /* Log information regarding the port modes under interception. */
3541 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3542 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3544 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3546 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3547 if ( !s
->s
.SetIPv4() ) {
3548 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3551 } else if (strcmp(token
, "tproxy") == 0) {
3552 if (s
->intercepted
|| s
->accel
) {
3553 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3556 s
->spoof_client_ip
= 1;
3557 Ip::Interceptor
.StartTransparency();
3558 /* Log information regarding the port modes under transparency. */
3559 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3560 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3562 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3563 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3567 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3569 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3572 safe_free(s
->defaultsite
);
3573 s
->defaultsite
= xstrdup(token
+ 12);
3574 } else if (strcmp(token
, "vhost") == 0) {
3576 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vhost option requires Acceleration mode flag.");
3580 } else if (strcmp(token
, "vport") == 0) {
3582 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3586 } else if (strncmp(token
, "vport=", 6) == 0) {
3588 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3591 s
->vport
= xatos(token
+ 6);
3592 } else if (strncmp(token
, "protocol=", 9) == 0) {
3594 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3597 s
->protocol
= xstrdup(token
+ 9);
3598 } else if (strcmp(token
, "allow-direct") == 0) {
3600 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3603 s
->allow_direct
= 1;
3604 } else if (strcmp(token
, "ignore-cc") == 0) {
3605 #if !USE_HTTP_VIOLATIONS
3607 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3612 } else if (strncmp(token
, "name=", 5) == 0) {
3614 s
->name
= xstrdup(token
+ 5);
3615 } else if (strcmp(token
, "no-connection-auth") == 0) {
3616 s
->connection_auth_disabled
= true;
3617 } else if (strcmp(token
, "connection-auth=off") == 0) {
3618 s
->connection_auth_disabled
= true;
3619 } else if (strcmp(token
, "connection-auth") == 0) {
3620 s
->connection_auth_disabled
= false;
3621 } else if (strcmp(token
, "connection-auth=on") == 0) {
3622 s
->connection_auth_disabled
= false;
3623 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3624 if (!strcasecmp(token
+ 23, "off"))
3625 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3626 else if (!strcasecmp(token
+ 23, "transparent"))
3627 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3628 else if (!strcasecmp(token
+ 23, "always"))
3629 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3632 } else if (strcmp(token
, "ipv4") == 0) {
3633 if ( !s
->s
.SetIPv4() ) {
3634 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3637 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3638 s
->tcp_keepalive
.enabled
= 1;
3639 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3640 char *t
= token
+ 13;
3641 s
->tcp_keepalive
.enabled
= 1;
3642 s
->tcp_keepalive
.idle
= atoi(t
);
3646 s
->tcp_keepalive
.interval
= atoi(t
);
3651 s
->tcp_keepalive
.timeout
= atoi(t
);
3655 } else if (strcasecmp(token
, "sslBump") == 0) {
3656 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3657 "in http_port. Use 'ssl-bump' instead.");
3658 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3659 } else if (strcmp(token
, "ssl-bump") == 0) {
3660 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3661 } else if (strncmp(token
, "cert=", 5) == 0) {
3663 s
->cert
= xstrdup(token
+ 5);
3664 } else if (strncmp(token
, "key=", 4) == 0) {
3666 s
->key
= xstrdup(token
+ 4);
3667 } else if (strncmp(token
, "version=", 8) == 0) {
3668 s
->version
= xatoi(token
+ 8);
3669 if (s
->version
< 1 || s
->version
> 4)
3671 } else if (strncmp(token
, "options=", 8) == 0) {
3672 safe_free(s
->options
);
3673 s
->options
= xstrdup(token
+ 8);
3674 } else if (strncmp(token
, "cipher=", 7) == 0) {
3675 safe_free(s
->cipher
);
3676 s
->cipher
= xstrdup(token
+ 7);
3677 } else if (strncmp(token
, "clientca=", 9) == 0) {
3678 safe_free(s
->clientca
);
3679 s
->clientca
= xstrdup(token
+ 9);
3680 } else if (strncmp(token
, "cafile=", 7) == 0) {
3681 safe_free(s
->cafile
);
3682 s
->cafile
= xstrdup(token
+ 7);
3683 } else if (strncmp(token
, "capath=", 7) == 0) {
3684 safe_free(s
->capath
);
3685 s
->capath
= xstrdup(token
+ 7);
3686 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3687 safe_free(s
->crlfile
);
3688 s
->crlfile
= xstrdup(token
+ 8);
3689 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3690 safe_free(s
->dhfile
);
3691 s
->dhfile
= xstrdup(token
+ 9);
3692 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3693 safe_free(s
->sslflags
);
3694 s
->sslflags
= xstrdup(token
+ 9);
3695 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3696 safe_free(s
->sslContextSessionId
);
3697 s
->sslContextSessionId
= xstrdup(token
+ 11);
3698 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3699 s
->generateHostCertificates
= true;
3700 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3701 s
->generateHostCertificates
= true;
3702 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3703 s
->generateHostCertificates
= false;
3704 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3705 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3712 static http_port_list
*
3713 create_http_port(char *portspec
)
3715 http_port_list
*s
= new http_port_list("http");
3716 parse_http_port_specification(s
, portspec
);
3721 add_http_port(char *portspec
)
3723 http_port_list
*s
= create_http_port(portspec
);
3724 // we may need to merge better of the above returns a list with clones
3725 assert(s
->next
== NULL
);
3726 s
->next
= Config
.Sockaddr
.http
;
3727 Config
.Sockaddr
.http
= s
;
3731 clone_http_port_list(http_port_list
*a
)
3733 http_port_list
*b
= new http_port_list(a
->protocol
);
3737 b
->name
= xstrdup(a
->name
);
3739 b
->defaultsite
= xstrdup(a
->defaultsite
);
3741 b
->intercepted
= a
->intercepted
;
3742 b
->spoof_client_ip
= a
->spoof_client_ip
;
3743 b
->accel
= a
->accel
;
3744 b
->allow_direct
= a
->allow_direct
;
3745 b
->vhost
= a
->vhost
;
3746 b
->sslBump
= a
->sslBump
;
3747 b
->vport
= a
->vport
;
3748 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3749 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3751 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3754 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3757 // XXX: temporary hack to ease move of SSL options to http_port
3758 http_port_list
&http
;
3771 char *sslContextSessionId
;
3772 SSL_CTX
*sslContext
;
3781 parse_http_port_list(http_port_list
** head
)
3783 char *token
= strtok(NULL
, w_space
);
3790 http_port_list
*s
= create_http_port(token
);
3792 /* parse options ... */
3793 while ((token
= strtok(NULL
, w_space
))) {
3794 parse_http_port_option(s
, token
);
3797 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3798 // clone the port options from *s to *(s->next)
3799 s
->next
= clone_http_port_list(s
);
3800 s
->next
->s
.SetIPv4();
3801 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3805 head
= &(*head
)->next
;
3811 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3813 char buf
[MAX_IPSTRLEN
];
3815 storeAppendPrintf(e
, "%s %s",
3817 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3819 // MODES and specific sub-options.
3821 storeAppendPrintf(e
, " intercept");
3823 else if (s
->spoof_client_ip
)
3824 storeAppendPrintf(e
, " tproxy");
3826 else if (s
->accel
) {
3827 storeAppendPrintf(e
, " accel");
3830 storeAppendPrintf(e
, " vhost");
3833 storeAppendPrintf(e
, " vport");
3834 else if (s
->vport
> 0)
3835 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3838 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3840 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3841 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3843 if (s
->allow_direct
)
3844 storeAppendPrintf(e
, " allow-direct");
3847 storeAppendPrintf(e
, " ignore-cc");
3851 // Generic independent options
3854 storeAppendPrintf(e
, " name=%s", s
->name
);
3856 #if USE_HTTP_VIOLATIONS
3857 if (!s
->accel
&& s
->ignore_cc
)
3858 storeAppendPrintf(e
, " ignore-cc");
3861 if (s
->connection_auth_disabled
)
3862 storeAppendPrintf(e
, " connection-auth=off");
3864 storeAppendPrintf(e
, " connection-auth=on");
3866 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3869 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3872 pmtu
= "transparent";
3874 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3877 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3878 storeAppendPrintf(e
, " ipv4");
3880 if (s
->tcp_keepalive
.enabled
) {
3881 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3882 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3884 storeAppendPrintf(e
, " tcpkeepalive");
3890 storeAppendPrintf(e
, " ssl-bump");
3893 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3896 storeAppendPrintf(e
, " key=%s", s
->key
);
3899 storeAppendPrintf(e
, " version=%d", s
->version
);
3902 storeAppendPrintf(e
, " options=%s", s
->options
);
3905 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3908 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3911 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3914 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3917 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3920 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3922 if (s
->sslContextSessionId
)
3923 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3925 if (s
->generateHostCertificates
)
3926 storeAppendPrintf(e
, " generate-host-certificates");
3928 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3929 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3934 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3937 dump_generic_http_port(e
, n
, s
);
3938 storeAppendPrintf(e
, "\n");
3944 free_http_port_list(http_port_list
** head
)
3948 while ((s
= *head
) != NULL
) {
3956 // TODO: merge better with parse_http_port_list
3958 parse_https_port_list(https_port_list
** head
)
3963 token
= strtok(NULL
, w_space
);
3968 s
= new https_port_list
;
3969 parse_http_port_specification(&s
->http
, token
);
3971 /* parse options ... */
3972 while ((token
= strtok(NULL
, w_space
))) {
3973 parse_http_port_option(s
, token
);
3977 http_port_list
** headTmp
= &(*head
)->http
.next
;
3978 head
= (https_port_list
**)headTmp
;
3985 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3987 dump_http_port_list(e
, n
, s
);
3991 free_https_port_list(https_port_list
** head
)
3993 free_http_port_list((http_port_list
**)head
);
3998 check_null_https_port_list(const https_port_list
* s
)
4005 #endif /* USE_SSL */
4008 configFreeMemory(void)
4012 SSL_CTX_free(Config
.ssl_client
.sslContext
);
4017 requirePathnameExists(const char *name
, const char *path
)
4021 char pathbuf
[BUFSIZ
];
4022 assert(path
!= NULL
);
4024 if (Config
.chroot_dir
&& (geteuid() == 0)) {
4025 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4029 if (stat(path
, &sb
) < 0) {
4030 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4031 fatalf("%s %s: %s", name
, path
, xstrerror());
4033 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
4040 return ConfigParser::strtokFile();
4043 #include "AccessLogEntry.h"
4046 parse_access_log(customlog
** logs
)
4048 const char *filename
, *logdef_name
;
4052 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
4054 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
4059 if (strcmp(filename
, "none") == 0) {
4060 cl
->type
= Log::Format::CLF_NONE
;
4064 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
4065 logdef_name
= "squid";
4067 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
4069 cl
->filename
= xstrdup(filename
);
4071 /* look for the definition pointer corresponding to this name */
4072 lf
= Log::TheConfig
.logformats
;
4074 while (lf
!= NULL
) {
4075 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4077 if (strcmp(lf
->name
, logdef_name
) == 0)
4084 cl
->type
= Log::Format::CLF_CUSTOM
;
4086 } else if (strcmp(logdef_name
, "auto") == 0) {
4087 debugs(0,0, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4088 cl
->type
= Log::Format::CLF_SQUID
;
4089 } else if (strcmp(logdef_name
, "squid") == 0) {
4090 cl
->type
= Log::Format::CLF_SQUID
;
4091 } else if (strcmp(logdef_name
, "common") == 0) {
4092 cl
->type
= Log::Format::CLF_COMMON
;
4093 } else if (strcmp(logdef_name
, "combined") == 0) {
4094 cl
->type
= Log::Format::CLF_COMBINED
;
4096 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4097 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4099 } else if (strcmp(logdef_name
, "useragent") == 0) {
4100 cl
->type
= Log::Format::CLF_USERAGENT
;
4101 } else if (strcmp(logdef_name
, "referrer") == 0) {
4102 cl
->type
= Log::Format::CLF_REFERER
;
4104 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
4110 aclParseAclList(LegacyParser
, &cl
->aclList
);
4113 logs
= &(*logs
)->next
;
4119 check_null_access_log(customlog
*customlog_definitions
)
4121 return customlog_definitions
== NULL
;
4125 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
4129 for (log
= logs
; log
; log
= log
->next
) {
4130 storeAppendPrintf(entry
, "%s ", name
);
4132 switch (log
->type
) {
4134 case Log::Format::CLF_CUSTOM
:
4135 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4138 case Log::Format::CLF_NONE
:
4139 storeAppendPrintf(entry
, "none");
4142 case Log::Format::CLF_SQUID
:
4143 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4146 case Log::Format::CLF_COMBINED
:
4147 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4150 case Log::Format::CLF_COMMON
:
4151 storeAppendPrintf(entry
, "%s common", log
->filename
);
4155 case Log::Format::CLF_ICAP_SQUID
:
4156 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4159 case Log::Format::CLF_USERAGENT
:
4160 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4163 case Log::Format::CLF_REFERER
:
4164 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4167 case Log::Format::CLF_UNKNOWN
:
4172 dump_acl_list(entry
, log
->aclList
);
4174 storeAppendPrintf(entry
, "\n");
4179 free_access_log(customlog
** definitions
)
4181 while (*definitions
) {
4182 customlog
*log
= *definitions
;
4183 *definitions
= log
->next
;
4185 log
->logFormat
= NULL
;
4186 log
->type
= Log::Format::CLF_UNKNOWN
;
4189 aclDestroyAclList(&log
->aclList
);
4191 safe_free(log
->filename
);
4197 /// parses list of integers form name=N1,N2,N3,...
4199 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4201 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4202 data
+= name
.size();
4207 if (!StringToInt(data
, value
, &data
, 10))
4209 list
.push_back(value
);
4210 if (*data
== '\0' || *data
!= ',')
4215 return data
&& *data
== '\0';
4219 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4221 #if !HAVE_CPU_AFFINITY
4222 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4223 "support, do not set 'cpu_affinity_map'");
4225 #endif /* HAVE_CPU_AFFINITY */
4227 if (!*cpuAffinityMap
)
4228 *cpuAffinityMap
= new CpuAffinityMap
;
4230 const char *const pToken
= strtok(NULL
, w_space
);
4231 const char *const cToken
= strtok(NULL
, w_space
);
4232 Vector
<int> processes
, cores
;
4233 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4234 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4235 "in 'cpu_affinity_map'");
4237 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4238 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4239 "'cpu_affinity_map'");
4241 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4242 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4243 "process_numbers and cores lists differ in length or " <<
4244 "contain numbers <= 0");
4250 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4252 if (cpuAffinityMap
) {
4253 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4254 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4255 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4256 cpuAffinityMap
->processes()[i
]);
4258 storeAppendPrintf(entry
, " cores=");
4259 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4260 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4261 cpuAffinityMap
->cores()[i
]);
4263 storeAppendPrintf(entry
, "\n");
4268 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4270 delete *cpuAffinityMap
;
4271 *cpuAffinityMap
= NULL
;
4277 parse_adaptation_service_set_type()
4279 Adaptation::Config::ParseServiceSet();
4283 parse_adaptation_service_chain_type()
4285 Adaptation::Config::ParseServiceChain();
4289 parse_adaptation_access_type()
4291 Adaptation::Config::ParseAccess(LegacyParser
);
4294 #endif /* USE_ADAPTATION */
4300 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4302 cfg
->parseService();
4306 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4312 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4314 cfg
.dumpService(entry
, name
);
4318 parse_icap_class_type()
4320 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
4321 "Use 'adaptation_service_set' instead");
4322 Adaptation::Config::ParseServiceSet();
4326 parse_icap_access_type()
4328 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
4329 "Use 'adaptation_access' instead");
4330 Adaptation::Config::ParseAccess(LegacyParser
);
4339 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4341 cfg
->parseService();
4345 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4351 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4353 cfg
.dumpService(entry
, name
);
4356 #endif /* USE_ECAP */
4359 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4364 cfg
->service_failure_limit
= GetInteger();
4366 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4369 if (strcmp(token
,"in") != 0) {
4370 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
4374 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4378 d
= static_cast<time_t> (xatoi(token
));
4380 m
= static_cast<time_t> (1);
4384 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4385 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
4387 } else if ((m
= parseTimeUnits(token
)) == 0)
4390 cfg
->oldest_service_failure
= (m
* d
);
4393 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4395 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4396 if (cfg
.oldest_service_failure
> 0) {
4397 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4399 storeAppendPrintf(entry
, "\n");
4402 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4404 cfg
->oldest_service_failure
= 0;
4405 cfg
->service_failure_limit
= 0;