From 90aea947e134dffae4c416b81745a9dd72bbe1a7 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Sun, 1 Dec 2019 02:46:24 +0000 Subject: [PATCH] Ask for confirmation (unless -d) --- Cargo.toml | 3 +++ src/main.rs | 15 +++++++++------ src/server.rs | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b4adf50..ead8f42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,6 @@ getopts = "0.2" log = "0.4" tokio = { version = "0.2", features = ["full"] } tokio-libtls = "1.1.0-alpha.3" + +[profile.release] +panic = "abort" diff --git a/src/main.rs b/src/main.rs index c66fcae..e9ed4c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,12 +35,13 @@ use tokio_libtls::prelude::*; #[derive(Clone, Debug, Default)] pub(crate) struct Config { - keypair: Option, - ca: Option, - timeout: Option, - servername: Option, address: Option, + ca: Option, + dont_ask: bool, + keypair: Option, + servername: Option, size_limit: usize, + timeout: Option, } impl Config { @@ -98,6 +99,7 @@ async fn main() { let mut config = Config::new(); let mut opts = Options::new(); + opts.optflag("d", "dontask", "don't ask for confirmation (server)"); opts.optopt( "a", "address", @@ -110,8 +112,8 @@ async fn main() { "server name", &config.servername.as_ref().unwrap(), ); - opts.optopt("f", "file", "send file as client", "filename"); - opts.optflag("s", "server", "run server"); + opts.optopt("f", "file", "send a file (client)", "filename"); + opts.optflag("s", "server", "run as server"); opts.optflag("h", "help", "print this help menu"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -127,6 +129,7 @@ async fn main() { if let Some(servername) = matches.opt_str("n") { config.servername = Some(servername); } + config.dont_ask = matches.opt_present("d"); let addr = match config.address { Some(SocketAddr::V6(addr)) => addr.clone(), diff --git a/src/server.rs b/src/server.rs index ac6ae49..4915ae7 100644 --- a/src/server.rs +++ b/src/server.rs @@ -16,6 +16,7 @@ use crate::Config; use std::{ io::{Error, ErrorKind, Result}, path::{PathBuf, MAIN_SEPARATOR}, + process::Command, }; use tokio::{ fs::{remove_file, File}, @@ -45,6 +46,7 @@ pub(crate) async fn run(config: Config) -> Result<()> { let (tcp, _) = listener.accept().await?; let size_limit = config.size_limit as u64; let peer_addr: String = tcp.peer_addr()?.to_string(); + let dont_ask = config.dont_ask; let options = options.build(); let tls = match AsyncTls::accept_stream(tcp, &tls_config, options).await { Ok(tls) => { @@ -124,6 +126,23 @@ pub(crate) async fn run(config: Config) -> Result<()> { file_size ); + if !dont_ask { + match Command::new("ssh-askpass") + .arg(&format!( + "Yo! Do you want to accept {} ({} bytes)?", + filename.display(), + file_size + )) + .output() + { + Ok(output) if output.status.success() => {} + _ => { + info!("{} failed: rejected file", peer_addr); + return; + } + } + } + // Create output file let file = match File::create(&filename).await { Ok(f) => f,