Fix (deprecated) reload device command to accept new device argument.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@241 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Milan Broz
2010-05-30 12:23:38 +00:00
parent 49463051bc
commit 6ec29d935f
3 changed files with 40 additions and 31 deletions

View File

@@ -2,6 +2,7 @@
* Fix luksFormat/luksOpen reading passphrase from stdin and "-" keyfile. * Fix luksFormat/luksOpen reading passphrase from stdin and "-" keyfile.
* Add verbose log level and move unlocking message there. * Add verbose log level and move unlocking message there.
* Remove device even if underlying device disappeared. * Remove device even if underlying device disappeared.
* Fix (deprecated) reload device command to accept new device argument.
2010-05-23 Milan Broz <mbroz@redhat.com> 2010-05-23 Milan Broz <mbroz@redhat.com>
* Fix luksClose operation for stacked DM devices. * Fix luksClose operation for stacked DM devices.

View File

@@ -254,8 +254,9 @@ static int device_check_and_adjust(struct crypt_device *cd,
{ {
struct device_infos infos; struct device_infos infos;
if (get_device_infos(device, &infos, cd) < 0) { if (!device || get_device_infos(device, &infos, cd) < 0) {
log_err(cd, _("Cannot get info about device %s.\n"), device); log_err(cd, _("Cannot get info about device %s.\n"),
device ?: "[none]");
return -ENOTBLK; return -ENOTBLK;
} }
@@ -587,7 +588,7 @@ void crypt_set_password_callback(struct crypt_device *cd,
/* OPTIONS: name, cipher, device, hash, key_file, key_size, key_slot, /* OPTIONS: name, cipher, device, hash, key_file, key_size, key_slot,
* offset, size, skip, timeout, tries, passphrase_fd (ignored), * offset, size, skip, timeout, tries, passphrase_fd (ignored),
* flags, icb */ * flags, icb */
int crypt_create_device(struct crypt_options *options) static int crypt_create_and_update_device(struct crypt_options *options, int update)
{ {
struct crypt_device *cd = NULL; struct crypt_device *cd = NULL;
char *key = NULL; char *key = NULL;
@@ -607,39 +608,21 @@ int crypt_create_device(struct crypt_options *options)
options->cipher, NULL, options->key_file, key, keyLen, options->cipher, NULL, options->key_file, key, keyLen,
options->key_size, options->size, options->skip, options->key_size, options->size, options->skip,
options->offset, NULL, options->flags & CRYPT_FLAG_READONLY, options->offset, NULL, options->flags & CRYPT_FLAG_READONLY,
options->flags, 0); options->flags, update);
safe_free(key); safe_free(key);
crypt_free(cd); crypt_free(cd);
return r; return r;
} }
/* OPTIONS: same as create above */ int crypt_create_device(struct crypt_options *options)
{
return crypt_create_and_update_device(options, 0);
}
int crypt_update_device(struct crypt_options *options) int crypt_update_device(struct crypt_options *options)
{ {
struct crypt_device *cd = NULL; return crypt_create_and_update_device(options, 1);
char *key = NULL;
unsigned int keyLen;
int r;
r = _crypt_init(&cd, CRYPT_PLAIN, options, 1, 1);
if (r)
return r;
get_key(_("Enter passphrase: "), &key, &keyLen, options->key_size,
options->key_file, cd->timeout, options->flags, cd);
if (!key)
r = -ENOENT;
else
r = create_device_helper(cd, options->name, options->hash,
options->cipher, NULL, options->key_file, key, keyLen,
options->key_size, options->size, options->skip,
options->offset, NULL, options->flags & CRYPT_FLAG_READONLY,
options->flags, 1);
safe_free(key);
crypt_free(cd);
return r;
} }
/* OPTIONS: name, size, icb */ /* OPTIONS: name, size, icb */

View File

@@ -476,7 +476,6 @@ void DeviceResizeGame(void)
co.size = 0; co.size = 0;
OK_(crypt_resize_device(&co)); OK_(crypt_resize_device(&co));
EQ_(_get_device_size(DMDIR CDEVICE_2), (orig_size - 333)); EQ_(_get_device_size(DMDIR CDEVICE_2), (orig_size - 333));
co.size = 0; co.size = 0;
co.offset = 444; co.offset = 444;
co.skip = 555; co.skip = 555;
@@ -492,10 +491,36 @@ void DeviceResizeGame(void)
EQ_(co.key_size, 128 / 8); EQ_(co.key_size, 128 / 8);
EQ_(co.offset, 444); EQ_(co.offset, 444);
EQ_(co.skip, 555); EQ_(co.skip, 555);
OK_(crypt_remove_device(&co));
crypt_put_options(&co); crypt_put_options(&co);
// dangerous switch device still works
memset(&co, 0, sizeof(co));
co.name = CDEVICE_2,
co.device = DEVICE_1;
co.key_file = KEYFILE2;
co.key_size = 128 / 8;
co.cipher = "aes-cbc-plain";
co.hash = "sha1";
co.icb = &cmd_icb;
OK_(crypt_update_device(&co));
memset(&co, 0, sizeof(co));
co.icb = &cmd_icb,
co.name = CDEVICE_2;
EQ_(crypt_query_device(&co), 1);
EQ_(strcmp(co.cipher, "aes-cbc-plain"), 0);
EQ_(co.key_size, 128 / 8);
EQ_(co.offset, 0);
EQ_(co.skip, 0);
// This expect lookup returns prefered /dev/loopX
EQ_(strcmp(co.device, DEVICE_1), 0);
crypt_put_options(&co);
memset(&co, 0, sizeof(co));
co.icb = &cmd_icb,
co.name = CDEVICE_2;
OK_(crypt_remove_device(&co));
_remove_keyfiles(); _remove_keyfiles();
} }