lwconfig.c revision e03329a3878634cc75d94e5a69661fcbc4981e52
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/***
*** Module for parsing resolv.conf files.
***
*** entry points are:
*** lwres_conf_init(lwres_context_t *ctx, lwres_conf_t *confdata)
*** intializes data structure for subsequent parsing.
***
*** lwres_conf_parse(const char *filename, lwres_conf_t *confdata)
*** parses a file and fills in the data structure.
***
*** lwres_conf_print(FILE *fp, lwres_conf_t *confdata)
*** prints the data structure to the FILE.
***
*** lwres_conf_clear(lwres_conf_t *confdata)
*** frees up all the internal memory used by the data
*** structure, returning it to the lwres_context_t.
***
***/
#include <config.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <lwres/lwbuffer.h>
#include "assert_p.h"
#include "context_p.h"
#if ! defined(NS_INADDRSZ)
#define NS_INADDRSZ 4
#endif
#if ! defined(NS_IN6ADDRSZ)
#define NS_IN6ADDRSZ 16
#endif
static lwres_result_t
static lwres_result_t
static lwres_result_t
static lwres_result_t
static lwres_result_t
static void
static lwres_result_t
/*
* Eat characters from FP until EOL or EOF. Returns EOF or '\n'
*/
static int
int ch;
return (ch);
}
/*
* Eats white space up to next newline or non-whitespace character (of
* EOF). Returns the last character read. Comments are considered white
* space.
*/
static int
int ch;
return (ch);
}
/*
* Skip over any leading whitespace and then read in the next sequence of
* non-whitespace characters. In this context newline is not considered
* whitespace. Returns EOF on end-of-file, or the character
* that caused the reading to stop.
*/
static int
int ch;
char *p = buffer;
*p = '\0';
return (EOF);
do {
*p = '\0';
break;
return (EOF); /* Not enough space. */
*p++ = (char)ch;
} while (1);
return (ch);
}
static void
}
static char *
char *p;
if (p != NULL)
return (p);
}
void
int i;
confdata->sortlistnxt = 0;
confdata->no_tld_query = 0;
for (i = 0 ; i < LWRES_CONFMAXNAMESERVERS ; i++)
for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++)
for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
}
}
void
int i;
}
}
}
for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
}
confdata->sortlistnxt = 0;
confdata->no_tld_query = 0;
}
static lwres_result_t
char word[LWRES_CONFMAXLINELEN];
int res;
return (LWRES_R_FAILURE);
return (LWRES_R_FAILURE); /* Nothing on line. */
return (LWRES_R_FAILURE); /* Extra junk on line. */
if (res != LWRES_R_SUCCESS)
return (res);
return (LWRES_R_SUCCESS);
}
static lwres_result_t
char word[LWRES_CONFMAXLINELEN];
int res, i;
return (LWRES_R_FAILURE); /* Nothing else on line. */
return (LWRES_R_FAILURE); /* Extra junk on line. */
/*
* Search and domain are mutually exclusive.
*/
for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) {
}
}
return (LWRES_R_FAILURE);
return (LWRES_R_SUCCESS);
}
static lwres_result_t
char word[LWRES_CONFMAXLINELEN];
/*
* Search and domain are mutually exclusive.
*/
}
/*
* Remove any previous search definitions.
*/
}
}
return (LWRES_R_FAILURE); /* Nothing else on line. */
idx = 0;
return (LWRES_R_FAILURE); /* Too many domains. */
return (LWRES_R_FAILURE);
idx++;
break;
else
}
return (LWRES_R_SUCCESS);
}
static lwres_result_t
unsigned char addrbuff[NS_IN6ADDRSZ];
unsigned int len;
#if 1 /* XXX BRISTER. Set to 0 for testing with lwresconf_test */
#else
#endif
len = 4;
#if defined(AF_INET6)
#if 1 /* XXX BRISTER. Set to 0 for testing with lwresconf_test */
#else
#endif
len = 16;
#endif
} else {
return (LWRES_R_FAILURE); /* Unrecongnised format. */
}
return (LWRES_R_SUCCESS);
}
static lwres_result_t
char word[LWRES_CONFMAXLINELEN];
char *p;
return (LWRES_R_FAILURE); /* Empty line after keyword. */
return (LWRES_R_FAILURE); /* Too many values. */
if (p != NULL)
*p++ = '\0';
if (res != LWRES_R_SUCCESS)
return (res);
if (p != NULL) {
res = lwres_create_addr(p,
if (res != LWRES_R_SUCCESS)
return (res);
} else {
/*
* Make up a mask.
*/
}
confdata->sortlistnxt++;
break;
else
}
return (LWRES_R_SUCCESS);
}
static lwres_result_t
int delim;
long ndots;
char *p;
char word[LWRES_CONFMAXLINELEN];
return (LWRES_R_FAILURE); /* Empty line after keyword. */
if (*p != '\0') /* Bad string. */
return (LWRES_R_FAILURE);
return (LWRES_R_FAILURE);
}
break;
else
}
return (LWRES_R_SUCCESS);
}
char word[256];
int stopchar;
errno = 0;
return (LWRES_R_FAILURE);
do {
break;
}
/* unrecognised word. Ignore entire line */
break;
}
}
} while (rval == LWRES_R_SUCCESS);
return (rval);
}
int i;
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
const char *p;
if (p != tmp)
return (LWRES_R_FAILURE);
}
}
if (confdata->sortlistnxt > 0) {
for (i = 0 ; i < confdata->sortlistnxt ; i++) {
if (p != tmp)
return (LWRES_R_FAILURE);
p = lwres_net_ntop
if (p != tmp)
return (LWRES_R_FAILURE);
}
}
}
if (confdata->no_tld_query)
return (LWRES_R_SUCCESS);
}
}