Excessive debugging off; client logout (exit) causing panic on server-side, debug TBD

This commit is contained in:
Russ Magee 2018-03-25 21:47:38 -07:00
parent 5ea75e456d
commit 65b7af8063
2 changed files with 30 additions and 13 deletions

View File

@ -9,7 +9,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"strings"
"syscall" "syscall"
hkex "blitter.com/hkexsh" hkex "blitter.com/hkexsh"
@ -27,7 +26,8 @@ type cmdSpec struct {
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
// Run a command (via os.exec) as a specific user /*
// Run a command (via os.exec) as a specific user
// //
// Uses ptys to support commands which expect a terminal. // Uses ptys to support commands which expect a terminal.
func runCmdAs(who string, cmd string, conn hkex.Conn) (err error) { func runCmdAs(who string, cmd string, conn hkex.Conn) (err error) {
@ -66,6 +66,7 @@ func runCmdAs(who string, cmd string, conn hkex.Conn) (err error) {
} }
return return
} }
*/
// Run a command (via default shell) as a specific user // Run a command (via default shell) as a specific user
// //
@ -111,8 +112,11 @@ func runShellAs(who string, cmd string, interactive bool, conn hkex.Conn) (err e
} }
// Make sure to close the pty at the end. // Make sure to close the pty at the end.
defer func() { _ = ptmx.Close() }() // Best effort. defer func() { _ = ptmx.Close() }() // Best effort.
// Copy stdin to the pty and the pty to stdout. // Copy stdin to the pty.. (bgnd goroutine)
go func() { _, _ = io.Copy(ptmx, conn) }() go func() {
_, _ = io.Copy(ptmx, conn)
}()
// ..and the pty to stdout.
_, _ = io.Copy(conn, ptmx) _, _ = io.Copy(conn, ptmx)
//err = c.Run() // returns when c finishes. //err = c.Run() // returns when c finishes.
@ -176,10 +180,10 @@ func main() {
//passed down to the command handlers. //passed down to the command handlers.
var rec cmdSpec var rec cmdSpec
var len1, len2, len3, len4 uint32 var len1, len2, len3, len4 uint32
n, err := fmt.Fscanf(c, "%d %d %d %d\n", &len1, &len2, &len3, &len4) n, err := fmt.Fscanf(c, "%d %d %d %d\n", &len1, &len2, &len3, &len4)
log.Printf("cmdSpec read:%d %d %d %d\n", len1, len2, len3, len4) log.Printf("cmdSpec read:%d %d %d %d\n", len1, len2, len3, len4)
if err != nil || n < 4 { if err != nil || n < 4 {
log.Println("[Bad cmdSpec fmt]") log.Println("[Bad cmdSpec fmt]")
return err return err

View File

@ -299,10 +299,10 @@ func (hl HKExListener) Accept() (hc Conn, err error) {
// See go doc io.Reader // See go doc io.Reader
func (c Conn) Read(b []byte) (n int, err error) { func (c Conn) Read(b []byte) (n int, err error) {
//log.Printf("[Decrypting...]\r\n") //log.Printf("[Decrypting...]\r\n")
//log.Printf("Read() requests %d bytes\n", len(b)) log.Printf("Read() requests %d bytes\n", len(b))
for { for {
//log.Printf("c.dBuf.Len(): %d\n", c.dBuf.Len()) //log.Printf("c.dBuf.Len(): %d\n", c.dBuf.Len())
if c.dBuf.Len() >= 1 /* len(b) */ { if c.dBuf.Len() > 0 /* len(b) */ {
break break
} }
@ -311,13 +311,21 @@ func (c Conn) Read(b []byte) (n int, err error) {
// Read the hmac LSB and payload len first // Read the hmac LSB and payload len first
err = binary.Read(c.c, binary.BigEndian, &hmacIn) err = binary.Read(c.c, binary.BigEndian, &hmacIn)
if err != nil && err.Error() != "EOF" { if err != nil {
panic(err) if err.Error() != "EOF" {
log.Println("Error was:", err.Error())
} else {
return 0, err
}
} }
err = binary.Read(c.c, binary.BigEndian, &payloadLen) err = binary.Read(c.c, binary.BigEndian, &payloadLen)
if err != nil { if err != nil {
// if err.Error() != "EOF" {
panic(err) panic(err)
// } else {
// return 0, err
// }
} }
if payloadLen > 16384 { if payloadLen > 16384 {
panic("Insane payloadLen") panic("Insane payloadLen")
@ -359,10 +367,15 @@ func (c Conn) Read(b []byte) (n int, err error) {
hTmp := c.rm.Sum(nil)[0] hTmp := c.rm.Sum(nil)[0]
log.Printf("<%04x) HMAC:(i)%02x (c)%02x\r\n", decryptN, hmacIn, hTmp) log.Printf("<%04x) HMAC:(i)%02x (c)%02x\r\n", decryptN, hmacIn, hTmp)
} }
//log.Printf("Read() got %d bytes\n", c.dBuf.Len()) retN := c.dBuf.Len()
copy(b, c.dBuf.Next(len(b))) if retN > len(b) {
retN = len(b)
}
log.Printf("Read() got %d bytes\n", retN)
copy(b, c.dBuf.Next(retN))
//log.Printf("As Read() returns, c.dBuf is %d long: %s\n", c.dBuf.Len(), hex.Dump(c.dBuf.Bytes())) //log.Printf("As Read() returns, c.dBuf is %d long: %s\n", c.dBuf.Len(), hex.Dump(c.dBuf.Bytes()))
return len(b), nil return retN, nil
} }
// Write a byte slice // Write a byte slice