1/* 2 * Copyright (C) 2004-2009, 2012 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 1999-2002 Internet Software Consortium. 4 * 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. 8 * 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. 16 */ 17 18/* $Id$ */ 19 20#ifndef DNS_MASTER_H 21#define DNS_MASTER_H 1 22 23/*! \file dns/master.h */ 24 25/*** 26 *** Imports 27 ***/ 28 29#include <stdio.h> 30 31#include <isc/lang.h> 32 33#include <dns/types.h> 34 35/* 36 * Flags to be passed in the 'options' argument in the functions below. 37 */ 38#define DNS_MASTER_AGETTL 0x00000001 /*%< Age the ttl based on $DATE. */ 39#define DNS_MASTER_MANYERRORS 0x00000002 /*%< Continue processing on errors. */ 40#define DNS_MASTER_NOINCLUDE 0x00000004 /*%< Disallow $INCLUDE directives. */ 41#define DNS_MASTER_ZONE 0x00000008 /*%< Loading a zone master file. */ 42#define DNS_MASTER_HINT 0x00000010 /*%< Loading a hint master file. */ 43#define DNS_MASTER_SLAVE 0x00000020 /*%< Loading a slave master file. */ 44#define DNS_MASTER_CHECKNS 0x00000040 /*%< 45 * Check NS records to see 46 * if they are an address 47 */ 48#define DNS_MASTER_FATALNS 0x00000080 /*%< 49 * Treat DNS_MASTER_CHECKNS 50 * matches as fatal 51 */ 52#define DNS_MASTER_CHECKNAMES 0x00000100 53#define DNS_MASTER_CHECKNAMESFAIL 0x00000200 54#define DNS_MASTER_CHECKWILDCARD 0x00000400 /* Check for internal wildcards. */ 55#define DNS_MASTER_CHECKMX 0x00000800 56#define DNS_MASTER_CHECKMXFAIL 0x00001000 57 58#define DNS_MASTER_RESIGN 0x00002000 59#define DNS_MASTER_KEY 0x00004000 /*%< Loading a key zone master file. */ 60 61ISC_LANG_BEGINDECLS 62 63/* 64 * Structures that implement the "raw" format for master dump. 65 * These are provided for a reference purpose only; in the actual 66 * encoding, we directly read/write each field so that the encoded data 67 * is always "packed", regardless of the hardware architecture. 68 */ 69#define DNS_RAWFORMAT_VERSION 0 70 71/* Common header */ 72typedef struct { 73 isc_uint32_t format; /* must be 74 * dns_masterformat_raw */ 75 isc_uint32_t version; /* compatibility for future 76 * extensions */ 77 isc_uint32_t dumptime; /* timestamp on creation 78 * (currently unused) 79 */ 80} dns_masterrawheader_t; 81 82/* The structure for each RRset */ 83typedef struct { 84 isc_uint32_t totallen; /* length of the data for this 85 * RRset, including the 86 * "header" part */ 87 dns_rdataclass_t rdclass; /* 16-bit class */ 88 dns_rdatatype_t type; /* 16-bit type */ 89 dns_rdatatype_t covers; /* same as type */ 90 dns_ttl_t ttl; /* 32-bit TTL */ 91 isc_uint32_t nrdata; /* number of RRs in this set */ 92 /* followed by encoded owner name, and then rdata */ 93} dns_masterrawrdataset_t; 94 95/*** 96 *** Function 97 ***/ 98 99isc_result_t 100dns_master_loadfile(const char *master_file, 101 dns_name_t *top, 102 dns_name_t *origin, 103 dns_rdataclass_t zclass, 104 unsigned int options, 105 dns_rdatacallbacks_t *callbacks, 106 isc_mem_t *mctx); 107 108isc_result_t 109dns_master_loadfile2(const char *master_file, 110 dns_name_t *top, 111 dns_name_t *origin, 112 dns_rdataclass_t zclass, 113 unsigned int options, 114 dns_rdatacallbacks_t *callbacks, 115 isc_mem_t *mctx, 116 dns_masterformat_t format); 117 118isc_result_t 119dns_master_loadfile3(const char *master_file, 120 dns_name_t *top, 121 dns_name_t *origin, 122 dns_rdataclass_t zclass, 123 unsigned int options, 124 isc_uint32_t resign, 125 dns_rdatacallbacks_t *callbacks, 126 isc_mem_t *mctx, 127 dns_masterformat_t format); 128 129isc_result_t 130dns_master_loadstream(FILE *stream, 131 dns_name_t *top, 132 dns_name_t *origin, 133 dns_rdataclass_t zclass, 134 unsigned int options, 135 dns_rdatacallbacks_t *callbacks, 136 isc_mem_t *mctx); 137 138isc_result_t 139dns_master_loadbuffer(isc_buffer_t *buffer, 140 dns_name_t *top, 141 dns_name_t *origin, 142 dns_rdataclass_t zclass, 143 unsigned int options, 144 dns_rdatacallbacks_t *callbacks, 145 isc_mem_t *mctx); 146 147isc_result_t 148dns_master_loadlexer(isc_lex_t *lex, 149 dns_name_t *top, 150 dns_name_t *origin, 151 dns_rdataclass_t zclass, 152 unsigned int options, 153 dns_rdatacallbacks_t *callbacks, 154 isc_mem_t *mctx); 155 156isc_result_t 157dns_master_loadfileinc(const char *master_file, 158 dns_name_t *top, 159 dns_name_t *origin, 160 dns_rdataclass_t zclass, 161 unsigned int options, 162 dns_rdatacallbacks_t *callbacks, 163 isc_task_t *task, 164 dns_loaddonefunc_t done, void *done_arg, 165 dns_loadctx_t **ctxp, isc_mem_t *mctx); 166 167isc_result_t 168dns_master_loadfileinc2(const char *master_file, 169 dns_name_t *top, 170 dns_name_t *origin, 171 dns_rdataclass_t zclass, 172 unsigned int options, 173 dns_rdatacallbacks_t *callbacks, 174 isc_task_t *task, 175 dns_loaddonefunc_t done, void *done_arg, 176 dns_loadctx_t **ctxp, isc_mem_t *mctx, 177 dns_masterformat_t format); 178 179isc_result_t 180dns_master_loadfileinc3(const char *master_file, 181 dns_name_t *top, 182 dns_name_t *origin, 183 dns_rdataclass_t zclass, 184 unsigned int options, 185 isc_uint32_t resign, 186 dns_rdatacallbacks_t *callbacks, 187 isc_task_t *task, 188 dns_loaddonefunc_t done, void *done_arg, 189 dns_loadctx_t **ctxp, isc_mem_t *mctx, 190 dns_masterformat_t format); 191 192isc_result_t 193dns_master_loadstreaminc(FILE *stream, 194 dns_name_t *top, 195 dns_name_t *origin, 196 dns_rdataclass_t zclass, 197 unsigned int options, 198 dns_rdatacallbacks_t *callbacks, 199 isc_task_t *task, 200 dns_loaddonefunc_t done, void *done_arg, 201 dns_loadctx_t **ctxp, isc_mem_t *mctx); 202 203isc_result_t 204dns_master_loadbufferinc(isc_buffer_t *buffer, 205 dns_name_t *top, 206 dns_name_t *origin, 207 dns_rdataclass_t zclass, 208 unsigned int options, 209 dns_rdatacallbacks_t *callbacks, 210 isc_task_t *task, 211 dns_loaddonefunc_t done, void *done_arg, 212 dns_loadctx_t **ctxp, isc_mem_t *mctx); 213 214isc_result_t 215dns_master_loadlexerinc(isc_lex_t *lex, 216 dns_name_t *top, 217 dns_name_t *origin, 218 dns_rdataclass_t zclass, 219 unsigned int options, 220 dns_rdatacallbacks_t *callbacks, 221 isc_task_t *task, 222 dns_loaddonefunc_t done, void *done_arg, 223 dns_loadctx_t **ctxp, isc_mem_t *mctx); 224 225/*%< 226 * Loads a RFC1305 master file from a file, stream, buffer, or existing 227 * lexer into rdatasets and then calls 'callbacks->commit' to commit the 228 * rdatasets. Rdata memory belongs to dns_master_load and will be 229 * reused / released when the callback completes. dns_load_master will 230 * abort if callbacks->commit returns any value other than ISC_R_SUCCESS. 231 * 232 * If 'DNS_MASTER_AGETTL' is set and the master file contains one or more 233 * $DATE directives, the TTLs of the data will be aged accordingly. 234 * 235 * 'callbacks->commit' is assumed to call 'callbacks->error' or 236 * 'callbacks->warn' to generate any error messages required. 237 * 238 * 'done' is called with 'done_arg' and a result code when the loading 239 * is completed or has failed. If the initial setup fails 'done' is 240 * not called. 241 * 242 * 'resign' the number of seconds before a RRSIG expires that it should 243 * be re-signed. 0 is used if not provided. 244 * 245 * Requires: 246 *\li 'master_file' points to a valid string. 247 *\li 'lexer' points to a valid lexer. 248 *\li 'top' points to a valid name. 249 *\li 'origin' points to a valid name. 250 *\li 'callbacks->commit' points to a valid function. 251 *\li 'callbacks->error' points to a valid function. 252 *\li 'callbacks->warn' points to a valid function. 253 *\li 'mctx' points to a valid memory context. 254 *\li 'task' and 'done' to be valid. 255 *\li 'lmgr' to be valid. 256 *\li 'ctxp != NULL && ctxp == NULL'. 257 * 258 * Returns: 259 *\li ISC_R_SUCCESS upon successfully loading the master file. 260 *\li ISC_R_SEENINCLUDE upon successfully loading the master file with 261 * a $INCLUDE statement. 262 *\li ISC_R_NOMEMORY out of memory. 263 *\li ISC_R_UNEXPECTEDEND expected to be able to read a input token and 264 * there was not one. 265 *\li ISC_R_UNEXPECTED 266 *\li DNS_R_NOOWNER failed to specify a ownername. 267 *\li DNS_R_NOTTL failed to specify a ttl. 268 *\li DNS_R_BADCLASS record class did not match zone class. 269 *\li DNS_R_CONTINUE load still in progress (dns_master_load*inc() only). 270 *\li Any dns_rdata_fromtext() error code. 271 *\li Any error code from callbacks->commit(). 272 */ 273 274void 275dns_loadctx_detach(dns_loadctx_t **ctxp); 276/*%< 277 * Detach from the load context. 278 * 279 * Requires: 280 *\li '*ctxp' to be valid. 281 * 282 * Ensures: 283 *\li '*ctxp == NULL' 284 */ 285 286void 287dns_loadctx_attach(dns_loadctx_t *source, dns_loadctx_t **target); 288/*%< 289 * Attach to the load context. 290 * 291 * Requires: 292 *\li 'source' to be valid. 293 *\li 'target != NULL && *target == NULL'. 294 */ 295 296void 297dns_loadctx_cancel(dns_loadctx_t *ctx); 298/*%< 299 * Cancel loading the zone file associated with this load context. 300 * 301 * Requires: 302 *\li 'ctx' to be valid 303 */ 304 305ISC_LANG_ENDDECLS 306 307#endif /* DNS_MASTER_H */ 308