2
* Copyright (C) 2000, 2001 Internet Software Consortium.
2
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3
* Copyright (C) 2000-2003 Internet Software Consortium.
4
5
* Permission to use, copy, modify, and distribute this software for any
5
6
* purpose with or without fee is hereby granted, provided that the above
6
7
* copyright notice and this permission notice appear in all copies.
8
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
9
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
* PERFORMANCE OF THIS SOFTWARE.
18
/* $Id: lwconfig.c,v 1.1.1.1 2002/09/30 19:51:06 mcr Exp $ */
18
/* $Id: lwconfig.c,v 1.2 2004/09/20 18:00:36 mcr Exp $ */
21
21
*** Module for parsing resolv.conf files.
220
220
confdata->ndots = 1;
221
221
confdata->no_tld_query = 0;
223
for (i = 0 ; i < LWRES_CONFMAXNAMESERVERS ; i++)
223
for (i = 0; i < LWRES_CONFMAXNAMESERVERS; i++)
224
224
lwres_resetaddr(&confdata->nameservers[i]);
226
for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++)
226
for (i = 0; i < LWRES_CONFMAXSEARCH; i++)
227
227
confdata->search[i] = NULL;
229
for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
229
for (i = 0; i < LWRES_CONFMAXSORTLIST; i++) {
230
230
lwres_resetaddr(&confdata->sortlist[i].addr);
231
231
lwres_resetaddr(&confdata->sortlist[i].mask);
240
240
REQUIRE(ctx != NULL);
241
241
confdata = &ctx->confdata;
243
for (i = 0 ; i < confdata->nsnext ; i++)
243
for (i = 0; i < confdata->nsnext; i++)
244
244
lwres_resetaddr(&confdata->nameservers[i]);
246
246
if (confdata->domainname != NULL) {
249
249
confdata->domainname = NULL;
252
for (i = 0 ; i < confdata->searchnxt ; i++) {
252
for (i = 0; i < confdata->searchnxt; i++) {
253
253
if (confdata->search[i] != NULL) {
254
254
CTXFREE(confdata->search[i],
255
255
strlen(confdata->search[i]) + 1);
284
284
return (LWRES_R_SUCCESS);
286
286
res = getword(fp, word, sizeof(word));
287
if (strlen(word) == 0)
287
if (strlen(word) == 0U)
288
288
return (LWRES_R_FAILURE); /* Nothing on line. */
289
289
else if (res == ' ' || res == '\t')
290
290
res = eatwhite(fp);
312
312
return (LWRES_R_SUCCESS);
314
314
res = getword(fp, word, sizeof(word));
315
if (strlen(word) == 0)
315
if (strlen(word) == 0U)
316
316
return (LWRES_R_FAILURE); /* Nothing on line. */
317
317
else if (res == ' ' || res == '\t')
318
318
res = eatwhite(fp);
337
337
confdata = &ctx->confdata;
339
339
res = getword(fp, word, sizeof(word));
340
if (strlen(word) == 0)
340
if (strlen(word) == 0U)
341
341
return (LWRES_R_FAILURE); /* Nothing else on line. */
342
342
else if (res == ' ' || res == '\t')
343
343
res = eatwhite(fp);
353
353
* Search and domain are mutually exclusive.
355
for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) {
355
for (i = 0; i < LWRES_CONFMAXSEARCH; i++) {
356
356
if (confdata->search[i] != NULL) {
357
357
CTXFREE(confdata->search[i],
358
358
strlen(confdata->search[i])+1);
390
390
* Remove any previous search definitions.
392
for (idx = 0 ; idx < LWRES_CONFMAXSEARCH ; idx++) {
392
for (idx = 0; idx < LWRES_CONFMAXSEARCH; idx++) {
393
393
if (confdata->search[idx] != NULL) {
394
394
CTXFREE(confdata->search[idx],
395
395
strlen(confdata->search[idx])+1);
399
399
confdata->searchnxt = 0;
401
401
delim = getword(fp, word, sizeof(word));
402
if (strlen(word) == 0)
402
if (strlen(word) == 0U)
403
403
return (LWRES_R_FAILURE); /* Nothing else on line. */
406
while (strlen(word) > 0) {
406
while (strlen(word) > 0U) {
407
407
if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
408
408
goto ignore; /* Too many domains. */
460
460
confdata = &ctx->confdata;
462
462
delim = getword(fp, word, sizeof(word));
463
if (strlen(word) == 0)
463
if (strlen(word) == 0U)
464
464
return (LWRES_R_FAILURE); /* Empty line after keyword. */
466
while (strlen(word) > 0) {
466
while (strlen(word) > 0U) {
467
467
if (confdata->sortlistnxt == LWRES_CONFMAXSORTLIST)
468
468
return (LWRES_R_FAILURE); /* Too many values. */
516
516
confdata = &ctx->confdata;
518
518
delim = getword(fp, word, sizeof(word));
519
if (strlen(word) == 0)
519
if (strlen(word) == 0U)
520
520
return (LWRES_R_FAILURE); /* Empty line after keyword. */
522
while (strlen(word) > 0) {
522
while (strlen(word) > 0U) {
523
523
if (strcmp("debug", word) == 0) {
524
524
confdata->resdebug = 1;
525
525
} else if (strcmp("no_tld_query", word) == 0) {
554
554
confdata = &ctx->confdata;
556
556
REQUIRE(filename != NULL);
557
REQUIRE(strlen(filename) > 0);
557
REQUIRE(strlen(filename) > 0U);
558
558
REQUIRE(confdata != NULL);
581
581
rval = lwres_conf_parsesearch(ctx, fp);
582
582
else if (strcmp(word, "sortlist") == 0)
583
583
rval = lwres_conf_parsesortlist(ctx, fp);
584
else if (strcmp(word, "option") == 0)
584
else if (strcmp(word, "options") == 0)
585
585
rval = lwres_conf_parseoption(ctx, fp);
587
587
/* unrecognised word. Ignore entire line */
615
615
REQUIRE(confdata->nsnext <= LWRES_CONFMAXNAMESERVERS);
617
for (i = 0 ; i < confdata->nsnext ; i++) {
617
for (i = 0; i < confdata->nsnext; i++) {
618
618
af = lwresaddr2af(confdata->nameservers[i].family);
620
620
p = lwres_net_ntop(af, confdata->nameservers[i].address,
625
625
fprintf(fp, "nameserver %s\n", tmp);
628
for (i = 0 ; i < confdata->lwnext ; i++) {
628
for (i = 0; i < confdata->lwnext; i++) {
629
629
af = lwresaddr2af(confdata->lwservers[i].family);
631
631
p = lwres_net_ntop(af, confdata->lwservers[i].address,
642
642
REQUIRE(confdata->searchnxt <= LWRES_CONFMAXSEARCH);
644
644
fprintf(fp, "search");
645
for (i = 0 ; i < confdata->searchnxt ; i++)
645
for (i = 0; i < confdata->searchnxt; i++)
646
646
fprintf(fp, " %s", confdata->search[i]);