diff --git a/src/knot/server/zones.c b/src/knot/server/zones.c index 705d9346467b9e0d1d417f522c1b919b69a80382..2e9ff9100ef9de8da184c7da0a8a8e6b4ed11738 100644 --- a/src/knot/server/zones.c +++ b/src/knot/server/zones.c @@ -2591,46 +2591,6 @@ knot_ns_xfr_type_t zones_transfer_to_use(zonedata_t *data) /*----------------------------------------------------------------------------*/ -static int zones_find_zone_for_xfr(const knot_zone_contents_t *zone, - const char **zonefile, const char **zonedb) -{ - /* find the zone file name and zone db file name for the zone */ - conf_t *cnf = conf(); - node *n = NULL; - WALK_LIST(n, cnf->zones) { - conf_zone_t *zone_conf = (conf_zone_t *)n; - knot_dname_t *zone_name = knot_dname_new_from_str( - zone_conf->name, strlen(zone_conf->name), NULL); - if (zone_name == NULL) { - return KNOTD_ENOMEM; - } - - int r = knot_dname_compare(zone_name, knot_node_owner( - knot_zone_contents_apex(zone))); - - /* Directly discard dname, won't be needed. */ - knot_dname_free(&zone_name); - - if (r == 0) { - /* found the right zone */ - *zonefile = zone_conf->file; - *zonedb = zone_conf->db; - return KNOTD_EOK; - } - } -#ifdef KNOTD_ZONES_DEBUG - char *name = knot_dname_to_str(knot_node_owner( - knot_zone_contents_apex(zone))); - dbg_zones("zones: no zone found for the zone received by transfer " - "(%s).\n", name); - free(name); -#endif - - return KNOTD_ENOENT; -} - -/*----------------------------------------------------------------------------*/ - static int zones_open_free_filename(const char *old_name, char **new_name) { /* find zone name not present on the disk */ @@ -2809,33 +2769,48 @@ static int zones_dump_zone_binary(knot_zone_contents_t *zone, int zones_save_zone(const knot_ns_xfr_t *xfr) { - if (xfr == NULL || xfr->new_contents == NULL) { + if (xfr == NULL || xfr->new_contents == NULL || xfr->zone == NULL) { return KNOTD_EINVAL; } - knot_zone_contents_t *zone = xfr->new_contents; - - const char *zonefile = NULL; - const char *zonedb = NULL; + rcu_read_lock(); - int ret = zones_find_zone_for_xfr(zone, &zonefile, &zonedb); - if (ret != KNOTD_EOK) { - return ret; + zonedata_t *zd = (zonedata_t *)knot_zone_data(xfr->zone); + knot_zone_contents_t *new_zone = xfr->new_contents; + + const char *zonefile = zd->conf->file; + const char *zonedb = zd->conf->db; + + /* Check if the new zone apex dname matches zone name. */ + knot_dname_t *cur_name = knot_dname_new_from_str(zd->conf->name, + strlen(zd->conf->name), + NULL); + const knot_dname_t *new_name = NULL; + new_name = knot_node_owner(knot_zone_contents_apex(new_zone)); + int r = knot_dname_compare(cur_name, new_name); + knot_dname_free(&cur_name); + if (r != 0) { + rcu_read_unlock(); + return KNOTD_EINVAL; } assert(zonefile != NULL && zonedb != NULL); /* dump the zone into text zone file */ - ret = zones_dump_zone_text(zone, zonefile); + int ret = zones_dump_zone_text(new_zone, zonefile); if (ret != KNOTD_EOK) { + rcu_read_unlock(); return KNOTD_ERROR; } /* dump the zone into binary db file */ - ret = zones_dump_zone_binary(zone, zonedb, zonefile); + ret = zones_dump_zone_binary(new_zone, zonedb, zonefile); if (ret != KNOTD_EOK) { + rcu_read_unlock(); return KNOTD_ERROR; } + rcu_read_unlock(); + return KNOTD_EOK; }