Do not support user uuid for plain & loopaes devices.
authorMilan Broz <gmazyland@gmail.com>
Tue, 22 Jan 2013 15:20:09 +0000 (16:20 +0100)
committerMilan Broz <gmazyland@gmail.com>
Tue, 22 Jan 2013 15:20:09 +0000 (16:20 +0100)
This function was not documented.
So now crypt_get_uuid() returns only on-disk UUID.

lib/libdevmapper.c
lib/loopaes/loopaes.c
lib/setup.c

index 9fd01b4..59c3453 100644 (file)
@@ -493,14 +493,19 @@ int dm_remove_device(struct crypt_device *cd, const char *name,
  * CRYPT-LUKS1-00000000000000000000000000000000-name
  * CRYPT-TEMP-name
  */
  * CRYPT-LUKS1-00000000000000000000000000000000-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};
        uuid_t uu;
        unsigned i = 0;
 
        /* Remove '-' chars */
 {
        char *ptr, uuid2[UUID_LEN] = {0};
        uuid_t uu;
        unsigned i = 0;
 
        /* 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++)
                        if (uuid[i] != '-') {
                                *ptr = uuid[i];
                for (ptr = uuid2, i = 0; i < UUID_LEN; i++)
                        if (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);
        if (i >= buflen)
                log_err(NULL, _("DM-UUID for device %s was truncated.\n"), name);
        log_dbg("DM-UUID is %s", buf);
        if (i >= buflen)
                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))
                        goto out_no_removal;
        } else {
                if (!dm_task_set_name(dmt, name))
                        goto out_no_removal;
        } 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)))
                        goto out_no_removal;
 
                if (!(dmt = dm_task_create(DM_DEVICE_CREATE)))
                        goto out_no_removal;
index 6ad965c..0c1fd93 100644 (file)
@@ -195,7 +195,6 @@ int LOOPAES_activate(struct crypt_device *cd,
        int r;
        struct crypt_dm_active_device dmd = {
                .target = DM_CRYPT,
        int r;
        struct crypt_dm_active_device dmd = {
                .target = DM_CRYPT,
-               .uuid   = crypt_get_uuid(cd),
                .size   = 0,
                .flags  = flags,
                .data_device = crypt_data_device(cd),
                .size   = 0,
                .flags  = flags,
                .data_device = crypt_data_device(cd),
index 6263578..86967fe 100644 (file)
@@ -60,14 +60,12 @@ struct crypt_device {
                struct crypt_params_plain hdr;
                char *cipher;
                char *cipher_mode;
                struct crypt_params_plain hdr;
                char *cipher;
                char *cipher_mode;
-               char *uuid;
                unsigned int key_size;
        } plain;
        struct { /* used in CRYPT_LOOPAES */
                struct crypt_params_loopaes hdr;
                char *cipher;
                char *cipher_mode;
                unsigned int key_size;
        } plain;
        struct { /* used in CRYPT_LOOPAES */
                struct crypt_params_loopaes hdr;
                char *cipher;
                char *cipher_mode;
-               char *uuid;
                unsigned int key_size;
        } loopaes;
        struct { /* used in CRYPT_VERITY */
                unsigned int key_size;
        } loopaes;
        struct { /* used in CRYPT_VERITY */
@@ -329,7 +327,6 @@ int PLAIN_activate(struct crypt_device *cd,
        enum devcheck device_check;
        struct crypt_dm_active_device dmd = {
                .target = DM_CRYPT,
        enum devcheck device_check;
        struct crypt_dm_active_device dmd = {
                .target = DM_CRYPT,
-               .uuid   = crypt_get_uuid(cd),
                .size   = size,
                .flags  = flags,
                .data_device = crypt_data_device(cd),
                .size   = size,
                .flags  = flags,
                .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);
        return r;
 }
        free(dm_cipher);
        return r;
 }
@@ -715,7 +708,6 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
                goto out;
 
        if (isPLAIN(cd->type)) {
                goto out;
 
        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.offset = dmd.u.crypt.offset;
                cd->u.plain.hdr.skip = dmd.u.crypt.iv_offset;
                cd->u.plain.hdr.hash = NULL; /* no way to get this */
                cd->u.plain.hdr.offset = dmd.u.crypt.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);
                }
        } else if (isLOOPAES(cd->type)) {
                        cd->u.plain.cipher_mode = strdup(cipher_mode);
                }
        } else if (isLOOPAES(cd->type)) {
-               cd->u.loopaes.uuid = dmd.uuid ? strdup(dmd.uuid) : NULL;
                cd->u.loopaes.hdr.offset = dmd.u.crypt.offset;
 
                r = crypt_parse_name_and_mode(dmd.u.crypt.cipher, cipher,
                cd->u.loopaes.hdr.offset = dmd.u.crypt.offset;
 
                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,
                                DM_ACTIVE_DEVICE |
 
        r = dm_query_device(cd, name,
                                DM_ACTIVE_DEVICE |
-                               DM_ACTIVE_UUID |
                                DM_ACTIVE_VERITY_HASH_DEVICE |
                                DM_ACTIVE_VERITY_PARAMS, &dmd);
        if (r < 0)
                goto out;
 
        if (isVERITY(cd->type)) {
                                DM_ACTIVE_VERITY_HASH_DEVICE |
                                DM_ACTIVE_VERITY_PARAMS, &dmd);
        if (r < 0)
                goto out;
 
        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.data_size = params.data_size;
                cd->u.verity.root_hash_size = dmd.u.verity.root_hash_size;
                cd->u.verity.hdr.flags = CRYPT_VERITY_NO_HEADER; //FIXME
                cd->u.verity.hdr.data_size = params.data_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:
        device_free(dmd.data_device);
        }
 out:
        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)))
                return -ENOMEM;
 
        if (!(cd->type = strdup(CRYPT_PLAIN)))
                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_mode = strdup(cipher_mode);
 
        cd->u.plain.cipher = strdup(cipher);
        cd->u.plain.cipher_mode = strdup(cipher_mode);
 
