Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While preparing to port my netcat/tar shell combo to shoop, I noticed… #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ pub struct Server {
sock: UdtSocket,
}

pub type SSHPort = String;

pub struct Client {
addr: SocketAddr,
sock: UdtSocket,
crypto: crypto::Handler,
ssh_port: SSHPort
}

pub struct ServerConnection {
Expand All @@ -105,12 +108,13 @@ pub struct ServerConnection {
}

impl Client {
pub fn new(addr: SocketAddr, key: &[u8]) -> Client {
pub fn new(addr: SocketAddr, key: &[u8], ssh_port: &str) -> Client {
let sock = new_udt_socket();
Client {
addr: addr,
sock: sock,
crypto: crypto::Handler::new(key),
ssh_port: ssh_port.to_owned()
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod progress;

use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use colored::*;
use connection::{PortRange, Transceiver};
use connection::{PortRange, SSHPort, Transceiver};
use log::{Record, Level, Metadata};
use std::net::{SocketAddr, IpAddr};
use std::fs::File;
Expand Down Expand Up @@ -99,6 +99,7 @@ enum TransferState {
pub struct Client {
port_range: PortRange,
transfer_state: TransferState,
ssh_port: SSHPort
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -488,7 +489,7 @@ impl Server {

impl Client {

pub fn new(source: Target, dest: Target, port_range: PortRange)
pub fn new(source: Target, dest: Target, port_range: PortRange, ssh_port: SSHPort)
-> Result<Client, String> {
if source.is_local() && dest.is_local() ||
source.is_remote() && dest.is_remote() {
Expand Down Expand Up @@ -541,7 +542,8 @@ impl Client {

Ok(Client {
port_range: port_range,
transfer_state: state
transfer_state: state,
ssh_port: ssh_port
})
}

Expand All @@ -551,7 +553,7 @@ impl Client {
panic!("sending unsupported");
}
TransferState::Receive((host, path), _) => {
ssh::Connection::new(host, path, &self.port_range)
ssh::Connection::new(host, path, &self.port_range, &self.ssh_port)
}
};

Expand Down Expand Up @@ -627,7 +629,7 @@ impl Client {

loop {
overprint!(" - opening UDT connection...");
let mut conn = connection::Client::new(addr, &keybytes);
let mut conn = connection::Client::new(addr, &keybytes, &self.ssh_port);
match conn.connect() {
Ok(()) => {
overprint!(" - connection opened, shakin' hands, makin' frands");
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct Opt {
#[structopt(short = "p", long = "port-range", default_value = "55000-55050")]
port_range: String,

#[structopt(short = "P", long = "ssh-port", default_value = "22")]
ssh_port: String,

#[structopt(name = "SOURCE", help = "The source target, ex. \"my.server.com:~/file.bin\"")]
source: String,

Expand All @@ -44,6 +47,8 @@ fn main() {

let port_range = PortRange::from(&opt.port_range).unwrap();

let ssh_port = opt.ssh_port;

ShoopLogger::init(mode, verbosity).expect("Error starting shoop logger.");

match mode {
Expand All @@ -58,8 +63,8 @@ fn main() {
ShoopMode::Client => {
let source = Target::from(opt.source.clone());
let dest = Target::from(opt.dest.clone());

match Client::new(source, dest, port_range) {
match Client::new(source, dest, port_range, ssh_port) {
Ok(mut client) => client.start(opt.force),
Err(e) => error!("{}", e),
}
Expand Down
12 changes: 9 additions & 3 deletions src/ssh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use connection::PortRange;
use connection::{PortRange, SSHPort};
use std::collections::HashMap;
use std::io;
use std::net::SocketAddr;
Expand Down Expand Up @@ -33,6 +33,7 @@ pub struct Connection {
hostname: String,
path: PathBuf,
port_range: PortRange,
ssh_port: SSHPort
}

pub struct Response {
Expand Down Expand Up @@ -70,11 +71,12 @@ impl From<io::Error> for Error {
}

impl Connection {
pub fn new<S: Into<String>>(hostname: S, path: PathBuf, port_range: &PortRange) -> Connection {
pub fn new<S: Into<String>>(hostname: S, path: PathBuf, port_range: &PortRange, ssh_port: &SSHPort) -> Connection {
Connection {
hostname: hostname.into(),
path: path,
port_range: port_range.to_owned(),
ssh_port: ssh_port.to_owned()
}
}

Expand All @@ -94,7 +96,10 @@ impl Connection {
self.path.to_string_lossy(),
self.port_range);
debug!("👉 ssh {} {}", &self.hostname, cmd);

let mut command = Command::new("ssh");
command.arg(format!("-p {}", &self.ssh_port));

for arg in extra_args {
command.arg(&arg);
}
Expand All @@ -103,7 +108,8 @@ impl Connection {
.output());

if !output.status.success() {
Err(Error::new(ErrorType::SshError, "ssh returned failure exit code"))
let err = String::from_utf8_lossy(&output.stderr);
Err(Error::new(ErrorType::SshError, format!("ssh returned failure exit code: {:?}", err)))
} else {
Ok(output)
}
Expand Down