diff options
author | Hristo Venev <hristo@venev.name> | 2020-02-04 20:31:51 +0100 |
---|---|---|
committer | Hristo Venev <hristo@venev.name> | 2020-02-04 20:31:51 +0100 |
commit | c4f743e2a33ba39036f7e9919b7adc80415b1754 (patch) | |
tree | c708bbc6e089a1b66c61d189a010cb2a80aa0a34 /src/wg.rs | |
parent | 3f5c00af303c1b706a74cafa58ff23b068f6d819 (diff) |
Reference preshared keys by path.
Diffstat (limited to 'src/wg.rs')
-rw-r--r-- | src/wg.rs | 24 |
1 files changed, 5 insertions, 19 deletions
@@ -2,21 +2,19 @@ // // Copyright 2019 Hristo Venev -use crate::{fileutil, model}; +use crate::model; use std::ffi::{OsStr, OsString}; -use std::path::PathBuf; use std::process::{Command, Stdio}; -use std::{env, io, mem}; +use std::{env, io}; pub struct Device { ifname: OsString, - tmpdir: PathBuf, } impl Device { #[inline] - pub fn open(ifname: OsString, tmpdir: PathBuf) -> io::Result<Self> { - let dev = Self { ifname, tmpdir }; + pub fn open(ifname: OsString) -> io::Result<Self> { + let dev = Self { ifname }; let _ = dev.get_public_key()?; Ok(dev) } @@ -60,8 +58,6 @@ impl Device { proc.arg("set"); proc.arg(&self.ifname); - let mut tmps = vec![]; - for (pubkey, conf) in &new.peers { let old_endpoint; if let Some(old_peer) = old.peers.get(pubkey) { @@ -88,16 +84,7 @@ impl Device { if let Some(psk) = &conf.psk { proc.arg("preshared-key"); - let mut tmp = self.tmpdir.clone(); - tmp.push(format!("tmp-{}", tmps.len())); - let mut tmp = fileutil::Writer::new(tmp)?; - { - use io::Write; - writeln!(tmp.file(), "{}", psk)?; - } - let tmp = tmp.done(); - proc.arg(tmp.path()); - tmps.push(tmp); + proc.arg(psk.path()); } let mut ips = String::new(); @@ -131,7 +118,6 @@ impl Device { } let r = proc.status()?; - mem::drop(tmps); if !r.success() { return Err(io::Error::new(io::ErrorKind::Other, "child process failed")); } |