2 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: masterdump.c,v 1.94.50.3 2009/11/18 00:15:37 marka Exp $ */
26 #include <isc/event.h>
28 #include <isc/magic.h>
30 #include <isc/print.h>
31 #include <isc/stdio.h>
32 #include <isc/string.h>
38 #include <dns/dbiterator.h>
39 #include <dns/events.h>
40 #include <dns/fixedname.h>
43 #include <dns/master.h>
44 #include <dns/masterdump.h>
45 #include <dns/rdata.h>
46 #include <dns/rdataclass.h>
47 #include <dns/rdataset.h>
48 #include <dns/rdatasetiter.h>
49 #include <dns/rdatatype.h>
50 #include <dns/result.h>
54 #define DNS_DCTX_MAGIC ISC_MAGIC('D', 'c', 't', 'x')
55 #define DNS_DCTX_VALID(d) ISC_MAGIC_VALID(d, DNS_DCTX_MAGIC)
57 #define RETERR(x) do { \
58 isc_result_t _r = (x); \
59 if (_r != ISC_R_SUCCESS) \
63 struct dns_master_style {
64 unsigned int flags; /* DNS_STYLEFLAG_* */
65 unsigned int ttl_column;
66 unsigned int class_column;
67 unsigned int type_column;
68 unsigned int rdata_column;
69 unsigned int line_length;
70 unsigned int tab_width;
74 * The maximum length of the newline+indentation that is output
75 * when inserting a line break in an RR. This effectively puts an
76 * upper limits on the value of "rdata_column", because if it is
77 * very large, the tabs and spaces needed to reach it will not fit.
79 #define DNS_TOTEXT_LINEBREAK_MAXLEN 100
82 * Context structure for a masterfile dump in progress.
84 typedef struct dns_totext_ctx {
85 dns_master_style_t style;
86 isc_boolean_t class_printed;
88 char linebreak_buf[DNS_TOTEXT_LINEBREAK_MAXLEN];
90 dns_name_t * neworigin;
91 dns_fixedname_t origin_fixname;
92 isc_uint32_t current_ttl;
93 isc_boolean_t current_ttl_valid;
96 LIBDNS_EXTERNAL_DATA const dns_master_style_t
97 dns_master_style_default = {
98 DNS_STYLEFLAG_OMIT_OWNER |
99 DNS_STYLEFLAG_OMIT_CLASS |
100 DNS_STYLEFLAG_REL_OWNER |
101 DNS_STYLEFLAG_REL_DATA |
102 DNS_STYLEFLAG_OMIT_TTL |
104 DNS_STYLEFLAG_COMMENT |
105 DNS_STYLEFLAG_MULTILINE,
106 24, 24, 24, 32, 80, 8
109 LIBDNS_EXTERNAL_DATA const dns_master_style_t
110 dns_master_style_full = {
111 DNS_STYLEFLAG_COMMENT |
112 DNS_STYLEFLAG_RESIGN,
113 46, 46, 46, 64, 120, 8
116 LIBDNS_EXTERNAL_DATA const dns_master_style_t
117 dns_master_style_explicitttl = {
118 DNS_STYLEFLAG_OMIT_OWNER |
119 DNS_STYLEFLAG_OMIT_CLASS |
120 DNS_STYLEFLAG_REL_OWNER |
121 DNS_STYLEFLAG_REL_DATA |
122 DNS_STYLEFLAG_COMMENT |
123 DNS_STYLEFLAG_MULTILINE,
124 24, 32, 32, 40, 80, 8
127 LIBDNS_EXTERNAL_DATA const dns_master_style_t
128 dns_master_style_cache = {
129 DNS_STYLEFLAG_OMIT_OWNER |
130 DNS_STYLEFLAG_OMIT_CLASS |
131 DNS_STYLEFLAG_MULTILINE |
132 DNS_STYLEFLAG_TRUST |
133 DNS_STYLEFLAG_NCACHE,
134 24, 32, 32, 40, 80, 8
137 LIBDNS_EXTERNAL_DATA const dns_master_style_t
138 dns_master_style_simple = {
140 24, 32, 32, 40, 80, 8
144 * A style suitable for dns_rdataset_totext().
146 LIBDNS_EXTERNAL_DATA const dns_master_style_t
147 dns_master_style_debug = {
148 DNS_STYLEFLAG_REL_OWNER,
149 24, 32, 40, 48, 80, 8
154 static char spaces[N_SPACES+1] = " ";
157 static char tabs[N_TABS+1] = "\t\t\t\t\t\t\t\t\t\t";
163 unsigned int references;
164 isc_boolean_t canceled;
166 isc_boolean_t do_date;
170 dns_dbversion_t *version;
171 dns_dbiterator_t *dbiter;
172 dns_totext_ctx_t tctx;
174 dns_dumpdonefunc_t done;
177 /* dns_master_dumpinc() */
180 dns_masterformat_t format;
181 isc_result_t (*dumpsets)(isc_mem_t *mctx, dns_name_t *name,
182 dns_rdatasetiter_t *rdsiter,
183 dns_totext_ctx_t *ctx,
184 isc_buffer_t *buffer, FILE *f);
187 #define NXDOMAIN(x) (((x)->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0)
190 * Output tabs and spaces to go from column '*current' to
191 * column 'to', and update '*current' to reflect the new
195 indent(unsigned int *current, unsigned int to, int tabwidth,
196 isc_buffer_t *target)
201 int ntabs, nspaces, t;
208 ntabs = to / tabwidth - from / tabwidth;
213 isc_buffer_availableregion(target, &r);
214 if (r.length < (unsigned) ntabs)
215 return (ISC_R_NOSPACE);
227 isc_buffer_add(target, ntabs);
228 from = (to / tabwidth) * tabwidth;
232 INSIST(nspaces >= 0);
234 isc_buffer_availableregion(target, &r);
235 if (r.length < (unsigned) nspaces)
236 return (ISC_R_NOSPACE);
244 memcpy(p, spaces, n);
248 isc_buffer_add(target, nspaces);
251 return (ISC_R_SUCCESS);
255 totext_ctx_init(const dns_master_style_t *style, dns_totext_ctx_t *ctx) {
258 REQUIRE(style->tab_width != 0);
261 ctx->class_printed = ISC_FALSE;
263 dns_fixedname_init(&ctx->origin_fixname);
266 * Set up the line break string if needed.
268 if ((ctx->style.flags & DNS_STYLEFLAG_MULTILINE) != 0) {
271 unsigned int col = 0;
273 isc_buffer_init(&buf, ctx->linebreak_buf,
274 sizeof(ctx->linebreak_buf));
276 isc_buffer_availableregion(&buf, &r);
278 return (DNS_R_TEXTTOOLONG);
280 isc_buffer_add(&buf, 1);
282 result = indent(&col, ctx->style.rdata_column,
283 ctx->style.tab_width, &buf);
285 * Do not return ISC_R_NOSPACE if the line break string
286 * buffer is too small, because that would just make
287 * dump_rdataset() retry indefinitely with ever
288 * bigger target buffers. That's a different buffer,
289 * so it won't help. Use DNS_R_TEXTTOOLONG as a substitute.
291 if (result == ISC_R_NOSPACE)
292 return (DNS_R_TEXTTOOLONG);
293 if (result != ISC_R_SUCCESS)
296 isc_buffer_availableregion(&buf, &r);
298 return (DNS_R_TEXTTOOLONG);
300 isc_buffer_add(&buf, 1);
301 ctx->linebreak = ctx->linebreak_buf;
303 ctx->linebreak = NULL;
307 ctx->neworigin = NULL;
308 ctx->current_ttl = 0;
309 ctx->current_ttl_valid = ISC_FALSE;
311 return (ISC_R_SUCCESS);
314 #define INDENT_TO(col) \
316 if ((result = indent(&column, ctx->style.col, \
317 ctx->style.tab_width, target)) \
324 str_totext(const char *source, isc_buffer_t *target) {
328 isc_buffer_availableregion(target, ®ion);
331 if (l > region.length)
332 return (ISC_R_NOSPACE);
334 memcpy(region.base, source, l);
335 isc_buffer_add(target, l);
336 return (ISC_R_SUCCESS);
340 * Convert 'rdataset' to master file text format according to 'ctx',
341 * storing the result in 'target'. If 'owner_name' is NULL, it
342 * is omitted; otherwise 'owner_name' must be valid and have at least
347 rdataset_totext(dns_rdataset_t *rdataset,
348 dns_name_t *owner_name,
349 dns_totext_ctx_t *ctx,
350 isc_boolean_t omit_final_dot,
351 isc_buffer_t *target)
355 isc_boolean_t first = ISC_TRUE;
356 isc_uint32_t current_ttl;
357 isc_boolean_t current_ttl_valid;
358 dns_rdatatype_t type;
360 REQUIRE(DNS_RDATASET_VALID(rdataset));
362 rdataset->attributes |= DNS_RDATASETATTR_LOADORDER;
363 result = dns_rdataset_first(rdataset);
364 REQUIRE(result == ISC_R_SUCCESS);
366 current_ttl = ctx->current_ttl;
367 current_ttl_valid = ctx->current_ttl_valid;
375 if (owner_name != NULL &&
376 ! ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != 0 &&
379 unsigned int name_start = target->used;
380 RETERR(dns_name_totext(owner_name,
383 column += target->used - name_start;
389 if ((ctx->style.flags & DNS_STYLEFLAG_NO_TTL) == 0 &&
390 !((ctx->style.flags & DNS_STYLEFLAG_OMIT_TTL) != 0 &&
392 rdataset->ttl == current_ttl))
398 INDENT_TO(ttl_column);
399 length = snprintf(ttlbuf, sizeof(ttlbuf), "%u",
401 INSIST(length <= sizeof(ttlbuf));
402 isc_buffer_availableregion(target, &r);
403 if (r.length < length)
404 return (ISC_R_NOSPACE);
405 memcpy(r.base, ttlbuf, length);
406 isc_buffer_add(target, length);
410 * If the $TTL directive is not in use, the TTL we
411 * just printed becomes the default for subsequent RRs.
413 if ((ctx->style.flags & DNS_STYLEFLAG_TTL) == 0) {
414 current_ttl = rdataset->ttl;
415 current_ttl_valid = ISC_TRUE;
422 if ((ctx->style.flags & DNS_STYLEFLAG_NO_CLASS) == 0 &&
423 ((ctx->style.flags & DNS_STYLEFLAG_OMIT_CLASS) == 0 ||
424 ctx->class_printed == ISC_FALSE))
426 unsigned int class_start;
427 INDENT_TO(class_column);
428 class_start = target->used;
429 result = dns_rdataclass_totext(rdataset->rdclass,
431 if (result != ISC_R_SUCCESS)
433 column += (target->used - class_start);
440 if (rdataset->type == 0) {
441 type = rdataset->covers;
443 type = rdataset->type;
447 unsigned int type_start;
448 INDENT_TO(type_column);
449 type_start = target->used;
450 if (rdataset->type == 0)
451 RETERR(str_totext("\\-", target));
452 result = dns_rdatatype_totext(type, target);
453 if (result != ISC_R_SUCCESS)
455 column += (target->used - type_start);
461 INDENT_TO(rdata_column);
462 if (rdataset->type == 0) {
463 if (NXDOMAIN(rdataset))
464 RETERR(str_totext(";-$NXDOMAIN\n", target));
466 RETERR(str_totext(";-$NXRRSET\n", target));
468 dns_rdata_t rdata = DNS_RDATA_INIT;
471 dns_rdataset_current(rdataset, &rdata);
473 RETERR(dns_rdata_tofmttext(&rdata,
476 ctx->style.line_length -
477 ctx->style.rdata_column,
481 isc_buffer_availableregion(target, &r);
483 return (ISC_R_NOSPACE);
485 isc_buffer_add(target, 1);
489 result = dns_rdataset_next(rdataset);
490 } while (result == ISC_R_SUCCESS);
492 if (result != ISC_R_NOMORE)
496 * Update the ctx state to reflect what we just printed.
497 * This is done last, only when we are sure we will return
498 * success, because this function may be called multiple
499 * times with increasing buffer sizes until it succeeds,
500 * and failed attempts must not update the state prematurely.
502 ctx->class_printed = ISC_TRUE;
503 ctx->current_ttl= current_ttl;
504 ctx->current_ttl_valid = current_ttl_valid;
506 return (ISC_R_SUCCESS);
510 * Print the name, type, and class of an empty rdataset,
511 * such as those used to represent the question section
515 question_totext(dns_rdataset_t *rdataset,
516 dns_name_t *owner_name,
517 dns_totext_ctx_t *ctx,
518 isc_boolean_t omit_final_dot,
519 isc_buffer_t *target)
525 REQUIRE(DNS_RDATASET_VALID(rdataset));
526 result = dns_rdataset_first(rdataset);
527 REQUIRE(result == ISC_R_NOMORE);
533 unsigned int name_start = target->used;
534 RETERR(dns_name_totext(owner_name,
537 column += target->used - name_start;
542 unsigned int class_start;
543 INDENT_TO(class_column);
544 class_start = target->used;
545 result = dns_rdataclass_totext(rdataset->rdclass, target);
546 if (result != ISC_R_SUCCESS)
548 column += (target->used - class_start);
553 unsigned int type_start;
554 INDENT_TO(type_column);
555 type_start = target->used;
556 result = dns_rdatatype_totext(rdataset->type, target);
557 if (result != ISC_R_SUCCESS)
559 column += (target->used - type_start);
562 isc_buffer_availableregion(target, &r);
564 return (ISC_R_NOSPACE);
566 isc_buffer_add(target, 1);
568 return (ISC_R_SUCCESS);
572 dns_rdataset_totext(dns_rdataset_t *rdataset,
573 dns_name_t *owner_name,
574 isc_boolean_t omit_final_dot,
575 isc_boolean_t question,
576 isc_buffer_t *target)
578 dns_totext_ctx_t ctx;
580 result = totext_ctx_init(&dns_master_style_debug, &ctx);
581 if (result != ISC_R_SUCCESS) {
582 UNEXPECTED_ERROR(__FILE__, __LINE__,
583 "could not set master file style");
584 return (ISC_R_UNEXPECTED);
588 * The caller might want to give us an empty owner
589 * name (e.g. if they are outputting into a master
590 * file and this rdataset has the same name as the
593 if (dns_name_countlabels(owner_name) == 0)
597 return (question_totext(rdataset, owner_name, &ctx,
598 omit_final_dot, target));
600 return (rdataset_totext(rdataset, owner_name, &ctx,
601 omit_final_dot, target));
605 dns_master_rdatasettotext(dns_name_t *owner_name,
606 dns_rdataset_t *rdataset,
607 const dns_master_style_t *style,
608 isc_buffer_t *target)
610 dns_totext_ctx_t ctx;
612 result = totext_ctx_init(style, &ctx);
613 if (result != ISC_R_SUCCESS) {
614 UNEXPECTED_ERROR(__FILE__, __LINE__,
615 "could not set master file style");
616 return (ISC_R_UNEXPECTED);
619 return (rdataset_totext(rdataset, owner_name, &ctx,
624 dns_master_questiontotext(dns_name_t *owner_name,
625 dns_rdataset_t *rdataset,
626 const dns_master_style_t *style,
627 isc_buffer_t *target)
629 dns_totext_ctx_t ctx;
631 result = totext_ctx_init(style, &ctx);
632 if (result != ISC_R_SUCCESS) {
633 UNEXPECTED_ERROR(__FILE__, __LINE__,
634 "could not set master file style");
635 return (ISC_R_UNEXPECTED);
638 return (question_totext(rdataset, owner_name, &ctx,
643 * Print an rdataset. 'buffer' is a scratch buffer, which must have been
644 * dynamically allocated by the caller. It must be large enough to
645 * hold the result from dns_ttl_totext(). If more than that is needed,
646 * the buffer will be grown automatically.
650 dump_rdataset(isc_mem_t *mctx, dns_name_t *name, dns_rdataset_t *rdataset,
651 dns_totext_ctx_t *ctx,
652 isc_buffer_t *buffer, FILE *f)
657 REQUIRE(buffer->length > 0);
660 * Output a $TTL directive if needed.
663 if ((ctx->style.flags & DNS_STYLEFLAG_TTL) != 0) {
664 if (ctx->current_ttl_valid == ISC_FALSE ||
665 ctx->current_ttl != rdataset->ttl)
667 if ((ctx->style.flags & DNS_STYLEFLAG_COMMENT) != 0)
669 isc_buffer_clear(buffer);
670 result = dns_ttl_totext(rdataset->ttl,
672 INSIST(result == ISC_R_SUCCESS);
673 isc_buffer_usedregion(buffer, &r);
674 fprintf(f, "$TTL %u\t; %.*s\n", rdataset->ttl,
675 (int) r.length, (char *) r.base);
677 fprintf(f, "$TTL %u\n", rdataset->ttl);
679 ctx->current_ttl = rdataset->ttl;
680 ctx->current_ttl_valid = ISC_TRUE;
684 isc_buffer_clear(buffer);
687 * Generate the text representation of the rdataset into
688 * the buffer. If the buffer is too small, grow it.
693 result = rdataset_totext(rdataset, name, ctx,
695 if (result != ISC_R_NOSPACE)
698 newlength = buffer->length * 2;
699 newmem = isc_mem_get(mctx, newlength);
701 return (ISC_R_NOMEMORY);
702 isc_mem_put(mctx, buffer->base, buffer->length);
703 isc_buffer_init(buffer, newmem, newlength);
705 if (result != ISC_R_SUCCESS)
709 * Write the buffer contents to the master file.
711 isc_buffer_usedregion(buffer, &r);
712 result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL);
714 if (result != ISC_R_SUCCESS) {
715 UNEXPECTED_ERROR(__FILE__, __LINE__,
716 "master file write failed: %s",
717 isc_result_totext(result));
721 return (ISC_R_SUCCESS);
725 * Define the order in which rdatasets should be printed in zone
726 * files. We will print SOA and NS records before others, SIGs
727 * immediately following the things they sign, and order everything
728 * else by RR number. This is all just for aesthetics and
729 * compatibility with buggy software that expects the SOA to be first;
730 * the DNS specifications allow any order.
734 dump_order(const dns_rdataset_t *rds) {
737 if (rds->type == dns_rdatatype_rrsig) {
745 case dns_rdatatype_soa:
748 case dns_rdatatype_ns:
755 return (t << 1) + sig;
759 dump_order_compare(const void *a, const void *b) {
760 return (dump_order(*((const dns_rdataset_t * const *) a)) -
761 dump_order(*((const dns_rdataset_t * const *) b)));
765 * Dump all the rdatasets of a domain name to a master file. We make
766 * a "best effort" attempt to sort the RRsets in a nice order, but if
767 * there are more than MAXSORT RRsets, we punt and only sort them in
768 * groups of MAXSORT. This is not expected to ever happen in practice
769 * since much less than 64 RR types have been registered with the
770 * IANA, so far, and the output will be correct (though not
771 * aesthetically pleasing) even if it does happen.
776 static const char *trustnames[] = {
778 "pending-additional",
786 "local" /* aka ultimate */
790 dns_trust_totext(dns_trust_t trust) {
791 if (trust >= sizeof(trustnames)/sizeof(*trustnames))
793 return (trustnames[trust]);
797 dump_rdatasets_text(isc_mem_t *mctx, dns_name_t *name,
798 dns_rdatasetiter_t *rdsiter, dns_totext_ctx_t *ctx,
799 isc_buffer_t *buffer, FILE *f)
801 isc_result_t itresult, dumpresult;
803 dns_rdataset_t rdatasets[MAXSORT];
804 dns_rdataset_t *sorted[MAXSORT];
807 itresult = dns_rdatasetiter_first(rdsiter);
808 dumpresult = ISC_R_SUCCESS;
810 if (itresult == ISC_R_SUCCESS && ctx->neworigin != NULL) {
811 isc_buffer_clear(buffer);
812 itresult = dns_name_totext(ctx->neworigin, ISC_FALSE, buffer);
813 RUNTIME_CHECK(itresult == ISC_R_SUCCESS);
814 isc_buffer_usedregion(buffer, &r);
815 fprintf(f, "$ORIGIN %.*s\n", (int) r.length, (char *) r.base);
816 ctx->neworigin = NULL;
821 itresult == ISC_R_SUCCESS && i < MAXSORT;
822 itresult = dns_rdatasetiter_next(rdsiter), i++) {
823 dns_rdataset_init(&rdatasets[i]);
824 dns_rdatasetiter_current(rdsiter, &rdatasets[i]);
825 sorted[i] = &rdatasets[i];
828 INSIST(n <= MAXSORT);
830 qsort(sorted, n, sizeof(sorted[0]), dump_order_compare);
832 for (i = 0; i < n; i++) {
833 dns_rdataset_t *rds = sorted[i];
834 if (ctx->style.flags & DNS_STYLEFLAG_TRUST) {
835 unsigned int trust = rds->trust;
836 INSIST(trust < (sizeof(trustnames) /
837 sizeof(trustnames[0])));
838 fprintf(f, "; %s\n", trustnames[trust]);
840 if (rds->type == 0 &&
841 (ctx->style.flags & DNS_STYLEFLAG_NCACHE) == 0) {
842 /* Omit negative cache entries */
844 isc_result_t result =
845 dump_rdataset(mctx, name, rds, ctx,
847 if (result != ISC_R_SUCCESS)
849 if ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != 0)
852 if (ctx->style.flags & DNS_STYLEFLAG_RESIGN &&
853 rds->attributes & DNS_RDATASETATTR_RESIGN) {
855 char buf[sizeof("YYYYMMDDHHMMSS")];
856 memset(buf, 0, sizeof(buf));
857 isc_buffer_init(&b, buf, sizeof(buf) - 1);
858 dns_time64_totext((isc_uint64_t)rds->resign, &b);
859 fprintf(f, "; resign=%s\n", buf);
861 dns_rdataset_disassociate(rds);
864 if (dumpresult != ISC_R_SUCCESS)
868 * If we got more data than could be sorted at once,
869 * go handle the rest.
871 if (itresult == ISC_R_SUCCESS)
874 if (itresult == ISC_R_NOMORE)
875 itresult = ISC_R_SUCCESS;
881 * Dump given RRsets in the "raw" format.
884 dump_rdataset_raw(isc_mem_t *mctx, dns_name_t *name, dns_rdataset_t *rdataset,
885 isc_buffer_t *buffer, FILE *f)
888 isc_uint32_t totallen;
890 isc_region_t r, r_hdr;
892 REQUIRE(buffer->length > 0);
893 REQUIRE(DNS_RDATASET_VALID(rdataset));
897 result = dns_rdataset_first(rdataset);
898 REQUIRE(result == ISC_R_SUCCESS);
900 isc_buffer_clear(buffer);
903 * Common header and owner name (length followed by name)
904 * These fields should be in a moderate length, so we assume we
905 * can store all of them in the initial buffer.
907 isc_buffer_availableregion(buffer, &r_hdr);
908 INSIST(r_hdr.length >= sizeof(dns_masterrawrdataset_t));
909 isc_buffer_putuint32(buffer, totallen); /* XXX: leave space */
910 isc_buffer_putuint16(buffer, rdataset->rdclass); /* 16-bit class */
911 isc_buffer_putuint16(buffer, rdataset->type); /* 16-bit type */
912 isc_buffer_putuint16(buffer, rdataset->covers); /* same as type */
913 isc_buffer_putuint32(buffer, rdataset->ttl); /* 32-bit TTL */
914 isc_buffer_putuint32(buffer, dns_rdataset_count(rdataset));
915 totallen = isc_buffer_usedlength(buffer);
916 INSIST(totallen <= sizeof(dns_masterrawrdataset_t));
918 dns_name_toregion(name, &r);
919 INSIST(isc_buffer_availablelength(buffer) >=
920 (sizeof(dlen) + r.length));
921 dlen = (isc_uint16_t)r.length;
922 isc_buffer_putuint16(buffer, dlen);
923 isc_buffer_copyregion(buffer, &r);
924 totallen += sizeof(dlen) + r.length;
927 dns_rdata_t rdata = DNS_RDATA_INIT;
930 dns_rdataset_current(rdataset, &rdata);
931 dns_rdata_toregion(&rdata, &r);
932 INSIST(r.length <= 0xffffU);
933 dlen = (isc_uint16_t)r.length;
936 * Copy the rdata into the buffer. If the buffer is too small,
937 * grow it. This should be rare, so we'll simply restart the
938 * entire procedure (or should we copy the old data and
941 if (isc_buffer_availablelength(buffer) <
942 sizeof(dlen) + r.length) {
946 newlength = buffer->length * 2;
947 newmem = isc_mem_get(mctx, newlength);
949 return (ISC_R_NOMEMORY);
950 isc_mem_put(mctx, buffer->base, buffer->length);
951 isc_buffer_init(buffer, newmem, newlength);
954 isc_buffer_putuint16(buffer, dlen);
955 isc_buffer_copyregion(buffer, &r);
956 totallen += sizeof(dlen) + r.length;
958 result = dns_rdataset_next(rdataset);
959 } while (result == ISC_R_SUCCESS);
961 if (result != ISC_R_NOMORE)
965 * Fill in the total length field.
966 * XXX: this is a bit tricky. Since we have already "used" the space
967 * for the total length in the buffer, we first remember the entire
968 * buffer length in the region, "rewind", and then write the value.
970 isc_buffer_usedregion(buffer, &r);
971 isc_buffer_clear(buffer);
972 isc_buffer_putuint32(buffer, totallen);
973 INSIST(isc_buffer_usedlength(buffer) < totallen);
976 * Write the buffer contents to the raw master file.
978 result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL);
980 if (result != ISC_R_SUCCESS) {
981 UNEXPECTED_ERROR(__FILE__, __LINE__,
982 "raw master file write failed: %s",
983 isc_result_totext(result));
991 dump_rdatasets_raw(isc_mem_t *mctx, dns_name_t *name,
992 dns_rdatasetiter_t *rdsiter, dns_totext_ctx_t *ctx,
993 isc_buffer_t *buffer, FILE *f)
996 dns_rdataset_t rdataset;
998 for (result = dns_rdatasetiter_first(rdsiter);
999 result == ISC_R_SUCCESS;
1000 result = dns_rdatasetiter_next(rdsiter)) {
1002 dns_rdataset_init(&rdataset);
1003 dns_rdatasetiter_current(rdsiter, &rdataset);
1005 if (rdataset.type == 0 &&
1006 (ctx->style.flags & DNS_STYLEFLAG_NCACHE) == 0) {
1007 /* Omit negative cache entries */
1009 result = dump_rdataset_raw(mctx, name, &rdataset,
1012 dns_rdataset_disassociate(&rdataset);
1015 if (result == ISC_R_NOMORE)
1016 result = ISC_R_SUCCESS;
1022 * Initial size of text conversion buffer. The buffer is used
1023 * for several purposes: converting origin names, rdatasets,
1024 * $DATE timestamps, and comment strings for $TTL directives.
1026 * When converting rdatasets, it is dynamically resized, but
1027 * when converting origins, timestamps, etc it is not. Therefore,
1028 * the initial size must large enough to hold the longest possible
1029 * text representation of any domain name (for $ORIGIN).
1031 static const int initial_buffer_length = 1200;
1034 dumptostreaminc(dns_dumpctx_t *dctx);
1037 dumpctx_destroy(dns_dumpctx_t *dctx) {
1040 DESTROYLOCK(&dctx->lock);
1041 dns_dbiterator_destroy(&dctx->dbiter);
1042 if (dctx->version != NULL)
1043 dns_db_closeversion(dctx->db, &dctx->version, ISC_FALSE);
1044 dns_db_detach(&dctx->db);
1045 if (dctx->task != NULL)
1046 isc_task_detach(&dctx->task);
1047 if (dctx->file != NULL)
1048 isc_mem_free(dctx->mctx, dctx->file);
1049 if (dctx->tmpfile != NULL)
1050 isc_mem_free(dctx->mctx, dctx->tmpfile);
1051 isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(*dctx));
1055 dns_dumpctx_attach(dns_dumpctx_t *source, dns_dumpctx_t **target) {
1057 REQUIRE(DNS_DCTX_VALID(source));
1058 REQUIRE(target != NULL && *target == NULL);
1060 LOCK(&source->lock);
1061 INSIST(source->references > 0);
1062 source->references++;
1063 INSIST(source->references != 0); /* Overflow? */
1064 UNLOCK(&source->lock);
1070 dns_dumpctx_detach(dns_dumpctx_t **dctxp) {
1071 dns_dumpctx_t *dctx;
1072 isc_boolean_t need_destroy = ISC_FALSE;
1074 REQUIRE(dctxp != NULL);
1076 REQUIRE(DNS_DCTX_VALID(dctx));
1081 INSIST(dctx->references != 0);
1083 if (dctx->references == 0)
1084 need_destroy = ISC_TRUE;
1085 UNLOCK(&dctx->lock);
1087 dumpctx_destroy(dctx);
1091 dns_dumpctx_version(dns_dumpctx_t *dctx) {
1092 REQUIRE(DNS_DCTX_VALID(dctx));
1093 return (dctx->version);
1097 dns_dumpctx_db(dns_dumpctx_t *dctx) {
1098 REQUIRE(DNS_DCTX_VALID(dctx));
1103 dns_dumpctx_cancel(dns_dumpctx_t *dctx) {
1104 REQUIRE(DNS_DCTX_VALID(dctx));
1107 dctx->canceled = ISC_TRUE;
1108 UNLOCK(&dctx->lock);
1112 closeandrename(FILE *f, isc_result_t result, const char *temp, const char *file)
1114 isc_result_t tresult;
1115 isc_boolean_t logit = ISC_TF(result == ISC_R_SUCCESS);
1117 if (result == ISC_R_SUCCESS)
1118 result = isc_stdio_sync(f);
1119 if (result != ISC_R_SUCCESS && logit) {
1120 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1121 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1122 "dumping master file: %s: fsync: %s",
1123 temp, isc_result_totext(result));
1126 tresult = isc_stdio_close(f);
1127 if (result == ISC_R_SUCCESS)
1129 if (result != ISC_R_SUCCESS && logit) {
1130 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1131 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1132 "dumping master file: %s: fclose: %s",
1133 temp, isc_result_totext(result));
1136 if (result == ISC_R_SUCCESS)
1137 result = isc_file_rename(temp, file);
1139 (void)isc_file_remove(temp);
1140 if (result != ISC_R_SUCCESS && logit) {
1141 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1142 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1143 "dumping master file: rename: %s: %s",
1144 file, isc_result_totext(result));
1150 dump_quantum(isc_task_t *task, isc_event_t *event) {
1151 isc_result_t result;
1152 isc_result_t tresult;
1153 dns_dumpctx_t *dctx;
1155 REQUIRE(event != NULL);
1156 dctx = event->ev_arg;
1157 REQUIRE(DNS_DCTX_VALID(dctx));
1159 result = ISC_R_CANCELED;
1161 result = dumptostreaminc(dctx);
1162 if (result == DNS_R_CONTINUE) {
1163 event->ev_arg = dctx;
1164 isc_task_send(task, &event);
1168 if (dctx->file != NULL) {
1169 tresult = closeandrename(dctx->f, result,
1170 dctx->tmpfile, dctx->file);
1171 if (tresult != ISC_R_SUCCESS && result == ISC_R_SUCCESS)
1174 (dctx->done)(dctx->done_arg, result);
1175 isc_event_free(&event);
1176 dns_dumpctx_detach(&dctx);
1180 task_send(dns_dumpctx_t *dctx) {
1183 event = isc_event_allocate(dctx->mctx, NULL, DNS_EVENT_DUMPQUANTUM,
1184 dump_quantum, dctx, sizeof(*event));
1186 return (ISC_R_NOMEMORY);
1187 isc_task_send(dctx->task, &event);
1188 return (ISC_R_SUCCESS);
1192 dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1193 const dns_master_style_t *style, FILE *f, dns_dumpctx_t **dctxp,
1194 dns_masterformat_t format)
1196 dns_dumpctx_t *dctx;
1197 isc_result_t result;
1198 unsigned int options;
1200 dctx = isc_mem_get(mctx, sizeof(*dctx));
1202 return (ISC_R_NOMEMORY);
1206 dctx->dbiter = NULL;
1208 dctx->version = NULL;
1210 dctx->done_arg = NULL;
1213 dctx->first = ISC_TRUE;
1214 dctx->canceled = ISC_FALSE;
1216 dctx->tmpfile = NULL;
1217 dctx->format = format;
1220 case dns_masterformat_text:
1221 dctx->dumpsets = dump_rdatasets_text;
1223 case dns_masterformat_raw:
1224 dctx->dumpsets = dump_rdatasets_raw;
1231 result = totext_ctx_init(style, &dctx->tctx);
1232 if (result != ISC_R_SUCCESS) {
1233 UNEXPECTED_ERROR(__FILE__, __LINE__,
1234 "could not set master file style");
1238 isc_stdtime_get(&dctx->now);
1239 dns_db_attach(db, &dctx->db);
1241 dctx->do_date = dns_db_iscache(dctx->db);
1243 if (dctx->format == dns_masterformat_text &&
1244 (dctx->tctx.style.flags & DNS_STYLEFLAG_REL_OWNER) != 0) {
1245 options = DNS_DB_RELATIVENAMES;
1248 result = dns_db_createiterator(dctx->db, options, &dctx->dbiter);
1249 if (result != ISC_R_SUCCESS)
1252 result = isc_mutex_init(&dctx->lock);
1253 if (result != ISC_R_SUCCESS)
1255 if (version != NULL)
1256 dns_db_attachversion(dctx->db, version, &dctx->version);
1257 else if (!dns_db_iscache(db))
1258 dns_db_currentversion(dctx->db, &dctx->version);
1259 isc_mem_attach(mctx, &dctx->mctx);
1260 dctx->references = 1;
1261 dctx->magic = DNS_DCTX_MAGIC;
1263 return (ISC_R_SUCCESS);
1266 if (dctx->dbiter != NULL)
1267 dns_dbiterator_destroy(&dctx->dbiter);
1268 if (dctx->db != NULL)
1269 dns_db_detach(&dctx->db);
1271 isc_mem_put(mctx, dctx, sizeof(*dctx));
1276 dumptostreaminc(dns_dumpctx_t *dctx) {
1277 isc_result_t result;
1278 isc_buffer_t buffer;
1282 dns_fixedname_t fixname;
1284 dns_masterrawheader_t rawheader;
1288 bufmem = isc_mem_get(dctx->mctx, initial_buffer_length);
1290 return (ISC_R_NOMEMORY);
1292 isc_buffer_init(&buffer, bufmem, initial_buffer_length);
1294 dns_fixedname_init(&fixname);
1295 name = dns_fixedname_name(&fixname);
1298 switch (dctx->format) {
1299 case dns_masterformat_text:
1301 * If the database has cache semantics, output an
1302 * RFC2540 $DATE directive so that the TTLs can be
1303 * adjusted when it is reloaded. For zones it is not
1304 * really needed, and it would make the file
1305 * incompatible with pre-RFC2540 software, so we omit
1306 * it in the zone case.
1308 if (dctx->do_date) {
1309 result = dns_time32_totext(dctx->now, &buffer);
1310 RUNTIME_CHECK(result == ISC_R_SUCCESS);
1311 isc_buffer_usedregion(&buffer, &r);
1312 fprintf(dctx->f, "$DATE %.*s\n",
1313 (int) r.length, (char *) r.base);
1316 case dns_masterformat_raw:
1317 r.base = (unsigned char *)&rawheader;
1318 r.length = sizeof(rawheader);
1319 isc_buffer_region(&buffer, &r);
1320 isc_buffer_putuint32(&buffer, dns_masterformat_raw);
1321 isc_buffer_putuint32(&buffer, DNS_RAWFORMAT_VERSION);
1322 if (sizeof(now32) != sizeof(dctx->now)) {
1324 * We assume isc_stdtime_t is a 32-bit integer,
1325 * which should be the case on most cases.
1326 * If it turns out to be uncommon, we'll need
1327 * to bump the version number and revise the
1330 isc_log_write(dns_lctx,
1331 ISC_LOGCATEGORY_GENERAL,
1332 DNS_LOGMODULE_MASTERDUMP,
1334 "dumping master file in raw "
1335 "format: stdtime is not 32bits");
1339 isc_buffer_putuint32(&buffer, now32);
1340 INSIST(isc_buffer_usedlength(&buffer) <=
1342 result = isc_stdio_write(buffer.base, 1,
1343 isc_buffer_usedlength(&buffer),
1345 if (result != ISC_R_SUCCESS)
1347 isc_buffer_clear(&buffer);
1353 result = dns_dbiterator_first(dctx->dbiter);
1354 dctx->first = ISC_FALSE;
1356 result = ISC_R_SUCCESS;
1358 nodes = dctx->nodes;
1359 isc_time_now(&start);
1360 while (result == ISC_R_SUCCESS && (dctx->nodes == 0 || nodes--)) {
1361 dns_rdatasetiter_t *rdsiter = NULL;
1362 dns_dbnode_t *node = NULL;
1364 result = dns_dbiterator_current(dctx->dbiter, &node, name);
1365 if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN)
1367 if (result == DNS_R_NEWORIGIN) {
1368 dns_name_t *origin =
1369 dns_fixedname_name(&dctx->tctx.origin_fixname);
1370 result = dns_dbiterator_origin(dctx->dbiter, origin);
1371 RUNTIME_CHECK(result == ISC_R_SUCCESS);
1372 if ((dctx->tctx.style.flags & DNS_STYLEFLAG_REL_DATA) != 0)
1373 dctx->tctx.origin = origin;
1374 dctx->tctx.neworigin = origin;
1376 result = dns_db_allrdatasets(dctx->db, node, dctx->version,
1377 dctx->now, &rdsiter);
1378 if (result != ISC_R_SUCCESS) {
1379 dns_db_detachnode(dctx->db, &node);
1382 result = (dctx->dumpsets)(dctx->mctx, name, rdsiter,
1383 &dctx->tctx, &buffer, dctx->f);
1384 dns_rdatasetiter_destroy(&rdsiter);
1385 if (result != ISC_R_SUCCESS) {
1386 dns_db_detachnode(dctx->db, &node);
1389 dns_db_detachnode(dctx->db, &node);
1390 result = dns_dbiterator_next(dctx->dbiter);
1394 * Work out how many nodes can be written in the time between
1395 * two requests to the nameserver. Smooth the resulting number and
1396 * use it as a estimate for the number of nodes to be written in the
1399 if (dctx->nodes != 0 && result == ISC_R_SUCCESS) {
1400 unsigned int pps = dns_pps; /* packets per second */
1401 unsigned int interval;
1408 interval = 1000000 / pps; /* interval in usecs */
1411 usecs = isc_time_microdiff(&end, &start);
1413 dctx->nodes = dctx->nodes * 2;
1414 if (dctx->nodes > 1000)
1417 nodes = dctx->nodes * interval;
1418 nodes /= (unsigned int)usecs;
1421 else if (nodes > 1000)
1424 /* Smooth and assign. */
1425 dctx->nodes = (nodes + dctx->nodes * 7) / 8;
1427 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1428 DNS_LOGMODULE_MASTERDUMP,
1430 "dumptostreaminc(%p) new nodes -> %d\n",
1433 result = DNS_R_CONTINUE;
1434 } else if (result == ISC_R_NOMORE)
1435 result = ISC_R_SUCCESS;
1437 RUNTIME_CHECK(dns_dbiterator_pause(dctx->dbiter) == ISC_R_SUCCESS);
1438 isc_mem_put(dctx->mctx, buffer.base, buffer.length);
1443 dns_master_dumptostreaminc(isc_mem_t *mctx, dns_db_t *db,
1444 dns_dbversion_t *version,
1445 const dns_master_style_t *style,
1446 FILE *f, isc_task_t *task,
1447 dns_dumpdonefunc_t done, void *done_arg,
1448 dns_dumpctx_t **dctxp)
1450 dns_dumpctx_t *dctx = NULL;
1451 isc_result_t result;
1453 REQUIRE(task != NULL);
1455 REQUIRE(done != NULL);
1457 result = dumpctx_create(mctx, db, version, style, f, &dctx,
1458 dns_masterformat_text);
1459 if (result != ISC_R_SUCCESS)
1461 isc_task_attach(task, &dctx->task);
1463 dctx->done_arg = done_arg;
1466 result = task_send(dctx);
1467 if (result == ISC_R_SUCCESS) {
1468 dns_dumpctx_attach(dctx, dctxp);
1469 return (DNS_R_CONTINUE);
1472 dns_dumpctx_detach(&dctx);
1477 * Dump an entire database into a master file.
1480 dns_master_dumptostream(isc_mem_t *mctx, dns_db_t *db,
1481 dns_dbversion_t *version,
1482 const dns_master_style_t *style,
1485 return (dns_master_dumptostream2(mctx, db, version, style,
1486 dns_masterformat_text, f));
1490 dns_master_dumptostream2(isc_mem_t *mctx, dns_db_t *db,
1491 dns_dbversion_t *version,
1492 const dns_master_style_t *style,
1493 dns_masterformat_t format, FILE *f)
1495 dns_dumpctx_t *dctx = NULL;
1496 isc_result_t result;
1498 result = dumpctx_create(mctx, db, version, style, f, &dctx, format);
1499 if (result != ISC_R_SUCCESS)
1502 result = dumptostreaminc(dctx);
1503 INSIST(result != DNS_R_CONTINUE);
1504 dns_dumpctx_detach(&dctx);
1509 opentmp(isc_mem_t *mctx, const char *file, char **tempp, FILE **fp) {
1511 isc_result_t result;
1512 char *tempname = NULL;
1515 tempnamelen = strlen(file) + 20;
1516 tempname = isc_mem_allocate(mctx, tempnamelen);
1517 if (tempname == NULL)
1518 return (ISC_R_NOMEMORY);
1520 result = isc_file_mktemplate(file, tempname, tempnamelen);
1521 if (result != ISC_R_SUCCESS)
1524 result = isc_file_openunique(tempname, &f);
1525 if (result != ISC_R_SUCCESS) {
1526 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1527 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1528 "dumping master file: %s: open: %s",
1529 tempname, isc_result_totext(result));
1534 return (ISC_R_SUCCESS);
1537 isc_mem_free(mctx, tempname);
1542 dns_master_dumpinc(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1543 const dns_master_style_t *style, const char *filename,
1544 isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
1545 dns_dumpctx_t **dctxp)
1547 return (dns_master_dumpinc2(mctx, db, version, style, filename, task,
1548 done, done_arg, dctxp,
1549 dns_masterformat_text));
1553 dns_master_dumpinc2(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1554 const dns_master_style_t *style, const char *filename,
1555 isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
1556 dns_dumpctx_t **dctxp, dns_masterformat_t format)
1559 isc_result_t result;
1560 char *tempname = NULL;
1562 dns_dumpctx_t *dctx = NULL;
1564 file = isc_mem_strdup(mctx, filename);
1566 return (ISC_R_NOMEMORY);
1568 result = opentmp(mctx, filename, &tempname, &f);
1569 if (result != ISC_R_SUCCESS)
1572 result = dumpctx_create(mctx, db, version, style, f, &dctx, format);
1573 if (result != ISC_R_SUCCESS) {
1574 (void)isc_stdio_close(f);
1575 (void)isc_file_remove(tempname);
1579 isc_task_attach(task, &dctx->task);
1581 dctx->done_arg = done_arg;
1585 dctx->tmpfile = tempname;
1588 result = task_send(dctx);
1589 if (result == ISC_R_SUCCESS) {
1590 dns_dumpctx_attach(dctx, dctxp);
1591 return (DNS_R_CONTINUE);
1596 dns_dumpctx_detach(&dctx);
1598 isc_mem_free(mctx, file);
1599 if (tempname != NULL)
1600 isc_mem_free(mctx, tempname);
1605 dns_master_dump(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1606 const dns_master_style_t *style, const char *filename)
1608 return (dns_master_dump2(mctx, db, version, style, filename,
1609 dns_masterformat_text));
1613 dns_master_dump2(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1614 const dns_master_style_t *style, const char *filename,
1615 dns_masterformat_t format)
1618 isc_result_t result;
1620 dns_dumpctx_t *dctx = NULL;
1622 result = opentmp(mctx, filename, &tempname, &f);
1623 if (result != ISC_R_SUCCESS)
1626 result = dumpctx_create(mctx, db, version, style, f, &dctx, format);
1627 if (result != ISC_R_SUCCESS)
1630 result = dumptostreaminc(dctx);
1631 INSIST(result != DNS_R_CONTINUE);
1632 dns_dumpctx_detach(&dctx);
1634 result = closeandrename(f, result, tempname, filename);
1637 isc_mem_free(mctx, tempname);
1642 * Dump a database node into a master file.
1643 * XXX: this function assumes the text format.
1646 dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db,
1647 dns_dbversion_t *version,
1648 dns_dbnode_t *node, dns_name_t *name,
1649 const dns_master_style_t *style,
1652 isc_result_t result;
1653 isc_buffer_t buffer;
1656 dns_totext_ctx_t ctx;
1657 dns_rdatasetiter_t *rdsiter = NULL;
1659 result = totext_ctx_init(style, &ctx);
1660 if (result != ISC_R_SUCCESS) {
1661 UNEXPECTED_ERROR(__FILE__, __LINE__,
1662 "could not set master file style");
1663 return (ISC_R_UNEXPECTED);
1666 isc_stdtime_get(&now);
1668 bufmem = isc_mem_get(mctx, initial_buffer_length);
1670 return (ISC_R_NOMEMORY);
1672 isc_buffer_init(&buffer, bufmem, initial_buffer_length);
1674 result = dns_db_allrdatasets(db, node, version, now, &rdsiter);
1675 if (result != ISC_R_SUCCESS)
1677 result = dump_rdatasets_text(mctx, name, rdsiter, &ctx, &buffer, f);
1678 if (result != ISC_R_SUCCESS)
1680 dns_rdatasetiter_destroy(&rdsiter);
1682 result = ISC_R_SUCCESS;
1685 isc_mem_put(mctx, buffer.base, buffer.length);
1690 dns_master_dumpnode(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1691 dns_dbnode_t *node, dns_name_t *name,
1692 const dns_master_style_t *style, const char *filename)
1695 isc_result_t result;
1697 result = isc_stdio_open(filename, "w", &f);
1698 if (result != ISC_R_SUCCESS) {
1699 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1700 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1701 "dumping node to file: %s: open: %s", filename,
1702 isc_result_totext(result));
1703 return (ISC_R_UNEXPECTED);
1706 result = dns_master_dumpnodetostream(mctx, db, version, node, name,
1709 result = isc_stdio_close(f);
1710 if (result != ISC_R_SUCCESS) {
1711 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1712 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1713 "dumping master file: %s: close: %s", filename,
1714 isc_result_totext(result));
1715 return (ISC_R_UNEXPECTED);
1722 dns_master_stylecreate(dns_master_style_t **stylep, unsigned int flags,
1723 unsigned int ttl_column, unsigned int class_column,
1724 unsigned int type_column, unsigned int rdata_column,
1725 unsigned int line_length, unsigned int tab_width,
1728 dns_master_style_t *style;
1730 REQUIRE(stylep != NULL && *stylep == NULL);
1731 style = isc_mem_get(mctx, sizeof(*style));
1733 return (ISC_R_NOMEMORY);
1735 style->flags = flags;
1736 style->ttl_column = ttl_column;
1737 style->class_column = class_column;
1738 style->type_column = type_column;
1739 style->rdata_column = rdata_column;
1740 style->line_length = line_length;
1741 style->tab_width = tab_width;
1744 return (ISC_R_SUCCESS);
1748 dns_master_styledestroy(dns_master_style_t **stylep, isc_mem_t *mctx) {
1749 dns_master_style_t *style;
1751 REQUIRE(stylep != NULL && *stylep != NULL);
1754 isc_mem_put(mctx, style, sizeof(*style));