lwconfig.c revision 6c6ad82aca98a80c0b557e31605d406e2e250901
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * Copyright (C) 2000 Internet Software Consortium.
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * Permission to use, copy, modify, and distribute this software for any
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * purpose with or without fee is hereby granted, provided that the above
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * copyright notice and this permission notice appear in all copies.
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *** Module for parsing resolv.conf files.
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *** entry points are:
bbedadf76ab670b01887fb9b41097120ea4fdf14Evan Hunt *** lwres_conf_init(lwres_context_t *ctx, lwres_conf_t *confdata)
bbedadf76ab670b01887fb9b41097120ea4fdf14Evan Hunt *** intializes data structure for subsequent parsing.
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *** lwres_conf_parse(const char *filename, lwres_conf_t *confdata)
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *** parses a file and fills in the data structure.
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *** lwres_conf_print(FILE *fp, lwres_conf_t *confdata)
0245f7725c40fd29637fbc83ee25bd84be25bfd2Evan Hunt *** prints the data structure to the FILE.
0245f7725c40fd29637fbc83ee25bd84be25bfd2Evan Hunt *** lwres_conf_clear(lwres_conf_t *confdata)
0245f7725c40fd29637fbc83ee25bd84be25bfd2Evan Hunt *** frees up all the internal memory used by the data
0245f7725c40fd29637fbc83ee25bd84be25bfd2Evan Hunt *** structure, returning it to the lwres_context_t.
ba88bcf08b965f65c07735efa2f675b8cbeb735aMark Andrewsextern int lwres_net_pton(int af, const char *src, void *dst);
ba88bcf08b965f65c07735efa2f675b8cbeb735aMark Andrewsextern const char *lwres_net_ntop(int af, const void *src, char *dst,
ba88bcf08b965f65c07735efa2f675b8cbeb735aMark Andrewslwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp);
ba88bcf08b965f65c07735efa2f675b8cbeb735aMark Andrewslwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp);
ba88bcf08b965f65c07735efa2f675b8cbeb735aMark Andrewslwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp);
e24ccb512c110d181e01f977196e518b0e72e451Mark Andrewslwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp);
ba88bcf08b965f65c07735efa2f675b8cbeb735aMark Andrewslwres_conf_parseoption(lwres_context_t *ctx, FILE *fp);
e24ccb512c110d181e01f977196e518b0e72e451Mark Andrewslwres_create_addr(const char *buff, lwres_addr_t *addr);
e24ccb512c110d181e01f977196e518b0e72e451Mark Andrews * Skip over any leading whitespace and then read in the next sequence of
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt * non-whitespace characters. Returnss EOF on end-of-file, or the character
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt * that caused the reading to stop.
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt while (ch != '\n' && ch != EOF && isspace((unsigned char)ch))
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *p++ = (char)ch;
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt } while (1);
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Huntstatic char *
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Huntlwres_strdup(lwres_context_t *ctx, const char *str) {
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt for (i = 0 ; i < LWRES_CONFMAXNAMESERVERS ; i++)
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++)
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
b47c020d5c635b662ac57e5485d266fd62c796c0Evan Hunt for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
b47c020d5c635b662ac57e5485d266fd62c796c0Evan Huntlwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp) {
36b2d5f93c22b096c0417495f27ae0bdebf06ae1Evan Hunt return (LWRES_R_FAILURE); /* Extra junk on line. */
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Huntlwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) {
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt return (LWRES_R_FAILURE); /* Nothing else on line. */
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt return (LWRES_R_FAILURE); /* Extra junk on line. */
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt * Search and domain are mutually exclusive.
79ce3a9e82384cc31fd6b86be8f3d1474fcfd9f4Evan Hunt for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) {
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Huntlwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp) {
e11a0c114cdaf8f7e7832e9f1a011138248093a6Evan Hunt * Search and domain are mutually exclusive.
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt * Remove any previous search definitions.
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt for (idx = 0 ; idx < LWRES_CONFMAXSEARCH ; idx++) {
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt return (LWRES_R_FAILURE); /* Nothing else on line. */
61bcc232038f0a2cb77ed6269675fdc288f5ec98Evan Huntlwres_create_addr(const char *buffer, lwres_addr_t *addr) {
61bcc232038f0a2cb77ed6269675fdc288f5ec98Evan Hunt unsigned int len;
61bcc232038f0a2cb77ed6269675fdc288f5ec98Evan Hunt if (lwres_net_pton(AF_INET, buffer, &addrbuff) == 1) {
61bcc232038f0a2cb77ed6269675fdc288f5ec98Evan Hunt } else if (lwres_net_pton(AF_INET6, buffer, &addrbuff) == 1) {
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt return (LWRES_R_FAILURE); /* Unrecongnised format. */
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Huntlwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp) {
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt return (LWRES_R_FAILURE); /* Empty line after keyword. */
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt if (confdata->sortlistnxt == LWRES_CONFMAXSORTLIST)
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt *p++ = '\0';
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt res = lwres_create_addr(word, &confdata->sortlist[idx].addr);
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt * Make up a mask.
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Huntlwres_conf_parseoption(lwres_context_t *ctx, FILE *fp) {
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt return (LWRES_R_FAILURE); /* Empty line after keyword. */
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt if (ndots < 0 || ndots > 0xff) /* Out of range. */
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Huntlwres_conf_parse(lwres_context_t *ctx, const char *filename) {
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt rval = LWRES_R_FAILURE; /* Make compiler happy. */
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt const char *p;
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt REQUIRE(confdata->nsnext <= LWRES_CONFMAXNAMESERVERS);
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt p = lwres_net_ntop(confdata->nameservers[i].family,
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt REQUIRE(confdata->searchnxt <= LWRES_CONFMAXSEARCH);
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt REQUIRE(confdata->sortlistnxt <= LWRES_CONFMAXSORTLIST);
75b8de87879ad017c9cd2ffc328e5d2391d16e99Evan Hunt p = lwres_net_ntop(confdata->sortlist[i].addr.family,