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

add stdin remapping support #23

Merged
merged 1 commit into from
Dec 24, 2015
Merged

add stdin remapping support #23

merged 1 commit into from
Dec 24, 2015

Conversation

lunixbochs
Copy link
Contributor

This allows replacing Stdin with a socket other file interface as requested in #14. I'm using this in my Usercorn project for a remote debugging interface. I made the API use a new FdReader interface for Stdin in lieu of using os.File for ease of wrapping. The connecting client is expected to manually place stdin into raw mode.

This shouldn't break any existing features as it falls back to the global Stdin object for normal use.

Here's what the server-side looks like: https://github.com/lunixbochs/usercorn/blob/master/go/usercorn/debugger.go#L40

Here's the client-side (where I manually set raw mode on stdin): https://github.com/lunixbochs/usercorn/blob/master/go/usercorn/cli.go#L74

@@ -330,7 +329,7 @@ func (o *Operation) Password(prompt string) ([]byte, error) {
o.t.EnterRawMode()
defer o.t.ExitRawMode()

b, err := terminal.ReadPassword(int(os.Stdin.Fd()))
b, err := terminal.ReadPassword(int(o.cfg.Stdin.Fd()))
Copy link
Owner

Choose a reason for hiding this comment

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

@lunixbochs, Maybe netfd is not working here? Have you tried this yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work and isn't likely to ever work. You're in raw mode for operations already. Why are you using the crypto/ssh/terminal library to read passwords? Just stop echoing characters for the line.

Copy link
Owner

Choose a reason for hiding this comment

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

@lunixbochs I haven't dig out a lot about how it implement, I'm not sure it's as simple as stop echoing characters.
Anyway, it seems not breaking anything. Thanks for you pr!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, my suggestion was a result of looking at the source for terminal. They literally just set t.echo = false then read a line:

https://github.com/golang/crypto/blob/master/ssh/terminal/terminal.go#L649

Also when I said "it doesn't work", I mean it throws an error about being unable to configure the device. The only way to fix this would be reading passwords from your own code (by disabling echo, then reading a line in raw mode).

chzyer added a commit that referenced this pull request Dec 24, 2015
add stdin remapping support
@chzyer chzyer merged commit 94a7081 into chzyer:master Dec 24, 2015
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