Commit 673ba67f authored by Thomas Gatzweiler's avatar Thomas Gatzweiler
Browse files

Add verbose option to sshd

parent 86d7d48a
extern crate ssh;
extern crate log;
use std::env;
use std::fs::File;
......@@ -6,11 +7,28 @@ use std::io::{self, Write};
use std::process;
use std::str::FromStr;
use log::{LogLevelFilter, LogMetadata, LogRecord};
use ssh::{Server, ServerConfig};
use ssh::public_key::ED25519;
struct StdErrLogger;
impl log::Log for StdErrLogger {
fn enabled(&self, _: &LogMetadata) -> bool {
true
}
fn log(&self, record: &LogRecord) {
if self.enabled(record.metadata()) {
writeln!(io::stderr(), "{} - {}", record.level(), record.args())
.unwrap();
}
}
}
pub fn main() {
let mut quiet = false;
let mut verbose = false;
let key_pair = File::open("server.key").and_then(
|mut f| (ED25519.import)(&mut f),
......@@ -32,7 +50,7 @@ pub fn main() {
while let Some(arg) = args.next() {
match arg.as_ref()
{
"-q" => quiet = true,
"-v" => verbose = true,
"-p" => {
config.port =
u16::from_str(
......@@ -43,6 +61,13 @@ pub fn main() {
}
}
if verbose {
log::set_logger(|max_log_level| {
max_log_level.set(LogLevelFilter::Trace);
Box::new(StdErrLogger)
}).unwrap();
}
let server = Server::with_config(config);
if let Err(err) = server.run() {
......
......@@ -55,7 +55,7 @@ impl<W: Write> Connection<W> {
loop {
let packet = Packet::read_from(&mut stream)?;
println!("packet: {:?}", packet);
self.process(&packet);
self.process(&packet)?;
}
}
......
......@@ -24,9 +24,13 @@ impl Packet {
pub fn read_from<R: io::Read>(stream: &mut R) -> Result<Packet> {
let mac_len = 0;
trace!("Waiting for incoming packet...");
let packet_len = stream.read_u32::<BigEndian>()? as usize;
trace!("Read incoming packet ({} bytes)", packet_len);
let padding_len = stream.read_u8()? as usize;
let payload_len = packet_len - padding_len - 1;
trace!("Padding: {} bytes", padding_len);
// TODO: Prevent packets that are too large
......@@ -34,7 +38,9 @@ impl Packet {
let mut padding = Vec::with_capacity(padding_len);
// let mut mac = Vec::with_capacity(mac_len);
trace!("Reading packet...");
stream.take(payload_len as u64).read_to_end(&mut payload)?;
trace!("Reading payload...");
stream.take(padding_len as u64).read_to_end(&mut padding)?;
// if mac_len > 0 {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment