mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 11:50:10 +01:00
Detect # of keys from cipher string.
Fix status output string. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@417 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
25
lib/setup.c
25
lib/setup.c
@@ -722,7 +722,7 @@ int crypt_luksFormat(struct crypt_options *options)
|
||||
};
|
||||
int r;
|
||||
|
||||
r = crypt_parse_name_and_mode(options->cipher, cipherName, cipherMode);
|
||||
r = crypt_parse_name_and_mode(options->cipher, cipherName, NULL, cipherMode);
|
||||
if(r < 0) {
|
||||
log_err(cd, _("No known cipher specification pattern detected.\n"));
|
||||
return r;
|
||||
@@ -1035,7 +1035,7 @@ int crypt_init_by_name(struct crypt_device **cd, const char *name)
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = crypt_parse_name_and_mode(cipher_full, cipher, cipher_mode);
|
||||
r = crypt_parse_name_and_mode(cipher_full, cipher, NULL, cipher_mode);
|
||||
if (!r) {
|
||||
(*cd)->plain_cipher = strdup(cipher);
|
||||
(*cd)->plain_cipher_mode = strdup(cipher_mode);
|
||||
@@ -1179,11 +1179,11 @@ int crypt_format(struct crypt_device *cd,
|
||||
{
|
||||
int r;
|
||||
|
||||
log_dbg("Formatting device %s as type %s.", cd->device ?: "(none)", cd->type ?: "(none)");
|
||||
|
||||
if (!type)
|
||||
return -EINVAL;
|
||||
|
||||
log_dbg("Formatting device %s as type %s.", cd->device ?: "(none)", type);
|
||||
|
||||
r = init_crypto(cd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -1834,12 +1834,11 @@ int crypt_activate_by_keyfile(struct crypt_device *cd,
|
||||
if (!keyfile)
|
||||
return -EINVAL;
|
||||
|
||||
if (isPLAIN(cd->type)) {
|
||||
r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
|
||||
&passphrase_size_read, keyfile, keyfile_size);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
if (isPLAIN(cd->type)) {
|
||||
r = create_device_helper(cd, name, cd->plain_hdr.hash,
|
||||
cd->plain_cipher, cd->plain_cipher_mode,
|
||||
NULL, passphrase_read, passphrase_size_read,
|
||||
@@ -1847,17 +1846,23 @@ int crypt_activate_by_keyfile(struct crypt_device *cd,
|
||||
cd->plain_hdr.skip, cd->plain_hdr.offset,
|
||||
cd->plain_uuid,
|
||||
flags & CRYPT_ACTIVATE_READONLY, 0, 0);
|
||||
keyslot = 0;
|
||||
} else if (isLUKS(cd->type)) {
|
||||
r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
|
||||
&passphrase_size_read, keyfile, keyfile_size);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
r = LUKS_open_key_with_hdr(cd->device, keyslot, passphrase_read,
|
||||
passphrase_size_read, &cd->hdr, &vk, cd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
keyslot = r;
|
||||
|
||||
if (name)
|
||||
if (name) {
|
||||
r = open_from_hdr_and_vk(cd, vk, name, flags);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
}
|
||||
r = keyslot;
|
||||
} else
|
||||
r = -EINVAL;
|
||||
|
||||
@@ -1865,7 +1870,7 @@ out:
|
||||
crypt_safe_free(passphrase_read);
|
||||
crypt_free_volume_key(vk);
|
||||
|
||||
return r < 0 ? r : keyslot;
|
||||
return r;
|
||||
}
|
||||
|
||||
int crypt_activate_by_volume_key(struct crypt_device *cd,
|
||||
|
||||
@@ -18,17 +18,27 @@ struct safe_allocation {
|
||||
char data[0];
|
||||
};
|
||||
|
||||
int crypt_parse_name_and_mode(const char *s, char *cipher, char *cipher_mode)
|
||||
int crypt_parse_name_and_mode(const char *s, char *cipher, int *key_nums,
|
||||
char *cipher_mode)
|
||||
{
|
||||
if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]-%" MAX_CIPHER_LEN_STR "s",
|
||||
cipher, cipher_mode) == 2) {
|
||||
if (!strcmp(cipher_mode, "plain"))
|
||||
strncpy(cipher_mode, "cbc-plain", 10);
|
||||
if (key_nums) {
|
||||
char *tmp = strchr(cipher, ':');
|
||||
*key_nums = tmp ? atoi(++tmp) : 1;
|
||||
if (!*key_nums)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]", cipher) == 1) {
|
||||
strncpy(cipher_mode, "cbc-plain", 10);
|
||||
if (key_nums)
|
||||
*key_nums = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -143,7 +153,7 @@ static int interactive_pass(const char *prompt, char *pass, size_t maxlen,
|
||||
memcpy(&tmp, &orig, sizeof(tmp));
|
||||
tmp.c_lflag &= ~ECHO;
|
||||
|
||||
if (write(outfd, prompt, strlen(prompt)) < 0)
|
||||
if (prompt && write(outfd, prompt, strlen(prompt)) < 0)
|
||||
goto out_err;
|
||||
|
||||
tcsetattr(infd, TCSAFLUSH, &tmp);
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
struct crypt_device;
|
||||
|
||||
int crypt_parse_name_and_mode(const char *s, char *cipher, char *cipher_mode);
|
||||
int crypt_parse_name_and_mode(const char *s, char *cipher,
|
||||
int *key_nums, char *cipher_mode);
|
||||
|
||||
int crypt_get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
|
||||
const char *key_file, int timeout, int how2verify,
|
||||
|
||||
@@ -209,7 +209,7 @@ static int action_create(int arg)
|
||||
params.hash = NULL;
|
||||
|
||||
r = crypt_parse_name_and_mode(opt_cipher ?: DEFAULT_CIPHER(PLAIN),
|
||||
cipher, cipher_mode);
|
||||
cipher, NULL, cipher_mode);
|
||||
if (r < 0) {
|
||||
log_err("No known cipher specification pattern detected.\n");
|
||||
goto out;
|
||||
@@ -372,7 +372,7 @@ static int action_luksFormat(int arg)
|
||||
goto out;
|
||||
|
||||
r = crypt_parse_name_and_mode(opt_cipher ?: DEFAULT_CIPHER(LUKS1),
|
||||
cipher, cipher_mode);
|
||||
cipher, NULL, cipher_mode);
|
||||
if (r < 0) {
|
||||
log_err("No known cipher specification pattern detected.\n");
|
||||
goto out;
|
||||
@@ -875,6 +875,8 @@ static int run_action(struct action_type *action)
|
||||
{
|
||||
int r;
|
||||
|
||||
log_dbg("Running command %s.", action->type);
|
||||
|
||||
if (action->required_memlock)
|
||||
crypt_memory_lock(NULL, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user