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);
282 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
284 adapter_str, tmp_serial, zone->
name);
285 new_serial = tmp_serial;
290 adapter_str, tmp_serial, zone->
name);
294 ods_log_error(
"[%s] bad ixfr for zone %s, bad start serial %u",
295 adapter_str, zone->
name, tmp_serial);
299 new_serial = tmp_serial;
305 if (tmp_serial < new_serial) {
310 ods_log_error(
"[%s] bad ixfr for zone %s, bad soa serial %u",
311 adapter_str, zone->
name, tmp_serial);
319 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
323 if (tmp_serial <= new_serial) {
324 if (tmp_serial == new_serial) {
327 del_mode = !del_mode;
335 adapter_str, zone->
name);
347 if (!is_axfr && del_mode) {
349 adapter_str, rr_count, l, line);
355 adapter_str, rr_count, l, line);
360 adapter_str, l, del_mode?
"not found":
"duplicate", line);
367 adapter_str, del_mode?
"deleting":
"adding", l, line);
375 ldns_rdf_deep_free(orig);
379 ldns_rdf_deep_free(prev);
385 adapter_str, zone->
name);
389 adapter_str, zone->
name);
402 adapter_str, l, ldns_get_errorstr_by_id(status), line);
407 if ((is_axfr && soa_seen != 2) || (!is_axfr && soa_seen != 3)) {
409 adapter_str, is_axfr?
"axfr":
"ixfr", soa_seen);
434 if (!xfrd || !fin || !fout) {
437 ods_log_debug(
"[%s] restore xfrd zone %s xfrd %s fin %s fout %s",
438 adapter_str, zone->
name, xfrd, fin, fout);
441 ods_log_crit(
"[%s] unable to restore incomple xfr zone %s: %s",
450 }
else if (rename(fout, xfrd) != 0) {
455 }
else if (rename(fout, xfrd) != 0) {
477 addns_read_file(FILE* fd,
zone_type* zone)
482 status = addns_read_pkt(fd, zone);
507 ods_log_error(
"[%s] unable to create dnsin: allocator_create() "
508 " failed", adapter_str);
513 ods_log_error(
"[%s] unable to create dnsin: allocator_alloc() "
514 " failed", adapter_str);
536 ods_log_error(
"[%s] unable to create dnsout: allocator_create() "
537 " failed", adapter_str);
542 ods_log_error(
"[%s] unable to create dnsout: allocator_alloc() "
543 " failed", adapter_str);
560 dnsin_read(
dnsin_type* addns,
const char* filename)
562 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
565 if (!filename || !addns) {
568 ods_log_debug(
"[%s] read dnsin file %s", adapter_str, filename);
579 filename, addns->
tsig);
581 filename, addns->
tsig);
585 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
586 adapter_str, filename);
602 if (!filename || !addns || !last_mod) {
609 "failed", adapter_str);
612 status = dnsin_read(new_addns, filename);
615 *last_mod = st_mtime;
629 dnsout_read(
dnsout_type* addns,
const char* filename)
631 const char* rngfile = ODS_SE_RNGDIR
"/addns.rng";
634 if (!filename || !addns) {
637 ods_log_debug(
"[%s] read dnsout file %s", adapter_str, filename);
648 filename, addns->
tsig);
654 ods_log_error(
"[%s] unable to read dnsout: failed to open file %s",
655 adapter_str, filename);
671 if (!filename || !addns || !last_mod) {
677 ods_log_error(
"[%s] unable to update dnsout: dnsout_create() "
678 "failed", adapter_str);
681 status = dnsout_read(new_addns, filename);
684 *last_mod = st_mtime;
686 ods_log_error(
"[%s] unable to update dnsout: dnsout_read(%s) "
699 dnsout_send_notify(
void* zone)
705 ods_log_error(
"[%s] unable to send notify for zone %s: no notify "
706 "handler", adapter_str, z->
name);
714 ods_log_debug(
"[%s] enable notify for zone %s serial %u", adapter_str,
718 soa = ldns_rr_clone(rrset->
rrs[0].
rr);
733 char* xfrfile = NULL;
762 if (!xfrfile || !file) {
763 ods_log_error(
"[%s] unable to build paths to xfrd files", adapter_str);
766 if (rename(xfrfile, file) != 0) {
769 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
770 xfrfile, file, strerror(errno));
771 free((
void*) xfrfile);
778 free((
void*) xfrfile);
786 status = addns_read_file(fd, z);
789 if (unlink((
const char*) file) != 0) {
790 ods_log_error(
"[%s] unable to unlink zone transfer copy file %s: "
791 " %s", adapter_str, strerror(errno));
809 char* atmpfile = NULL;
810 char* axfrfile = NULL;
811 char* itmpfile = NULL;
812 char* ixfrfile = NULL;
827 free((
void*) atmpfile);
833 free((
void*) atmpfile);
840 free((
void*) atmpfile);
845 free((
void*) atmpfile);
846 free((
void*) itmpfile);
852 free((
void*) atmpfile);
853 free((
void*) itmpfile);
861 "more RR print failed", adapter_str, z->
name);
864 free((
void*) atmpfile);
865 free((
void*) itmpfile);
873 free((
void*) atmpfile);
874 free((
void*) itmpfile);
879 ret = rename(atmpfile, axfrfile);
881 ods_log_error(
"[%s] unable to rename file %s to %s: %s", adapter_str,
882 atmpfile, axfrfile, strerror(errno));
884 free((
void*) atmpfile);
885 free((
void*) axfrfile);
886 free((
void*) itmpfile);
889 free((
void*) axfrfile);
890 free((
void*) atmpfile);
895 free((
void*) axfrfile);
896 free((
void*) atmpfile);
897 free((
void*) itmpfile);
900 ret = rename(itmpfile, ixfrfile);
903 adapter_str, itmpfile, ixfrfile, strerror(errno));
905 free((
void*) itmpfile);
906 free((
void*) ixfrfile);
909 free((
void*) ixfrfile);
911 free((
void*) itmpfile);
914 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)
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)