diff --git a/client.go b/client.go index 087abc7..733f242 100644 --- a/client.go +++ b/client.go @@ -168,20 +168,8 @@ func (cc *Client) Shell() error { return err } - ch := make(chan os.Signal, 2) - signal.Notify(ch, syscall.SIGWINCH) - go func() { - for { - select { - case <-ch: - ws, _ := _console.Size() - _winCh := windowChange{Rows: uint32(ws.Height), Columns: uint32(ws.Width)} - d := ssh.Marshal(_winCh) - ok, err := session.SendRequest("window-change", true, d) - log.Debugf("send window change request %+v %+v", ok, err) - } - } - }() + // register console change signal + consoleChange(_console, session) session.Stdin = _console session.Stdout = os.Stdout diff --git a/console.go b/console.go new file mode 100644 index 0000000..320d7d1 --- /dev/null +++ b/console.go @@ -0,0 +1,22 @@ +// +build windows + +package obfssh + +import ( + "errors" + "syscall" + + "github.com/containerd/console" + "golang.org/x/crypto/ssh" +) + +func consoleChange(_console console.Console, session *ssh.Session) { + +} + +func newPty() (console.Console, string, error) { + return nil, "", errors.New("not supported") +} + +func setProcAttr(attr *syscall.SysProcAttr) { +} diff --git a/console_unix.go b/console_unix.go new file mode 100644 index 0000000..552e001 --- /dev/null +++ b/console_unix.go @@ -0,0 +1,39 @@ +// +build darwin freebsd linux openbsd solaris + +package obfssh + +import ( + "os" + "os/signal" + "syscall" + + "github.com/containerd/console" + "github.com/fangdingjun/go-log/v5" + "golang.org/x/crypto/ssh" +) + +func consoleChange(_console console.Console, session *ssh.Session) { + ch := make(chan os.Signal, 2) + signal.Notify(ch, syscall.SIGWINCH) + go func() { + for { + select { + case <-ch: + ws, _ := _console.Size() + _winCh := windowChange{Rows: uint32(ws.Height), Columns: uint32(ws.Width)} + d := ssh.Marshal(_winCh) + ok, err := session.SendRequest("window-change", true, d) + log.Debugf("send window change request %+v %+v", ok, err) + } + } + }() +} + +func newPty() (console.Console, string, error) { + return console.NewPty() +} + +func setProcAttr(attr *syscall.SysProcAttr) { + attr.Setsid = true + attr.Setctty = true +} diff --git a/server.go b/server.go index 5ef83ab..33a67a5 100644 --- a/server.go +++ b/server.go @@ -234,7 +234,7 @@ func (sc *Server) handleSession(newch ssh.NewChannel) { } log.Debugf("pty req %+v", _ptyReq) if err == nil && (runtime.GOOS == "unix" || runtime.GOOS == "linux") { - _console, ptsname, err = console.NewPty() + _console, ptsname, err = newPty() if err == nil { log.Debugf("allocate pty %s", ptsname) env = append(env, fmt.Sprintf("SSH_TTY=%s", ptsname)) @@ -321,9 +321,8 @@ func handleShell(cmd *exec.Cmd, ch ssh.Channel, _console console.Console, ptsnam if cmd.SysProcAttr == nil { cmd.SysProcAttr = &syscall.SysProcAttr{} } - cmd.SysProcAttr.Setsid = true - cmd.SysProcAttr.Setctty = true - // cmd.SysProcAttr.Ctty = int(_tty.Fd()) + + setProcAttr(cmd.SysProcAttr) go io.Copy(ch, _console) go io.Copy(_console, ch)