lwconfig.c revision d8c8722f28ca439b9ca46f109e2804a7eb33a1ac
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff/*
dc3d68d6fe0c0dc0d43015ed6b651f407b38ee25Tinderbox User * Copyright (C) 2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * copyright notice and this permission notice appear in all copies.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff */
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
23daf8948b2e5462ccea082a441e9759dffa50cdMark Andrews/* $Id: lwconfig.c,v 1.22 2000/07/07 18:58:46 bwelling Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/***
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence *** Module for parsing resolv.conf files.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff ***
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *** entry points are:
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *** lwres_conf_init(lwres_context_t *ctx)
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews *** intializes data structure for subsequent config parsing.
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews ***
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *** lwres_conf_parse(lwres_context_t *ctx, const char *filename)
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *** parses a file and fills in the data structure.
80617c8faa03b2c425e320597eb768073fd0b987Michael Graff ***
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff *** lwres_conf_print(lwres_context_t *ctx, FILE *fp)
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff *** prints the config data structure to the FILE.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ***
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence *** lwres_conf_clear(lwres_context_t *ctx)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *** frees up all the internal memory used by the config data
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt *** structure, returning it to the lwres_context_t.
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 ***
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence ***/
32eddfc189108fa93e31761e13150594c7a79d2bDavid Lawrence
a095cd0ef599eb04d74fb9f9bc46ae13081c5bcbMark Andrews#include <config.h>
440be4c866f6935ac069db79a414304507a664c2Michael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <assert.h>
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington#include <ctype.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <errno.h>
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff#include <stdlib.h>
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff#include <stdio.h>
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff#include <string.h>
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews#include <unistd.h>
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff#include <sys/types.h>
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#include <sys/socket.h>
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#include <netinet/in.h>
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include <lwres/lwbuffer.h>
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉#include <lwres/lwres.h>
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉#include <lwres/net.h>
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include <lwres/result.h>
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include "assert_p.h"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include "context_p.h"
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#if ! defined(NS_INADDRSZ)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define NS_INADDRSZ 4
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#endif
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#if ! defined(NS_IN6ADDRSZ)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define NS_IN6ADDRSZ 16
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews#endif
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern int lwres_net_pton(int af, const char *src, void *dst);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinextern const char *lwres_net_ntop(int af, const void *src, char *dst,
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews size_t size);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉static lwres_result_t
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewslwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffstatic lwres_result_t
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafflwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffstatic lwres_result_t
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellingtonlwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp);
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉static lwres_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffstatic lwres_result_t
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Grafflwres_conf_parseoption(lwres_context_t *ctx, FILE *fp);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffstatic void
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrewslwres_resetaddr(lwres_addr_t *addr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static lwres_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_create_addr(const char *buff, lwres_addr_t *addr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrewsstatic int lwresaddr2af(int lwresaddrtype);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic int
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinlwresaddr2af(int lwresaddrtype)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein{
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff int af = 0;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt switch (lwresaddrtype) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt case LWRES_ADDRTYPE_V4:
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt af = AF_INET;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt break;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein case LWRES_ADDRTYPE_V6:
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt af = AF_INET6;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt break;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt }
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (af);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Eat characters from FP until EOL or EOF. Returns EOF or '\n'
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static int
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉eatline(FILE *fp) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int ch;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ch = fgetc(fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 while (ch != '\n' && ch != EOF)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ch = fgetc(fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ch);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff * Eats white space up to next newline or non-whitespace character (of
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff * EOF). Returns the last character read. Comments are considered white
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff * space.
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffstatic int
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffeatwhite(FILE *fp) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff int ch;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ch = fgetc(fp);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff while (ch != '\n' && ch != EOF && isspace((unsigned char)ch))
038a3e6bfe6e15479b0469bd87de3a7139ad1109Brian Wellington ch = fgetc(fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (ch == ';' || ch == '#')
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff ch = eatline(fp);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff return (ch);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff/*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Skip over any leading whitespace and then read in the next sequence of
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * non-whitespace characters. In this context newline is not considered
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * whitespace. Returns EOF on end-of-file, or the character
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * that caused the reading to stop.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static int
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉getword(FILE *fp, char *buffer, size_t size) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int ch;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char *p = buffer;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(buffer != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(size > 0);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *p = '\0';
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ch = eatwhite(fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (ch == EOF)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (EOF);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 do {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *p = '\0';
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (ch == EOF || isspace((unsigned char)ch))
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 break;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if ((size_t) (p - buffer) == size - 1)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (EOF); /* Not enough space. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 *p++ = (char)ch;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews ch = fgetc(fp);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews } while (1);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ch);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉static void
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Grafflwres_resetaddr(lwres_addr_t *addr) {
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff REQUIRE(addr != NULL);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews memset(addr->address, 0, LWRES_ADDR_MAXLEN);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews addr->family = 0;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews addr->length = 0;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews}
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrewsstatic char *
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrewslwres_strdup(lwres_context_t *ctx, const char *str) {
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews char *p;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews REQUIRE(str != NULL);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews REQUIRE(strlen(str) > 0);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews p = CTXMALLOC(strlen(str) + 1);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (p != NULL)
607dc8013a8cb34cd03b59292aa1ac01e008c9c1Michael Graff strcpy(p, str);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (p);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_conf_init(lwres_context_t *ctx) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int i;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_conf_t *confdata;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff REQUIRE(ctx != NULL);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein confdata = &ctx->confdata;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->nsnext = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->domainname = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->searchnxt = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->sortlistnxt = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->resdebug = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->ndots = 1;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->no_tld_query = 0;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein for (i = 0 ; i < LWRES_CONFMAXNAMESERVERS ; i++)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_resetaddr(&confdata->nameservers[i]);
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++)
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington confdata->search[i] = NULL;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt lwres_resetaddr(&confdata->sortlist[i].addr);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt lwres_resetaddr(&confdata->sortlist[i].mask);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff}
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffvoid
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinlwres_conf_clear(lwres_context_t *ctx) {
ce5bd92088923d1c76e26d313d1d8c0b8bbe38feMichael Graff int i;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lwres_conf_t *confdata;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein REQUIRE(ctx != NULL);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff confdata = &ctx->confdata;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff for (i = 0 ; i < confdata->nsnext ; i++)
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington lwres_resetaddr(&confdata->nameservers[i]);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff if (confdata->domainname != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CTXFREE(confdata->domainname,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 strlen(confdata->domainname) + 1);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->domainname = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein for (i = 0 ; i < confdata->searchnxt ; i++) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (confdata->search[i] != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CTXFREE(confdata->search[i],
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews strlen(confdata->search[i]) + 1);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews confdata->search[i] = NULL;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff }
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff }
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews lwres_resetaddr(&confdata->sortlist[i].addr);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff lwres_resetaddr(&confdata->sortlist[i].mask);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff }
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->nsnext = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->domainname = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->searchnxt = 0;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff confdata->sortlistnxt = 0;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff confdata->resdebug = 0;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff confdata->ndots = 1;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff confdata->no_tld_query = 0;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff}
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewsstatic lwres_result_t
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrewslwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char word[LWRES_CONFMAXLINELEN];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int res;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_conf_t *confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata = &ctx->confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (confdata->nsnext == LWRES_CONFMAXNAMESERVERS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 res = getword(fp, word, sizeof(word));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (strlen(word) == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE); /* Nothing on line. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if (res == ' ' || res == '\t')
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff res = eatwhite(fp);
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (res != EOF && res != '\n')
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE); /* Extra junk on line. */
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff res = lwres_create_addr(word,
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington &confdata->nameservers[confdata->nsnext++]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (res != LWRES_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (res);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static lwres_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char word[LWRES_CONFMAXLINELEN];
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff int res, i;
8470db5b12c18cfb32a757e265ce4e7789052c92Michael Graff lwres_conf_t *confdata;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt confdata = &ctx->confdata;
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews res = getword(fp, word, sizeof(word));
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (strlen(word) == 0)
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff return (LWRES_R_FAILURE); /* Nothing else on line. */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff else if (res == ' ' || res == '\t')
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 res = eatwhite(fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (res != EOF && res != '\n')
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE); /* Extra junk on line. */
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt if (confdata->domainname != NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff CTXFREE(confdata->domainname,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff strlen(confdata->domainname) + 1); /* */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff /*
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * Search and domain are mutually exclusive.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff */
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) {
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt if (confdata->search[i] != NULL) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff CTXFREE(confdata->search[i],
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff strlen(confdata->search[i])+1);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews confdata->search[i] = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews confdata->searchnxt = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt confdata->domainname = lwres_strdup(ctx, word);
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (confdata->domainname == NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff return (LWRES_R_SUCCESS);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonstatic lwres_result_t
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonlwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson int idx, delim;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff char word[LWRES_CONFMAXLINELEN];
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lwres_conf_t *confdata;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff confdata = &ctx->confdata;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington if (confdata->domainname != NULL) {
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington /*
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington * Search and domain are mutually exclusive.
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff */
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff CTXFREE(confdata->domainname,
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff strlen(confdata->domainname) + 1);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff confdata->domainname = NULL;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff /*
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * Remove any previous search definitions.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff */
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews for (idx = 0 ; idx < LWRES_CONFMAXSEARCH ; idx++) {
870a748bae74b9c4b264da96cfbcb4e90d7a2c1dMark Andrews if (confdata->search[idx] != NULL) {
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews CTXFREE(confdata->search[idx],
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews strlen(confdata->search[idx])+1);
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews confdata->search[idx] = NULL;
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews }
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt }
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt confdata->searchnxt = 0;
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt delim = getword(fp, word, sizeof(word));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (strlen(word) == 0)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt return (LWRES_R_FAILURE); /* Nothing else on line. */
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson idx = 0;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson while (strlen(word) > 0) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff goto ignore; /* Too many domains. */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff confdata->search[idx] = lwres_strdup(ctx, word);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (confdata->search[idx] == NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff return (LWRES_R_FAILURE);
9317787889b6d2437b2f8e77583b49246f7511feAndreas Gustafsson idx++;
9317787889b6d2437b2f8e77583b49246f7511feAndreas Gustafsson confdata->searchnxt++;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff ignore:
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (delim == EOF || delim == '\n')
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff break;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff else
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff delim = getword(fp, word, sizeof(word));
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff }
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff return (LWRES_R_SUCCESS);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff}
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonstatic lwres_result_t
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonlwres_create_addr(const char *buffer, lwres_addr_t *addr) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson unsigned char addrbuff[NS_IN6ADDRSZ];
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson unsigned int len;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if (lwres_net_pton(AF_INET, buffer, &addrbuff) == 1) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff addr->family = LWRES_ADDRTYPE_V4;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff addr->length = NS_INADDRSZ;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff len = 4;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff } else if (lwres_net_pton(AF_INET6, buffer, &addrbuff) == 1) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff addr->family = LWRES_ADDRTYPE_V6;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff addr->length = NS_IN6ADDRSZ;
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington len = 16;
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington } else {
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington return (LWRES_R_FAILURE); /* Unrecognised format. */
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff }
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff memcpy((void *)addr->address, addrbuff, len);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff return (LWRES_R_SUCCESS);
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson}
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffstatic lwres_result_t
ec46482ef3c0c3e9747f0074cb9263adb8aef961Andreas Gustafssonlwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff int delim, res, idx;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff char word[LWRES_CONFMAXLINELEN];
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff char *p;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff lwres_conf_t *confdata;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff confdata = &ctx->confdata;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff delim = getword(fp, word, sizeof(word));
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if (strlen(word) == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE); /* Empty line after keyword. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 while (strlen(word) > 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (confdata->sortlistnxt == LWRES_CONFMAXSORTLIST)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE); /* Too many values. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 p = strchr(word, '/');
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (p != NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *p++ = '\0';
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 idx = confdata->sortlistnxt;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 res = lwres_create_addr(word, &confdata->sortlist[idx].addr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (res != LWRES_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (res);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (p != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 res = lwres_create_addr(p,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &confdata->sortlist[idx].mask);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (res != LWRES_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (res);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Make up a mask.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 confdata->sortlist[idx].mask =
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 confdata->sortlist[idx].addr;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 memset(&confdata->sortlist[idx].mask.address, 0xff,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->sortlist[idx].addr.length);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->sortlistnxt++;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (delim == EOF || delim == '\n')
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 break;
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews else
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 delim = getword(fp, word, sizeof(word));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static lwres_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_conf_parseoption(lwres_context_t *ctx, FILE *fp) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int delim;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 long ndots;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char *p;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char word[LWRES_CONFMAXLINELEN];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_conf_t *confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(ctx != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata = &ctx->confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 delim = getword(fp, word, sizeof(word));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (strlen(word) == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE); /* Empty line after keyword. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 while (strlen(word) > 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (strcmp("debug", word) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->resdebug = 1;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else if (strcmp("no_tld_query", word) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->no_tld_query = 1;
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews } else if (strncmp("ndots:", word, 6) == 0) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ndots = strtol(word + 6, &p, 10);
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews if (*p != '\0') /* Bad string. */
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews return (LWRES_R_FAILURE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (ndots < 0 || ndots > 0xff) /* Out of range. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata->ndots = (lwres_uint8_t)ndots;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (delim == EOF || delim == '\n')
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 break;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 delim = getword(fp, word, sizeof(word));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_conf_parse(lwres_context_t *ctx, const char *filename) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 FILE *fp = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char word[256];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_result_t rval, ret;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_conf_t *confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int stopchar;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(ctx != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata = &ctx->confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(filename != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(strlen(filename) > 0);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(confdata != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 errno = 0;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if ((fp = fopen(filename, "r")) == NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ret = LWRES_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 do {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 stopchar = getword(fp, word, sizeof(word));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (stopchar == EOF) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = LWRES_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 break;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (strlen(word) == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = LWRES_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if (strcmp(word, "nameserver") == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = lwres_conf_parsenameserver(ctx, fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if (strcmp(word, "domain") == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = lwres_conf_parsedomain(ctx, fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if (strcmp(word, "search") == 0)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rval = lwres_conf_parsesearch(ctx, fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if (strcmp(word, "sortlist") == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = lwres_conf_parsesortlist(ctx, fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else if (strcmp(word, "option") == 0)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = lwres_conf_parseoption(ctx, fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /* unrecognised word. Ignore entire line */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 rval = LWRES_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 stopchar = eatline(fp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (stopchar == EOF) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 break;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ret == LWRES_R_SUCCESS && rval != LWRES_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ret = rval;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } while (1);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 fclose(fp);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ret);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉lwres_conf_print(lwres_context_t *ctx, FILE *fp) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int i;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 int af;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 const char *p;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff lwres_conf_t *confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 lwres_addr_t tmpaddr;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(ctx != NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 confdata = &ctx->confdata;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(confdata->nsnext <= LWRES_CONFMAXNAMESERVERS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (i = 0 ; i < confdata->nsnext ; i++) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 af = lwresaddr2af(confdata->nameservers[i].family);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 p = lwres_net_ntop(af, confdata->nameservers[i].address,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 tmp, sizeof(tmp));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (p != tmp)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (LWRES_R_FAILURE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 fprintf(fp, "nameserver %s\n", tmp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff if (confdata->domainname != NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff fprintf(fp, "domain %s\n", confdata->domainname);
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff } else if (confdata->searchnxt > 0) {
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff REQUIRE(confdata->searchnxt <= LWRES_CONFMAXSEARCH);
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff fprintf(fp, "search");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 for (i = 0 ; i < confdata->searchnxt ; i++)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 fprintf(fp, " %s", confdata->search[i]);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 fputc('\n', fp);
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff }
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff REQUIRE(confdata->sortlistnxt <= LWRES_CONFMAXSORTLIST);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (confdata->sortlistnxt > 0) {
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff fputs("sortlist", fp);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews for (i = 0 ; i < confdata->sortlistnxt ; i++) {
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff af = lwresaddr2af(confdata->sortlist[i].addr.family);
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff p = lwres_net_ntop(af,
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff confdata->sortlist[i].addr.address,
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson tmp, sizeof(tmp));
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson if (p != tmp)
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson return (LWRES_R_FAILURE);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews fprintf(fp, " %s", tmp);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff tmpaddr = confdata->sortlist[i].mask;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff memset(&tmpaddr.address, 0xff, tmpaddr.length);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (memcmp(&tmpaddr.address,
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews confdata->sortlist[i].mask.address,
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews confdata->sortlist[i].mask.length) != 0) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff af = lwresaddr2af(
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff confdata->sortlist[i].mask.family);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff p = lwres_net_ntop
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff (af,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff confdata->sortlist[i].mask.address,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff tmp, sizeof(tmp));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (p != tmp)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return (LWRES_R_FAILURE);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson fprintf(fp, "/%s", tmp);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson }
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff fputc('\n', fp);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (confdata->resdebug)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff fprintf(fp, "options debug\n");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (confdata->ndots > 0)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff fprintf(fp, "options ndots:%d\n", confdata->ndots);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (confdata->no_tld_query)
c17c59662f0969a5e52e8b7529cbde1a7c746095Andreas Gustafsson fprintf(fp, "options no_tld_query\n");
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews return (LWRES_R_SUCCESS);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Grafflwres_conf_t *
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Grafflwres_conf_get(lwres_context_t *ctx) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff REQUIRE(ctx != NULL);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return (&ctx->confdata);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff}
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff