uint64_t size, skip, offset;
int key_size, read_only, r;
+ if (dm_init(NULL, 1) < 0)
+ return -ENOSYS;
+
r = dm_query_device(options->name, &device, &size, &skip, &offset,
&cipher, &key_size, &key, &read_only, NULL, &uuid);
if (r < 0)
free(device);
free(uuid);
crypt_free(cd);
+ dm_exit();
return r;
}
{
int read_only, r;
+ if (dm_init(NULL, 1) < 0)
+ return -ENOSYS;
+
r = dm_status_device(options->name);
- if (r == -ENODEV)
+ if (r == -ENODEV) {
+ dm_exit();
return 0;
+ }
r = dm_query_device(options->name, (char **)&options->device, &options->size,
&options->skip, &options->offset, (char **)&options->cipher,
&options->key_size, NULL, &read_only, NULL, NULL);
+ dm_exit();
if (r < 0)
return r;
return -ENOMEM;
}
- if (!dm_init(h, 1) < 0) {
+ if (dm_init(h, 1) < 0) {
free(h);
return -ENOSYS;
}
log_dbg("Allocating crypt device context by device %s.", name);
ci = crypt_status(NULL, name);
+ if (ci == INVALID)
+ return -ENODEV;
+
if (ci < ACTIVE) {
log_err(NULL, _("Device %s is not active.\n"), name);
return -ENODEV;
return -EINVAL;
}
+ if (!cd && dm_init(NULL, 1) < 0)
+ return -ENOSYS;
+
r = dm_query_device(name, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, &suspended, NULL);
if (r < 0)
- return r;
+ goto out;
if (suspended) {
log_err(cd, _("Volume %s is already suspended.\n"), name);
- return -EINVAL;
+ r = -EINVAL;
+ goto out;
}
r = dm_suspend_and_wipe_key(name);
if (r)
log_err(cd, "Error during suspending device %s.\n", name);
-
+out:
+ if (!cd)
+ dm_exit();
return r;
}
int crypt_deactivate(struct crypt_device *cd, const char *name)
{
+ int r;
+
if (!name)
return -EINVAL;
log_dbg("Deactivating volume %s.", name);
+ if (!cd && dm_init(NULL, 1) < 0)
+ return -ENOSYS;
+
switch (crypt_status(cd, name)) {
- case ACTIVE: return dm_remove_device(name, 0, 0);
+ case ACTIVE: r = dm_remove_device(name, 0, 0);
+ break;
case BUSY: log_err(cd, _("Device %s is busy."), name);
- return -EBUSY;
+ r = -EBUSY;
+ break;
case INACTIVE: log_err(cd, _("Device %s is not active."), name);
- return -ENODEV;
+ r = -ENODEV;
+ break;
default: log_err(cd, _("Invalid device %s."), name);
- return -EINVAL;
+ r = -EINVAL;
}
+
+ if (!cd)
+ dm_exit();
+
+ return r;
}
// misc helper functions
{
int r;
+ if (!cd && dm_init(NULL, 1) < 0)
+ return INVALID;
+
r = dm_status_device(name);
+ if (!cd)
+ dm_exit();
+
if (r < 0 && r != -ENODEV)
return INVALID;
int (*handler)(int);
int arg;
int required_action_argc;
- int required_dm_backend;
int required_memlock;
int show_status;
const char *arg_desc;
const char *desc;
} action_types[] = {
- { "create", action_create, 0, 2, 1, 1, 1, N_("<name> <device>"),N_("create device") },
- { "remove", action_remove, 0, 1, 1, 1, 1, N_("<name>"), N_("remove device") },
- { "resize", action_resize, 0, 1, 1, 1, 1, N_("<name>"), N_("resize active device") },
- { "status", action_status, 0, 1, 1, 0, 1, N_("<name>"), N_("show device status") },
- { "luksFormat", action_luksFormat, 0, 1, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
- { "luksOpen", action_luksOpen, 0, 2, 1, 1, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
- { "luksAddKey", action_luksAddKey, 0, 1, 1, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
- { "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
- { "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
- { "luksUUID", action_luksUUID, 0, 1, 0, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
- { "isLuks", action_isLuks, 0, 1, 0, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
- { "luksClose", action_remove, 0, 1, 1, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
- { "luksDump", action_luksDump, 0, 1, 0, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
- { "luksSuspend",action_luksSuspend, 0, 1, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
- { "luksResume", action_luksResume, 0, 1, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
- { "luksHeaderBackup",action_luksBackup, 0, 1, 1, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
- { "luksHeaderRestore",action_luksRestore,0,1, 1, 1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
- { "luksDelKey", action_luksDelKey, 0, 2, 1, 1, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
- { "reload", action_create, 1, 2, 1, 1, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
- { NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL }
+ { "create", action_create, 0, 2, 1, 1, N_("<name> <device>"),N_("create device") },
+ { "remove", action_remove, 0, 1, 1, 1, N_("<name>"), N_("remove device") },
+ { "resize", action_resize, 0, 1, 1, 1, N_("<name>"), N_("resize active device") },
+ { "status", action_status, 0, 1, 0, 1, N_("<name>"), N_("show device status") },
+ { "luksFormat", action_luksFormat, 0, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
+ { "luksOpen", action_luksOpen, 0, 2, 1, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
+ { "luksAddKey", action_luksAddKey, 0, 1, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
+ { "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
+ { "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
+ { "luksUUID", action_luksUUID, 0, 1, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
+ { "isLuks", action_isLuks, 0, 1, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
+ { "luksClose", action_remove, 0, 1, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
+ { "luksDump", action_luksDump, 0, 1, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
+ { "luksSuspend",action_luksSuspend, 0, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
+ { "luksResume", action_luksResume, 0, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
+ { "luksHeaderBackup",action_luksBackup, 0, 1, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
+ { "luksHeaderRestore",action_luksRestore,0,1, 1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
+ { "luksDelKey", action_luksDelKey, 0, 2, 1, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
+ { "reload", action_create, 1, 2, 1, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
+ { NULL, NULL, 0, 0, 0, 0, NULL, NULL }
};
static void clogger(struct crypt_device *cd, int class, const char *file,