From 91cf68b183bbf7fc2a387915a7ac918a101f99b4 Mon Sep 17 00:00:00 2001 From: James Brister Date: Fri, 17 Sep 1999 14:29:20 +0000 Subject: [PATCH] Config file parser tester. --- bin/tests/nconf_test.c | 144 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 bin/tests/nconf_test.c diff --git a/bin/tests/nconf_test.c b/bin/tests/nconf_test.c new file mode 100644 index 0000000000..7569cde5a5 --- /dev/null +++ b/bin/tests/nconf_test.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 1996-1999 by 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. + */ + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +isc_result_t zonecbk(dns_c_ctx_t *ctx, dns_c_zone_t *zone, void *uap); +isc_result_t optscbk(dns_c_ctx_t *ctx, void *uap); + + +isc_result_t +zonecbk(dns_c_ctx_t *ctx, dns_c_zone_t *zone, void *uap) +{ + const char *zname; + + (void) ctx; + (void) uap; + + dns_c_zone_getname(zone, &zname); + + fprintf(stderr, "handling zone %s\n", zname); + + return (ISC_R_SUCCESS); +} + + +isc_result_t +optscbk(dns_c_ctx_t *ctx, void *uap) +{ + (void) ctx; + (void) uap; + + fprintf(stderr, "Processing options in callback.\n"); + return (ISC_R_SUCCESS); +} + + + +int main (int argc, char **argv) { + dns_c_ctx_t *configctx = NULL; + const char *conffile; + FILE *outfp; + isc_mem_t *mem = NULL; + dns_c_cbks_t callbacks; + +#if 1 + callbacks.zonecbk = NULL; + callbacks.zonecbkuap = NULL; + callbacks.optscbk = NULL; + callbacks.optscbkuap = NULL; +#else + callbacks.zonecbk = zonecbk; + callbacks.zonecbkuap = NULL; + callbacks.optscbk = optscbk; + callbacks.optscbkuap = NULL; +#endif + + if (argc > 1 && strcmp(argv[1],"-d") == 0) { + argv++; + argc--; + debug_mem_print = ISC_TRUE; + } + + conffile = getenv("NAMED_CONF"); + if (argc > 1) + conffile = argv[1]; + if (conffile == NULL || conffile[0] == '\0') + conffile = "/etc/named.conf"; + + RUNTIME_CHECK(isc_mem_create(0, 0, &mem) == ISC_R_SUCCESS); + + if (dns_c_parse_namedconf(conffile, mem, &configctx, &callbacks) != + ISC_R_SUCCESS) { + fprintf(stderr, "parse_configuration failed.\n"); + exit(1); + } + + if (configctx->errors > 0) { + fprintf(stderr, + "There were %d semantic errors in the config file.\n", + configctx->errors); + } + + outfp = stderr; + if (argc > 2) { + if ((outfp = fopen(argv[2], "w")) == NULL) { + fprintf(stderr, "Cannot open %s: %s", + argv[2], strerror(errno)); + outfp = stderr; + } + } + + dns_c_ctx_print(outfp, 0, configctx); + +#if 0 + /* Test the acl expansion */ + { + dns_ipmatch_list_t *list; + dns_acl_t *acl; + + dns_acl_table_get_acl(configctx->acls, "cannot_query", &acl); + dns_acl_get_ipml_expanded(mem, acl, &list); + dns_ipmatch_list_print(outfp, 0, list); + } +#endif + + if (outfp != stderr) { + fclose(outfp); + } + + dns_c_ctx_delete(&configctx); + isc_mem_destroy(&mem); + + return (0); +} + + + +