From 6166dad05c1bf505f1c0fca1fbe8bf6a27d02db9 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 29 Jan 2017 00:34:12 +0100 Subject: readpassword: support spaces in "-passfile" filename ...and while we are at it, also filenames starting with "-". --- internal/readpassword/read.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/readpassword/read.go b/internal/readpassword/read.go index 6945f0a..f00b425 100644 --- a/internal/readpassword/read.go +++ b/internal/readpassword/read.go @@ -83,7 +83,16 @@ func readPasswordStdin() string { // Exits on read error or empty result. func readPasswordExtpass(extpass string) string { tlog.Info.Println("Reading password from extpass program") - parts := strings.Split(extpass, " ") + var parts []string + // The option "-passfile=FILE" gets transformed to + // "-extpass="/bin/cat -- FILE". We don't want to split FILE on spaces, + // so let's handle it manually. + passfileCat := "/bin/cat -- " + if strings.HasPrefix(extpass, passfileCat) { + parts = []string{"/bin/cat", "--", extpass[len(passfileCat):]} + } else { + parts = strings.Split(extpass, " ") + } cmd := exec.Command(parts[0], parts[1:]...) cmd.Stderr = os.Stderr pipe, err := cmd.StdoutPipe() -- cgit v1.2.3