1999-09-24 01:43:02 +00:00
|
|
|
/*
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
* Copyright (C) 1999-2002 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-09-24 01:43:02 +00:00
|
|
|
* 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.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC 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.
|
1999-09-24 01:43:02 +00:00
|
|
|
*/
|
|
|
|
|
2004-03-05 05:14:21 +00:00
|
|
|
/* $Id: rootns.c,v 1.26 2004/03/05 05:09:24 marka Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-09-24 01:43:02 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/buffer.h>
|
2000-05-08 19:23:32 +00:00
|
|
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-09-24 01:43:02 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/callbacks.h>
|
1999-09-24 01:43:02 +00:00
|
|
|
#include <dns/db.h>
|
2001-08-27 03:36:00 +00:00
|
|
|
#include <dns/dbiterator.h>
|
|
|
|
#include <dns/log.h>
|
|
|
|
#include <dns/fixedname.h>
|
1999-09-24 01:43:02 +00:00
|
|
|
#include <dns/master.h>
|
2001-08-27 03:36:00 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatasetiter.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
2000-10-17 07:22:39 +00:00
|
|
|
#include <dns/result.h>
|
2000-01-22 01:59:02 +00:00
|
|
|
#include <dns/rootns.h>
|
1999-09-24 01:43:02 +00:00
|
|
|
|
1999-10-04 22:39:48 +00:00
|
|
|
static char root_ns[] =
|
1999-10-05 17:40:12 +00:00
|
|
|
";\n"
|
|
|
|
"; Internet Root Nameservers\n"
|
|
|
|
";\n"
|
|
|
|
"; Thu Sep 23 17:57:37 PDT 1999\n"
|
|
|
|
";\n"
|
|
|
|
"$TTL 518400\n"
|
2000-01-22 02:28:04 +00:00
|
|
|
". 518400 IN NS A.ROOT-SERVERS.NET.\n"
|
1999-10-05 17:40:12 +00:00
|
|
|
". 518400 IN NS B.ROOT-SERVERS.NET.\n"
|
2000-01-22 02:28:04 +00:00
|
|
|
". 518400 IN NS C.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS D.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS E.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS F.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS G.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS H.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS I.ROOT-SERVERS.NET.\n"
|
1999-10-05 17:40:12 +00:00
|
|
|
". 518400 IN NS J.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS K.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS L.ROOT-SERVERS.NET.\n"
|
|
|
|
". 518400 IN NS M.ROOT-SERVERS.NET.\n"
|
2000-01-22 02:28:04 +00:00
|
|
|
"A.ROOT-SERVERS.NET. 3600000 IN A 198.41.0.4\n"
|
2004-01-29 04:34:13 +00:00
|
|
|
"B.ROOT-SERVERS.NET. 3600000 IN A 192.228.79.201\n"
|
2000-01-22 02:28:04 +00:00
|
|
|
"C.ROOT-SERVERS.NET. 3600000 IN A 192.33.4.12\n"
|
|
|
|
"D.ROOT-SERVERS.NET. 3600000 IN A 128.8.10.90\n"
|
|
|
|
"E.ROOT-SERVERS.NET. 3600000 IN A 192.203.230.10\n"
|
|
|
|
"F.ROOT-SERVERS.NET. 3600000 IN A 192.5.5.241\n"
|
2000-01-22 02:35:10 +00:00
|
|
|
"G.ROOT-SERVERS.NET. 3600000 IN A 192.112.36.4\n"
|
2000-01-22 02:28:04 +00:00
|
|
|
"H.ROOT-SERVERS.NET. 3600000 IN A 128.63.2.53\n"
|
|
|
|
"I.ROOT-SERVERS.NET. 3600000 IN A 192.36.148.17\n"
|
2002-11-05 22:21:28 +00:00
|
|
|
"J.ROOT-SERVERS.NET. 3600000 IN A 192.58.128.30\n"
|
1999-10-05 17:40:12 +00:00
|
|
|
"K.ROOT-SERVERS.NET. 3600000 IN A 193.0.14.129\n"
|
|
|
|
"L.ROOT-SERVERS.NET. 3600000 IN A 198.32.64.12\n"
|
2000-01-22 02:35:10 +00:00
|
|
|
"M.ROOT-SERVERS.NET. 3600000 IN A 202.12.27.33\n";
|
1999-09-24 01:43:02 +00:00
|
|
|
|
2001-08-27 03:36:00 +00:00
|
|
|
static isc_result_t
|
|
|
|
in_rootns(dns_rdataset_t *rootns, dns_name_t *name) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
dns_rdata_ns_t ns;
|
|
|
|
|
2001-09-30 03:02:47 +00:00
|
|
|
if (!dns_rdataset_isassociated(rootns))
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
|
2001-08-27 03:36:00 +00:00
|
|
|
result = dns_rdataset_first(rootns);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
dns_rdataset_current(rootns, &rdata);
|
|
|
|
result = dns_rdata_tostruct(&rdata, &ns, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
if (dns_name_compare(name, &ns.name) == 0)
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
result = dns_rdataset_next(rootns);
|
|
|
|
}
|
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
check_node(dns_rdataset_t *rootns, dns_name_t *name,
|
|
|
|
dns_rdatasetiter_t *rdsiter) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
result = dns_rdatasetiter_first(rdsiter);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
dns_rdatasetiter_current(rdsiter, &rdataset);
|
|
|
|
switch (rdataset.type) {
|
|
|
|
case dns_rdatatype_a:
|
|
|
|
case dns_rdatatype_aaaa:
|
|
|
|
result = in_rootns(rootns, name);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
case dns_rdatatype_ns:
|
|
|
|
if (dns_name_compare(name, dns_rootname) == 0)
|
|
|
|
break;
|
|
|
|
/*FALLTHROUGH*/
|
|
|
|
default:
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
result = dns_rdatasetiter_next(rdsiter);
|
|
|
|
}
|
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
cleanup:
|
|
|
|
if (dns_rdataset_isassociated(&rdataset))
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
check_hints(dns_db_t *db) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataset_t rootns;
|
|
|
|
dns_dbiterator_t *dbiter = NULL;
|
|
|
|
dns_dbnode_t *node = NULL;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
dns_fixedname_t fixname;
|
|
|
|
dns_name_t *name;
|
|
|
|
dns_rdatasetiter_t *rdsiter = NULL;
|
|
|
|
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
|
|
|
dns_fixedname_init(&fixname);
|
|
|
|
name = dns_fixedname_name(&fixname);
|
|
|
|
|
|
|
|
dns_rdataset_init(&rootns);
|
2001-09-30 03:02:47 +00:00
|
|
|
(void)dns_db_find(db, dns_rootname, NULL, dns_rdatatype_ns, 0,
|
|
|
|
now, NULL, name, &rootns, NULL);
|
2001-08-27 03:36:00 +00:00
|
|
|
result = dns_db_createiterator(db, ISC_FALSE, &dbiter);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
result = dns_dbiterator_first(dbiter);
|
|
|
|
while (result == ISC_R_SUCCESS) {
|
|
|
|
result = dns_dbiterator_current(dbiter, &node, name);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
result = dns_db_allrdatasets(db, node, NULL, now, &rdsiter);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
result = check_node(&rootns, name, rdsiter);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
dns_rdatasetiter_destroy(&rdsiter);
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
result = dns_dbiterator_next(dbiter);
|
|
|
|
}
|
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (dns_rdataset_isassociated(&rootns))
|
|
|
|
dns_rdataset_disassociate(&rootns);
|
|
|
|
if (rdsiter != NULL)
|
|
|
|
dns_rdatasetiter_destroy(&rdsiter);
|
|
|
|
if (node != NULL)
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
if (dbiter != NULL)
|
|
|
|
dns_dbiterator_destroy(&dbiter);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-09-24 01:43:02 +00:00
|
|
|
isc_result_t
|
2000-01-27 01:55:46 +00:00
|
|
|
dns_rootns_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
|
|
|
|
const char *filename, dns_db_t **target)
|
|
|
|
{
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result, eresult;
|
1999-09-24 01:43:02 +00:00
|
|
|
isc_buffer_t source;
|
|
|
|
size_t len;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
2000-01-18 23:38:42 +00:00
|
|
|
dns_db_t *db = NULL;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-01-18 23:38:42 +00:00
|
|
|
REQUIRE(target != NULL && *target == NULL);
|
1999-09-24 01:43:02 +00:00
|
|
|
|
2000-06-07 02:38:41 +00:00
|
|
|
result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
|
2000-01-27 01:55:46 +00:00
|
|
|
rdclass, 0, NULL, &db);
|
1999-09-24 01:43:02 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
dns_rdatacallbacks_init(&callbacks);
|
|
|
|
|
|
|
|
len = strlen(root_ns);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&source, root_ns, len);
|
1999-09-24 01:43:02 +00:00
|
|
|
isc_buffer_add(&source, len);
|
|
|
|
|
2000-01-18 23:38:42 +00:00
|
|
|
result = dns_db_beginload(db, &callbacks.add,
|
1999-09-24 01:43:02 +00:00
|
|
|
&callbacks.add_private);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-01-27 01:55:46 +00:00
|
|
|
if (filename != NULL) {
|
|
|
|
/*
|
|
|
|
* Load the hints from the specified filename.
|
|
|
|
*/
|
|
|
|
result = dns_master_loadfile(filename, &db->origin,
|
2001-09-30 04:31:28 +00:00
|
|
|
&db->origin, db->rdclass,
|
|
|
|
DNS_MASTER_HINT,
|
2000-06-07 03:30:02 +00:00
|
|
|
&callbacks, db->mctx);
|
2000-01-27 01:55:46 +00:00
|
|
|
} else if (rdclass == dns_rdataclass_in) {
|
|
|
|
/*
|
|
|
|
* Default to using the Internet root servers.
|
|
|
|
*/
|
|
|
|
result = dns_master_loadbuffer(&source, &db->origin,
|
2001-09-30 04:31:28 +00:00
|
|
|
&db->origin, db->rdclass,
|
|
|
|
DNS_MASTER_HINT,
|
2000-06-07 03:30:02 +00:00
|
|
|
&callbacks, db->mctx);
|
2000-01-27 01:55:46 +00:00
|
|
|
} else
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
2000-01-18 23:38:42 +00:00
|
|
|
eresult = dns_db_endload(db, &callbacks.add_private);
|
2000-10-17 07:22:39 +00:00
|
|
|
if (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE)
|
1999-09-24 01:43:02 +00:00
|
|
|
result = eresult;
|
2000-10-17 07:22:39 +00:00
|
|
|
if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE)
|
1999-09-24 01:43:02 +00:00
|
|
|
goto db_detach;
|
2001-08-27 03:36:00 +00:00
|
|
|
if (check_hints(db) != ISC_R_SUCCESS)
|
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
|
|
|
|
DNS_LOGMODULE_HINTS, ISC_LOG_WARNING,
|
2001-08-27 17:21:56 +00:00
|
|
|
"extra data in root hints '%s'",
|
2001-08-27 03:36:00 +00:00
|
|
|
(filename != NULL) ? filename : "<BUILT-IN>");
|
2000-01-18 23:38:42 +00:00
|
|
|
*target = db;
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-24 01:43:02 +00:00
|
|
|
|
|
|
|
db_detach:
|
2000-01-18 23:38:42 +00:00
|
|
|
dns_db_detach(&db);
|
1999-09-24 01:43:02 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|