2 * Copyright (C) 2004-2009, 2011 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.10 2011-06-09 00:16:34 each 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;
359 unsigned int type_start;
361 REQUIRE(DNS_RDATASET_VALID(rdataset));
363 rdataset->attributes |= DNS_RDATASETATTR_LOADORDER;
364 result = dns_rdataset_first(rdataset);
365 REQUIRE(result == ISC_R_SUCCESS);
367 current_ttl = ctx->current_ttl;
368 current_ttl_valid = ctx->current_ttl_valid;
376 if (owner_name != NULL &&
377 ! ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != 0 &&
380 unsigned int name_start = target->used;
381 RETERR(dns_name_totext(owner_name,
384 column += target->used - name_start;
390 if ((ctx->style.flags & DNS_STYLEFLAG_NO_TTL) == 0 &&
391 !((ctx->style.flags & DNS_STYLEFLAG_OMIT_TTL) != 0 &&
393 rdataset->ttl == current_ttl))
399 INDENT_TO(ttl_column);
400 length = snprintf(ttlbuf, sizeof(ttlbuf), "%u",
402 INSIST(length <= sizeof(ttlbuf));
403 isc_buffer_availableregion(target, &r);
404 if (r.length < length)
405 return (ISC_R_NOSPACE);
406 memcpy(r.base, ttlbuf, length);
407 isc_buffer_add(target, length);
411 * If the $TTL directive is not in use, the TTL we
412 * just printed becomes the default for subsequent RRs.
414 if ((ctx->style.flags & DNS_STYLEFLAG_TTL) == 0) {
415 current_ttl = rdataset->ttl;
416 current_ttl_valid = ISC_TRUE;
423 if ((ctx->style.flags & DNS_STYLEFLAG_NO_CLASS) == 0 &&
424 ((ctx->style.flags & DNS_STYLEFLAG_OMIT_CLASS) == 0 ||
425 ctx->class_printed == ISC_FALSE))
427 unsigned int class_start;
428 INDENT_TO(class_column);
429 class_start = target->used;
430 result = dns_rdataclass_totext(rdataset->rdclass,
432 if (result != ISC_R_SUCCESS)
434 column += (target->used - class_start);
441 if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
442 type = rdataset->covers;
444 type = rdataset->type;
447 INDENT_TO(type_column);
448 type_start = target->used;
449 if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0)
450 RETERR(str_totext("\\-", target));
451 result = dns_rdatatype_totext(type, target);
452 if (result != ISC_R_SUCCESS)
454 column += (target->used - type_start);
459 INDENT_TO(rdata_column);
460 if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
461 if (NXDOMAIN(rdataset))
462 RETERR(str_totext(";-$NXDOMAIN\n", target));
464 RETERR(str_totext(";-$NXRRSET\n", target));
466 dns_rdata_t rdata = DNS_RDATA_INIT;
469 dns_rdataset_current(rdataset, &rdata);
471 RETERR(dns_rdata_tofmttext(&rdata,
474 ctx->style.line_length -
475 ctx->style.rdata_column,
479 isc_buffer_availableregion(target, &r);
481 return (ISC_R_NOSPACE);
483 isc_buffer_add(target, 1);
487 result = dns_rdataset_next(rdataset);
488 } while (result == ISC_R_SUCCESS);
490 if (result != ISC_R_NOMORE)
494 * Update the ctx state to reflect what we just printed.
495 * This is done last, only when we are sure we will return
496 * success, because this function may be called multiple
497 * times with increasing buffer sizes until it succeeds,
498 * and failed attempts must not update the state prematurely.
500 ctx->class_printed = ISC_TRUE;
501 ctx->current_ttl= current_ttl;
502 ctx->current_ttl_valid = current_ttl_valid;
504 return (ISC_R_SUCCESS);
508 * Print the name, type, and class of an empty rdataset,
509 * such as those used to represent the question section
513 question_totext(dns_rdataset_t *rdataset,
514 dns_name_t *owner_name,
515 dns_totext_ctx_t *ctx,
516 isc_boolean_t omit_final_dot,
517 isc_buffer_t *target)
523 REQUIRE(DNS_RDATASET_VALID(rdataset));
524 result = dns_rdataset_first(rdataset);
525 REQUIRE(result == ISC_R_NOMORE);
531 unsigned int name_start = target->used;
532 RETERR(dns_name_totext(owner_name,
535 column += target->used - name_start;
540 unsigned int class_start;
541 INDENT_TO(class_column);
542 class_start = target->used;
543 result = dns_rdataclass_totext(rdataset->rdclass, target);
544 if (result != ISC_R_SUCCESS)
546 column += (target->used - class_start);
551 unsigned int type_start;
552 INDENT_TO(type_column);
553 type_start = target->used;
554 result = dns_rdatatype_totext(rdataset->type, target);
555 if (result != ISC_R_SUCCESS)
557 column += (target->used - type_start);
560 isc_buffer_availableregion(target, &r);
562 return (ISC_R_NOSPACE);
564 isc_buffer_add(target, 1);
566 return (ISC_R_SUCCESS);
570 dns_rdataset_totext(dns_rdataset_t *rdataset,
571 dns_name_t *owner_name,
572 isc_boolean_t omit_final_dot,
573 isc_boolean_t question,
574 isc_buffer_t *target)
576 dns_totext_ctx_t ctx;
578 result = totext_ctx_init(&dns_master_style_debug, &ctx);
579 if (result != ISC_R_SUCCESS) {
580 UNEXPECTED_ERROR(__FILE__, __LINE__,
581 "could not set master file style");
582 return (ISC_R_UNEXPECTED);
586 * The caller might want to give us an empty owner
587 * name (e.g. if they are outputting into a master
588 * file and this rdataset has the same name as the
591 if (dns_name_countlabels(owner_name) == 0)
595 return (question_totext(rdataset, owner_name, &ctx,
596 omit_final_dot, target));
598 return (rdataset_totext(rdataset, owner_name, &ctx,
599 omit_final_dot, target));
603 dns_master_rdatasettotext(dns_name_t *owner_name,
604 dns_rdataset_t *rdataset,
605 const dns_master_style_t *style,
606 isc_buffer_t *target)
608 dns_totext_ctx_t ctx;
610 result = totext_ctx_init(style, &ctx);
611 if (result != ISC_R_SUCCESS) {
612 UNEXPECTED_ERROR(__FILE__, __LINE__,
613 "could not set master file style");
614 return (ISC_R_UNEXPECTED);
617 return (rdataset_totext(rdataset, owner_name, &ctx,
622 dns_master_questiontotext(dns_name_t *owner_name,
623 dns_rdataset_t *rdataset,
624 const dns_master_style_t *style,
625 isc_buffer_t *target)
627 dns_totext_ctx_t ctx;
629 result = totext_ctx_init(style, &ctx);
630 if (result != ISC_R_SUCCESS) {
631 UNEXPECTED_ERROR(__FILE__, __LINE__,
632 "could not set master file style");
633 return (ISC_R_UNEXPECTED);
636 return (question_totext(rdataset, owner_name, &ctx,
641 * Print an rdataset. 'buffer' is a scratch buffer, which must have been
642 * dynamically allocated by the caller. It must be large enough to
643 * hold the result from dns_ttl_totext(). If more than that is needed,
644 * the buffer will be grown automatically.
648 dump_rdataset(isc_mem_t *mctx, dns_name_t *name, dns_rdataset_t *rdataset,
649 dns_totext_ctx_t *ctx,
650 isc_buffer_t *buffer, FILE *f)
655 REQUIRE(buffer->length > 0);
658 * Output a $TTL directive if needed.
661 if ((ctx->style.flags & DNS_STYLEFLAG_TTL) != 0) {
662 if (ctx->current_ttl_valid == ISC_FALSE ||
663 ctx->current_ttl != rdataset->ttl)
665 if ((ctx->style.flags & DNS_STYLEFLAG_COMMENT) != 0)
667 isc_buffer_clear(buffer);
668 result = dns_ttl_totext(rdataset->ttl,
670 INSIST(result == ISC_R_SUCCESS);
671 isc_buffer_usedregion(buffer, &r);
672 fprintf(f, "$TTL %u\t; %.*s\n", rdataset->ttl,
673 (int) r.length, (char *) r.base);
675 fprintf(f, "$TTL %u\n", rdataset->ttl);
677 ctx->current_ttl = rdataset->ttl;
678 ctx->current_ttl_valid = ISC_TRUE;
682 isc_buffer_clear(buffer);
685 * Generate the text representation of the rdataset into
686 * the buffer. If the buffer is too small, grow it.
691 result = rdataset_totext(rdataset, name, ctx,
693 if (result != ISC_R_NOSPACE)
696 newlength = buffer->length * 2;
697 newmem = isc_mem_get(mctx, newlength);
699 return (ISC_R_NOMEMORY);
700 isc_mem_put(mctx, buffer->base, buffer->length);
701 isc_buffer_init(buffer, newmem, newlength);
703 if (result != ISC_R_SUCCESS)
707 * Write the buffer contents to the master file.
709 isc_buffer_usedregion(buffer, &r);
710 result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL);
712 if (result != ISC_R_SUCCESS) {
713 UNEXPECTED_ERROR(__FILE__, __LINE__,
714 "master file write failed: %s",
715 isc_result_totext(result));
719 return (ISC_R_SUCCESS);
723 * Define the order in which rdatasets should be printed in zone
724 * files. We will print SOA and NS records before others, SIGs
725 * immediately following the things they sign, and order everything
726 * else by RR number. This is all just for aesthetics and
727 * compatibility with buggy software that expects the SOA to be first;
728 * the DNS specifications allow any order.
732 dump_order(const dns_rdataset_t *rds) {
735 if (rds->type == dns_rdatatype_rrsig) {
743 case dns_rdatatype_soa:
746 case dns_rdatatype_ns:
753 return (t << 1) + sig;
757 dump_order_compare(const void *a, const void *b) {
758 return (dump_order(*((const dns_rdataset_t * const *) a)) -
759 dump_order(*((const dns_rdataset_t * const *) b)));
763 * Dump all the rdatasets of a domain name to a master file. We make
764 * a "best effort" attempt to sort the RRsets in a nice order, but if
765 * there are more than MAXSORT RRsets, we punt and only sort them in
766 * groups of MAXSORT. This is not expected to ever happen in practice
767 * since much less than 64 RR types have been registered with the
768 * IANA, so far, and the output will be correct (though not
769 * aesthetically pleasing) even if it does happen.
775 dump_rdatasets_text(isc_mem_t *mctx, dns_name_t *name,
776 dns_rdatasetiter_t *rdsiter, dns_totext_ctx_t *ctx,
777 isc_buffer_t *buffer, FILE *f)
779 isc_result_t itresult, dumpresult;
781 dns_rdataset_t rdatasets[MAXSORT];
782 dns_rdataset_t *sorted[MAXSORT];
785 itresult = dns_rdatasetiter_first(rdsiter);
786 dumpresult = ISC_R_SUCCESS;
788 if (itresult == ISC_R_SUCCESS && ctx->neworigin != NULL) {
789 isc_buffer_clear(buffer);
790 itresult = dns_name_totext(ctx->neworigin, ISC_FALSE, buffer);
791 RUNTIME_CHECK(itresult == ISC_R_SUCCESS);
792 isc_buffer_usedregion(buffer, &r);
793 fprintf(f, "$ORIGIN %.*s\n", (int) r.length, (char *) r.base);
794 ctx->neworigin = NULL;
799 itresult == ISC_R_SUCCESS && i < MAXSORT;
800 itresult = dns_rdatasetiter_next(rdsiter), i++) {
801 dns_rdataset_init(&rdatasets[i]);
802 dns_rdatasetiter_current(rdsiter, &rdatasets[i]);
803 sorted[i] = &rdatasets[i];
806 INSIST(n <= MAXSORT);
808 qsort(sorted, n, sizeof(sorted[0]), dump_order_compare);
810 for (i = 0; i < n; i++) {
811 dns_rdataset_t *rds = sorted[i];
812 if (ctx->style.flags & DNS_STYLEFLAG_TRUST)
813 fprintf(f, "; %s\n", dns_trust_totext(rds->trust));
814 if (((rds->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) &&
815 (ctx->style.flags & DNS_STYLEFLAG_NCACHE) == 0) {
816 /* Omit negative cache entries */
818 isc_result_t result =
819 dump_rdataset(mctx, name, rds, ctx,
821 if (result != ISC_R_SUCCESS)
823 if ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != 0)
826 if (ctx->style.flags & DNS_STYLEFLAG_RESIGN &&
827 rds->attributes & DNS_RDATASETATTR_RESIGN) {
829 char buf[sizeof("YYYYMMDDHHMMSS")];
830 memset(buf, 0, sizeof(buf));
831 isc_buffer_init(&b, buf, sizeof(buf) - 1);
832 dns_time64_totext((isc_uint64_t)rds->resign, &b);
833 fprintf(f, "; resign=%s\n", buf);
835 dns_rdataset_disassociate(rds);
838 if (dumpresult != ISC_R_SUCCESS)
842 * If we got more data than could be sorted at once,
843 * go handle the rest.
845 if (itresult == ISC_R_SUCCESS)
848 if (itresult == ISC_R_NOMORE)
849 itresult = ISC_R_SUCCESS;
855 * Dump given RRsets in the "raw" format.
858 dump_rdataset_raw(isc_mem_t *mctx, dns_name_t *name, dns_rdataset_t *rdataset,
859 isc_buffer_t *buffer, FILE *f)
862 isc_uint32_t totallen;
864 isc_region_t r, r_hdr;
866 REQUIRE(buffer->length > 0);
867 REQUIRE(DNS_RDATASET_VALID(rdataset));
871 result = dns_rdataset_first(rdataset);
872 REQUIRE(result == ISC_R_SUCCESS);
874 isc_buffer_clear(buffer);
877 * Common header and owner name (length followed by name)
878 * These fields should be in a moderate length, so we assume we
879 * can store all of them in the initial buffer.
881 isc_buffer_availableregion(buffer, &r_hdr);
882 INSIST(r_hdr.length >= sizeof(dns_masterrawrdataset_t));
883 isc_buffer_putuint32(buffer, totallen); /* XXX: leave space */
884 isc_buffer_putuint16(buffer, rdataset->rdclass); /* 16-bit class */
885 isc_buffer_putuint16(buffer, rdataset->type); /* 16-bit type */
886 isc_buffer_putuint16(buffer, rdataset->covers); /* same as type */
887 isc_buffer_putuint32(buffer, rdataset->ttl); /* 32-bit TTL */
888 isc_buffer_putuint32(buffer, dns_rdataset_count(rdataset));
889 totallen = isc_buffer_usedlength(buffer);
890 INSIST(totallen <= sizeof(dns_masterrawrdataset_t));
892 dns_name_toregion(name, &r);
893 INSIST(isc_buffer_availablelength(buffer) >=
894 (sizeof(dlen) + r.length));
895 dlen = (isc_uint16_t)r.length;
896 isc_buffer_putuint16(buffer, dlen);
897 isc_buffer_copyregion(buffer, &r);
898 totallen += sizeof(dlen) + r.length;
901 dns_rdata_t rdata = DNS_RDATA_INIT;
904 dns_rdataset_current(rdataset, &rdata);
905 dns_rdata_toregion(&rdata, &r);
906 INSIST(r.length <= 0xffffU);
907 dlen = (isc_uint16_t)r.length;
910 * Copy the rdata into the buffer. If the buffer is too small,
911 * grow it. This should be rare, so we'll simply restart the
912 * entire procedure (or should we copy the old data and
915 if (isc_buffer_availablelength(buffer) <
916 sizeof(dlen) + r.length) {
920 newlength = buffer->length * 2;
921 newmem = isc_mem_get(mctx, newlength);
923 return (ISC_R_NOMEMORY);
924 isc_mem_put(mctx, buffer->base, buffer->length);
925 isc_buffer_init(buffer, newmem, newlength);
928 isc_buffer_putuint16(buffer, dlen);
929 isc_buffer_copyregion(buffer, &r);
930 totallen += sizeof(dlen) + r.length;
932 result = dns_rdataset_next(rdataset);
933 } while (result == ISC_R_SUCCESS);
935 if (result != ISC_R_NOMORE)
939 * Fill in the total length field.
940 * XXX: this is a bit tricky. Since we have already "used" the space
941 * for the total length in the buffer, we first remember the entire
942 * buffer length in the region, "rewind", and then write the value.
944 isc_buffer_usedregion(buffer, &r);
945 isc_buffer_clear(buffer);
946 isc_buffer_putuint32(buffer, totallen);
947 INSIST(isc_buffer_usedlength(buffer) < totallen);
950 * Write the buffer contents to the raw master file.
952 result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL);
954 if (result != ISC_R_SUCCESS) {
955 UNEXPECTED_ERROR(__FILE__, __LINE__,
956 "raw master file write failed: %s",
957 isc_result_totext(result));
965 dump_rdatasets_raw(isc_mem_t *mctx, dns_name_t *name,
966 dns_rdatasetiter_t *rdsiter, dns_totext_ctx_t *ctx,
967 isc_buffer_t *buffer, FILE *f)
970 dns_rdataset_t rdataset;
972 for (result = dns_rdatasetiter_first(rdsiter);
973 result == ISC_R_SUCCESS;
974 result = dns_rdatasetiter_next(rdsiter)) {
976 dns_rdataset_init(&rdataset);
977 dns_rdatasetiter_current(rdsiter, &rdataset);
979 if (((rdataset.attributes & DNS_RDATASETATTR_NEGATIVE) != 0) &&
980 (ctx->style.flags & DNS_STYLEFLAG_NCACHE) == 0) {
981 /* Omit negative cache entries */
983 result = dump_rdataset_raw(mctx, name, &rdataset,
986 dns_rdataset_disassociate(&rdataset);
987 if (result != ISC_R_SUCCESS)
991 if (result == ISC_R_NOMORE)
992 result = ISC_R_SUCCESS;
998 * Initial size of text conversion buffer. The buffer is used
999 * for several purposes: converting origin names, rdatasets,
1000 * $DATE timestamps, and comment strings for $TTL directives.
1002 * When converting rdatasets, it is dynamically resized, but
1003 * when converting origins, timestamps, etc it is not. Therefore,
1004 * the initial size must large enough to hold the longest possible
1005 * text representation of any domain name (for $ORIGIN).
1007 static const int initial_buffer_length = 1200;
1010 dumptostreaminc(dns_dumpctx_t *dctx);
1013 dumpctx_destroy(dns_dumpctx_t *dctx) {
1016 DESTROYLOCK(&dctx->lock);
1017 dns_dbiterator_destroy(&dctx->dbiter);
1018 if (dctx->version != NULL)
1019 dns_db_closeversion(dctx->db, &dctx->version, ISC_FALSE);
1020 dns_db_detach(&dctx->db);
1021 if (dctx->task != NULL)
1022 isc_task_detach(&dctx->task);
1023 if (dctx->file != NULL)
1024 isc_mem_free(dctx->mctx, dctx->file);
1025 if (dctx->tmpfile != NULL)
1026 isc_mem_free(dctx->mctx, dctx->tmpfile);
1027 isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(*dctx));
1031 dns_dumpctx_attach(dns_dumpctx_t *source, dns_dumpctx_t **target) {
1033 REQUIRE(DNS_DCTX_VALID(source));
1034 REQUIRE(target != NULL && *target == NULL);
1036 LOCK(&source->lock);
1037 INSIST(source->references > 0);
1038 source->references++;
1039 INSIST(source->references != 0); /* Overflow? */
1040 UNLOCK(&source->lock);
1046 dns_dumpctx_detach(dns_dumpctx_t **dctxp) {
1047 dns_dumpctx_t *dctx;
1048 isc_boolean_t need_destroy = ISC_FALSE;
1050 REQUIRE(dctxp != NULL);
1052 REQUIRE(DNS_DCTX_VALID(dctx));
1057 INSIST(dctx->references != 0);
1059 if (dctx->references == 0)
1060 need_destroy = ISC_TRUE;
1061 UNLOCK(&dctx->lock);
1063 dumpctx_destroy(dctx);
1067 dns_dumpctx_version(dns_dumpctx_t *dctx) {
1068 REQUIRE(DNS_DCTX_VALID(dctx));
1069 return (dctx->version);
1073 dns_dumpctx_db(dns_dumpctx_t *dctx) {
1074 REQUIRE(DNS_DCTX_VALID(dctx));
1079 dns_dumpctx_cancel(dns_dumpctx_t *dctx) {
1080 REQUIRE(DNS_DCTX_VALID(dctx));
1083 dctx->canceled = ISC_TRUE;
1084 UNLOCK(&dctx->lock);
1088 closeandrename(FILE *f, isc_result_t result, const char *temp, const char *file)
1090 isc_result_t tresult;
1091 isc_boolean_t logit = ISC_TF(result == ISC_R_SUCCESS);
1093 if (result == ISC_R_SUCCESS)
1094 result = isc_stdio_sync(f);
1095 if (result != ISC_R_SUCCESS && logit) {
1096 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1097 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1098 "dumping master file: %s: fsync: %s",
1099 temp, isc_result_totext(result));
1102 tresult = isc_stdio_close(f);
1103 if (result == ISC_R_SUCCESS)
1105 if (result != ISC_R_SUCCESS && logit) {
1106 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1107 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1108 "dumping master file: %s: fclose: %s",
1109 temp, isc_result_totext(result));
1112 if (result == ISC_R_SUCCESS)
1113 result = isc_file_rename(temp, file);
1115 (void)isc_file_remove(temp);
1116 if (result != ISC_R_SUCCESS && logit) {
1117 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1118 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1119 "dumping master file: rename: %s: %s",
1120 file, isc_result_totext(result));
1126 dump_quantum(isc_task_t *task, isc_event_t *event) {
1127 isc_result_t result;
1128 isc_result_t tresult;
1129 dns_dumpctx_t *dctx;
1131 REQUIRE(event != NULL);
1132 dctx = event->ev_arg;
1133 REQUIRE(DNS_DCTX_VALID(dctx));
1135 result = ISC_R_CANCELED;
1137 result = dumptostreaminc(dctx);
1138 if (result == DNS_R_CONTINUE) {
1139 event->ev_arg = dctx;
1140 isc_task_send(task, &event);
1144 if (dctx->file != NULL) {
1145 tresult = closeandrename(dctx->f, result,
1146 dctx->tmpfile, dctx->file);
1147 if (tresult != ISC_R_SUCCESS && result == ISC_R_SUCCESS)
1150 (dctx->done)(dctx->done_arg, result);
1151 isc_event_free(&event);
1152 dns_dumpctx_detach(&dctx);
1156 task_send(dns_dumpctx_t *dctx) {
1159 event = isc_event_allocate(dctx->mctx, NULL, DNS_EVENT_DUMPQUANTUM,
1160 dump_quantum, dctx, sizeof(*event));
1162 return (ISC_R_NOMEMORY);
1163 isc_task_send(dctx->task, &event);
1164 return (ISC_R_SUCCESS);
1168 dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1169 const dns_master_style_t *style, FILE *f, dns_dumpctx_t **dctxp,
1170 dns_masterformat_t format)
1172 dns_dumpctx_t *dctx;
1173 isc_result_t result;
1174 unsigned int options;
1176 dctx = isc_mem_get(mctx, sizeof(*dctx));
1178 return (ISC_R_NOMEMORY);
1182 dctx->dbiter = NULL;
1184 dctx->version = NULL;
1186 dctx->done_arg = NULL;
1189 dctx->first = ISC_TRUE;
1190 dctx->canceled = ISC_FALSE;
1192 dctx->tmpfile = NULL;
1193 dctx->format = format;
1196 case dns_masterformat_text:
1197 dctx->dumpsets = dump_rdatasets_text;
1199 case dns_masterformat_raw:
1200 dctx->dumpsets = dump_rdatasets_raw;
1207 result = totext_ctx_init(style, &dctx->tctx);
1208 if (result != ISC_R_SUCCESS) {
1209 UNEXPECTED_ERROR(__FILE__, __LINE__,
1210 "could not set master file style");
1214 isc_stdtime_get(&dctx->now);
1215 dns_db_attach(db, &dctx->db);
1217 dctx->do_date = dns_db_iscache(dctx->db);
1219 if (dctx->format == dns_masterformat_text &&
1220 (dctx->tctx.style.flags & DNS_STYLEFLAG_REL_OWNER) != 0) {
1221 options = DNS_DB_RELATIVENAMES;
1224 result = dns_db_createiterator(dctx->db, options, &dctx->dbiter);
1225 if (result != ISC_R_SUCCESS)
1228 result = isc_mutex_init(&dctx->lock);
1229 if (result != ISC_R_SUCCESS)
1231 if (version != NULL)
1232 dns_db_attachversion(dctx->db, version, &dctx->version);
1233 else if (!dns_db_iscache(db))
1234 dns_db_currentversion(dctx->db, &dctx->version);
1235 isc_mem_attach(mctx, &dctx->mctx);
1236 dctx->references = 1;
1237 dctx->magic = DNS_DCTX_MAGIC;
1239 return (ISC_R_SUCCESS);
1242 if (dctx->dbiter != NULL)
1243 dns_dbiterator_destroy(&dctx->dbiter);
1244 if (dctx->db != NULL)
1245 dns_db_detach(&dctx->db);
1247 isc_mem_put(mctx, dctx, sizeof(*dctx));
1252 dumptostreaminc(dns_dumpctx_t *dctx) {
1253 isc_result_t result;
1254 isc_buffer_t buffer;
1258 dns_fixedname_t fixname;
1260 dns_masterrawheader_t rawheader;
1264 bufmem = isc_mem_get(dctx->mctx, initial_buffer_length);
1266 return (ISC_R_NOMEMORY);
1268 isc_buffer_init(&buffer, bufmem, initial_buffer_length);
1270 dns_fixedname_init(&fixname);
1271 name = dns_fixedname_name(&fixname);
1274 switch (dctx->format) {
1275 case dns_masterformat_text:
1277 * If the database has cache semantics, output an
1278 * RFC2540 $DATE directive so that the TTLs can be
1279 * adjusted when it is reloaded. For zones it is not
1280 * really needed, and it would make the file
1281 * incompatible with pre-RFC2540 software, so we omit
1282 * it in the zone case.
1284 if (dctx->do_date) {
1285 result = dns_time32_totext(dctx->now, &buffer);
1286 RUNTIME_CHECK(result == ISC_R_SUCCESS);
1287 isc_buffer_usedregion(&buffer, &r);
1288 fprintf(dctx->f, "$DATE %.*s\n",
1289 (int) r.length, (char *) r.base);
1292 case dns_masterformat_raw:
1293 r.base = (unsigned char *)&rawheader;
1294 r.length = sizeof(rawheader);
1295 isc_buffer_region(&buffer, &r);
1296 isc_buffer_putuint32(&buffer, dns_masterformat_raw);
1297 isc_buffer_putuint32(&buffer, DNS_RAWFORMAT_VERSION);
1298 #if !defined(STDTIME_ON_32BITS) || (STDTIME_ON_32BITS + 0) != 1
1300 * We assume isc_stdtime_t is a 32-bit integer,
1301 * which should be the case on most cases.
1302 * If it turns out to be uncommon, we'll need
1303 * to bump the version number and revise the
1306 isc_log_write(dns_lctx,
1307 ISC_LOGCATEGORY_GENERAL,
1308 DNS_LOGMODULE_MASTERDUMP,
1310 "dumping master file in raw "
1311 "format: stdtime is not 32bits");
1316 isc_buffer_putuint32(&buffer, now32);
1317 INSIST(isc_buffer_usedlength(&buffer) <=
1319 result = isc_stdio_write(buffer.base, 1,
1320 isc_buffer_usedlength(&buffer),
1322 if (result != ISC_R_SUCCESS)
1324 isc_buffer_clear(&buffer);
1330 result = dns_dbiterator_first(dctx->dbiter);
1331 dctx->first = ISC_FALSE;
1333 result = ISC_R_SUCCESS;
1335 nodes = dctx->nodes;
1336 isc_time_now(&start);
1337 while (result == ISC_R_SUCCESS && (dctx->nodes == 0 || nodes--)) {
1338 dns_rdatasetiter_t *rdsiter = NULL;
1339 dns_dbnode_t *node = NULL;
1341 result = dns_dbiterator_current(dctx->dbiter, &node, name);
1342 if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN)
1344 if (result == DNS_R_NEWORIGIN) {
1345 dns_name_t *origin =
1346 dns_fixedname_name(&dctx->tctx.origin_fixname);
1347 result = dns_dbiterator_origin(dctx->dbiter, origin);
1348 RUNTIME_CHECK(result == ISC_R_SUCCESS);
1349 if ((dctx->tctx.style.flags & DNS_STYLEFLAG_REL_DATA) != 0)
1350 dctx->tctx.origin = origin;
1351 dctx->tctx.neworigin = origin;
1353 result = dns_db_allrdatasets(dctx->db, node, dctx->version,
1354 dctx->now, &rdsiter);
1355 if (result != ISC_R_SUCCESS) {
1356 dns_db_detachnode(dctx->db, &node);
1359 result = (dctx->dumpsets)(dctx->mctx, name, rdsiter,
1360 &dctx->tctx, &buffer, dctx->f);
1361 dns_rdatasetiter_destroy(&rdsiter);
1362 if (result != ISC_R_SUCCESS) {
1363 dns_db_detachnode(dctx->db, &node);
1366 dns_db_detachnode(dctx->db, &node);
1367 result = dns_dbiterator_next(dctx->dbiter);
1371 * Work out how many nodes can be written in the time between
1372 * two requests to the nameserver. Smooth the resulting number and
1373 * use it as a estimate for the number of nodes to be written in the
1376 if (dctx->nodes != 0 && result == ISC_R_SUCCESS) {
1377 unsigned int pps = dns_pps; /* packets per second */
1378 unsigned int interval;
1385 interval = 1000000 / pps; /* interval in usecs */
1388 usecs = isc_time_microdiff(&end, &start);
1390 dctx->nodes = dctx->nodes * 2;
1391 if (dctx->nodes > 1000)
1394 nodes = dctx->nodes * interval;
1395 nodes /= (unsigned int)usecs;
1398 else if (nodes > 1000)
1401 /* Smooth and assign. */
1402 dctx->nodes = (nodes + dctx->nodes * 7) / 8;
1404 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1405 DNS_LOGMODULE_MASTERDUMP,
1407 "dumptostreaminc(%p) new nodes -> %d\n",
1410 result = DNS_R_CONTINUE;
1411 } else if (result == ISC_R_NOMORE)
1412 result = ISC_R_SUCCESS;
1414 RUNTIME_CHECK(dns_dbiterator_pause(dctx->dbiter) == ISC_R_SUCCESS);
1415 isc_mem_put(dctx->mctx, buffer.base, buffer.length);
1420 dns_master_dumptostreaminc(isc_mem_t *mctx, dns_db_t *db,
1421 dns_dbversion_t *version,
1422 const dns_master_style_t *style,
1423 FILE *f, isc_task_t *task,
1424 dns_dumpdonefunc_t done, void *done_arg,
1425 dns_dumpctx_t **dctxp)
1427 dns_dumpctx_t *dctx = NULL;
1428 isc_result_t result;
1430 REQUIRE(task != NULL);
1432 REQUIRE(done != NULL);
1434 result = dumpctx_create(mctx, db, version, style, f, &dctx,
1435 dns_masterformat_text);
1436 if (result != ISC_R_SUCCESS)
1438 isc_task_attach(task, &dctx->task);
1440 dctx->done_arg = done_arg;
1443 result = task_send(dctx);
1444 if (result == ISC_R_SUCCESS) {
1445 dns_dumpctx_attach(dctx, dctxp);
1446 return (DNS_R_CONTINUE);
1449 dns_dumpctx_detach(&dctx);
1454 * Dump an entire database into a master file.
1457 dns_master_dumptostream(isc_mem_t *mctx, dns_db_t *db,
1458 dns_dbversion_t *version,
1459 const dns_master_style_t *style,
1462 return (dns_master_dumptostream2(mctx, db, version, style,
1463 dns_masterformat_text, f));
1467 dns_master_dumptostream2(isc_mem_t *mctx, dns_db_t *db,
1468 dns_dbversion_t *version,
1469 const dns_master_style_t *style,
1470 dns_masterformat_t format, FILE *f)
1472 dns_dumpctx_t *dctx = NULL;
1473 isc_result_t result;
1475 result = dumpctx_create(mctx, db, version, style, f, &dctx, format);
1476 if (result != ISC_R_SUCCESS)
1479 result = dumptostreaminc(dctx);
1480 INSIST(result != DNS_R_CONTINUE);
1481 dns_dumpctx_detach(&dctx);
1486 opentmp(isc_mem_t *mctx, const char *file, char **tempp, FILE **fp) {
1488 isc_result_t result;
1489 char *tempname = NULL;
1492 tempnamelen = strlen(file) + 20;
1493 tempname = isc_mem_allocate(mctx, tempnamelen);
1494 if (tempname == NULL)
1495 return (ISC_R_NOMEMORY);
1497 result = isc_file_mktemplate(file, tempname, tempnamelen);
1498 if (result != ISC_R_SUCCESS)
1501 result = isc_file_openunique(tempname, &f);
1502 if (result != ISC_R_SUCCESS) {
1503 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1504 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1505 "dumping master file: %s: open: %s",
1506 tempname, isc_result_totext(result));
1511 return (ISC_R_SUCCESS);
1514 isc_mem_free(mctx, tempname);
1519 dns_master_dumpinc(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1520 const dns_master_style_t *style, const char *filename,
1521 isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
1522 dns_dumpctx_t **dctxp)
1524 return (dns_master_dumpinc2(mctx, db, version, style, filename, task,
1525 done, done_arg, dctxp,
1526 dns_masterformat_text));
1530 dns_master_dumpinc2(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1531 const dns_master_style_t *style, const char *filename,
1532 isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
1533 dns_dumpctx_t **dctxp, dns_masterformat_t format)
1536 isc_result_t result;
1537 char *tempname = NULL;
1539 dns_dumpctx_t *dctx = NULL;
1541 file = isc_mem_strdup(mctx, filename);
1543 return (ISC_R_NOMEMORY);
1545 result = opentmp(mctx, filename, &tempname, &f);
1546 if (result != ISC_R_SUCCESS)
1549 result = dumpctx_create(mctx, db, version, style, f, &dctx, format);
1550 if (result != ISC_R_SUCCESS) {
1551 (void)isc_stdio_close(f);
1552 (void)isc_file_remove(tempname);
1556 isc_task_attach(task, &dctx->task);
1558 dctx->done_arg = done_arg;
1562 dctx->tmpfile = tempname;
1565 result = task_send(dctx);
1566 if (result == ISC_R_SUCCESS) {
1567 dns_dumpctx_attach(dctx, dctxp);
1568 return (DNS_R_CONTINUE);
1573 dns_dumpctx_detach(&dctx);
1575 isc_mem_free(mctx, file);
1576 if (tempname != NULL)
1577 isc_mem_free(mctx, tempname);
1582 dns_master_dump(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1583 const dns_master_style_t *style, const char *filename)
1585 return (dns_master_dump2(mctx, db, version, style, filename,
1586 dns_masterformat_text));
1590 dns_master_dump2(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1591 const dns_master_style_t *style, const char *filename,
1592 dns_masterformat_t format)
1595 isc_result_t result;
1597 dns_dumpctx_t *dctx = NULL;
1599 result = opentmp(mctx, filename, &tempname, &f);
1600 if (result != ISC_R_SUCCESS)
1603 result = dumpctx_create(mctx, db, version, style, f, &dctx, format);
1604 if (result != ISC_R_SUCCESS)
1607 result = dumptostreaminc(dctx);
1608 INSIST(result != DNS_R_CONTINUE);
1609 dns_dumpctx_detach(&dctx);
1611 result = closeandrename(f, result, tempname, filename);
1614 isc_mem_free(mctx, tempname);
1619 * Dump a database node into a master file.
1620 * XXX: this function assumes the text format.
1623 dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db,
1624 dns_dbversion_t *version,
1625 dns_dbnode_t *node, dns_name_t *name,
1626 const dns_master_style_t *style,
1629 isc_result_t result;
1630 isc_buffer_t buffer;
1633 dns_totext_ctx_t ctx;
1634 dns_rdatasetiter_t *rdsiter = NULL;
1636 result = totext_ctx_init(style, &ctx);
1637 if (result != ISC_R_SUCCESS) {
1638 UNEXPECTED_ERROR(__FILE__, __LINE__,
1639 "could not set master file style");
1640 return (ISC_R_UNEXPECTED);
1643 isc_stdtime_get(&now);
1645 bufmem = isc_mem_get(mctx, initial_buffer_length);
1647 return (ISC_R_NOMEMORY);
1649 isc_buffer_init(&buffer, bufmem, initial_buffer_length);
1651 result = dns_db_allrdatasets(db, node, version, now, &rdsiter);
1652 if (result != ISC_R_SUCCESS)
1654 result = dump_rdatasets_text(mctx, name, rdsiter, &ctx, &buffer, f);
1655 if (result != ISC_R_SUCCESS)
1657 dns_rdatasetiter_destroy(&rdsiter);
1659 result = ISC_R_SUCCESS;
1662 isc_mem_put(mctx, buffer.base, buffer.length);
1667 dns_master_dumpnode(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
1668 dns_dbnode_t *node, dns_name_t *name,
1669 const dns_master_style_t *style, const char *filename)
1672 isc_result_t result;
1674 result = isc_stdio_open(filename, "w", &f);
1675 if (result != ISC_R_SUCCESS) {
1676 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1677 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1678 "dumping node to file: %s: open: %s", filename,
1679 isc_result_totext(result));
1680 return (ISC_R_UNEXPECTED);
1683 result = dns_master_dumpnodetostream(mctx, db, version, node, name,
1685 if (result != ISC_R_SUCCESS) {
1686 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1687 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1688 "dumping master file: %s: dump: %s", filename,
1689 isc_result_totext(result));
1690 (void)isc_stdio_close(f);
1691 return (ISC_R_UNEXPECTED);
1694 result = isc_stdio_close(f);
1695 if (result != ISC_R_SUCCESS) {
1696 isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL,
1697 DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR,
1698 "dumping master file: %s: close: %s", filename,
1699 isc_result_totext(result));
1700 return (ISC_R_UNEXPECTED);
1707 dns_master_stylecreate(dns_master_style_t **stylep, unsigned int flags,
1708 unsigned int ttl_column, unsigned int class_column,
1709 unsigned int type_column, unsigned int rdata_column,
1710 unsigned int line_length, unsigned int tab_width,
1713 dns_master_style_t *style;
1715 REQUIRE(stylep != NULL && *stylep == NULL);
1716 style = isc_mem_get(mctx, sizeof(*style));
1718 return (ISC_R_NOMEMORY);
1720 style->flags = flags;
1721 style->ttl_column = ttl_column;
1722 style->class_column = class_column;
1723 style->type_column = type_column;
1724 style->rdata_column = rdata_column;
1725 style->line_length = line_length;
1726 style->tab_width = tab_width;
1729 return (ISC_R_SUCCESS);
1733 dns_master_styledestroy(dns_master_style_t **stylep, isc_mem_t *mctx) {
1734 dns_master_style_t *style;
1736 REQUIRE(stylep != NULL && *stylep != NULL);
1739 isc_mem_put(mctx, style, sizeof(*style));