45 #include <ldns/ldns.h>
49 static const char* adapter_str =
"adapter";
70 adfile_read_rr(FILE* fd,
zone_type* zone,
char* line, ldns_rdf** orig,
71 ldns_rdf** prev, uint32_t* ttl, ldns_status* status,
unsigned int* l)
75 FILE* fd_include = NULL;
94 if (strncmp(line,
"$ORIGIN", 7) == 0 && isspace(line[7])) {
97 ldns_rdf_deep_free(*orig);
101 while (isspace(line[offset])) {
104 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
108 *status = LDNS_STATUS_SYNTAX_DNAME_ERR;
113 goto adfile_read_line;
115 }
else if (strncmp(line,
"$TTL", 4) == 0 &&
119 while (isspace(line[offset])) {
123 *ttl = ldns_str2period(line + offset, &endptr);
126 goto adfile_read_line;
128 }
else if (strncmp(line,
"$INCLUDE", 8) == 0 &&
132 while (isspace(line[offset])) {
135 fd_include =
ods_fopen(line + offset, NULL,
"r");
137 s = adfile_read_file(fd_include, zone);
141 adapter_str, (line+offset));
142 *status = LDNS_STATUS_SYNTAX_ERR;
146 *status = LDNS_STATUS_SYNTAX_ERR;
148 adapter_str, (line+offset));
155 goto adfile_read_line;
163 goto adfile_read_line;
169 goto adfile_read_line;
173 *status = ldns_rr_new_frm_str(&rr, line, new_ttl, *orig, prev);
174 if (*status == LDNS_STATUS_OK) {
175 ldns_rr2canonical(rr);
177 }
else if (*status == LDNS_STATUS_SYNTAX_EMPTY) {
182 *status = LDNS_STATUS_OK;
183 goto adfile_read_line;
187 adapter_str, l&&*l?*l:0,
188 ldns_get_errorstr_by_id(*status), line);
203 *status = LDNS_STATUS_OK;
213 adfile_read_file(FILE* fd,
zone_type* zone)
217 ldns_rdf* prev = NULL;
218 ldns_rdf* orig = NULL;
219 ldns_rdf* dname = NULL;
221 ldns_status status = LDNS_STATUS_OK;
223 unsigned int line_update_interval = 100000;
224 unsigned int line_update = line_update_interval;
233 ods_log_error(
"[%s] error getting default value for $ORIGIN",
237 orig = ldns_rdf_clone(dname);
239 ods_log_error(
"[%s] error setting default value for $ORIGIN",
248 while ((rr = adfile_read_rr(fd, zone, line, &orig, &prev, &ttl,
249 &status, &l)) != NULL) {
251 if (status != LDNS_STATUS_OK) {
253 adapter_str, l, ldns_get_errorstr_by_id(status), line);
258 if (l > line_update) {
259 ods_log_debug(
"[%s] ...at line %i: %s", adapter_str, l, line);
260 line_update += line_update_interval;
274 adapter_str, l, line);
281 ldns_rdf_deep_free(orig);
285 ldns_rdf_deep_free(prev);
291 adapter_str, l, ldns_get_errorstr_by_id(status), line);
308 uint32_t new_serial = 0;
313 ods_log_error(
"[%s] unable to read file: no zone (or no name given)",
338 status = adfile_read_file(fd, adzone);
344 ods_log_error(
"[%s] unable to read file %s: %s", adapter_str,
353 ods_log_error(
"[%s] unable to read file: start transaction failed",
362 ods_log_error(
"[%s] unable to read file: zonefile contains errors",
385 ods_log_error(
"[%s] unable to read file: no zone (or no name given)",
401 status = adfile_read_file(fd, adzone);
407 ods_log_error(
"[%s] unable to recover file: %s", adapter_str,
416 ods_log_error(
"[%s] unable to recover file: start transaction failed",
433 char* tmpname = NULL;
440 "name given)", adapter_str);
445 ods_log_error(
"[%s] unable to write file: no filename given",
462 if (rename((
const char*) tmpname, filename) != 0) {
463 ods_log_error(
"[%s] unable to write file: failed to rename %s "
464 "to %s (%s)", adapter_str, tmpname, filename, strerror(errno));
ods_status adbackup_read(struct zone_struct *zone, const char *filename)
ldns_rr * adutil_lookup_soa_rr(FILE *fd)
void ods_log_debug(const char *format,...)
ods_status adfile_read(struct zone_struct *zone, const char *filename)
enum ods_enum_status ods_status
ods_status zone_print(FILE *fd, zone_type *zone)
void ods_log_error(const char *format,...)
const char * ods_status2str(ods_status status)
#define SE_SOA_RDATA_SERIAL
ods_status adapi_trans_full(zone_type *zone)
ods_status zone_examine(zone_type *zone)
FILE * ods_fopen(const char *file, const char *dir, const char *mode)
ods_status adapi_add_rr(zone_type *zone, ldns_rr *rr)
void adapi_set_serial(zone_type *zone, uint32_t serial)
ldns_rdf * adapi_get_origin(zone_type *zone)
int adutil_readline_frm_file(FILE *fd, char *line, unsigned int *l)
int adutil_whitespace_line(char *line, int line_len)
void adutil_rtrim_line(char *line, int *line_len)
ods_status adfile_init(void)
char * ods_build_path(const char *file, const char *suffix, int dir, int no_slash)
void ods_fclose(FILE *fd)
#define SE_ADFILE_MAXLINE
uint32_t adapi_get_ttl(zone_type *zone)
#define ods_log_assert(x)
ods_status adfile_write(struct zone_struct *zone, const char *filename)
int util_is_dnssec_rr(ldns_rr *rr)