Commit f90edb61 authored by Milan Broz's avatar Milan Broz

Simplify return codes from get key functions.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@363 36d66b0a-2a48-0410-832c-cd162a569da5
parent 6258753b
This diff is collapsed.
......@@ -175,9 +175,9 @@ out_err:
* Note: --key-file=- is interpreted as a read from a binary file (stdin)
*/
void crypt_get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
const char *key_file, int timeout, int verify,
struct crypt_device *cd)
int crypt_get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
const char *key_file, int timeout, int verify,
struct crypt_device *cd)
{
int fd = -1;
char *pass = NULL;
......@@ -282,7 +282,7 @@ void crypt_get_key(char *prompt, char **key, unsigned int *passLen, int key_size
}
if(fd != STDIN_FILENO)
close(fd);
return;
return 0;
out_err:
if(fd >= 0 && fd != STDIN_FILENO)
......@@ -291,4 +291,5 @@ out_err:
crypt_safe_free(pass);
*key = NULL;
*passLen = 0;
return -EINVAL;
}
......@@ -10,9 +10,9 @@ struct crypt_device;
int crypt_parse_name_and_mode(const char *s, char *cipher, char *cipher_mode);
void crypt_get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
const char *key_file, int timeout, int how2verify,
struct crypt_device *cd);
int crypt_get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
const char *key_file, int timeout, int how2verify,
struct crypt_device *cd);
void *crypt_safe_alloc(size_t size);
void crypt_safe_free(void *data);
......
......@@ -223,12 +223,11 @@ static int action_create(int arg)
if (r < 0)
goto out;
crypt_get_key(_("Enter passphrase: "),
&password, &passwordLen,
opt_keyfile_size, opt_key_file,
opt_timeout,
opt_batch_mode ? 0 : opt_verify_passphrase,
cd);
r = crypt_get_key(_("Enter passphrase: "), &password, &passwordLen,
opt_keyfile_size, opt_key_file, opt_timeout,
opt_batch_mode ? 0 : opt_verify_passphrase, cd);
if (r < 0)
goto out;
r = crypt_activate_by_passphrase(cd, action_argv[0], CRYPT_ANY_SLOT,
password, passwordLen,
......@@ -380,14 +379,10 @@ static int action_luksFormat(int arg)
else if (opt_urandom)
crypt_set_rng_type(cd, CRYPT_RNG_URANDOM);
r = -EINVAL;
crypt_get_key(_("Enter LUKS passphrase: "),
&password, &passwordLen,
opt_keyfile_size, opt_key_file,
opt_timeout,
opt_batch_mode ? 0 : 1, /* always verify */
cd);
if(!password)
r = crypt_get_key(_("Enter LUKS passphrase: "), &password, &passwordLen,
opt_keyfile_size, opt_key_file, opt_timeout,
opt_batch_mode ? 0 : 1 /* always verify */, cd);
if (r < 0)
goto out;
if (opt_master_key_file) {
......@@ -452,19 +447,17 @@ static int verify_keyslot(struct crypt_device *cd, int key_slot,
crypt_keyslot_info ki;
char *password = NULL;
unsigned int passwordLen, i;
int r = -EPERM;
int r;
ki = crypt_keyslot_status(cd, key_slot);
if (ki == CRYPT_SLOT_ACTIVE_LAST && msg_last && !_yesDialog(msg_last, NULL))
return -EPERM;
crypt_get_key(msg_pass, &password, &passwordLen,
keyfile_size, key_file,
opt_timeout,
opt_batch_mode ? 0 : opt_verify_passphrase,
cd);
if(!password)
return -EINVAL;
r = crypt_get_key(msg_pass, &password, &passwordLen,
keyfile_size, key_file, opt_timeout,
opt_batch_mode ? 0 : opt_verify_passphrase, cd);
if(r < 0)
goto out;
if (ki == CRYPT_SLOT_ACTIVE_LAST) {
/* check the last keyslot */
......@@ -486,7 +479,7 @@ static int verify_keyslot(struct crypt_device *cd, int key_slot,
if (r < 0)
log_err(_("No key available with this passphrase.\n"));
out:
crypt_safe_free(password);
return r;
}
......@@ -548,16 +541,14 @@ static int action_luksRemoveKey(int arg)
if ((r = crypt_load(cd, CRYPT_LUKS1, NULL)))
goto out;
crypt_get_key(_("Enter LUKS passphrase to be deleted: "),
r = crypt_get_key(_("Enter LUKS passphrase to be deleted: "),
&password, &passwordLen,
opt_keyfile_size, opt_key_file,
opt_timeout,
opt_batch_mode ? 0 : opt_verify_passphrase,
cd);
if(!password) {
r = -EINVAL;
if(r < 0)
goto out;
}
r = crypt_activate_by_passphrase(cd, NULL, CRYPT_ANY_SLOT,
password, passwordLen, 0);
......
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