diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33b101a --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +sshserver + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (uncomment if using dep or similar) +# vendor/ + +# Go workspace file +go.work + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo + +# Logs +*.log + +# Temporary files +*.tmp + +# SSH host key +host_key \ No newline at end of file diff --git a/main.go b/main.go index 3eab7d1..e301581 100644 --- a/main.go +++ b/main.go @@ -95,15 +95,32 @@ func handleConn(conn net.Conn, config *ssh.ServerConfig) { func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) { defer channel.Close() var ptmx *os.File + var termWidth, termHeight uint32 = 15, 15 for req := range requests { switch req.Type { case "pty-req": + if len(req.Payload) >= 8 { + width := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-8:]) + height := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-4:]) + if width > 0 { + termWidth = width + } + if height > 0 { + termHeight = height + } + } req.Reply(true, nil) case "window-change": + width := binary.BigEndian.Uint32(req.Payload) + height := binary.BigEndian.Uint32(req.Payload[4:]) + if width > 0 { + termWidth = width + } + if height > 0 { + termHeight = height + } if ptmx != nil { - width := binary.BigEndian.Uint32(req.Payload) - height := binary.BigEndian.Uint32(req.Payload[4:]) - pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(width), Rows: uint16(height)}) + pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)}) } req.Reply(true, nil) case "shell": @@ -121,6 +138,7 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) { log.Println("PTY start error:", err) return } + pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)}) go func() { defer ptmx.Close() go io.Copy(channel, ptmx)