+static int action_open(void)
+{
+ if (!opt_type)
+ return -EINVAL;
+
+ if (!strcmp(opt_type, "luks") || !strcmp(opt_type, "luks1")) {
+ if (action_argc < 2 && !opt_test_passphrase)
+ goto args;
+ return action_open_luks();
+ } else if (!strcmp(opt_type, "plain")) {
+ if (action_argc < 2)
+ goto args;
+ return action_open_plain();
+ } else if (!strcmp(opt_type, "loopaes")) {
+ if (action_argc < 2)
+ goto args;
+ return action_open_loopaes();
+ } else if (!strcmp(opt_type, "tcrypt")) {
+ if (action_argc < 2 && !opt_test_passphrase)
+ goto args;
+ return action_open_tcrypt();
+ }
+
+ log_err(_("Unrecognized metadata device type %s.\n"), opt_type);
+ return -EINVAL;
+args:
+ log_err(_("Command requires device and mapped name as arguments.\n"));
+ return -EINVAL;
+}
+
+static int action_luksErase(void)
+{
+ struct crypt_device *cd = NULL;
+ crypt_keyslot_info ki;
+ char *msg = NULL;
+ int i, r;
+
+ if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
+ goto out;
+
+ crypt_set_confirm_callback(cd, yesDialog, NULL);
+
+ if ((r = crypt_load(cd, CRYPT_LUKS1, NULL)))
+ goto out;
+
+ if(asprintf(&msg, _("This operation will erase all keyslots on device %s.\n"
+ "Device will become unusable after this operation."),
+ uuid_or_device_header(NULL)) == -1) {
+ r = -ENOMEM;
+ goto out;
+ }
+
+ if (!yesDialog(msg, NULL)) {
+ r = -EPERM;
+ goto out;
+ }
+
+ for (i = 0; i < crypt_keyslot_max(CRYPT_LUKS1); i++) {
+ ki = crypt_keyslot_status(cd, i);
+ if (ki == CRYPT_SLOT_ACTIVE || ki == CRYPT_SLOT_ACTIVE_LAST) {
+ r = crypt_keyslot_destroy(cd, i);
+ if (r < 0)
+ goto out;
+ }
+ }
+out:
+ free(msg);
+ crypt_free(cd);
+ return r;
+}
+
+static struct action_type {
+ const char *type;
+ int (*handler)(void);
+ int required_action_argc;
+ int required_memlock;
+ const char *arg_desc;
+ const char *desc;
+} action_types[] = {
+ { "open", action_open, 1, 1, N_("<device> [--type <type>] [<name>]"),N_("open device as mapping <name>") },
+ { "close", action_close, 1, 1, N_("<name>"), N_("close device (remove mapping)") },
+ { "resize", action_resize, 1, 1, N_("<name>"), N_("resize active device") },
+ { "status", action_status, 1, 0, N_("<name>"), N_("show device status") },
+ { "benchmark", action_benchmark, 0, 0, N_("<name>"), N_("benchmark cipher") },
+ { "repair", action_luksRepair, 1, 1, N_("<device>"), N_("try to repair on-disk metadata") },
+ { "erase", action_luksErase , 1, 1, N_("<device>"), N_("erase all keyslots (remove encryption key)") },
+ { "luksFormat", action_luksFormat, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
+ { "luksAddKey", action_luksAddKey, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
+ { "luksRemoveKey",action_luksRemoveKey,1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
+ { "luksChangeKey",action_luksChangeKey,1, 1, N_("<device> [<key file>]"), N_("changes supplied key or key file of LUKS device") },
+ { "luksKillSlot", action_luksKillSlot, 2, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
+ { "luksUUID", action_luksUUID, 1, 0, N_("<device>"), N_("print UUID of LUKS device") },
+ { "isLuks", action_isLuks, 1, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
+ { "luksDump", action_luksDump, 1, 1, N_("<device>"), N_("dump LUKS partition information") },
+ { "tcryptDump", action_tcryptDump, 1, 1, N_("<device>"), N_("dump TCRYPT device information") },
+ { "luksSuspend", action_luksSuspend, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
+ { "luksResume", action_luksResume, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
+ { "luksHeaderBackup", action_luksBackup,1,1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
+ { "luksHeaderRestore",action_luksRestore,1,1,N_("<device>"), N_("Restore LUKS device header and keyslots") },
+ {}
+};
+