]> git.ipfire.org Git - thirdparty/squid.git/blame - src/cache_cf.cc
updating to squid-1.0.1
[thirdparty/squid.git] / src / cache_cf.cc
CommitLineData
983061ed 1/* $Id: cache_cf.cc,v 1.55 1996/05/03 22:56:21 wessels Exp $ */
cf5fd929 2
3/* DEBUG: Section 3 cache_cf: Configuration file parsing */
ed43818f 4
44a47c6e 5#include "squid.h"
090089c4 6
090089c4 7static struct {
8 struct {
9 int maxSize;
10 int highWatherMark;
11 int lowWaterMark;
12 } Mem , Swap;
13 struct {
14 int maxObjSize;
15 int defaultTtl;
16 } Gopher, Http, Ftp;
090089c4 17 struct {
18 int maxObjSize;
19 int defaultTtl;
20 char *relayHost;
21 int relayPort;
22 } Wais;
090089c4 23 int negativeTtl;
61d6fc5c 24 int negativeDnsTtl;
2639dac6 25 int positiveDnsTtl;
090089c4 26 int readTimeout;
27 int lifetimeDefault;
605ba5ca 28 int lifetimeShutdown;
090089c4 29 int connectTimeout;
30 int ageMaxDefault;
31 int cleanRate;
32 int dnsChildren;
fa966b74 33 int maxRequestSize;
090089c4 34 double hotVmFactor;
35 struct {
36 int ascii;
37 int udp;
090089c4 38 } Port;
39 struct {
40 char *log;
41 char *access;
42 char *hierarchy;
d8b45066 43 char *store;
090089c4 44 int rotateNumber;
45 } Log;
46 char *adminEmail;
47 char *effectiveUser;
48 char *effectiveGroup;
49 struct {
50 char *ftpget;
51 char *ftpget_opts;
52 char *dnsserver;
53 } Program;
54 int sourcePing;
55 int quickAbort;
56 int commonLogFormat;
090089c4 57 int neighborTimeout;
e5c22962 58 int stallDelay;
090089c4 59 int singleParentBypass;
60 struct {
61 char *host;
62 char *prefix;
63 int port;
64 int withProxy;
65 } Accel;
66 char *appendDomain;
12b9e9b1 67 char *debugOptions;
ccff9601 68 char *pidFilename;
cf5fd929 69 char *visibleHostname;
fb263c4c 70 char *ftpUser;
7d49daab 71 struct {
72 char *host;
73 int port;
74 char *file;
75 int rate;
76 } Announce;
0ffd22bc 77 wordlist *cache_dirs;
78 wordlist *http_stoplist;
79 wordlist *gopher_stoplist;
80 wordlist *ftp_stoplist;
81 wordlist *bind_addr_list;
82 wordlist *local_domain_list;
83 wordlist *inside_firewall_list;
605ba5ca 84 wordlist *dns_testname_list;
090089c4 85} Config;
86
87#define DefaultMemMaxSize (16 << 20) /* 16 MB */
88#define DefaultMemHighWatherMark 90 /* 90% */
234967c9 89#define DefaultMemLowWatherMark 75 /* 75% */
090089c4 90#define DefaultSwapMaxSize (100 << 10) /* 100 MB (100*1024 kbytes) */
91#define DefaultSwapHighWaterMark 90 /* 90% */
234967c9 92#define DefaultSwapLowWaterMark 75 /* 75% */
090089c4 93
94#define DefaultFtpDefaultTtl (7 * 24 * 60 * 60) /* 1 week */
95#define DefaultFtpMaxObjSize (4 << 20) /* 4 MB */
96#define DefaultGopherDefaultTtl (7 * 24 * 60 * 60) /* 1 week */
97#define DefaultGopherMaxObjSize (4 << 20) /* 4 MB */
98#define DefaultHttpDefaultTtl (7 * 24 * 60 * 60) /* 1 week */
99#define DefaultHttpMaxObjSize (4 << 20) /* 4 MB */
090089c4 100#define DefaultWaisDefaultTtl (7 * 24 * 60 * 60) /* 1 week */
101#define DefaultWaisMaxObjSize (4 << 20) /* 4 MB */
102#define DefaultWaisRelayHost (char *)NULL
103#define DefaultWaisRelayPort -1
090089c4 104
105#define DefaultNegativeTtl (5 * 60) /* 5 min */
61d6fc5c 106#define DefaultNegativeDnsTtl (2 * 60) /* 2 min */
2639dac6 107#define DefaultPositiveDnsTtl (360 * 60) /* 6 hours */
090089c4 108#define DefaultReadTimeout (15 * 60) /* 15 min */
109#define DefaultLifetimeDefault (200 * 60) /* 3+ hours */
234967c9 110#define DefaultLifetimeShutdown 30 /* 30 seconds */
090089c4 111#define DefaultConnectTimeout (2 * 60) /* 2 min */
112#define DefaultDefaultAgeMax (3600 * 24 * 30) /* 30 days */
113#define DefaultCleanRate -1 /* disabled */
114#define DefaultDnsChildren 5 /* 3 processes */
115#define DefaultDnsChildrenMax 32 /* 32 processes */
234967c9 116#define DefaultMaxRequestSize (100 << 10) /* 100Kb */
090089c4 117#define DefaultHotVmFactor 0.0 /* disabled */
118
119#define DefaultAsciiPortNum CACHE_HTTP_PORT
090089c4 120#define DefaultUdpPortNum CACHE_ICP_PORT
121
a26bdc75 122#define DefaultCacheLogFile DEFAULT_CACHE_LOG
123#define DefaultAccessLogFile DEFAULT_ACCESS_LOG
124#define DefaultHierarchyLogFile DEFAULT_HIERARCHY_LOG
d8b45066 125#define DefaultStoreLogFile DEFAULT_STORE_LOG
090089c4 126#define DefaultLogRotateNumber 10
127#define DefaultAdminEmail "webmaster"
a26bdc75 128#define DefaultFtpgetProgram DEFAULT_FTPGET
090089c4 129#define DefaultFtpgetOptions ""
a26bdc75 130#define DefaultDnsserverProgram DEFAULT_DNSSERVER
090089c4 131#define DefaultEffectiveUser (char *)NULL /* default NONE */
132#define DefaultEffectiveGroup (char *)NULL /* default NONE */
133#define DefaultAppendDomain (char *)NULL /* default NONE */
134
ccff9601 135#define DefaultDebugOptions "ALL,1" /* All sections at level 1 */
090089c4 136#define DefaultAccelHost (char *)NULL /* default NONE */
137#define DefaultAccelPrefix (char *)NULL /* default NONE */
138#define DefaultAccelPort 0 /* default off */
139#define DefaultAccelWithProxy 0 /* default off */
140#define DefaultSourcePing 0 /* default off */
141#define DefaultCommonLogFormat 1 /* default on */
142#define DefaultQuickAbort 0 /* default off */
143#define DefaultNeighborTimeout 2 /* 2 seconds */
234967c9 144#define DefaultStallDelay 1 /* 1 seconds */
090089c4 145#define DefaultSingleParentBypass 0 /* default off */
77ffc99f 146#define DefaultPidFilename (char *)NULL /* default NONE */
cf5fd929 147#define DefaultVisibleHostname (char *)NULL /* default NONE */
b8de7ebe 148#define DefaultFtpUser "squid@" /* Default without domain */
7d49daab 149#define DefaultAnnounceHost "sd.cache.nlanr.net"
150#define DefaultAnnouncePort 3131
7ba794f4 151#define DefaultAnnounceFile (char *)NULL /* default NONE */
152#define DefaultAnnounceRate 86400 /* every 24 hours */
ccff9601 153
090089c4 154ip_acl *local_ip_list = NULL;
155
156int zap_disk_store = 0; /* off, try to rebuild from disk */
157int httpd_accel_mode = 0; /* for fast access */
158int emulate_httpd_log = DefaultCommonLogFormat; /* for fast access */
159time_t neighbor_timeout = DefaultNeighborTimeout; /* for fast access */
160int single_parent_bypass = 0;
2639dac6 161int DnsPositiveTtl = DefaultPositiveDnsTtl;
f133a434 162char *DefaultSwapDir = DEFAULT_SWAP_DIR;
00fac1f8 163char *DefaultConfigFile = DEFAULT_CONFIG_FILE;
cbbad1ed 164char *ConfigFile = NULL; /* the whole thing */
fe1c7f28 165char *cfg_filename = NULL; /* just the last part */
090089c4 166
12b9e9b1 167char w_space[] = " \t\n";
3003c0f3 168char config_input_line[BUFSIZ];
169int config_lineno = 0;
090089c4 170
0ffd22bc 171static void configSetFactoryDefaults _PARAMS((void));
172static void configFreeMemory _PARAMS((void));
173static void configDoConfigure _PARAMS((void));
cf5fd929 174static char fatal_str[BUFSIZ];
090089c4 175
3003c0f3 176void self_destruct()
090089c4 177{
b8de7ebe 178 sprintf(fatal_str, "Bungled %s line %d: %s",
179 cfg_filename, config_lineno, config_input_line);
090089c4 180 fatal(fatal_str);
181}
182
c8bd12b1 183int ip_acl_match(c, a)
184 struct in_addr c;
185 ip_acl *a;
186{
187 static struct in_addr h;
188
189 h.s_addr = c.s_addr & a->mask.s_addr;
190 if (h.s_addr == a->addr.s_addr)
191 return 1;
192 else
193 return 0;
194}
195
196
c837641d 197ip_access_type ip_access_check(address, list)
c8bd12b1 198 struct in_addr address;
199 ip_acl *list;
200{
c7f37efb 201 static int init = 0;
202 static struct in_addr localhost;
c837641d 203 ip_acl *p = NULL;
c8bd12b1 204 struct in_addr naddr; /* network byte-order IP addr */
c8bd12b1 205
206 if (!list)
207 return IP_ALLOW;
208
c7f37efb 209 if (!init) {
210 memset((char *) &localhost, '\0', sizeof(struct in_addr));
c8bd12b1 211 localhost.s_addr = inet_addr("127.0.0.1");
c7f37efb 212 init = 1;
213 }
c8bd12b1 214 naddr.s_addr = address.s_addr;
215 if (naddr.s_addr == localhost.s_addr)
216 return IP_ALLOW;
217
a4f583ee 218 debug(3, 5, "ip_access_check: using %s\n", inet_ntoa(naddr));
c8bd12b1 219
220 for (p = list; p; p = p->next) {
a4f583ee 221 debug(3, 5, "ip_access_check: %s vs %s/%s\n",
222 inet_ntoa(naddr),
223 inet_ntoa(p->addr),
224 inet_ntoa(p->mask));
c8bd12b1 225 if (ip_acl_match(naddr, p))
226 return p->access;
227 }
228 return IP_ALLOW;
229}
230
231
232void addToIPACL(list, ip_str, access)
233 ip_acl **list;
234 char *ip_str;
235 ip_access_type access;
236{
237 ip_acl *p, *q;
238 int a1, a2, a3, a4;
239 int m1, m2, m3, m4;
240 struct in_addr lmask;
241 int c;
242
243 if (!ip_str) {
244 return;
245 }
246 if (!(*list)) {
247 /* empty list */
248 *list = (ip_acl *) xcalloc(1, sizeof(ip_acl));
249 (*list)->next = NULL;
250 q = *list;
251 } else {
252 /* find end of list */
253 p = *list;
254 while (p->next)
255 p = p->next;
256 q = (ip_acl *) xcalloc(1, sizeof(ip_acl));
257 q->next = NULL;
258 p->next = q;
259 }
260
261
262 /* decode ip address */
263 if (!strcasecmp(ip_str, "all")) {
264 a1 = a2 = a3 = a4 = 0;
265 lmask.s_addr = 0;
266 } else {
267 a1 = a2 = a3 = a4 = 0;
268 c = sscanf(ip_str, "%d.%d.%d.%d/%d.%d.%d.%d", &a1, &a2, &a3, &a4,
269 &m1, &m2, &m3, &m4);
270
271 switch (c) {
272 case 4:
d3c1a245 273 if (a1 == 0 && a2 == 0 && a3 == 0 && a4 == 0) /* world */
b2bc6f9e 274 lmask.s_addr = 0x00000000;
d3c1a245 275 else if (a2 == 0 && a3 == 0 && a4 == 0) /* class A */
b2bc6f9e 276 lmask.s_addr = htonl(0xff000000);
d3c1a245 277 else if (a3 == 0 && a4 == 0) /* class B */
b2bc6f9e 278 lmask.s_addr = htonl(0xffff0000);
d3c1a245 279 else if (a4 == 0) /* class C */
b2bc6f9e 280 lmask.s_addr = htonl(0xffffff00);
c8bd12b1 281 else
282 lmask.s_addr = 0xffffffff;
283 break;
284
285 case 5:
286 if (m1 < 0 || m1 > 32) {
da00e850 287 debug(3, 0, "addToIPACL: Ignoring invalid IP acl line '%s'\n",
c8bd12b1 288 ip_str);
289 return;
290 }
291 lmask.s_addr = htonl(0xffffffff << (32 - m1));
292 break;
293
294 case 8:
295 lmask.s_addr = htonl(m1 * 0x1000000 + m2 * 0x10000 + m3 * 0x100 + m4);
296 break;
297
298 default:
da00e850 299 debug(3, 0, "addToIPACL: Ignoring invalid IP acl line '%s'\n",
300 ip_str);
c8bd12b1 301 return;
302 }
303 }
304
305 q->access = access;
306 q->addr.s_addr = htonl(a1 * 0x1000000 + a2 * 0x10000 + a3 * 0x100 + a4);
307 q->mask.s_addr = lmask.s_addr;
308}
c837641d 309
92a6f4b1 310void wordlistDestroy(list)
84c6cc9f 311 wordlist **list;
0ffd22bc 312{
313 wordlist *w = NULL;
314 wordlist *n = NULL;
315
84c6cc9f 316 for (w = *list; w; w = n) {
0ffd22bc 317 n = w->next;
318 safe_free(w->key);
319 safe_free(w);
320 }
321 *list = NULL;
322}
323
324void wordlistAdd(list, key)
325 wordlist **list;
090089c4 326 char *key;
327{
0ffd22bc 328 wordlist *p = NULL;
329 wordlist *q = NULL;
090089c4 330
331 if (!(*list)) {
332 /* empty list */
0ffd22bc 333 *list = (wordlist *) xcalloc(1, sizeof(wordlist));
090089c4 334 (*list)->key = xstrdup(key);
335 (*list)->next = NULL;
336 } else {
337 p = *list;
338 while (p->next)
339 p = p->next;
0ffd22bc 340 q = (wordlist *) xcalloc(1, sizeof(wordlist));
090089c4 341 q->key = xstrdup(key);
342 q->next = NULL;
343 p->next = q;
344 }
345}
346
92a6f4b1 347void intlistDestroy(list)
348 intlist **list;
349{
350 intlist *w = NULL;
351 intlist *n = NULL;
352
353 for (w = *list; w; w = n) {
354 n = w->next;
355 safe_free(w);
356 }
357 *list = NULL;
358}
359
403279e0 360
090089c4 361/* Use this #define in all the parse*() functions. Assumes
3003c0f3 362 * ** char *token is defined
090089c4 363 */
364
365#define GetInteger(var) \
366 token = strtok(NULL, w_space); \
367 if( token == (char *) NULL) \
3003c0f3 368 self_destruct(); \
090089c4 369 if (sscanf(token, "%d", &var) != 1) \
3003c0f3 370 self_destruct();
090089c4 371
372
3003c0f3 373static void parseCacheHostLine()
090089c4 374{
375 char *type = NULL;
376 char *hostname = NULL;
377 char *token = NULL;
378 int ascii_port = CACHE_HTTP_PORT;
379 int udp_port = CACHE_ICP_PORT;
380 int proxy_only = 0;
fe113054 381 int weight = 1;
090089c4 382
383 /* Parse a cache_host line */
384 if (!(hostname = strtok(NULL, w_space)))
3003c0f3 385 self_destruct();
090089c4 386 if (!(type = strtok(NULL, w_space)))
3003c0f3 387 self_destruct();
090089c4 388
389 GetInteger(ascii_port);
390 GetInteger(udp_port);
fe113054 391 while ((token = strtok(NULL, w_space))) {
392 if (!strcasecmp(token, "proxy-only")) {
090089c4 393 proxy_only = 1;
c06a5b15 394 } else if (!strncasecmp(token, "weight=", 7)) {
a0bbd6c8 395 weight = atoi(token + 7);
fe113054 396 } else {
01f2d250 397 debug(3, 0, "parseCacheHostLine: token='%s'\n", token);
a0bbd6c8 398 self_destruct();
fe113054 399 }
090089c4 400 }
234967c9 401 if (weight < 1)
402 weight = 1;
fe113054 403 neighbors_cf_add(hostname, type, ascii_port, udp_port, proxy_only, weight);
090089c4 404}
405
3003c0f3 406static void parseHostDomainLine()
090089c4 407{
408 char *host = NULL;
409 char *domain = NULL;
410
411 if (!(host = strtok(NULL, w_space)))
3003c0f3 412 self_destruct();
090089c4 413 while ((domain = strtok(NULL, ", \t\n"))) {
414 if (neighbors_cf_domain(host, domain) == 0)
3003c0f3 415 self_destruct();
090089c4 416 }
417}
418
090089c4 419
3003c0f3 420static void parseSourcePingLine()
090089c4 421{
422 char *srcping;
423
424 srcping = strtok(NULL, w_space);
425 if (srcping == (char *) NULL)
3003c0f3 426 self_destruct();
090089c4 427
428 /* set source_ping, default is off. */
429 if (!strcasecmp(srcping, "on"))
430 Config.sourcePing = 1;
431 else if (!strcasecmp(srcping, "off"))
432 Config.sourcePing = 0;
433 else
434 Config.sourcePing = 0;
435}
436
437
3003c0f3 438static void parseQuickAbortLine()
090089c4 439{
440 char *abort;
441
442 abort = strtok(NULL, w_space);
443 if (abort == (char *) NULL)
3003c0f3 444 self_destruct();
090089c4 445
446 if (!strcasecmp(abort, "on") || !strcasecmp(abort, "quick"))
447 Config.quickAbort = 1;
448 else if (!strcmp(abort, "off") || !strcasecmp(abort, "normal"))
449 Config.quickAbort = 0;
450 else
451 Config.quickAbort = 0;
452
453}
454
3003c0f3 455static void parseMemLine()
090089c4 456{
457 char *token;
458 int i;
459 GetInteger(i);
460 Config.Mem.maxSize = i << 20;
461}
462
3003c0f3 463static void parseMemHighLine()
090089c4 464{
465 char *token;
466 int i;
467 GetInteger(i);
468 Config.Mem.highWatherMark = i;
469}
470
3003c0f3 471static void parseMemLowLine()
090089c4 472{
473 char *token;
474 int i;
475 GetInteger(i);
476 Config.Mem.lowWaterMark = i;
477}
478
3003c0f3 479static void parseHotVmFactorLine()
090089c4 480{
481 char *token = NULL;
482 double d;
483
484 token = strtok(NULL, w_space);
485 if (token == (char *) NULL)
3003c0f3 486 self_destruct();
090089c4 487 if (sscanf(token, "%lf", &d) != 1)
3003c0f3 488 self_destruct();
090089c4 489 if (d < 0)
3003c0f3 490 self_destruct();
090089c4 491 Config.hotVmFactor = d;
492}
493
3003c0f3 494static void parseSwapLine()
090089c4 495{
496 char *token;
497 int i;
498 GetInteger(i);
499 Config.Swap.maxSize = i << 10;
500}
501
3003c0f3 502static void parseSwapHighLine()
090089c4 503{
504 char *token;
505 int i;
506 GetInteger(i);
507 Config.Swap.highWatherMark = i;
508}
509
3003c0f3 510static void parseSwapLowLine()
090089c4 511{
512 char *token;
513 int i;
514 GetInteger(i);
515 Config.Swap.lowWaterMark = i;
516}
517
3003c0f3 518static void parseHttpLine()
090089c4 519{
520 char *token;
521 int i;
522 GetInteger(i);
523 Config.Http.maxObjSize = i << 20;
524 GetInteger(i);
525 Config.Http.defaultTtl = i * 60;
526}
527
3003c0f3 528static void parseGopherLine()
090089c4 529{
530 char *token;
531 int i;
532 GetInteger(i);
533 Config.Gopher.maxObjSize = i << 20;
534 GetInteger(i);
535 Config.Gopher.defaultTtl = i * 60;
536}
537
3003c0f3 538static void parseFtpLine()
090089c4 539{
540 char *token;
541 int i;
542 GetInteger(i);
543 Config.Ftp.maxObjSize = i << 20;
544 GetInteger(i);
545 Config.Ftp.defaultTtl = i * 60;
546}
547
3003c0f3 548static void parseTTLPattern()
090089c4 549{
550 char *token;
551 char *pattern;
552 time_t abs_ttl = 0;
553 int pct_age = 0;
554 time_t age_max = Config.ageMaxDefault;
555 int i;
556
557 token = strtok(NULL, w_space); /* token: regex pattern */
558 if (token == (char *) NULL)
3003c0f3 559 self_destruct();
090089c4 560 pattern = xstrdup(token);
561
562 GetInteger(i); /* token: abs_ttl */
563 abs_ttl = (time_t) (i * 60); /* convert minutes to seconds */
564
565 token = strtok(NULL, w_space); /* token: pct_age */
566 if (token != (char *) NULL) { /* pct_age is optional */
567 if (sscanf(token, "%d", &pct_age) != 1)
3003c0f3 568 self_destruct();
090089c4 569 }
570 token = strtok(NULL, w_space); /* token: age_max */
571 if (token != (char *) NULL) { /* age_max is optional */
572 if (sscanf(token, "%d", &i) != 1)
3003c0f3 573 self_destruct();
090089c4 574 age_max = (time_t) (i * 60); /* convert minutes to seconds */
575 }
576 ttlAddToList(pattern, abs_ttl, pct_age, age_max);
577
578 safe_free(pattern);
579}
580
3003c0f3 581static void parseNegativeLine()
090089c4 582{
583 char *token;
584 int i;
585 GetInteger(i);
586 Config.negativeTtl = i * 60;
587}
588
3003c0f3 589static void parseNegativeDnsLine()
61d6fc5c 590{
591 char *token;
592 int i;
593 GetInteger(i);
594 Config.negativeDnsTtl = i * 60;
595}
596
2639dac6 597static void parsePositiveDnsLine()
598{
599 char *token;
600 int i;
601 GetInteger(i);
602 Config.positiveDnsTtl = i * 60;
603}
604
3003c0f3 605static void parseReadTimeoutLine()
090089c4 606{
607 char *token;
608 int i;
609 GetInteger(i);
610 Config.readTimeout = i * 60;
611}
612
3003c0f3 613static void parseLifetimeLine()
090089c4 614{
615 char *token;
616 int i;
617 GetInteger(i);
618 Config.lifetimeDefault = i * 60;
619}
620
605ba5ca 621static void parseShutdownLifetimeLine()
622{
623 char *token;
624 int i;
625 GetInteger(i);
626 Config.lifetimeShutdown = i;
627}
628
3003c0f3 629static void parseConnectTimeout()
090089c4 630{
631 char *token;
632 int i;
633 GetInteger(i);
634 Config.connectTimeout = i;
635}
636
3003c0f3 637static void parseCleanRateLine()
090089c4 638{
639 char *token;
640 int i;
641 GetInteger(i);
642 Config.cleanRate = i * 60;
643}
644
3003c0f3 645static void parseDnsChildrenLine()
090089c4 646{
647 char *token;
648 int i;
649 GetInteger(i);
650 Config.dnsChildren = i;
651}
652
3003c0f3 653static void parseRequestSizeLine()
fa966b74 654{
655 char *token;
656 int i;
657 GetInteger(i);
658 Config.maxRequestSize = i * 1024;
659}
660
3003c0f3 661static void parseMgrLine()
090089c4 662{
663 char *token;
664 token = strtok(NULL, w_space);
665 if (token == (char *) NULL)
3003c0f3 666 self_destruct();
090089c4 667 safe_free(Config.adminEmail);
668 Config.adminEmail = xstrdup(token);
669}
670
3003c0f3 671static void parseDirLine()
090089c4 672{
673 char *token;
674
675 token = strtok(NULL, w_space);
676 if (token == (char *) NULL)
3003c0f3 677 self_destruct();
0ffd22bc 678 wordlistAdd(&Config.cache_dirs, token);
090089c4 679}
680
3003c0f3 681static void parseHttpdAccelLine()
090089c4 682{
683 char *token;
684 char buf[1024];
685 int i;
686
687 token = strtok(NULL, w_space);
688 if (token == (char *) NULL)
3003c0f3 689 self_destruct();
090089c4 690 safe_free(Config.Accel.host);
691 Config.Accel.host = xstrdup(token);
692 GetInteger(i);
693 Config.Accel.port = i;
694 safe_free(Config.Accel.prefix);
695 sprintf(buf, "http://%s:%d", Config.Accel.host, Config.Accel.port);
696 Config.Accel.prefix = xstrdup(buf);
697 httpd_accel_mode = 1;
698}
699
3003c0f3 700static void parseHttpdAccelWithProxyLine()
090089c4 701{
702 char *proxy;
703
704 proxy = strtok(NULL, w_space);
705 if (proxy == (char *) NULL)
3003c0f3 706 self_destruct();
090089c4 707
708 /* set httpd_accel_with_proxy, default is off. */
709 if (!strcasecmp(proxy, "on"))
710 Config.Accel.withProxy = 1;
711 else if (!strcasecmp(proxy, "off"))
712 Config.Accel.withProxy = 0;
713 else
714 Config.Accel.withProxy = 0;
715}
716
3003c0f3 717static void parseEffectiveUserLine()
090089c4 718{
719 char *token;
720
721 token = strtok(NULL, w_space);
722 if (token == (char *) NULL)
3003c0f3 723 self_destruct();
090089c4 724 safe_free(Config.effectiveUser);
725 safe_free(Config.effectiveGroup);
726 Config.effectiveUser = xstrdup(token);
727
728 token = strtok(NULL, w_space);
729 if (token == (char *) NULL)
730 return; /* group is optional */
731 Config.effectiveGroup = xstrdup(token);
732}
733
3003c0f3 734static void parseLogLine()
090089c4 735{
736 char *token;
090089c4 737 token = strtok(NULL, w_space);
738 if (token == (char *) NULL)
3003c0f3 739 self_destruct();
090089c4 740 safe_free(Config.Log.log);
741 Config.Log.log = xstrdup(token);
090089c4 742}
743
3003c0f3 744static void parseAccessLogLine()
090089c4 745{
746 char *token;
747 token = strtok(NULL, w_space);
748 if (token == (char *) NULL)
3003c0f3 749 self_destruct();
090089c4 750 safe_free(Config.Log.access);
751 Config.Log.access = xstrdup(token);
752}
753
3003c0f3 754static void parseHierachyLogLine()
090089c4 755{
756 char *token;
757 token = strtok(NULL, w_space);
758 if (token == (char *) NULL)
3003c0f3 759 self_destruct();
090089c4 760 safe_free(Config.Log.hierarchy);
761 Config.Log.hierarchy = xstrdup(token);
762}
763
d8b45066 764static void parseStoreLogLine()
765{
766 char *token;
767 token = strtok(NULL, w_space);
768 if (token == (char *) NULL)
769 self_destruct();
770 safe_free(Config.Log.store);
771 Config.Log.store = xstrdup(token);
772}
773
3003c0f3 774static void parseLogfileRotateLine()
090089c4 775{
776 char *token;
777 int i;
778 GetInteger(i);
779 Config.Log.rotateNumber = i;
780}
781
3003c0f3 782static void parseFtpProgramLine()
090089c4 783{
784 char *token;
785 token = strtok(NULL, w_space);
786 if (token == (char *) NULL)
3003c0f3 787 self_destruct();
090089c4 788 safe_free(Config.Program.ftpget);
789 Config.Program.ftpget = xstrdup(token);
790}
791
3003c0f3 792static void parseFtpOptionsLine()
090089c4 793{
794 char *token;
795 token = strtok(NULL, ""); /* Note "", don't separate these */
796 if (token == (char *) NULL)
3003c0f3 797 self_destruct();
090089c4 798 safe_free(Config.Program.ftpget_opts);
799 Config.Program.ftpget_opts = xstrdup(token);
800}
801
3003c0f3 802static void parseDnsProgramLine()
090089c4 803{
804 char *token;
805 token = strtok(NULL, w_space);
806 if (token == (char *) NULL)
3003c0f3 807 self_destruct();
090089c4 808 safe_free(Config.Program.dnsserver);
809 Config.Program.dnsserver = xstrdup(token);
810}
811
3003c0f3 812static void parseEmulateLine()
090089c4 813{
814 char *token;
815 token = strtok(NULL, w_space);
816 if (token == (char *) NULL)
3003c0f3 817 self_destruct();
090089c4 818 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
819 Config.commonLogFormat = 1;
820 else
821 Config.commonLogFormat = 0;
822}
823
3003c0f3 824static void parseWAISRelayLine()
090089c4 825{
826 char *token;
827 int i;
828 token = strtok(NULL, w_space);
829 if (token == (char *) NULL)
3003c0f3 830 self_destruct();
090089c4 831 safe_free(Config.Wais.relayHost);
832 Config.Wais.relayHost = xstrdup(token);
833 GetInteger(i);
834 Config.Wais.relayPort = i;
835 GetInteger(i);
836 Config.Wais.maxObjSize = i << 20;
837}
838
3003c0f3 839static void parseLocalIPLine()
090089c4 840{
841 char *token;
842 while ((token = strtok(NULL, w_space))) {
843 addToIPACL(&local_ip_list, token, IP_DENY);
844 }
845}
846
3003c0f3 847static void parseHttpStopLine()
090089c4 848{
849 char *token;
850 token = strtok(NULL, w_space);
851 if (token == (char *) NULL)
852 return;
0ffd22bc 853 wordlistAdd(&Config.http_stoplist, token);
090089c4 854}
855
3003c0f3 856static void parseGopherStopLine()
090089c4 857{
858 char *token;
859 token = strtok(NULL, w_space);
860 if (token == (char *) NULL)
861 return;
0ffd22bc 862 wordlistAdd(&Config.gopher_stoplist, token);
090089c4 863}
3003c0f3 864static void parseFtpStopLine()
090089c4 865{
866 char *token;
867 token = strtok(NULL, w_space);
868 if (token == (char *) NULL)
869 return;
0ffd22bc 870 wordlistAdd(&Config.ftp_stoplist, token);
090089c4 871}
872
3003c0f3 873static void parseAppendDomainLine()
090089c4 874{
875 char *token;
876 token = strtok(NULL, w_space);
877 if (token == (char *) NULL)
3003c0f3 878 self_destruct();
090089c4 879 if (*token != '.')
3003c0f3 880 self_destruct();
090089c4 881 safe_free(Config.appendDomain);
882 Config.appendDomain = xstrdup(token);
883}
884
3003c0f3 885static void parseBindAddressLine()
090089c4 886{
887 char *token;
888 token = strtok(NULL, w_space);
889 if (token == (char *) NULL)
3003c0f3 890 self_destruct();
cf5fd929 891 debug(3, 1, "parseBindAddressLine: adding %s\n", token);
0ffd22bc 892 wordlistAdd(&Config.bind_addr_list, token);
090089c4 893}
894
983061ed 895static void parseLocalDomainFile(fname)
896 char *fname;
897{
898 char tmp_line[BUFSIZ];
899 FILE *fp = NULL;
900 char *t = NULL;
901
902 if ((fp = fopen(fname, "r")) == NULL) {
903 debug(3, 1, "parseLocalDomainFile: %s: %s\n", fname, xstrerror());
904 return;
905 }
906 memset(tmp_line, '\0', BUFSIZ);
907 while (fgets(tmp_line, BUFSIZ, fp)) {
908 if (tmp_line[0] == '#')
909 continue;
910 if (tmp_line[0] == '\0')
911 continue;
912 if (tmp_line[0] == '\n')
913 continue;
914 for (t = strtok(tmp_line, w_space); t; t = strtok(NULL, w_space)) {
915 debug(3, 1, "parseLocalDomainFileLine: adding %s\n", t);
916 wordlistAdd(&Config.local_domain_list, t);
917 }
918 }
919 fclose(fp);
920}
921
3003c0f3 922static void parseLocalDomainLine()
090089c4 923{
983061ed 924 char *token = NULL;
925 struct stat sb;
090089c4 926 while ((token = strtok(NULL, w_space))) {
983061ed 927 if (stat(token, &sb) < 0) {
928 wordlistAdd(&Config.local_domain_list, token);
929 } else {
930 parseLocalDomainFile(token);
931 }
090089c4 932 }
933}
934
983061ed 935
3003c0f3 936static void parseInsideFirewallLine()
090089c4 937{
938 char *token;
939 while ((token = strtok(NULL, w_space))) {
0ffd22bc 940 wordlistAdd(&Config.inside_firewall_list, token);
090089c4 941 }
942}
943
605ba5ca 944static void parseDnsTestnameLine()
945{
946 char *token;
947 while ((token = strtok(NULL, w_space))) {
948 wordlistAdd(&Config.dns_testname_list, token);
949 }
950}
951
3003c0f3 952static void parseAsciiPortLine()
090089c4 953{
954 char *token;
955 int i;
956 GetInteger(i);
957 Config.Port.ascii = i;
958}
959
3003c0f3 960static void parseUdpPortLine()
090089c4 961{
962 char *token;
963 int i;
964 GetInteger(i);
965 Config.Port.udp = i;
966}
967
3003c0f3 968static void parseNeighborTimeout()
090089c4 969{
970 char *token;
971 int i;
972 GetInteger(i);
973 Config.neighborTimeout = i;
974}
975
3003c0f3 976static void parseSingleParentBypassLine()
090089c4 977{
978 char *token;
979 token = strtok(NULL, w_space);
980 if (token == (char *) NULL)
3003c0f3 981 self_destruct();
090089c4 982 if (!strcasecmp(token, "on"))
983 Config.singleParentBypass = 1;
984}
985
3003c0f3 986static void parseDebugOptionsLine()
090089c4 987{
12b9e9b1 988 char *token;
989 token = strtok(NULL, ""); /* Note "", don't separate these */
990 safe_free(Config.debugOptions);
991 if (token == (char *) NULL) {
992 Config.debugOptions = NULL;
993 return;
994 }
995 Config.debugOptions = xstrdup(token);
090089c4 996}
997
3003c0f3 998static void parsePidFilenameLine()
ccff9601 999{
1000 char *token;
1001 token = strtok(NULL, w_space);
1002 safe_free(Config.pidFilename);
1003 if (token == (char *) NULL)
3003c0f3 1004 self_destruct();
ccff9601 1005 Config.pidFilename = xstrdup(token);
1006}
1007
3003c0f3 1008static void parseVisibleHostnameLine()
cf5fd929 1009{
1010 char *token;
1011 token = strtok(NULL, w_space);
1012 safe_free(Config.visibleHostname);
1013 if (token == (char *) NULL)
3003c0f3 1014 self_destruct();
cf5fd929 1015 Config.visibleHostname = xstrdup(token);
1016}
1017
3003c0f3 1018static void parseFtpUserLine()
fb263c4c 1019{
1020 char *token;
1021 token = strtok(NULL, w_space);
fb263c4c 1022 if (token == (char *) NULL)
3003c0f3 1023 self_destruct();
7d49daab 1024 safe_free(Config.ftpUser);
fb263c4c 1025 Config.ftpUser = xstrdup(token);
1026}
1027
3003c0f3 1028static void parseCacheAnnounceLine()
7d49daab 1029{
1030 char *token;
1031 int i;
1032 GetInteger(i);
1033 Config.Announce.rate = i * 3600; /* hours to seconds */
1034}
1035
3003c0f3 1036static void parseAnnounceToLine()
7d49daab 1037{
1038 char *token;
1039 int i;
1040 token = strtok(NULL, w_space);
1041 if (token == (char *) NULL)
3003c0f3 1042 self_destruct();
7d49daab 1043 safe_free(Config.Announce.host);
1044 Config.Announce.host = xstrdup(token);
1045 if ((token = strchr(Config.Announce.host, ':'))) {
1046 *token++ = '\0';
1047 if (sscanf(token, "%d", &i) != 1)
1048 Config.Announce.port = i;
1049 }
1050 token = strtok(NULL, w_space);
1051 if (token == (char *) NULL)
1052 return;
1053 safe_free(Config.Announce.file);
1054 Config.Announce.file = xstrdup(token);
1055}
1056
403279e0 1057
090089c4 1058int parseConfigFile(file_name)
1059 char *file_name;
1060{
12b9e9b1 1061 FILE *fp = NULL;
1062 char *token = NULL;
1063 static char tmp_line[BUFSIZ];
090089c4 1064
0ffd22bc 1065 configFreeMemory();
090089c4 1066 configSetFactoryDefaults();
92a6f4b1 1067 aclDestroyAcls();
1068 aclDestroyAccessList(&HTTPAccessList);
1069 aclDestroyAccessList(&ICPAccessList);
090089c4 1070
12b9e9b1 1071 if ((fp = fopen(file_name, "r")) == NULL) {
234967c9 1072 sprintf(fatal_str, "Unable to open configuration file: %s: %s",
1073 file_name, xstrerror());
090089c4 1074 fatal(fatal_str);
1075 }
b8de7ebe 1076 cfg_filename = file_name;
1077 if ((token = strrchr(cfg_filename, '/')))
4cd0ab45 1078 cfg_filename = token + 1;
3003c0f3 1079 memset(config_input_line, '\0', BUFSIZ);
1080 config_lineno = 0;
1081 while (fgets(config_input_line, BUFSIZ, fp)) {
1082 config_lineno++;
1083 if ((token = strchr(config_input_line, '\n')))
540830c4 1084 *token = '\0';
3003c0f3 1085 if (config_input_line[0] == '#')
540830c4 1086 continue;
3003c0f3 1087 if (config_input_line[0] == '\0')
090089c4 1088 continue;
3003c0f3 1089 debug(3, 5, "Processing: '%s'\n", config_input_line);
1090 strcpy(tmp_line, config_input_line);
92a6f4b1 1091 if ((token = strtok(tmp_line, w_space)) == NULL)
090089c4 1092 continue;
1093
1094 /* Parse a cache_host line */
1095 if (!strcmp(token, "cache_host"))
3003c0f3 1096 parseCacheHostLine();
090089c4 1097
1098 /* Parse a cache_host_domain line */
1099 else if (!strcmp(token, "cache_host_domain"))
3003c0f3 1100 parseHostDomainLine();
090089c4 1101
1102 /* Parse a neighbor_timeout line */
1103 else if (!strcmp(token, "neighbor_timeout"))
3003c0f3 1104 parseNeighborTimeout();
090089c4 1105 else if (!strcmp(token, "neighbour_timeout")) /* alternate spelling */
3003c0f3 1106 parseNeighborTimeout();
090089c4 1107
090089c4 1108 /* Parse a cache_dir line */
1109 else if (!strcmp(token, "cache_dir"))
3003c0f3 1110 parseDirLine();
090089c4 1111
1112 /* Parse a cache_log line */
1113 else if (!strcmp(token, "cache_log"))
3003c0f3 1114 parseLogLine();
090089c4 1115
1116 /* Parse a cache_access_log line */
1117 else if (!strcmp(token, "cache_access_log"))
3003c0f3 1118 parseAccessLogLine();
090089c4 1119
1120 /* Parse a cache_hierarchy_log line */
1121 else if (!strcmp(token, "cache_hierarchy_log"))
3003c0f3 1122 parseHierachyLogLine();
090089c4 1123
d8b45066 1124 /* Parse a cache_store_log line */
1125 else if (!strcmp(token, "cache_store_log"))
1126 parseStoreLogLine();
1127
090089c4 1128 /* Parse a logfile_rotate line */
1129 else if (!strcmp(token, "logfile_rotate"))
3003c0f3 1130 parseLogfileRotateLine();
090089c4 1131
1132 /* Parse a httpd_accel_with_proxy line */
1133 else if (!strcmp(token, "httpd_accel_with_proxy"))
3003c0f3 1134 parseHttpdAccelWithProxyLine();
090089c4 1135
1136 /* Parse a httpd_accel line */
1137 else if (!strcmp(token, "httpd_accel"))
3003c0f3 1138 parseHttpdAccelLine();
090089c4 1139
1140 /* Parse a cache_effective_user line */
1141 else if (!strcmp(token, "cache_effective_user"))
3003c0f3 1142 parseEffectiveUserLine();
090089c4 1143
1144 /* Parse a cache_mem_high line */
1145 else if (!strcmp(token, "cache_swap_high"))
3003c0f3 1146 parseSwapHighLine();
090089c4 1147
1148 /* Parse a cache_mem_low line */
1149 else if (!strcmp(token, "cache_swap_low"))
3003c0f3 1150 parseSwapLowLine();
090089c4 1151
1152 /* Parse a cache_mem_high line */
1153 else if (!strcmp(token, "cache_mem_high"))
3003c0f3 1154 parseMemHighLine();
090089c4 1155
1156 /* Parse a cache_mem_low line */
1157 else if (!strcmp(token, "cache_mem_low"))
3003c0f3 1158 parseMemLowLine();
090089c4 1159
1160 /* Parse a cache_hot_vm_factor line */
1161 else if (!strcmp(token, "cache_hot_vm_factor"))
3003c0f3 1162 parseHotVmFactorLine();
090089c4 1163
1164 /* Parse a cache_mem line */
1165 /* XXX: this must be AFTER cache_mem_low, etc. */
1166 else if (!strcmp(token, "cache_mem"))
3003c0f3 1167 parseMemLine();
090089c4 1168
1169 /* Parse a cache_swap line */
1170 else if (!strcmp(token, "cache_swap"))
3003c0f3 1171 parseSwapLine();
090089c4 1172
1173 /* Parse a cache_mgr line */
1174 else if (!strcmp(token, "cache_mgr"))
3003c0f3 1175 parseMgrLine();
090089c4 1176
8213067d 1177 else if (!strcmp(token, "acl"))
3003c0f3 1178 aclParseAclLine();
8213067d 1179
92a6f4b1 1180 else if (!strcmp(token, "http_access"))
1181 aclParseAccessLine(&HTTPAccessList);
1182
1183 else if (!strcmp(token, "icp_access"))
1184 aclParseAccessLine(&ICPAccessList);
8213067d 1185
090089c4 1186 /* Parse a http_stop line */
1187 else if (!strcmp(token, "http_stop"))
3003c0f3 1188 parseHttpStopLine();
090089c4 1189
1190 /* Parse a gopher_stop line */
1191 else if (!strcmp(token, "gopher_stop"))
3003c0f3 1192 parseGopherStopLine();
090089c4 1193
1194 /* Parse a ftp_stop line */
1195 else if (!strcmp(token, "ftp_stop"))
3003c0f3 1196 parseFtpStopLine();
090089c4 1197
1198 /* Parse a gopher protocol line */
1199 /* XXX: Must go after any gopher* token */
1200 else if (!strcmp(token, "gopher"))
3003c0f3 1201 parseGopherLine();
090089c4 1202
1203 /* Parse a http protocol line */
1204 /* XXX: Must go after any http* token */
1205 else if (!strcmp(token, "http"))
3003c0f3 1206 parseHttpLine();
090089c4 1207
1208 /* Parse a ftp protocol line */
1209 /* XXX: Must go after any ftp* token */
1210 else if (!strcmp(token, "ftp"))
3003c0f3 1211 parseFtpLine();
090089c4 1212
1213 else if (!strcmp(token, "ttl_pattern"))
3003c0f3 1214 parseTTLPattern();
090089c4 1215
1216 /* Parse a negative_ttl line */
1217 else if (!strcmp(token, "negative_ttl"))
3003c0f3 1218 parseNegativeLine();
090089c4 1219
61d6fc5c 1220 /* Parse a negative_dns_ttl line */
1221 else if (!strcmp(token, "negative_dns_ttl"))
3003c0f3 1222 parseNegativeDnsLine();
61d6fc5c 1223
2639dac6 1224 /* Parse a positive_dns_ttl line */
1225 else if (!strcmp(token, "positive_dns_ttl"))
1226 parsePositiveDnsLine();
1227
090089c4 1228 /* Parse a read_timeout line */
1229 else if (!strcmp(token, "read_timeout"))
3003c0f3 1230 parseReadTimeoutLine();
090089c4 1231
1232 /* Parse a clean_rate line */
1233 else if (!strcmp(token, "clean_rate"))
3003c0f3 1234 parseCleanRateLine();
090089c4 1235
1236 /* Parse a client_lifetime line */
1237 else if (!strcmp(token, "client_lifetime"))
3003c0f3 1238 parseLifetimeLine();
090089c4 1239
605ba5ca 1240 /* Parse a client_lifetime line */
1241 else if (!strcmp(token, "shutdown_lifetime"))
1242 parseShutdownLifetimeLine();
1243
fa966b74 1244 /* Parse a request_size line */
1245 else if (!strcmp(token, "request_size"))
3003c0f3 1246 parseRequestSizeLine();
fa966b74 1247
090089c4 1248 /* Parse a connect_timeout line */
1249 else if (!strcmp(token, "connect_timeout"))
3003c0f3 1250 parseConnectTimeout();
090089c4 1251
1252 /* Parse a cache_ftp_program line */
1253 else if (!strcmp(token, "cache_ftp_program"))
3003c0f3 1254 parseFtpProgramLine();
090089c4 1255
1256 /* Parse a cache_ftp_options line */
1257 else if (!strcmp(token, "cache_ftp_options"))
3003c0f3 1258 parseFtpOptionsLine();
090089c4 1259
1260 /* Parse a cache_dns_program line */
1261 else if (!strcmp(token, "cache_dns_program"))
3003c0f3 1262 parseDnsProgramLine();
090089c4 1263
1264 /* Parse a cache_dns_program line */
1265 else if (!strcmp(token, "dns_children"))
3003c0f3 1266 parseDnsChildrenLine();
090089c4 1267
1268 /* Parse source_ping line */
1269 else if (!strcmp(token, "source_ping"))
3003c0f3 1270 parseSourcePingLine();
090089c4 1271
090089c4 1272 /* Parse quick_abort line */
1273 else if (!strcmp(token, "quick_abort"))
3003c0f3 1274 parseQuickAbortLine();
090089c4 1275
090089c4 1276 /* Parse emulate_httpd_log line */
1277 else if (!strcmp(token, "emulate_httpd_log"))
3003c0f3 1278 parseEmulateLine();
090089c4 1279
1280 else if (!strcmp(token, "append_domain"))
3003c0f3 1281 parseAppendDomainLine();
090089c4 1282
090089c4 1283 else if (!strcmp(token, "wais_relay"))
3003c0f3 1284 parseWAISRelayLine();
090089c4 1285
1286 /* Parse a local_ip line */
1287 else if (!strcmp(token, "local_ip"))
3003c0f3 1288 parseLocalIPLine();
090089c4 1289
1290 /* Parse a local_domain line */
1291 else if (!strcmp(token, "local_domain"))
3003c0f3 1292 parseLocalDomainLine();
090089c4 1293
1294 /* Parse a bind_address line */
1295 else if (!strcmp(token, "bind_address"))
3003c0f3 1296 parseBindAddressLine();
090089c4 1297
1298 /* Parse a ascii_port line */
1299 else if (!strcmp(token, "ascii_port"))
3003c0f3 1300 parseAsciiPortLine();
090089c4 1301
1302 /* Parse a udp_port line */
1303 else if (!strcmp(token, "udp_port"))
3003c0f3 1304 parseUdpPortLine();
090089c4 1305
1306 else if (!strcmp(token, "inside_firewall"))
3003c0f3 1307 parseInsideFirewallLine();
090089c4 1308
605ba5ca 1309 else if (!strcmp(token, "dns_testnames"))
1310 parseDnsTestnameLine();
1311
090089c4 1312 else if (!strcmp(token, "single_parent_bypass"))
3003c0f3 1313 parseSingleParentBypassLine();
090089c4 1314
12b9e9b1 1315 else if (!strcmp(token, "debug_options"))
3003c0f3 1316 parseDebugOptionsLine();
12b9e9b1 1317
ccff9601 1318 else if (!strcmp(token, "pid_filename"))
3003c0f3 1319 parsePidFilenameLine();
ccff9601 1320
cf5fd929 1321 else if (!strcmp(token, "visible_hostname"))
3003c0f3 1322 parseVisibleHostnameLine();
cf5fd929 1323
fb263c4c 1324 else if (!strcmp(token, "ftp_user"))
3003c0f3 1325 parseFtpUserLine();
fb263c4c 1326
7d49daab 1327 else if (!strcmp(token, "cache_announce"))
3003c0f3 1328 parseCacheAnnounceLine();
7d49daab 1329
1330 else if (!strcmp(token, "announce_to"))
3003c0f3 1331 parseAnnounceToLine();
7d49daab 1332
090089c4 1333 /* If unknown, treat as a comment line */
1334 else {
540830c4 1335 debug(3, 0, "parseConfigFile: line %d unrecognized: '%s'\n",
92a6f4b1 1336 config_lineno,
1337 config_input_line);
090089c4 1338 }
1339 }
1340
1341 /* Add INADDR_ANY to end of bind_addr_list as last chance */
0ffd22bc 1342 wordlistAdd(&Config.bind_addr_list, "0.0.0.0");
090089c4 1343
1344 /* Sanity checks */
1345 if (getClientLifetime() < getReadTimeout()) {
1346 printf("WARNING: client_lifetime (%d seconds) is less than read_timeout (%d seconds).\n",
1347 getClientLifetime(), getReadTimeout());
1348 printf(" This may cause serious problems with your cache!!!\n");
b8de7ebe 1349 printf(" Change your configuration file.\n");
090089c4 1350 fflush(stdout); /* print message */
1351 }
1352 if (getCacheSwapMax() < (getCacheMemMax() >> 10)) {
1353 printf("WARNING: cache_swap (%d kbytes) is less than cache_mem (%d bytes).\n", getCacheSwapMax(), getCacheMemMax());
1354 printf(" This will cause serious problems with your cache!!!\n");
b8de7ebe 1355 printf(" Change your configuration file.\n");
090089c4 1356 Config.Swap.maxSize = getCacheMemMax() >> 10;
b8de7ebe 1357 printf(" For this run, however, %s will use %d kbytes for cache_swap.\n", appname, getCacheSwapMax());
090089c4 1358 fflush(stdout); /* print message */
1359 }
1360 if (getCleanRate() > -1 && getCleanRate() < 60) {
1361 Config.cleanRate = (30 * 60);
1362 printf("WARNING: clean_rate is less than one minute.\n");
1363 printf(" This will cause serious problems with your cache!!!\n");
b8de7ebe 1364 printf(" Change your configuration file.\n");
1365 printf(" For this run, however, %s will use %d minutes for clean_rate.\n", appname, (int) (getCleanRate() / 60));
090089c4 1366 fflush(stdout); /* print message */
1367 }
090089c4 1368 if (getDnsChildren() < 1) {
1369 printf("WARNING: dns_children was set to a bad value: %d\n",
1370 getDnsChildren());
1371 printf("Setting it to the default (3).\n");
1372 Config.dnsChildren = 3;
1373 } else if (getDnsChildren() > DefaultDnsChildrenMax) {
1374 printf("WARNING: dns_children was set to a bad value: %d\n",
1375 getDnsChildren());
1376 printf("Setting it to the maximum (%d).\n", DefaultDnsChildrenMax);
1377 Config.dnsChildren = DefaultDnsChildrenMax;
1378 }
1379 fclose(fp);
1380
1381 configDoConfigure();
1382 return 0;
1383}
1384
1385
090089c4 1386
1387int getHttpMax()
1388{
1389 return Config.Http.maxObjSize;
1390}
090089c4 1391int getHttpTTL()
1392{
1393 return Config.Http.defaultTtl;
1394}
090089c4 1395int getGopherMax()
1396{
1397 return Config.Gopher.maxObjSize;
1398}
090089c4 1399int getGopherTTL()
1400{
1401 return Config.Gopher.defaultTtl;
1402}
090089c4 1403int getWAISMax()
1404{
1405 return Config.Wais.maxObjSize;
1406}
1407char *getWaisRelayHost()
1408{
1409 return Config.Wais.relayHost;
1410}
1411int getWaisRelayPort()
1412{
1413 return Config.Wais.relayPort;
1414}
090089c4 1415int getFtpMax()
1416{
1417 return Config.Ftp.maxObjSize;
1418}
090089c4 1419int getFtpTTL()
1420{
1421 return Config.Ftp.defaultTtl;
1422}
090089c4 1423int getNegativeTTL()
1424{
1425 return Config.negativeTtl;
1426}
61d6fc5c 1427int getNegativeDNSTTL()
1428{
1429 return Config.negativeDnsTtl;
1430}
090089c4 1431int getCacheMemMax()
1432{
1433 return Config.Mem.maxSize;
1434}
090089c4 1435int getCacheMemHighWaterMark()
1436{
1437 return Config.Mem.highWatherMark;
1438}
090089c4 1439int getCacheMemLowWaterMark()
1440{
1441 return Config.Mem.lowWaterMark;
1442}
090089c4 1443double getCacheHotVmFactor()
1444{
1445 return Config.hotVmFactor;
1446}
090089c4 1447int getCacheSwapHighWaterMark()
1448{
1449 return Config.Swap.highWatherMark;
1450}
090089c4 1451int getCacheSwapLowWaterMark()
1452{
1453 return Config.Swap.lowWaterMark;
1454}
090089c4 1455int getCacheSwapMax()
1456{
1457 return Config.Swap.maxSize;
1458}
090089c4 1459int setCacheSwapMax(size)
1460 int size;
1461{
1462 Config.Swap.maxSize = size;
1463 return Config.Swap.maxSize;
1464}
090089c4 1465int getReadTimeout()
1466{
1467 return Config.readTimeout;
1468}
090089c4 1469int getClientLifetime()
1470{
1471 return Config.lifetimeDefault;
1472}
605ba5ca 1473int getShutdownLifetime()
1474{
1475 return Config.lifetimeShutdown;
1476}
fa966b74 1477int getMaxRequestSize()
1478{
1479 return Config.maxRequestSize;
1480}
090089c4 1481int getConnectTimeout()
1482{
1483 return Config.connectTimeout;
1484}
090089c4 1485int getCleanRate()
1486{
1487 return Config.cleanRate;
1488}
090089c4 1489int getSourcePing()
1490{
1491 return Config.sourcePing;
1492}
090089c4 1493int getDnsChildren()
1494{
1495 return Config.dnsChildren;
1496}
090089c4 1497int getQuickAbort()
1498{
1499 return Config.quickAbort;
1500}
090089c4 1501char *getAccelPrefix()
1502{
1503 return Config.Accel.prefix;
1504}
1505int getAccelWithProxy()
1506{
1507 return Config.Accel.withProxy;
1508}
1509char *getAccessLogFile()
1510{
1511 return Config.Log.access;
1512}
1513char *getHierarchyLogFile()
1514{
1515 return Config.Log.hierarchy;
1516}
d8b45066 1517char *getStoreLogFile()
1518{
1519 return Config.Log.store;
1520}
090089c4 1521int getLogfileRotateNumber()
1522{
1523 return Config.Log.rotateNumber;
1524}
1525char *getCacheLogFile()
1526{
1527 return Config.Log.log;
1528}
1529int getAsciiPortNum()
1530{
1531 return Config.Port.ascii;
1532}
090089c4 1533int getUdpPortNum()
1534{
1535 return Config.Port.udp;
1536}
1537char *getDnsProgram()
1538{
1539 return Config.Program.dnsserver;
1540}
1541char *getFtpProgram()
1542{
1543 return Config.Program.ftpget;
1544}
1545char *getFtpOptions()
1546{
1547 return Config.Program.ftpget_opts;
1548}
1549char *getAdminEmail()
1550{
1551 return Config.adminEmail;
1552}
12b9e9b1 1553char *getDebugOptions()
090089c4 1554{
12b9e9b1 1555 return Config.debugOptions;
090089c4 1556}
e5c22962 1557int getStallDelay()
1558{
1559 return Config.stallDelay;
1560}
090089c4 1561char *getAppendDomain()
1562{
1563 return Config.appendDomain;
1564}
12b9e9b1 1565char *getEffectiveUser()
1566{
1567 return Config.effectiveUser;
1568}
1569char *getEffectiveGroup()
1570{
1571 return Config.effectiveGroup;
1572}
ccff9601 1573char *getPidFilename()
1574{
1575 return Config.pidFilename;
1576}
cf5fd929 1577char *getVisibleHostname()
1578{
1579 return Config.visibleHostname;
1580}
fb263c4c 1581char *getFtpUser()
1582{
1583 return Config.ftpUser;
1584}
7d49daab 1585char *getAnnounceHost()
1586{
1587 return Config.Announce.host;
1588}
1589int getAnnouncePort()
1590{
1591 return Config.Announce.port;
1592}
1593char *getAnnounceFile()
1594{
1595 return Config.Announce.file;
1596}
1597int getAnnounceRate()
1598{
1599 return Config.Announce.rate;
1600}
84c6cc9f 1601wordlist *getHttpStoplist()
0ffd22bc 1602{
1603 return Config.http_stoplist;
1604}
84c6cc9f 1605wordlist *getFtpStoplist()
0ffd22bc 1606{
1607 return Config.ftp_stoplist;
1608}
84c6cc9f 1609wordlist *getGopherStoplist()
0ffd22bc 1610{
1611 return Config.gopher_stoplist;
1612}
84c6cc9f 1613wordlist *getLocalDomainList()
0ffd22bc 1614{
1615 return Config.local_domain_list;
1616}
84c6cc9f 1617wordlist *getCacheDirs()
0ffd22bc 1618{
1619 return Config.cache_dirs;
1620}
84c6cc9f 1621wordlist *getInsideFirewallList()
0ffd22bc 1622{
1623 return Config.inside_firewall_list;
1624}
605ba5ca 1625wordlist *getDnsTestnameList()
1626{
1627 return Config.dns_testname_list;
1628}
84c6cc9f 1629wordlist *getBindAddrList()
0ffd22bc 1630{
1631 return Config.bind_addr_list;
1632}
ccff9601 1633
090089c4 1634int setAsciiPortNum(p)
1635 int p;
1636{
1637 return (Config.Port.ascii = p);
1638}
1639int setUdpPortNum(p)
1640 int p;
1641{
1642 return (Config.Port.udp = p);
1643}
090089c4 1644
1645
1646char *safe_xstrdup(p)
1647 char *p;
1648{
1649 return p ? xstrdup(p) : p;
1650}
1651
1652int safe_strlen(p)
1653 char *p;
1654{
1655 return p ? strlen(p) : -1;
1656}
1657
0ffd22bc 1658static void configFreeMemory()
1659{
1660 safe_free(Config.Wais.relayHost);
1661 safe_free(Config.Log.log);
1662 safe_free(Config.Log.access);
1663 safe_free(Config.Log.hierarchy);
983061ed 1664 safe_free(Config.Log.store);
0ffd22bc 1665 safe_free(Config.adminEmail);
1666 safe_free(Config.effectiveUser);
1667 safe_free(Config.effectiveGroup);
1668 safe_free(Config.Program.ftpget);
1669 safe_free(Config.Program.ftpget_opts);
1670 safe_free(Config.Program.dnsserver);
1671 safe_free(Config.Accel.host);
1672 safe_free(Config.Accel.prefix);
1673 safe_free(Config.appendDomain);
1674 safe_free(Config.debugOptions);
1675 safe_free(Config.pidFilename);
1676 safe_free(Config.visibleHostname);
1677 safe_free(Config.ftpUser);
1678 safe_free(Config.Announce.host);
1679 safe_free(Config.Announce.file);
1680 wordlistDestroy(&Config.cache_dirs);
1681 wordlistDestroy(&Config.http_stoplist);
1682 wordlistDestroy(&Config.gopher_stoplist);
1683 wordlistDestroy(&Config.ftp_stoplist);
1684 wordlistDestroy(&Config.bind_addr_list);
1685 wordlistDestroy(&Config.local_domain_list);
1686 wordlistDestroy(&Config.inside_firewall_list);
605ba5ca 1687 wordlistDestroy(&Config.dns_testname_list);
0ffd22bc 1688}
1689
090089c4 1690
1691static void configSetFactoryDefaults()
1692{
1693 Config.Mem.maxSize = DefaultMemMaxSize;
1694 Config.Mem.highWatherMark = DefaultMemHighWatherMark;
1695 Config.Mem.lowWaterMark = DefaultMemLowWatherMark;
1696 Config.Swap.maxSize = DefaultSwapMaxSize;
1697 Config.Swap.highWatherMark = DefaultSwapHighWaterMark;
1698 Config.Swap.lowWaterMark = DefaultSwapLowWaterMark;
1699
1700 Config.Ftp.defaultTtl = DefaultFtpDefaultTtl;
1701 Config.Ftp.maxObjSize = DefaultFtpMaxObjSize;
1702 Config.Gopher.defaultTtl = DefaultGopherDefaultTtl;
1703 Config.Gopher.maxObjSize = DefaultGopherMaxObjSize;
1704 Config.Http.defaultTtl = DefaultHttpDefaultTtl;
1705 Config.Http.maxObjSize = DefaultHttpMaxObjSize;
090089c4 1706 Config.Wais.defaultTtl = DefaultWaisDefaultTtl;
1707 Config.Wais.maxObjSize = DefaultWaisMaxObjSize;
1708 Config.Wais.relayHost = safe_xstrdup(DefaultWaisRelayHost);
1709 Config.Wais.relayPort = DefaultWaisRelayPort;
090089c4 1710
1711 Config.negativeTtl = DefaultNegativeTtl;
2639dac6 1712 Config.negativeDnsTtl = DefaultNegativeDnsTtl;
1713 Config.positiveDnsTtl = DefaultPositiveDnsTtl;
090089c4 1714 Config.readTimeout = DefaultReadTimeout;
1715 Config.lifetimeDefault = DefaultLifetimeDefault;
605ba5ca 1716 Config.lifetimeShutdown = DefaultLifetimeShutdown;
fa966b74 1717 Config.maxRequestSize = DefaultMaxRequestSize;
090089c4 1718 Config.connectTimeout = DefaultConnectTimeout;
1719 Config.ageMaxDefault = DefaultDefaultAgeMax;
1720 Config.cleanRate = DefaultCleanRate;
1721 Config.dnsChildren = DefaultDnsChildren;
1722 Config.hotVmFactor = DefaultHotVmFactor;
1723 Config.sourcePing = DefaultSourcePing;
1724 Config.quickAbort = DefaultQuickAbort;
1725 Config.commonLogFormat = DefaultCommonLogFormat;
12b9e9b1 1726 Config.debugOptions = safe_xstrdup(DefaultDebugOptions);
090089c4 1727 Config.neighborTimeout = DefaultNeighborTimeout;
e5c22962 1728 Config.stallDelay = DefaultStallDelay;
090089c4 1729 Config.singleParentBypass = DefaultSingleParentBypass;
1730 Config.adminEmail = safe_xstrdup(DefaultAdminEmail);
1731 Config.effectiveUser = safe_xstrdup(DefaultEffectiveUser);
1732 Config.effectiveGroup = safe_xstrdup(DefaultEffectiveGroup);
1733 Config.appendDomain = safe_xstrdup(DefaultAppendDomain);
1734
1735 Config.Port.ascii = DefaultAsciiPortNum;
090089c4 1736 Config.Port.udp = DefaultUdpPortNum;
1737 Config.Log.log = safe_xstrdup(DefaultCacheLogFile);
1738 Config.Log.access = safe_xstrdup(DefaultAccessLogFile);
1739 Config.Log.hierarchy = safe_xstrdup(DefaultHierarchyLogFile);
d8b45066 1740 Config.Log.store = safe_xstrdup(DefaultStoreLogFile);
090089c4 1741 Config.Log.rotateNumber = DefaultLogRotateNumber;
1742 Config.Program.ftpget = safe_xstrdup(DefaultFtpgetProgram);
1743 Config.Program.ftpget_opts = safe_xstrdup(DefaultFtpgetOptions);
1744 Config.Program.dnsserver = safe_xstrdup(DefaultDnsserverProgram);
1745 Config.Accel.host = safe_xstrdup(DefaultAccelHost);
1746 Config.Accel.prefix = safe_xstrdup(DefaultAccelPrefix);
1747 Config.Accel.port = DefaultAccelPort;
1748 Config.Accel.withProxy = DefaultAccelWithProxy;
ccff9601 1749 Config.pidFilename = safe_xstrdup(DefaultPidFilename);
cf5fd929 1750 Config.visibleHostname = safe_xstrdup(DefaultVisibleHostname);
fb263c4c 1751 Config.ftpUser = safe_xstrdup(DefaultFtpUser);
7d49daab 1752 Config.Announce.host = safe_xstrdup(DefaultAnnounceHost);
1753 Config.Announce.port = DefaultAnnouncePort;
1754 Config.Announce.file = safe_xstrdup(DefaultAnnounceFile);
1755 Config.Announce.rate = DefaultAnnounceRate;
090089c4 1756}
1757
1758static void configDoConfigure()
1759{
1760 httpd_accel_mode = Config.Accel.prefix ? 1 : 0;
1761 emulate_httpd_log = Config.commonLogFormat;
1762 neighbor_timeout = (time_t) Config.neighborTimeout;
1763 single_parent_bypass = Config.singleParentBypass;
2639dac6 1764 DnsPositiveTtl = Config.positiveDnsTtl;
090089c4 1765
1766#if !ALLOW_HOT_CACHE
1767 if (!httpd_accel_mode || Config.Accel.withProxy) {
1768 /* Not running strict httpd_accel--force hot_vm_factor to be 0 */
1769 if (Config.hotVmFactor != 0.0) {
1770 printf("WARNING: Non-zero hot_vm_factor not allowed unless running only\n");
1771 printf(" in httpd_accel mode. Setting hot_vm_factor to 0.\n");
1772 Config.hotVmFactor = 0.0;
1773 }
1774 }
1775#endif /* !ALLOW_HOT_CACHE */
1776}