1 /* $NetBSD: db_test.c,v 1.7 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007-2009, 2011-2013 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: db_test.c,v 1.70 2011/08/29 23:46:44 tbox Exp */
24 * Principal Author: Bob Halley
31 #include <isc/commandline.h>
35 #include <isc/string.h>
39 #include <dns/dbiterator.h>
40 #include <dns/dbtable.h>
41 #include <dns/fixedname.h>
43 #include <dns/rdataset.h>
44 #include <dns/rdatasetiter.h>
45 #include <dns/result.h>
48 #define MAXVERSIONS 100
50 typedef struct dbinfo
{
52 dns_dbversion_t
* version
;
53 dns_dbversion_t
* wversion
;
54 dns_dbversion_t
* rversions
[MAXVERSIONS
];
56 dns_dbnode_t
* hold_nodes
[MAXHOLD
];
58 dns_dbiterator_t
* dbiterator
;
59 dns_dbversion_t
* iversion
;
61 isc_boolean_t ascending
;
62 ISC_LINK(struct dbinfo
) link
;
65 static isc_mem_t
* mctx
= NULL
;
66 static char dbtype
[128];
67 static dns_dbtable_t
* dbtable
;
68 static ISC_LIST(dbinfo
) dbs
;
69 static dbinfo
* cache_dbi
= NULL
;
70 static int pause_every
= 0;
71 static isc_boolean_t ascending
= ISC_TRUE
;
74 print_result(const char *message
, isc_result_t result
) {
78 printf("%s%sresult %08x: %s\n", message
, (*message
== '\0') ? "" : " ",
79 result
, isc_result_totext(result
));
83 print_rdataset(dns_name_t
*name
, dns_rdataset_t
*rdataset
) {
89 isc_buffer_init(&text
, t
, sizeof(t
));
90 result
= dns_rdataset_totext(rdataset
, name
, ISC_FALSE
, ISC_FALSE
,
92 isc_buffer_usedregion(&text
, &r
);
93 if (result
== ISC_R_SUCCESS
)
94 printf("%.*s", (int)r
.length
, (char *)r
.base
);
96 print_result("", result
);
100 print_rdatasets(dns_name_t
*name
, dns_rdatasetiter_t
*rdsiter
) {
102 dns_rdataset_t rdataset
;
104 dns_rdataset_init(&rdataset
);
105 result
= dns_rdatasetiter_first(rdsiter
);
106 while (result
== ISC_R_SUCCESS
) {
107 dns_rdatasetiter_current(rdsiter
, &rdataset
);
108 print_rdataset(name
, &rdataset
);
109 dns_rdataset_disassociate(&rdataset
);
110 result
= dns_rdatasetiter_next(rdsiter
);
112 if (result
!= ISC_R_NOMORE
)
113 print_result("", result
);
117 select_db(char *origintext
) {
118 dns_fixedname_t forigin
;
125 if (strcasecmp(origintext
, "cache") == 0) {
126 if (cache_dbi
== NULL
)
127 printf("the cache does not exist\n");
130 len
= strlen(origintext
);
131 isc_buffer_init(&source
, origintext
, len
);
132 isc_buffer_add(&source
, len
);
133 dns_fixedname_init(&forigin
);
134 origin
= dns_fixedname_name(&forigin
);
135 result
= dns_name_fromtext(origin
, &source
, dns_rootname
, 0, NULL
);
136 if (result
!= ISC_R_SUCCESS
) {
137 print_result("bad name", result
);
141 for (dbi
= ISC_LIST_HEAD(dbs
);
143 dbi
= ISC_LIST_NEXT(dbi
, link
)) {
144 if (dns_name_compare(dns_db_origin(dbi
->db
), origin
) == 0)
152 list(dbinfo
*dbi
, char *seektext
) {
153 dns_fixedname_t fname
;
156 dns_rdatasetiter_t
*rdsiter
;
160 dns_fixedname_t fseekname
;
161 dns_name_t
*seekname
;
164 dns_fixedname_init(&fname
);
165 name
= dns_fixedname_name(&fname
);
167 if (dbi
->dbiterator
== NULL
) {
168 INSIST(dbi
->iversion
== NULL
);
169 if (dns_db_iszone(dbi
->db
)) {
170 if (dbi
->version
!= NULL
)
171 dns_db_attachversion(dbi
->db
, dbi
->version
,
174 dns_db_currentversion(dbi
->db
, &dbi
->iversion
);
177 result
= dns_db_createiterator(dbi
->db
, 0, &dbi
->dbiterator
);
178 if (result
== ISC_R_SUCCESS
) {
179 if (seektext
!= NULL
) {
180 len
= strlen(seektext
);
181 isc_buffer_init(&source
, seektext
, len
);
182 isc_buffer_add(&source
, len
);
183 dns_fixedname_init(&fseekname
);
184 seekname
= dns_fixedname_name(&fseekname
);
185 result
= dns_name_fromtext(seekname
, &source
,
189 if (result
== ISC_R_SUCCESS
)
190 result
= dns_dbiterator_seek(
193 } else if (dbi
->ascending
)
194 result
= dns_dbiterator_first(dbi
->dbiterator
);
196 result
= dns_dbiterator_last(dbi
->dbiterator
);
199 result
= ISC_R_SUCCESS
;
204 while (result
== ISC_R_SUCCESS
) {
205 result
= dns_dbiterator_current(dbi
->dbiterator
, &node
, name
);
206 if (result
!= ISC_R_SUCCESS
&& result
!= DNS_R_NEWORIGIN
)
208 result
= dns_db_allrdatasets(dbi
->db
, node
, dbi
->iversion
, 0,
210 if (result
!= ISC_R_SUCCESS
) {
211 dns_db_detachnode(dbi
->db
, &node
);
214 print_rdatasets(name
, rdsiter
);
215 dns_rdatasetiter_destroy(&rdsiter
);
216 dns_db_detachnode(dbi
->db
, &node
);
218 result
= dns_dbiterator_next(dbi
->dbiterator
);
220 result
= dns_dbiterator_prev(dbi
->dbiterator
);
222 if (result
== ISC_R_SUCCESS
&& i
== dbi
->pause_every
) {
223 printf("[more...]\n");
224 result
= dns_dbiterator_pause(dbi
->dbiterator
);
225 if (result
== ISC_R_SUCCESS
)
229 if (result
!= ISC_R_NOMORE
)
230 print_result("", result
);
232 dns_dbiterator_destroy(&dbi
->dbiterator
);
233 if (dbi
->iversion
!= NULL
)
234 dns_db_closeversion(dbi
->db
, &dbi
->iversion
, ISC_FALSE
);
238 load(const char *filename
, const char *origintext
, isc_boolean_t cache
) {
239 dns_fixedname_t forigin
;
247 dbi
= isc_mem_get(mctx
, sizeof(*dbi
));
249 return (ISC_R_NOMEMORY
);
253 dbi
->wversion
= NULL
;
254 for (i
= 0; i
< MAXVERSIONS
; i
++)
255 dbi
->rversions
[i
] = NULL
;
257 for (i
= 0; i
< MAXHOLD
; i
++)
258 dbi
->hold_nodes
[i
] = NULL
;
259 dbi
->dbiterator
= NULL
;
260 dbi
->iversion
= NULL
;
261 dbi
->pause_every
= pause_every
;
262 dbi
->ascending
= ascending
;
263 ISC_LINK_INIT(dbi
, link
);
265 len
= strlen(origintext
);
266 isc_buffer_constinit(&source
, origintext
, len
);
267 isc_buffer_add(&source
, len
);
268 dns_fixedname_init(&forigin
);
269 origin
= dns_fixedname_name(&forigin
);
270 result
= dns_name_fromtext(origin
, &source
, dns_rootname
, 0, NULL
);
271 if (result
!= ISC_R_SUCCESS
)
274 result
= dns_db_create(mctx
, dbtype
, origin
,
275 cache
? dns_dbtype_cache
: dns_dbtype_zone
,
278 if (result
!= ISC_R_SUCCESS
) {
279 isc_mem_put(mctx
, dbi
, sizeof(*dbi
));
283 printf("loading %s (%s)\n", filename
, origintext
);
284 result
= dns_db_load(dbi
->db
, filename
);
285 if (result
!= ISC_R_SUCCESS
&& result
!= DNS_R_SEENINCLUDE
) {
286 dns_db_detach(&dbi
->db
);
287 isc_mem_put(mctx
, dbi
, sizeof(*dbi
));
293 INSIST(cache_dbi
== NULL
);
294 dns_dbtable_adddefault(dbtable
, dbi
->db
);
297 if (dns_dbtable_add(dbtable
, dbi
->db
) != ISC_R_SUCCESS
) {
298 dns_db_detach(&dbi
->db
);
299 isc_mem_put(mctx
, dbi
, sizeof(*dbi
));
303 ISC_LIST_APPEND(dbs
, dbi
, link
);
305 return (ISC_R_SUCCESS
);
310 dbinfo
*dbi
, *dbi_next
;
312 for (dbi
= ISC_LIST_HEAD(dbs
); dbi
!= NULL
; dbi
= dbi_next
) {
313 dbi_next
= ISC_LIST_NEXT(dbi
, link
);
314 if (dns_db_iszone(dbi
->db
))
315 dns_dbtable_remove(dbtable
, dbi
->db
);
317 INSIST(dbi
== cache_dbi
);
318 dns_dbtable_removedefault(dbtable
);
321 dns_db_detach(&dbi
->db
);
322 ISC_LIST_UNLINK(dbs
, dbi
, link
);
323 isc_mem_put(mctx
, dbi
, sizeof(*dbi
));
327 #define DBI_CHECK(dbi) \
328 if ((dbi) == NULL) { \
329 printf("You must first select a database with !DB\n"); \
334 main(int argc
, char *argv
[]) {
339 dns_offsets_t offsets
;
341 isc_buffer_t source
, target
;
344 dns_rdataset_t rdataset
, sigrdataset
;
346 dns_rdatatype_t type
= 1;
347 isc_boolean_t printnode
= ISC_FALSE
;
348 isc_boolean_t addmode
= ISC_FALSE
;
349 isc_boolean_t delmode
= ISC_FALSE
;
350 isc_boolean_t holdmode
= ISC_FALSE
;
351 isc_boolean_t verbose
= ISC_FALSE
;
352 isc_boolean_t done
= ISC_FALSE
;
353 isc_boolean_t quiet
= ISC_FALSE
;
354 isc_boolean_t time_lookups
= ISC_FALSE
;
355 isc_boolean_t found_as
;
356 isc_boolean_t find_zonecut
= ISC_FALSE
;
357 isc_boolean_t noexact_zonecut
= ISC_FALSE
;
359 dns_rdatasetiter_t
*rdsiter
;
362 isc_buffer_t tb1
, tb2
;
364 dns_fixedname_t foundname
;
366 unsigned int options
= 0, zcoptions
;
367 isc_time_t start
, finish
;
370 dns_dbversion_t
*version
;
372 size_t memory_quota
= 0;
373 dns_trust_t trust
= 0;
374 unsigned int addopts
;
375 isc_log_t
*lctx
= NULL
;
378 dns_result_register();
380 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx
) == ISC_R_SUCCESS
);
381 RUNTIME_CHECK(dns_dbtable_create(mctx
, dns_rdataclass_in
, &dbtable
) ==
386 strcpy(dbtype
, "rbt");
387 while ((ch
= isc_commandline_parse(argc
, argv
, "c:d:t:z:P:Q:glpqvT"))
391 result
= load(isc_commandline_argument
, ".", ISC_TRUE
);
392 if (result
!= ISC_R_SUCCESS
)
393 printf("cache load(%s) %08x: %s\n",
394 isc_commandline_argument
, result
,
395 isc_result_totext(result
));
398 n
= strlcpy(dbtype
, isc_commandline_argument
,
400 if (n
>= sizeof(dbtype
)) {
401 fprintf(stderr
, "bad db type '%s'\n",
402 isc_commandline_argument
);
407 options
|= (DNS_DBFIND_GLUEOK
|DNS_DBFIND_VALIDATEGLUE
);
410 RUNTIME_CHECK(isc_log_create(mctx
, &lctx
,
411 NULL
) == ISC_R_SUCCESS
);
412 isc_log_setcontext(lctx
);
414 dns_log_setcontext(lctx
);
421 printnode
= ISC_TRUE
;
424 pause_every
= atoi(isc_commandline_argument
);
427 memory_quota
= atoi(isc_commandline_argument
);
428 isc_mem_setquota(mctx
, memory_quota
);
431 type
= atoi(isc_commandline_argument
);
434 time_lookups
= ISC_TRUE
;
440 origintext
= strrchr(isc_commandline_argument
, '/');
441 if (origintext
== NULL
)
442 origintext
= isc_commandline_argument
;
444 origintext
++; /* Skip '/'. */
445 result
= load(isc_commandline_argument
, origintext
,
447 if (result
!= ISC_R_SUCCESS
)
448 printf("zone load(%s) %08x: %s\n",
449 isc_commandline_argument
, result
,
450 isc_result_totext(result
));
455 argc
-= isc_commandline_index
;
456 argv
+= isc_commandline_index
;
460 printf("ignoring trailing arguments\n");
463 * Some final initialization...
465 dns_fixedname_init(&foundname
);
466 fname
= dns_fixedname_name(&foundname
);
468 origin
= dns_rootname
;
478 if (fgets(s
, sizeof(s
), stdin
) == NULL
) {
483 if (len
> 0U && s
[len
- 1] == '\n') {
487 if (verbose
&& dbi
!= NULL
) {
488 if (dbi
->wversion
!= NULL
)
489 printf("future version (%p)\n", dbi
->wversion
);
490 for (i
= 0; i
< dbi
->rcount
; i
++)
491 if (dbi
->rversions
[i
] != NULL
)
492 printf("open version %d (%p)\n", i
,
495 dns_name_init(&name
, offsets
);
496 if (strcmp(s
, "!R") == 0) {
498 if (dbi
->rcount
== MAXVERSIONS
) {
499 printf("too many open versions\n");
502 dns_db_currentversion(dbi
->db
,
503 &dbi
->rversions
[dbi
->rcount
]);
504 printf("opened version %d\n", dbi
->rcount
);
505 dbi
->version
= dbi
->rversions
[dbi
->rcount
];
506 version
= dbi
->version
;
509 } else if (strcmp(s
, "!W") == 0) {
511 if (dbi
->wversion
!= NULL
) {
512 printf("using existing future version\n");
513 dbi
->version
= dbi
->wversion
;
514 version
= dbi
->version
;
517 result
= dns_db_newversion(dbi
->db
, &dbi
->wversion
);
518 if (result
!= ISC_R_SUCCESS
)
519 print_result("", result
);
521 printf("newversion\n");
522 dbi
->version
= dbi
->wversion
;
523 version
= dbi
->version
;
525 } else if (strcmp(s
, "!C") == 0) {
529 if (dbi
->version
== NULL
)
531 if (dbi
->version
== dbi
->wversion
) {
532 printf("closing future version\n");
533 dbi
->wversion
= NULL
;
535 for (i
= 0; i
< dbi
->rcount
; i
++) {
538 dbi
->rversions
[i
] = NULL
;
539 printf("closing open version %d\n",
545 dns_db_closeversion(dbi
->db
, &dbi
->version
, ISC_TRUE
);
548 } else if (strcmp(s
, "!X") == 0) {
552 if (dbi
->version
== NULL
)
554 if (dbi
->version
== dbi
->wversion
) {
555 printf("aborting future version\n");
556 dbi
->wversion
= NULL
;
558 for (i
= 0; i
< dbi
->rcount
; i
++) {
561 dbi
->rversions
[i
] = NULL
;
562 printf("closing open version %d\n",
568 dns_db_closeversion(dbi
->db
, &dbi
->version
, ISC_FALSE
);
571 } else if (strcmp(s
, "!A") == 0) {
578 printf("addmode = %s\n", addmode
? "TRUE" : "FALSE");
580 } else if (strcmp(s
, "!D") == 0) {
587 printf("delmode = %s\n", delmode
? "TRUE" : "FALSE");
589 } else if (strcmp(s
, "!H") == 0) {
592 holdmode
= ISC_FALSE
;
595 printf("holdmode = %s\n", holdmode
? "TRUE" : "FALSE");
597 } else if (strcmp(s
, "!HR") == 0) {
599 for (i
= 0; i
< dbi
->hold_count
; i
++)
600 dns_db_detachnode(dbi
->db
,
601 &dbi
->hold_nodes
[i
]);
603 holdmode
= ISC_FALSE
;
604 printf("held nodes have been detached\n");
606 } else if (strcmp(s
, "!VC") == 0) {
608 printf("switching to current version\n");
612 } else if (strstr(s
, "!V") == s
) {
615 if (v
>= dbi
->rcount
|| v
< 0) {
616 printf("unknown open version %d\n", v
);
619 if (dbi
->rversions
[v
] == NULL
) {
620 printf("version %d is not open\n", v
);
623 printf("switching to open version %d\n", v
);
624 dbi
->version
= dbi
->rversions
[v
];
625 version
= dbi
->version
;
627 } else if (strstr(s
, "!TR") == s
) {
628 trust
= (unsigned int)atoi(&s
[3]);
629 printf("trust level is now %u\n", (unsigned int)trust
);
631 } else if (strstr(s
, "!T") == s
) {
632 type
= (unsigned int)atoi(&s
[2]);
633 printf("now searching for type %u\n", type
);
635 } else if (strcmp(s
, "!G") == 0) {
636 if ((options
& DNS_DBFIND_GLUEOK
) != 0)
637 options
&= ~DNS_DBFIND_GLUEOK
;
639 options
|= DNS_DBFIND_GLUEOK
;
640 printf("glue ok = %s\n",
641 ((options
& DNS_DBFIND_GLUEOK
) != 0) ?
644 } else if (strcmp(s
, "!GV") == 0) {
645 if ((options
& DNS_DBFIND_VALIDATEGLUE
) != 0)
646 options
&= ~DNS_DBFIND_VALIDATEGLUE
;
648 options
|= DNS_DBFIND_VALIDATEGLUE
;
649 printf("validate glue = %s\n",
650 ((options
& DNS_DBFIND_VALIDATEGLUE
) != 0) ?
653 } else if (strcmp(s
, "!WC") == 0) {
654 if ((options
& DNS_DBFIND_NOWILD
) != 0)
655 options
&= ~DNS_DBFIND_NOWILD
;
657 options
|= DNS_DBFIND_NOWILD
;
658 printf("wildcard matching = %s\n",
659 ((options
& DNS_DBFIND_NOWILD
) == 0) ?
662 } else if (strstr(s
, "!LS ") == s
) {
666 } else if (strcmp(s
, "!LS") == 0) {
670 } else if (strstr(s
, "!DU ") == s
) {
672 result
= dns_db_dump(dbi
->db
, dbi
->version
, s
+4);
673 if (result
!= ISC_R_SUCCESS
) {
675 print_result("", result
);
678 } else if (strcmp(s
, "!PN") == 0) {
680 printnode
= ISC_FALSE
;
682 printnode
= ISC_TRUE
;
683 printf("printnode = %s\n",
684 printnode
? "TRUE" : "FALSE");
686 } else if (strstr(s
, "!P") == s
) {
689 dbi
->pause_every
= v
;
691 } else if (strcmp(s
, "!+") == 0) {
693 dbi
->ascending
= ISC_TRUE
;
695 } else if (strcmp(s
, "!-") == 0) {
697 dbi
->ascending
= ISC_FALSE
;
699 } else if (strcmp(s
, "!DB") == 0) {
701 origin
= dns_rootname
;
703 printf("now searching all databases\n");
705 } else if (strncmp(s
, "!DB ", 4) == 0) {
706 dbi
= select_db(s
+4);
709 origin
= dns_db_origin(dbi
->db
);
710 version
= dbi
->version
;
713 holdmode
= ISC_FALSE
;
717 origin
= dns_rootname
;
718 printf("database not found; "
719 "now searching all databases\n");
722 } else if (strcmp(s
, "!ZC") == 0) {
724 find_zonecut
= ISC_FALSE
;
726 find_zonecut
= ISC_TRUE
;
727 printf("find_zonecut = %s\n",
728 find_zonecut
? "TRUE" : "FALSE");
730 } else if (strcmp(s
, "!NZ") == 0) {
732 noexact_zonecut
= ISC_FALSE
;
734 noexact_zonecut
= ISC_TRUE
;
735 printf("noexact_zonecut = %s\n",
736 noexact_zonecut
? "TRUE" : "FALSE");
740 isc_buffer_init(&source
, s
, len
);
741 isc_buffer_add(&source
, len
);
742 isc_buffer_init(&target
, b
, sizeof(b
));
743 result
= dns_name_fromtext(&name
, &source
, origin
, 0, &target
);
744 if (result
!= ISC_R_SUCCESS
) {
745 print_result("bad name: ", result
);
752 zcoptions
|= DNS_DBTABLEFIND_NOEXACT
;
754 result
= dns_dbtable_find(dbtable
, &name
, zcoptions
,
756 if (result
!= ISC_R_SUCCESS
&&
757 result
!= DNS_R_PARTIALMATCH
) {
760 print_result("", result
);
764 isc_buffer_init(&tb1
, t1
, sizeof(t1
));
765 result
= dns_name_totext(dns_db_origin(db
), ISC_FALSE
,
767 if (result
!= ISC_R_SUCCESS
) {
769 print_result("", result
);
773 isc_buffer_usedregion(&tb1
, &r1
);
774 printf("\ndatabase = %.*s (%s)\n",
775 (int)r1
.length
, r1
.base
,
776 (dns_db_iszone(db
)) ? "zone" : "cache");
779 dns_rdataset_init(&rdataset
);
780 dns_rdataset_init(&sigrdataset
);
782 if (find_zonecut
&& dns_db_iscache(db
)) {
785 zcoptions
|= DNS_DBFIND_NOEXACT
;
786 result
= dns_db_findzonecut(db
, &name
, zcoptions
,
788 &rdataset
, &sigrdataset
);
790 result
= dns_db_find(db
, &name
, version
, type
,
791 options
, 0, &node
, fname
,
792 &rdataset
, &sigrdataset
);
798 print_result("", result
);
801 found_as
= ISC_FALSE
;
809 case DNS_R_DELEGATION
:
813 if (dns_rdataset_isassociated(&rdataset
))
817 RUNTIME_CHECK(dbi
->hold_count
<
819 dbi
->hold_nodes
[dbi
->hold_count
++] =
823 dns_db_detachnode(db
, &node
);
825 dns_db_detachnode(db
, &node
);
830 if (dns_rdataset_isassociated(&rdataset
))
837 print_result("", result
);
840 if (found_as
&& !quiet
) {
841 isc_buffer_init(&tb1
, t1
, sizeof(t1
));
842 isc_buffer_init(&tb2
, t2
, sizeof(t2
));
843 result
= dns_name_totext(&name
, ISC_FALSE
, &tb1
);
844 if (result
!= ISC_R_SUCCESS
) {
845 print_result("", result
);
846 dns_db_detachnode(db
, &node
);
851 result
= dns_name_totext(fname
, ISC_FALSE
, &tb2
);
852 if (result
!= ISC_R_SUCCESS
) {
853 print_result("", result
);
854 dns_db_detachnode(db
, &node
);
859 isc_buffer_usedregion(&tb1
, &r1
);
860 isc_buffer_usedregion(&tb2
, &r2
);
861 printf("found %.*s as %.*s\n",
862 (int)r1
.length
, r1
.base
,
863 (int)r2
.length
, r2
.base
);
867 dns_db_printnode(db
, node
, stdout
);
869 if (!found_as
&& type
== dns_rdatatype_any
) {
871 result
= dns_db_allrdatasets(db
, node
, version
, 0,
873 if (result
== ISC_R_SUCCESS
) {
875 print_rdatasets(fname
, rdsiter
);
876 dns_rdatasetiter_destroy(&rdsiter
);
878 print_result("", result
);
881 print_rdataset(fname
, &rdataset
);
882 if (dns_rdataset_isassociated(&sigrdataset
)) {
884 print_rdataset(fname
, &sigrdataset
);
885 dns_rdataset_disassociate(&sigrdataset
);
887 if (dbi
!= NULL
&& addmode
&& !found_as
) {
889 rdataset
.trust
= trust
;
890 if (dns_db_iszone(db
))
891 addopts
= DNS_DBADD_MERGE
;
894 result
= dns_db_addrdataset(db
, node
, version
,
897 if (result
!= ISC_R_SUCCESS
)
898 print_result("", result
);
900 dns_db_printnode(db
, node
, stdout
);
901 } else if (dbi
!= NULL
&& delmode
&& !found_as
) {
902 result
= dns_db_deleterdataset(db
, node
,
905 if (result
!= ISC_R_SUCCESS
)
906 print_result("", result
);
908 dns_db_printnode(db
, node
, stdout
);
910 dns_rdataset_disassociate(&rdataset
);
915 RUNTIME_CHECK(dbi
->hold_count
< MAXHOLD
);
916 dbi
->hold_nodes
[dbi
->hold_count
++] = node
;
919 dns_db_detachnode(db
, &node
);
921 dns_db_detachnode(db
, &node
);
931 usec
= isc_time_microdiff(&finish
, &start
);
933 printf("elapsed time: %lu.%06lu seconds\n",
934 (unsigned long)(usec
/ 1000000),
935 (unsigned long)(usec
% 1000000));
940 dns_dbtable_detach(&dbtable
);
943 isc_log_destroy(&lctx
);
946 isc_mem_stats(mctx
, stdout
);