Skip to content
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

fixed/finished basic pty support, added an example, and included tests #25

Merged
merged 8 commits into from
Feb 16, 2017

Conversation

progrium
Copy link
Contributor

cc @belak for review

Missing support for terminal modes, and still need signals, but omg tests.

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
@progrium progrium requested review from shazow and mattatcha February 15, 2017 00:39
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
…ndow size on it

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
@progrium
Copy link
Contributor Author

Last commit was a fix I added in working on a more complex example. You always end up writing the call to your "resizeWindow" function twice, once initially, once in the channel range. This PR changes behavior to where the window change channel has the initial window size in it, so you can just implement your range and that's it.

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
@progrium
Copy link
Contributor Author

Just added a new example that turns SSH into a "docker run" bridge ... in ~100 lines! Still no signals, but many containers work and I learned how to resolve some bugs in cmd.io, namely gliderlabs/cmd#58 and gliderlabs/cmd#59

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
@belak
Copy link
Collaborator

belak commented Feb 15, 2017

I'm not sure how we want to handle this, but the if req.WantReply portions aren't strictly needed because it's handled in x/crypto/ssh:

func (r *Request) Reply(ok bool, payload []byte) error {
	if !r.WantReply {
		return nil
	}

	...
}

Copy link
Collaborator

@belak belak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only changes I think this could really use is some fixes around users sending multiple pty-req messages.

session.go Outdated
@@ -152,6 +152,9 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {
var kv = struct{ Key, Value string }{}
gossh.Unmarshal(req.Payload, &kv)
sess.env = append(sess.env, fmt.Sprintf("%s=%s", kv.Key, kv.Value))
if req.WantReply {
req.Reply(true, nil)
}
case "pty-req":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should this handle multiple pty-req messages before the exec/shell? Right now I think this will overwrite the pty, but if that's what we want, we need to be more careful about closing sess.winch because that could be double-closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the simplest solution is to ignore/deny (reply false) any more pty requests...

Copy link
Contributor Author

@progrium progrium Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps once pty is set, it ignores the rest. I can imagine the callback denying for some reason and then the client fixing and trying again. No idea if that's a realistic scenario with known SSH clients, but it makes sense implementation wise and resolves this issue.

gossh "golang.org/x/crypto/ssh"
)

func (srv *Server) serveOnce(l net.Listener) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is a nice hack. I'll hopefully be able to cobble together something a bit more robust when the Shutdown pr goes in.

@@ -5,7 +5,6 @@ import (
"net"
)

// Signal as in RFC 4254 Section 6.10.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this comment was removed?

Copy link
Contributor Author

@progrium progrium Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's duplicated a few lines below. Since this portion is copy and pasted directly from the crypto/ssh implementation, I went and looked and they don't double reference. So as is with this commit it matches.

@progrium
Copy link
Contributor Author

@belak regarding if req.WantReply, you're right. I know somebody removed them with a point, but I couldn't remember the point and added them back here. But I was wrong! Good catch.

…ess.pty once

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
@progrium progrium merged commit a2a4749 into master Feb 16, 2017
@josegonzalez josegonzalez deleted the basic-pty branch April 27, 2017 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants