veyron/security/agent: enabling non-interactive invocations of agentd
Change-Id: I76a52ea9ca5553cf6bd5ecb4708d6a46b361aa51
diff --git a/security/agent/agentd/main.go b/security/agent/agentd/main.go
index e76941e..1c47dc0 100644
--- a/security/agent/agentd/main.go
+++ b/security/agent/agentd/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "bufio"
"flag"
"fmt"
"os"
@@ -139,6 +140,13 @@
}
func getPassword(prompt string) ([]byte, error) {
+ if !terminal.IsTerminal(int(os.Stdin.Fd())) {
+ // If the standard input is not a terminal, the
+ // password is obtained by reading a line from it.
+ //
+ // TODO(suharshs): Mitigate buffering.
+ return bufio.NewReader(os.Stdin).ReadBytes('\n')
+ }
fmt.Printf(prompt)
stop := make(chan bool)
defer close(stop)