From 1f1df9379160879f4ba4401bc62c1b72e4d78618 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Thu, 1 Jun 2017 19:02:53 +0200 Subject: [PATCH] Add "-debug" flag, and make use of it. --- sshd.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sshd.go b/sshd.go index 01f71bb..34a96cc 100644 --- a/sshd.go +++ b/sshd.go @@ -30,6 +30,7 @@ var ( hostkey = flag.String("hostkey", "id_rsa", "Server host key to load") authorisedkeys = flag.String("authorisedkeys", "authorized_keys", "Authorised keys") verbose = flag.Bool("verbose", false, "Enable verbose mode") + debug = flag.Bool("debug", false, "Enable debug mode") // TODO: Separate for read/write? (Right now assume that on either // read/write, reset deadline) @@ -379,18 +380,40 @@ func serve(cssh ssh.Channel, conn net.Conn, client *sshClient, timeout time.Dura var once sync.Once go func() { //io.Copy(cssh, conn) - _, _ = copyTimeout(cssh, conn, func() { + bytes_written, err := copyTimeout(cssh, conn, func() { + if *debug { + log.Printf("[%s] Updating deadline for direct|forwarded socket and main socket (sending data)", client.Name) + } conn.SetDeadline(time.Now().Add(timeout)) client.Conn.SetDeadline(time.Now().Add(*maintimeout)) }) + if err != nil { + if *debug { + log.Printf("[%s] copyTimeout failed with: %s", client.Name, err) + } + } + if *verbose { + log.Printf("[%s] Connection closed, bytes written: %d", client.Name, bytes_written) + } once.Do(close) }() go func() { //io.Copy(conn, cssh) - _, _ = copyTimeout(conn, cssh, func() { + bytes_written, err := copyTimeout(conn, cssh, func() { + if *debug { + log.Printf("[%s] Updating deadline for direct|forwarded socket and main socket (received data)", client.Name) + } conn.SetDeadline(time.Now().Add(timeout)) client.Conn.SetDeadline(time.Now().Add(*maintimeout)) }) + if err != nil { + if *debug { + log.Printf("[%s] copyTimeout failed with: %s", client.Name, err) + } + } + if *verbose { + log.Printf("[%s] Connection closed, bytes written: %d", client.Name, bytes_written) + } once.Do(close) }() }