Created
November 12, 2012 12:22
-
-
Save fsouza/4059071 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== modified file 'terminal.go' | |
--- terminal.go 2012-02-21 18:47:37 +0000 | |
+++ terminal.go 2012-08-31 16:29:38 +0000 | |
@@ -5,9 +5,7 @@ | |
package rietveld | |
import ( | |
- "io" | |
- "syscall" | |
- "unsafe" | |
+ "github.com/timeredbull/tsuru/cmd/term" | |
) | |
// This was copied from package exp/terminal | |
@@ -16,42 +14,6 @@ | |
// is commonly used for inputting passwords and other sensitive data. The slice | |
// returned does not include the \n. | |
func readPassword(fd uintptr) ([]byte, error) { | |
- var oldState syscall.Termios | |
- if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 { | |
- return nil, syscall.Errno(e) | |
- } | |
- | |
- newState := oldState | |
- newState.Lflag &^= syscall.ECHO | |
- if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 { | |
- return nil, syscall.Errno(e) | |
- } | |
- | |
- defer func() { | |
- syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TCSETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0) | |
- }() | |
- | |
- var buf [16]byte | |
- var ret []byte | |
- for { | |
- n, errno := syscall.Read(int(fd), buf[:]) | |
- if errno != nil { | |
- return nil, errno | |
- } | |
- if n == 0 { | |
- if len(ret) == 0 { | |
- return nil, io.EOF | |
- } | |
- break | |
- } | |
- if buf[n-1] == '\n' { | |
- n-- | |
- } | |
- ret = append(ret, buf[:n]...) | |
- if n < len(buf) { | |
- break | |
- } | |
- } | |
- | |
- return ret, nil | |
+ pass, err := term.ReadPassword(fd) | |
+ return []byte(pass), err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment