+ /* FIXME: rewrite this from scratch */
+
+ if (opt_shared && strcmp(aname, "create")) {
+ usage(popt_context, EXIT_FAILURE,
+ _("Option --shared is allowed only for create operation.\n"),
+ poptGetInvocationName(popt_context));
+ }
+
+ if (opt_allow_discards &&
+ strcmp(aname, "luksOpen") &&
+ strcmp(aname, "create") &&
+ strcmp(aname, "loopaesOpen")) {
+ usage(popt_context, EXIT_FAILURE,
+ _("Option --allow-discards is allowed only for luksOpen, loopaesOpen and create operation.\n"),
+ poptGetInvocationName(popt_context));
+ }
+
+ if (opt_key_size &&
+ strcmp(aname, "luksFormat") &&
+ strcmp(aname, "create") &&
+ strcmp(aname, "loopaesOpen")) {
+ usage(popt_context, EXIT_FAILURE,
+ _("Option --key-size is allowed only for luksFormat, create and loopaesOpen.\n"
+ "To limit read from keyfile use --keyfile-size=(bytes)."),
+ poptGetInvocationName(popt_context));
+ }
+
+ if (opt_key_size % 8)
+ usage(popt_context, EXIT_FAILURE,
+ _("Key size must be a multiple of 8 bits"),
+ poptGetInvocationName(popt_context));
+
+ if (!strcmp(aname, "luksKillSlot") && action_argc > 1)
+ opt_key_slot = atoi(action_argv[1]);
+ if (opt_key_slot != CRYPT_ANY_SLOT &&
+ (opt_key_slot < 0 || opt_key_slot >= crypt_keyslot_max(CRYPT_LUKS1)))
+ usage(popt_context, EXIT_FAILURE, _("Key slot is invalid."),
+ poptGetInvocationName(popt_context));
+
+ if ((!strcmp(aname, "luksRemoveKey") ||
+ !strcmp(aname, "luksFormat")) &&
+ action_argc > 1) {
+ if (opt_key_file)
+ log_err(_("Option --key-file takes precedence over specified key file argument.\n"));
+ else
+ opt_key_file = action_argv[1];
+ }
+
+ if (opt_keyfile_size < 0 || opt_new_keyfile_size < 0 || opt_key_size < 0 ||
+ opt_keyfile_offset < 0 || opt_new_keyfile_offset < 0) {
+ usage(popt_context, EXIT_FAILURE,
+ _("Negative number for option not permitted."),
+ poptGetInvocationName(popt_context));
+ }
+
+ 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));
+
+ if (opt_uuid && strcmp(aname, "luksFormat") && strcmp(aname, "luksUUID"))
+ 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"),
+ poptGetInvocationName(popt_context));
+
+ if (opt_offset && strcmp(aname, "create") && strcmp(aname, "loopaesOpen"))
+ usage(popt_context, EXIT_FAILURE,
+ _("Option --offset is supported only for create and loopaesOpen commands.\n"),
+ poptGetInvocationName(popt_context));
+