-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add support for X11 forwarding #7205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) bool { | |
|
||
go func() { | ||
defer s.trackListener(listener, false) | ||
handledFirstConnection := false | ||
|
||
for { | ||
conn, err := listener.Accept() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
@@ -71,6 +72,13 @@ func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) bool { | |
s.logger.Warn(ctx, "failed to accept X11 connection", slog.Error(err)) | ||
return | ||
} | ||
if x11.SingleConnection && handledFirstConnection { | ||
s.logger.Warn(ctx, "X11 connection rejected because single connection is enabled") | ||
_ = conn.Close() | ||
continue | ||
} | ||
handledFirstConnection = true | ||
|
||
unixConn, ok := conn.(*net.UnixConn) | ||
if !ok { | ||
s.logger.Warn(ctx, fmt.Sprintf("failed to cast connection to UnixConn. got: %T", conn)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,9 +68,12 @@ func TestServer_X11(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
x11Chans := c.HandleChannelOpen("x11") | ||
payload := "hello world" | ||
require.Eventually(t, func() bool { | ||
conn, err := net.Dial("unix", filepath.Join(dir, "X0")) | ||
if err == nil { | ||
_, err = conn.Write([]byte(payload)) | ||
assert.NoError(t, err) | ||
_ = conn.Close() | ||
} | ||
return err == nil | ||
|
@@ -80,9 +83,12 @@ func TestServer_X11(t *testing.T) { | |
ch, reqs, err := x11.Accept() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if this also checked that reads and writes were piped properly like other listener tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Fixed! |
||
require.NoError(t, err) | ||
go gossh.DiscardRequests(reqs) | ||
err = ch.Close() | ||
got := make([]byte, len(payload)) | ||
_, err = ch.Read(got) | ||
require.NoError(t, err) | ||
s.Close() | ||
assert.Equal(t, payload, string(got)) | ||
_ = ch.Close() | ||
_ = s.Close() | ||
<-done | ||
|
||
// Ensure the Xauthority file was written! | ||
|
Uh oh!
There was an error while loading. Please reload this page.