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

Fix #22 - search for stty in PATH #24

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions speakeasy_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ package speakeasy
import (
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
)

const sttyArg0 = "/bin/stty"
const sttyBin = "stty"

var (
sttyArgvEOff = []string{"stty", "-echo"}
Expand Down Expand Up @@ -64,7 +65,11 @@ func getPassword() (password string, err error) {

// echoOff turns off the terminal echo.
func echoOff(fd []uintptr) (int, error) {
pid, err := syscall.ForkExec(sttyArg0, sttyArgvEOff, &syscall.ProcAttr{Dir: "", Files: fd})
path, err := exec.LookPath(sttyBin)
if err != nil {
return 0, fmt.Errorf("%s binary not found:\n\t%s", sttyBin, err)
}
pid, err := syscall.ForkExec(path, sttyArgvEOff, &syscall.ProcAttr{Dir: "", Files: fd})
if err != nil {
return 0, fmt.Errorf("failed turning off console echo for password entry:\n\t%s", err)
}
Expand All @@ -74,7 +79,11 @@ func echoOff(fd []uintptr) (int, error) {
// echoOn turns back on the terminal echo.
func echoOn(fd []uintptr) {
// Turn on the terminal echo.
pid, e := syscall.ForkExec(sttyArg0, sttyArgvEOn, &syscall.ProcAttr{Dir: "", Files: fd})
path, err := exec.LookPath(sttyBin)
if err != nil {
return
}
pid, e := syscall.ForkExec(path, sttyArgvEOn, &syscall.ProcAttr{Dir: "", Files: fd})
if e == nil {
syscall.Wait4(pid, nil, 0, nil)
}
Expand Down