12 #include <libcryptsetup.h>
15 #include "../config.h"
17 #include "cryptsetup.h"
19 static int opt_verbose = 0;
20 static int opt_debug = 0;
21 static char *opt_cipher = NULL;
22 static char *opt_hash = NULL;
23 static int opt_verify_passphrase = 0;
24 static char *opt_key_file = NULL;
25 static char *opt_master_key_file = NULL;
26 static char *opt_header_backup_file = NULL;
27 static unsigned int opt_key_size = 0;
28 static int opt_key_slot = CRYPT_ANY_SLOT;
29 static uint64_t opt_size = 0;
30 static uint64_t opt_offset = 0;
31 static uint64_t opt_skip = 0;
32 static int opt_readonly = 0;
33 static int opt_iteration_time = 1000;
34 static int opt_batch_mode = 0;
35 static int opt_version_mode = 0;
36 static int opt_timeout = 0;
37 static int opt_tries = 3;
38 static int opt_align_payload = 0;
39 static int opt_non_exclusive = 0;
40 static int opt_random = 0;
41 static int opt_urandom = 0;
43 static const char **action_argv;
44 static int action_argc;
46 static int action_create(int arg);
47 static int action_remove(int arg);
48 static int action_resize(int arg);
49 static int action_status(int arg);
50 static int action_luksFormat(int arg);
51 static int action_luksOpen(int arg);
52 static int action_luksAddKey(int arg);
53 static int action_luksDelKey(int arg);
54 static int action_luksKillSlot(int arg);
55 static int action_luksRemoveKey(int arg);
56 static int action_isLuks(int arg);
57 static int action_luksUUID(int arg);
58 static int action_luksDump(int arg);
59 static int action_luksSuspend(int arg);
60 static int action_luksResume(int arg);
61 static int action_luksBackup(int arg);
62 static int action_luksRestore(int arg);
64 static struct action_type {
68 int required_action_argc;
73 { "create", action_create, 0, 2, 1, N_("<name> <device>"),N_("create device") },
74 { "remove", action_remove, 0, 1, 1, N_("<name>"), N_("remove device") },
75 { "resize", action_resize, 0, 1, 1, N_("<name>"), N_("resize active device") },
76 { "status", action_status, 0, 1, 0, N_("<name>"), N_("show device status") },
77 { "luksFormat", action_luksFormat, 0, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
78 { "luksOpen", action_luksOpen, 0, 2, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
79 { "luksAddKey", action_luksAddKey, 0, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
80 { "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
81 { "luksKillSlot", action_luksKillSlot, 0, 2, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
82 { "luksUUID", action_luksUUID, 0, 1, 0, N_("<device>"), N_("print UUID of LUKS device") },
83 { "isLuks", action_isLuks, 0, 1, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
84 { "luksClose", action_remove, 0, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
85 { "luksDump", action_luksDump, 0, 1, 0, N_("<device>"), N_("dump LUKS partition information") },
86 { "luksSuspend",action_luksSuspend, 0, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
87 { "luksResume", action_luksResume, 0, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
88 { "luksHeaderBackup",action_luksBackup, 0, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
89 { "luksHeaderRestore",action_luksRestore,0,1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
90 { "luksDelKey", action_luksDelKey, 0, 2, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
91 { "reload", action_create, 1, 2, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
92 { NULL, NULL, 0, 0, 0, NULL, NULL }
95 static void clogger(struct crypt_device *cd, int level, const char *file,
96 int line, const char *format, ...)
101 va_start(argp, format);
103 if (vasprintf(&target, format, argp) > 0) {
105 crypt_log(cd, level, target);
107 } else if (opt_debug)
108 printf("# %s:%d %s\n", file ?: "?", line, target);
110 } else if (opt_debug)
111 printf("# %s\n", target);
119 /* Interface Callbacks */
120 static int yesDialog(char *msg)
126 if(isatty(0) && !opt_batch_mode) {
127 log_std("\nWARNING!\n========\n");
128 log_std("%s\n\nAre you sure? (Type uppercase yes): ", msg);
129 if(getline(&answer, &size, stdin) == -1) {
134 if(strcmp(answer, "YES\n"))
142 static void cmdLineLog(int level, char *msg) {
145 case CRYPT_LOG_NORMAL:
148 case CRYPT_LOG_VERBOSE:
152 case CRYPT_LOG_ERROR:
156 fprintf(stderr, "Internal error on logging class for msg: %s", msg);
161 static struct interface_callbacks cmd_icb = {
162 .yesDialog = yesDialog,
166 static void _log(int level, const char *msg, void *usrptr)
168 cmdLineLog(level, (char *)msg);
171 static int _yesDialog(const char *msg, void *usrptr)
173 return yesDialog((char*)msg);
178 static void show_status(int errcode)
180 char error[256], *error_;
186 log_std(_("Command successful.\n"));
190 crypt_get_error(error, sizeof(error));
193 error_ = strerror_r(-errcode, error, sizeof(error));
194 if (error_ != error) {
195 strncpy(error, error_, sizeof(error));
196 error[sizeof(error) - 1] = '\0';
200 log_err(_("Command failed with code %i"), -errcode);
202 log_err(": %s\n", error);
207 static int action_create(int reload)
209 struct crypt_options options = {
210 .name = action_argv[0],
211 .device = action_argv[1],
212 .cipher = opt_cipher ? opt_cipher : DEFAULT_CIPHER(PLAIN),
213 .hash = opt_hash ?: DEFAULT_PLAIN_HASH,
214 .key_file = opt_key_file,
215 .key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS) / 8,
216 .key_slot = opt_key_slot,
219 .offset = opt_offset,
221 .timeout = opt_timeout,
228 log_err(_("The reload action is deprecated. Please use \"dmsetup reload\" in case you really need this functionality.\nWARNING: do not use reload to touch LUKS devices. If that is the case, hit Ctrl-C now.\n"));
230 if (options.hash && strcmp(options.hash, "plain") == 0)
232 if (opt_verify_passphrase)
233 options.flags |= CRYPT_FLAG_VERIFY;
235 options.flags |= CRYPT_FLAG_READONLY;
238 r = crypt_update_device(&options);
240 r = crypt_create_device(&options);
245 static int action_remove(int arg)
247 struct crypt_options options = {
248 .name = action_argv[0],
252 return crypt_remove_device(&options);
255 static int action_resize(int arg)
257 struct crypt_options options = {
258 .name = action_argv[0],
263 return crypt_resize_device(&options);
266 static int action_status(int arg)
268 struct crypt_options options = {
269 .name = action_argv[0],
274 r = crypt_query_device(&options);
280 log_std("%s/%s is inactive.\n", crypt_get_dir(), options.name);
284 log_std("%s/%s is active:\n", crypt_get_dir(), options.name);
285 log_std(" cipher: %s\n", options.cipher);
286 log_std(" keysize: %d bits\n", options.key_size * 8);
287 log_std(" device: %s\n", options.device ?: "");
288 log_std(" offset: %" PRIu64 " sectors\n", options.offset);
289 log_std(" size: %" PRIu64 " sectors\n", options.size);
291 log_std(" skipped: %" PRIu64 " sectors\n", options.skip);
292 log_std(" mode: %s\n", (options.flags & CRYPT_FLAG_READONLY)
293 ? "readonly" : "read/write");
294 crypt_put_options(&options);
300 static int _read_mk(const char *file, char **key, int keysize)
304 *key = crypt_safe_alloc(keysize);
308 fd = open(file, O_RDONLY);
310 log_err("Cannot read keyfile %s.\n", file);
313 if ((read(fd, *key, keysize) != keysize)) {
314 log_err("Cannot read %d bytes from keyfile %s.\n", keysize, file);
316 crypt_safe_free(*key);
323 static int action_luksFormat(int arg)
325 int r = -EINVAL, keysize;
326 char *msg = NULL, *key = NULL, cipher [MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN];
327 const char *key_file = NULL;
328 char *password = NULL;
329 unsigned int passwordLen;
330 struct crypt_device *cd = NULL;
331 struct crypt_params_luks1 params = {
332 .hash = opt_hash ?: DEFAULT_LUKS1_HASH,
333 .data_alignment = opt_align_payload,
336 /* Avoid overwriting possibly wrong part of device than user requested by rejecting these options */
337 if (opt_offset || opt_skip) {
338 log_err("Options --offset and --skip are not supported for luksFormat.\n");
343 if (action_argc > 1) {
344 key_file = action_argv[1];
346 log_err(_("Option --key-file takes precedence over specified key file argument.\n"));
348 key_file = opt_key_file;
350 if(asprintf(&msg, _("This will overwrite data on %s irrevocably."), action_argv[0]) == -1) {
351 log_err(_("memory allocation error in action_luksFormat"));
363 r = crypt_parse_name_and_mode(opt_cipher ?: DEFAULT_CIPHER(LUKS1),
364 cipher, cipher_mode);
366 log_err("No known cipher specification pattern detected.\n");
370 if ((r = crypt_init(&cd, action_argv[0])))
373 crypt_set_log_callback(cd, _log, NULL);
375 keysize = (opt_key_size ?: DEFAULT_LUKS1_KEYBITS) / 8;
377 crypt_set_password_verify(cd, 1);
378 crypt_set_timeout(cd, opt_timeout);
379 if (opt_iteration_time)
380 crypt_set_iterarion_time(cd, opt_iteration_time);
383 crypt_set_rng_type(cd, CRYPT_RNG_RANDOM);
384 else if (opt_urandom)
385 crypt_set_rng_type(cd, CRYPT_RNG_URANDOM);
387 if (opt_master_key_file) {
388 r = _read_mk(opt_master_key_file, &key, keysize);
392 r = crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode,
393 NULL, key, keysize, ¶ms);
397 r = crypt_keyslot_add_by_volume_key(cd, opt_key_slot,
398 key, keysize, NULL, 0);
400 crypt_get_key(_("Enter LUKS passphrase: "),
401 &password, &passwordLen, 0,
402 key_file, opt_timeout,
403 opt_verify_passphrase && !opt_batch_mode,
411 r = crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode,
412 NULL, NULL, keysize, ¶ms);
416 /* Add keyslot using internally stored volume key generated during format */
417 r = crypt_keyslot_add_by_volume_key(cd, opt_key_slot,
418 NULL, 0, password, passwordLen);
422 crypt_safe_free(key);
423 crypt_safe_free(password);
425 return (r < 0) ? r : 0;
428 static int action_luksOpen(int arg)
430 struct crypt_device *cd = NULL;
434 if ((r = crypt_init(&cd, action_argv[0])))
437 crypt_set_log_callback(cd, _log, NULL);
439 if ((r = crypt_load(cd, CRYPT_LUKS1, NULL)))
442 crypt_set_timeout(cd, opt_timeout);
443 crypt_set_password_retry(cd, opt_tries);
445 if (opt_iteration_time)
446 crypt_set_iterarion_time(cd, opt_iteration_time);
448 flags |= CRYPT_ACTIVATE_READONLY;
450 if (opt_non_exclusive)
451 log_err(_("Obsolete option --non-exclusive is ignored.\n"));
454 crypt_set_password_retry(cd, 1);
455 /* limit bytes read from keyfile using opt_key_size*/
456 r = crypt_activate_by_keyfile(cd, action_argv[1],
457 CRYPT_ANY_SLOT, opt_key_file, opt_key_size / 8,
460 r = crypt_activate_by_passphrase(cd, action_argv[1],
461 CRYPT_ANY_SLOT, NULL, 0, flags);
464 return (r < 0) ? r : 0;
467 /* FIXME: keyslot operation needs better get_key() implementation. Use old API for now */
468 static int action_luksDelKey(int arg)
470 log_err("luksDelKey is a deprecated action name.\nPlease use luksKillSlot.\n");
471 return action_luksKillSlot(arg);
474 static int action_luksKillSlot(int arg)
476 struct crypt_options options = {
477 .device = action_argv[0],
478 .key_slot = atoi(action_argv[1]),
479 .key_file = opt_key_file,
480 .timeout = opt_timeout,
481 .flags = !opt_batch_mode?CRYPT_FLAG_VERIFY_ON_DELKEY : 0,
485 return crypt_luksKillSlot(&options);
488 static int action_luksRemoveKey(int arg)
490 struct crypt_options options = {
491 .device = action_argv[0],
492 .new_key_file = action_argc>1?action_argv[1]:NULL,
493 .key_file = opt_key_file,
494 .timeout = opt_timeout,
495 .flags = !opt_batch_mode?CRYPT_FLAG_VERIFY_ON_DELKEY : 0,
499 return crypt_luksRemoveKey(&options);
502 static int action_luksAddKey(int arg)
504 int r = -EINVAL, keysize = 0;
506 const char *opt_new_key_file = (action_argc > 1 ? action_argv[1] : NULL);
507 struct crypt_device *cd = NULL;
509 if ((r = crypt_init(&cd, action_argv[0])))
512 crypt_set_log_callback(cd, _log, NULL);
513 crypt_set_confirm_callback(cd, _yesDialog, NULL);
515 if ((r = crypt_load(cd, CRYPT_LUKS1, NULL)))
518 keysize = crypt_get_volume_key_size(cd);
519 crypt_set_password_verify(cd, opt_verify_passphrase ? 1 : 0);
520 crypt_set_timeout(cd, opt_timeout);
521 if (opt_iteration_time)
522 crypt_set_iterarion_time(cd, opt_iteration_time);
524 if (opt_master_key_file) {
525 if (_read_mk(opt_master_key_file, &key, keysize) < 0)
528 r = crypt_keyslot_add_by_volume_key(cd, opt_key_slot,
529 key, keysize, NULL, 0);
530 } else if (opt_key_file || opt_new_key_file) {
531 r = crypt_keyslot_add_by_keyfile(cd, opt_key_slot,
533 opt_new_key_file, 0);
535 r = crypt_keyslot_add_by_passphrase(cd, opt_key_slot,
540 crypt_safe_free(key);
542 return (r < 0) ? r : 0;
545 static int action_isLuks(int arg)
547 struct crypt_options options = {
548 .device = action_argv[0],
552 return crypt_isLuks(&options);
555 static int action_luksUUID(int arg)
557 struct crypt_options options = {
558 .device = action_argv[0],
562 return crypt_luksUUID(&options);
565 static int action_luksDump(int arg)
567 struct crypt_options options = {
568 .device = action_argv[0],
572 return crypt_luksDump(&options);
575 static int action_luksSuspend(int arg)
577 struct crypt_device *cd = NULL;
580 r = crypt_init_by_name(&cd, action_argv[0]);
582 r = crypt_suspend(cd, action_argv[0]);
588 static int action_luksResume(int arg)
590 struct crypt_device *cd = NULL;
593 if ((r = crypt_init_by_name(&cd, action_argv[0])))
596 if ((r = crypt_load(cd, CRYPT_LUKS1, NULL)))
600 r = crypt_resume_by_keyfile(cd, action_argv[0], CRYPT_ANY_SLOT,
601 opt_key_file, opt_key_size / 8);
603 r = crypt_resume_by_passphrase(cd, action_argv[0], CRYPT_ANY_SLOT,
610 static int action_luksBackup(int arg)
612 struct crypt_device *cd = NULL;
615 if (!opt_header_backup_file) {
616 log_err(_("Option --header-backup-file is required.\n"));
620 if ((r = crypt_init(&cd, action_argv[0])))
623 crypt_set_log_callback(cd, _log, NULL);
624 crypt_set_confirm_callback(cd, _yesDialog, NULL);
626 r = crypt_header_backup(cd, CRYPT_LUKS1, opt_header_backup_file);
632 static int action_luksRestore(int arg)
634 struct crypt_device *cd = NULL;
637 if (!opt_header_backup_file) {
638 log_err(_("Option --header-backup-file is required.\n"));
642 if ((r = crypt_init(&cd, action_argv[0])))
645 crypt_set_log_callback(cd, _log, NULL);
646 crypt_set_confirm_callback(cd, _yesDialog, NULL);
647 r = crypt_header_restore(cd, CRYPT_LUKS1, opt_header_backup_file);
653 static void usage(poptContext popt_context, int exitcode,
654 const char *error, const char *more)
656 poptPrintUsage(popt_context, stderr, 0);
658 log_err("%s: %s\n", more, error);
662 static void help(poptContext popt_context, enum poptCallbackReason reason,
663 struct poptOption *key, const char * arg, void *data)
665 if (key->shortName == '?') {
666 struct action_type *action;
668 log_std("%s\n",PACKAGE_STRING);
670 poptPrintHelp(popt_context, stdout, 0);
673 "<action> is one of:\n"));
675 for(action = action_types; action->type; action++)
676 log_std("\t%s %s - %s\n", action->type, _(action->arg_desc), _(action->desc));
679 "<name> is the device to create under %s\n"
680 "<device> is the encrypted device\n"
681 "<key slot> is the LUKS key slot number to modify\n"
682 "<key file> optional key file for the new key for luksAddKey action\n"),
685 log_std(_("\nDefault compiled-in device cipher parameters:\n"
686 "\tplain: %s, Key: %d bits, Password hashing: %s\n"
687 "\tLUKS1: %s, Key: %d bits, LUKS header hashing: %s, RNG: %s\n"),
688 DEFAULT_CIPHER(PLAIN), DEFAULT_PLAIN_KEYBITS, DEFAULT_PLAIN_HASH,
689 DEFAULT_CIPHER(LUKS1), DEFAULT_LUKS1_KEYBITS, DEFAULT_LUKS1_HASH,
693 usage(popt_context, 0, NULL, NULL);
696 void set_debug_level(int level);
698 static void _dbg_version_and_cmd(int argc, char **argv)
702 log_std("# %s %s processing \"", PACKAGE_NAME, PACKAGE_VERSION);
703 for (i = 0; i < argc; i++) {
711 static int run_action(struct action_type *action)
715 if (action->required_memlock)
716 crypt_memory_lock(NULL, 1);
718 r = action->handler(action->arg);
720 if (action->required_memlock)
721 crypt_memory_lock(NULL, 0);
728 int main(int argc, char **argv)
730 static char *popt_tmp;
731 static struct poptOption popt_help_options[] = {
732 { NULL, '\0', POPT_ARG_CALLBACK, help, 0, NULL, NULL },
733 { "help", '?', POPT_ARG_NONE, NULL, 0, N_("Show this help message"), NULL },
734 { "usage", '\0', POPT_ARG_NONE, NULL, 0, N_("Display brief usage"), NULL },
737 static struct poptOption popt_options[] = {
738 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, popt_help_options, 0, N_("Help options:"), NULL },
739 { "verbose", 'v', POPT_ARG_NONE, &opt_verbose, 0, N_("Shows more detailed error messages"), NULL },
740 { "debug", '\0', POPT_ARG_NONE, &opt_debug, 0, N_("Show debug messages"), NULL },
741 { "cipher", 'c', POPT_ARG_STRING, &opt_cipher, 0, N_("The cipher used to encrypt the disk (see /proc/crypto)"), NULL },
742 { "hash", 'h', POPT_ARG_STRING, &opt_hash, 0, N_("The hash used to create the encryption key from the passphrase"), NULL },
743 { "verify-passphrase", 'y', POPT_ARG_NONE, &opt_verify_passphrase, 0, N_("Verifies the passphrase by asking for it twice"), NULL },
744 { "key-file", 'd', POPT_ARG_STRING, &opt_key_file, 0, N_("Read the key from a file (can be /dev/random)"), NULL },
745 { "master-key-file", '\0', POPT_ARG_STRING, &opt_master_key_file, 0, N_("Read the volume (master) key from file."), NULL },
746 { "key-size", 's', POPT_ARG_INT, &opt_key_size, 0, N_("The size of the encryption key"), N_("BITS") },
747 { "key-slot", 'S', POPT_ARG_INT, &opt_key_slot, 0, N_("Slot number for new key (default is first free)"), NULL },
748 { "size", 'b', POPT_ARG_STRING, &popt_tmp, 1, N_("The size of the device"), N_("SECTORS") },
749 { "offset", 'o', POPT_ARG_STRING, &popt_tmp, 2, N_("The start offset in the backend device"), N_("SECTORS") },
750 { "skip", 'p', POPT_ARG_STRING, &popt_tmp, 3, N_("How many sectors of the encrypted data to skip at the beginning"), N_("SECTORS") },
751 { "readonly", 'r', POPT_ARG_NONE, &opt_readonly, 0, N_("Create a readonly mapping"), NULL },
752 { "iter-time", 'i', POPT_ARG_INT, &opt_iteration_time, 0, N_("PBKDF2 iteration time for LUKS (in ms)"), N_("msecs") },
753 { "batch-mode", 'q', POPT_ARG_NONE, &opt_batch_mode, 0, N_("Do not ask for confirmation"), NULL },
754 { "version", '\0', POPT_ARG_NONE, &opt_version_mode, 0, N_("Print package version"), NULL },
755 { "timeout", 't', POPT_ARG_INT, &opt_timeout, 0, N_("Timeout for interactive passphrase prompt (in seconds)"), N_("secs") },
756 { "tries", 'T', POPT_ARG_INT, &opt_tries, 0, N_("How often the input of the passphrase can be retried"), NULL },
757 { "align-payload", '\0', POPT_ARG_INT, &opt_align_payload, 0, N_("Align payload at <n> sector boundaries - for luksFormat"), N_("SECTORS") },
758 { "non-exclusive", '\0', POPT_ARG_NONE, &opt_non_exclusive, 0, N_("(Obsoleted, see man page.)"), NULL },
759 { "header-backup-file",'\0', POPT_ARG_STRING, &opt_header_backup_file, 0, N_("File with LUKS header and keyslots backup."), NULL },
760 { "use-random", '\0', POPT_ARG_NONE, &opt_random, 0, N_("Use /dev/random for generating volume key."), NULL },
761 { "use-urandom", '\0', POPT_ARG_NONE, &opt_urandom, 0, N_("Use /dev/urandom for generating volume key."), NULL },
764 poptContext popt_context;
765 struct action_type *action;
768 const char *null_action_argv[] = {NULL};
770 crypt_set_log_callback(NULL, _log, NULL);
772 setlocale(LC_ALL, "");
773 bindtextdomain(PACKAGE, LOCALEDIR);
776 popt_context = poptGetContext(PACKAGE, argc, (const char **)argv,
778 poptSetOtherOptionHelp(popt_context,
779 N_("[OPTION...] <action> <action-specific>]"));
781 while((r = poptGetNextOpt(popt_context)) > 0) {
782 unsigned long long ull_value;
785 ull_value = strtoull(popt_tmp, &endp, 0);
786 if (*endp || !*popt_tmp)
787 r = POPT_ERROR_BADNUMBER;
791 opt_size = ull_value;
794 opt_offset = ull_value;
797 opt_skip = ull_value;
806 usage(popt_context, 1, poptStrerror(r),
807 poptBadOption(popt_context, POPT_BADOPTION_NOALIAS));
808 if (opt_version_mode) {
809 log_std("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
813 if (opt_key_size % 8)
814 usage(popt_context, 1,
815 _("Key size must be a multiple of 8 bits"),
816 poptGetInvocationName(popt_context));
818 /* FIXME: use per format define here */
819 if (opt_key_slot != CRYPT_ANY_SLOT &&
820 (opt_key_slot < 0 || opt_key_slot > 8)) {
821 usage(popt_context, 1, _("Key slot is invalid."),
822 poptGetInvocationName(popt_context));
825 if (!(aname = (char *)poptGetArg(popt_context)))
826 usage(popt_context, 1, _("Argument <action> missing."),
827 poptGetInvocationName(popt_context));
828 for(action = action_types; action->type; action++)
829 if (strcmp(action->type, aname) == 0)
832 usage(popt_context, 1, _("Unknown action."),
833 poptGetInvocationName(popt_context));
835 if (opt_random && opt_urandom)
836 usage(popt_context, 1, _("Only one of --use-[u]random options is allowed."),
837 poptGetInvocationName(popt_context));
838 if ((opt_random || opt_urandom) && strcmp(aname, "luksFormat"))
839 usage(popt_context, 1, _("Option --use-[u]random is allowed only for luksFormat."),
840 poptGetInvocationName(popt_context));
843 action_argv = poptGetArgs(popt_context);
844 /* Make return values of poptGetArgs more consistent in case of remaining argc = 0 */
846 action_argv = null_action_argv;
848 /* Count args, somewhat unnice, change? */
849 while(action_argv[action_argc] != NULL)
852 if(action_argc < action->required_action_argc) {
854 snprintf(buf, 128,_("%s: requires %s as arguments"), action->type, action->arg_desc);
855 usage(popt_context, 1, buf,
856 poptGetInvocationName(popt_context));
861 crypt_set_debug_level(-1);
862 _dbg_version_and_cmd(argc, argv);
865 return run_action(action);