just use tcsetattr directly instead of roundabout way

that drags in mountains of syscall code.
This commit is contained in:
Ted Unangst 2019-04-10 18:06:04 -04:00
parent 5dc562e449
commit 320666a131
2 changed files with 22 additions and 4 deletions

1
go.mod
View File

@ -4,6 +4,5 @@ require (
github.com/gorilla/mux v1.7.1
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e
humungus.tedunangst.com/r/go-sqlite3 v1.1.2
)

25
util.go
View File

@ -15,6 +15,23 @@
package main
/*
#include <termios.h>
void
termecho(int on)
{
struct termios t;
tcgetattr(1, &t);
if (on)
t.c_lflag |= ECHO;
else
t.c_lflag &= ~ECHO;
tcsetattr(1, TCSADRAIN, &t);
}
*/
import "C"
import (
"bufio"
"crypto/rand"
@ -29,7 +46,6 @@ import (
"strings"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/ssh/terminal"
_ "humungus.tedunangst.com/r/go-sqlite3"
)
@ -72,6 +88,7 @@ func initdb() {
signal.Notify(c, os.Interrupt)
go func() {
<-c
C.termecho(1)
fmt.Printf("\n")
os.Remove(dbname)
os.Exit(1)
@ -97,14 +114,16 @@ func initdb() {
log.Print("that's way too short")
return
}
C.termecho(0)
fmt.Printf("password: ")
passbytes, err := terminal.ReadPassword(1)
pass, err := r.ReadString('\n')
C.termecho(1)
fmt.Printf("\n")
if err != nil {
log.Print(err)
return
}
pass := string(passbytes)
pass = pass[:len(pass)-1]
if len(pass) < 6 {
log.Print("that's way too short")
return