50 #include <ldns/ldns.h>
54 static const char* adapter_str =
"adapter";
65 uint32_t* ttl, ldns_status* status,
unsigned int* l)
86 *status = LDNS_STATUS_OK;
91 *status = LDNS_STATUS_OK;
102 *status = ldns_rr_new_frm_str(&rr, line, new_ttl, *orig, prev);
103 if (*status == LDNS_STATUS_OK) {
105 }
else if (*status == LDNS_STATUS_SYNTAX_EMPTY) {
110 *status = LDNS_STATUS_OK;
111 goto addns_read_line;
115 adapter_str, l&&*l?*l:0,
116 ldns_get_errorstr_by_id(*status), line);
130 *status = LDNS_STATUS_ERR;
140 addns_read_pkt(FILE* fd,
zone_type* zone)
144 uint32_t new_serial = 0;
145 uint32_t old_serial = 0;
146 uint32_t tmp_serial = 0;
147 ldns_rdf* prev = NULL;
148 ldns_rdf* orig = NULL;
149 ldns_rdf* dname = NULL;
153 ldns_status status = LDNS_STATUS_OK;
155 unsigned is_axfr = 0;
156 unsigned del_mode = 0;
157 unsigned soa_seen = 0;
158 unsigned line_update_interval = 100000;
159 unsigned line_update = line_update_interval;
173 ods_log_error(
"[%s] bogus xfrd file zone %s, missing ;;BEGINPACKET (was %s)",
174 adapter_str, zone->
name, line);
186 ods_log_error(
"[%s] error getting default value for $ORIGIN",
190 orig = ldns_rdf_clone(dname);
192 ods_log_error(
"[%s] error setting default value for $ORIGIN",
200 while ((rr =
addns_read_rr(fd, line, &orig, &prev, &ttl, &status, &l))
203 if (status != LDNS_STATUS_OK) {
205 adapter_str, l, ldns_get_errorstr_by_id(status), line);
210 if (l > line_update) {
211 ods_log_debug(
"[%s] ...at line %i: %s", adapter_str, l, line);
212 line_update += line_update_interval;
217 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
226 if (ldns_dname_compare(ldns_rr_owner(rr), zone->
apex)) {
228 "dname %s", adapter_str, zone->
name);
238 ods_log_info(
"[%s] zone %s is already up to date, have "
239 "serial %u, got serial %u", adapter_str, zone->
name,
240 old_serial, tmp_serial);
241 new_serial = tmp_serial;
247 if (len &&
ods_strcmp(
";;ENDPACKET", line) == 0) {
261 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
263 adapter_str, tmp_serial, zone->
name);
264 new_serial = tmp_serial;
269 adapter_str, tmp_serial, zone->
name);
270 new_serial = tmp_serial;
276 if (tmp_serial < new_serial) {
282 adapter_str, zone->
name);
290 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
294 if (tmp_serial <= new_serial) {
295 if (tmp_serial == new_serial) {
298 del_mode = !del_mode;
306 adapter_str, zone->
name);
318 if (!is_axfr && del_mode) {
320 adapter_str, rr_count, l, line);
326 adapter_str, rr_count, l, line);
331 adapter_str, l, del_mode?
"not found":
"duplicate", line);
338 adapter_str, del_mode?
"deleting":
"adding", l, line);
346 ldns_rdf_deep_free(orig);
350 ldns_rdf_deep_free(prev);
356 adapter_str, zone->
name);
362 adapter_str, zone->
name);
367 adapter_str, l, ldns_get_errorstr_by_id(status), line);
372 if ((is_axfr && soa_seen != 2) || (!is_axfr && soa_seen != 3)) {
374 adapter_str, is_axfr?
"axfr":
"ixfr", soa_seen);
401 addns_read_file(FILE* fd,
zone_type* zone)
406 status = addns_read_pkt(fd, zone);
425 ods_log_error(
"[%s] unable to create dnsin: allocator_create() "
426 " failed", adapter_str);
431 ods_log_error(
"[%s] unable to create dnsin: allocator_alloc() "
432 " failed", adapter_str);
454 ods_log_error(
"[%s] unable to create dnsout: allocator_create() "
455 " failed", adapter_str);
460 ods_log_error(
"[%s] unable to create dnsout: allocator_alloc() "
461 " failed", adapter_str);
478 dnsin_read(
dnsin_type* addns,
const char* filename)
480 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
483 if (!filename || !addns) {
486 ods_log_debug(
"[%s] read dnsin file %s", adapter_str, filename);
497 filename, addns->
tsig);
499 filename, addns->
tsig);
503 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
504 adapter_str, filename);
520 if (!filename || !addns || !last_mod) {
527 "failed", adapter_str);
530 status = dnsin_read(new_addns, filename);
533 *last_mod = st_mtime;
547 dnsout_read(
dnsout_type* addns,
const char* filename)
549 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
552 if (!filename || !addns) {
555 ods_log_debug(
"[%s] read dnsout file %s", adapter_str, filename);
566 filename, addns->
tsig);
572 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
573 adapter_str, filename);
589 if (!filename || !addns || !last_mod) {
595 ods_log_error(
"[%s] unable to update dnsout: dnsout_create() "
596 "failed", adapter_str);
599 status = dnsout_read(new_addns, filename);
602 *last_mod = st_mtime;
604 ods_log_error(
"[%s] unable to update dnsout: dnsout_read(%s) "
617 dnsout_send_notify(
void* zone)
623 ods_log_error(
"[%s] unable to send notify for zone %s: no notify "
624 "handler", adapter_str, z->
name);
632 ods_log_debug(
"[%s] enable notify for zone %s serial %u", adapter_str,
636 soa = ldns_rr_clone(rrset->
rrs[0].
rr);
651 char* xfrfile = NULL;
678 if (!xfrfile || !file) {
679 ods_log_error(
"[%s] unable to build paths to xfrd files", adapter_str);
682 if (rename(xfrfile, file) != 0) {
685 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
686 xfrfile, file, strerror(errno));
687 free((
void*) xfrfile);
694 free((
void*) xfrfile);
701 status = addns_read_file(fd, z);
708 if (unlink((
const char*) file) != 0) {
709 ods_log_error(
"[%s] unable to unlink zone transfer copy file %s: "
710 " %s", adapter_str, strerror(errno));
729 char* atmpfile = NULL;
730 char* axfrfile = NULL;
731 char* itmpfile = NULL;
732 char* ixfrfile = NULL;
747 free((
void*) atmpfile);
753 free((
void*) atmpfile);
760 free((
void*) atmpfile);
765 free((
void*) atmpfile);
766 free((
void*) itmpfile);
772 free((
void*) atmpfile);
773 free((
void*) itmpfile);
781 "more RR print failed", adapter_str, z->
name);
784 free((
void*) atmpfile);
785 free((
void*) itmpfile);
793 free((
void*) atmpfile);
794 free((
void*) itmpfile);
799 ret = rename(atmpfile, axfrfile);
801 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
802 atmpfile, axfrfile, strerror(errno));
804 free((
void*) atmpfile);
805 free((
void*) axfrfile);
806 free((
void*) itmpfile);
809 free((
void*) axfrfile);
810 free((
void*) atmpfile);
815 free((
void*) axfrfile);
816 free((
void*) atmpfile);
817 free((
void*) itmpfile);
820 ret = rename(itmpfile, ixfrfile);
823 adapter_str, itmpfile, ixfrfile, strerror(errno));
825 free((
void*) itmpfile);
826 free((
void*) ixfrfile);
829 free((
void*) ixfrfile);
831 free((
void*) itmpfile);
834 dnsout_send_notify(zone);