18 static void print_usage(
const char* progname)
20 printf(
"Usage: %s [OPTIONS] <zonefile>\n", progname);
21 printf(
"\tReads the zonefile and prints it.\n");
22 printf(
"\tThe RR count of the zone is printed to stderr.\n");
23 printf(
"\t-0 zeroize timestamps and signature in RRSIG records.\n");
24 printf(
"\t-b include Bubble Babble encoding of DS's.\n");
25 printf(
"\t-c canonicalize all rrs in the zone.\n");
26 printf(
"\t-d only show DNSSEC data from the zone\n");
27 printf(
"\t-e <rr type>\n");
28 printf(
"\t\tDo not print RRs of the given <rr type>.\n");
29 printf(
"\t\tThis option may be given multiple times.\n");
30 printf(
"\t\t-e is not meant to be used together with -E.\n");
31 printf(
"\t-E <rr type>\n");
32 printf(
"\t\tPrint only RRs of the given <rr type>.\n");
33 printf(
"\t\tThis option may be given multiple times.\n");
34 printf(
"\t\t-E is not meant to be used together with -e.\n");
35 printf(
"\t-h show this text\n");
36 printf(
"\t-n do not print the SOA record\n");
37 printf(
"\t-p prepend SOA serial with spaces so"
38 " it takes exactly ten characters.\n");
39 printf(
"\t-s strip DNSSEC data from the zone\n");
40 printf(
"\t-S [[+|-]<number> | YYYYMMDDxx | "
42 "\t\tSet serial number to <number> or,"
43 " when preceded by a sign,\n"
44 "\t\toffset the existing number with "
45 "<number>. With YYYYMMDDxx\n"
46 "\t\tthe serial is formatted as a datecounter"
47 ", and with unixtime as\n"
48 "\t\tthe number of seconds since 1-1-1970."
49 " However, on serial\n"
50 "\t\tnumber decrease, +1 is used in stead"
52 printf(
"\t-u <rr type>\n");
53 printf(
"\t\tMark <rr type> for printing in unknown type format.\n");
54 printf(
"\t\tThis option may be given multiple times.\n");
55 printf(
"\t\t-u is not meant to be used together with -U.\n");
56 printf(
"\t-U <rr type>\n");
57 printf(
"\t\tMark <rr type> for not printing in unknown type format.\n");
58 printf(
"\t\tThis option may be given multiple times.\n");
60 "\t\tThe first occurrence of the -U option marks all RR types for"
61 "\n\t\tprinting in unknown type format except for the given <rr type>."
62 "\n\t\tSubsequent -U options will clear the mark for those <rr type>s"
63 "\n\t\ttoo, so that only the given <rr type>s will be printed in the"
64 "\n\t\tpresentation format specific for those <rr type>s.\n");
65 printf(
"\t\t-U is not meant to be used together with -u.\n");
66 printf(
"\t-v shows the version and exits\n");
67 printf(
"\t-z sort the zone (implies -c).\n");
68 printf(
"\nif no file is given standard input is read\n");
76 assert(show_types != NULL);
86 fprintf(stderr,
"Cannot exclude rr type %s: %s\n"
96 assert(show_types != NULL);
106 fprintf(stderr,
"Cannot exclude all rr types except %s: %s\n"
113 main(
int argc,
char **argv)
120 bool canonicalize =
false;
122 bool print_soa =
true;
132 int soa_serial_increment_func_data = 0;
134 while ((c = getopt(argc, argv,
"0bcde:E:hnpsS:u:U:vz")) != -1) {
153 exclude_type(&show_types,
157 include_type(&show_types,
161 print_usage(
"ldns-read-zone");
175 if (*optarg ==
'+' || *optarg ==
'-') {
176 soa_serial_increment_func_data =
178 soa_serial_increment_func =
180 }
else if (! strtok(optarg,
"0123456789")) {
181 soa_serial_increment_func_data =
183 soa_serial_increment_func =
185 }
else if (!strcasecmp(optarg,
"YYYYMMDDxx")){
186 soa_serial_increment_func =
188 }
else if (!strcasecmp(optarg,
"unixtime")){
189 soa_serial_increment_func =
192 fprintf(stderr,
"-S expects a number "
193 "optionally preceded by a "
194 "+ or - sign to indicate an "
195 "offset, or the text YYYYMM"
196 "DDxx or unixtime\n");
205 ,
"Cannot set rr type %s "
206 "in output format to "
207 "print as unknown type: %s\n"
221 ,
"Cannot set rr type %s "
222 "in output format to not "
223 "print as unknown type: %s\n"
250 fp = fopen(filename,
"r");
252 fprintf(stderr,
"Unable to open %s: %s\n", filename, strerror(errno));
261 fprintf(stderr,
"%s at line %d\n",
293 if (soa_serial_increment_func) {
296 , soa_serial_increment_func
297 , soa_serial_increment_func_data
bool ldns_nsec_bitmap_covers_type(const ldns_rdf *bitmap, ldns_rr_type type)
Check if RR type t is enumerated and set in the RR type bitmap rdf.
ldns_status ldns_nsec_bitmap_set_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and sets the bit.
ldns_status ldns_nsec_bitmap_clear_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and clears the bit.
const char * ldns_get_errorstr_by_id(ldns_status err)
look up a descriptive text by each error.
enum ldns_enum_status ldns_status
void ldns_rr_list_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_rr_list *lst)
print a rr_list to output
ldns_status ldns_output_format_clear_type(ldns_output_format *fmt, ldns_rr_type t)
Makes sure the LDNS_FMT_RFC3597 is set in the output format.
ldns_status ldns_output_format_set_type(ldns_output_format *fmt, ldns_rr_type t)
Makes sure the LDNS_FMT_RFC3597 is set in the output format.
void ldns_rr_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_rr *rr)
Prints the data in the resource record to the given file stream (in presentation format)
host2str.h - txt presentation of RRs
#define LDNS_FMT_PAD_SOA_SERIAL
#define LDNS_COMMENT_BUBBLEBABBLE
Provide bubblebabble representation for DS RR's as comment.
#define LDNS_FMT_ZEROIZE_RRSIGS
#define LDNS_COMMENT_FLAGS
Show when a NSEC3 RR has the optout flag set as comment.
Including this file will include all ldns files, and define some lookup tables.
void ldns_rr_list_free(ldns_rr_list *rr_list)
frees an rr_list structure.
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
ldns_rr * ldns_rr_list_pop_rr(ldns_rr_list *rr_list)
pops the last rr from an rrlist.
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
void ldns_rr2canonical(ldns_rr *rr)
converts each dname in a rr to its canonical form.
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf **rdf)
Create a rr type bitmap rdf providing enough space to set all known (to ldns) rr types.
ldns_rr_list * ldns_rr_list_new(void)
creates a new rr_list structure.
ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf **rdf)
Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
ldns_rr_type ldns_get_rr_type_by_name(const char *name)
retrieves a rrtype by looking up its name.
enum ldns_enum_rr_type ldns_rr_type
@ LDNS_RR_TYPE_RRSIG
DNSSEC.
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
@ LDNS_RR_CLASS_IN
the Internet
uint32_t ldns_soa_serial_unixtime(uint32_t s, void *data)
Function to be used with ldns_rr_soa_increment_func or ldns_rr_soa_increment_func_int to set the soa ...
void ldns_rr_soa_increment_func_int(ldns_rr *soa, ldns_soa_serial_increment_func_t f, int data)
Increment the serial number of the given SOA with the given function using data as an argument for th...
uint32_t ldns_soa_serial_identity(uint32_t unused __attribute__((unused)), void *data)
uint32_t ldns_soa_serial_increment_by(uint32_t s, void *data)
Function to be used with dns_rr_soa_increment_func_int, to increment the soa serial number with a cer...
uint32_t ldns_soa_serial_datecounter(uint32_t s, void *data)
Function to be used with ldns_rr_soa_increment_func or ldns_rr_soa_increment_func_int to set the soa ...
uint32_t(* ldns_soa_serial_increment_func_t)(uint32_t, void *)
The type of function to be passed to ldns_rr_soa_increment_func, ldns_rr_soa_increment_func_data or l...
Resource record data field.
List or Set of Resource Records.
const char * ldns_version(void)
Show the internal library version.
void ldns_zone_set_rrs(ldns_zone *z, ldns_rr_list *rrlist)
Set the zone's contents.
ldns_rr_list * ldns_zone_rrs(const ldns_zone *z)
Get a list of a zone's content.
void ldns_zone_deep_free(ldns_zone *zone)
Frees the allocated memory for the zone, the soa rr in it, and the rr_list structure in it,...
ldns_rr * ldns_zone_soa(const ldns_zone *z)
Return the soa record of a zone.
void ldns_zone_sort(ldns_zone *zone)
Sort the rrs in a zone, with the current impl.
ldns_status ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, const ldns_rdf *origin, uint32_t default_ttl, ldns_rr_class c __attribute__((unused)), int *line_nr)