@@ -5,12 +5,9 @@ import (
55 "io"
66 "os"
77 "os/exec"
8- "os/signal"
98 "path/filepath"
10- "syscall"
119 "time"
1210
13- "github.com/creack/pty"
1411 "github.com/paramientos/leap/internal/config"
1512 "golang.org/x/crypto/ssh"
1613 "golang.org/x/term"
@@ -44,6 +41,17 @@ func Connect(conn config.Connection, record bool) error {
4441}
4542
4643func connectWithSystemSSH (conn config.Connection , recording io.Writer ) error {
44+ args := buildSSHArgs (conn )
45+ cmd := exec .Command ("ssh" , args ... )
46+
47+ if recording != nil {
48+ return connectWithSystemSSHRecording (cmd , recording )
49+ }
50+
51+ return connectWithSystemSSHNormal (conn )
52+ }
53+
54+ func buildSSHArgs (conn config.Connection ) []string {
4755 args := []string {}
4856
4957 if conn .IdentityFile != "" {
@@ -56,42 +64,7 @@ func connectWithSystemSSH(conn config.Connection, recording io.Writer) error {
5664 target := fmt .Sprintf ("%s@%s" , conn .User , conn .Host )
5765 args = append (args , target )
5866
59- cmd := exec .Command ("ssh" , args ... )
60-
61- if recording != nil {
62- ptmx , err := pty .Start (cmd )
63- if err != nil {
64- return err
65- }
66- defer ptmx .Close ()
67-
68- ch := make (chan os.Signal , 1 )
69- signal .Notify (ch , syscall .SIGWINCH )
70- go func () {
71- for range ch {
72- if err := pty .InheritSize (os .Stdin , ptmx ); err != nil {
73- fmt .Printf ("error resizing pty: %s" , err )
74- }
75- }
76- }()
77- ch <- syscall .SIGWINCH
78-
79- oldState , err := term .MakeRaw (int (os .Stdin .Fd ()))
80- if err != nil {
81- panic (err )
82- }
83- defer term .Restore (int (os .Stdin .Fd ()), oldState )
84-
85- multi := io .MultiWriter (os .Stdout , recording )
86- go func () { io .Copy (ptmx , os .Stdin ) }()
87- io .Copy (multi , ptmx )
88- return nil
89- }
90-
91- cmd .Stdin = os .Stdin
92- cmd .Stdout = os .Stdout
93- cmd .Stderr = os .Stderr
94- return cmd .Run ()
67+ return args
9568}
9669
9770func connectWithPassword (conn config.Connection , recording io.Writer ) error {
0 commit comments