mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-19 23:00:18 +01:00
Transfer persistent flags to new LUKS2 header.
This commit is contained in:
committed by
Milan Broz
parent
471f781022
commit
5f26f8a03d
@@ -581,7 +581,7 @@ static int luks2_transfer_tokens(struct reenc_ctx *rc)
|
|||||||
|
|
||||||
if (crypt_init(&cd_old, rc->header_file_tmp) ||
|
if (crypt_init(&cd_old, rc->header_file_tmp) ||
|
||||||
crypt_load(cd_old, CRYPT_LUKS2, NULL))
|
crypt_load(cd_old, CRYPT_LUKS2, NULL))
|
||||||
return -EINVAL;
|
goto out;
|
||||||
|
|
||||||
if (crypt_init(&cd_new, rc->header_file_new) ||
|
if (crypt_init(&cd_new, rc->header_file_new) ||
|
||||||
crypt_load(cd_new, CRYPT_LUKS2, NULL))
|
crypt_load(cd_new, CRYPT_LUKS2, NULL))
|
||||||
@@ -638,6 +638,35 @@ out:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int luks2_transfer_flags(struct reenc_ctx *rc)
|
||||||
|
{
|
||||||
|
int r = -EINVAL;
|
||||||
|
uint32_t flags;
|
||||||
|
struct crypt_device *cd_old = NULL, *cd_new = NULL;
|
||||||
|
|
||||||
|
if (crypt_init(&cd_old, rc->header_file_org) ||
|
||||||
|
crypt_load(cd_old, CRYPT_LUKS2, NULL))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (crypt_init(&cd_new, rc->header_file_new) ||
|
||||||
|
crypt_load(cd_new, CRYPT_LUKS2, NULL))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if ((r = crypt_persistent_flags_get(cd_old, CRYPT_FLAGS_ACTIVATION, &flags)))
|
||||||
|
log_err(_("Failed to read activation flags from backup header.\n"));
|
||||||
|
else if ((r = crypt_persistent_flags_set(cd_new, CRYPT_FLAGS_ACTIVATION, flags)))
|
||||||
|
log_err(_("Failed to write activation flags to new header.\n"));
|
||||||
|
else if ((r = crypt_persistent_flags_get(cd_old, CRYPT_FLAGS_REQUIREMENTS, &flags)))
|
||||||
|
log_err(_("Failed to read requirements from backup header.\n"));
|
||||||
|
else if ((r = crypt_persistent_flags_set(cd_new, CRYPT_FLAGS_REQUIREMENTS, flags)))
|
||||||
|
log_err(_("Failed to read requirements from backup header.\n"));
|
||||||
|
out:
|
||||||
|
crypt_free(cd_old);
|
||||||
|
crypt_free(cd_new);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
static int backup_luks_headers(struct reenc_ctx *rc)
|
static int backup_luks_headers(struct reenc_ctx *rc)
|
||||||
{
|
{
|
||||||
struct crypt_device *cd = NULL;
|
struct crypt_device *cd = NULL;
|
||||||
@@ -713,8 +742,12 @@ static int backup_luks_headers(struct reenc_ctx *rc)
|
|||||||
rc->type,
|
rc->type,
|
||||||
isLUKS2(rc->type) ? (void*)¶ms2 : (void*)¶ms);
|
isLUKS2(rc->type) ? (void*)¶ms2 : (void*)¶ms);
|
||||||
|
|
||||||
if (!r && isLUKS2(rc->type))
|
if (r || !isLUKS2(rc->type))
|
||||||
|
goto out;
|
||||||
|
|
||||||
r = luks2_transfer_tokens(rc);
|
r = luks2_transfer_tokens(rc);
|
||||||
|
if (!r)
|
||||||
|
r = luks2_transfer_flags(rc);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
|
|||||||
Reference in New Issue
Block a user