Do not allow format of already formatted context.
authorMilan Broz <gmazyland@gmail.com>
Fri, 26 Aug 2011 19:46:29 +0000 (19:46 +0000)
committerMilan Broz <gmazyland@gmail.com>
Fri, 26 Aug 2011 19:46:29 +0000 (19:46 +0000)
(Thanks to okozina@redhat.com)

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@608 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/setup.c
tests/api-test.c

index a3eaec1..6606323 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
        * Fix crypt_load to properly check device size.
        * Use new /dev/loop-control (kernel 3.1) if possible.
        * Enhance check of device size before writing LUKS header.
+       * Do not allow context format of already formatted device.
 
 2011-07-25  Milan Broz  <mbroz@redhat.com>
        * Remove hash/hmac restart from crypto backend and make it part of hash/hmac final.
index b284514..8aff22a 100644 (file)
@@ -851,6 +851,11 @@ int crypt_format(struct crypt_device *cd,
        if (!type)
                return -EINVAL;
 
+       if (cd->type) {
+               log_dbg("Context already formatted as %s.", cd->type);
+               return -EINVAL;
+       }
+
        log_dbg("Formatting device %s as type %s.", mdata_device(cd) ?: "(none)", type);
 
        r = init_crypto(cd);
index d7dc795..5d7dd22 100644 (file)
@@ -974,8 +974,8 @@ static void AddDeviceLuks(void)
        OK_(crypt_deactivate(cd, CDEVICE_1));
        EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
        // restrict format only to empty context
-//     FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params), "Context is already formated");
-//     FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, NULL), "Context is already formated");
+       FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params), "Context is already formated");
+       FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, NULL), "Context is already formated");
        // change data device to wrong one
        OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_0S));
        FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Device too small");