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_OK;
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);
359 adapter_str, zone->
name);
371 adapter_str, l, ldns_get_errorstr_by_id(status), line);
376 if ((is_axfr && soa_seen != 2) || (!is_axfr && soa_seen != 3)) {
378 adapter_str, is_axfr?
"axfr":
"ixfr", soa_seen);
405 addns_read_file(FILE* fd,
zone_type* zone)
410 status = addns_read_pkt(fd, zone);
429 ods_log_error(
"[%s] unable to create dnsin: allocator_create() "
430 " failed", adapter_str);
435 ods_log_error(
"[%s] unable to create dnsin: allocator_alloc() "
436 " failed", adapter_str);
458 ods_log_error(
"[%s] unable to create dnsout: allocator_create() "
459 " failed", adapter_str);
464 ods_log_error(
"[%s] unable to create dnsout: allocator_alloc() "
465 " failed", adapter_str);
482 dnsin_read(
dnsin_type* addns,
const char* filename)
484 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
487 if (!filename || !addns) {
490 ods_log_debug(
"[%s] read dnsin file %s", adapter_str, filename);
501 filename, addns->
tsig);
503 filename, addns->
tsig);
507 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
508 adapter_str, filename);
524 if (!filename || !addns || !last_mod) {
531 "failed", adapter_str);
534 status = dnsin_read(new_addns, filename);
537 *last_mod = st_mtime;
551 dnsout_read(
dnsout_type* addns,
const char* filename)
553 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
556 if (!filename || !addns) {
559 ods_log_debug(
"[%s] read dnsout file %s", adapter_str, filename);
570 filename, addns->
tsig);
576 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
577 adapter_str, filename);
593 if (!filename || !addns || !last_mod) {
599 ods_log_error(
"[%s] unable to update dnsout: dnsout_create() "
600 "failed", adapter_str);
603 status = dnsout_read(new_addns, filename);
606 *last_mod = st_mtime;
608 ods_log_error(
"[%s] unable to update dnsout: dnsout_read(%s) "
621 dnsout_send_notify(
void* zone)
627 ods_log_error(
"[%s] unable to send notify for zone %s: no notify "
628 "handler", adapter_str, z->
name);
636 ods_log_debug(
"[%s] enable notify for zone %s serial %u", adapter_str,
640 soa = ldns_rr_clone(rrset->
rrs[0].
rr);
655 char* xfrfile = NULL;
682 if (!xfrfile || !file) {
683 ods_log_error(
"[%s] unable to build paths to xfrd files", adapter_str);
686 if (rename(xfrfile, file) != 0) {
689 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
690 xfrfile, file, strerror(errno));
691 free((
void*) xfrfile);
698 free((
void*) xfrfile);
705 status = addns_read_file(fd, z);
712 if (unlink((
const char*) file) != 0) {
713 ods_log_error(
"[%s] unable to unlink zone transfer copy file %s: "
714 " %s", adapter_str, strerror(errno));
733 char* atmpfile = NULL;
734 char* axfrfile = NULL;
735 char* itmpfile = NULL;
736 char* ixfrfile = NULL;
751 free((
void*) atmpfile);
757 free((
void*) atmpfile);
764 free((
void*) atmpfile);
769 free((
void*) atmpfile);
770 free((
void*) itmpfile);
776 free((
void*) atmpfile);
777 free((
void*) itmpfile);
785 "more RR print failed", adapter_str, z->
name);
788 free((
void*) atmpfile);
789 free((
void*) itmpfile);
797 free((
void*) atmpfile);
798 free((
void*) itmpfile);
803 ret = rename(atmpfile, axfrfile);
805 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
806 atmpfile, axfrfile, strerror(errno));
808 free((
void*) atmpfile);
809 free((
void*) axfrfile);
810 free((
void*) itmpfile);
813 free((
void*) axfrfile);
814 free((
void*) atmpfile);
819 free((
void*) axfrfile);
820 free((
void*) atmpfile);
821 free((
void*) itmpfile);
824 ret = rename(itmpfile, ixfrfile);
827 adapter_str, itmpfile, ixfrfile, strerror(errno));
829 free((
void*) itmpfile);
830 free((
void*) ixfrfile);
833 free((
void*) ixfrfile);
835 free((
void*) itmpfile);
838 dnsout_send_notify(zone);
void acl_cleanup(acl_type *acl, allocator_type *allocator)
allocator_type * allocator
uint32_t adapi_get_serial(zone_type *zone)
void notify_enable(notify_type *notify, ldns_rr *soa)
tsig_type * parse_addns_tsig(allocator_type *allocator, const char *filename)
acl_type * parse_addns_provide_xfr(allocator_type *allocator, const char *filename, tsig_type *tsig)
void dnsout_cleanup(dnsout_type *addns)
void ods_log_debug(const char *format,...)
void * allocator_alloc(allocator_type *allocator, size_t size)
time_t serial_xfr_acquired
acl_type * parse_addns_request_xfr(allocator_type *allocator, const char *filename, tsig_type *tsig)
void ods_log_info(const char *format,...)
enum ods_enum_status ods_status
ods_status parse_file_check(const char *cfgfile, const char *rngfile)
void ods_log_error(const char *format,...)
const char * ods_status2str(ods_status status)
#define SE_SOA_RDATA_SERIAL
int ods_strcmp(const char *s1, const char *s2)
lock_basic_type serial_lock
adapter_type * adoutbound
FILE * ods_fopen(const char *file, const char *dir, const char *mode)
ldns_rr * addns_read_rr(FILE *fd, char *line, ldns_rdf **orig, ldns_rdf **prev, uint32_t *ttl, ldns_status *status, unsigned int *l)
int util_serial_gt(uint32_t serial_new, uint32_t serial_old)
allocator_type * allocator
void tsig_cleanup(tsig_type *tsig, allocator_type *allocator)
#define lock_basic_lock(lock)
void adapi_set_serial(zone_type *zone, uint32_t serial)
void dnsin_cleanup(dnsin_type *addns)
allocator_type * allocator_create(void *(*allocator)(size_t size), void(*deallocator)(void *))
ldns_rdf * adapi_get_origin(zone_type *zone)
int adutil_whitespace_line(char *line, int line_len)
void namedb_rollback(namedb_type *db, unsigned keepsc)
acl_type * parse_addns_allow_notify(allocator_type *allocator, const char *filename, tsig_type *tsig)
void adutil_rtrim_line(char *line, int *line_len)
ods_status addns_read(void *zone)
ods_status adapi_del_rr(zone_type *zone, ldns_rr *rr, int backup)
char * ods_build_path(const char *file, const char *suffix, int dir, int no_slash)
ods_status dnsout_update(dnsout_type **addns, const char *filename, time_t *last_mod)
void ods_log_verbose(const char *format,...)
rrset_type * zone_lookup_rrset(zone_type *zone, ldns_rdf *owner, ldns_rr_type type)
acl_type * parse_addns_do_notify(allocator_type *allocator, const char *filename, tsig_type *tsig)
void adapi_trans_full(zone_type *zone, unsigned more_coming)
void ods_fclose(FILE *fd)
ods_status adapi_printixfr(FILE *fd, zone_type *zone)
void allocator_cleanup(allocator_type *allocator)
ods_status adapi_add_rr(zone_type *zone, ldns_rr *rr, int backup)
#define SE_ADFILE_MAXLINE
int adutil_readline_frm_file(FILE *fd, char *line, unsigned int *l, int keep_comments)
void ods_log_deeebug(const char *format,...)
void allocator_deallocate(allocator_type *allocator, void *data)
uint32_t adapi_get_ttl(zone_type *zone)
ods_status addns_write(void *zone)
dnsin_type * dnsin_create(void)
ods_status dnsin_update(dnsin_type **addns, const char *filename, time_t *last_mod)
#define ods_log_assert(x)
ods_status adapi_printaxfr(FILE *fd, zone_type *zone)
#define lock_basic_unlock(lock)
dnsout_type * dnsout_create(void)
void ods_log_warning(const char *format,...)
time_t serial_disk_acquired
void adapi_trans_diff(zone_type *zone, unsigned more_coming)