diff --git a/Cargo.lock b/Cargo.lock index 0f60e6db..8157ae6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,12 +104,14 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "async-broadcast" -version = "0.5.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c48ccdbf6ca6b121e0f586cbc0e73ae440e56c67c30fa0873b4e110d9c26d2b" +checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e" dependencies = [ - "event-listener 2.5.3", + "event-listener 5.3.1", + "event-listener-strategy 0.5.2", "futures-core", + "pin-project-lite", ] [[package]] @@ -132,41 +134,20 @@ checksum = "c8828ec6e544c02b0d6691d21ed9f9218d0384a82542855073c2a3f58304aaf0" dependencies = [ "async-task", "concurrent-queue", - "fastrand 2.1.0", - "futures-lite 2.3.0", + "fastrand", + "futures-lite", "slab", ] [[package]] name = "async-fs" -version = "1.6.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279cf904654eeebfa37ac9bb1598880884924aab82e290aa65c9e77a0e142e06" +checksum = "ebcd09b382f40fcd159c2d695175b2ae620ffa5f3bd6f664131efff4e8b9e04a" dependencies = [ - "async-lock 2.8.0", - "autocfg", + "async-lock", "blocking", - "futures-lite 1.13.0", -] - -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock 2.8.0", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite 1.13.0", - "log", - "parking", - "polling 2.8.0", - "rustix 0.37.27", - "slab", - "socket2 0.4.10", - "waker-fn", + "futures-lite", ] [[package]] @@ -175,28 +156,19 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcccb0f599cfa2f8ace422d3555572f47424da5648a4382a9dd0310ff8210884" dependencies = [ - "async-lock 3.3.0", + "async-lock", "cfg-if", "concurrent-queue", "futures-io", - "futures-lite 2.3.0", + "futures-lite", "parking", - "polling 3.7.0", - "rustix 0.38.34", + "polling", + "rustix", "slab", "tracing", "windows-sys 0.52.0", ] -[[package]] -name = "async-lock" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" -dependencies = [ - "event-listener 2.5.3", -] - [[package]] name = "async-lock" version = "3.3.0" @@ -210,19 +182,22 @@ dependencies = [ [[package]] name = "async-process" -version = "1.8.1" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" +checksum = "f7eda79bbd84e29c2b308d1dc099d7de8dcc7035e48f4bf5dc4a531a44ff5e2a" dependencies = [ - "async-io 1.13.0", - "async-lock 2.8.0", + "async-channel", + "async-io", + "async-lock", "async-signal", + "async-task", "blocking", "cfg-if", - "event-listener 3.1.0", - "futures-lite 1.13.0", - "rustix 0.38.34", - "windows-sys 0.48.0", + "event-listener 5.3.1", + "futures-lite", + "rustix", + "tracing", + "windows-sys 0.52.0", ] [[package]] @@ -242,13 +217,13 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afe66191c335039c7bb78f99dc7520b0cbb166b3a1cb33a03f53d8a1c6f2afda" dependencies = [ - "async-io 2.3.2", - "async-lock 3.3.0", + "async-io", + "async-lock", "atomic-waker", "cfg-if", "futures-core", "futures-io", - "rustix 0.38.34", + "rustix", "signal-hook-registry", "slab", "windows-sys 0.52.0", @@ -401,7 +376,7 @@ dependencies = [ "async-channel", "async-task", "futures-io", - "futures-lite 2.3.0", + "futures-lite", "piper", ] @@ -546,17 +521,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "dhcproto" version = "0.9.0" @@ -594,6 +558,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +[[package]] +name = "endi" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" + [[package]] name = "enum-as-inner" version = "0.5.1" @@ -707,23 +677,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - -[[package]] -name = "event-listener" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - [[package]] name = "event-listener" version = "4.0.3" @@ -766,15 +719,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - [[package]] name = "fastrand" version = "2.1.0" @@ -860,28 +804,13 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-lite" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" dependencies = [ - "fastrand 2.1.0", + "fastrand", "futures-core", "futures-io", "parking", @@ -1083,7 +1012,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -1166,26 +1095,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.9.0" @@ -1248,12 +1157,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1284,15 +1187,6 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.9.1" @@ -1539,18 +1433,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "nix" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", - "memoffset 0.7.1", -] - [[package]] name = "nix" version = "0.27.1" @@ -1572,6 +1454,7 @@ dependencies = [ "cfg-if", "cfg_aliases", "libc", + "memoffset", ] [[package]] @@ -1694,26 +1577,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "464db0c665917b13ebb5d453ccdec4add5658ee1adc7affc7677615356a8afaf" dependencies = [ "atomic-waker", - "fastrand 2.1.0", + "fastrand", "futures-io", ] -[[package]] -name = "polling" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "concurrent-queue", - "libc", - "log", - "pin-project-lite", - "windows-sys 0.48.0", -] - [[package]] name = "polling" version = "3.7.0" @@ -1724,7 +1591,7 @@ dependencies = [ "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix 0.38.34", + "rustix", "tracing", "windows-sys 0.52.0", ] @@ -1747,11 +1614,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "once_cell", "toml_edit", ] @@ -1909,20 +1775,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustix" -version = "0.37.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - [[package]] name = "rustix" version = "0.38.34" @@ -1932,7 +1784,7 @@ dependencies = [ "bitflags 2.5.0", "errno", "libc", - "linux-raw-sys 0.4.14", + "linux-raw-sys", "windows-sys 0.52.0", ] @@ -2065,16 +1917,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.7" @@ -2165,8 +2007,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand 2.1.0", - "rustix 0.38.34", + "fastrand", + "rustix", "windows-sys 0.52.0", ] @@ -2218,7 +2060,7 @@ dependencies = [ "num_cpus", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.7", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -2276,9 +2118,9 @@ checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap 2.2.6", "toml_datetime", @@ -2431,7 +2273,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9" dependencies = [ - "memoffset 0.9.1", + "memoffset", "tempfile", "winapi", ] @@ -2481,12 +2323,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "waker-fn" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" - [[package]] name = "walkdir" version = "2.5.0" @@ -2766,30 +2602,27 @@ dependencies = [ [[package]] name = "zbus" -version = "3.15.2" +version = "4.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "675d170b632a6ad49804c8cf2105d7c31eddd3312555cffd4b740e08e97c25e6" +checksum = "851238c133804e0aa888edf4a0229481c753544ca12a60fd1c3230c8a500fe40" dependencies = [ "async-broadcast", "async-executor", "async-fs", - "async-io 1.13.0", - "async-lock 2.8.0", + "async-io", + "async-lock", "async-process", "async-recursion", "async-task", "async-trait", "blocking", - "byteorder", - "derivative", "enumflags2", - "event-listener 2.5.3", + "event-listener 5.3.1", "futures-core", "futures-sink", "futures-util", "hex", - "nix 0.26.4", - "once_cell", + "nix 0.29.0", "ordered-stream", "rand", "serde", @@ -2798,7 +2631,7 @@ dependencies = [ "static_assertions", "tracing", "uds_windows", - "winapi", + "windows-sys 0.52.0", "xdg-home", "zbus_macros", "zbus_names", @@ -2807,23 +2640,22 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "3.15.2" +version = "4.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7131497b0f887e8061b430c530240063d33bf9455fa34438f388a245da69e0a5" +checksum = "8d5a3f12c20bd473be3194af6b49d50d7bb804ef3192dc70eddedb26b85d9da7" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "regex", - "syn 1.0.109", + "syn 2.0.66", "zvariant_utils", ] [[package]] name = "zbus_names" -version = "2.6.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "437d738d3750bed6ca9b8d423ccc7a8eb284f6b1d6d4e225a0e4e6258d864c8d" +checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" dependencies = [ "serde", "static_assertions", @@ -2832,13 +2664,12 @@ dependencies = [ [[package]] name = "zvariant" -version = "3.15.2" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eef2be88ba09b358d3b58aca6e41cd853631d44787f319a1383ca83424fb2db" +checksum = "1724a2b330760dc7d2a8402d841119dc869ef120b139d29862d6980e9c75bfc9" dependencies = [ - "byteorder", + "endi", "enumflags2", - "libc", "serde", "static_assertions", "zvariant_derive", @@ -2846,24 +2677,24 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "3.15.2" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c24dc0bed72f5f90d1f8bb5b07228cbf63b3c6e9f82d82559d4bae666e7ed9" +checksum = "55025a7a518ad14518fb243559c058a2e5b848b015e31f1d90414f36e3317859" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", "zvariant_utils", ] [[package]] name = "zvariant_utils" -version = "1.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7234f0d811589db492d16893e3f21e8e2fd282e6d01b0cddee310322062cc200" +checksum = "fc242db087efc22bd9ade7aa7809e4ba828132edc312871584a6b4391bdf8786" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", ] diff --git a/Cargo.toml b/Cargo.toml index 420acdeb..532ba1c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ serde-value = "0.7.0" serde_json = "1.0.120" sysctl = "0.5.5" url = "2.5.2" -zbus = { version = "3.15.2" } +zbus = { version = "4.3.1" } nix = { version = "0.29.0", features = ["sched", "signal", "user"] } rand = "0.8.5" sha2 = "0.10.8" diff --git a/src/commands/firewalld_reload.rs b/src/commands/firewalld_reload.rs index 0e1d8846..2a78811a 100644 --- a/src/commands/firewalld_reload.rs +++ b/src/commands/firewalld_reload.rs @@ -40,7 +40,7 @@ pub fn listen(config_dir: Option) -> NetavarkResult<()> { reload_rules(config_dir); // This loops forever until the process is killed or there is some dbus error. - for _ in proxy.receive_signal(SIGNAL_NAME)? { + for _ in proxy.0.receive_signal(SIGNAL_NAME)? { log::debug!("got firewalld {} signal", SIGNAL_NAME); reload_rules(config_dir); } diff --git a/src/firewall/firewalld.rs b/src/firewall/firewalld.rs index 635b2628..ab2dcafc 100644 --- a/src/firewall/firewalld.rs +++ b/src/firewall/firewalld.rs @@ -128,28 +128,27 @@ impl firewall::FirewallDriver for FirewallD { "getPolicySettings", &(PORTPOLICYNAME), )?; - let policy_config: HashMap<&str, Value> = match policy_config_msg.body() { - Ok(m) => m, - Err(e) => { - return Err(NetavarkError::wrap( - format!( - "Error decoding DBus message for policy {PORTPOLICYNAME} configuration" - ), - e.into(), - )) - } - }; + let body = policy_config_msg.body(); + let policy_config: HashMap<&str, Value> = body.deserialize().map_err(|e| { + NetavarkError::wrap( + format!("Error decoding DBus message for policy {PORTPOLICYNAME} configuration"), + e.into(), + ) + })?; let mut port_forwarding_rules: Array; match policy_config.get("forward_ports") { - Some(a) => match a { - Value::Array(arr) => port_forwarding_rules = arr.clone(), - _ => { - return Err(NetavarkError::msg( - "forward-port in firewalld policy object has a bad type", - )) + Some(a) => { + port_forwarding_rules = if let Value::Array(arr) = a { + Some(arr) + } else { + None } - }, + .and_then(|arr| arr.try_clone().ok()) + .ok_or_else(|| { + NetavarkError::msg("forward-port in firewalld policy object has a bad type") + })? + } None => { // No existing rules // Make us a new array. @@ -200,14 +199,17 @@ impl firewall::FirewallDriver for FirewallD { if setup_portfw.dns_port != 53 && !setup_portfw.dns_server_ips.is_empty() { let mut rich_rules: Array; match policy_config.get("rich_rules") { - Some(a) => match a { - Value::Array(arr) => rich_rules = arr.clone(), - _ => { - return Err(NetavarkError::msg( - "forward-port in firewalld policy object has a bad type", - )) + Some(a) => { + rich_rules = if let Value::Array(arr) = a { + Some(arr) + } else { + None } - }, + .and_then(|arr| arr.try_clone().ok()) + .ok_or_else(|| { + NetavarkError::msg("forward-port in firewalld policy object has a bad type") + })? + } None => { // No existing rules // Make us a new array. @@ -277,28 +279,28 @@ impl firewall::FirewallDriver for FirewallD { "getPolicySettings", &(PORTPOLICYNAME), )?; - let policy_config: HashMap<&str, Value> = match policy_config_msg.body() { - Ok(m) => m, - Err(e) => { - return Err(NetavarkError::wrap( - format!( - "Error decoding DBus message for policy {PORTPOLICYNAME} configuration" - ), - e.into(), - )) - } - }; + let body = policy_config_msg.body(); + let policy_config: HashMap<&str, Value> = body.deserialize().map_err(|e| { + NetavarkError::wrap( + format!("Error decoding DBus message for policy {PORTPOLICYNAME} configuration"), + e.into(), + ) + })?; let old_port_forwarding_rules_option: Option = match policy_config.get("forward_ports") { - Some(a) => match a { - Value::Array(arr) => Some(arr.clone()), - _ => { - return Err(NetavarkError::msg( - "forward-port in firewalld policy object has a bad type", - )) + Some(a) => { + let value = if let Value::Array(arr) = a { + Some(arr) + } else { + None } - }, + .and_then(|arr| arr.try_clone().ok()) + .ok_or_else(|| { + NetavarkError::msg("forward-port in firewalld policy object has a bad type") + })?; + Some(value) + } None => { // No existing rules - skip None @@ -333,19 +335,29 @@ impl firewall::FirewallDriver for FirewallD { for port_tuple in old_port_forwarding_rules.iter() { match port_tuple { Value::Structure(s) => { - let fields = s.clone().into_fields(); + let fields = s + .try_clone() + .map_err(|e| { + NetavarkError::wrap( + "Invalid port forwarding rule encountered", + e.into(), + ) + })? + .into_fields(); if fields.len() != 4 { return Err(NetavarkError::msg( "Port forwarding rule that was not a 4-tuple encountered", )); } - let port_ip = match fields[3].clone() { - Value::Str(s) => s.as_str().to_string(), + let port_ip = match fields[3].try_clone() { + Ok(Value::Str(s)) => s.as_str().to_string(), _ => return Err(NetavarkError::msg("Port forwarding tuples must contain only strings, encountered a non-string object")), }; debug!("IP string from firewalld is {}", port_ip); if port_ip != ipv4 && port_ip != ipv6 { - port_forwarding_rules.append(port_tuple.clone())?; + port_forwarding_rules.append(port_tuple.try_clone().map_err( + |e| NetavarkError::wrap("TODO: write a proper message", e.into()), + )?)?; } } _ => { @@ -368,14 +380,17 @@ impl firewall::FirewallDriver for FirewallD { && !teardown_pf.config.dns_server_ips.is_empty() { if let Some(a) = policy_config.get("rich_rules") { - match a { - Value::Array(arr) => old_rich_rules_option = Some(arr.clone()), - _ => { - return Err(NetavarkError::msg( - "forward-port in firewalld policy object has a bad type", - )) + old_rich_rules_option = Some( + if let Value::Array(arr) = a { + Some(arr) + } else { + None } - } + .and_then(|arr| arr.try_clone().ok()) + .ok_or_else(|| { + NetavarkError::msg("forward-port in firewalld policy object has a bad type") + })?, + ); } } if let Some(old_rich_rules) = old_rich_rules_option { @@ -397,17 +412,13 @@ impl firewall::FirewallDriver for FirewallD { }; let mut rich_rules = Array::new(sig); for rule in old_rich_rules.iter() { - match rule { - Value::Str(old_rule) => { - if !rules_to_delete.contains(&old_rule.to_string()) { - rich_rules.append(rule.clone())?; - } - } - _ => { - return Err(NetavarkError::msg( - "Rich rule that was not a string encountered", - )) - } + let Ok(Value::Str(old_rule)) = rule.try_clone() else { + return Err(NetavarkError::msg( + "Rich rule that was not a string encountered", + )); + }; + if !rules_to_delete.contains(&old_rule.to_string()) { + rich_rules.append(Value::Str(old_rule))?; } } rich_rules_option = Some(rich_rules); @@ -464,15 +475,10 @@ fn create_zone_if_not_exist(conn: &Connection, zone_name: &str) -> NetavarkResul "getZones", &(), )?; - let zones: Vec<&str> = match zones_msg.body() { - Ok(b) => b, - Err(e) => { - return Err(NetavarkError::wrap( - "Error decoding DBus message for active zones", - e.into(), - )) - } - }; + let body = zones_msg.body(); + let zones: Vec<&str> = body.deserialize().map_err(|e| { + NetavarkError::wrap("Error decoding DBus message for active zones", e.into()) + })?; for &zone in zones.iter() { if zone == zone_name { debug!("Zone exists and is running"); @@ -488,15 +494,10 @@ fn create_zone_if_not_exist(conn: &Connection, zone_name: &str) -> NetavarkResul "getZoneNames", &(), )?; - let zones_perm: Vec<&str> = match perm_zones_msg.body() { - Ok(b) => b, - Err(e) => { - return Err(NetavarkError::wrap( - "Error decoding DBus message for permanent zones", - e.into(), - )) - } - }; + let body = perm_zones_msg.body(); + let zones_perm: Vec<&str> = body.deserialize().map_err(|e| { + NetavarkError::wrap("Error decoding DBus message for permanent zones", e.into()) + })?; for &zone in zones_perm.iter() { if zone == zone_name { debug!("Zone exists and is not running"); @@ -535,15 +536,9 @@ pub fn add_source_subnets_to_zone( "getZoneOfSource", &(net.to_string()), )?; - let zone_string: String = match subnet_zone.body() { - Ok(s) => s, - Err(e) => { - return Err(NetavarkError::wrap( - "Error decoding DBus message for zone of subnet", - e.into(), - )) - } - }; + let zone_string: String = subnet_zone.body().deserialize().map_err(|e| { + NetavarkError::wrap("Error decoding DBus message for zone of subnet", e.into()) + })?; if zone_string == zone_name { debug!("Subnet {} already exists in zone {}", net, zone_name); return Ok(()); @@ -584,15 +579,10 @@ fn add_policy_if_not_exist( "getPolicies", &(), )?; - let policies: Vec<&str> = match policies_msg.body() { - Ok(v) => v, - Err(e) => { - return Err(NetavarkError::wrap( - "Error decoding policy list response", - e.into(), - )) - } - }; + let body = policies_msg.body(); + let policies: Vec<&str> = body + .deserialize() + .map_err(|e| NetavarkError::wrap("Error decoding policy list response", e.into()))?; for &policy in policies.iter() { if policy == policy_name { debug!("Policy exists and is running"); @@ -608,15 +598,10 @@ fn add_policy_if_not_exist( "getPolicyNames", &(), )?; - let perm_policies: Vec<&str> = match perm_policies_msg.body() { - Ok(v) => v, - Err(e) => { - return Err(NetavarkError::wrap( - "Error decoding permanent policy list response", - e.into(), - )) - } - }; + let body = perm_policies_msg.body(); + let perm_policies: Vec<&str> = body.deserialize().map_err(|e| { + NetavarkError::wrap("Error decoding permanent policy list response", e.into()) + })?; for &policy in perm_policies.iter() { if policy == policy_name { debug!("Policy exists and is not running");