Allow no hash specification in plain device constructor (issue 63).
authorMilan Broz <gmazyland@gmail.com>
Fri, 30 Apr 2010 14:05:25 +0000 (14:05 +0000)
committerMilan Broz <gmazyland@gmail.com>
Fri, 30 Apr 2010 14:05:25 +0000 (14:05 +0000)
Fix some warnings in apitest.

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

ChangeLog
lib/setup.c
tests/apitest.c

index 5ccd91b..a7c7d14 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
        * Try to use pkgconfig for device mapper library.
        * Detect old dm-crypt module and disable LUKS suspend/resume.
        * Fix apitest to work on older systems.
+       * Allow no hash specification in plain device constructor.
 
 2010-04-12  Milan Broz  <mbroz@redhat.com>
        * Fix package config to use proper package version.
index fd264f3..df03588 100644 (file)
@@ -112,7 +112,8 @@ static char *process_key(struct crypt_device *cd, const char *hash_name,
        /* key is coming from tty, fd or binary stdin */
        if (hash_name) {
                if (hash(NULL, hash_name, key, key_size, pass, passLen) < 0) {
-                       log_err(cd, _("Key processing error.\n"));
+                       log_err(cd, _("Key processing error (using hash algorithm %s).\n"),
+                               hash_name);
                        safe_free(key);
                        return NULL;
                }
@@ -1056,7 +1057,7 @@ static int _crypt_format_plain(struct crypt_device *cd,
                               const char *uuid,
                               struct crypt_params_plain *params)
 {
-       if (!cipher || !cipher_mode || !params || !params->hash) {
+       if (!cipher || !cipher_mode) {
                log_err(cd, _("Invalid plain crypt parameters.\n"));
                return -EINVAL;
        }
@@ -1072,14 +1073,13 @@ static int _crypt_format_plain(struct crypt_device *cd,
        if (uuid)
                cd->plain_uuid = strdup(uuid);
 
-       if (params->hash)
+       if (params && params->hash)
                cd->plain_hdr.hash = strdup(params->hash);
 
-       cd->plain_hdr.offset = params->offset;
-       cd->plain_hdr.skip = params->skip;
+       cd->plain_hdr.offset = params ? params->offset : 0;
+       cd->plain_hdr.skip = params ? params->skip : 0;
 
-       if ((params->hash && !cd->plain_hdr.hash) ||
-           !cd->plain_cipher || !cd->plain_cipher_mode)
+       if (!cd->plain_cipher || !cd->plain_cipher_mode)
                return -ENOMEM;
 
        return 0;
@@ -1863,7 +1863,7 @@ int crypt_volume_key_get(struct crypt_device *cd,
                return -ENOMEM;
        }
 
-       if (isPLAIN(cd->type)) {
+       if (isPLAIN(cd->type) && cd->plain_hdr.hash) {
                processed_key = process_key(cd, cd->plain_hdr.hash, NULL, key_len,
                                            passphrase, passphrase_size);
                if (!processed_key) {
index 14f6aed..bf38e11 100644 (file)
@@ -113,7 +113,7 @@ static int yesDialog(char *msg)
 
 static void cmdLineLog(int level, char *msg)
 {
-       strncat(global_log, msg, sizeof(global_log));
+       strncat(global_log, msg, sizeof(global_log) - strlen(global_log));
        global_lines++;
 }
 
@@ -136,41 +136,44 @@ static struct interface_callbacks cmd_icb = {
 
 static void _cleanup(void)
 {
+       int r;
        struct stat st;
 
-       //system("udevadm settle");
+       //r = system("udevadm settle");
 
        if (!stat(DMDIR CDEVICE_1, &st))
-               system("dmsetup remove " CDEVICE_1);
+               r = system("dmsetup remove " CDEVICE_1);
 
        if (!stat(DMDIR CDEVICE_2, &st))
-               system("dmsetup remove " CDEVICE_2);
+               r = system("dmsetup remove " CDEVICE_2);
 
        if (!stat(DEVICE_EMPTY, &st))
-               system("dmsetup remove " DEVICE_EMPTY_name);
+               r = system("dmsetup remove " DEVICE_EMPTY_name);
 
        if (!stat(DEVICE_ERROR, &st))
-               system("dmsetup remove " DEVICE_ERROR_name);
+               r = system("dmsetup remove " DEVICE_ERROR_name);
 
        if (!strncmp("/dev/loop", DEVICE_1, 9))
-               system("losetup -d " DEVICE_1);
+               r = system("losetup -d " DEVICE_1);
 
        if (!strncmp("/dev/loop", DEVICE_2, 9))
-               system("losetup -d " DEVICE_2);
+               r = system("losetup -d " DEVICE_2);
 
-       system("rm -f " IMAGE_EMPTY);
+       r = system("rm -f " IMAGE_EMPTY);
        _remove_keyfiles();
 }
 
 static void _setup(void)
 {
-       system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"");
-       system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"");
+       int r;
+
+       r = system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"");
+       r = system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"");
        if (!strncmp("/dev/loop", DEVICE_1, 9))
-               system("losetup " DEVICE_1 " " IMAGE1);
+               r = system("losetup " DEVICE_1 " " IMAGE1);
        if (!strncmp("/dev/loop", DEVICE_2, 9)) {
-               system("dd if=/dev/zero of=" IMAGE_EMPTY " bs=1M count=4");
-               system("losetup " DEVICE_2 " " IMAGE_EMPTY);
+               r = system("dd if=/dev/zero of=" IMAGE_EMPTY " bs=1M count=4");
+               r = system("losetup " DEVICE_2 " " IMAGE_EMPTY);
        }
 
 }
@@ -517,6 +520,18 @@ static void AddDevicePlain(void)
 
        FAIL_(crypt_init(&cd, ""), "empty device string");
 
+       // default is "plain" hash - no password hash
+       OK_(crypt_init(&cd, DEVICE_1));
+       OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, NULL));
+       OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
+       EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
+       // FIXME: this should get key from active device?
+       //OK_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
+       //OK_(memcmp(key, key2, key_size));
+       OK_(crypt_deactivate(cd, CDEVICE_1));
+       crypt_free(cd);
+
+       // Now use hashed password
        OK_(crypt_init(&cd, DEVICE_1));
        OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, &params));
        OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));