From 2b145ebeffd46f65ae2386bda99c4008117aa82c Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 2 Jan 2024 15:58:39 +0100 Subject: [PATCH] Prevent default rules from being deleted --- virtweb_backend/src/controllers/nwfilter_controller.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/virtweb_backend/src/controllers/nwfilter_controller.rs b/virtweb_backend/src/controllers/nwfilter_controller.rs index 8bda625..bdbbbcb 100644 --- a/virtweb_backend/src/controllers/nwfilter_controller.rs +++ b/virtweb_backend/src/controllers/nwfilter_controller.rs @@ -100,6 +100,13 @@ pub async fn update( /// Delete a network filter pub async fn delete(client: LibVirtReq, path: web::Path) -> HttpResult { + // Prevent deletion of default rules + let network = client.get_single_network_filter(path.uid).await?; + if constants::BUILTIN_NETWORK_FILTER_RULES.contains(&network.name.as_str()) { + return Ok(HttpResponse::ExpectationFailed() + .json("Builtin network filter rules shall not be deleted!")); + } + client.delete_network_filter(path.uid).await?; Ok(HttpResponse::Ok().json("Network deleted"))