-       if (uuid)
-               cd->u.plain.uuid = strdup(uuid);
 
        if (params && params->hash)
                cd->u.plain.hdr.hash = strdup(params->hash);
 
        if (params && 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)))
                return -ENOMEM;
 
        if (!(cd->type = strdup(CRYPT_LOOPAES)))
                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)
                cd->u.loopaes.hdr.hash = strdup(params->hash);
 
        if (params && 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;
 
        /* Device context type must be initialised */
        int r;
 
        /* Device context type must be initialised */
-       if (!cd->type || !crypt_get_uuid(cd))
+       if (!cd->type)
                return -EINVAL;
 
        log_dbg("Resizing device %s to %" PRIu64 " sectors.", name, new_size);
                return -EINVAL;
 
        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(cd->u.plain.cipher);
                        free(cd->u.plain.cipher_mode);
                        free(CONST_CAST(void*)cd->u.plain.hdr.hash);
                        free(cd->u.plain.cipher);
                        free(cd->u.plain.cipher_mode);
-                       free(cd->u.plain.uuid);
                } else if (isLOOPAES(cd->type)) {
                        free(CONST_CAST(void*)cd->u.loopaes.hdr.hash);
                        free(cd->u.loopaes.cipher);
                } else if (isLOOPAES(cd->type)) {
                        free(CONST_CAST(void*)cd->u.loopaes.hdr.hash);
                        free(cd->u.loopaes.cipher);
-                       free(cd->u.loopaes.uuid);
                } else if (isVERITY(cd->type)) {
                        free(CONST_CAST(void*)cd->u.verity.hdr.hash_name);
                        free(CONST_CAST(void*)cd->u.verity.hdr.salt);
                } else if (isVERITY(cd->type)) {
                        free(CONST_CAST(void*)cd->u.verity.hdr.hash_name);
                        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))
                return cd->u.luks1.hdr.uuid;
 
        if (isLUKS(cd->type))
                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))
                return cd->u.verity.uuid;
 
        if (isVERITY(cd->type))
                return cd->u.verity.uuid;