1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
|
/*
libutil -- read config file
Written by Arnt Gulbrandsen <agulbra@troll.no> and copyright 1995
Troll Tech AS, Postboks 6133 Etterstad, 0602 Oslo, Norway, fax +47
22646949.
Modified by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>
and Randolf Skerka <Randolf.Skerka@gmx.de>.
Copyright of the modifications 1997.
Modified by Kent Robotti <robotti@erols.com>. Copyright of the
modifications 1998.
Modified by Markus Enzenberger <enz@cip.physik.uni-muenchen.de>.
Copyright of the modifications 1998.
Modified by Cornelius Krasel <krasel@wpxx02.toxi.uni-wuerzburg.de>.
Copyright of the modifications 1998, 1999.
Modified and copyright of the modifications 2002 by Ralf Wildenhues
<ralf.wildenhues@gmx.de>.
Modified and copyright of the modifications 2001 - 2003 by Matthias Andree
<matthias.andree@web.de>.
See file COPYING for restrictions on the use of this software.
*/
#include "leafnode.h"
#include "validatefqdn.h"
#include "ln_log.h"
#include "strlcpy.h"
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <limits.h>
#include <netdb.h>
#include <netinet/in.h>
#ifndef __LCLINT__
#include <arpa/inet.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <sys/stat.h>
#include <sys/resource.h>
#define COREFILESIZE 1024*1024*64
#define TOKENSIZE 4096
#include "groupselect.h"
#ifndef min
#define min(a,b) ((a < b) ? (a) : (b))
#endif
/*
* misc. global variables, documented in leafnode.h
*/
time_t expire = 0;
int expiredays = 0;
struct expire_entry *expire_base;
unsigned long artlimit = 0;
unsigned long initiallimit = 0;
long crosspostlimit = 0;
int create_all_links = 0;
int delaybody = 0;
int db_situ = 0;
int debugmode = 0; /* if 1, log lots of stuff via syslog */
int maxage = 10;
int article_despite_filter = 0;
long maxlines = 0;
long minlines = 0;
unsigned long maxbytes = 0;
static int linebuffer = 0; /* if 1, make stdout and stderr explicitly
line buffered, GNU libc makes them fully buffered
if redirected to files */
int timeout_long = 7;
int timeout_short = 2;
int timeout_active = 90;
int timeout_client = 15*60; /* when newsreader is idle for this many seconds, disconnect */
int timeout_fetchnews = 5*60; /* wait at most this many seconds for server replies in fetchnews */
int clamp_maxage = 1; /* if 1, maxage will be lowered to
* groupexpire or expire if the
* applicable parameter is lower than
* maxage, to prevent duplicate fetches
* after a premature exit of
* fetchnews. */
int allowstrangers = 0;
char *filterfile;
struct server *servers = NULL;
int allow_8bit_headers = 0;
char *newsadmin;
unsigned long timeout_lock = 5UL;
/** parse the line in \a l, breaking it into param and value at the "="
* delimiter. The right-hand side can be quoted with double quotes,
* inside these a backslash escapes a quote that is part of the string.
* \return success
*/
static int parse_line(
/*@unique@*/ char *l /** input, will be modified */,
/*@out@*/ char *param /** output, left-hand side */,
/*@out@*/ char *value /** output, right-hand side */);
/* parse a line, destructively */
static int
parse_line(char *l, char *param, char *value)
{
char *p;
size_t le, len;
enum modes { plain, quoted } mode = plain;
p = l;
/* skip leading spaces, read parameter */
SKIPLWS(p);
le = strcspn(p, "=#");
/* strip trailing space */
while(le && strchr(" \t", p[le-1])) le--;
len = min(le, TOKENSIZE - 1);
if (!len) return 0;
memcpy(param, p, len);
param[len] = '\0';
p += le;
SKIPLWS(p);
if (*p++ != '=')
return 0;
SKIPLWS(p);
/* strip trailing blanks from input */
le = strlen(p);
while (le--) {
if (p[le] == ' ' || p[le] == '\t')
p[le] = '\0';
else
break;
}
/* read value */
for (le = 0 ; le < TOKENSIZE - 1 ; le ++) {
char c = *p++;
if (mode == plain) {
if (c == '#' || c == '\0') { break; }
if (c == '"') { mode = quoted; continue; }
*value++ = c;
} else if (mode == quoted) {
if (c == '\\') {
if (*p) {
*value++ = *p++; continue;
} else
return 0;
}
if (c == '\0') return 0;
if (c == '"') break;
*value++ = c;
} else {
abort();
}
}
*value = '\0';
return 1;
}
/*
05/25/97 - T. Sweeney - Modified to read user name and password for AUTHINFO.
Security questionable as password is stored in
plaintext in insecure file.
1999-07-15 - Matthias Andree
Set p and q defaults to 0
*/
/* parses value into timeout_lock, returns 0 for success, -1 for error */
static int read_timeout_lock(
const char *value, /* input */
const char *source /* where did value come from */) {
char *t;
unsigned long u;
errno = 0;
u = strtoul(value, &t, 10);
if ((u != 0 || errno == 0)
&& t > value
&& (!*t || isspace((unsigned char)*t)))
{
timeout_lock = u;
if (debugmode) {
if (timeout_lock) {
syslog(LOG_DEBUG,
"%s: waiting %lu second%s for lockfile",
source, timeout_lock, PLURAL(timeout_lock));
} else {
syslog(LOG_DEBUG,
"%s: waiting indefinitely for lockfile", source);
}
}
return 0;
} else {
ln_log(LNLOG_SERR, LNLOG_CTOP, "error: cannot parse lockfile value \"%s\" from %s", value, source);
return -1;
}
}
int
readconfig(int logtostderr)
{
struct server *p = 0, *q = 0;
struct rlimit corelimit;
struct expire_entry *ent = NULL, *prev = NULL;
FILE *f;
char *l;
char *param, *value;
char s[SIZE_s + 1];
unsigned long curline = 0;
artlimit = 0;
param = critmalloc(TOKENSIZE, "allocating space for parsing");
value = critmalloc(TOKENSIZE, "allocating space for parsing");
xsnprintf(s, SIZE_s, "%s/config", sysconfdir);
if ((f = fopen(s, "r")) == NULL) {
syslog(LOG_ERR, "cannot open %s", s);
free(param);
free(value);
return 0;
}
while ((l = getaline(f))) {
++curline;
if (parse_line(l, param, value)) {
if (strcmp("username", param) == 0) {
if (p) {
if (p->username != NULL)
free(p->username);
p->username = critstrdup(value, "readconfig");
if (debugmode)
syslog(LOG_DEBUG, "config: found username for %s",
p->name);
} else
syslog(LOG_ERR, "config: no server for username %s", value);
} else if (strcmp("password", param) == 0) {
if (p) {
if (p->password != NULL)
free(p->password);
p->password = critstrdup(value, "readconfig");
if (debugmode)
syslog(LOG_DEBUG, "config: found password for %s",
p->name);
} else
syslog(LOG_ERR, "config: no server for password");
} else if (strcmp("timeout", param) == 0) {
if (p) {
p->timeout = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: timeout is %d second%s",
p->timeout, PLURAL(p->timeout));
} else
syslog(LOG_ERR, "config: no server for timeout");
} else if (strcmp("allowSTRANGERS", param) == 0) {
if (value && strlen(value)) {
if (atoi(value) == 42)
allowstrangers = 1;
syslog(LOG_DEBUG,
"config: allowstrangers is %s",
allowstrangers ? "set" : "unset");
}
} else if (strcmp("create_all_links", param) == 0) {
if (value && strlen(value)) {
create_all_links = atoi(value);
if (create_all_links && debugmode)
syslog(LOG_DEBUG,
"config: link articles in all groups");
}
} else if (strcmp("expire", param) == 0) {
int i = atoi(value);
if (i >= (INT_MAX / SECONDS_PER_DAY))
i = (INT_MAX / SECONDS_PER_DAY) - 1;
if (i <= 0) {
ln_log(LNLOG_SERR, LNLOG_CTOP, "config: expire must be positive, not %d, abort", i);
exit(1);
}
expiredays = i;
expire = time(NULL) - (time_t) (SECONDS_PER_DAY * i);
if (debugmode)
syslog(LOG_DEBUG, "config: expire is %d day%s", i, PLURAL(i));
} else if (strcmp("newsadmin", param) == 0) {
if (debugmode)
syslog(LOG_DEBUG, "config: newsadmin is %s", value);
newsadmin = critstrdup(value, "readconfig");
} else if (strcmp("filterfile", param) == 0) {
if (debugmode)
syslog(LOG_DEBUG, "config: filterfile is %s", value);
filterfile = critstrdup(value, "readconfig");
} else if ((strcmp("hostname", param) == 0) ||
(strcmp("fqdn", param) == 0)) {
if (is_validfqdn(value)) {
if (debugmode)
syslog(LOG_DEBUG, "config: hostname is %s", value);
(void)xstrlcpy(fqdn, value, sizeof(fqdn));
} else {
ln_log(LNLOG_SCRIT, LNLOG_CTOP, "config: hostname %s is "
"not a valid fully-qualified domain name, exit.",
value);
exit(1);
}
} else if ((strcmp("maxcrosspost", param) == 0) ||
(strcmp("maxgroups", param) == 0)) {
/* maxgroups is for compatibility with leafnode+ */
crosspostlimit = strtol(value, NULL, 10);
if (debugmode)
syslog(LOG_DEBUG, "config: crosspostlimit is %ld group%s",
crosspostlimit, PLURAL(crosspostlimit));
} else if (strcmp("article_despite_filter", param) == 0) {
article_despite_filter = atoi(value) ? 1 : 0;
if (debugmode)
syslog(LOG_DEBUG, "config: article_despite_filter is %s",
article_despite_filter ? "TRUE" : "FALSE");
} else if (strcmp("clamp_maxage", param) == 0) {
clamp_maxage = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: clamp_maxage is %s",
clamp_maxage ? "TRUE" : "FALSE");
} else if (strcmp("maxlines", param) == 0) {
maxlines = strtol(value, NULL, 10);
if (debugmode)
syslog(LOG_DEBUG, "config: postings have max. %ld line%s",
maxlines, PLURAL(maxlines));
} else if (strcmp("minlines", param) == 0) {
minlines = strtol(value, NULL, 10);
if (debugmode)
syslog(LOG_DEBUG, "config: postings have min. %ld line%s",
minlines, PLURAL(minlines));
} else if (strcmp("maxbytes", param) == 0) {
maxbytes = strtoul(value, NULL, 10);
if (debugmode)
syslog(LOG_DEBUG,
"config: postings have max. %lu byte%s",
maxbytes, PLURAL(maxbytes));
} else if (strcmp("linebuffer", param) == 0) {
linebuffer = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: linebuffer is %d", linebuffer);
} else if (strcmp("allow_8bit_headers", param) == 0) {
allow_8bit_headers = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: allow_8bit_headers is %d",
allow_8bit_headers);
} else if (strcmp("debugmode", param) == 0) {
int d;
d = atoi(value);
debugmode = d > debugmode ? d : debugmode;
if (debugmode)
syslog(LOG_DEBUG, "config: debugmode is %d", debugmode);
} else if (strcmp("delaybody_in_situ", param) == 0) {
db_situ = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: delaybody_in_situ is %d (default 0)",
db_situ);
} else if (strcmp("delaybody", param) == 0) {
delaybody = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: delaybody is %d (default 0)",
delaybody);
} else if (strcmp("timeout_short", param) == 0) {
timeout_short = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: timeout_short is %d day%s",
timeout_short, PLURAL(timeout_short));
} else if (strcmp("timeout_long", param) == 0) {
timeout_long = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: timeout_long is %d day%s",
timeout_long, PLURAL(timeout_long));
} else if (strcmp("timeout_active", param) == 0) {
timeout_active = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: timeout_active is %d day%s",
timeout_active, PLURAL(timeout_active));
} else if (strcmp("timeout_client", param) == 0) {
timeout_client = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: timeout_client is %d second%s",
timeout_client, PLURAL(timeout_client));
} else if (strcmp("timeout_fetchnews", param) == 0) {
timeout_fetchnews = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: timeout_fetchnews is %d second%s",
timeout_fetchnews, PLURAL(timeout_fetchnews));
} else if (strcmp("timeout_lock", param) == 0) {
read_timeout_lock(value, "config");
} else if (strncmp("groupexpire", param, 11) == 0) {
char *m;
m = param;
while (*m && !(isspace((unsigned char)*m)))
m++;
while (isspace((unsigned char)*m))
m++;
if (m && *m) {
time_t e, i = (time_t) atol(value);
if (i >= (INT_MAX / SECONDS_PER_DAY))
i = (INT_MAX / SECONDS_PER_DAY) - 1;
if (debugmode) {
if ((long)i < 0)
syslog(LOG_DEBUG,
"config: groupexpire for %s is %ld (never)",
m, (long)i);
else if (i == 0) {
fprintf(stderr,
"config: groupexpire for %s is 0, which is treated as \"use the default expire\"\n", m);
syslog(LOG_INFO,
"config: groupexpire for %s is 0, which is treated as \"use the default expire\"",
m);
} else
syslog(LOG_DEBUG,
"config: groupexpire for %s is %ld day%s",
m, (long)i, PLURAL(i));
}
e = time(NULL) - (time_t) (SECONDS_PER_DAY * i);
ent = (struct expire_entry *)
critmalloc(sizeof(struct expire_entry), "readconfig");
ent->group = critstrdup(m, "readconfig");
ent->days = i;
ent->xtime = e;
ent->next = prev;
prev = ent;
}
} else if ((strcmp("maxage", param) == 0) ||
(strcmp("maxold", param) == 0)) {
/* maxold is for compatibility with leafnode+ */
maxage = atoi(value);
if (maxage > LONG_MAX / 86400) {
maxage = 24854; /* 32-bit: LONG_MAX / 86400 - 1 */
ln_log(LNLOG_SWARNING, LNLOG_CTOP,
"warning: config: maxage cannot exceed %d, "
"please fix %s", maxage, s);
}
if (debugmode)
syslog(LOG_DEBUG, "config: maxage is %d", maxage);
} else if (strcmp("maxfetch", param) == 0) {
artlimit = strtoul(value, NULL, 10);
if (debugmode)
syslog(LOG_DEBUG, "config: maxfetch is %lu", artlimit);
} else if (strcmp("port", param) == 0) {
unsigned long pp = strtoul(value, NULL, 10);
if (p) {
if (pp == 0 || pp > 65535) {
syslog(LOG_ERR,
"config: invalid port number for nntpport %s",
value);
} else {
p->port = (unsigned int)pp;
if (debugmode)
syslog(LOG_DEBUG, "config: nntpport is %u",
p->port);
}
} else {
syslog(LOG_ERR, "config: no server for nntpport %s", value);
}
} else if (strcmp("noactive", param) == 0) {
if (p) {
p->updateactive = FALSE;
if (debugmode)
syslog(LOG_DEBUG, "config: no active file updates for %s",
p->name);
} else
syslog(LOG_ERR, "config: no server for noactive = %s",
value);
} else if (strcmp("noxover", param) == 0) {
if (p) {
p->noxover = TRUE;
if (debugmode)
syslog(LOG_DEBUG, "config: no XOVER for %s",
p->name);
} else
syslog(LOG_ERR, "config: no server for noxover = %s", value);
} else if (strcmp("nodesc", param) == 0) {
if (p) {
p->descriptions = FALSE;
if (debugmode)
syslog(LOG_DEBUG, "config: no LIST NEWSGROUPS for %s",
p->name);
} else
syslog(LOG_ERR, "config: no server for nodesc = %s", value);
} else if (strcmp("nopost", param) == 0) {
if (p) {
p->nopost = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: nopost for %s is %d",
p->name, p->nopost);
} else
syslog(LOG_ERR, "config: no server for nopost = %s", value);
} else if (strcmp("post_anygroup", param) == 0) {
if (p) {
p->post_anygroup = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: post_anygroup for %s is %d",
p->name, p->nopost);
} else
syslog(LOG_ERR, "config: no server for post_anygroup = %s", value);
} else if (strcmp("noread", param) == 0) {
if (p) {
p->noread = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: noread for %s is %d",
p->name, p->noread);
} else
syslog(LOG_ERR, "config: no server for noread = %s", value);
} else if (strcmp("only_groups_match_all", param) == 0) {
if (p) {
p->only_groups_match_all = atoi(value);
if (debugmode)
syslog(LOG_DEBUG, "config: only_groups_match_all for %s is %d",
p->name, p->only_groups_match_all);
} else
syslog(LOG_ERR, "config: no server for only_groups_match_all = %s", value);
} else if (strcmp("initialfetch", param) == 0) {
initiallimit = strtoul(value, NULL, 10);
if (debugmode)
syslog(LOG_DEBUG, "config: initialfetch is %lu",
initiallimit);
} else if ((strcmp("server", param) == 0) ||
(strcmp("supplement", param) == 0)) {
if (debugmode)
syslog(LOG_DEBUG, "config: server is %s", value);
p = (struct server *)critmalloc(sizeof(struct server),
"allocating space for server");
p->name = critstrdup(value, "readconfig");
p->descriptions = TRUE;
p->next = NULL;
p->timeout = 30; /* default 30 seconds */
p->port = 0;
p->username = NULL;
p->password = NULL;
p->nopost = 0;
p->noread = 0;
p->noxover = 0;
p->post_anygroup = 0;
p->updateactive = TRUE;
p->group_pcre = NULL;
p->only_groups_match_all = 0;
if (servers == NULL)
servers = p;
else
q->next = p;
q = p;
} else if (0 == strcmp("only_groups_pcre", param)) {
pcre *re = gs_compile(value);
if (!re) exit(2);
if (p) {
p->group_pcre = re;
if (debugmode)
syslog(LOG_DEBUG, "config: only_groups_pcre for %s is %s",
p->name, value);
} else {
free(re);
syslog(LOG_ERR, "config: no server for nopost = %s", value);
}
} else {
ln_log(LNLOG_SERR, LNLOG_CTOP,
"config: unknown line %lu: \"%s = %s\"", curline,
param, value);
}
} else {
size_t i;
if ((i = strspn(l, " \t")) < strlen(l) && l[i] != '#') {
ln_log(LNLOG_SERR, LNLOG_CTOP,
"config: malformatted line %lu: \"%s\"", curline,
l);
}
}
}
if (maxage != 0 && maxage > expiredays && clamp_maxage == 0) {
ln_log(LNLOG_SERR, LNLOG_CTOP,
"config: maxage (%d) > expire (%d). This can cause duplicate download. Please fix your configuration, maxage must not be greater than expire.",
maxage, expiredays);
exit(1);
}
debug = debugmode;
if (!newsadmin) {
const char t[] = NEWS_USER;
newsadmin = critmalloc(strlen(fqdn) + strlen(t) + 2, "readconfig");
strcpy(newsadmin, t); /* RATS: ignore */
strcat(newsadmin, "@");
strcat(newsadmin, fqdn); /* RATS: ignore */
}
expire_base = ent;
fclose(f);
free(param);
free(value);
if (servers == NULL) {
syslog(LOG_ERR, "no server declaration in config file");
return 0;
}
if (!expire)
syslog(LOG_ERR, "no expire declaration in config file");
/* check for duplicate server configurations */
{
unsigned short port = 0;
struct servent *sp = getservbyname("nntp", "tcp");
if (sp) port = ntohs(sp->s_port);
for (p = servers; p ; p=p->next) {
for (q = p->next ; q ; q=q->next) {
unsigned short pp = p->port, qp = q->port;
if (!pp) pp = port;
if (!qp) qp = port;
if (!pp || !qp) {
syslog(LOG_ERR, "Cannot resolve service \"nntp\" protocol \"tcp\".");
fprintf(stderr, "Cannot resolve service \"nntp\" protocol \"tcp\".\n");
return 0;
}
if (pp != qp) continue;
if (strcasecmp(p->name, q->name)) continue;
syslog(LOG_ERR, "Duplicate definition for server %s port %hu", p->name, pp);
fprintf(stderr, "Duplicate definition for server %s port %hu\n", p->name, pp);
return 0;
}
}
}
if (debugmode > 1) {
getrlimit(RLIMIT_CORE, &corelimit);
corelimit.rlim_cur = COREFILESIZE;
if (setrlimit(RLIMIT_CORE, &corelimit) < 0)
syslog(LOG_DEBUG, "Changing core file size failed: %m");
corelimit.rlim_cur = 0;
getrlimit(RLIMIT_CORE, &corelimit);
syslog(LOG_DEBUG, "Core file size: %d", (int)corelimit.rlim_cur);
}
l = getenv("LN_LOCK_TIMEOUT");
if (l && *l)
read_timeout_lock(l, "LN_LOCK_TIMEOUT");
if (linebuffer) {
fflush(stdout);
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
fflush(stderr);
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
}
validatefqdn(logtostderr);
return 1;
}
/*
1997-05-27 - T. Sweeney - Find a group in the expireinfo linked list and return
its expire time. Otherwise, return zero.
*/
static struct expire_entry *
lookup_expireent(char *group)
{
struct expire_entry *a;
a = expire_base;
while (a != NULL) {
if (ngmatch(a->group, group) == 0)
return a;
a = a->next;
}
return NULL;
}
static void
freeserver(struct server *a) {
if (a->group_pcre) pcre_free(a->group_pcre);
if (a->name) free(a->name);
if (a->username) free(a->username);
if (a->password) free(a->password);
free(a);
}
void /* exported for exclusive use in nntpd.c */
freeservers(void) {
struct server *i = servers, *n;
while(i != NULL) {
n = i->next;
freeserver(i);
i = n;
}
servers = NULL;
}
void
freeexpire(void)
{
struct expire_entry *a, *b;
a = expire_base;
while(a)
{
b = a->next;
free(a->group);
free(a);
a = b;
}
}
void freeconfig(void) {
freeservers();
if (newsadmin)
free(newsadmin);
freefilter();
if (filterfile)
free(filterfile);
freegetaline();
freeexpire();
(void)lookup(LOOKUP_FREE);
freelastreply();
}
time_t lookup_expire(char *group)
{
struct expire_entry *e;
e = lookup_expireent(group);
if (e) return e->xtime;
return 0;
}
int lookup_expiredays(char *group)
{
struct expire_entry *e;
e = lookup_expireent(group);
if (e) return e->days;
return 0;
}
|