From 203c6aed5444ce0d5955b8cc58b8227747f22ee2 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Wed, 12 Jul 2023 16:10:25 +0200 Subject: [PATCH] RRUpdated + RRReadOnly. --- src/responses/zone.cr | 16 ++++++++++++++++ src/storage.cr | 12 ++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/responses/zone.cr b/src/responses/zone.cr index 487f540..698f896 100644 --- a/src/responses/zone.cr +++ b/src/responses/zone.cr @@ -86,5 +86,21 @@ class DNSManager::Response end end DNSManager.responses << InvalidRR + + IPC::JSON.message RRUpdated, 21 do + property domain : String + property rr : Storage::Zone::ResourceRecord + def initialize(@domain, @rr) + end + end + DNSManager.responses << RRUpdated + + IPC::JSON.message RRReadOnly, 22 do + property domain : String + property rr : Storage::Zone::ResourceRecord + def initialize(@domain, @rr) + end + end + DNSManager.responses << RRReadOnly end diff --git a/src/storage.cr b/src/storage.cr index 3dc4271..eb58847 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -205,19 +205,23 @@ class DNSManager::Storage end end - # TODO: verify that this rr.rrid isn't ReadOnly. - stored_rr = zone.resources.select { |x| x.rrid == rr.rrid } - unless stored_rr.size > 0 + stored_rrs = zone.resources.select { |x| x.rrid == rr.rrid } + unless stored_rrs.size > 0 Baguette::Log.warning "modifying a RR that doesn't exist (#{rr.rrid}) in domain #{domain}" return Response::RRNotFound.new end + # Verify that this resource isn't ReadOnly. + stored_rrs.each do |stored_rr| + return Response::RRReadOnly.new domain, rr if stored_rr.readonly + end + zone.resources = zone.resources.map { |x| x.rrid == rr.rrid ? rr : x } # Update the zone. zones_by_domain.update_or_create zone.domain, zone - Response::Success.new + Response::RRUpdated.new domain, rr rescue e Baguette::Log.error "trying to replace a resource record in domain #{domain}: #{e}" Response::Error.new "error while replacing a resource record in domain #{domain}"