45 #include <ldns/ldns.h>
47 static const char* backup_str =
"backup";
57 static char buf[4000];
61 if (fscanf(in,
"%3990s", buf) != 1) {
67 if (!fgets(buf,
sizeof(buf), in)) {
83 ods_log_debug(
"[%s] cannot read check string \'%s\'", backup_str, str);
87 ods_log_debug(
"[%s] \'%s\' does not match \'%s\'", backup_str, p, str);
157 *v=(ldns_rr_type) atoi(p);
208 *v= (uint8_t)atoi(p);
225 *v= (uint16_t)atoi(p);
242 *v= (uint32_t)atol(p);
252 backup_read_rr(FILE* in,
zone_type* zone,
char* line, ldns_rdf** orig,
253 ldns_rdf** prev, ldns_status* status,
unsigned int* l)
263 *status = LDNS_STATUS_OK;
268 goto backup_read_line;
272 *status = ldns_rr_new_frm_str(&rr, line, zone->
default_ttl,
274 if (*status == LDNS_STATUS_OK) {
276 }
else if (*status == LDNS_STATUS_SYNTAX_EMPTY) {
281 *status = LDNS_STATUS_OK;
282 goto backup_read_line;
286 backup_str, l&&*l?*l:0,
287 ldns_get_errorstr_by_id(*status), line);
298 *status = LDNS_STATUS_OK;
308 replace_space_with_nul(
char* str)
336 ldns_rr_type type_covered;
338 ldns_rdf* prev = NULL;
339 ldns_rdf* orig = NULL;
340 ldns_rdf* dname = NULL;
341 ldns_status status = LDNS_STATUS_OK;
344 char* locator = NULL;
354 ods_log_error(
"[%s] error getting default value for $ORIGIN",
358 orig = ldns_rdf_clone(dname);
360 ods_log_error(
"[%s] error setting default value for $ORIGIN",
366 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
369 if (status != LDNS_STATUS_OK) {
371 backup_str, l, ldns_get_errorstr_by_id(status), line);
373 goto backup_namedb_done;
379 backup_str, l, line);
386 backup_str, l, line);
389 goto backup_namedb_done;
394 backup_str, l, ldns_get_errorstr_by_id(status), line);
396 goto backup_namedb_done;
403 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
406 if (status != LDNS_STATUS_OK) {
408 backup_str, l, ldns_get_errorstr_by_id(status), line);
410 goto backup_namedb_done;
412 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_NSEC &&
413 ldns_rr_get_type(rr) != LDNS_RR_TYPE_NSEC3) {
415 backup_str, l, line);
419 goto backup_namedb_done;
425 backup_str, l, line);
429 goto backup_namedb_done;
435 backup_str, l, ldns_get_errorstr_by_id(status), line);
437 goto backup_namedb_done;
443 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
446 if (status != LDNS_STATUS_OK) {
448 backup_str, l, ldns_get_errorstr_by_id(status), line);
450 goto backup_namedb_done;
452 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG) {
454 backup_str, l, line);
458 goto backup_namedb_done;
461 str = strstr(line,
"flags");
463 flags = (uint32_t) atoi(str+6);
465 str = strstr(line,
"locator");
467 locator = replace_space_with_nul(str+8);
470 type_covered = ldns_rdf2rr_type(ldns_rr_rrsig_typecovered(rr));
471 if (type_covered == LDNS_RR_TYPE_NSEC ||
472 type_covered == LDNS_RR_TYPE_NSEC3) {
476 backup_str, l, ldns_get_errorstr_by_id(status), line);
480 goto backup_namedb_done;
482 rrset = denial->
rrset;
488 backup_str, l, ldns_get_errorstr_by_id(status), line);
492 goto backup_namedb_done;
499 backup_str, l, ldns_get_errorstr_by_id(status), line);
505 ldns_rdf_deep_free(orig);
509 ldns_rdf_deep_free(prev);
527 ldns_rdf* prev = NULL;
528 ldns_rdf* orig = NULL;
529 ldns_rdf* dname = NULL;
530 ldns_status status = LDNS_STATUS_OK;
534 unsigned first_soa = 1;
535 unsigned del_mode = 0;
543 ods_log_error(
"[%s] error getting default value for $ORIGIN",
547 orig = ldns_rdf_clone(dname);
549 ods_log_error(
"[%s] error setting default value for $ORIGIN",
554 while ((rr = backup_read_rr(in, z, line, &orig, &prev, &status, &l))
557 if (status != LDNS_STATUS_OK) {
559 backup_str, l, ldns_get_errorstr_by_id(status), line);
561 goto backup_ixfr_done;
563 if (first_soa == 2) {
564 ods_log_error(
"[%s] bad ixfr journal: trailing RRs after final "
569 goto backup_ixfr_done;
571 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
572 serial = ldns_rdf2native_int32(
582 "serial (was %u, expected %u)", backup_str,
585 goto backup_ixfr_done;
612 del_mode = !del_mode;
621 goto backup_ixfr_done;
626 ods_log_debug(
"[%s] -IXFR: %s", backup_str, ldns_rr2str(rr));
629 ods_log_debug(
"[%s] +IXFR: %s", backup_str, ldns_rr2str(rr));
636 backup_str, l, ldns_get_errorstr_by_id(status), line);
642 ldns_rdf_deep_free(orig);
646 ldns_rdf_deep_free(prev);