diff --git a/client/src/main.rs b/client/src/main.rs index bcf25d8..de5ca89 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -725,7 +725,7 @@ fn delete_cidr( let cidr_id = prompts::delete_cidr(&cidrs, &peers, &sub_opts)?; println!("Deleting CIDR..."); - let _ = api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?; + api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?; println!("CIDR deleted."); @@ -801,7 +801,7 @@ fn rename_peer( .next() .ok_or_else(|| anyhow!("Peer not found."))?; - let _ = api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?; + api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?; log::info!("Peer renamed."); } else { log::info!("exited without renaming peer."); diff --git a/server/src/main.rs b/server/src/main.rs index 1109352..9bf9986 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -357,7 +357,7 @@ fn rename_peer( .into_iter() .find(|p| p.name == old_name) .ok_or_else(|| anyhow!("Peer not found."))?; - let _peer = db_peer.update(&conn, peer_request)?; + db_peer.update(&conn, peer_request)?; } else { println!("exited without creating peer."); } @@ -408,7 +408,7 @@ fn delete_cidr( let cidr_id = prompts::delete_cidr(&cidrs, &peers, &args)?; println!("Deleting CIDR..."); - let _ = DatabaseCidr::delete(&conn, cidr_id)?; + DatabaseCidr::delete(&conn, cidr_id)?; println!("CIDR deleted."); diff --git a/wireguard-control/src/backends/kernel.rs b/wireguard-control/src/backends/kernel.rs index 2e22320..0aca7cb 100644 --- a/wireguard-control/src/backends/kernel.rs +++ b/wireguard-control/src/backends/kernel.rs @@ -34,7 +34,7 @@ macro_rules! get_nla_value { }; } -impl<'a> TryFrom for AllowedIp { +impl TryFrom for AllowedIp { type Error = io::Error; fn try_from(attrs: WgAllowedIp) -> Result { @@ -88,7 +88,7 @@ impl PeerConfigBuilder { } } -impl<'a> TryFrom for PeerInfo { +impl TryFrom for PeerInfo { type Error = io::Error; fn try_from(attrs: WgPeer) -> Result { diff --git a/wireguard-control/src/backends/userspace.rs b/wireguard-control/src/backends/userspace.rs index 3e34039..7cf1194 100644 --- a/wireguard-control/src/backends/userspace.rs +++ b/wireguard-control/src/backends/userspace.rs @@ -1,8 +1,7 @@ -use crate::{Backend, Device, DeviceUpdate, InterfaceName, PeerConfig, PeerInfo, PeerStats}; - -use crate::Key; +use crate::{Backend, Device, DeviceUpdate, InterfaceName, Key, PeerConfig, PeerInfo, PeerStats}; use std::{ + fmt::Write as _, fs, io::{self, prelude::*, BufReader}, os::unix::net::UnixStream, @@ -311,55 +310,61 @@ pub fn apply(builder: &DeviceUpdate, iface: &InterfaceName) -> io::Result<()> { let mut request = String::from("set=1\n"); if let Some(ref k) = builder.private_key { - request.push_str(&format!("private_key={}\n", hex::encode(k.as_bytes()))); + writeln!(request, "private_key={}", hex::encode(k.as_bytes())).ok(); } if let Some(f) = builder.fwmark { - request.push_str(&format!("fwmark={}\n", f)); + writeln!(request, "fwmark={}", f).ok(); } if let Some(f) = builder.listen_port { - request.push_str(&format!("listen_port={}\n", f)); + writeln!(request, "listen_port={}", f).ok(); } if builder.replace_peers { - request.push_str("replace_peers=true\n"); + writeln!(request, "replace_peers=true").ok(); } for peer in &builder.peers { - request.push_str(&format!( - "public_key={}\n", + writeln!( + request, + "public_key={}", hex::encode(peer.public_key.as_bytes()) - )); + ) + .ok(); if peer.replace_allowed_ips { - request.push_str("replace_allowed_ips=true\n"); + writeln!(request, "replace_allowed_ips=true").ok(); } if peer.remove_me { - request.push_str("remove=true\n"); + writeln!(request, "remove=true").ok(); } if let Some(ref k) = peer.preshared_key { - request.push_str(&format!("preshared_key={}\n", hex::encode(k.as_bytes()))); + writeln!(request, "preshared_key={}", hex::encode(k.as_bytes())).ok(); } if let Some(endpoint) = peer.endpoint { - request.push_str(&format!("endpoint={}\n", endpoint)); + writeln!(request, "endpoint={}", endpoint).ok(); } if let Some(keepalive_interval) = peer.persistent_keepalive_interval { - request.push_str(&format!( - "persistent_keepalive_interval={}\n", + writeln!( + request, + "persistent_keepalive_interval={}", keepalive_interval - )); + ) + .ok(); } for allowed_ip in &peer.allowed_ips { - request.push_str(&format!( - "allowed_ip={}/{}\n", + writeln!( + request, + "allowed_ip={}/{}", allowed_ip.address, allowed_ip.cidr - )); + ) + .ok(); } }