Do not support user uuid for plain & loopaes devices.

This function was not documented.
So now crypt_get_uuid() returns only on-disk UUID.
This commit is contained in:
Milan Broz
2013-01-22 16:20:09 +01:00
parent 2780ccdd62
commit 72db6e4de2
3 changed files with 24 additions and 30 deletions

View File

@@ -493,14 +493,19 @@ int dm_remove_device(struct crypt_device *cd, const char *name,
* CRYPT-LUKS1-00000000000000000000000000000000-name * CRYPT-LUKS1-00000000000000000000000000000000-name
* CRYPT-TEMP-name * CRYPT-TEMP-name
*/ */
static void dm_prepare_uuid(const char *name, const char *type, const char *uuid, char *buf, size_t buflen) static int dm_prepare_uuid(const char *name, const char *type, const char *uuid, char *buf, size_t buflen)
{ {
char *ptr, uuid2[UUID_LEN] = {0}; char *ptr, uuid2[UUID_LEN] = {0};
uuid_t uu; uuid_t uu;
unsigned i = 0; unsigned i = 0;
/* Remove '-' chars */ /* Remove '-' chars */
if (uuid && !uuid_parse(uuid, uu)) { if (uuid) {
if (uuid_parse(uuid, uu) < 0) {
log_dbg("Requested UUID %s has invalid format.", uuid);
return -EINVAL;
}
for (ptr = uuid2, i = 0; i < UUID_LEN; i++) for (ptr = uuid2, i = 0; i < UUID_LEN; i++)
if (uuid[i] != '-') { if (uuid[i] != '-') {
*ptr = uuid[i]; *ptr = uuid[i];
@@ -516,6 +521,8 @@ static void dm_prepare_uuid(const char *name, const char *type, const char *uuid
log_dbg("DM-UUID is %s", buf); log_dbg("DM-UUID is %s", buf);
if (i >= buflen) if (i >= buflen)
log_err(NULL, _("DM-UUID for device %s was truncated.\n"), name); log_err(NULL, _("DM-UUID for device %s was truncated.\n"), name);
return 0;
} }
static int _dm_create_device(const char *name, const char *type, static int _dm_create_device(const char *name, const char *type,
@@ -542,7 +549,9 @@ static int _dm_create_device(const char *name, const char *type,
if (!dm_task_set_name(dmt, name)) if (!dm_task_set_name(dmt, name))
goto out_no_removal; goto out_no_removal;
} else { } else {
dm_prepare_uuid(name, type, uuid, dev_uuid, sizeof(dev_uuid)); r = dm_prepare_uuid(name, type, uuid, dev_uuid, sizeof(dev_uuid));
if (r < 0)
return r;
if (!(dmt = dm_task_create(DM_DEVICE_CREATE))) if (!(dmt = dm_task_create(DM_DEVICE_CREATE)))
goto out_no_removal; goto out_no_removal;

View File

@@ -195,7 +195,6 @@ int LOOPAES_activate(struct crypt_device *cd,
int r; int r;
struct crypt_dm_active_device dmd = { struct crypt_dm_active_device dmd = {
.target = DM_CRYPT, .target = DM_CRYPT,
.uuid = crypt_get_uuid(cd),
.size = 0, .size = 0,
.flags = flags, .flags = flags,
.data_device = crypt_data_device(cd), .data_device = crypt_data_device(cd),

View File

@@ -60,14 +60,12 @@ struct crypt_device {
struct crypt_params_plain hdr; struct crypt_params_plain hdr;
char *cipher; char *cipher;
char *cipher_mode; char *cipher_mode;
char *uuid;
unsigned int key_size; unsigned int key_size;
} plain; } plain;
struct { /* used in CRYPT_LOOPAES */ struct { /* used in CRYPT_LOOPAES */
struct crypt_params_loopaes hdr; struct crypt_params_loopaes hdr;
char *cipher; char *cipher;
char *cipher_mode; char *cipher_mode;
char *uuid;
unsigned int key_size; unsigned int key_size;
} loopaes; } loopaes;
struct { /* used in CRYPT_VERITY */ struct { /* used in CRYPT_VERITY */
@@ -329,7 +327,6 @@ int PLAIN_activate(struct crypt_device *cd,
enum devcheck device_check; enum devcheck device_check;
struct crypt_dm_active_device dmd = { struct crypt_dm_active_device dmd = {
.target = DM_CRYPT, .target = DM_CRYPT,
.uuid = crypt_get_uuid(cd),
.size = size, .size = size,
.flags = flags, .flags = flags,
.data_device = crypt_data_device(cd), .data_device = crypt_data_device(cd),
@@ -364,10 +361,6 @@ int PLAIN_activate(struct crypt_device *cd,
r = dm_create_device(cd, name, CRYPT_PLAIN, &dmd, 0); r = dm_create_device(cd, name, CRYPT_PLAIN, &dmd, 0);
// FIXME
if (!cd->u.plain.uuid && dm_query_device(cd, name, DM_ACTIVE_UUID, &dmd) >= 0)
cd->u.plain.uuid = CONST_CAST(char*)dmd.uuid;
free(dm_cipher); free(dm_cipher);
return r; return r;
} }
@@ -715,7 +708,6 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
goto out; goto out;
if (isPLAIN(cd->type)) { if (isPLAIN(cd->type)) {
cd->u.plain.uuid = dmd.uuid ? strdup(dmd.uuid) : NULL;
cd->u.plain.hdr.hash = NULL; /* no way to get this */ cd->u.plain.hdr.hash = NULL; /* no way to get this */
cd->u.plain.hdr.offset = dmd.u.crypt.offset; cd->u.plain.hdr.offset = dmd.u.crypt.offset;
cd->u.plain.hdr.skip = dmd.u.crypt.iv_offset; cd->u.plain.hdr.skip = dmd.u.crypt.iv_offset;
@@ -727,7 +719,6 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
cd->u.plain.cipher_mode = strdup(cipher_mode); cd->u.plain.cipher_mode = strdup(cipher_mode);
} }
} else if (isLOOPAES(cd->type)) { } else if (isLOOPAES(cd->type)) {
cd->u.loopaes.uuid = dmd.uuid ? strdup(dmd.uuid) : NULL;
cd->u.loopaes.hdr.offset = dmd.u.crypt.offset; cd->u.loopaes.hdr.offset = dmd.u.crypt.offset;
r = crypt_parse_name_and_mode(dmd.u.crypt.cipher, cipher, r = crypt_parse_name_and_mode(dmd.u.crypt.cipher, cipher,
@@ -784,14 +775,13 @@ static int _init_by_name_verity(struct crypt_device *cd, const char *name)
r = dm_query_device(cd, name, r = dm_query_device(cd, name,
DM_ACTIVE_DEVICE | DM_ACTIVE_DEVICE |
DM_ACTIVE_UUID |
DM_ACTIVE_VERITY_HASH_DEVICE | DM_ACTIVE_VERITY_HASH_DEVICE |
DM_ACTIVE_VERITY_PARAMS, &dmd); DM_ACTIVE_VERITY_PARAMS, &dmd);
if (r < 0) if (r < 0)
goto out; goto out;
if (isVERITY(cd->type)) { if (isVERITY(cd->type)) {
cd->u.verity.uuid = dmd.uuid ? strdup(dmd.uuid) : NULL; cd->u.verity.uuid = NULL; // FIXME
cd->u.verity.hdr.flags = CRYPT_VERITY_NO_HEADER; //FIXME cd->u.verity.hdr.flags = CRYPT_VERITY_NO_HEADER; //FIXME
cd->u.verity.hdr.data_size = params.data_size; cd->u.verity.hdr.data_size = params.data_size;
cd->u.verity.root_hash_size = dmd.u.verity.root_hash_size; cd->u.verity.root_hash_size = dmd.u.verity.root_hash_size;
@@ -810,7 +800,6 @@ static int _init_by_name_verity(struct crypt_device *cd, const char *name)
} }
out: out:
device_free(dmd.data_device); device_free(dmd.data_device);
free(CONST_CAST(void*)dmd.uuid);
return r; return r;
} }
@@ -920,6 +909,11 @@ static int _crypt_format_plain(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
if (uuid) {
log_err(cd, _("UUID is not supported for this crypt type.\n"));
return -EINVAL;
}
if (!(cd->type = strdup(CRYPT_PLAIN))) if (!(cd->type = strdup(CRYPT_PLAIN)))
return -ENOMEM; return -ENOMEM;
@@ -931,8 +925,6 @@ static int _crypt_format_plain(struct crypt_device *cd,
cd->u.plain.cipher = strdup(cipher); cd->u.plain.cipher = strdup(cipher);
cd->u.plain.cipher_mode = strdup(cipher_mode); cd->u.plain.cipher_mode = strdup(cipher_mode);
if (uuid)
cd->u.plain.uuid = strdup(uuid);
if (params && params->hash) if (params && params->hash)
cd->u.plain.hdr.hash = strdup(params->hash); cd->u.plain.hdr.hash = strdup(params->hash);
@@ -1042,6 +1034,11 @@ static int _crypt_format_loopaes(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
if (uuid) {
log_err(cd, _("UUID is not supported for this crypt type.\n"));
return -EINVAL;
}
if (!(cd->type = strdup(CRYPT_LOOPAES))) if (!(cd->type = strdup(CRYPT_LOOPAES)))
return -ENOMEM; return -ENOMEM;
@@ -1049,9 +1046,6 @@ static int _crypt_format_loopaes(struct crypt_device *cd,
cd->u.loopaes.cipher = strdup(cipher ?: DEFAULT_LOOPAES_CIPHER); cd->u.loopaes.cipher = strdup(cipher ?: DEFAULT_LOOPAES_CIPHER);
if (uuid)
cd->u.loopaes.uuid = strdup(uuid);
if (params && params->hash) if (params && params->hash)
cd->u.loopaes.hdr.hash = strdup(params->hash); cd->u.loopaes.hdr.hash = strdup(params->hash);
@@ -1288,7 +1282,7 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
int r; int r;
/* Device context type must be initialised */ /* Device context type must be initialised */
if (!cd->type || !crypt_get_uuid(cd)) if (!cd->type)
return -EINVAL; return -EINVAL;
log_dbg("Resizing device %s to %" PRIu64 " sectors.", name, new_size); log_dbg("Resizing device %s to %" PRIu64 " sectors.", name, new_size);
@@ -1413,11 +1407,9 @@ void crypt_free(struct crypt_device *cd)
free(CONST_CAST(void*)cd->u.plain.hdr.hash); free(CONST_CAST(void*)cd->u.plain.hdr.hash);
free(cd->u.plain.cipher); free(cd->u.plain.cipher);
free(cd->u.plain.cipher_mode); free(cd->u.plain.cipher_mode);
free(cd->u.plain.uuid);
} else if (isLOOPAES(cd->type)) { } else if (isLOOPAES(cd->type)) {
free(CONST_CAST(void*)cd->u.loopaes.hdr.hash); free(CONST_CAST(void*)cd->u.loopaes.hdr.hash);
free(cd->u.loopaes.cipher); free(cd->u.loopaes.cipher);
free(cd->u.loopaes.uuid);
} else if (isVERITY(cd->type)) { } else if (isVERITY(cd->type)) {
free(CONST_CAST(void*)cd->u.verity.hdr.hash_name); free(CONST_CAST(void*)cd->u.verity.hdr.hash_name);
free(CONST_CAST(void*)cd->u.verity.hdr.salt); free(CONST_CAST(void*)cd->u.verity.hdr.salt);
@@ -2452,12 +2444,6 @@ const char *crypt_get_uuid(struct crypt_device *cd)
if (isLUKS(cd->type)) if (isLUKS(cd->type))
return cd->u.luks1.hdr.uuid; return cd->u.luks1.hdr.uuid;
if (isPLAIN(cd->type))
return cd->u.plain.uuid;
if (isLOOPAES(cd->type))
return cd->u.loopaes.uuid;
if (isVERITY(cd->type)) if (isVERITY(cd->type))
return cd->u.verity.uuid; return cd->u.verity.uuid;