mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-08 23:02:05 -04:00
Merge branch '1758-cleanup-libirs' into 'master'
Cleanup libirs APIs and slim down the library to just irs_resconf Closes #1758 See merge request isc-projects/bind9!3416
This commit is contained in:
commit
e2dd8f48b1
23 changed files with 11 additions and 3322 deletions
3
CHANGES
3
CHANGES
|
|
@ -1,3 +1,6 @@
|
|||
5393. [cleanup] Unused or redundant APIs were removed from libirs.
|
||||
[GL #1758]
|
||||
|
||||
5392. [bug] It was possible for named to crash during shutdown
|
||||
or reconfiguration if an RPZ zone was still being
|
||||
updated. [GL #1779]
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@
|
|||
#include <isccfg/log.h>
|
||||
#include <isccfg/namedconf.h>
|
||||
|
||||
#include <irs/netdb.h>
|
||||
#include <irs/resconf.h>
|
||||
|
||||
#define CHECK(r) \
|
||||
|
|
|
|||
|
|
@ -4,19 +4,10 @@ lib_LTLIBRARIES = libirs.la
|
|||
|
||||
libirs_ladir = $(includedir)/irs
|
||||
libirs_la_HEADERS = \
|
||||
include/irs/context.h \
|
||||
include/irs/dnsconf.h \
|
||||
include/irs/netdb.h \
|
||||
include/irs/resconf.h \
|
||||
include/irs/types.h
|
||||
include/irs/resconf.h
|
||||
|
||||
libirs_la_SOURCES = \
|
||||
$(libirs_la_HEADERS) \
|
||||
context.c \
|
||||
dnsconf.c \
|
||||
gai_strerror.c \
|
||||
getaddrinfo.c \
|
||||
getnameinfo.c \
|
||||
resconf.c
|
||||
|
||||
libirs_la_CPPFLAGS = \
|
||||
|
|
|
|||
|
|
@ -1,325 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/lib.h>
|
||||
#include <isc/magic.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/once.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/client.h>
|
||||
#include <dns/lib.h>
|
||||
|
||||
#include <irs/context.h>
|
||||
#include <irs/dnsconf.h>
|
||||
#include <irs/resconf.h>
|
||||
|
||||
#define IRS_CONTEXT_MAGIC ISC_MAGIC('I', 'R', 'S', 'c')
|
||||
#define IRS_CONTEXT_VALID(c) ISC_MAGIC_VALID(c, IRS_CONTEXT_MAGIC)
|
||||
|
||||
#ifndef RESOLV_CONF
|
||||
/*% location of resolve.conf */
|
||||
#define RESOLV_CONF "/etc/resolv.conf"
|
||||
#endif /* ifndef RESOLV_CONF */
|
||||
|
||||
#ifndef DNS_CONF
|
||||
/*% location of dns.conf */
|
||||
#define DNS_CONF "/etc/dns.conf"
|
||||
#endif /* ifndef DNS_CONF */
|
||||
|
||||
static thread_local irs_context_t *irs_context = NULL;
|
||||
|
||||
struct irs_context {
|
||||
/*
|
||||
* An IRS context is a thread-specific object, and does not need to
|
||||
* be locked.
|
||||
*/
|
||||
unsigned int magic;
|
||||
isc_mem_t *mctx;
|
||||
isc_appctx_t *actx;
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_task_t *task;
|
||||
isc_socketmgr_t *socketmgr;
|
||||
isc_timermgr_t *timermgr;
|
||||
dns_client_t *dnsclient;
|
||||
irs_resconf_t *resconf;
|
||||
irs_dnsconf_t *dnsconf;
|
||||
};
|
||||
|
||||
static void
|
||||
ctxs_destroy(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp,
|
||||
isc_socketmgr_t **socketmgrp, isc_timermgr_t **timermgrp) {
|
||||
if (taskmgrp != NULL) {
|
||||
isc_taskmgr_destroy(taskmgrp);
|
||||
}
|
||||
|
||||
if (timermgrp != NULL) {
|
||||
isc_timermgr_destroy(timermgrp);
|
||||
}
|
||||
|
||||
if (socketmgrp != NULL) {
|
||||
isc_socketmgr_destroy(socketmgrp);
|
||||
}
|
||||
|
||||
if (actxp != NULL) {
|
||||
isc_appctx_destroy(actxp);
|
||||
}
|
||||
|
||||
if (mctxp != NULL) {
|
||||
isc_mem_destroy(mctxp);
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp,
|
||||
isc_socketmgr_t **socketmgrp, isc_timermgr_t **timermgrp) {
|
||||
isc_result_t result;
|
||||
|
||||
isc_mem_create(mctxp);
|
||||
|
||||
result = isc_appctx_create(*mctxp, actxp);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
result = isc_timermgr_createinctx(*mctxp, timermgrp);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
fail:
|
||||
ctxs_destroy(mctxp, actxp, taskmgrp, socketmgrp, timermgrp);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
irs_context_get(irs_context_t **contextp) {
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(contextp != NULL && *contextp == NULL);
|
||||
|
||||
if (irs_context == NULL) {
|
||||
result = irs_context_create(&irs_context);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
*contextp = irs_context;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
irs_context_create(irs_context_t **contextp) {
|
||||
isc_result_t result;
|
||||
irs_context_t *context;
|
||||
isc_appctx_t *actx = NULL;
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_taskmgr_t *taskmgr = NULL;
|
||||
isc_socketmgr_t *socketmgr = NULL;
|
||||
isc_timermgr_t *timermgr = NULL;
|
||||
dns_client_t *client = NULL;
|
||||
isc_sockaddrlist_t *nameservers;
|
||||
irs_dnsconf_dnskeylist_t *trustedkeys;
|
||||
irs_dnsconf_dnskey_t *trustedkey;
|
||||
|
||||
isc_lib_register();
|
||||
result = dns_lib_init();
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
result = ctxs_init(&mctx, &actx, &taskmgr, &socketmgr, &timermgr);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
result = isc_app_ctxstart(actx);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
ctxs_destroy(&mctx, &actx, &taskmgr, &socketmgr, &timermgr);
|
||||
return (result);
|
||||
}
|
||||
|
||||
context = isc_mem_get(mctx, sizeof(*context));
|
||||
|
||||
context->mctx = mctx;
|
||||
context->actx = actx;
|
||||
context->taskmgr = taskmgr;
|
||||
context->socketmgr = socketmgr;
|
||||
context->timermgr = timermgr;
|
||||
context->resconf = NULL;
|
||||
context->dnsconf = NULL;
|
||||
context->task = NULL;
|
||||
result = isc_task_create(taskmgr, 0, &context->task);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Create a DNS client object */
|
||||
result = dns_client_createx(mctx, actx, taskmgr, socketmgr, timermgr, 0,
|
||||
&client, NULL, NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
context->dnsclient = client;
|
||||
|
||||
/* Read resolver configuration file */
|
||||
result = irs_resconf_load(mctx, RESOLV_CONF, &context->resconf);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
/* Set nameservers */
|
||||
nameservers = irs_resconf_getnameservers(context->resconf);
|
||||
result = dns_client_setservers(client, dns_rdataclass_in, NULL,
|
||||
nameservers);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Read advanced DNS configuration (if any) */
|
||||
result = irs_dnsconf_load(mctx, DNS_CONF, &context->dnsconf);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
trustedkeys = irs_dnsconf_gettrustedkeys(context->dnsconf);
|
||||
for (trustedkey = ISC_LIST_HEAD(*trustedkeys); trustedkey != NULL;
|
||||
trustedkey = ISC_LIST_NEXT(trustedkey, link))
|
||||
{
|
||||
result = dns_client_addtrustedkey(
|
||||
client, dns_rdataclass_in, dns_rdatatype_dnskey,
|
||||
trustedkey->keyname, trustedkey->keydatabuf);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
context->magic = IRS_CONTEXT_MAGIC;
|
||||
*contextp = context;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
fail:
|
||||
if (context->task != NULL) {
|
||||
isc_task_detach(&context->task);
|
||||
}
|
||||
if (context->resconf != NULL) {
|
||||
irs_resconf_destroy(&context->resconf);
|
||||
}
|
||||
if (context->dnsconf != NULL) {
|
||||
irs_dnsconf_destroy(&context->dnsconf);
|
||||
}
|
||||
if (client != NULL) {
|
||||
dns_client_destroy(&client);
|
||||
}
|
||||
ctxs_destroy(NULL, &actx, &taskmgr, &socketmgr, &timermgr);
|
||||
isc_mem_putanddetach(&mctx, context, sizeof(*context));
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
irs_context_destroy(irs_context_t **contextp) {
|
||||
irs_context_t *context;
|
||||
|
||||
REQUIRE(contextp != NULL);
|
||||
context = *contextp;
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
*contextp = irs_context = NULL;
|
||||
|
||||
isc_task_detach(&context->task);
|
||||
irs_dnsconf_destroy(&context->dnsconf);
|
||||
irs_resconf_destroy(&context->resconf);
|
||||
dns_client_destroy(&context->dnsclient);
|
||||
|
||||
ctxs_destroy(NULL, &context->actx, &context->taskmgr,
|
||||
&context->socketmgr, &context->timermgr);
|
||||
|
||||
context->magic = 0;
|
||||
|
||||
isc_mem_putanddetach(&context->mctx, context, sizeof(*context));
|
||||
}
|
||||
|
||||
isc_mem_t *
|
||||
irs_context_getmctx(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->mctx);
|
||||
}
|
||||
|
||||
isc_appctx_t *
|
||||
irs_context_getappctx(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->actx);
|
||||
}
|
||||
|
||||
isc_taskmgr_t *
|
||||
irs_context_gettaskmgr(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->taskmgr);
|
||||
}
|
||||
|
||||
isc_timermgr_t *
|
||||
irs_context_gettimermgr(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->timermgr);
|
||||
}
|
||||
|
||||
isc_task_t *
|
||||
irs_context_gettask(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->task);
|
||||
}
|
||||
|
||||
dns_client_t *
|
||||
irs_context_getdnsclient(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->dnsclient);
|
||||
}
|
||||
|
||||
irs_resconf_t *
|
||||
irs_context_getresconf(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->resconf);
|
||||
}
|
||||
|
||||
irs_dnsconf_t *
|
||||
irs_context_getdnsconf(irs_context_t *context) {
|
||||
REQUIRE(IRS_CONTEXT_VALID(context));
|
||||
|
||||
return (context->dnsconf);
|
||||
}
|
||||
|
|
@ -1,289 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/base64.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/file.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/fixedname.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/rdatastruct.h>
|
||||
|
||||
#include <isccfg/dnsconf.h>
|
||||
|
||||
#include <irs/dnsconf.h>
|
||||
|
||||
#define IRS_DNSCONF_MAGIC ISC_MAGIC('D', 'c', 'f', 'g')
|
||||
#define IRS_DNSCONF_VALID(c) ISC_MAGIC_VALID(c, IRS_DNSCONF_MAGIC)
|
||||
|
||||
/*!
|
||||
* configuration data structure
|
||||
*/
|
||||
|
||||
struct irs_dnsconf {
|
||||
unsigned int magic;
|
||||
isc_mem_t *mctx;
|
||||
irs_dnsconf_dnskeylist_t trusted_keylist;
|
||||
};
|
||||
|
||||
static isc_result_t
|
||||
configure_key(isc_mem_t *mctx, const cfg_obj_t *key, irs_dnsconf_t *conf,
|
||||
dns_rdataclass_t rdclass) {
|
||||
isc_result_t result;
|
||||
uint32_t flags, proto, alg;
|
||||
dns_fixedname_t fkeyname;
|
||||
dns_name_t *keyname_base = NULL, *keyname = NULL;
|
||||
const char *keystr = NULL, *keynamestr = NULL;
|
||||
unsigned char keydata[4096];
|
||||
isc_buffer_t keydatabuf_base, *keydatabuf = NULL;
|
||||
dns_rdata_dnskey_t keystruct;
|
||||
unsigned char rrdata[4096];
|
||||
isc_buffer_t rrdatabuf;
|
||||
isc_region_t r;
|
||||
isc_buffer_t namebuf;
|
||||
irs_dnsconf_dnskey_t *keyent = NULL;
|
||||
|
||||
flags = cfg_obj_asuint32(cfg_tuple_get(key, "flags"));
|
||||
proto = cfg_obj_asuint32(cfg_tuple_get(key, "protocol"));
|
||||
alg = cfg_obj_asuint32(cfg_tuple_get(key, "algorithm"));
|
||||
keynamestr = cfg_obj_asstring(cfg_tuple_get(key, "name"));
|
||||
|
||||
keystruct.common.rdclass = rdclass;
|
||||
keystruct.common.rdtype = dns_rdatatype_dnskey;
|
||||
keystruct.mctx = NULL;
|
||||
ISC_LINK_INIT(&keystruct.common, link);
|
||||
|
||||
if (flags > 0xffff) {
|
||||
return (ISC_R_RANGE);
|
||||
}
|
||||
if (proto > 0xff) {
|
||||
return (ISC_R_RANGE);
|
||||
}
|
||||
if (alg > 0xff) {
|
||||
return (ISC_R_RANGE);
|
||||
}
|
||||
keystruct.flags = (uint16_t)flags;
|
||||
keystruct.protocol = (uint8_t)proto;
|
||||
keystruct.algorithm = (uint8_t)alg;
|
||||
|
||||
isc_buffer_init(&keydatabuf_base, keydata, sizeof(keydata));
|
||||
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
|
||||
|
||||
/* Configure key value */
|
||||
keystr = cfg_obj_asstring(cfg_tuple_get(key, "key"));
|
||||
result = isc_base64_decodestring(keystr, &keydatabuf_base);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
isc_buffer_usedregion(&keydatabuf_base, &r);
|
||||
keystruct.datalen = r.length;
|
||||
keystruct.data = r.base;
|
||||
|
||||
result = dns_rdata_fromstruct(NULL, keystruct.common.rdclass,
|
||||
keystruct.common.rdtype, &keystruct,
|
||||
&rrdatabuf);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
isc_buffer_usedregion(&rrdatabuf, &r);
|
||||
isc_buffer_allocate(mctx, &keydatabuf, r.length);
|
||||
result = isc_buffer_copyregion(keydatabuf, &r);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Configure key name */
|
||||
keyname_base = dns_fixedname_initname(&fkeyname);
|
||||
isc_buffer_constinit(&namebuf, keynamestr, strlen(keynamestr));
|
||||
isc_buffer_add(&namebuf, strlen(keynamestr));
|
||||
result = dns_name_fromtext(keyname_base, &namebuf, dns_rootname, 0,
|
||||
NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
keyname = isc_mem_get(mctx, sizeof(*keyname));
|
||||
dns_name_init(keyname, NULL);
|
||||
dns_name_dup(keyname_base, mctx, keyname);
|
||||
|
||||
/* Add the key data to the list */
|
||||
keyent = isc_mem_get(mctx, sizeof(*keyent));
|
||||
keyent->keyname = keyname;
|
||||
keyent->keydatabuf = keydatabuf;
|
||||
|
||||
ISC_LIST_APPEND(conf->trusted_keylist, keyent, link);
|
||||
|
||||
cleanup:
|
||||
if (keydatabuf != NULL) {
|
||||
isc_buffer_free(&keydatabuf);
|
||||
}
|
||||
if (keyname != NULL) {
|
||||
isc_mem_put(mctx, keyname, sizeof(*keyname));
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
configure_keygroup(irs_dnsconf_t *conf, const cfg_obj_t *keys,
|
||||
dns_rdataclass_t rdclass) {
|
||||
isc_result_t result;
|
||||
const cfg_obj_t *key, *keylist;
|
||||
const cfg_listelt_t *element, *element2;
|
||||
isc_mem_t *mctx = conf->mctx;
|
||||
|
||||
for (element = cfg_list_first(keys); element != NULL;
|
||||
element = cfg_list_next(element))
|
||||
{
|
||||
keylist = cfg_listelt_value(element);
|
||||
for (element2 = cfg_list_first(keylist); element2 != NULL;
|
||||
element2 = cfg_list_next(element2))
|
||||
{
|
||||
key = cfg_listelt_value(element2);
|
||||
result = configure_key(mctx, key, conf, rdclass);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
configure_dnsseckeys(irs_dnsconf_t *conf, cfg_obj_t *cfgobj,
|
||||
dns_rdataclass_t rdclass) {
|
||||
isc_result_t result;
|
||||
const cfg_obj_t *keys = NULL;
|
||||
|
||||
cfg_map_get(cfgobj, "trusted-keys", &keys);
|
||||
if (keys == NULL) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
result = configure_keygroup(conf, keys, rdclass);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
keys = NULL;
|
||||
cfg_map_get(cfgobj, "trust-anchors", &keys);
|
||||
if (keys == NULL) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
result = configure_keygroup(conf, keys, rdclass);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
keys = NULL;
|
||||
cfg_map_get(cfgobj, "managed-keys", &keys);
|
||||
if (keys == NULL) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
result = configure_keygroup(conf, keys, rdclass);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
irs_dnsconf_load(isc_mem_t *mctx, const char *filename, irs_dnsconf_t **confp) {
|
||||
irs_dnsconf_t *conf;
|
||||
cfg_parser_t *parser = NULL;
|
||||
cfg_obj_t *cfgobj = NULL;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
REQUIRE(confp != NULL && *confp == NULL);
|
||||
|
||||
conf = isc_mem_get(mctx, sizeof(*conf));
|
||||
|
||||
conf->mctx = mctx;
|
||||
ISC_LIST_INIT(conf->trusted_keylist);
|
||||
|
||||
/*
|
||||
* If the specified file does not exist, we'll simply with an empty
|
||||
* configuration.
|
||||
*/
|
||||
if (!isc_file_exists(filename)) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = cfg_parser_create(mctx, NULL, &parser);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = cfg_parse_file(parser, filename, &cfg_type_dnsconf, &cfgobj);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = configure_dnsseckeys(conf, cfgobj, dns_rdataclass_in);
|
||||
|
||||
cleanup:
|
||||
if (parser != NULL) {
|
||||
if (cfgobj != NULL) {
|
||||
cfg_obj_destroy(parser, &cfgobj);
|
||||
}
|
||||
cfg_parser_destroy(&parser);
|
||||
}
|
||||
|
||||
conf->magic = IRS_DNSCONF_MAGIC;
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
*confp = conf;
|
||||
} else {
|
||||
irs_dnsconf_destroy(&conf);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
irs_dnsconf_destroy(irs_dnsconf_t **confp) {
|
||||
irs_dnsconf_t *conf;
|
||||
irs_dnsconf_dnskey_t *keyent;
|
||||
|
||||
REQUIRE(confp != NULL);
|
||||
conf = *confp;
|
||||
*confp = NULL;
|
||||
REQUIRE(IRS_DNSCONF_VALID(conf));
|
||||
|
||||
while ((keyent = ISC_LIST_HEAD(conf->trusted_keylist)) != NULL) {
|
||||
ISC_LIST_UNLINK(conf->trusted_keylist, keyent, link);
|
||||
|
||||
isc_buffer_free(&keyent->keydatabuf);
|
||||
dns_name_free(keyent->keyname, conf->mctx);
|
||||
isc_mem_put(conf->mctx, keyent->keyname, sizeof(dns_name_t));
|
||||
isc_mem_put(conf->mctx, keyent, sizeof(*keyent));
|
||||
}
|
||||
|
||||
isc_mem_put(conf->mctx, conf, sizeof(*conf));
|
||||
}
|
||||
|
||||
irs_dnsconf_dnskeylist_t *
|
||||
irs_dnsconf_gettrustedkeys(irs_dnsconf_t *conf) {
|
||||
REQUIRE(IRS_DNSCONF_VALID(conf));
|
||||
|
||||
return (&conf->trusted_keylist);
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file gai_strerror.c
|
||||
* gai_strerror() returns an error message corresponding to an
|
||||
* error code returned by getaddrinfo() and getnameinfo(). The following error
|
||||
* codes and their meaning are defined in
|
||||
* \link netdb.h include/irs/netdb.h.\endlink
|
||||
* This implementation is almost an exact copy of lwres/gai_sterror.c except
|
||||
* that it catches up the latest API standard, RFC3493.
|
||||
*
|
||||
* \li #EAI_ADDRFAMILY address family for hostname not supported
|
||||
* \li #EAI_AGAIN temporary failure in name resolution
|
||||
* \li #EAI_BADFLAGS invalid value for ai_flags
|
||||
* \li #EAI_FAIL non-recoverable failure in name resolution
|
||||
* \li #EAI_FAMILY ai_family not supported
|
||||
* \li #EAI_MEMORY memory allocation failure
|
||||
* \li #EAI_NODATA no address associated with hostname (obsoleted in RFC3493)
|
||||
* \li #EAI_NONAME hostname nor servname provided, or not known
|
||||
* \li #EAI_SERVICE servname not supported for ai_socktype
|
||||
* \li #EAI_SOCKTYPE ai_socktype not supported
|
||||
* \li #EAI_SYSTEM system error returned in errno
|
||||
* \li #EAI_BADHINTS Invalid value for hints (non-standard)
|
||||
* \li #EAI_PROTOCOL Resolved protocol is unknown (non-standard)
|
||||
* \li #EAI_OVERFLOW Argument buffer overflow
|
||||
* \li #EAI_INSECUREDATA Insecure Data (experimental)
|
||||
*
|
||||
* The message invalid error code is returned if ecode is out of range.
|
||||
*
|
||||
* ai_flags, ai_family and ai_socktype are elements of the struct
|
||||
* addrinfo used by lwres_getaddrinfo().
|
||||
*
|
||||
* \section gai_strerror_see See Also
|
||||
*
|
||||
* strerror(), getaddrinfo(), getnameinfo(), RFC3493.
|
||||
*/
|
||||
|
||||
#include <isc/net.h>
|
||||
|
||||
#include <irs/netdb.h>
|
||||
|
||||
/*% Text of error messages. */
|
||||
static const char *gai_messages[] = { "no error",
|
||||
"address family for hostname not "
|
||||
"supported",
|
||||
"temporary failure in name resolution",
|
||||
"invalid value for ai_flags",
|
||||
"non-recoverable failure in name "
|
||||
"resolution",
|
||||
"ai_family not supported",
|
||||
"memory allocation failure",
|
||||
"no address associated with hostname",
|
||||
"hostname nor servname provided, or not "
|
||||
"known",
|
||||
"servname not supported for ai_socktype",
|
||||
"ai_socktype not supported",
|
||||
"system error returned in errno",
|
||||
"bad hints",
|
||||
"bad protocol",
|
||||
"argument buffer overflow",
|
||||
"insecure data provided" };
|
||||
|
||||
/*%
|
||||
* Returns an error message corresponding to an error code returned by
|
||||
* getaddrinfo() and getnameinfo()
|
||||
*/
|
||||
#if defined _WIN32
|
||||
char *
|
||||
#else /* if defined _WIN32 */
|
||||
const char *
|
||||
#endif /* if defined _WIN32 */
|
||||
gai_strerror(int ecode) {
|
||||
union {
|
||||
const char *const_ptr;
|
||||
char *deconst_ptr;
|
||||
} ptr;
|
||||
|
||||
if ((ecode < 0) ||
|
||||
(ecode >= (int)(sizeof(gai_messages) / sizeof(*gai_messages))))
|
||||
{
|
||||
ptr.const_ptr = "invalid error code";
|
||||
} else {
|
||||
ptr.const_ptr = gai_messages[ecode];
|
||||
}
|
||||
return (ptr.deconst_ptr);
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,435 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* getnameinfo() returns the hostname for the struct sockaddr sa which is
|
||||
* salen bytes long. The hostname is of length hostlen and is returned via
|
||||
* *host. The maximum length of the hostname is 1025 bytes: #NI_MAXHOST.
|
||||
*
|
||||
* The name of the service associated with the port number in sa is
|
||||
* returned in *serv. It is servlen bytes long. The maximum length of the
|
||||
* service name is #NI_MAXSERV - 32 bytes.
|
||||
*
|
||||
* The flags argument sets the following bits:
|
||||
*
|
||||
* \li #NI_NOFQDN:
|
||||
* A fully qualified domain name is not required for local hosts.
|
||||
* The local part of the fully qualified domain name is returned
|
||||
* instead.
|
||||
*
|
||||
* \li #NI_NUMERICHOST
|
||||
* Return the address in numeric form, as if calling inet_ntop(),
|
||||
* instead of a host name.
|
||||
*
|
||||
* \li #NI_NAMEREQD
|
||||
* A name is required. If the hostname cannot be found in the DNS
|
||||
* and this flag is set, a non-zero error code is returned. If the
|
||||
* hostname is not found and the flag is not set, the address is
|
||||
* returned in numeric form.
|
||||
*
|
||||
* \li #NI_NUMERICSERV
|
||||
* The service name is returned as a digit string representing the
|
||||
* port number.
|
||||
*
|
||||
* \li #NI_DGRAM
|
||||
* Specifies that the service being looked up is a datagram
|
||||
* service, and causes getservbyport() to be called with a second
|
||||
* argument of "udp" instead of its default of "tcp". This is
|
||||
* required for the few ports (512-514) that have different
|
||||
* services for UDP and TCP.
|
||||
*
|
||||
* \section getnameinfo_return Return Values
|
||||
*
|
||||
* getnameinfo() returns 0 on success or a non-zero error code if
|
||||
* an error occurs.
|
||||
*
|
||||
* \section getname_see See Also
|
||||
*
|
||||
* RFC3493, getservbyport(),
|
||||
* getnamebyaddr(). inet_ntop().
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/byaddr.h>
|
||||
#include <dns/client.h>
|
||||
#include <dns/fixedname.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/rdataset.h>
|
||||
#include <dns/rdatastruct.h>
|
||||
#include <dns/result.h>
|
||||
|
||||
#include <irs/context.h>
|
||||
#include <irs/netdb.h>
|
||||
|
||||
#define SUCCESS 0
|
||||
|
||||
/*% afd structure definition */
|
||||
static struct afd {
|
||||
int a_af;
|
||||
size_t a_addrlen;
|
||||
size_t a_socklen;
|
||||
} afdl[] = {
|
||||
/*!
|
||||
* First entry is linked last...
|
||||
*/
|
||||
{ AF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in) },
|
||||
{ AF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6) },
|
||||
{ 0, 0, 0 },
|
||||
};
|
||||
|
||||
/*!
|
||||
* The test against 0 is there to keep the Solaris compiler
|
||||
* from complaining about "end-of-loop code not reached".
|
||||
*/
|
||||
#define ERR(code) \
|
||||
do { \
|
||||
result = (code); \
|
||||
if (result != 0) \
|
||||
goto cleanup; \
|
||||
} while (0)
|
||||
|
||||
#ifdef _WIN32
|
||||
int
|
||||
getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host,
|
||||
DWORD hostlen, char *serv, DWORD servlen, int flags) {
|
||||
#else
|
||||
int
|
||||
getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host,
|
||||
socklen_t hostlen, char *serv, socklen_t servlen, int flags) {
|
||||
#endif
|
||||
struct afd *afd = NULL;
|
||||
struct servent *sp;
|
||||
unsigned short port = 0;
|
||||
#ifdef IRS_PLATFORM_HAVESALEN
|
||||
size_t len;
|
||||
#endif /* ifdef IRS_PLATFORM_HAVESALEN */
|
||||
int family, i;
|
||||
const void *addr = NULL;
|
||||
char *p;
|
||||
#if 0
|
||||
unsigned long v4a;
|
||||
unsigned char pfx;
|
||||
#endif /* if 0 */
|
||||
char numserv[sizeof("65000")];
|
||||
char numaddr[sizeof("abcd:abcd:abcd:abcd:abcd:abcd:255.255.255.255") +
|
||||
1 + sizeof("4294967295")];
|
||||
const char *proto;
|
||||
int result = SUCCESS;
|
||||
|
||||
if (sa == NULL) {
|
||||
ERR(EAI_FAIL);
|
||||
}
|
||||
|
||||
#ifdef IRS_PLATFORM_HAVESALEN
|
||||
len = sa->sa_len;
|
||||
if (len != salen) {
|
||||
ERR(EAI_FAIL);
|
||||
}
|
||||
#endif /* ifdef IRS_PLATFORM_HAVESALEN */
|
||||
|
||||
family = sa->sa_family;
|
||||
for (i = 0; afdl[i].a_af; i++) {
|
||||
if (afdl[i].a_af == family) {
|
||||
{
|
||||
afd = &afdl[i];
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
ERR(EAI_FAMILY);
|
||||
|
||||
found:
|
||||
if (salen != afd->a_socklen) {
|
||||
ERR(EAI_FAIL);
|
||||
}
|
||||
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
port = ((const struct sockaddr_in *)sa)->sin_port;
|
||||
addr = &((const struct sockaddr_in *)sa)->sin_addr.s_addr;
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
port = ((const struct sockaddr_in6 *)sa)->sin6_port;
|
||||
addr = ((const struct sockaddr_in6 *)sa)->sin6_addr.s6_addr;
|
||||
break;
|
||||
|
||||
default:
|
||||
INSIST(0);
|
||||
ISC_UNREACHABLE();
|
||||
}
|
||||
proto = ((flags & NI_DGRAM) != 0) ? "udp" : "tcp";
|
||||
|
||||
if (serv == NULL || servlen == 0U) {
|
||||
/*
|
||||
* Caller does not want service.
|
||||
*/
|
||||
} else if ((flags & NI_NUMERICSERV) != 0 ||
|
||||
(sp = getservbyport(port, proto)) == NULL)
|
||||
{
|
||||
snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
|
||||
if ((strlen(numserv) + 1) > servlen) {
|
||||
ERR(EAI_OVERFLOW);
|
||||
}
|
||||
strlcpy(serv, numserv, servlen);
|
||||
} else {
|
||||
if ((strlen(sp->s_name) + 1) > servlen) {
|
||||
ERR(EAI_OVERFLOW);
|
||||
}
|
||||
strlcpy(serv, sp->s_name, servlen);
|
||||
}
|
||||
|
||||
#if 0
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET:
|
||||
v4a = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
|
||||
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) {
|
||||
flags |= NI_NUMERICHOST;
|
||||
}
|
||||
v4a >>= IN_CLASSA_NSHIFT;
|
||||
if (v4a == 0 || v4a == IN_LOOPBACKNET) {
|
||||
flags |= NI_NUMERICHOST;
|
||||
}
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0];
|
||||
if (pfx == 0 || pfx == 0xfe || pfx == 0xff) {
|
||||
flags |= NI_NUMERICHOST;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* if 0 */
|
||||
|
||||
if (host == NULL || hostlen == 0U) {
|
||||
/*
|
||||
* do nothing in this case.
|
||||
* in case you are wondering if "&&" is more correct than
|
||||
* "||" here: RFC3493 says that host == NULL or hostlen == 0
|
||||
* means that the caller does not want the result.
|
||||
*/
|
||||
} else if ((flags & NI_NUMERICHOST) != 0) {
|
||||
if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) ==
|
||||
NULL) {
|
||||
ERR(EAI_SYSTEM);
|
||||
}
|
||||
#if defined(IRS_HAVE_SIN6_SCOPE_ID)
|
||||
if (afd->a_af == AF_INET6 &&
|
||||
((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
|
||||
char *p = numaddr + strlen(numaddr);
|
||||
const char *stringscope = NULL;
|
||||
#ifdef VENDOR_SPECIFIC
|
||||
/*
|
||||
* Vendors may want to add support for
|
||||
* non-numeric scope identifier.
|
||||
*/
|
||||
stringscope = foo;
|
||||
#endif /* ifdef VENDOR_SPECIFIC */
|
||||
if (stringscope == NULL) {
|
||||
snprintf(p, sizeof(numaddr) - (p - numaddr),
|
||||
"%%%u",
|
||||
((const struct sockaddr_in6 *)sa)
|
||||
->sin6_scope_id);
|
||||
} else {
|
||||
snprintf(p, sizeof(numaddr) - (p - numaddr),
|
||||
"%%%s", stringscope);
|
||||
}
|
||||
}
|
||||
#endif /* if defined(IRS_HAVE_SIN6_SCOPE_ID) */
|
||||
if (strlen(numaddr) + 1 > hostlen) {
|
||||
ERR(EAI_OVERFLOW);
|
||||
}
|
||||
strlcpy(host, numaddr, hostlen);
|
||||
} else {
|
||||
isc_netaddr_t netaddr;
|
||||
dns_fixedname_t ptrfname;
|
||||
dns_name_t *ptrname;
|
||||
irs_context_t *irsctx = NULL;
|
||||
dns_client_t *client;
|
||||
bool found = false;
|
||||
dns_namelist_t answerlist;
|
||||
dns_rdataset_t *rdataset;
|
||||
isc_region_t hostregion;
|
||||
char hoststr[1024]; /* is this enough? */
|
||||
isc_result_t iresult;
|
||||
|
||||
/* Get IRS context and the associated DNS client object */
|
||||
iresult = irs_context_get(&irsctx);
|
||||
if (iresult != ISC_R_SUCCESS) {
|
||||
ERR(EAI_FAIL);
|
||||
}
|
||||
client = irs_context_getdnsclient(irsctx);
|
||||
|
||||
/* Make query name */
|
||||
isc_netaddr_fromsockaddr(&netaddr, (const isc_sockaddr_t *)sa);
|
||||
ptrname = dns_fixedname_initname(&ptrfname);
|
||||
iresult = dns_byaddr_createptrname(&netaddr, 0, ptrname);
|
||||
if (iresult != ISC_R_SUCCESS) {
|
||||
ERR(EAI_FAIL);
|
||||
}
|
||||
|
||||
/* Get the PTR RRset */
|
||||
ISC_LIST_INIT(answerlist);
|
||||
iresult = dns_client_resolve(
|
||||
client, ptrname, dns_rdataclass_in, dns_rdatatype_ptr,
|
||||
DNS_CLIENTRESOPT_ALLOWRUN, &answerlist);
|
||||
switch (iresult) {
|
||||
case ISC_R_SUCCESS:
|
||||
/*
|
||||
* a 'non-existent' error is not necessarily fatal for
|
||||
* getnameinfo().
|
||||
*/
|
||||
case DNS_R_NCACHENXDOMAIN:
|
||||
case DNS_R_NCACHENXRRSET:
|
||||
break;
|
||||
case DNS_R_SIGINVALID:
|
||||
case DNS_R_SIGEXPIRED:
|
||||
case DNS_R_SIGFUTURE:
|
||||
case DNS_R_KEYUNAUTHORIZED:
|
||||
case DNS_R_MUSTBESECURE:
|
||||
case DNS_R_COVERINGNSEC:
|
||||
case DNS_R_NOTAUTHORITATIVE:
|
||||
case DNS_R_NOVALIDKEY:
|
||||
case DNS_R_NOVALIDDS:
|
||||
case DNS_R_NOVALIDSIG:
|
||||
/*
|
||||
* Don't use ERR as GCC 7 wants to raise a
|
||||
* warning with ERR about possible falling
|
||||
* through which is impossible.
|
||||
*/
|
||||
result = EAI_INSECUREDATA;
|
||||
goto cleanup;
|
||||
default:
|
||||
ERR(EAI_FAIL);
|
||||
}
|
||||
|
||||
/* Parse the answer for the hostname */
|
||||
for (ptrname = ISC_LIST_HEAD(answerlist); ptrname != NULL;
|
||||
ptrname = ISC_LIST_NEXT(ptrname, link))
|
||||
{
|
||||
for (rdataset = ISC_LIST_HEAD(ptrname->list);
|
||||
rdataset != NULL;
|
||||
rdataset = ISC_LIST_NEXT(rdataset, link))
|
||||
{
|
||||
if (!dns_rdataset_isassociated(rdataset)) {
|
||||
continue;
|
||||
}
|
||||
if (rdataset->type != dns_rdatatype_ptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (iresult = dns_rdataset_first(rdataset);
|
||||
iresult == ISC_R_SUCCESS;
|
||||
iresult = dns_rdataset_next(rdataset))
|
||||
{
|
||||
dns_rdata_t rdata;
|
||||
dns_rdata_ptr_t rdata_ptr;
|
||||
isc_buffer_t b;
|
||||
|
||||
dns_rdata_init(&rdata);
|
||||
dns_rdataset_current(rdataset, &rdata);
|
||||
dns_rdata_tostruct(&rdata, &rdata_ptr,
|
||||
NULL);
|
||||
|
||||
isc_buffer_init(&b, hoststr,
|
||||
sizeof(hoststr));
|
||||
iresult = dns_name_totext(
|
||||
&rdata_ptr.ptr, true, &b);
|
||||
dns_rdata_freestruct(&rdata_ptr);
|
||||
if (iresult == ISC_R_SUCCESS) {
|
||||
/*
|
||||
* We ignore the rest of the
|
||||
* answer. After all,
|
||||
* getnameinfo() can return
|
||||
* at most one hostname.
|
||||
*/
|
||||
found = true;
|
||||
isc_buffer_usedregion(
|
||||
&b, &hostregion);
|
||||
goto ptrfound;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ptrfound:
|
||||
dns_client_freeresanswer(client, &answerlist);
|
||||
if (found) {
|
||||
if ((flags & NI_NOFQDN) != 0) {
|
||||
p = strchr(hoststr, '.');
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
if (hostregion.length + 1 > hostlen) {
|
||||
ERR(EAI_OVERFLOW);
|
||||
}
|
||||
snprintf(host, hostlen, "%.*s", (int)hostregion.length,
|
||||
(char *)hostregion.base);
|
||||
} else {
|
||||
if ((flags & NI_NAMEREQD) != 0) {
|
||||
ERR(EAI_NONAME);
|
||||
}
|
||||
if (inet_ntop(afd->a_af, addr, numaddr,
|
||||
sizeof(numaddr)) == NULL) {
|
||||
ERR(EAI_SYSTEM);
|
||||
}
|
||||
if ((strlen(numaddr) + 1) > hostlen) {
|
||||
ERR(EAI_OVERFLOW);
|
||||
}
|
||||
strlcpy(host, numaddr, hostlen);
|
||||
}
|
||||
}
|
||||
result = SUCCESS;
|
||||
|
||||
cleanup:
|
||||
return (result);
|
||||
}
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#ifndef IRS_CONTEXT_H
|
||||
#define IRS_CONTEXT_H 1
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* \brief
|
||||
* The IRS context module provides an abstract interface to the DNS library
|
||||
* with an application. An IRS context object initializes and holds various
|
||||
* resources used in the DNS library.
|
||||
*/
|
||||
|
||||
#include <dns/types.h>
|
||||
|
||||
#include <irs/types.h>
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
irs_context_create(irs_context_t **contextp);
|
||||
/*%<
|
||||
* Create an IRS context. It internally initializes the ISC and DNS libraries
|
||||
* (if not yet), creates a DNS client object and initializes the client using
|
||||
* the configuration files parsed via the 'resconf' and 'dnsconf' IRS modules.
|
||||
* Some of the internally initialized objects can be used by the application
|
||||
* via irs_context_getxxx() functions (see below).
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li contextp != NULL && *contextp == NULL.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
irs_context_get(irs_context_t **contextp);
|
||||
/*%<
|
||||
* Return an IRS context for the calling thread. If no IRS context is
|
||||
* associated to the thread, this function creates a new one by calling
|
||||
* irs_context_create(), and associates it with the thread as a thread specific
|
||||
* data value. This function is provided for standard libraries that are
|
||||
* expected to be thread-safe but do not accept an appropriate IRS context
|
||||
* as a library parameter, e.g., getaddrinfo().
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li contextp != NULL && *contextp == NULL.
|
||||
*/
|
||||
|
||||
void
|
||||
irs_context_destroy(irs_context_t **contextp);
|
||||
/*%<
|
||||
* Destroy an IRS context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li '*contextp' is a valid IRS context.
|
||||
*
|
||||
* Ensures:
|
||||
*\li '*contextp' == NULL.
|
||||
*/
|
||||
|
||||
isc_mem_t *
|
||||
irs_context_getmctx(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the memory context held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
isc_appctx_t *
|
||||
irs_context_getappctx(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the application context held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
isc_taskmgr_t *
|
||||
irs_context_gettaskmgr(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the task manager held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
isc_timermgr_t *
|
||||
irs_context_gettimermgr(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the timer manager held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
isc_task_t *
|
||||
irs_context_gettask(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the task object held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
dns_client_t *
|
||||
irs_context_getdnsclient(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the DNS client object held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
irs_resconf_t *
|
||||
irs_context_getresconf(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the resolver configuration object held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
irs_dnsconf_t *
|
||||
irs_context_getdnsconf(irs_context_t *context);
|
||||
/*%<
|
||||
* Return the advanced DNS configuration object held in the context.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'context' is a valid IRS context.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* IRS_CONTEXT_H */
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#ifndef IRS_DNSCONF_H
|
||||
#define IRS_DNSCONF_H 1
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* \brief
|
||||
* The IRS dnsconf module parses an "advanced" configuration file related to
|
||||
* the DNS library, such as trust anchors for DNSSEC validation, and creates
|
||||
* the corresponding configuration objects for the DNS library modules.
|
||||
*
|
||||
* Notes:
|
||||
* This module is very experimental and the configuration syntax or library
|
||||
* interfaces may change in future versions. Currently, only static
|
||||
* key configuration is supported; "trusted-keys" and "trust-anchors"/
|
||||
* "managed-keys" statements will be parsed exactly as they are in
|
||||
* named.conf, except that "trust-anchors" and "managed-keys" entries will
|
||||
* be treated as if they were configured with "static-key", even if they
|
||||
* were actually configured with "initial-key".
|
||||
*/
|
||||
|
||||
#include <irs/types.h>
|
||||
|
||||
/*%
|
||||
* A compound structure storing DNS key information mainly for DNSSEC
|
||||
* validation. A dns_key_t object will be created using the 'keyname' and
|
||||
* 'keydatabuf' members with the dst_key_fromdns() function.
|
||||
*/
|
||||
typedef struct irs_dnsconf_dnskey {
|
||||
dns_name_t * keyname;
|
||||
isc_buffer_t *keydatabuf;
|
||||
ISC_LINK(struct irs_dnsconf_dnskey) link;
|
||||
} irs_dnsconf_dnskey_t;
|
||||
|
||||
typedef ISC_LIST(irs_dnsconf_dnskey_t) irs_dnsconf_dnskeylist_t;
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
irs_dnsconf_load(isc_mem_t *mctx, const char *filename, irs_dnsconf_t **confp);
|
||||
/*%<
|
||||
* Load the "advanced" DNS configuration file 'filename' in the "dns.conf"
|
||||
* format, and create a new irs_dnsconf_t object from the configuration.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'mctx' is a valid memory context.
|
||||
*
|
||||
*\li 'filename' != NULL
|
||||
*
|
||||
*\li 'confp' != NULL && '*confp' == NULL
|
||||
*/
|
||||
|
||||
void
|
||||
irs_dnsconf_destroy(irs_dnsconf_t **confp);
|
||||
/*%<
|
||||
* Destroy the dnsconf object.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li '*confp' is a valid dnsconf object.
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
*\li *confp == NULL
|
||||
*/
|
||||
|
||||
irs_dnsconf_dnskeylist_t *
|
||||
irs_dnsconf_gettrustedkeys(irs_dnsconf_t *conf);
|
||||
/*%<
|
||||
* Return a list of key information stored in 'conf'.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'conf' is a valid dnsconf object.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* IRS_DNSCONF_H */
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#ifndef IRS_NETDB_H
|
||||
#define IRS_NETDB_H 1
|
||||
|
||||
#include <netdb.h> /* Contractual provision. */
|
||||
#include <stddef.h> /* Required on FreeBSD (and others?) for size_t. */
|
||||
|
||||
/*
|
||||
* Undefine all #defines we are interested in as <netdb.h> may or may not have
|
||||
* defined them.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Error return codes from gethostbyname() and gethostbyaddr()
|
||||
* (left in extern int h_errno).
|
||||
*/
|
||||
|
||||
#undef NETDB_INTERNAL
|
||||
#undef NETDB_SUCCESS
|
||||
#undef HOST_NOT_FOUND
|
||||
#undef TRY_AGAIN
|
||||
#undef NO_RECOVERY
|
||||
#undef NO_DATA
|
||||
#undef NO_ADDRESS
|
||||
|
||||
#define NETDB_INTERNAL -1 /* see errno */
|
||||
#define NETDB_SUCCESS 0 /* no problem */
|
||||
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
|
||||
#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
|
||||
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
||||
#define NO_DATA 4 /* Valid name, no data record of requested type */
|
||||
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
|
||||
|
||||
/*
|
||||
* Error return codes from getaddrinfo(). EAI_INSECUREDATA is our own extension
|
||||
* and it's very unlikely to be already defined, but undef it just in case; it
|
||||
* at least doesn't do any harm.
|
||||
*/
|
||||
|
||||
#undef EAI_ADDRFAMILY
|
||||
#undef EAI_AGAIN
|
||||
#undef EAI_BADFLAGS
|
||||
#undef EAI_FAIL
|
||||
#undef EAI_FAMILY
|
||||
#undef EAI_MEMORY
|
||||
#undef EAI_NODATA
|
||||
#undef EAI_NONAME
|
||||
#undef EAI_SERVICE
|
||||
#undef EAI_SOCKTYPE
|
||||
#undef EAI_SYSTEM
|
||||
#undef EAI_BADHINTS
|
||||
#undef EAI_PROTOCOL
|
||||
#undef EAI_OVERFLOW
|
||||
#undef EAI_INSECUREDATA
|
||||
#undef EAI_MAX
|
||||
|
||||
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
|
||||
#define EAI_AGAIN 2 /* temporary failure in name resolution */
|
||||
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
|
||||
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
|
||||
#define EAI_FAMILY 5 /* ai_family not supported */
|
||||
#define EAI_MEMORY 6 /* memory allocation failure */
|
||||
#define EAI_NODATA 7 /* no address associated with hostname */
|
||||
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
|
||||
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
|
||||
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
|
||||
#define EAI_SYSTEM 11 /* system error returned in errno */
|
||||
#define EAI_BADHINTS 12
|
||||
#define EAI_PROTOCOL 13
|
||||
#define EAI_OVERFLOW 14
|
||||
#define EAI_INSECUREDATA 15
|
||||
#define EAI_MAX 16
|
||||
|
||||
/*
|
||||
* Flag values for getaddrinfo()
|
||||
*/
|
||||
#undef AI_PASSIVE
|
||||
#undef AI_CANONNAME
|
||||
#undef AI_NUMERICHOST
|
||||
|
||||
#define AI_PASSIVE 0x00000001
|
||||
#define AI_CANONNAME 0x00000002
|
||||
#define AI_NUMERICHOST 0x00000004
|
||||
|
||||
/*
|
||||
* Flag values for getipnodebyname()
|
||||
*/
|
||||
#undef AI_V4MAPPED
|
||||
#undef AI_ALL
|
||||
#undef AI_ADDRCONFIG
|
||||
#undef AI_DEFAULT
|
||||
|
||||
#define AI_V4MAPPED 0x00000008
|
||||
#define AI_ALL 0x00000010
|
||||
#define AI_ADDRCONFIG 0x00000020
|
||||
#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
|
||||
|
||||
/*
|
||||
* Constants for getnameinfo()
|
||||
*/
|
||||
#undef NI_MAXHOST
|
||||
#undef NI_MAXSERV
|
||||
|
||||
#define NI_MAXHOST 1025
|
||||
#define NI_MAXSERV 32
|
||||
|
||||
/*
|
||||
* Flag values for getnameinfo()
|
||||
*/
|
||||
#undef NI_NOFQDN
|
||||
#undef NI_NUMERICHOST
|
||||
#undef NI_NAMEREQD
|
||||
#undef NI_NUMERICSERV
|
||||
#undef NI_DGRAM
|
||||
#undef NI_NUMERICSCOPE
|
||||
|
||||
#define NI_NOFQDN 0x00000001
|
||||
#define NI_NUMERICHOST 0x00000002
|
||||
#define NI_NAMEREQD 0x00000004
|
||||
#define NI_NUMERICSERV 0x00000008
|
||||
#define NI_DGRAM 0x00000010
|
||||
|
||||
/*
|
||||
* Define to map into irs_ namespace.
|
||||
*/
|
||||
|
||||
#define IRS_NAMESPACE
|
||||
|
||||
#ifdef IRS_NAMESPACE
|
||||
|
||||
/*
|
||||
* Use our versions not the ones from the C library.
|
||||
*/
|
||||
|
||||
#ifdef getnameinfo
|
||||
#undef getnameinfo
|
||||
#endif
|
||||
#define getnameinfo irs_getnameinfo
|
||||
|
||||
#ifdef getaddrinfo
|
||||
#undef getaddrinfo
|
||||
#endif
|
||||
#define getaddrinfo irs_getaddrinfo
|
||||
|
||||
#ifdef freeaddrinfo
|
||||
#undef freeaddrinfo
|
||||
#endif
|
||||
#define freeaddrinfo irs_freeaddrinfo
|
||||
|
||||
#ifdef gai_strerror
|
||||
#undef gai_strerror
|
||||
#endif
|
||||
#define gai_strerror irs_gai_strerror
|
||||
|
||||
int
|
||||
getaddrinfo(const char *hostname, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res);
|
||||
|
||||
int
|
||||
getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host,
|
||||
socklen_t hostlen, char *serv, socklen_t servlen, int flags);
|
||||
|
||||
void
|
||||
freeaddrinfo(struct addrinfo *ai);
|
||||
|
||||
const char *
|
||||
gai_strerror(int ecode);
|
||||
|
||||
#endif /* IRS_NAMESPACE */
|
||||
|
||||
/*
|
||||
* Tell Emacs to use C mode on this file.
|
||||
* Local variables:
|
||||
* mode: c
|
||||
* End:
|
||||
*/
|
||||
|
||||
#endif /* IRS_NETDB_H */
|
||||
|
|
@ -9,8 +9,11 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#ifndef IRS_RESCONF_H
|
||||
#define IRS_RESCONF_H 1
|
||||
#pragma once
|
||||
|
||||
#include <isc/lang.h>
|
||||
#include <isc/list.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
/*! \file
|
||||
*
|
||||
|
|
@ -20,7 +23,8 @@
|
|||
* modules.
|
||||
*/
|
||||
|
||||
#include <irs/types.h>
|
||||
/*%< resolv.conf configuration information */
|
||||
typedef struct irs_resconf irs_resconf_t;
|
||||
|
||||
/*%
|
||||
* A DNS search list specified in the 'domain' or 'search' statements
|
||||
|
|
@ -112,5 +116,3 @@ irs_resconf_getndots(irs_resconf_t *conf);
|
|||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* IRS_RESCONF_H */
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#ifndef IRS_TYPES_H
|
||||
#define IRS_TYPES_H 1
|
||||
|
||||
/* Core Types. Alphabetized by defined type. */
|
||||
|
||||
/*%< per-thread IRS context */
|
||||
typedef struct irs_context irs_context_t;
|
||||
/*%< resolv.conf configuration information */
|
||||
typedef struct irs_resconf irs_resconf_t;
|
||||
/*%< advanced DNS-related configuration information */
|
||||
typedef struct irs_dnsconf irs_dnsconf_t;
|
||||
|
||||
#endif /* IRS_TYPES_H */
|
||||
|
|
@ -51,7 +51,6 @@
|
|||
#include <isc/sockaddr.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <irs/netdb.h>
|
||||
#include <irs/resconf.h>
|
||||
|
||||
#define IRS_RESCONF_MAGIC ISC_MAGIC('R', 'E', 'S', 'c')
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <isc/util.h>
|
||||
|
||||
#include <irs/resconf.h>
|
||||
#include <irs/types.h>
|
||||
|
||||
static isc_mem_t *mctx = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,205 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#ifndef IRS_NETDB_H
|
||||
#define IRS_NETDB_H 1
|
||||
|
||||
#include <stddef.h> /* Required on FreeBSD (and others?) for size_t. */
|
||||
|
||||
/*
|
||||
* Define if <netdb.h> does not declare struct addrinfo.
|
||||
*/
|
||||
#undef ISC_IRS_NEEDADDRINFO
|
||||
|
||||
#ifdef ISC_IRS_NEEDADDRINFO
|
||||
struct addrinfo {
|
||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
||||
int ai_family; /* PF_xxx */
|
||||
int ai_socktype; /* SOCK_xxx */
|
||||
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and
|
||||
* IPv6 */
|
||||
size_t ai_addrlen; /* Length of ai_addr */
|
||||
char * ai_canonname; /* Canonical name for hostname */
|
||||
struct sockaddr *ai_addr; /* Binary address */
|
||||
struct addrinfo *ai_next; /* Next structure in linked list */
|
||||
};
|
||||
#endif /* ifdef ISC_IRS_NEEDADDRINFO */
|
||||
|
||||
/*
|
||||
* Undefine all #defines we are interested in as <netdb.h> may or may not have
|
||||
* defined them.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Error return codes from gethostbyname() and gethostbyaddr()
|
||||
* (left in extern int h_errno).
|
||||
*/
|
||||
|
||||
#undef NETDB_INTERNAL
|
||||
#undef NETDB_SUCCESS
|
||||
#undef HOST_NOT_FOUND
|
||||
#undef TRY_AGAIN
|
||||
#undef NO_RECOVERY
|
||||
#undef NO_DATA
|
||||
#undef NO_ADDRESS
|
||||
|
||||
#define NETDB_INTERNAL -1 /* see errno */
|
||||
#define NETDB_SUCCESS 0 /* no problem */
|
||||
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
|
||||
#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
|
||||
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
||||
#define NO_DATA 4 /* Valid name, no data record of requested type */
|
||||
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
|
||||
|
||||
/*
|
||||
* Error return codes from getaddrinfo(). EAI_INSECUREDATA is our own extension
|
||||
* and it's very unlikely to be already defined, but undef it just in case; it
|
||||
* at least doesn't do any harm.
|
||||
*/
|
||||
|
||||
#undef EAI_ADDRFAMILY
|
||||
#undef EAI_AGAIN
|
||||
#undef EAI_BADFLAGS
|
||||
#undef EAI_FAIL
|
||||
#undef EAI_FAMILY
|
||||
#undef EAI_MEMORY
|
||||
#undef EAI_NODATA
|
||||
#undef EAI_NONAME
|
||||
#undef EAI_SERVICE
|
||||
#undef EAI_SOCKTYPE
|
||||
#undef EAI_SYSTEM
|
||||
#undef EAI_BADHINTS
|
||||
#undef EAI_PROTOCOL
|
||||
#undef EAI_OVERFLOW
|
||||
#undef EAI_INSECUREDATA
|
||||
#undef EAI_MAX
|
||||
|
||||
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
|
||||
#define EAI_AGAIN 2 /* temporary failure in name resolution */
|
||||
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
|
||||
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
|
||||
#define EAI_FAMILY 5 /* ai_family not supported */
|
||||
#define EAI_MEMORY 6 /* memory allocation failure */
|
||||
#define EAI_NODATA 7 /* no address associated with hostname */
|
||||
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
|
||||
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
|
||||
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
|
||||
#define EAI_SYSTEM 11 /* system error returned in errno */
|
||||
#define EAI_BADHINTS 12
|
||||
#define EAI_PROTOCOL 13
|
||||
#define EAI_OVERFLOW 14
|
||||
#define EAI_INSECUREDATA 15
|
||||
#define EAI_MAX 16
|
||||
|
||||
/*
|
||||
* Flag values for getaddrinfo()
|
||||
*/
|
||||
#undef AI_PASSIVE
|
||||
#undef AI_CANONNAME
|
||||
#undef AI_NUMERICHOST
|
||||
|
||||
#define AI_PASSIVE 0x00000001
|
||||
#define AI_CANONNAME 0x00000002
|
||||
#define AI_NUMERICHOST 0x00000004
|
||||
|
||||
/*
|
||||
* Flag values for getipnodebyname()
|
||||
*/
|
||||
#undef AI_V4MAPPED
|
||||
#undef AI_ALL
|
||||
#undef AI_ADDRCONFIG
|
||||
#undef AI_DEFAULT
|
||||
|
||||
#define AI_V4MAPPED 0x00000008
|
||||
#define AI_ALL 0x00000010
|
||||
#define AI_ADDRCONFIG 0x00000020
|
||||
#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
|
||||
|
||||
/*
|
||||
* Constants for getnameinfo()
|
||||
*/
|
||||
#undef NI_MAXHOST
|
||||
#undef NI_MAXSERV
|
||||
|
||||
#define NI_MAXHOST 1025
|
||||
#define NI_MAXSERV 32
|
||||
|
||||
/*
|
||||
* Flag values for getnameinfo()
|
||||
*/
|
||||
#undef NI_NOFQDN
|
||||
#undef NI_NUMERICHOST
|
||||
#undef NI_NAMEREQD
|
||||
#undef NI_NUMERICSERV
|
||||
#undef NI_DGRAM
|
||||
#undef NI_NUMERICSCOPE
|
||||
|
||||
#define NI_NOFQDN 0x00000001
|
||||
#define NI_NUMERICHOST 0x00000002
|
||||
#define NI_NAMEREQD 0x00000004
|
||||
#define NI_NUMERICSERV 0x00000008
|
||||
#define NI_DGRAM 0x00000010
|
||||
|
||||
/*
|
||||
* Define to map into irs_ namespace.
|
||||
*/
|
||||
|
||||
#define IRS_NAMESPACE
|
||||
|
||||
#ifdef IRS_NAMESPACE
|
||||
|
||||
/*
|
||||
* Use our versions not the ones from the C library.
|
||||
*/
|
||||
|
||||
#ifdef getnameinfo
|
||||
#undef getnameinfo
|
||||
#endif /* ifdef getnameinfo */
|
||||
#define getnameinfo irs_getnameinfo
|
||||
|
||||
#ifdef getaddrinfo
|
||||
#undef getaddrinfo
|
||||
#endif /* ifdef getaddrinfo */
|
||||
#define getaddrinfo irs_getaddrinfo
|
||||
|
||||
#ifdef freeaddrinfo
|
||||
#undef freeaddrinfo
|
||||
#endif /* ifdef freeaddrinfo */
|
||||
#define freeaddrinfo irs_freeaddrinfo
|
||||
|
||||
#ifdef gai_strerror
|
||||
#undef gai_strerror
|
||||
#endif /* ifdef gai_strerror */
|
||||
#define gai_strerror irs_gai_strerror
|
||||
|
||||
#endif /* ifdef IRS_NAMESPACE */
|
||||
|
||||
int
|
||||
getaddrinfo(const char *, const char *, const struct addrinfo *,
|
||||
struct addrinfo **);
|
||||
int
|
||||
getnameinfo(const struct sockaddr *, socklen_t, char *, DWORD, char *, DWORD,
|
||||
int);
|
||||
void
|
||||
freeaddrinfo(struct addrinfo *);
|
||||
char *
|
||||
gai_strerror(int);
|
||||
|
||||
/*
|
||||
* Tell Emacs to use C mode on this file.
|
||||
* Local variables:
|
||||
* mode: c
|
||||
* End:
|
||||
*/
|
||||
|
||||
#endif /* IRS_NETDB_H */
|
||||
|
|
@ -2,24 +2,6 @@ LIBRARY libirs
|
|||
|
||||
; Exported Functions
|
||||
EXPORTS
|
||||
irs_context_create
|
||||
irs_context_destroy
|
||||
irs_context_get
|
||||
irs_context_getappctx
|
||||
irs_context_getdnsclient
|
||||
irs_context_getdnsconf
|
||||
irs_context_getmctx
|
||||
irs_context_getresconf
|
||||
irs_context_gettask
|
||||
irs_context_gettaskmgr
|
||||
irs_context_gettimermgr
|
||||
irs_dnsconf_destroy
|
||||
irs_dnsconf_gettrustedkeys
|
||||
irs_dnsconf_load
|
||||
irs_freeaddrinfo
|
||||
irs_gai_strerror
|
||||
irs_getaddrinfo
|
||||
irs_getnameinfo
|
||||
irs_resconf_destroy
|
||||
irs_resconf_getnameservers
|
||||
irs_resconf_getndots
|
||||
|
|
|
|||
|
|
@ -21,40 +21,13 @@
|
|||
<ClCompile Include="DLLMain.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\context.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\dnsconf.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\gai_strerror.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\getaddrinfo.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\getnameinfo.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="resconf.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\irs\context.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\irs\dnsconf.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\irs\netdb.h.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\irs\resconf.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\irs\types.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -118,20 +118,10 @@
|
|||
<None Include="libirs.def" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\context.c" />
|
||||
<ClCompile Include="..\dnsconf.c" />
|
||||
<ClCompile Include="..\gai_strerror.c" />
|
||||
<ClCompile Include="..\getaddrinfo.c" />
|
||||
<ClCompile Include="..\getnameinfo.c" />
|
||||
<ClCompile Include="DLLMain.c" />
|
||||
<ClCompile Include="resconf.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\irs\context.h" />
|
||||
<ClInclude Include="..\include\irs\dnsconf.h" />
|
||||
<ClInclude Include="..\include\irs\netdb.h" />
|
||||
<ClInclude Include="..\include\irs\resconf.h" />
|
||||
<ClInclude Include="..\include\irs\types.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ AM_CPPFLAGS += \
|
|||
noinst_PROGRAMS = \
|
||||
resolve \
|
||||
sample-async \
|
||||
sample-gai \
|
||||
sample-update \
|
||||
sample-request \
|
||||
nsprobe
|
||||
|
|
@ -19,9 +18,6 @@ resolve_LDADD = $(LIBISC_LIBS) $(LIBIRS_LIBS) $(LIBDNS_LIBS)
|
|||
sample_async_SOURCES = sample-async.c
|
||||
sample_async_LDADD = $(LIBISC_LIBS) $(LIBDNS_LIBS)
|
||||
|
||||
sample_gai_SOURCES = sample-gai.c
|
||||
sample_gai_LDADD = $(LIBIRS_LIBS)
|
||||
|
||||
sample_update_SOURCES = sample-update.c
|
||||
sample_update_LDADD = $(LIBISC_LIBS) $(LIBDNS_LIBS)
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@
|
|||
|
||||
#include <dst/dst.h>
|
||||
|
||||
#include <irs/netdb.h>
|
||||
#include <irs/resconf.h>
|
||||
|
||||
static char *algname;
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/net.h>
|
||||
#include <isc/print.h>
|
||||
|
||||
#include <irs/netdb.h>
|
||||
|
||||
static void
|
||||
do_gai(int family, char *hostname) {
|
||||
struct addrinfo hints, *res, *res0;
|
||||
int error;
|
||||
char namebuf[1024], addrbuf[1024], servbuf[1024];
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = family;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
error = getaddrinfo(hostname, "http", &hints, &res0);
|
||||
if (error) {
|
||||
fprintf(stderr, "getaddrinfo failed for %s,family=%d: %s\n",
|
||||
hostname, family, gai_strerror(error));
|
||||
return;
|
||||
}
|
||||
|
||||
for (res = res0; res; res = res->ai_next) {
|
||||
error = getnameinfo(res->ai_addr, (socklen_t)res->ai_addrlen,
|
||||
addrbuf, sizeof(addrbuf), NULL, 0,
|
||||
NI_NUMERICHOST);
|
||||
if (error == 0) {
|
||||
error = getnameinfo(res->ai_addr,
|
||||
(socklen_t)res->ai_addrlen, namebuf,
|
||||
sizeof(namebuf), servbuf,
|
||||
sizeof(servbuf), 0);
|
||||
}
|
||||
if (error != 0) {
|
||||
fprintf(stderr, "getnameinfo failed: %s\n",
|
||||
gai_strerror(error));
|
||||
} else {
|
||||
printf("%s(%s/%s)=%s:%s\n", hostname, res->ai_canonname,
|
||||
addrbuf, namebuf, servbuf);
|
||||
}
|
||||
}
|
||||
|
||||
freeaddrinfo(res0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
do_gai(AF_INET, argv[1]);
|
||||
do_gai(AF_INET6, argv[1]);
|
||||
do_gai(AF_UNSPEC, argv[1]);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1853,16 +1853,7 @@
|
|||
./lib/dns/zoneverify.c C 2018,2019,2020
|
||||
./lib/dns/zt.c C 1999,2000,2001,2002,2004,2005,2006,2007,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020
|
||||
./lib/irs/api X 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020
|
||||
./lib/irs/context.c C 2009,2014,2016,2018,2019,2020
|
||||
./lib/irs/dnsconf.c C 2009,2012,2016,2018,2019,2020
|
||||
./lib/irs/gai_strerror.c C 2009,2014,2016,2018,2019,2020
|
||||
./lib/irs/getaddrinfo.c C 2009,2012,2013,2014,2015,2016,2017,2018,2019,2020
|
||||
./lib/irs/getnameinfo.c C 2009,2011,2012,2013,2014,2016,2017,2018,2019,2020
|
||||
./lib/irs/include/irs/context.h C 2009,2016,2018,2019,2020
|
||||
./lib/irs/include/irs/dnsconf.h C 2009,2016,2018,2019,2020
|
||||
./lib/irs/include/irs/netdb.h C 2009,2016,2017,2018,2019,2020
|
||||
./lib/irs/include/irs/resconf.h C 2009,2014,2016,2018,2019,2020
|
||||
./lib/irs/include/irs/types.h C 2009,2016,2018,2019,2020
|
||||
./lib/irs/resconf.c C 2009,2011,2012,2014,2015,2016,2017,2018,2019,2020
|
||||
./lib/irs/tests/resconf_test.c C 2016,2018,2019,2020
|
||||
./lib/irs/tests/testdata/domain.conf CONF-SH 2016,2018,2019
|
||||
|
|
@ -1883,7 +1874,6 @@
|
|||
./lib/irs/tests/testdata/timeout.conf CONF-SH 2016,2018,2019
|
||||
./lib/irs/tests/testdata/unknown.conf CONF-SH 2016,2018,2019
|
||||
./lib/irs/win32/DLLMain.c C 2014,2016,2018,2019,2020
|
||||
./lib/irs/win32/include/irs/netdb.h C 2014,2016,2017,2018,2019,2020
|
||||
./lib/irs/win32/libirs.def X 2014,2018,2019,2020
|
||||
./lib/irs/win32/libirs.vcxproj.filters.in X 2014,2015,2016,2018,2019,2020
|
||||
./lib/irs/win32/libirs.vcxproj.in X 2014,2015,2016,2017,2018,2019,2020
|
||||
|
|
@ -2271,7 +2261,6 @@
|
|||
./lib/samples/resolve.c C 2009,2012,2013,2014,2015,2016,2017,2018,2019,2020
|
||||
./lib/samples/rootkey.sh SH 2013,2016,2018,2019,2020
|
||||
./lib/samples/sample-async.c C 2009,2013,2014,2015,2016,2018,2019,2020
|
||||
./lib/samples/sample-gai.c C 2009,2012,2013,2014,2015,2016,2018,2019,2020
|
||||
./lib/samples/sample-request.c C 2009,2012,2013,2014,2015,2016,2018,2019,2020
|
||||
./lib/samples/sample-update.c C 2009,2010,2012,2013,2014,2015,2016,2017,2018,2019,2020
|
||||
./lib/samples/win32/async.vcxproj.filters.in X 2014,2015,2018,2019,2020
|
||||
|
|
|
|||
Loading…
Reference in a new issue