43 #include <ldns/ldns.h>
45 static const char* backup_str =
"backup";
55 static char buf[4000];
59 if (fscanf(in,
"%3990s", buf) != 1) {
65 if (!fgets(buf,
sizeof(buf), in)) {
81 ods_log_debug(
"[%s] cannot read check string \'%s\'", backup_str, str);
85 ods_log_debug(
"[%s] \'%s\' does not match \'%s\'", backup_str, p, str);
155 *v=(ldns_rr_type) atoi(p);
206 *v= (uint8_t)atoi(p);
223 *v= (uint16_t)atoi(p);
240 *v= (uint32_t)atol(p);
250 backup_read_rr(FILE* in,
zone_type* zone,
char* line, ldns_rdf** orig,
251 ldns_rdf** prev, ldns_status* status,
unsigned int* l)
261 *status = LDNS_STATUS_OK;
266 goto backup_read_line;
270 *status = ldns_rr_new_frm_str(&rr, line, zone->
default_ttl,
272 if (*status == LDNS_STATUS_OK) {
274 }
else if (*status == LDNS_STATUS_SYNTAX_EMPTY) {
279 *status = LDNS_STATUS_OK;
280 goto backup_read_line;
284 backup_str, l&&*l?*l:0,
285 ldns_get_errorstr_by_id(*status), line);
296 *status = LDNS_STATUS_OK;
306 replace_space_with_nul(
char* str)
334 ldns_rr_type type_covered;
336 ldns_rdf* prev = NULL;
337 ldns_rdf* orig = NULL;
338 ldns_rdf* dname = NULL;
339 ldns_status status = LDNS_STATUS_OK;
342 char* locator = NULL;
352 ods_log_error(
"[%s] error getting default value for $ORIGIN",
356 orig = ldns_rdf_clone(dname);
358 ods_log_error(
"[%s] error setting default value for $ORIGIN",
364 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
367 if (status != LDNS_STATUS_OK) {
369 backup_str, l, ldns_get_errorstr_by_id(status), line);
371 goto backup_namedb_done;
377 backup_str, l, line);
384 backup_str, l, line);
387 goto backup_namedb_done;
392 backup_str, l, ldns_get_errorstr_by_id(status), line);
394 goto backup_namedb_done;
401 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
404 if (status != LDNS_STATUS_OK) {
406 backup_str, l, ldns_get_errorstr_by_id(status), line);
408 goto backup_namedb_done;
410 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_NSEC &&
411 ldns_rr_get_type(rr) != LDNS_RR_TYPE_NSEC3) {
413 backup_str, l, line);
417 goto backup_namedb_done;
423 backup_str, l, line);
427 goto backup_namedb_done;
433 backup_str, l, ldns_get_errorstr_by_id(status), line);
435 goto backup_namedb_done;
441 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
444 if (status != LDNS_STATUS_OK) {
446 backup_str, l, ldns_get_errorstr_by_id(status), line);
448 goto backup_namedb_done;
450 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG) {
452 backup_str, l, line);
456 goto backup_namedb_done;
459 str = strstr(line,
"flags");
461 flags = (uint32_t) atoi(str+6);
463 str = strstr(line,
"locator");
465 locator = replace_space_with_nul(str+8);
468 type_covered = ldns_rdf2rr_type(ldns_rr_rrsig_typecovered(rr));
469 if (type_covered == LDNS_RR_TYPE_NSEC ||
470 type_covered == LDNS_RR_TYPE_NSEC3) {
474 backup_str, l, ldns_get_errorstr_by_id(status), line);
478 goto backup_namedb_done;
480 rrset = denial->
rrset;
486 backup_str, l, ldns_get_errorstr_by_id(status), line);
490 goto backup_namedb_done;
497 backup_str, l, ldns_get_errorstr_by_id(status), line);
503 ldns_rdf_deep_free(orig);
507 ldns_rdf_deep_free(prev);
525 ldns_rdf* prev = NULL;
526 ldns_rdf* orig = NULL;
527 ldns_rdf* dname = NULL;
528 ldns_status status = LDNS_STATUS_OK;
532 unsigned first_soa = 0;
533 unsigned del_mode = 0;
541 ods_log_error(
"[%s] error getting default value for $ORIGIN",
545 orig = ldns_rdf_clone(dname);
547 ods_log_error(
"[%s] error setting default value for $ORIGIN",
552 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
555 if (status != LDNS_STATUS_OK) {
557 backup_str, l, ldns_get_errorstr_by_id(status), line);
559 goto backup_ixfr_done;
561 if (first_soa == 2) {
562 ods_log_error(
"[%s] bad ixfr journal: trailing RRs after final "
567 goto backup_ixfr_done;
569 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
570 serial = ldns_rdf2native_int32(
580 "serial (was %u, expected %u)", backup_str,
583 goto backup_ixfr_done;
610 del_mode = !del_mode;
619 goto backup_ixfr_done;
624 ods_log_debug(
"[%s] -IXFR: %s", backup_str, ldns_rr2str(rr));
627 ods_log_debug(
"[%s] +IXFR: %s", backup_str, ldns_rr2str(rr));
634 backup_str, l, ldns_get_errorstr_by_id(status), line);
640 ldns_rdf_deep_free(orig);
644 ldns_rdf_deep_free(prev);