48 #include <ldns/ldns.h>
52 static const char* adapter_str =
"adapter";
63 uint32_t* ttl, ldns_status* status,
unsigned int* l)
84 *status = LDNS_STATUS_OK;
89 *status = LDNS_STATUS_OK;
100 *status = ldns_rr_new_frm_str(&rr, line, new_ttl, *orig, prev);
101 if (*status == LDNS_STATUS_OK) {
103 }
else if (*status == LDNS_STATUS_SYNTAX_EMPTY) {
108 *status = LDNS_STATUS_OK;
109 goto addns_read_line;
113 adapter_str, l&&*l?*l:0,
114 ldns_get_errorstr_by_id(*status), line);
128 *status = LDNS_STATUS_OK;
138 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;
178 ods_log_error(
"[%s] bogus xfrd file zone %s, missing ;;BEGINPACKET (was %s)",
179 adapter_str, zone->
name, line);
193 ods_log_error(
"[%s] error getting default value for $ORIGIN",
197 orig = ldns_rdf_clone(dname);
199 ods_log_error(
"[%s] error setting default value for $ORIGIN",
207 while ((rr =
addns_read_rr(fd, line, &orig, &prev, &ttl, &status, &l))
212 if (status != LDNS_STATUS_OK) {
214 adapter_str, l, ldns_get_errorstr_by_id(status), line);
219 if (l > line_update) {
220 ods_log_debug(
"[%s] ...at line %i: %s", adapter_str, l, line);
221 line_update += line_update_interval;
226 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
235 if (ldns_dname_compare(ldns_rr_owner(rr), zone->
apex)) {
237 "dname %s", adapter_str, zone->
name);
247 ods_log_info(
"[%s] zone %s is already up to date, have "
248 "serial %u, got serial %u", adapter_str, zone->
name,
249 old_serial, tmp_serial);
250 new_serial = tmp_serial;
256 if (len &&
ods_strcmp(
";;ENDPACKET", line) == 0) {
271 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
273 adapter_str, tmp_serial, zone->
name);
274 new_serial = tmp_serial;
279 adapter_str, tmp_serial, zone->
name);
280 new_serial = tmp_serial;
286 if (tmp_serial < new_serial) {
292 adapter_str, zone->
name);
300 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
304 if (tmp_serial <= new_serial) {
305 if (tmp_serial == new_serial) {
308 del_mode = !del_mode;
316 adapter_str, zone->
name);
328 if (!is_axfr && del_mode) {
330 adapter_str, rr_count, l, line);
336 adapter_str, rr_count, l, line);
341 adapter_str, l, del_mode?
"not found":
"duplicate", line);
348 adapter_str, del_mode?
"deleting":
"adding", l, line);
356 ldns_rdf_deep_free(orig);
360 ldns_rdf_deep_free(prev);
366 adapter_str, zone->
name);
370 adapter_str, zone->
name);
383 adapter_str, l, ldns_get_errorstr_by_id(status), line);
388 if ((is_axfr && soa_seen != 2) || (!is_axfr && soa_seen != 3)) {
390 adapter_str, is_axfr?
"axfr":
"ixfr", soa_seen);
415 if (!xfrd || !fin || !fout) {
418 ods_log_debug(
"[%s] restore xfrd zone %s xfrd %s fin %s fout %s",
419 adapter_str, zone->
name, xfrd, fin, fout);
422 ods_log_crit(
"[%s] unable to restore incomple xfr zone %s: %s",
431 }
else if (rename(fout, xfrd) != 0) {
436 }
else if (rename(fout, xfrd) != 0) {
458 addns_read_file(FILE* fd,
zone_type* zone)
463 status = addns_read_pkt(fd, zone);
488 ods_log_error(
"[%s] unable to create dnsin: allocator_create() "
489 " failed", adapter_str);
494 ods_log_error(
"[%s] unable to create dnsin: allocator_alloc() "
495 " failed", adapter_str);
517 ods_log_error(
"[%s] unable to create dnsout: allocator_create() "
518 " failed", adapter_str);
523 ods_log_error(
"[%s] unable to create dnsout: allocator_alloc() "
524 " failed", adapter_str);
541 dnsin_read(
dnsin_type* addns,
const char* filename)
543 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
546 if (!filename || !addns) {
549 ods_log_debug(
"[%s] read dnsin file %s", adapter_str, filename);
560 filename, addns->
tsig);
562 filename, addns->
tsig);
566 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
567 adapter_str, filename);
583 if (!filename || !addns || !last_mod) {
590 "failed", adapter_str);
593 status = dnsin_read(new_addns, filename);
596 *last_mod = st_mtime;
610 dnsout_read(
dnsout_type* addns,
const char* filename)
612 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
615 if (!filename || !addns) {
618 ods_log_debug(
"[%s] read dnsout file %s", adapter_str, filename);
629 filename, addns->
tsig);
635 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
636 adapter_str, filename);
652 if (!filename || !addns || !last_mod) {
658 ods_log_error(
"[%s] unable to update dnsout: dnsout_create() "
659 "failed", adapter_str);
662 status = dnsout_read(new_addns, filename);
665 *last_mod = st_mtime;
667 ods_log_error(
"[%s] unable to update dnsout: dnsout_read(%s) "
680 dnsout_send_notify(
void* zone)
686 ods_log_error(
"[%s] unable to send notify for zone %s: no notify "
687 "handler", adapter_str, z->
name);
695 ods_log_debug(
"[%s] enable notify for zone %s serial %u", adapter_str,
699 soa = ldns_rr_clone(rrset->
rrs[0].
rr);
714 char* xfrfile = NULL;
741 if (!xfrfile || !file) {
742 ods_log_error(
"[%s] unable to build paths to xfrd files", adapter_str);
745 if (rename(xfrfile, file) != 0) {
748 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
749 xfrfile, file, strerror(errno));
750 free((
void*) xfrfile);
757 free((
void*) xfrfile);
765 status = addns_read_file(fd, z);
768 if (unlink((
const char*) file) != 0) {
769 ods_log_error(
"[%s] unable to unlink zone transfer copy file %s: "
770 " %s", adapter_str, strerror(errno));
788 char* atmpfile = NULL;
789 char* axfrfile = NULL;
790 char* itmpfile = NULL;
791 char* ixfrfile = NULL;
806 free((
void*) atmpfile);
812 free((
void*) atmpfile);
819 free((
void*) atmpfile);
824 free((
void*) atmpfile);
825 free((
void*) itmpfile);
831 free((
void*) atmpfile);
832 free((
void*) itmpfile);
840 "more RR print failed", adapter_str, z->
name);
843 free((
void*) atmpfile);
844 free((
void*) itmpfile);
852 free((
void*) atmpfile);
853 free((
void*) itmpfile);
858 ret = rename(atmpfile, axfrfile);
860 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
861 atmpfile, axfrfile, strerror(errno));
863 free((
void*) atmpfile);
864 free((
void*) axfrfile);
865 free((
void*) itmpfile);
868 free((
void*) axfrfile);
869 free((
void*) atmpfile);
874 free((
void*) axfrfile);
875 free((
void*) atmpfile);
876 free((
void*) itmpfile);
879 ret = rename(itmpfile, ixfrfile);
882 adapter_str, itmpfile, ixfrfile, strerror(errno));
884 free((
void*) itmpfile);
885 free((
void*) ixfrfile);
888 free((
void*) ixfrfile);
890 free((
void*) itmpfile);
893 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)
time_t ods_file_lastmodified(const char *file)
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 ods_log_crit(const char *format,...)
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)
dnsout_type * dnsout_create(void)
#define lock_basic_unlock(lock)
void ods_log_warning(const char *format,...)
time_t serial_disk_acquired
ods_status ods_file_copy(const char *file1, const char *file2, long startpos, int append)
void adapi_trans_diff(zone_type *zone, unsigned more_coming)