aboutsummaryrefslogtreecommitdiff
path: root/internal/readpassword/read.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-03-22 00:02:10 +0100
committerJakob Unterwurzacher2018-03-22 00:02:10 +0100
commit9bc039a4bac6b51d9ebe116de5c311e90343a088 (patch)
treef4ebd37e2cbe4088435421fb7c9550c186161b09 /internal/readpassword/read.go
parent9c86daf499dca8a69b058ec56803d06fbba4fdab (diff)
Add `-masterkey=stdin` functionality
https://github.com/rfjakob/gocryptfs/issues/218
Diffstat (limited to 'internal/readpassword/read.go')
-rw-r--r--internal/readpassword/read.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/internal/readpassword/read.go b/internal/readpassword/read.go
index e2fce8a..c99be5d 100644
--- a/internal/readpassword/read.go
+++ b/internal/readpassword/read.go
@@ -23,15 +23,18 @@ const (
)
// Once tries to get a password from the user, either from the terminal, extpass
-// or stdin.
-func Once(extpass string) []byte {
+// or stdin. Leave "prompt" empty to use the default "Password: " prompt.
+func Once(extpass string, prompt string) []byte {
if extpass != "" {
return readPasswordExtpass(extpass)
}
+ if prompt == "" {
+ prompt = "Password"
+ }
if !terminal.IsTerminal(int(os.Stdin.Fd())) {
- return readPasswordStdin()
+ return readPasswordStdin(prompt)
}
- return readPasswordTerminal("Password: ")
+ return readPasswordTerminal(prompt + ": ")
}
// Twice is the same as Once but will prompt twice if we get the password from
@@ -41,7 +44,7 @@ func Twice(extpass string) []byte {
return readPasswordExtpass(extpass)
}
if !terminal.IsTerminal(int(os.Stdin.Fd())) {
- return readPasswordStdin()
+ return readPasswordStdin("Password")
}
p1 := readPasswordTerminal("Password: ")
p2 := readPasswordTerminal("Repeat: ")
@@ -77,11 +80,11 @@ func readPasswordTerminal(prompt string) []byte {
// readPasswordStdin reads a line from stdin.
// It exits with a fatal error on read error or empty result.
-func readPasswordStdin() []byte {
- tlog.Info.Println("Reading password from stdin")
+func readPasswordStdin(prompt string) []byte {
+ tlog.Info.Printf("Reading %s from stdin", prompt)
p := readLineUnbuffered(os.Stdin)
if len(p) == 0 {
- tlog.Fatal.Println("Got empty password from stdin")
+ tlog.Fatal.Printf("Got empty %s from stdin", prompt)
os.Exit(exitcodes.ReadPassword)
}
return p