Commit 38590eae authored by Milan Broz's avatar Milan Broz

Fix return code when passphrase is read from pipe.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@486 36d66b0a-2a48-0410-832c-cd162a569da5
parent 63717860
2011-04-22 Milan Broz <mbroz@redhat.com>
* Also support --skip option for loopaesOpen.
* Fix return code when passphrase is read from pipe.
2011-04-18 Milan Broz <mbroz@redhat.com>
* Respect maximum keyfile size paramater.
......
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment