mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-12 03:10:08 +01:00
Print error if device name is invalid (in use by other target).
This commit is contained in:
87
lib/setup.c
87
lib/setup.c
@@ -2902,8 +2902,10 @@ static int _activate_by_passphrase(struct crypt_device *cd,
|
|||||||
if (name)
|
if (name)
|
||||||
r = LUKS2_activate(cd, name, vk, flags);
|
r = LUKS2_activate(cd, name, vk, flags);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
|
log_err(cd, _("Device type is not properly initialised.\n"));
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
|
}
|
||||||
out:
|
out:
|
||||||
crypt_free_volume_key(vk);
|
crypt_free_volume_key(vk);
|
||||||
|
|
||||||
@@ -2913,6 +2915,24 @@ out:
|
|||||||
return r < 0 ? r : keyslot;
|
return r < 0 ? r : keyslot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _activate_check_status(struct crypt_device *cd, const char *name)
|
||||||
|
{
|
||||||
|
crypt_status_info ci;
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ci = crypt_status(cd, name);
|
||||||
|
if (ci == CRYPT_INVALID) {
|
||||||
|
log_err(cd, _("Cannot use device %s, name is invalid or still in use.\n"), name);
|
||||||
|
return -EINVAL;
|
||||||
|
} else if (ci >= CRYPT_ACTIVE) {
|
||||||
|
log_err(cd, _("Device %s already exists.\n"), name);
|
||||||
|
return -EEXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// activation/deactivation of device mapping
|
// activation/deactivation of device mapping
|
||||||
int crypt_activate_by_passphrase(struct crypt_device *cd,
|
int crypt_activate_by_passphrase(struct crypt_device *cd,
|
||||||
@@ -2922,7 +2942,7 @@ int crypt_activate_by_passphrase(struct crypt_device *cd,
|
|||||||
size_t passphrase_size,
|
size_t passphrase_size,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
crypt_status_info ci;
|
int r;
|
||||||
|
|
||||||
if (!cd || !passphrase)
|
if (!cd || !passphrase)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -2931,15 +2951,9 @@ int crypt_activate_by_passphrase(struct crypt_device *cd,
|
|||||||
name ? "Activating" : "Checking", name ?: "passphrase",
|
name ? "Activating" : "Checking", name ?: "passphrase",
|
||||||
keyslot);
|
keyslot);
|
||||||
|
|
||||||
if (name) {
|
r = _activate_check_status(cd, name);
|
||||||
ci = crypt_status(NULL, name);
|
if (r < 0)
|
||||||
if (ci == CRYPT_INVALID)
|
return r;
|
||||||
return -EINVAL;
|
|
||||||
else if (ci >= CRYPT_ACTIVE) {
|
|
||||||
log_err(cd, _("Device %s already exists.\n"), name);
|
|
||||||
return -EEXIST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _activate_by_passphrase(cd, name, keyslot, passphrase, passphrase_size, flags);
|
return _activate_by_passphrase(cd, name, keyslot, passphrase, passphrase_size, flags);
|
||||||
}
|
}
|
||||||
@@ -2952,7 +2966,6 @@ int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
|
|||||||
size_t keyfile_offset,
|
size_t keyfile_offset,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
crypt_status_info ci;
|
|
||||||
struct volume_key *vk = NULL;
|
struct volume_key *vk = NULL;
|
||||||
char *passphrase_read = NULL;
|
char *passphrase_read = NULL;
|
||||||
size_t passphrase_size_read;
|
size_t passphrase_size_read;
|
||||||
@@ -2965,16 +2978,9 @@ int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
|
|||||||
log_dbg("%s volume %s [keyslot %d] using keyfile %s.",
|
log_dbg("%s volume %s [keyslot %d] using keyfile %s.",
|
||||||
name ? "Activating" : "Checking", name ?: "passphrase", keyslot, keyfile);
|
name ? "Activating" : "Checking", name ?: "passphrase", keyslot, keyfile);
|
||||||
|
|
||||||
if (name) {
|
r = _activate_check_status(cd, name);
|
||||||
ci = crypt_status(NULL, name);
|
if (r < 0)
|
||||||
if (ci == CRYPT_INVALID) {
|
return r;
|
||||||
log_err(cd, _("Cannot use device %s, name is invalid or still in use.\n"), name);
|
|
||||||
return -EINVAL;
|
|
||||||
} else if (ci >= CRYPT_ACTIVE) {
|
|
||||||
log_err(cd, _("Device %s already exists.\n"), name);
|
|
||||||
return -EEXIST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isPLAIN(cd->type)) {
|
if (isPLAIN(cd->type)) {
|
||||||
if (!name)
|
if (!name)
|
||||||
@@ -3049,8 +3055,10 @@ int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
|
|||||||
if (name)
|
if (name)
|
||||||
r = LOOPAES_activate(cd, name, cd->u.loopaes.cipher,
|
r = LOOPAES_activate(cd, name, cd->u.loopaes.cipher,
|
||||||
key_count, vk, flags);
|
key_count, vk, flags);
|
||||||
} else
|
} else {
|
||||||
|
log_err(cd, _("Device type is not properly initialised.\n"));
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypt_safe_free(passphrase_read);
|
crypt_safe_free(passphrase_read);
|
||||||
@@ -3079,9 +3087,8 @@ int crypt_activate_by_volume_key(struct crypt_device *cd,
|
|||||||
size_t volume_key_size,
|
size_t volume_key_size,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
crypt_status_info ci;
|
|
||||||
struct volume_key *vk = NULL;
|
struct volume_key *vk = NULL;
|
||||||
int r = -EINVAL;
|
int r;
|
||||||
|
|
||||||
if (!cd)
|
if (!cd)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -3089,16 +3096,9 @@ int crypt_activate_by_volume_key(struct crypt_device *cd,
|
|||||||
log_dbg("%s volume %s by volume key.", name ? "Activating" : "Checking",
|
log_dbg("%s volume %s by volume key.", name ? "Activating" : "Checking",
|
||||||
name ?: "");
|
name ?: "");
|
||||||
|
|
||||||
if (name) {
|
r = _activate_check_status(cd, name);
|
||||||
ci = crypt_status(NULL, name);
|
if (r < 0)
|
||||||
if (ci == CRYPT_INVALID) {
|
return r;
|
||||||
log_err(cd, _("Cannot use device %s, name is invalid or still in use.\n"), name);
|
|
||||||
return -EINVAL;
|
|
||||||
} else if (ci >= CRYPT_ACTIVE) {
|
|
||||||
log_err(cd, _("Device %s already exists.\n"), name);
|
|
||||||
return -EEXIST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* use key directly, no hash */
|
/* use key directly, no hash */
|
||||||
if (isPLAIN(cd->type)) {
|
if (isPLAIN(cd->type)) {
|
||||||
@@ -3197,8 +3197,10 @@ int crypt_activate_by_volume_key(struct crypt_device *cd,
|
|||||||
r = INTEGRITY_activate(cd, name, &cd->u.integrity.params, vk,
|
r = INTEGRITY_activate(cd, name, &cd->u.integrity.params, vk,
|
||||||
cd->u.integrity.journal_crypt_key,
|
cd->u.integrity.journal_crypt_key,
|
||||||
cd->u.integrity.journal_mac_key, flags);
|
cd->u.integrity.journal_mac_key, flags);
|
||||||
} else
|
} else {
|
||||||
log_err(cd, _("Device type is not properly initialised.\n"));
|
log_err(cd, _("Device type is not properly initialised.\n"));
|
||||||
|
r = -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
crypt_free_volume_key(vk);
|
crypt_free_volume_key(vk);
|
||||||
|
|
||||||
@@ -4149,7 +4151,6 @@ int crypt_activate_by_keyring(struct crypt_device *cd,
|
|||||||
{
|
{
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
size_t passphrase_size;
|
size_t passphrase_size;
|
||||||
crypt_status_info ci;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!cd || !key_description)
|
if (!cd || !key_description)
|
||||||
@@ -4163,15 +4164,9 @@ int crypt_activate_by_keyring(struct crypt_device *cd,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name) {
|
r = _activate_check_status(cd, name);
|
||||||
ci = crypt_status(NULL, name);
|
if (r < 0)
|
||||||
if (ci == CRYPT_INVALID)
|
return r;
|
||||||
return -EINVAL;
|
|
||||||
else if (ci >= CRYPT_ACTIVE) {
|
|
||||||
log_err(cd, _("Device %s already exists.\n"), name);
|
|
||||||
return -EEXIST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyring_get_passphrase(key_description, &passphrase, &passphrase_size)) {
|
if (keyring_get_passphrase(key_description, &passphrase, &passphrase_size)) {
|
||||||
log_err(cd, _("Failed to read passphrase from keyring key %s"), key_description);
|
log_err(cd, _("Failed to read passphrase from keyring key %s"), key_description);
|
||||||
|
|||||||
Reference in New Issue
Block a user