/* * seek_emty: walk database starting at an empty nonterminal node * (should fail) */ static void test_seek_nx(const atf_tc_t *tc) { isc_result_t result; dns_db_t *db = NULL; dns_dbiterator_t *iter = NULL; dns_name_t *seekname; dns_fixedname_t f1; UNUSED(tc); dns_fixedname_init(&f1); seekname = dns_fixedname_name(&f1); result = dns_test_begin(NULL, ISC_FALSE); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, atf_tc_get_md_var(tc, "X-filename")); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_db_createiterator(db, 0, &iter); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = make_name("nonexistent." TEST_ORIGIN, seekname); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_dbiterator_seek(iter, seekname); ATF_CHECK_EQ(result, ISC_R_NOTFOUND); dns_dbiterator_destroy(&iter); dns_db_detach(&db); dns_test_end(); }
static void db_rr_iterator_destroy(db_rr_iterator_t *it) { if (dns_rdataset_isassociated(&it->rdataset)) dns_rdataset_disassociate(&it->rdataset); if (it->rdatasetit != NULL) dns_rdatasetiter_destroy(&it->rdatasetit); if (it->node != NULL) dns_db_detachnode(it->db, &it->node); dns_dbiterator_destroy(&it->dbit); }
void dns_rriterator_destroy(dns_rriterator_t *it) { REQUIRE(VALID_RRITERATOR(it)); if (dns_rdataset_isassociated(&it->rdataset)) dns_rdataset_disassociate(&it->rdataset); if (it->rdatasetit != NULL) dns_rdatasetiter_destroy(&it->rdatasetit); if (it->node != NULL) dns_db_detachnode(it->db, &it->node); dns_dbiterator_destroy(&it->dbit); }
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); (void)dns_db_find(db, dns_rootname, NULL, dns_rdatatype_ns, 0, now, NULL, name, &rootns, NULL); result = dns_db_createiterator(db, 0, &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); }
/* seek: walk database starting at a particular node */ static void test_seek(const atf_tc_t *tc) { isc_result_t result; dns_db_t *db = NULL; dns_dbiterator_t *iter = NULL; dns_dbnode_t *node = NULL; dns_name_t *name, *seekname; dns_fixedname_t f1, f2; int i = 0; UNUSED(tc); dns_fixedname_init(&f1); name = dns_fixedname_name(&f1); dns_fixedname_init(&f2); seekname = dns_fixedname_name(&f2); result = dns_test_begin(NULL, ISC_FALSE); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, atf_tc_get_md_var(tc, "X-filename")); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_db_createiterator(db, 0, &iter); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = make_name("c." TEST_ORIGIN, seekname); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_dbiterator_seek(iter, seekname); ATF_CHECK_EQ(result, ISC_R_SUCCESS); while (result == ISC_R_SUCCESS) { result = dns_dbiterator_current(iter, &node, name); if (result == DNS_R_NEWORIGIN) result = ISC_R_SUCCESS; ATF_CHECK_EQ(result, ISC_R_SUCCESS); dns_db_detachnode(db, &node); result = dns_dbiterator_next(iter); i++; } ATF_CHECK_EQ(i, atoi(atf_tc_get_md_var(tc, "X-nodes"))); dns_dbiterator_destroy(&iter); dns_db_detach(&db); dns_test_end(); }
/* create: make sure we can create a dbiterator */ static void test_create(const atf_tc_t *tc) { isc_result_t result; dns_db_t *db = NULL; dns_dbiterator_t *iter = NULL; result = dns_test_begin(NULL, ISC_FALSE); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, atf_tc_get_md_var(tc, "X-filename")); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_db_createiterator(db, 0, &iter); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); dns_dbiterator_destroy(&iter); dns_db_detach(&db); dns_test_end(); }
/* reverse: walk database backwards */ static void test_reverse(const atf_tc_t *tc) { isc_result_t result; dns_db_t *db = NULL; dns_dbiterator_t *iter = NULL; dns_dbnode_t *node = NULL; dns_name_t *name; dns_fixedname_t f; int i = 0; UNUSED(tc); dns_fixedname_init(&f); name = dns_fixedname_name(&f); result = dns_test_begin(NULL, ISC_FALSE); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN, atf_tc_get_md_var(tc, "X-filename")); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); result = dns_db_createiterator(db, 0, &iter); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); for (result = dns_dbiterator_last(iter); result == ISC_R_SUCCESS; result = dns_dbiterator_prev(iter)) { result = dns_dbiterator_current(iter, &node, name); if (result == DNS_R_NEWORIGIN) result = ISC_R_SUCCESS; ATF_CHECK_EQ(result, ISC_R_SUCCESS); dns_db_detachnode(db, &node); i++; } ATF_CHECK_EQ(i, 12); dns_dbiterator_destroy(&iter); dns_db_detach(&db); dns_test_end(); }
static void list(dbinfo *dbi, char *seektext) { dns_fixedname_t fname; dns_name_t *name; dns_dbnode_t *node; dns_rdatasetiter_t *rdsiter; isc_result_t result; int i; size_t len; dns_fixedname_t fseekname; dns_name_t *seekname; isc_buffer_t source; dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); if (dbi->dbiterator == NULL) { INSIST(dbi->iversion == NULL); if (dns_db_iszone(dbi->db)) { if (dbi->version != NULL) dns_db_attachversion(dbi->db, dbi->version, &dbi->iversion); else dns_db_currentversion(dbi->db, &dbi->iversion); } result = dns_db_createiterator(dbi->db, 0, &dbi->dbiterator); if (result == ISC_R_SUCCESS) { if (seektext != NULL) { len = strlen(seektext); isc_buffer_init(&source, seektext, len); isc_buffer_add(&source, len); dns_fixedname_init(&fseekname); seekname = dns_fixedname_name(&fseekname); result = dns_name_fromtext(seekname, &source, dns_db_origin( dbi->db), 0, NULL); if (result == ISC_R_SUCCESS) result = dns_dbiterator_seek( dbi->dbiterator, seekname); } else if (dbi->ascending) result = dns_dbiterator_first(dbi->dbiterator); else result = dns_dbiterator_last(dbi->dbiterator); } } else result = ISC_R_SUCCESS; node = NULL; rdsiter = NULL; i = 0; while (result == ISC_R_SUCCESS) { result = dns_dbiterator_current(dbi->dbiterator, &node, name); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) break; result = dns_db_allrdatasets(dbi->db, node, dbi->iversion, 0, &rdsiter); if (result != ISC_R_SUCCESS) { dns_db_detachnode(dbi->db, &node); break; } print_rdatasets(name, rdsiter); dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(dbi->db, &node); if (dbi->ascending) result = dns_dbiterator_next(dbi->dbiterator); else result = dns_dbiterator_prev(dbi->dbiterator); i++; if (result == ISC_R_SUCCESS && i == dbi->pause_every) { printf("[more...]\n"); result = dns_dbiterator_pause(dbi->dbiterator); if (result == ISC_R_SUCCESS) return; } } if (result != ISC_R_NOMORE) print_result("", result); dns_dbiterator_destroy(&dbi->dbiterator); if (dbi->iversion != NULL) dns_db_closeversion(dbi->db, &dbi->iversion, ISC_FALSE); }
static void nsecify (char *filename) { isc_result_t result; dns_db_t *db; dns_dbversion_t *wversion; dns_dbnode_t *node, *nextnode; char *origintext; dns_fixedname_t fname, fnextname; dns_name_t *name, *nextname, *target; isc_buffer_t b; size_t len; dns_dbiterator_t *dbiter; char newfilename[1024]; dns_fixedname_init (&fname); name = dns_fixedname_name (&fname); dns_fixedname_init (&fnextname); nextname = dns_fixedname_name (&fnextname); origintext = strrchr (filename, '/'); if (origintext == NULL) origintext = filename; else origintext++; /* Skip '/'. */ len = strlen (origintext); isc_buffer_init (&b, origintext, len); isc_buffer_add (&b, len); result = dns_name_fromtext (name, &b, dns_rootname, 0, NULL); check_result (result, "dns_name_fromtext()"); db = NULL; result = dns_db_create (mctx, "rbt", name, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); check_result (result, "dns_db_create()"); result = dns_db_load (db, filename); if (result == DNS_R_SEENINCLUDE) result = ISC_R_SUCCESS; check_result (result, "dns_db_load()"); wversion = NULL; result = dns_db_newversion (db, &wversion); check_result (result, "dns_db_newversion()"); dbiter = NULL; result = dns_db_createiterator (db, 0, &dbiter); check_result (result, "dns_db_createiterator()"); result = dns_dbiterator_first (dbiter); check_result (result, "dns_dbiterator_first()"); node = NULL; result = next_active (db, wversion, dbiter, name, &node); while (result == ISC_R_SUCCESS) { nextnode = NULL; result = dns_dbiterator_next (dbiter); if (result == ISC_R_SUCCESS) result = next_active (db, wversion, dbiter, nextname, &nextnode); if (result == ISC_R_SUCCESS) target = nextname; else if (result == ISC_R_NOMORE) target = dns_db_origin (db); else { target = NULL; /* Make compiler happy. */ fatal ("db iteration failed"); } dns_nsec_build (db, wversion, node, target, 3600); /* XXX BEW */ dns_db_detachnode (db, &node); node = nextnode; } if (result != ISC_R_NOMORE) fatal ("db iteration failed"); dns_dbiterator_destroy (&dbiter); /* * XXXRTH For now, we don't increment the SOA serial. */ dns_db_closeversion (db, &wversion, ISC_TRUE); len = strlen (filename); if (len + 4 + 1 > sizeof (newfilename)) fatal ("filename too long"); sprintf (newfilename, "%s.new", filename); result = dns_db_dump (db, NULL, newfilename); check_result (result, "dns_db_dump"); dns_db_detach (&db); }
int main(int argc, char **argv) { char *porigin, *zonefile; dns_fixedname_t forigin, fname; dns_name_t *origin, *name; dns_db_t *db = NULL; dns_dbiterator_t *dbiter; dns_dbnode_t *node; dns_rdatasetiter_t *rdsiter; dns_rdataset_t rdataset; dns_rdata_t rdata = DNS_RDATA_INIT; isc_mem_t *mctx = NULL; isc_entropy_t *ectx = NULL; isc_buffer_t b; isc_result_t result; PGresult *res; if (argc != 5) { printf("usage: %s origin file dbname dbtable\n", argv[0]); printf("Note that dbname must be an existing database.\n"); exit(1); } porigin = argv[1]; zonefile = argv[2]; dbname = argv[3]; dbtable = argv[4]; dns_result_register(); mctx = NULL; result = isc_mem_create(0, 0, &mctx); check_result(result, "isc_mem_create"); result = isc_entropy_create(mctx, &ectx); result_check (result, "isc_entropy_create"); result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE); check_result (result, "isc_hash_create"); isc_buffer_init(&b, porigin, strlen(porigin)); isc_buffer_add(&b, strlen(porigin)); dns_fixedname_init(&forigin); origin = dns_fixedname_name(&forigin); result = dns_name_fromtext(origin, &b, dns_rootname, ISC_FALSE, NULL); check_result(result, "dns_name_fromtext"); db = NULL; result = dns_db_create(mctx, "rbt", origin, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); check_result(result, "dns_db_create"); result = dns_db_load(db, zonefile); if (result == DNS_R_SEENINCLUDE) result = ISC_R_SUCCESS; check_result(result, "dns_db_load"); printf("Connecting to '%s'\n", dbname); conn = PQsetdb(NULL, NULL, NULL, NULL, dbname); if (PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr, "Connection to database '%s' failed: %s\n", dbname, PQerrorMessage(conn)); closeandexit(1); } snprintf(str, sizeof(str), "DROP TABLE %s", dbtable); printf("%s\n", str); res = PQexec(conn, str); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) fprintf(stderr, "DROP TABLE command failed: %s\n", PQresultErrorMessage(res)); PQclear(res); snprintf(str, sizeof(str), "BEGIN"); printf("%s\n", str); res = PQexec(conn, str); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "BEGIN command failed: %s\n", PQresultErrorMessage(res)); PQclear(res); closeandexit(1); } PQclear(res); snprintf(str, sizeof(str), "CREATE TABLE %s " "(NAME TEXT, TTL INTEGER, RDTYPE TEXT, RDATA TEXT)", dbtable); printf("%s\n", str); res = PQexec(conn, str); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "CREATE TABLE command failed: %s\n", PQresultErrorMessage(res)); PQclear(res); closeandexit(1); } PQclear(res); dbiter = NULL; result = dns_db_createiterator(db, ISC_FALSE, &dbiter); check_result(result, "dns_db_createiterator()"); result = dns_dbiterator_first(dbiter); check_result(result, "dns_dbiterator_first"); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); dns_rdataset_init(&rdataset); dns_rdata_init(&rdata); while (result == ISC_R_SUCCESS) { node = NULL; result = dns_dbiterator_current(dbiter, &node, name); if (result == ISC_R_NOMORE) break; check_result(result, "dns_dbiterator_current"); rdsiter = NULL; result = dns_db_allrdatasets(db, node, NULL, 0, &rdsiter); check_result(result, "dns_db_allrdatasets"); result = dns_rdatasetiter_first(rdsiter); while (result == ISC_R_SUCCESS) { dns_rdatasetiter_current(rdsiter, &rdataset); result = dns_rdataset_first(&rdataset); check_result(result, "dns_rdataset_first"); while (result == ISC_R_SUCCESS) { dns_rdataset_current(&rdataset, &rdata); addrdata(name, rdataset.ttl, &rdata); dns_rdata_reset(&rdata); result = dns_rdataset_next(&rdataset); } dns_rdataset_disassociate(&rdataset); result = dns_rdatasetiter_next(rdsiter); } dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(db, &node); result = dns_dbiterator_next(dbiter); } snprintf(str, sizeof(str), "COMMIT TRANSACTION"); printf("%s\n", str); res = PQexec(conn, str); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "COMMIT command failed: %s\n", PQresultErrorMessage(res)); PQclear(res); closeandexit(1); } PQclear(res); dns_dbiterator_destroy(&dbiter); dns_db_detach(&db); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mem_destroy(&mctx); closeandexit(0); exit(0); }
int main(int argc, char *argv[]) { char *sql; int res; char *errmsg = NULL; char *porigin, *zonefile; dns_fixedname_t forigin, fname; dns_name_t *origin, *name; dns_db_t *db = NULL; dns_dbiterator_t *dbiter; dns_dbnode_t *node; dns_rdatasetiter_t *rdsiter; dns_rdataset_t rdataset; dns_rdata_t rdata = DNS_RDATA_INIT; isc_mem_t *mctx = NULL; isc_entropy_t *ectx = NULL; isc_buffer_t b; isc_result_t result; if (argc != 5) { printf("usage: %s <zone> <zonefile> <dbfile> <dbtable>\n", argv[0]); exit(1); } porigin = argv[1]; zonefile = argv[2]; dbi.filename = argv[3]; dbi.table = argv[4]; dns_result_register(); result = isc_mem_create(0, 0, &mctx); check_result(result, "isc_mem_create"); result = isc_entropy_create(mctx, &ectx); check_result(result, "isc_entropy_create"); result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE); check_result(result, "isc_hash_create"); isc_buffer_init(&b, porigin, strlen(porigin)); isc_buffer_add(&b, strlen(porigin)); dns_fixedname_init(&forigin); origin = dns_fixedname_name(&forigin); result = dns_name_fromtext(origin, &b, dns_rootname, 0, NULL); check_result(result, "dns_name_fromtext"); db = NULL; result = dns_db_create(mctx, "rbt", origin, dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db); check_result(result, "dns_db_create"); result = dns_db_load(db, zonefile); if (result == DNS_R_SEENINCLUDE) result = ISC_R_SUCCESS; check_result(result, "dns_db_load"); printf("Connecting to '%s'\n", dbi.filename); if ((result = db_connect(&dbi)) != ISC_R_SUCCESS) { fprintf(stderr, "Connection to database '%s' failed\n", dbi.filename); closeandexit(1); } sql = sqlite3_mprintf("DROP TABLE %q ", dbi.table); printf("%s\n", sql); res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg); sqlite3_free(sql); #if 0 if (res != SQLITE_OK) { fprintf(stderr, "DROP TABLE %s failed: %s\n", dbi.table, errmsg); } #endif #if 0 sql = sqlite3_mprintf(sql, "BEGIN TRANSACTION"); printf("%s\n", sql); res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg); sqlite3_free(sql); if (res != SQLITE_OK) { fprintf(stderr, "BEGIN TRANSACTION failed: %s\n", errmsg); closeandexit(1); } #endif sql = sqlite3_mprintf( "CREATE TABLE %q " "(NAME TEXT, TTL INTEGER, RDTYPE TEXT, RDATA TEXT) ", dbi.table); printf("%s\n", sql); res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg); sqlite3_free(sql); if (res != SQLITE_OK) { fprintf(stderr, "CREATE TABLE %s failed: %s\n", dbi.table, errmsg); closeandexit(1); } dbiter = NULL; result = dns_db_createiterator(db, 0, &dbiter); check_result(result, "dns_db_createiterator()"); result = dns_dbiterator_first(dbiter); check_result(result, "dns_dbiterator_first"); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); dns_rdataset_init(&rdataset); dns_rdata_init(&rdata); while (result == ISC_R_SUCCESS) { node = NULL; result = dns_dbiterator_current(dbiter, &node, name); if (result == ISC_R_NOMORE) break; check_result(result, "dns_dbiterator_current"); rdsiter = NULL; result = dns_db_allrdatasets(db, node, NULL, 0, &rdsiter); check_result(result, "dns_db_allrdatasets"); result = dns_rdatasetiter_first(rdsiter); while (result == ISC_R_SUCCESS) { dns_rdatasetiter_current(rdsiter, &rdataset); result = dns_rdataset_first(&rdataset); check_result(result, "dns_rdataset_first"); while (result == ISC_R_SUCCESS) { dns_rdataset_current(&rdataset, &rdata); addrdata(name, rdataset.ttl, &rdata); dns_rdata_reset(&rdata); result = dns_rdataset_next(&rdataset); } dns_rdataset_disassociate(&rdataset); result = dns_rdatasetiter_next(rdsiter); } dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(db, &node); result = dns_dbiterator_next(dbiter); } #if 0 sql = sqlite3_mprintf(sql, "COMMIT TRANSACTION "); printf("%s\n", sql); res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg); sqlite3_free(sql); if (res != SQLITE_OK) { fprintf(stderr, "COMMIT TRANSACTION failed: %s\n", errmsg); closeandexit(1); } #endif dns_dbiterator_destroy(&dbiter); dns_db_detach(&db); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mem_destroy(&mctx); closeandexit(0); exit(0); }
int main(int argc, char *argv[]) { isc_mem_t *mctx = NULL; isc_buffer_t b; int n; dns_fixedname_t origin, name; dns_db_t *db = NULL; dns_dbiterator_t *dbiter = NULL; isc_result_t res; dns_dbnode_t *node = NULL; dns_rdataset_t rdataset; dns_rdatasetiter_t *rdatasetiter = NULL; dns_rdata_t rdata; DB *bdb; if (argc != 4) usage(*argv); REQUIRE(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); n = strlen(argv[1]); isc_buffer_init(&b, argv[1], n); isc_buffer_add(&b, n); dns_fixedname_init(&origin); REQUIRE(dns_name_fromtext(dns_fixedname_name(&origin), &b, dns_rootname, 0, NULL) == ISC_R_SUCCESS); REQUIRE(dns_db_create(mctx, "rbt", dns_fixedname_name(&origin), dns_dbtype_zone, dns_rdataclass_in, 0, NULL, &db) == ISC_R_SUCCESS); REQUIRE(dns_db_load(db, argv[2]) == ISC_R_SUCCESS); REQUIRE(dns_db_createiterator(db, 0, &dbiter) == ISC_R_SUCCESS); dns_rdataset_init(&rdataset); dns_rdata_init(&rdata); dns_fixedname_init(&name); bdb = bdb_init(argv[3]); for (res = dns_dbiterator_first(dbiter); res == ISC_R_SUCCESS; res = dns_dbiterator_next(dbiter)) { dns_dbiterator_current(dbiter, &node, dns_fixedname_name(&name)); REQUIRE(dns_db_allrdatasets(db, node, NULL, 0, &rdatasetiter) == ISC_R_SUCCESS); for (res = dns_rdatasetiter_first(rdatasetiter); res == ISC_R_SUCCESS; res = dns_rdatasetiter_next(rdatasetiter)) { dns_rdatasetiter_current(rdatasetiter, &rdataset); res = dns_rdataset_first(&rdataset); while (res == ISC_R_SUCCESS) { dns_rdataset_current(&rdataset, &rdata); REQUIRE(bdb_putrdata(bdb, dns_fixedname_name(&name), rdataset.ttl, &rdata) == ISC_R_SUCCESS); dns_rdata_reset(&rdata); res = dns_rdataset_next(&rdataset); } dns_rdataset_disassociate(&rdataset); } dns_rdatasetiter_destroy(&rdatasetiter); dns_db_detachnode(db, &node); } dns_dbiterator_destroy(&dbiter); REQUIRE(bdb_destroy(bdb) == ISC_R_SUCCESS); return 0; }
/*% scan the zone for oversize TTLs */ static isc_result_t check_ttls(dns_zone_t *zone, dns_ttl_t maxttl) { isc_result_t result; dns_db_t *db = NULL; dns_dbversion_t *version = NULL; dns_dbnode_t *node = NULL; dns_dbiterator_t *dbiter = NULL; dns_rdatasetiter_t *rdsiter = NULL; dns_rdataset_t rdataset; dns_fixedname_t fname; dns_name_t *name; dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); dns_rdataset_init(&rdataset); CHECK(dns_zone_getdb(zone, &db)); INSIST(db != NULL); CHECK(dns_db_newversion(db, &version)); CHECK(dns_db_createiterator(db, 0, &dbiter)); for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS; result = dns_dbiterator_next(dbiter)) { result = dns_dbiterator_current(dbiter, &node, name); if (result == DNS_R_NEWORIGIN) result = ISC_R_SUCCESS; CHECK(result); CHECK(dns_db_allrdatasets(db, node, version, 0, &rdsiter)); for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(rdsiter)) { dns_rdatasetiter_current(rdsiter, &rdataset); if (rdataset.ttl > maxttl) { char nbuf[DNS_NAME_FORMATSIZE]; char tbuf[255]; isc_buffer_t b; isc_region_t r; dns_name_format(name, nbuf, sizeof(nbuf)); isc_buffer_init(&b, tbuf, sizeof(tbuf) - 1); CHECK(dns_rdatatype_totext(rdataset.type, &b)); isc_buffer_usedregion(&b, &r); r.base[r.length] = 0; dns_zone_log(zone, ISC_LOG_ERROR, "%s/%s TTL %d exceeds " "maximum TTL %d", nbuf, tbuf, rdataset.ttl, maxttl); dns_rdataset_disassociate(&rdataset); CHECK(ISC_R_RANGE); } dns_rdataset_disassociate(&rdataset); } if (result == ISC_R_NOMORE) result = ISC_R_SUCCESS; CHECK(result); dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(db, &node); } if (result == ISC_R_NOMORE) result = ISC_R_SUCCESS; cleanup: if (node != NULL) dns_db_detachnode(db, &node); if (rdsiter != NULL) dns_rdatasetiter_destroy(&rdsiter); if (dbiter != NULL) dns_dbiterator_destroy(&dbiter); if (version != NULL) dns_db_closeversion(db, &version, ISC_FALSE); if (db != NULL) dns_db_detach(&db); return (result); }