1 /* $NetBSD: t_db.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: t_db.c,v 1.41 2011/03/12 04:59:46 tbox Exp */
27 #include <isc/entropy.h>
30 #include <isc/string.h>
34 #include <dns/fixedname.h>
35 #include <dns/rdata.h>
36 #include <dns/rdataclass.h>
37 #include <dns/rdatatype.h>
38 #include <dns/rdatalist.h>
39 #include <dns/rdataset.h>
40 #include <dns/result.h>
42 #include <tests/t_api.h>
45 t_create(const char *db_type
, const char *origin
, const char *class,
46 const char *model
, isc_mem_t
*mctx
, dns_db_t
**db
)
49 isc_result_t dns_result
;
51 isc_textregion_t region
;
52 isc_buffer_t origin_buffer
;
53 dns_fixedname_t dns_origin
;
54 dns_rdataclass_t rdataclass
;
57 dbtype
= dns_dbtype_zone
;
58 if (strcasecmp(model
, "cache") == 0)
59 dbtype
= dns_dbtype_cache
;
61 dns_fixedname_init(&dns_origin
);
63 isc_buffer_constinit(&origin_buffer
, origin
, len
);
64 isc_buffer_add(&origin_buffer
, len
);
65 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_origin
),
66 &origin_buffer
, NULL
, 0, NULL
);
67 if (dns_result
!= ISC_R_SUCCESS
) {
68 t_info("dns_name_fromtext failed %s\n",
69 dns_result_totext(dns_result
));
73 DE_CONST(class, region
.base
);
74 region
.length
= strlen(class);
75 dns_result
= dns_rdataclass_fromtext(&rdataclass
, ®ion
);
76 if (dns_result
!= ISC_R_SUCCESS
) {
77 t_info("dns_rdataclass_fromtext failed %s\n",
78 dns_result_totext(dns_result
));
82 dns_result
= dns_db_create(mctx
, db_type
,
83 dns_fixedname_name(&dns_origin
),
84 dbtype
, rdataclass
, 0, NULL
, db
);
85 if (dns_result
!= ISC_R_SUCCESS
)
86 t_info("dns_db_create failed %s\n",
87 dns_result_totext(dns_result
));
94 t_dns_db_load(char **av
) {
100 char *expected_load_result
;
103 char *expected_find_result
;
108 isc_result_t dns_result
;
109 isc_result_t isc_result
;
113 isc_textregion_t textregion
;
114 isc_buffer_t findname_buffer
;
115 dns_fixedname_t dns_findname
;
116 dns_fixedname_t dns_foundname
;
117 dns_rdataset_t rdataset
;
118 dns_rdatatype_t rdatatype
;
119 dns_dbversion_t
*versionp
;
120 isc_result_t exp_load_result
;
121 isc_result_t exp_find_result
;
131 expected_load_result
= T_ARG(5);
133 find_type
= T_ARG(7);
134 expected_find_result
= T_ARG(8);
136 t_info("testing using file %s and name %s\n", filename
, findname
);
138 exp_load_result
= t_dns_result_fromtext(expected_load_result
);
139 exp_find_result
= t_dns_result_fromtext(expected_find_result
);
141 isc_result
= isc_mem_create(0, 0, &mctx
);
142 if (isc_result
!= ISC_R_SUCCESS
) {
143 t_info("isc_mem_create failed %s\n",
144 isc_result_totext(isc_result
));
145 return(T_UNRESOLVED
);
148 isc_result
= isc_entropy_create(mctx
, &ectx
);
149 if (isc_result
!= ISC_R_SUCCESS
) {
150 t_info("isc_entropy_create failed %s\n",
151 isc_result_totext(isc_result
));
152 isc_mem_destroy(&mctx
);
153 return(T_UNRESOLVED
);
156 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
157 if (isc_result
!= ISC_R_SUCCESS
) {
158 t_info("isc_hash_create failed %s\n",
159 isc_result_totext(isc_result
));
160 isc_entropy_detach(&ectx
);
161 isc_mem_destroy(&mctx
);
162 return(T_UNRESOLVED
);
165 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
166 if (dns_result
!= ISC_R_SUCCESS
) {
168 isc_entropy_detach(&ectx
);
169 isc_mem_destroy(&mctx
);
170 return(T_UNRESOLVED
);
173 dns_result
= dns_db_load(db
, filename
);
174 if (dns_result
!= exp_load_result
) {
175 t_info("dns_db_load returned %s, expected %s\n",
176 dns_result_totext(dns_result
),
177 dns_result_totext(exp_load_result
));
180 isc_entropy_detach(&ectx
);
181 isc_mem_destroy(&mctx
);
184 if (dns_result
!= ISC_R_SUCCESS
) {
189 dns_fixedname_init(&dns_findname
);
190 len
= strlen(findname
);
191 isc_buffer_init(&findname_buffer
, findname
, len
);
192 isc_buffer_add(&findname_buffer
, len
);
193 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_findname
),
194 &findname_buffer
, NULL
, 0, NULL
);
195 if (dns_result
!= ISC_R_SUCCESS
) {
196 t_info("dns_name_fromtext failed %s\n",
197 dns_result_totext(dns_result
));
200 isc_entropy_detach(&ectx
);
201 isc_mem_destroy(&mctx
);
202 return(T_UNRESOLVED
);
205 textregion
.base
= find_type
;
206 textregion
.length
= strlen(find_type
);
207 dns_result
= dns_rdatatype_fromtext(&rdatatype
, &textregion
);
208 if (dns_result
!= ISC_R_SUCCESS
) {
209 t_info("dns_rdatatype_fromtext %s failed %s\n",
211 dns_result_totext(dns_result
));
214 isc_entropy_detach(&ectx
);
215 isc_mem_destroy(&mctx
);
216 return(T_UNRESOLVED
);
220 dns_fixedname_init(&dns_foundname
);
221 dns_rdataset_init(&rdataset
);
222 if (dns_db_iszone(db
))
223 dns_db_currentversion(db
, &versionp
);
226 dns_result
= dns_db_find(db
,
227 dns_fixedname_name(&dns_findname
),
233 dns_fixedname_name(&dns_foundname
),
236 if (dns_result
!= exp_find_result
) {
237 t_info("dns_db_find returned %s, expected %s\n",
238 dns_result_totext(dns_result
),
239 dns_result_totext(exp_find_result
));
245 if (dns_result
!= ISC_R_NOTFOUND
) {
246 dns_db_detachnode(db
, &nodep
);
247 if (dns_rdataset_isassociated(&rdataset
))
248 dns_rdataset_disassociate(&rdataset
);
251 if (dns_db_iszone(db
))
252 dns_db_closeversion(db
, &versionp
, ISC_FALSE
);
256 isc_entropy_detach(&ectx
);
257 isc_mem_destroy(&mctx
);
261 static const char *a1
=
262 "A call to dns_db_load(db, filename) loads the contents of "
263 "the database in filename into db.";
269 t_assert("dns_db_load", 1, T_REQUIRED
, "%s", a1
);
270 result
= t_eval("dns_db_load_data", t_dns_db_load
, 9);
275 static const char *a2
=
276 "When the database db has cache semantics, a call to "
277 "dns_db_iscache(db) returns ISC_TRUE.";
280 t_dns_db_zc_x(char *filename
, char *db_type
, char *origin
, char *class,
281 dns_dbtype_t dbtype
, isc_boolean_t(*cf
)(dns_db_t
*),
282 isc_boolean_t exp_result
)
287 isc_result_t dns_result
;
288 isc_result_t isc_result
;
291 dns_rdataclass_t rdataclass
;
292 isc_textregion_t textregion
;
293 isc_buffer_t origin_buffer
;
294 dns_fixedname_t dns_origin
;
300 t_info("testing using file %s\n", filename
);
302 dns_fixedname_init(&dns_origin
);
303 len
= strlen(origin
);
304 isc_buffer_init(&origin_buffer
, origin
, len
);
305 isc_buffer_add(&origin_buffer
, len
);
306 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_origin
),
307 &origin_buffer
, NULL
, 0, NULL
);
308 if (dns_result
!= ISC_R_SUCCESS
) {
309 t_info("dns_name_fromtext failed %s\n",
310 dns_result_totext(dns_result
));
311 return(T_UNRESOLVED
);
314 textregion
.base
= class;
315 textregion
.length
= strlen(class);
316 dns_result
= dns_rdataclass_fromtext(&rdataclass
, &textregion
);
317 if (dns_result
!= ISC_R_SUCCESS
) {
318 t_info("dns_rdataclass_fromtext failed %s\n",
319 dns_result_totext(dns_result
));
320 return(T_UNRESOLVED
);
323 isc_result
= isc_mem_create(0, 0, &mctx
);
324 if (isc_result
!= ISC_R_SUCCESS
) {
325 t_info("isc_mem_create failed %s\n",
326 isc_result_totext(isc_result
));
327 return(T_UNRESOLVED
);
330 isc_result
= isc_entropy_create(mctx
, &ectx
);
331 if (isc_result
!= ISC_R_SUCCESS
) {
332 t_info("isc_entropy_create failed %s\n",
333 isc_result_totext(isc_result
));
334 isc_mem_destroy(&mctx
);
335 return(T_UNRESOLVED
);
338 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
339 if (isc_result
!= ISC_R_SUCCESS
) {
340 t_info("isc_hash_create failed %s\n",
341 isc_result_totext(isc_result
));
342 isc_entropy_detach(&ectx
);
343 isc_mem_destroy(&mctx
);
344 return(T_UNRESOLVED
);
347 dns_result
= dns_db_create(mctx
, db_type
,
348 dns_fixedname_name(&dns_origin
),
349 dbtype
, rdataclass
, 0, NULL
, &db
);
350 if (dns_result
!= ISC_R_SUCCESS
) {
351 t_info("dns_db_create failed %s\n",
352 dns_result_totext(dns_result
));
354 isc_entropy_detach(&ectx
);
355 isc_mem_destroy(&mctx
);
356 return(T_UNRESOLVED
);
359 dns_result
= dns_db_load(db
, filename
);
360 if (dns_result
== ISC_R_SUCCESS
) {
361 if ((*cf
)(db
) == exp_result
)
366 t_info("dns_db_load failed %s\n",
367 dns_result_totext(dns_result
));
373 isc_entropy_detach(&ectx
);
374 isc_mem_destroy(&mctx
);
379 test_dns_db_zc_x(const char *filename
, dns_dbtype_t dbtype
,
380 isc_boolean_t(*cf
)(dns_db_t
*), isc_boolean_t exp_result
)
390 char *tokens
[T_MAXTOKS
];
395 fp
= fopen(filename
, "r");
398 while ((p
= t_fgetbs(fp
)) != NULL
) {
403 * Skip comment lines.
405 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
410 cnt
= t_bustline(p
, tokens
);
412 result
= t_dns_db_zc_x(tokens
[0], /* file */
413 tokens
[1], /* type */
414 tokens
[2], /* origin */
415 tokens
[3], /* class */
418 exp_result
);/* expect */
419 if (result
!= T_PASS
) {
420 if (result
== T_FAIL
)
426 t_info("bad format in %s at line %d\n",
435 t_info("Missing datafile %s\n", filename
);
439 result
= T_UNRESOLVED
;
441 if (nfails
== 0 && nprobs
== 0)
453 t_assert("dns_db_iscache", 2, T_REQUIRED
, "%s", a2
);
454 result
= test_dns_db_zc_x("dns_db_iscache_1_data",
455 dns_dbtype_cache
, dns_db_iscache
, ISC_TRUE
);
460 static const char *a3
=
461 "When the database db has zone semantics, a call to "
462 "dns_db_iscache(db) returns ISC_FALSE.";
469 t_assert("dns_db_iscache", 3, T_REQUIRED
, "%s", a3
);
470 result
= test_dns_db_zc_x("dns_db_iscache_2_data",
471 dns_dbtype_zone
, dns_db_iscache
, ISC_FALSE
);
476 static const char *a4
=
477 "When the database db has zone semantics, a call to "
478 "dns_db_iszone(db) returns ISC_TRUE.";
485 t_assert("dns_db_iszone", 4, T_REQUIRED
, "%s", a4
);
486 result
= test_dns_db_zc_x("dns_db_iszone_1_data",
487 dns_dbtype_zone
, dns_db_iszone
, ISC_TRUE
);
492 static const char *a5
=
493 "When the database db has cache semantics, a call to "
494 "dns_db_iszone(db) returns ISC_FALSE.";
500 t_assert("dns_db_iszone", 5, T_REQUIRED
, "%s", a5
);
501 result
= test_dns_db_zc_x("dns_db_iszone_2_data",
502 dns_dbtype_cache
, dns_db_iszone
, ISC_FALSE
);
507 t_dns_db_origin(char **av
) {
515 isc_result_t dns_result
;
516 isc_result_t isc_result
;
520 dns_fixedname_t dns_origin
;
521 dns_fixedname_t dns_dborigin
;
522 isc_buffer_t origin_buffer
;
531 t_info("testing with database %s and origin %s\n",
534 isc_result
= isc_mem_create(0, 0, &mctx
);
535 if (isc_result
!= ISC_R_SUCCESS
) {
536 t_info("isc_mem_create failed %s\n",
537 isc_result_totext(isc_result
));
538 return(T_UNRESOLVED
);
541 isc_result
= isc_entropy_create(mctx
, &ectx
);
542 if (isc_result
!= ISC_R_SUCCESS
) {
543 t_info("isc_entropy_create failed %s\n",
544 isc_result_totext(isc_result
));
545 isc_mem_destroy(&mctx
);
546 return(T_UNRESOLVED
);
549 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
550 if (isc_result
!= ISC_R_SUCCESS
) {
551 t_info("isc_hash_create failed %s\n",
552 isc_result_totext(isc_result
));
553 isc_entropy_detach(&ectx
);
554 isc_mem_destroy(&mctx
);
555 return(T_UNRESOLVED
);
558 dns_result
= t_create("rbt", origin
, "in", "isc_true", mctx
, &db
);
559 if (dns_result
!= ISC_R_SUCCESS
) {
560 t_info("t_create failed %s\n",
561 dns_result_totext(dns_result
));
563 isc_entropy_detach(&ectx
);
564 isc_mem_destroy(&mctx
);
565 return(T_UNRESOLVED
);
567 dns_fixedname_init(&dns_origin
);
568 dns_fixedname_init(&dns_dborigin
);
570 len
= strlen(origin
);
571 isc_buffer_init(&origin_buffer
, origin
, len
);
572 isc_buffer_add(&origin_buffer
, len
);
574 dns_result
= dns_db_load(db
, filename
);
575 if (dns_result
!= ISC_R_SUCCESS
) {
576 t_info("dns_db_load failed %s\n",
577 dns_result_totext(dns_result
));
580 isc_entropy_detach(&ectx
);
581 isc_mem_destroy(&mctx
);
582 return(T_UNRESOLVED
);
585 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_origin
),
586 &origin_buffer
, NULL
, 0, NULL
);
587 if (dns_result
!= ISC_R_SUCCESS
) {
588 t_info("dns_name_fromtext failed %s\n",
589 dns_result_totext(dns_result
));
592 isc_entropy_detach(&ectx
);
593 isc_mem_destroy(&mctx
);
594 return(T_UNRESOLVED
);
596 order
= dns_name_compare(dns_fixedname_name(&dns_origin
),
601 t_info("dns_name_compare returned %d\n", order
);
607 isc_entropy_detach(&ectx
);
608 isc_mem_destroy(&mctx
);
613 static const char *a6
=
614 "A call to dns_db_origin(db) returns the origin of the database.";
620 t_assert("dns_db_origin", 6, T_REQUIRED
, "%s", a6
);
621 result
= t_eval("dns_db_origin_data", t_dns_db_origin
, 2);
626 static const char *a7
=
627 "A call to dns_db_class(db) returns the class of the database.";
630 #define CLASSBUFLEN 256
633 t_dns_db_class(char **av
) {
639 isc_result_t dns_result
;
640 isc_result_t isc_result
;
644 dns_rdataclass_t rdataclass
;
645 dns_rdataclass_t db_rdataclass
;
646 isc_textregion_t textregion
;
654 t_info("testing with database %s and class %s\n",
657 textregion
.base
= class;
658 textregion
.length
= strlen(class);
659 dns_result
= dns_rdataclass_fromtext(&rdataclass
, &textregion
);
660 if (dns_result
!= ISC_R_SUCCESS
) {
661 t_info("dns_rdataclass_fromtext failed %s\n",
662 dns_result_totext(dns_result
));
663 return(T_UNRESOLVED
);
666 isc_result
= isc_mem_create(0, 0, &mctx
);
667 if (isc_result
!= ISC_R_SUCCESS
) {
668 t_info("isc_mem_create failed %s\n",
669 isc_result_totext(isc_result
));
670 return(T_UNRESOLVED
);
673 isc_result
= isc_entropy_create(mctx
, &ectx
);
674 if (isc_result
!= ISC_R_SUCCESS
) {
675 t_info("isc_entropy_create failed %s\n",
676 isc_result_totext(isc_result
));
677 isc_mem_destroy(&mctx
);
678 return(T_UNRESOLVED
);
681 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
682 if (isc_result
!= ISC_R_SUCCESS
) {
683 t_info("isc_hash_create failed %s\n",
684 isc_result_totext(isc_result
));
685 isc_entropy_detach(&ectx
);
686 isc_mem_destroy(&mctx
);
687 return(T_UNRESOLVED
);
690 dns_result
= t_create("rbt", ".", class, "isc_true", mctx
, &db
);
691 if (dns_result
!= ISC_R_SUCCESS
) {
692 t_info("t_create failed %s\n",
693 dns_result_totext(dns_result
));
695 isc_entropy_detach(&ectx
);
696 isc_mem_destroy(&mctx
);
697 return(T_UNRESOLVED
);
700 dns_result
= dns_db_load(db
, filename
);
701 if (dns_result
!= ISC_R_SUCCESS
) {
702 t_info("dns_db_load failed %s\n",
703 dns_result_totext(dns_result
));
706 isc_entropy_detach(&ectx
);
707 isc_mem_destroy(&mctx
);
708 return(T_UNRESOLVED
);
711 db_rdataclass
= dns_db_class(db
);
712 if (db_rdataclass
== rdataclass
)
715 char classbuf
[DNS_RDATACLASS_FORMATSIZE
];
716 dns_rdataclass_format(db_rdataclass
,
717 classbuf
, sizeof(classbuf
));
718 t_info("dns_db_class returned %s, expected %s\n",
725 isc_entropy_detach(&ectx
);
726 isc_mem_destroy(&mctx
);
734 t_assert("dns_db_class", 7, T_REQUIRED
, "%s", a7
);
735 result
= t_eval("dns_db_class_data", t_dns_db_class
, 2);
740 static const char *a8
=
741 "A call to dns_db_currentversion() opens the current "
742 "version for reading.";
745 t_dns_db_currentversion(char **av
) {
757 isc_result_t dns_result
;
758 isc_result_t isc_result
;
762 isc_textregion_t textregion
;
763 isc_buffer_t findname_buffer
;
764 dns_fixedname_t dns_findname
;
765 dns_fixedname_t dns_foundname
;
766 dns_rdataset_t rdataset
;
767 dns_rdatatype_t rdatatype
;
768 dns_dbversion_t
*cversionp
;
769 dns_dbversion_t
*nversionp
;
782 t_info("testing using file %s and name %s\n", filename
, findname
);
784 isc_result
= isc_mem_create(0, 0, &mctx
);
785 if (isc_result
!= ISC_R_SUCCESS
) {
786 t_info("isc_mem_create failed %s\n",
787 isc_result_totext(isc_result
));
788 return(T_UNRESOLVED
);
791 isc_result
= isc_entropy_create(mctx
, &ectx
);
792 if (isc_result
!= ISC_R_SUCCESS
) {
793 t_info("isc_entropy_create failed %s\n",
794 isc_result_totext(isc_result
));
795 isc_mem_destroy(&mctx
);
796 return(T_UNRESOLVED
);
799 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
800 if (isc_result
!= ISC_R_SUCCESS
) {
801 t_info("isc_hash_create failed %s\n",
802 isc_result_totext(isc_result
));
803 isc_entropy_detach(&ectx
);
804 isc_mem_destroy(&mctx
);
805 return(T_UNRESOLVED
);
808 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
809 if (dns_result
!= ISC_R_SUCCESS
) {
811 isc_entropy_detach(&ectx
);
812 isc_mem_destroy(&mctx
);
813 return(T_UNRESOLVED
);
816 dns_result
= dns_db_load(db
, filename
);
817 if (dns_result
!= ISC_R_SUCCESS
) {
818 t_info("dns_db_load returned %s\n",
819 dns_result_totext(dns_result
));
822 isc_entropy_detach(&ectx
);
823 isc_mem_destroy(&mctx
);
824 return(T_UNRESOLVED
);
827 dns_fixedname_init(&dns_findname
);
828 len
= strlen(findname
);
829 isc_buffer_init(&findname_buffer
, findname
, len
);
830 isc_buffer_add(&findname_buffer
, len
);
831 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_findname
),
832 &findname_buffer
, NULL
, 0, NULL
);
833 if (dns_result
!= ISC_R_SUCCESS
) {
834 t_info("dns_name_fromtext failed %s\n",
835 dns_result_totext(dns_result
));
838 isc_entropy_detach(&ectx
);
839 isc_mem_destroy(&mctx
);
840 return(T_UNRESOLVED
);
843 textregion
.base
= findtype
;
844 textregion
.length
= strlen(findtype
);
845 dns_result
= dns_rdatatype_fromtext(&rdatatype
, &textregion
);
846 if (dns_result
!= ISC_R_SUCCESS
) {
847 t_info("dns_rdatatype_fromtext %s failed %s\n",
849 dns_result_totext(dns_result
));
852 isc_entropy_detach(&ectx
);
853 isc_mem_destroy(&mctx
);
854 return(T_UNRESOLVED
);
858 * find a name we know is there
862 dns_fixedname_init(&dns_foundname
);
863 dns_rdataset_init(&rdataset
);
864 dns_db_currentversion(db
, &cversionp
);
867 dns_result
= dns_db_find(db
,
868 dns_fixedname_name(&dns_findname
),
874 dns_fixedname_name(&dns_foundname
),
877 if (dns_result
!= ISC_R_SUCCESS
) {
878 t_info("unable to find %s using current version\n", findname
);
879 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
882 isc_entropy_detach(&ectx
);
883 isc_mem_destroy(&mctx
);
884 return(T_UNRESOLVED
);
888 * create a new version
889 * delete the found rdataset in the new version
890 * attempt to find the rdataset again and expect the find to fail
891 * close/commit the new version
892 * attempt to find the rdataset in the current version and
893 * expect the find to succeed
897 dns_result
= dns_db_newversion(db
, &nversionp
);
898 if (dns_result
!= ISC_R_SUCCESS
) {
899 t_info("dns_db_newversion failed %s\n",
900 dns_result_totext(dns_result
));
901 dns_db_detachnode(db
, &nodep
);
902 dns_rdataset_disassociate(&rdataset
);
903 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
906 isc_entropy_detach(&ectx
);
907 isc_mem_destroy(&mctx
);
908 return(T_UNRESOLVED
);
912 * Delete the found rdataset in the new version.
914 dns_result
= dns_db_deleterdataset(db
, nodep
, nversionp
, rdatatype
, 0);
915 if (dns_result
!= ISC_R_SUCCESS
) {
916 t_info("dns_db_deleterdataset failed %s\n",
917 dns_result_totext(dns_result
));
918 dns_rdataset_disassociate(&rdataset
);
919 dns_db_detachnode(db
, &nodep
);
920 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
921 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
924 isc_entropy_detach(&ectx
);
925 isc_mem_destroy(&mctx
);
926 return(T_UNRESOLVED
);
930 * Don't need these now.
932 dns_rdataset_disassociate(&rdataset
);
933 dns_db_detachnode(db
, &nodep
);
937 * Find the deleted rdataset and expect it to fail.
939 dns_result
= dns_db_find(db
,
940 dns_fixedname_name(&dns_findname
),
946 dns_fixedname_name(&dns_foundname
),
949 if ((dns_result
!= ISC_R_NOTFOUND
) && (dns_result
!= DNS_R_NXDOMAIN
)) {
950 t_info("unexpectedly found %s using current version\n",
952 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
953 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
956 isc_entropy_detach(&ectx
);
957 isc_mem_destroy(&mctx
);
962 * Close/commit the new version.
964 dns_db_closeversion(db
, &nversionp
, ISC_TRUE
);
967 * Find the deleted rdata in the current version.
969 dns_result
= dns_db_find(db
, dns_fixedname_name(&dns_findname
),
970 cversionp
, rdatatype
, DNS_DBFIND_GLUEOK
,
971 0, &nodep
, dns_fixedname_name(&dns_foundname
),
975 * And expect it to succeed.
977 if (dns_result
== ISC_R_SUCCESS
) {
980 t_info("cound not find %s using current version\n", findname
);
981 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
984 isc_entropy_detach(&ectx
);
985 isc_mem_destroy(&mctx
);
989 dns_db_detachnode(db
, &nodep
);
990 dns_rdataset_disassociate(&rdataset
);
992 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
995 isc_entropy_detach(&ectx
);
996 isc_mem_destroy(&mctx
);
1005 t_assert("dns_db_currentversion", 8, T_REQUIRED
, "%s", a8
);
1006 result
= t_eval("dns_db_currentversion_data",
1007 t_dns_db_currentversion
, 7);
1011 static const char *a9
=
1012 "A call to dns_db_newversion() opens a new version for "
1013 "reading and writing.";
1016 t_dns_db_newversion(char **av
) {
1030 isc_result_t dns_result
;
1031 isc_result_t isc_result
;
1033 isc_entropy_t
*ectx
;
1034 dns_dbnode_t
*nodep
;
1035 dns_dbnode_t
*found_nodep
;
1036 isc_textregion_t textregion
;
1037 isc_buffer_t newname_buffer
;
1038 dns_fixedname_t dns_newname
;
1039 dns_fixedname_t dns_foundname
;
1040 dns_rdata_t added_rdata
= DNS_RDATA_INIT
;
1041 const char * added_rdata_data
;
1042 dns_rdataset_t added_rdataset
;
1043 dns_rdata_t found_rdata
= DNS_RDATA_INIT
;
1044 dns_rdataset_t found_rdataset
;
1045 dns_rdatatype_t rdatatype
;
1046 dns_rdataclass_t rdataclass
;
1047 dns_dbversion_t
*nversionp
;
1048 dns_rdatalist_t rdatalist
;
1050 filename
= T_ARG(0);
1062 * Open a new version, add some data, commit it,
1063 * close it, open a new version, and check that changes
1067 t_info("testing using file %s and name %s\n", filename
, newname
);
1069 isc_result
= isc_mem_create(0, 0, &mctx
);
1070 if (isc_result
!= ISC_R_SUCCESS
) {
1071 t_info("isc_mem_create failed %s\n",
1072 isc_result_totext(isc_result
));
1073 return(T_UNRESOLVED
);
1076 isc_result
= isc_entropy_create(mctx
, &ectx
);
1077 if (isc_result
!= ISC_R_SUCCESS
) {
1078 t_info("isc_entropy_create failed %s\n",
1079 isc_result_totext(isc_result
));
1080 isc_mem_destroy(&mctx
);
1081 return(T_UNRESOLVED
);
1084 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
1085 if (isc_result
!= ISC_R_SUCCESS
) {
1086 t_info("isc_hash_create failed %s\n",
1087 isc_result_totext(isc_result
));
1088 isc_entropy_detach(&ectx
);
1089 isc_mem_destroy(&mctx
);
1090 return(T_UNRESOLVED
);
1093 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
1094 if (dns_result
!= ISC_R_SUCCESS
) {
1096 isc_entropy_detach(&ectx
);
1097 isc_mem_destroy(&mctx
);
1098 return(T_UNRESOLVED
);
1101 dns_result
= dns_db_load(db
, filename
);
1102 if (dns_result
!= ISC_R_SUCCESS
) {
1103 t_info("dns_db_load returned %s\n",
1104 dns_result_totext(dns_result
));
1107 isc_entropy_detach(&ectx
);
1108 isc_mem_destroy(&mctx
);
1109 return(T_UNRESOLVED
);
1116 dns_fixedname_init(&dns_newname
);
1117 len
= strlen(newname
);
1118 isc_buffer_init(&newname_buffer
, newname
, len
);
1119 isc_buffer_add(&newname_buffer
, len
);
1120 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_newname
),
1121 &newname_buffer
, NULL
, 0, NULL
);
1122 if (dns_result
!= ISC_R_SUCCESS
) {
1123 t_info("dns_name_fromtext failed %s\n",
1124 dns_result_totext(dns_result
));
1127 isc_entropy_detach(&ectx
);
1128 isc_mem_destroy(&mctx
);
1129 return(T_UNRESOLVED
);
1133 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_newname
),
1135 if (dns_result
!= ISC_R_SUCCESS
) {
1136 t_info("dns_db_findnode failed %s\n",
1137 dns_result_totext(dns_result
));
1140 isc_entropy_detach(&ectx
);
1141 isc_mem_destroy(&mctx
);
1142 return(T_UNRESOLVED
);
1146 * Open a new version and associate some rdata with the new name.
1149 textregion
.base
= newtype
;
1150 textregion
.length
= strlen(newtype
);
1151 dns_result
= dns_rdatatype_fromtext(&rdatatype
, &textregion
);
1153 if (dns_result
!= ISC_R_SUCCESS
) {
1154 t_info("dns_rdatatype_fromtext %s failed %s\n",
1156 dns_result_totext(dns_result
));
1157 dns_db_detachnode(db
, &nodep
);
1160 isc_entropy_detach(&ectx
);
1161 isc_mem_destroy(&mctx
);
1162 return(T_UNRESOLVED
);
1165 textregion
.base
= class;
1166 textregion
.length
= strlen(class);
1167 dns_result
= dns_rdataclass_fromtext(&rdataclass
, &textregion
);
1168 if (dns_result
!= ISC_R_SUCCESS
) {
1169 t_info("dns_rdataclass_fromtext failed %s\n",
1170 dns_result_totext(dns_result
));
1171 dns_db_detachnode(db
, &nodep
);
1174 isc_entropy_detach(&ectx
);
1175 isc_mem_destroy(&mctx
);
1176 return(T_UNRESOLVED
);
1179 dns_rdata_init(&added_rdata
);
1180 added_rdata_data
= "\x10\x00\x00\x01";
1181 DE_CONST(added_rdata_data
, added_rdata
.data
);
1182 added_rdata
.length
= 4;
1183 added_rdata
.rdclass
= rdataclass
;
1184 added_rdata
.type
= rdatatype
;
1186 dns_rdataset_init(&added_rdataset
);
1187 rdatalist
.type
= rdatatype
;
1188 rdatalist
.covers
= 0;
1189 rdatalist
.rdclass
= rdataclass
;
1191 ISC_LIST_INIT(rdatalist
.rdata
);
1192 ISC_LIST_APPEND(rdatalist
.rdata
, &added_rdata
, link
);
1194 dns_result
= dns_rdatalist_tordataset(&rdatalist
, &added_rdataset
);
1195 if (dns_result
!= ISC_R_SUCCESS
) {
1196 t_info("dns_rdatalist_tordataset failed %s\n",
1197 dns_result_totext(dns_result
));
1198 dns_db_detachnode(db
, &nodep
);
1201 isc_entropy_detach(&ectx
);
1202 isc_mem_destroy(&mctx
);
1203 return(T_UNRESOLVED
);
1207 dns_result
= dns_db_newversion(db
, &nversionp
);
1208 if (dns_result
!= ISC_R_SUCCESS
) {
1209 t_info("dns_db_newversion failed %s\n",
1210 dns_result_totext(dns_result
));
1211 dns_db_detachnode(db
, &nodep
);
1214 isc_entropy_detach(&ectx
);
1215 isc_mem_destroy(&mctx
);
1216 return(T_UNRESOLVED
);
1219 dns_result
= dns_db_addrdataset(db
, nodep
, nversionp
, 0,
1220 &added_rdataset
, 0, NULL
);
1221 if (dns_result
!= ISC_R_SUCCESS
) {
1222 t_info("dns_db_addrdataset failed %s\n",
1223 dns_result_totext(dns_result
));
1224 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1225 dns_db_detachnode(db
, &nodep
);
1228 isc_entropy_detach(&ectx
);
1229 isc_mem_destroy(&mctx
);
1230 return(T_UNRESOLVED
);
1234 * Close and commit the version.
1236 dns_db_closeversion(db
, &nversionp
, ISC_TRUE
);
1237 dns_db_detachnode(db
, &nodep
);
1238 if (dns_rdataset_isassociated(&added_rdataset
))
1239 dns_rdataset_disassociate(&added_rdataset
);
1243 * Open a new version and find the data we added.
1245 dns_fixedname_init(&dns_foundname
);
1246 dns_rdataset_init(&found_rdataset
);
1249 dns_db_newversion(db
, &nversionp
);
1252 * Find the recently added name and rdata.
1254 dns_result
= dns_db_find(db
, dns_fixedname_name(&dns_newname
),
1255 nversionp
, rdatatype
, 0, 0, &found_nodep
,
1256 dns_fixedname_name(&dns_foundname
),
1257 &found_rdataset
, NULL
);
1259 if (dns_result
!= ISC_R_SUCCESS
) {
1260 /* XXXWPK - NXRRSET ??? reference counts ??? */
1261 t_info("dns_db_find failed %s\n",
1262 dns_result_totext(dns_result
));
1263 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1264 dns_db_detachnode(db
, &found_nodep
);
1265 if (dns_rdataset_isassociated(&found_rdataset
))
1266 dns_rdataset_disassociate(&found_rdataset
);
1269 isc_entropy_detach(&ectx
);
1270 isc_mem_destroy(&mctx
);
1274 dns_result
= dns_rdataset_first(&found_rdataset
);
1275 if (dns_result
!= ISC_R_SUCCESS
) {
1276 t_info("dns_rdataset_first failed %s\n",
1277 dns_result_totext(dns_result
));
1278 dns_db_detachnode(db
, &nodep
);
1279 if (dns_rdataset_isassociated(&found_rdataset
))
1280 dns_rdataset_disassociate(&found_rdataset
);
1281 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1284 isc_entropy_detach(&ectx
);
1285 isc_mem_destroy(&mctx
);
1290 * Now make sure its what we expect.
1292 dns_rdata_init(&found_rdata
);
1293 dns_rdataset_current(&found_rdataset
, &found_rdata
);
1294 rval
= dns_rdata_compare(&added_rdata
, &found_rdata
);
1298 t_info("dns_rdata_compare returned %d\n", rval
);
1303 * Don't need these now.
1305 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1306 if (dns_rdataset_isassociated(&found_rdataset
))
1307 dns_rdataset_disassociate(&found_rdataset
);
1308 dns_db_detachnode(db
, &found_nodep
);
1311 isc_entropy_detach(&ectx
);
1312 isc_mem_destroy(&mctx
);
1321 t_assert("dns_db_newversion", 9, T_REQUIRED
, "%s", a9
);
1322 result
= t_eval("dns_db_newversion_data", t_dns_db_newversion
, 7);
1326 static const char *a10
=
1327 "When versionp points to a read-write version and commit is "
1328 "ISC_TRUE, a call to dns_db_closeversion(db, versionp, commit) "
1329 "causes all changes made in the version to take effect, "
1330 "and returns ISC_R_SUCCESS.";
1333 t_dns_db_closeversion_1(char **av
) {
1341 char *existing_name
;
1342 char *existing_type
;
1349 isc_result_t dns_result
;
1350 isc_result_t isc_result
;
1352 isc_entropy_t
*ectx
;
1353 dns_dbnode_t
*nodep
;
1354 isc_textregion_t textregion
;
1355 isc_buffer_t name_buffer
;
1356 dns_fixedname_t dns_newname
;
1357 dns_fixedname_t dns_foundname
;
1358 dns_fixedname_t dns_existingname
;
1359 dns_rdata_t added_rdata
= DNS_RDATA_INIT
;
1360 const char * added_rdata_data
;
1361 dns_rdataset_t added_rdataset
;
1362 dns_rdata_t found_rdata
= DNS_RDATA_INIT
;
1363 dns_rdataset_t found_rdataset
;
1364 dns_rdatatype_t new_rdatatype
;
1365 dns_rdatatype_t existing_rdatatype
;
1366 dns_rdataclass_t rdataclass
;
1367 dns_dbversion_t
*nversionp
;
1368 dns_dbversion_t
*cversionp
;
1369 dns_rdatalist_t rdatalist
;
1371 filename
= T_ARG(0);
1376 new_name
= T_ARG(5);
1377 new_type
= T_ARG(6);
1378 existing_name
= T_ARG(7);
1379 existing_type
= T_ARG(8);
1387 * Open a new version, add some data,
1388 * remove some data, close with commit, open the current
1389 * version and check that changes are present.
1392 t_info("testing using file %s and name %s\n", filename
, new_name
);
1394 isc_result
= isc_mem_create(0, 0, &mctx
);
1395 if (isc_result
!= ISC_R_SUCCESS
) {
1396 t_info("isc_mem_create failed %s\n",
1397 isc_result_totext(isc_result
));
1398 return(T_UNRESOLVED
);
1401 isc_result
= isc_entropy_create(mctx
, &ectx
);
1402 if (isc_result
!= ISC_R_SUCCESS
) {
1403 t_info("isc_entropy_create failed %s\n",
1404 isc_result_totext(isc_result
));
1405 isc_mem_destroy(&mctx
);
1406 return(T_UNRESOLVED
);
1409 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
1410 if (isc_result
!= ISC_R_SUCCESS
) {
1411 t_info("isc_hash_create failed %s\n",
1412 isc_result_totext(isc_result
));
1413 isc_entropy_detach(&ectx
);
1414 isc_mem_destroy(&mctx
);
1415 return(T_UNRESOLVED
);
1418 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
1419 if (dns_result
!= ISC_R_SUCCESS
) {
1421 isc_entropy_detach(&ectx
);
1422 isc_mem_destroy(&mctx
);
1423 return(T_UNRESOLVED
);
1426 dns_result
= dns_db_load(db
, filename
);
1427 if (dns_result
!= ISC_R_SUCCESS
) {
1428 t_info("dns_db_load returned %s\n",
1429 dns_result_totext(dns_result
));
1432 isc_entropy_detach(&ectx
);
1433 isc_mem_destroy(&mctx
);
1434 return(T_UNRESOLVED
);
1438 * Remove all rdata for an existing name.
1441 dns_fixedname_init(&dns_existingname
);
1442 len
= strlen(existing_name
);
1443 isc_buffer_init(&name_buffer
, existing_name
, len
);
1444 isc_buffer_add(&name_buffer
, len
);
1445 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_existingname
),
1446 &name_buffer
, NULL
, 0, NULL
);
1447 if (dns_result
!= ISC_R_SUCCESS
) {
1448 t_info("dns_name_fromtext failed %s\n",
1449 dns_result_totext(dns_result
));
1452 isc_entropy_detach(&ectx
);
1453 isc_mem_destroy(&mctx
);
1454 return(T_UNRESOLVED
);
1457 textregion
.base
= existing_type
;
1458 textregion
.length
= strlen(existing_type
);
1459 dns_result
= dns_rdatatype_fromtext(&existing_rdatatype
, &textregion
);
1460 if (dns_result
!= ISC_R_SUCCESS
) {
1461 t_info("dns_rdatatype_fromtext %s failed %s\n",
1463 dns_result_totext(dns_result
));
1464 dns_db_detachnode(db
, &nodep
);
1467 isc_entropy_detach(&ectx
);
1468 isc_mem_destroy(&mctx
);
1469 return(T_UNRESOLVED
);
1473 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_existingname
),
1475 if (dns_result
!= ISC_R_SUCCESS
) {
1476 t_info("dns_db_findnode %s\n",
1477 dns_result_totext(dns_result
));
1480 isc_entropy_detach(&ectx
);
1481 isc_mem_destroy(&mctx
);
1482 return(T_UNRESOLVED
);
1485 /* open a new version */
1487 dns_result
= dns_db_newversion(db
, &nversionp
);
1488 if (dns_result
!= ISC_R_SUCCESS
) {
1489 t_info("dns_db_newversion failed %s\n",
1490 dns_result_totext(dns_result
));
1491 dns_db_detachnode(db
, &nodep
);
1494 isc_entropy_detach(&ectx
);
1495 isc_mem_destroy(&mctx
);
1496 return(T_UNRESOLVED
);
1499 dns_result
= dns_db_deleterdataset(db
, nodep
, nversionp
,
1500 existing_rdatatype
, 0);
1501 if (dns_result
!= ISC_R_SUCCESS
) {
1502 t_info("dns_db_deleterdataset failed %s\n",
1503 dns_result_totext(dns_result
));
1504 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1505 dns_db_detachnode(db
, &nodep
);
1508 isc_entropy_detach(&ectx
);
1509 isc_mem_destroy(&mctx
);
1510 return(T_UNRESOLVED
);
1514 * add a new name and associate some rdata with it
1517 dns_db_detachnode(db
, &nodep
);
1520 dns_fixedname_init(&dns_newname
);
1521 len
= strlen(new_name
);
1522 isc_buffer_init(&name_buffer
, new_name
, len
);
1523 isc_buffer_add(&name_buffer
, len
);
1524 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_newname
),
1525 &name_buffer
, NULL
, 0, NULL
);
1526 if (dns_result
!= ISC_R_SUCCESS
) {
1527 t_info("dns_name_fromtext failed %s\n",
1528 dns_result_totext(dns_result
));
1529 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1532 isc_entropy_detach(&ectx
);
1533 isc_mem_destroy(&mctx
);
1534 return(T_UNRESOLVED
);
1537 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_newname
),
1539 if (dns_result
!= ISC_R_SUCCESS
) {
1540 t_info("dns_db_findnode failed %s\n",
1541 dns_result_totext(dns_result
));
1542 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1545 isc_entropy_detach(&ectx
);
1546 isc_mem_destroy(&mctx
);
1547 return(T_UNRESOLVED
);
1551 * associate some rdata with the new name
1554 textregion
.base
= new_type
;
1555 textregion
.length
= strlen(new_type
);
1556 dns_result
= dns_rdatatype_fromtext(&new_rdatatype
, &textregion
);
1557 if (dns_result
!= ISC_R_SUCCESS
) {
1558 t_info("dns_rdatatype_fromtext %s failed %s\n",
1560 dns_result_totext(dns_result
));
1561 dns_db_detachnode(db
, &nodep
);
1564 isc_entropy_detach(&ectx
);
1565 isc_mem_destroy(&mctx
);
1566 return(T_UNRESOLVED
);
1569 textregion
.base
= class;
1570 textregion
.length
= strlen(class);
1571 dns_result
= dns_rdataclass_fromtext(&rdataclass
, &textregion
);
1572 if (dns_result
!= ISC_R_SUCCESS
) {
1573 t_info("dns_rdataclass_fromtext failed %s\n",
1574 dns_result_totext(dns_result
));
1575 dns_db_detachnode(db
, &nodep
);
1578 isc_entropy_detach(&ectx
);
1579 isc_mem_destroy(&mctx
);
1580 return(T_UNRESOLVED
);
1583 dns_rdata_init(&added_rdata
);
1584 added_rdata_data
= "\x10\x00\x00\x01";
1585 DE_CONST(added_rdata_data
, added_rdata
.data
);
1586 added_rdata
.length
= 4;
1587 added_rdata
.rdclass
= rdataclass
;
1588 added_rdata
.type
= new_rdatatype
;
1590 dns_rdataset_init(&added_rdataset
);
1591 rdatalist
.type
= new_rdatatype
;
1592 rdatalist
.covers
= 0;
1593 rdatalist
.rdclass
= rdataclass
;
1595 ISC_LIST_INIT(rdatalist
.rdata
);
1596 ISC_LIST_APPEND(rdatalist
.rdata
, &added_rdata
, link
);
1598 dns_result
= dns_rdatalist_tordataset(&rdatalist
, &added_rdataset
);
1599 if (dns_result
!= ISC_R_SUCCESS
) {
1600 t_info("dns_rdatalist_tordataset failed %s\n",
1601 dns_result_totext(dns_result
));
1602 dns_db_detachnode(db
, &nodep
);
1605 isc_entropy_detach(&ectx
);
1606 isc_mem_destroy(&mctx
);
1607 return(T_UNRESOLVED
);
1610 dns_result
= dns_db_addrdataset(db
, nodep
, nversionp
, 0,
1611 &added_rdataset
, 0, NULL
);
1612 if (dns_result
!= ISC_R_SUCCESS
) {
1613 t_info("dns_db_addrdataset failed %s\n",
1614 dns_result_totext(dns_result
));
1615 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1616 dns_db_detachnode(db
, &nodep
);
1619 isc_entropy_detach(&ectx
);
1620 isc_mem_destroy(&mctx
);
1621 return(T_UNRESOLVED
);
1624 /* close and commit the version */
1625 dns_db_closeversion(db
, &nversionp
, ISC_TRUE
);
1626 dns_db_detachnode(db
, &nodep
);
1629 /* open the current version and check changes */
1630 dns_fixedname_init(&dns_foundname
);
1631 dns_rdataset_init(&found_rdataset
);
1633 dns_db_currentversion(db
, &cversionp
);
1635 /* find the recently added name and rdata */
1636 dns_result
= dns_db_find(db
,
1637 dns_fixedname_name(&dns_newname
),
1643 dns_fixedname_name(&dns_foundname
),
1644 &found_rdataset
, NULL
);
1646 if (dns_result
!= ISC_R_SUCCESS
) {
1647 /* XXXWPK NXRRSET ??? reference counting ??? */
1648 t_info("dns_db_find failed %s\n",
1649 dns_result_totext(dns_result
));
1650 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
1651 dns_db_detachnode(db
, &nodep
);
1652 if (dns_rdataset_isassociated(&found_rdataset
))
1653 dns_rdataset_disassociate(&found_rdataset
);
1656 isc_entropy_detach(&ectx
);
1657 isc_mem_destroy(&mctx
);
1661 dns_result
= dns_rdataset_first(&found_rdataset
);
1662 if (dns_result
!= ISC_R_SUCCESS
) {
1663 t_info("dns_rdataset_first failed %s\n",
1664 dns_result_totext(dns_result
));
1665 dns_db_detachnode(db
, &nodep
);
1666 if (dns_rdataset_isassociated(&found_rdataset
))
1667 dns_rdataset_disassociate(&found_rdataset
);
1668 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
1671 isc_entropy_detach(&ectx
);
1672 isc_mem_destroy(&mctx
);
1677 * Now make sure its what we expect.
1679 dns_rdata_init(&found_rdata
);
1680 dns_rdataset_current(&found_rdataset
, &found_rdata
);
1681 rval
= dns_rdata_compare(&added_rdata
, &found_rdata
);
1683 t_info("dns_rdata_compare returned %d\n", rval
);
1688 * Now check the rdata deletion.
1691 if (dns_rdataset_isassociated(&found_rdataset
))
1692 dns_rdataset_disassociate(&found_rdataset
);
1693 dns_rdataset_init(&found_rdataset
);
1694 dns_db_detachnode(db
, &nodep
);
1696 dns_fixedname_init(&dns_foundname
);
1698 dns_result
= dns_db_find(db
, dns_fixedname_name(&dns_existingname
),
1699 cversionp
, existing_rdatatype
,
1701 dns_fixedname_name(&dns_foundname
),
1702 &found_rdataset
, NULL
);
1705 if ((dns_result
!= ISC_R_NOTFOUND
) && (dns_result
!= DNS_R_NXDOMAIN
)) {
1706 dns_rdataset_disassociate(&found_rdataset
);
1707 dns_db_detachnode(db
, &nodep
);
1708 t_info("dns_db_find %s returned %s\n", existing_name
,
1709 dns_result_totext(dns_result
));
1713 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
1716 isc_entropy_detach(&ectx
);
1717 isc_mem_destroy(&mctx
);
1731 t_assert("dns_db_closeversion", 10, T_REQUIRED
, "%s", a10
);
1732 result
= t_eval("dns_db_closeversion_1_data",
1733 t_dns_db_closeversion_1
, 9);
1737 static const char *a11
=
1738 "When versionp points to a read-write version and commit is "
1739 "ISC_FALSE, a call to dns_db_closeversion(db, versionp, commit) "
1740 "causes all changes made in the version to to be rolled back, "
1741 "and returns ISC_R_SUCCESS.";
1744 t_dns_db_closeversion_2(char **av
) {
1752 char *existing_name
;
1753 char *existing_type
;
1760 isc_result_t dns_result
;
1761 isc_result_t isc_result
;
1763 isc_entropy_t
*ectx
;
1764 dns_dbnode_t
*nodep
;
1765 isc_textregion_t textregion
;
1766 isc_buffer_t name_buffer
;
1767 dns_fixedname_t dns_newname
;
1768 dns_fixedname_t dns_foundname
;
1769 dns_fixedname_t dns_existingname
;
1770 dns_rdata_t added_rdata
= DNS_RDATA_INIT
;
1771 const char * added_rdata_data
;
1772 dns_rdataset_t added_rdataset
;
1773 dns_rdata_t found_rdata
= DNS_RDATA_INIT
;
1774 dns_rdataset_t found_rdataset
;
1775 dns_rdatatype_t new_rdatatype
;
1776 dns_rdatatype_t existing_rdatatype
;
1777 dns_rdataclass_t rdataclass
;
1778 dns_dbversion_t
*nversionp
;
1779 dns_dbversion_t
*cversionp
;
1780 dns_rdatalist_t rdatalist
;
1782 filename
= T_ARG(0);
1787 new_name
= T_ARG(5);
1788 new_type
= T_ARG(6);
1789 existing_name
= T_ARG(7);
1790 existing_type
= T_ARG(8);
1798 * Open a new version, add some data,
1799 * remove some data, close with commit, open the current
1800 * version and check that changes are present.
1803 t_info("testing using file %s and name %s\n", filename
, new_name
);
1805 isc_result
= isc_mem_create(0, 0, &mctx
);
1806 if (isc_result
!= ISC_R_SUCCESS
) {
1807 t_info("isc_mem_create failed %s\n",
1808 isc_result_totext(isc_result
));
1809 return(T_UNRESOLVED
);
1812 isc_result
= isc_entropy_create(mctx
, &ectx
);
1813 if (isc_result
!= ISC_R_SUCCESS
) {
1814 t_info("isc_entropy_create failed %s\n",
1815 isc_result_totext(isc_result
));
1816 isc_mem_destroy(&mctx
);
1817 return(T_UNRESOLVED
);
1820 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
1821 if (isc_result
!= ISC_R_SUCCESS
) {
1822 t_info("isc_hash_create failed %s\n",
1823 isc_result_totext(isc_result
));
1824 isc_entropy_detach(&ectx
);
1825 isc_mem_destroy(&mctx
);
1826 return(T_UNRESOLVED
);
1829 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
1830 if (dns_result
!= ISC_R_SUCCESS
) {
1832 isc_entropy_detach(&ectx
);
1833 isc_mem_destroy(&mctx
);
1834 return(T_UNRESOLVED
);
1837 dns_result
= dns_db_load(db
, filename
);
1838 if (dns_result
!= ISC_R_SUCCESS
) {
1839 t_info("dns_db_load returned %s\n",
1840 dns_result_totext(dns_result
));
1843 isc_entropy_detach(&ectx
);
1844 isc_mem_destroy(&mctx
);
1845 return(T_UNRESOLVED
);
1849 * Remove all rdata for an existing name.
1852 dns_fixedname_init(&dns_existingname
);
1853 len
= strlen(existing_name
);
1854 isc_buffer_init(&name_buffer
, existing_name
, len
);
1855 isc_buffer_add(&name_buffer
, len
);
1856 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_existingname
),
1857 &name_buffer
, NULL
, 0, NULL
);
1858 if (dns_result
!= ISC_R_SUCCESS
) {
1859 t_info("dns_name_fromtext failed %s\n",
1860 dns_result_totext(dns_result
));
1863 isc_entropy_detach(&ectx
);
1864 isc_mem_destroy(&mctx
);
1865 return(T_UNRESOLVED
);
1868 textregion
.base
= existing_type
;
1869 textregion
.length
= strlen(existing_type
);
1870 dns_result
= dns_rdatatype_fromtext(&existing_rdatatype
, &textregion
);
1871 if (dns_result
!= ISC_R_SUCCESS
) {
1872 t_info("dns_rdatatype_fromtext %s failed %s\n",
1874 dns_result_totext(dns_result
));
1875 dns_db_detachnode(db
, &nodep
);
1878 isc_entropy_detach(&ectx
);
1879 isc_mem_destroy(&mctx
);
1880 return(T_UNRESOLVED
);
1884 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_existingname
),
1886 if (dns_result
!= ISC_R_SUCCESS
) {
1887 t_info("dns_db_findnode %s\n",
1888 dns_result_totext(dns_result
));
1891 isc_entropy_detach(&ectx
);
1892 isc_mem_destroy(&mctx
);
1893 return(T_UNRESOLVED
);
1897 * Open a new version.
1900 dns_result
= dns_db_newversion(db
, &nversionp
);
1901 if (dns_result
!= ISC_R_SUCCESS
) {
1902 t_info("dns_db_newversion failed %s\n",
1903 dns_result_totext(dns_result
));
1904 dns_db_detachnode(db
, &nodep
);
1907 isc_entropy_detach(&ectx
);
1908 isc_mem_destroy(&mctx
);
1909 return(T_UNRESOLVED
);
1912 dns_result
= dns_db_deleterdataset(db
, nodep
, nversionp
,
1913 existing_rdatatype
, 0);
1914 if (dns_result
!= ISC_R_SUCCESS
) {
1915 t_info("dns_db_deleterdataset failed %s\n",
1916 dns_result_totext(dns_result
));
1917 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1918 dns_db_detachnode(db
, &nodep
);
1921 isc_entropy_detach(&ectx
);
1922 isc_mem_destroy(&mctx
);
1923 return(T_UNRESOLVED
);
1927 * add a new name and associate some rdata with it
1930 dns_db_detachnode(db
, &nodep
);
1933 dns_fixedname_init(&dns_newname
);
1934 len
= strlen(new_name
);
1935 isc_buffer_init(&name_buffer
, new_name
, len
);
1936 isc_buffer_add(&name_buffer
, len
);
1937 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_newname
),
1938 &name_buffer
, NULL
, 0, NULL
);
1939 if (dns_result
!= ISC_R_SUCCESS
) {
1940 t_info("dns_name_fromtext failed %s\n",
1941 dns_result_totext(dns_result
));
1942 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1945 isc_entropy_detach(&ectx
);
1946 isc_mem_destroy(&mctx
);
1947 return(T_UNRESOLVED
);
1950 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_newname
),
1952 if (dns_result
!= ISC_R_SUCCESS
) {
1953 t_info("dns_db_findnode failed %s\n",
1954 dns_result_totext(dns_result
));
1955 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
1958 isc_entropy_detach(&ectx
);
1959 isc_mem_destroy(&mctx
);
1960 return(T_UNRESOLVED
);
1963 textregion
.base
= new_type
;
1964 textregion
.length
= strlen(new_type
);
1965 dns_result
= dns_rdatatype_fromtext(&new_rdatatype
, &textregion
);
1966 if (dns_result
!= ISC_R_SUCCESS
) {
1967 t_info("dns_rdatatype_fromtext %s failed %s\n",
1968 new_type
, dns_result_totext(dns_result
));
1969 dns_db_detachnode(db
, &nodep
);
1972 isc_entropy_detach(&ectx
);
1973 isc_mem_destroy(&mctx
);
1974 return(T_UNRESOLVED
);
1977 textregion
.base
= class;
1978 textregion
.length
= strlen(class);
1979 dns_result
= dns_rdataclass_fromtext(&rdataclass
, &textregion
);
1980 if (dns_result
!= ISC_R_SUCCESS
) {
1981 t_info("dns_rdataclass_fromtext failed %s\n",
1982 dns_result_totext(dns_result
));
1983 dns_db_detachnode(db
, &nodep
);
1986 isc_entropy_detach(&ectx
);
1987 isc_mem_destroy(&mctx
);
1988 return(T_UNRESOLVED
);
1991 dns_rdata_init(&added_rdata
);
1992 added_rdata_data
= "\x10\x00\x00\x01";
1993 DE_CONST(added_rdata_data
, added_rdata
.data
);
1994 added_rdata
.length
= 4;
1995 added_rdata
.rdclass
= rdataclass
;
1996 added_rdata
.type
= new_rdatatype
;
1998 dns_rdataset_init(&added_rdataset
);
1999 rdatalist
.type
= new_rdatatype
;
2000 rdatalist
.covers
= 0;
2001 rdatalist
.rdclass
= rdataclass
;
2003 ISC_LIST_INIT(rdatalist
.rdata
);
2004 ISC_LIST_APPEND(rdatalist
.rdata
, &added_rdata
, link
);
2006 dns_result
= dns_rdatalist_tordataset(&rdatalist
, &added_rdataset
);
2007 if (dns_result
!= ISC_R_SUCCESS
) {
2008 t_info("dns_rdatalist_tordataset failed %s\n",
2009 dns_result_totext(dns_result
));
2010 dns_db_detachnode(db
, &nodep
);
2013 isc_entropy_detach(&ectx
);
2014 isc_mem_destroy(&mctx
);
2015 return(T_UNRESOLVED
);
2018 dns_result
= dns_db_addrdataset(db
, nodep
, nversionp
, 0,
2019 &added_rdataset
, 0, NULL
);
2020 if (dns_result
!= ISC_R_SUCCESS
) {
2021 t_info("dns_db_addrdataset failed %s\n",
2022 dns_result_totext(dns_result
));
2023 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
2024 dns_db_detachnode(db
, &nodep
);
2027 isc_entropy_detach(&ectx
);
2028 isc_mem_destroy(&mctx
);
2029 return(T_UNRESOLVED
);
2033 * Check that our changes took.
2035 dns_db_detachnode(db
, &nodep
);
2037 dns_fixedname_init(&dns_foundname
);
2038 dns_rdataset_init(&found_rdataset
);
2041 * Find the recently added name and rdata.
2043 dns_result
= dns_db_find(db
, dns_fixedname_name(&dns_newname
),
2044 nversionp
, new_rdatatype
, 0, 0, &nodep
,
2045 dns_fixedname_name(&dns_foundname
),
2046 &found_rdataset
, NULL
);
2048 if ((dns_result
== ISC_R_NOTFOUND
) ||
2049 (dns_result
== DNS_R_NXDOMAIN
) ||
2050 (dns_result
== DNS_R_NXRRSET
)) {
2052 t_info("dns_db_find failed %s\n",
2053 dns_result_totext(dns_result
));
2054 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
2055 dns_db_detachnode(db
, &nodep
);
2056 if (dns_rdataset_isassociated(&found_rdataset
))
2057 dns_rdataset_disassociate(&found_rdataset
);
2060 isc_entropy_detach(&ectx
);
2061 isc_mem_destroy(&mctx
);
2065 dns_result
= dns_rdataset_first(&found_rdataset
);
2066 if (dns_result
!= ISC_R_SUCCESS
) {
2067 t_info("dns_rdataset_first failed %s\n",
2068 dns_result_totext(dns_result
));
2069 dns_db_detachnode(db
, &nodep
);
2070 if (dns_rdataset_isassociated(&found_rdataset
))
2071 dns_rdataset_disassociate(&found_rdataset
);
2072 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
2075 isc_entropy_detach(&ectx
);
2076 isc_mem_destroy(&mctx
);
2081 * Now make sure its what we expect.
2083 dns_rdata_init(&found_rdata
);
2084 dns_rdataset_current(&found_rdataset
, &found_rdata
);
2085 rval
= dns_rdata_compare(&added_rdata
, &found_rdata
);
2087 t_info("dns_rdata_compare returned %d\n", rval
);
2092 * Now check the rdata deletion.
2094 if (dns_rdataset_isassociated(&found_rdataset
))
2095 dns_rdataset_disassociate(&found_rdataset
);
2096 dns_rdataset_init(&found_rdataset
);
2097 dns_db_detachnode(db
, &nodep
);
2099 dns_fixedname_init(&dns_foundname
);
2101 dns_result
= dns_db_find(db
,
2102 dns_fixedname_name(&dns_existingname
),
2108 dns_fixedname_name(&dns_foundname
),
2109 &found_rdataset
, NULL
);
2112 if ((dns_result
!= ISC_R_NOTFOUND
) && (dns_result
!= DNS_R_NXDOMAIN
)) {
2113 t_info("dns_db_find %s returned %s\n", existing_name
,
2114 dns_result_totext(dns_result
));
2115 if (dns_rdataset_isassociated(&found_rdataset
))
2116 dns_rdataset_disassociate(&found_rdataset
);
2117 dns_db_detachnode(db
, &nodep
);
2123 * Close the version without a commit.
2125 dns_db_closeversion(db
, &nversionp
, ISC_FALSE
);
2128 * Open the current version and check changes.
2130 dns_fixedname_init(&dns_foundname
);
2131 dns_rdataset_init(&found_rdataset
);
2133 dns_db_currentversion(db
, &cversionp
);
2136 * Find the recently added name and rdata.
2138 dns_result
= dns_db_find(db
,
2139 dns_fixedname_name(&dns_newname
),
2145 dns_fixedname_name(&dns_foundname
),
2146 &found_rdataset
, NULL
);
2148 if ((dns_result
!= ISC_R_NOTFOUND
) && (dns_result
!= DNS_R_NXDOMAIN
)) {
2149 t_info("dns_db_find %s returned %s\n", new_name
,
2150 dns_result_totext(dns_result
));
2151 dns_rdataset_disassociate(&found_rdataset
);
2152 dns_db_detachnode(db
, &nodep
);
2153 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
2156 isc_entropy_detach(&ectx
);
2157 isc_mem_destroy(&mctx
);
2162 * Now check the rdata deletion.
2165 dns_rdataset_init(&found_rdataset
);
2166 dns_fixedname_init(&dns_foundname
);
2168 dns_result
= dns_db_find(db
, dns_fixedname_name(&dns_existingname
),
2169 cversionp
, existing_rdatatype
, 0, 0,
2170 &nodep
, dns_fixedname_name(&dns_foundname
),
2171 &found_rdataset
, NULL
);
2174 if ((dns_result
== ISC_R_NOTFOUND
) ||
2175 (dns_result
== DNS_R_NXDOMAIN
) ||
2176 (dns_result
== DNS_R_NXRRSET
)) {
2178 t_info("dns_db_find %s returned %s\n", existing_name
,
2179 dns_result_totext(dns_result
));
2180 dns_rdataset_disassociate(&found_rdataset
);
2181 dns_db_detachnode(db
, &nodep
);
2185 dns_db_detachnode(db
, &nodep
);
2186 dns_rdataset_disassociate(&found_rdataset
);
2187 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
2190 isc_entropy_detach(&ectx
);
2191 isc_mem_destroy(&mctx
);
2205 t_assert("dns_db_closeversion", 11, T_REQUIRED
, "%s", a11
);
2206 result
= t_eval("dns_db_closeversion_2_data",
2207 t_dns_db_closeversion_2
, 9);
2211 static const char *a12
=
2212 "A call to dns_db_expirenode() marks as stale all records at node "
2213 "which expire at or before 'now'. If 'now' is zero, then the current "
2214 "time will be used.";
2217 t_dns_db_expirenode(char **av
) {
2222 char *existing_name
;
2225 char *exp_find_result
;
2230 isc_result_t dns_result
;
2231 isc_result_t exp_result
;
2232 isc_result_t isc_result
;
2234 isc_entropy_t
*ectx
;
2235 dns_dbnode_t
*nodep
;
2236 isc_buffer_t name_buffer
;
2237 dns_fixedname_t dns_foundname
;
2238 dns_fixedname_t dns_existingname
;
2239 isc_stdtime_t node_expire_time
;
2240 isc_stdtime_t find_expire_time
;
2242 dns_rdataset_t rdataset
;
2244 filename
= T_ARG(0);
2248 existing_name
= T_ARG(4);
2249 node_xtime
= T_ARG(5);
2250 find_xtime
= T_ARG(6);
2251 exp_find_result
= T_ARG(7);
2256 * Find a node, mark it as stale, do a dns_db_find on the name and
2257 * expect it to fail.
2260 t_info("testing using file %s and name %s\n", filename
, existing_name
);
2262 node_expire_time
= (isc_stdtime_t
) strtol(node_xtime
, NULL
, 10);
2263 find_expire_time
= (isc_stdtime_t
) strtol(find_xtime
, NULL
, 10);
2264 exp_result
= t_dns_result_fromtext(exp_find_result
);
2266 isc_stdtime_get(&now
);
2268 dns_fixedname_init(&dns_existingname
);
2269 len
= strlen(existing_name
);
2270 isc_buffer_init(&name_buffer
, existing_name
, len
);
2271 isc_buffer_add(&name_buffer
, len
);
2272 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_existingname
),
2273 &name_buffer
, NULL
, 0, NULL
);
2274 if (dns_result
!= ISC_R_SUCCESS
) {
2275 t_info("dns_name_fromtext failed %s\n",
2276 dns_result_totext(dns_result
));
2277 return(T_UNRESOLVED
);
2280 isc_result
= isc_mem_create(0, 0, &mctx
);
2281 if (isc_result
!= ISC_R_SUCCESS
) {
2282 t_info("isc_mem_create failed %s\n",
2283 isc_result_totext(isc_result
));
2284 return(T_UNRESOLVED
);
2287 isc_result
= isc_entropy_create(mctx
, &ectx
);
2288 if (isc_result
!= ISC_R_SUCCESS
) {
2289 t_info("isc_entropy_create failed %s\n",
2290 isc_result_totext(isc_result
));
2291 isc_mem_destroy(&mctx
);
2292 return(T_UNRESOLVED
);
2295 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
2296 if (isc_result
!= ISC_R_SUCCESS
) {
2297 t_info("isc_hash_create failed %s\n",
2298 isc_result_totext(isc_result
));
2299 isc_entropy_detach(&ectx
);
2300 isc_mem_destroy(&mctx
);
2301 return(T_UNRESOLVED
);
2305 dns_result
= t_create(db_type
, origin
, class, "cache", mctx
, &db
);
2306 if (dns_result
!= ISC_R_SUCCESS
) {
2308 isc_entropy_detach(&ectx
);
2309 isc_mem_destroy(&mctx
);
2310 return(T_UNRESOLVED
);
2313 dns_result
= dns_db_load(db
, filename
);
2314 if (dns_result
!= ISC_R_SUCCESS
) {
2315 t_info("dns_db_load returned %s\n",
2316 dns_result_totext(dns_result
));
2319 isc_entropy_detach(&ectx
);
2320 isc_mem_destroy(&mctx
);
2321 return(T_UNRESOLVED
);
2327 * Check that the node is there.
2329 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_existingname
),
2331 if (dns_result
!= ISC_R_SUCCESS
) {
2332 t_info("unable to find %s\n", existing_name
);
2335 isc_entropy_detach(&ectx
);
2336 isc_mem_destroy(&mctx
);
2337 return(T_UNRESOLVED
);
2343 if (node_expire_time
!= 0)
2344 node_expire_time
+= now
;
2346 dns_result
= dns_db_expirenode(db
, nodep
, node_expire_time
);
2347 if (dns_result
!= ISC_R_SUCCESS
) {
2348 t_info("dns_db_expirenode failed %s\n",
2349 dns_result_totext(dns_result
));
2350 dns_db_detachnode(db
, &nodep
);
2353 isc_entropy_detach(&ectx
);
2354 isc_mem_destroy(&mctx
);
2358 dns_fixedname_init(&dns_foundname
);
2359 dns_rdataset_init(&rdataset
);
2360 dns_db_detachnode(db
, &nodep
);
2363 if (find_expire_time
!= 0)
2364 find_expire_time
+= now
;
2366 dns_result
= dns_db_find(db
,
2367 dns_fixedname_name(&dns_existingname
),
2373 dns_fixedname_name(&dns_foundname
),
2376 if (dns_result
== exp_result
) {
2379 t_info("dns_db_find %s returned %s\n", existing_name
,
2380 dns_result_totext(dns_result
));
2384 if ((dns_result
!= ISC_R_NOTFOUND
) &&
2385 (dns_result
!= DNS_R_NXDOMAIN
) &&
2386 (dns_result
!= DNS_R_NXRRSET
)) {
2389 * Don't need to disassociate the rdataset because
2390 * we're searching with dns_rdatatype_any.
2392 dns_db_detachnode(db
, &nodep
);
2398 isc_entropy_detach(&ectx
);
2399 isc_mem_destroy(&mctx
);
2408 t_assert("dns_db_expirenode", 12, T_REQUIRED
, "%s", a12
);
2409 result
= t_eval("dns_db_expirenode_data", t_dns_db_expirenode
, 8);
2413 static const char *a13
=
2414 "If the node name exists, then a call to "
2415 "dns_db_findnode(db, name, ISC_FALSE, nodep) initializes nodep "
2416 "to point to the node and returns ISC_R_SUCCESS, otherwise "
2417 "it returns ISC_R_NOTFOUND.";
2420 t_dns_db_findnode_1(char **av
) {
2428 char *expected_result
;
2433 isc_result_t dns_result
;
2434 isc_result_t isc_result
;
2436 isc_entropy_t
*ectx
;
2437 dns_dbnode_t
*nodep
;
2438 isc_buffer_t name_buffer
;
2439 dns_rdataset_t rdataset
;
2440 dns_rdatatype_t rdatatype
;
2441 isc_textregion_t textregion
;
2442 dns_fixedname_t dns_name
;
2443 dns_dbversion_t
*cversionp
;
2444 isc_result_t exp_result
;
2446 filename
= T_ARG(0);
2451 find_name
= T_ARG(5);
2452 find_type
= T_ARG(6);
2453 expected_result
= T_ARG(7);
2459 t_info("testing using file %s and name %s\n", filename
, find_name
);
2461 exp_result
= t_dns_result_fromtext(expected_result
);
2463 textregion
.base
= find_type
;
2464 textregion
.length
= strlen(find_type
);
2465 dns_result
= dns_rdatatype_fromtext(&rdatatype
, &textregion
);
2466 if (dns_result
!= ISC_R_SUCCESS
) {
2467 t_info("dns_rdatatype_fromtext %s failed %s\n",
2469 dns_result_totext(dns_result
));
2470 return(T_UNRESOLVED
);
2473 isc_result
= isc_mem_create(0, 0, &mctx
);
2474 if (isc_result
!= ISC_R_SUCCESS
) {
2475 t_info("isc_mem_create failed %s\n",
2476 isc_result_totext(isc_result
));
2477 return(T_UNRESOLVED
);
2480 isc_result
= isc_entropy_create(mctx
, &ectx
);
2481 if (isc_result
!= ISC_R_SUCCESS
) {
2482 t_info("isc_entropy_create failed %s\n",
2483 isc_result_totext(isc_result
));
2484 isc_mem_destroy(&mctx
);
2485 return(T_UNRESOLVED
);
2488 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
2489 if (isc_result
!= ISC_R_SUCCESS
) {
2490 t_info("isc_hash_create failed %s\n",
2491 isc_result_totext(isc_result
));
2492 isc_mem_destroy(&mctx
);
2493 return(T_UNRESOLVED
);
2496 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
2497 if (dns_result
!= ISC_R_SUCCESS
) {
2498 isc_mem_destroy(&mctx
);
2499 return(T_UNRESOLVED
);
2502 dns_result
= dns_db_load(db
, filename
);
2503 if (dns_result
!= ISC_R_SUCCESS
) {
2504 t_info("dns_db_load returned %s\n",
2505 dns_result_totext(dns_result
));
2507 isc_mem_destroy(&mctx
);
2508 return(T_UNRESOLVED
);
2512 dns_fixedname_init(&dns_name
);
2514 len
= strlen(find_name
);
2515 isc_buffer_init(&name_buffer
, find_name
, len
);
2516 isc_buffer_add(&name_buffer
, len
);
2517 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_name
),
2518 &name_buffer
, NULL
, 0, NULL
);
2519 if (dns_result
!= ISC_R_SUCCESS
) {
2520 t_info("dns_name_fromtext failed %s\n",
2521 dns_result_totext(dns_result
));
2523 isc_mem_destroy(&mctx
);
2524 return(T_UNRESOLVED
);
2527 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_name
),
2529 if (dns_result
!= exp_result
) {
2530 t_info("dns_db_findnode failed %s\n",
2531 dns_result_totext(dns_result
));
2532 if (dns_result
== ISC_R_SUCCESS
)
2533 dns_db_detachnode(db
, &nodep
);
2535 isc_mem_destroy(&mctx
);
2540 * if we're expecting the find to succeed and it did,
2541 * check that the node has been initialized
2542 * by checking for the specified type of rdata
2543 * and expecting the search to succeed
2546 if (dns_result
== ISC_R_SUCCESS
) {
2548 dns_db_currentversion(db
, &cversionp
);
2549 dns_rdataset_init(&rdataset
);
2551 dns_result
= dns_db_findrdataset(db
, nodep
, cversionp
,
2553 0, &rdataset
, NULL
);
2554 if (dns_result
== ISC_R_SUCCESS
) {
2555 dns_rdataset_disassociate(&rdataset
);
2558 t_info("dns_db_findrdataset failed %s\n",
2559 dns_result_totext(dns_result
));
2562 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
2563 dns_db_detachnode(db
, &nodep
);
2570 isc_entropy_detach(&ectx
);
2571 isc_mem_destroy(&mctx
);
2580 t_assert("dns_db_findnode", 13, T_REQUIRED
, "%s", a13
);
2581 result
= t_eval("dns_db_findnode_1_data", t_dns_db_findnode_1
, 8);
2585 static const char *a14
=
2586 "If the node name does not exist and create is ISC_TRUE, "
2587 "then a call to dns_db_findnode(db, name, create, nodep) "
2588 "creates the node, initializes nodep to point to the node, "
2589 "and returns ISC_R_SUCCESS.";
2592 t_dns_db_findnode_2(char **av
) {
2604 isc_result_t dns_result
;
2605 isc_result_t isc_result
;
2607 isc_entropy_t
*ectx
;
2608 dns_dbnode_t
*nodep
;
2609 dns_dbnode_t
*newnodep
;
2610 isc_buffer_t name_buffer
;
2611 dns_rdataset_t rdataset
;
2612 dns_fixedname_t dns_name
;
2613 dns_fixedname_t dns_foundname
;
2614 dns_dbversion_t
*cversionp
;
2616 filename
= T_ARG(0);
2628 t_info("testing using file %s and name %s\n", filename
, newname
);
2630 isc_result
= isc_mem_create(0, 0, &mctx
);
2631 if (isc_result
!= ISC_R_SUCCESS
) {
2632 t_info("isc_mem_create failed %s\n",
2633 isc_result_totext(isc_result
));
2634 return(T_UNRESOLVED
);
2637 isc_result
= isc_entropy_create(mctx
, &ectx
);
2638 if (isc_result
!= ISC_R_SUCCESS
) {
2639 t_info("isc_entropy_create failed %s\n",
2640 isc_result_totext(isc_result
));
2641 return(T_UNRESOLVED
);
2644 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
2645 if (isc_result
!= ISC_R_SUCCESS
) {
2646 t_info("isc_hash_create failed %s\n",
2647 isc_result_totext(isc_result
));
2648 return(T_UNRESOLVED
);
2651 dns_result
= t_create(db_type
, origin
, class, model
, mctx
, &db
);
2652 if (dns_result
!= ISC_R_SUCCESS
) {
2654 isc_entropy_detach(&ectx
);
2655 isc_mem_destroy(&mctx
);
2656 return(T_UNRESOLVED
);
2659 dns_result
= dns_db_load(db
, filename
);
2660 if (dns_result
!= ISC_R_SUCCESS
) {
2661 t_info("dns_db_load returned %s\n",
2662 dns_result_totext(dns_result
));
2665 isc_entropy_detach(&ectx
);
2666 isc_mem_destroy(&mctx
);
2667 return(T_UNRESOLVED
);
2671 dns_fixedname_init(&dns_name
);
2674 * Make sure the name isn't there
2676 len
= strlen(newname
);
2677 isc_buffer_init(&name_buffer
, newname
, len
);
2678 isc_buffer_add(&name_buffer
, len
);
2679 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_name
),
2680 &name_buffer
, NULL
, 0, NULL
);
2681 if (dns_result
!= ISC_R_SUCCESS
) {
2682 t_info("dns_name_fromtext returned %s\n",
2683 dns_result_totext(dns_result
));
2686 isc_entropy_detach(&ectx
);
2687 isc_mem_destroy(&mctx
);
2688 return(T_UNRESOLVED
);
2691 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_name
),
2693 if ((dns_result
!= ISC_R_NOTFOUND
) &&
2694 (dns_result
!= DNS_R_NXDOMAIN
) &&
2695 (dns_result
!= DNS_R_NXRRSET
)) {
2696 t_info("dns_db_findnode %s\n",
2697 dns_result_totext(dns_result
));
2698 dns_db_detachnode(db
, &nodep
);
2701 isc_entropy_detach(&ectx
);
2702 isc_mem_destroy(&mctx
);
2703 return(T_UNRESOLVED
);
2709 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_name
),
2711 if (dns_result
!= ISC_R_SUCCESS
) {
2712 t_info("dns_db_findnode %s\n",
2713 dns_result_totext(dns_result
));
2716 isc_entropy_detach(&ectx
);
2717 isc_mem_destroy(&mctx
);
2725 dns_rdataset_init(&rdataset
);
2726 dns_fixedname_init(&dns_foundname
);
2728 dns_db_currentversion(db
, &cversionp
);
2731 * First try dns_db_find DNS_R_NXDOMAIN.
2733 dns_result
= dns_db_find(db
,
2734 dns_fixedname_name(&dns_name
),
2740 dns_fixedname_name(&dns_foundname
),
2742 if ((dns_result
!= ISC_R_NOTFOUND
) && (dns_result
!= DNS_R_NXDOMAIN
)) {
2743 dns_db_detachnode(db
, &newnodep
);
2746 if (dns_result
!= DNS_R_NXDOMAIN
) {
2747 t_info("dns_db_find %s\n",
2748 dns_result_totext(dns_result
));
2753 * Then try dns_db_findnode ISC_R_SUCCESS.
2755 dns_result
= dns_db_findnode(db
, dns_fixedname_name(&dns_name
),
2756 ISC_FALSE
, &newnodep
);
2757 t_info("dns_db_findnode %s\n", dns_result_totext(dns_result
));
2758 if (dns_result
== ISC_R_SUCCESS
) {
2759 dns_db_detachnode(db
, &newnodep
);
2761 t_info("dns_db_findnode %s failed %s\n", newname
,
2762 dns_result_totext(dns_result
));
2767 dns_db_detachnode(db
, &nodep
);
2768 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
2771 isc_entropy_detach(&ectx
);
2772 isc_mem_destroy(&mctx
);
2786 t_assert("dns_db_findnode", 14, T_REQUIRED
, "%s", a14
);
2787 result
= t_eval("dns_db_findnode_2_data", t_dns_db_findnode_2
, 6);
2792 t_dns_db_find_x(char **av
) {
2802 char *expected_result
;
2808 isc_result_t dns_result
;
2809 isc_result_t isc_result
;
2810 isc_stdtime_t ftime
;
2812 isc_result_t exp_result
;
2814 isc_entropy_t
*ectx
;
2815 dns_dbnode_t
*nodep
;
2816 isc_textregion_t textregion
;
2817 isc_buffer_t findname_buffer
;
2818 dns_fixedname_t dns_findname
;
2819 dns_fixedname_t dns_foundname
;
2820 dns_rdataset_t rdataset
;
2821 dns_rdatatype_t rdatatype
;
2822 dns_dbversion_t
*cversionp
;
2826 dborigin
= T_ARG(2);
2829 findname
= T_ARG(5);
2830 findtype
= T_ARG(6);
2831 findopts
= T_ARG(7);
2832 findtime
= T_ARG(8);
2833 expected_result
= T_ARG(9);
2839 t_info("testing using %s, name %s, type %s\n", dbfile
, findname
,
2842 isc_result
= isc_mem_create(0, 0, &mctx
);
2843 if (isc_result
!= ISC_R_SUCCESS
) {
2844 t_info("isc_mem_create failed %s\n",
2845 isc_result_totext(isc_result
));
2846 return(T_UNRESOLVED
);
2849 isc_result
= isc_entropy_create(mctx
, &ectx
);
2850 if (isc_result
!= ISC_R_SUCCESS
) {
2851 t_info("isc_entropy_create failed %s\n",
2852 isc_result_totext(isc_result
));
2853 isc_mem_destroy(&mctx
);
2854 return(T_UNRESOLVED
);
2857 isc_result
= isc_hash_create(mctx
, ectx
, DNS_NAME_MAXWIRE
);
2858 if (isc_result
!= ISC_R_SUCCESS
) {
2859 t_info("isc_hash_create failed %s\n",
2860 isc_result_totext(isc_result
));
2861 isc_entropy_detach(&ectx
);
2862 isc_mem_destroy(&mctx
);
2863 return(T_UNRESOLVED
);
2866 dns_result
= t_create(dbtype
, dborigin
, dbclass
, dbmodel
, mctx
, &db
);
2867 if (dns_result
!= ISC_R_SUCCESS
) {
2869 isc_entropy_detach(&ectx
);
2870 isc_mem_destroy(&mctx
);
2871 return(T_UNRESOLVED
);
2874 dns_result
= dns_db_load(db
, dbfile
);
2875 if (dns_result
!= ISC_R_SUCCESS
) {
2876 t_info("dns_db_load returned %s\n",
2877 dns_result_totext(dns_result
));
2880 isc_entropy_detach(&ectx
);
2881 isc_mem_destroy(&mctx
);
2882 return(T_UNRESOLVED
);
2885 exp_result
= t_dns_result_fromtext(expected_result
);
2887 dns_fixedname_init(&dns_findname
);
2888 len
= strlen(findname
);
2889 isc_buffer_init(&findname_buffer
, findname
, len
);
2890 isc_buffer_add(&findname_buffer
, len
);
2891 dns_result
= dns_name_fromtext(dns_fixedname_name(&dns_findname
),
2892 &findname_buffer
, NULL
, 0, NULL
);
2893 if (dns_result
!= ISC_R_SUCCESS
) {
2894 t_info("dns_name_fromtext failed %s\n",
2895 dns_result_totext(dns_result
));
2898 isc_entropy_detach(&ectx
);
2899 isc_mem_destroy(&mctx
);
2900 return(T_UNRESOLVED
);
2903 textregion
.base
= findtype
;
2904 textregion
.length
= strlen(findtype
);
2905 dns_result
= dns_rdatatype_fromtext(&rdatatype
, &textregion
);
2906 if (dns_result
!= ISC_R_SUCCESS
) {
2907 t_info("dns_rdatatype_fromtext %s failed %s\n",
2909 dns_result_totext(dns_result
));
2912 isc_entropy_detach(&ectx
);
2913 isc_mem_destroy(&mctx
);
2914 return(T_UNRESOLVED
);
2917 if (strstr(findopts
, "DNS_DBFIND_GLUEOK"))
2918 opts
|= DNS_DBFIND_GLUEOK
;
2919 if (strstr(findopts
, "DNS_DBFIND_VALIDATEGLUE"))
2920 opts
|= DNS_DBFIND_VALIDATEGLUE
;
2922 isc_stdtime_get(&now
);
2924 ftime
= strtol(findtime
, NULL
, 10);
2929 dns_fixedname_init(&dns_foundname
);
2930 dns_rdataset_init(&rdataset
);
2931 if (dns_db_iszone(db
))
2932 dns_db_currentversion(db
, &cversionp
);
2935 dns_result
= dns_db_find(db
,
2936 dns_fixedname_name(&dns_findname
),
2942 dns_fixedname_name(&dns_foundname
),
2945 if (dns_result
!= exp_result
) {
2946 t_info("dns_db_find %s %s unexpectedly returned %s, "
2948 findname
, findtype
, dns_result_totext(dns_result
),
2949 dns_result_totext(exp_result
));
2955 if ((dns_result
!= ISC_R_NOTFOUND
) && (dns_result
!= DNS_R_NXDOMAIN
)) {
2957 if ((dns_result
!= DNS_R_NXRRSET
) &&
2958 (dns_result
!= DNS_R_ZONECUT
))
2959 if (dns_rdataset_isassociated(&rdataset
))
2960 dns_rdataset_disassociate(&rdataset
);
2961 dns_db_detachnode(db
, &nodep
);
2964 if (dns_db_iszone(db
))
2965 dns_db_closeversion(db
, &cversionp
, ISC_FALSE
);
2968 isc_entropy_detach(&ectx
);
2969 isc_mem_destroy(&mctx
);
2974 static const char *a15
=
2975 "A call to dns_db_find(db, name, version, type, options, now, ...) "
2976 "finds the best match for 'name' and 'type' in version 'version' "
2983 t_assert("dns_db_find", 15, T_REQUIRED
, "%s", a15
);
2984 result
= t_eval("dns_db_find_1_data", t_dns_db_find_x
, 10);
2989 static const char *a16
=
2990 "When the desired node and type were found, but are glue, "
2991 "and the DNS_DBFIND_GLUEOK option is set, a call to "
2992 "dns_db_find(db, name, version, type, options, now, ...) "
2993 "returns DNS_R_GLUE.";
2999 t_assert("dns_db_find", 16, T_REQUIRED
, "%s", a16
);
3000 result
= t_eval("dns_db_find_2_data", t_dns_db_find_x
, 10);
3004 static const char *a17
=
3005 "A call to dns_db_find() returns DNS_R_DELEGATION when the data "
3006 "requested is beneath a zone cut.";
3012 t_assert("dns_db_find", 17, T_REQUIRED
, "%s", a17
);
3013 result
= t_eval("dns_db_find_3_data", t_dns_db_find_x
, 10);
3017 static const char *a18
=
3018 "A call to dns_db_find() returns DNS_R_DELEGATION when type is "
3019 "dns_rdatatype_any and the desired node is a zone cut.";
3025 t_assert("dns_db_find", 18, T_REQUIRED
, "%s", a18
);
3026 result
= t_eval("dns_db_find_4_data", t_dns_db_find_x
, 10);
3030 static const char *a19
=
3031 "A call to dns_db_find() returns DNS_R_DNAME when the data "
3032 "requested is beneath a DNAME.";
3038 t_assert("dns_db_find", 19, T_REQUIRED
, "%s", a19
);
3039 result
= t_eval("dns_db_find_5_data", t_dns_db_find_x
, 10);
3043 static const char *a20
=
3044 "A call to dns_db_find() returns DNS_R_CNAME when the requested "
3045 "rdataset was not found but there is a CNAME at the desired name.";
3051 t_assert("dns_db_find", 20, T_REQUIRED
, "%s", a20
);
3052 result
= t_eval("dns_db_find_6_data", t_dns_db_find_x
, 10);
3056 static const char *a21
=
3057 "A call to dns_db_find() returns DNS_R_NXDOMAIN when name "
3064 t_assert("dns_db_find", 21, T_REQUIRED
, "%s", a21
);
3065 result
= t_eval("dns_db_find_7_data", t_dns_db_find_x
, 10);
3069 static const char *a22
=
3070 "A call to dns_db_find() returns DNS_R_NXRRSET when "
3071 "the desired name exists, but the desired type does not.";
3077 t_assert("dns_db_find", 22, T_REQUIRED
, "%s", a22
);
3078 result
= t_eval("dns_db_find_8_data", t_dns_db_find_x
, 10);
3082 static const char *a23
=
3083 "When db is a cache database, a call to dns_db_find() "
3084 "returns ISC_R_NOTFOUND when the desired name does not exist, "
3085 "and no delegation could be found.";
3091 t_assert("dns_db_find", 23, T_REQUIRED
, "%s", a23
);
3092 result
= t_eval("dns_db_find_9_data", t_dns_db_find_x
, 10);
3096 static const char *a24
=
3097 "When db is a cache database, an rdataset will be found only "
3098 "if at least one rdataset at the found node expires after 'now'.";
3104 t_assert("dns_db_find", 24, T_REQUIRED
, "%s", a24
);
3105 result
= t_eval("dns_db_find_10_data", t_dns_db_find_x
, 10);
3109 static const char *a25
=
3110 "A call to dns_db_load(db, filename) returns DNS_R_NOTZONETOP "
3111 "when the zone data contains a SOA not at the zone apex.";
3117 t_assert("dns_db_load", 25, T_REQUIRED
, "%s", a25
);
3118 result
= t_eval("dns_db_load_soa_not_top", t_dns_db_load
, 9);
3122 testspec_t T_testlist
[] = {
3123 { (PFV
) t1
, "dns_db_load" },
3124 { (PFV
) t2
, "dns_db_iscache" },
3125 { (PFV
) t3
, "dns_db_iscache" },
3126 { (PFV
) t4
, "dns_db_iszone" },
3127 { (PFV
) t5
, "dns_db_iszone" },
3128 { (PFV
) t6
, "dns_db_origin" },
3129 { (PFV
) t7
, "dns_db_class" },
3130 { (PFV
) t8
, "dns_db_currentversion" },
3131 { (PFV
) t9
, "dns_db_newversion" },
3132 { (PFV
) t10
, "dns_db_closeversion" },
3133 { (PFV
) t11
, "dns_db_closeversion" },
3134 { (PFV
) t12
, "dns_db_expirenode" },
3135 { (PFV
) t13
, "dns_db_findnode" },
3136 { (PFV
) t14
, "dns_db_findnode" },
3137 { (PFV
) t15
, "dns_db_find" },
3138 { (PFV
) t16
, "dns_db_find" },
3139 { (PFV
) t17
, "dns_db_find" },
3140 { (PFV
) t18
, "dns_db_find" },
3141 { (PFV
) t19
, "dns_db_find" },
3142 { (PFV
) t20
, "dns_db_find" },
3143 { (PFV
) t21
, "dns_db_find" },
3144 { (PFV
) t22
, "dns_db_find" },
3145 { (PFV
) t23
, "dns_db_find" },
3146 { (PFV
) t24
, "dns_db_find" },
3147 { (PFV
) t25
, "dns_db_load" },
3153 main(int argc
, char **argv
) {
3154 t_settests(T_testlist
);
3155 return (t_main(argc
, argv
));