masterdump.c revision 2674e1a455d4f71de09b2b60e7a8304b9a305588
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews/* $Id: masterdump.c,v 1.83 2005/11/30 03:33:49 marka Exp $ */
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews#define DNS_DCTX_MAGIC ISC_MAGIC('D', 'c', 't', 'x')
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews#define DNS_DCTX_VALID(d) ISC_MAGIC_VALID(d, DNS_DCTX_MAGIC)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews#define RETERR(x) do { \
90880946803188d7c6b3ca7dea69761eb21241c2Mark Andrews * The maximum length of the newline+indentation that is output
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington * when inserting a line break in an RR. This effectively puts an
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington * upper limits on the value of "rdata_column", because if it is
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington * very large, the tabs and spaces needed to reach it will not fit.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * Context structure for a masterfile dump in progress.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstypedef struct dns_totext_ctx {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson char linebreak_buf[DNS_TOTEXT_LINEBREAK_MAXLEN];
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian WellingtonLIBDNS_EXTERNAL_DATA const dns_master_style_t
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * A style suitable for dns_rdataset_totext().
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas GustafssonLIBDNS_EXTERNAL_DATA const dns_master_style_t
9f139761ca06977d1db8051842efc620c15b8199Andreas Gustafssonstatic char tabs[N_TABS+1] = "\t\t\t\t\t\t\t\t\t\t";
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int magic;
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater /* dns_master_dumpinc() */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_result_t (*dumpsets)(isc_mem_t *mctx, dns_name_t *name,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define NXDOMAIN(x) (((x)->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Output tabs and spaces to go from column '*current' to
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * column 'to', and update '*current' to reflect the new
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * current column.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsindent(unsigned int *current, unsigned int to, int tabwidth,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned char *p;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int from;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstotext_ctx_init(const dns_master_style_t *style, dns_totext_ctx_t *ctx) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Set up the line break string if needed.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if ((ctx->style.flags & DNS_STYLEFLAG_MULTILINE) != 0) {
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson unsigned int col = 0;
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews * Do not return ISC_R_NOSPACE if the line break string
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews * buffer is too small, because that would just make
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews * dump_rdataset() retry indenfinitely with ever
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews * bigger target buffers. That's a different buffer,
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington * so it won't help. Use DNS_R_TEXTTOOLONG as a substitute.
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews if ((result = indent(&column, ctx->style.col, \
05f90cac85760b4edef2962209df49ea019c180fMark Andrewsstr_totext(const char *source, isc_buffer_t *target) {
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews unsigned int l;
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews * Convert 'rdataset' to master file text format according to 'ctx',
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews * storing the result in 'target'. If 'owner_name' is NULL, it
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff * is omitted; otherwise 'owner_name' must be valid and have at least
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews * one label.
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews unsigned int column;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * Owner name.
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff ! ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != 0 &&
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley if ((ctx->style.flags & DNS_STYLEFLAG_NO_TTL) == 0 &&
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley !((ctx->style.flags & DNS_STYLEFLAG_OMIT_TTL) != 0 &&
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley unsigned int length;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * If the $TTL directive is not in use, the TTL we
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * just printed becomes the default for subsequent RRs.
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if ((ctx->style.flags & DNS_STYLEFLAG_TTL) == 0) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if ((ctx->style.flags & DNS_STYLEFLAG_NO_CLASS) == 0 &&
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews ((ctx->style.flags & DNS_STYLEFLAG_OMIT_CLASS) == 0 ||
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews result = dns_rdataclass_totext(rdataset->rdclass,
return (result);
isc_region_t r;
target));
return (ISC_R_NOSPACE);
return (result);
return (ISC_R_SUCCESS);
static isc_result_t
unsigned int column;
isc_region_t r;
column = 0;
target));
unsigned int class_start;
return (result);
unsigned int type_start;
return (result);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
return (ISC_R_UNEXPECTED);
if (question)
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
static isc_result_t
isc_region_t r;
int newlength;
void *newmem;
return (ISC_R_NOMEMORY);
return (result);
return (result);
return (ISC_R_SUCCESS);
int sig;
sig = 0;
case dns_rdatatype_soa:
case dns_rdatatype_ns:
dump_order_compare(const void *a, const void *b) {
static const char *trustnames[] = {
static isc_result_t
isc_region_t r;
sizeof(trustnames[0])));
buffer, f);
return (dumpresult);
goto again;
return (itresult);
static isc_result_t
totallen = 0;
isc_region_t r;
int newlength;
void *newmem;
return (ISC_R_NOMEMORY);
goto restart;
return (result);
return (result);
return (result);
static isc_result_t
buffer, f);
return (result);
static isc_result_t
if (need_destroy)
dns_db_t *
static isc_result_t
return (result);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMEMORY);
dctx->f = f;
switch (format) {
case dns_masterformat_text:
case dns_masterformat_raw:
INSIST(0);
goto cleanup;
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
char *bufmem;
isc_region_t r;
unsigned int nodes;
return (ISC_R_NOMEMORY);
case dns_masterformat_text:
case dns_masterformat_raw:
now32 = 0;
sizeof(rawheader));
return (result);
INSIST(0);
goto fail;
goto fail;
unsigned int interval;
if (interval == 0)
if (usecs == 0) {
if (nodes == 0)
fail:
return (result);
return (result);
return (DNS_R_CONTINUE);
return (result);
FILE *f)
dns_masterformat_text, f));
return (result);
return (result);
static isc_result_t
int tempnamelen;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
*fp = f;
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_NOMEMORY);
goto cleanup;
(void)isc_stdio_close(f);
goto cleanup;
return (DNS_R_CONTINUE);
return (result);
char *tempname;
return (result);
goto cleanup;
return (result);
FILE *f)
char *bufmem;
return (ISC_R_UNEXPECTED);
return (ISC_R_NOMEMORY);
goto failure;
goto failure;
return (result);
return (ISC_R_UNEXPECTED);
style, f);
return (ISC_R_UNEXPECTED);
return (result);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);