diff --git a/ChangeLog b/ChangeLog index fec3c214..d6ebf9b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2011-04-22 Milan Broz * Also support --skip option for loopaesOpen. + * Fix return code when passphrase is read from pipe. 2011-04-18 Milan Broz * Respect maximum keyfile size paramater. diff --git a/lib/setup.c b/lib/setup.c index 218e9acb..33318dbe 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -495,7 +495,7 @@ static int volume_key_by_terminal_passphrase(struct crypt_device *cd, int keyslo { char *passphrase_read = NULL; size_t passphrase_size_read; - int r = -EINVAL, tries = cd->tries; + int r = -EINVAL, eperm = 0, tries = cd->tries; *vk = NULL; do { @@ -509,6 +509,8 @@ static int volume_key_by_terminal_passphrase(struct crypt_device *cd, int keyslo r = LUKS_open_key_with_hdr(cd->device, keyslot, passphrase_read, passphrase_size_read, &cd->hdr, vk, cd); + if (r == -EPERM) + eperm = 1; crypt_safe_free(passphrase_read); passphrase_read = NULL; } while (r == -EPERM && (--tries > 0)); @@ -516,6 +518,10 @@ out: if (r < 0) { crypt_free_volume_key(*vk); *vk = NULL; + + /* Report wrong passphrase if at least one try failed */ + if (eperm && r == -EPIPE) + r = -EPERM; } crypt_safe_free(passphrase_read); diff --git a/lib/utils_crypt.c b/lib/utils_crypt.c index dbbcf8dc..ec5773ea 100644 --- a/lib/utils_crypt.c +++ b/lib/utils_crypt.c @@ -278,6 +278,11 @@ int crypt_get_key(const char *prompt, return -EINVAL; } + if (read_stdin) + log_dbg("STDIN descriptor passphrase entry requested."); + else + log_dbg("File descriptor passphrase entry requested."); + /* If not requsted otherwise, we limit input to prevent memory exhaustion */ if (keyfile_size_max == 0) { keyfile_size_max = DEFAULT_KEYFILE_SIZE_MAXKB * 1024; @@ -337,8 +342,11 @@ int crypt_get_key(const char *prompt, } /* Fail if piped input dies reading nothing */ - if(!i && !regular_file) + if(!i && !regular_file) { + log_dbg("Nothing read on input."); + r = -EPIPE; goto out_err; + } /* Fail if we exceeded internal default (no specified size) */ if (unlimited_read && i == keyfile_size_max) {