*
* Copyright (C) 2004, Christophe Saout <christophe@saout.de>
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
- * Copyright (C) 2009-2011, Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
#include <fcntl.h>
#include <assert.h>
#include <limits.h>
-#include <libcryptsetup.h>
#include <popt.h>
#include "cryptsetup.h"
static int action_luksBackup(int arg);
static int action_luksRestore(int arg);
static int action_loopaesOpen(int arg);
+static int action_luksRepair(int arg);
static struct action_type {
const char *type;
{ "remove", action_remove, 0, 1, 1, N_("<name>"), N_("remove device") },
{ "resize", action_resize, 0, 1, 1, N_("<name>"), N_("resize active device") },
{ "status", action_status, 0, 1, 0, N_("<name>"), N_("show device status") },
+ { "repair", action_luksRepair, 0, 1, 1, N_("<device>"), N_("try to repair on-disk metadata") },
{ "luksFormat", action_luksFormat, 0, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
{ "luksOpen", action_luksOpen, 0, 2, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
{ "luksAddKey", action_luksAddKey, 0, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
}
out:
crypt_free(cd);
+ if (r == -ENOTSUP)
+ r = 0;
return r;
}
return -EINVAL;
}
+static int action_luksRepair(int arg __attribute__((unused)))
+{
+ struct crypt_device *cd = NULL;
+ int r;
+
+ if ((r = crypt_init(&cd, action_argv[0])))
+ goto out;
+
+ /* Currently only LUKS1 allows repair */
+ crypt_set_log_callback(cd, _quiet_log, NULL);
+ r = crypt_load(cd, CRYPT_LUKS1, NULL);
+ crypt_set_log_callback(cd, _log, NULL);
+ if (r == 0) {
+ log_verbose( _("No known problems detected for LUKS header.\n"));
+ goto out;
+ }
+
+ r = _yesDialog(_("Really try to repair LUKS device header?"),
+ NULL) ? 0 : -EINVAL;
+ if (r == 0)
+ r = crypt_repair(cd, CRYPT_LUKS1, NULL);
+out:
+ crypt_free(cd);
+ return r;
+}
+
static int action_luksFormat(int arg __attribute__((unused)))
{
int r = -EINVAL, keysize;
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+ crypt_fips_self_check(NULL);
+
popt_context = poptGetContext(PACKAGE, argc, argv, popt_options, 0);
poptSetOtherOptionHelp(popt_context,
- N_("[OPTION...] <action> <action-specific>]"));
+ N_("[OPTION...] <action> <action-specific>"));
while((r = poptGetNextOpt(popt_context)) > 0) {
unsigned long long ull_value;
if (opt_random && opt_urandom)
usage(popt_context, EXIT_FAILURE, _("Only one of --use-[u]random options is allowed."),
poptGetInvocationName(popt_context));
+
if ((opt_random || opt_urandom) && strcmp(aname, "luksFormat"))
usage(popt_context, EXIT_FAILURE, _("Option --use-[u]random is allowed only for luksFormat."),
poptGetInvocationName(popt_context));
usage(popt_context, EXIT_FAILURE, _("Option --uuid is allowed only for luksFormat and luksUUID."),
poptGetInvocationName(popt_context));
+ if (opt_align_payload && strcmp(aname, "luksFormat"))
+ usage(popt_context, EXIT_FAILURE, _("Option --align-payload is allowed only for luksFormat."),
+ poptGetInvocationName(popt_context));
+
if (opt_skip && strcmp(aname, "create") && strcmp(aname, "loopaesOpen"))
usage(popt_context, EXIT_FAILURE,
_("Option --skip is supported only for create and loopaesOpen commands.\n"),