From b78e6a1c4cc0d1bbd3581d561773db85ee2e75b7 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 23 Aug 2024 12:27:59 +0200 Subject: readpassword: show where stdin is connected Should make debugging situations like https://github.com/rfjakob/gocryptfs/issues/852 Empty stdin in mkinitcpio hook easier. Examples: $ echo -n "" | ./gocryptfs -init a Choose a password for protecting your files. Reading Password from stdin (connected to "pipe:[749878]") Got empty Password from stdin $ ./gocryptfs -init a < /dev/null Choose a password for protecting your files. Reading Password from stdin (connected to "/dev/null") Got empty Password from stdin $ ./gocryptfs -init a < /dev/zero Choose a password for protecting your files. Reading Password from stdin (connected to "/dev/zero") fatal: maximum password length of 2048 bytes exceeded $ ./gocryptfs -init a < /dev/full Choose a password for protecting your files. Reading Password from stdin (connected to "/dev/full") fatal: maximum password length of 2048 bytes exceeded $ jakob@brikett:~/go/src/github.com/rfjakob/gocryptfs$ ./gocryptfs -init a < /dev/urandom Choose a password for protecting your files. Reading Password from stdin (connected to "/dev/urandom") Your master key is: 4e45a317-595d8a2d-46493a30-97de86ef- 540c7364-f0acc297-dd6f2592-7d9a5c97 If the gocryptfs.conf file becomes corrupted or you ever forget your password, there is only one hope for recovery: The master key. Print it to a piece of paper and store it in a drawer. This message is only printed once. The gocryptfs filesystem has been created successfully. You can now mount it using: gocryptfs a MOUNTPOINT --- internal/readpassword/read.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'internal/readpassword/read.go') diff --git a/internal/readpassword/read.go b/internal/readpassword/read.go index 3ad3bb4..582a104 100644 --- a/internal/readpassword/read.go +++ b/internal/readpassword/read.go @@ -87,7 +87,14 @@ func readPasswordTerminal(prompt string) ([]byte, error) { // readPasswordStdin reads a line from stdin. // It exits with a fatal error on read error or empty result. func readPasswordStdin(prompt string) ([]byte, error) { - tlog.Info.Printf("Reading %s from stdin", prompt) + // This should make debugging situations like + // https://github.com/rfjakob/gocryptfs/issues/852 + // easier. Only works on Linux, otherwise shows "?". + target, err := os.Readlink("/proc/self/fd/0") + if err != nil { + target = "?" + } + tlog.Info.Printf("Reading %s from stdin (connected to %q)", prompt, target) p, err := readLineUnbuffered(os.Stdin) if err != nil { return nil, err -- cgit v1.2.3