Ask for confirmation (unless -d)

This commit is contained in:
reykfloeter 2019-12-01 02:46:24 +00:00
parent 60a0a3a081
commit 90aea947e1
3 changed files with 31 additions and 6 deletions

View file

@ -14,3 +14,6 @@ getopts = "0.2"
log = "0.4" log = "0.4"
tokio = { version = "0.2", features = ["full"] } tokio = { version = "0.2", features = ["full"] }
tokio-libtls = "1.1.0-alpha.3" tokio-libtls = "1.1.0-alpha.3"
[profile.release]
panic = "abort"

View file

@ -35,12 +35,13 @@ use tokio_libtls::prelude::*;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub(crate) struct Config { pub(crate) struct Config {
keypair: Option<KeyPair>,
ca: Option<PathBuf>,
timeout: Option<Duration>,
servername: Option<String>,
address: Option<SocketAddr>, address: Option<SocketAddr>,
ca: Option<PathBuf>,
dont_ask: bool,
keypair: Option<KeyPair>,
servername: Option<String>,
size_limit: usize, size_limit: usize,
timeout: Option<Duration>,
} }
impl Config { impl Config {
@ -98,6 +99,7 @@ async fn main() {
let mut config = Config::new(); let mut config = Config::new();
let mut opts = Options::new(); let mut opts = Options::new();
opts.optflag("d", "dontask", "don't ask for confirmation (server)");
opts.optopt( opts.optopt(
"a", "a",
"address", "address",
@ -110,8 +112,8 @@ async fn main() {
"server name", "server name",
&config.servername.as_ref().unwrap(), &config.servername.as_ref().unwrap(),
); );
opts.optopt("f", "file", "send file as client", "filename"); opts.optopt("f", "file", "send a file (client)", "filename");
opts.optflag("s", "server", "run server"); opts.optflag("s", "server", "run as server");
opts.optflag("h", "help", "print this help menu"); opts.optflag("h", "help", "print this help menu");
let matches = match opts.parse(&args[1..]) { let matches = match opts.parse(&args[1..]) {
Ok(m) => m, Ok(m) => m,
@ -127,6 +129,7 @@ async fn main() {
if let Some(servername) = matches.opt_str("n") { if let Some(servername) = matches.opt_str("n") {
config.servername = Some(servername); config.servername = Some(servername);
} }
config.dont_ask = matches.opt_present("d");
let addr = match config.address { let addr = match config.address {
Some(SocketAddr::V6(addr)) => addr.clone(), Some(SocketAddr::V6(addr)) => addr.clone(),

View file

@ -16,6 +16,7 @@ use crate::Config;
use std::{ use std::{
io::{Error, ErrorKind, Result}, io::{Error, ErrorKind, Result},
path::{PathBuf, MAIN_SEPARATOR}, path::{PathBuf, MAIN_SEPARATOR},
process::Command,
}; };
use tokio::{ use tokio::{
fs::{remove_file, File}, fs::{remove_file, File},
@ -45,6 +46,7 @@ pub(crate) async fn run(config: Config) -> Result<()> {
let (tcp, _) = listener.accept().await?; let (tcp, _) = listener.accept().await?;
let size_limit = config.size_limit as u64; let size_limit = config.size_limit as u64;
let peer_addr: String = tcp.peer_addr()?.to_string(); let peer_addr: String = tcp.peer_addr()?.to_string();
let dont_ask = config.dont_ask;
let options = options.build(); let options = options.build();
let tls = match AsyncTls::accept_stream(tcp, &tls_config, options).await { let tls = match AsyncTls::accept_stream(tcp, &tls_config, options).await {
Ok(tls) => { Ok(tls) => {
@ -124,6 +126,23 @@ pub(crate) async fn run(config: Config) -> Result<()> {
file_size 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 // Create output file
let file = match File::create(&filename).await { let file = match File::create(&filename).await {
Ok(f) => f, Ok(f) => f,