diff --git a/zkey/keystore.c b/zkey/keystore.c index 26c1a76d..bffa180e 100644 --- a/zkey/keystore.c +++ b/zkey/keystore.c @@ -3242,6 +3242,7 @@ static int _keystore_execute_cmd(const char *cmd, struct crypt_info { bool execute; + bool batch_mode; const char *keyfile; size_t keyfile_offset; size_t keyfile_size; @@ -3318,8 +3319,9 @@ static int _keystore_process_cryptsetup(struct keystore *keystore, if (strcasecmp(volume_type, VOLUME_TYPE_PLAIN) == 0) { util_asprintf(&cmd, - "cryptsetup plainOpen %s--key-file '%s' " + "cryptsetup plainOpen %s%s--key-file '%s' " "--key-size %lu --cipher %s %s%s %s", + info->batch_mode ? "-q " : "", keystore->verbose ? "-v " : "", key_file_name, key_file_size * 8, cipher_spec, sector_size > 0 ? temp : "", volume, dmname); @@ -3338,9 +3340,10 @@ static int _keystore_process_cryptsetup(struct keystore *keystore, * automatically via /etc/crypttab */ util_asprintf(&cmd, - "cryptsetup luksFormat %s--type luks2 " + "cryptsetup luksFormat %s%s--type luks2 " "--master-key-file '%s' --key-size %lu " "--cipher %s --pbkdf pbkdf2 %s%s%s", + info->batch_mode ? "-q " : "", keystore->verbose ? "-v " : "", key_file_name, key_file_size * 8, cipher_spec, common_len > 0 ? common_passphrase_options : "", @@ -3615,12 +3618,13 @@ out: * @param[in] keyfile_offset the offset in bytes for reading from keyfile * @param[in] keyfile_size the size in bytes for reading from keyfile * @param[in] tries the number of tries for passphrase entry + * @param[in] batch_mode If TRUE, suppress cryptsetup confirmation questions * @returns 0 for success or a negative errno in case of an error */ int keystore_cryptsetup(struct keystore *keystore, const char *volume_filter, bool execute, const char *volume_type, const char *keyfile, size_t keyfile_offset, - size_t keyfile_size, size_t tries) + size_t keyfile_size, size_t tries, bool batch_mode) { struct crypt_info info = { 0 }; int rc; @@ -3637,6 +3641,7 @@ int keystore_cryptsetup(struct keystore *keystore, const char *volume_filter, } info.execute = execute; + info.batch_mode = batch_mode; info.keyfile = keyfile; info.keyfile_offset = keyfile_offset; info.keyfile_size = keyfile_size; diff --git a/zkey/keystore.h b/zkey/keystore.h index 80f37a32..b0d35e48 100644 --- a/zkey/keystore.h +++ b/zkey/keystore.h @@ -70,7 +70,7 @@ int keystore_list_keys(struct keystore *keystore, const char *name_filter, int keystore_cryptsetup(struct keystore *keystore, const char *volume_filter, bool execute, const char *volume_type, const char *keyfile, size_t keyfile_offset, - size_t keyfile_size, size_t tries); + size_t keyfile_size, size_t tries, bool batch_mode); int keystore_crypttab(struct keystore *keystore, const char *volume_filter, const char *volume_type); diff --git a/zkey/zkey.1 b/zkey/zkey.1 index 76ffd120..d61affcc 100644 --- a/zkey/zkey.1 +++ b/zkey/zkey.1 @@ -600,8 +600,11 @@ and to control which part of the key file is used as passphrase. These options are only available if .B zkey -has been compiled with LUKS2 support enabled. These options are passed to the -generated command(s) and behave in the same way as with \fBcryptsetup\fP. +has been compiled with LUKS2 support enabled. To avoid cryptsetup confirmation +questions, you can specify the +.B \-\-batch\-mode +option. These options are passed to the generated command(s) and behave in the +same way as with \fBcryptsetup\fP. . . . @@ -1018,6 +1021,10 @@ This option is passed to the generated command(s) for LUKS2 volumes, and is only available if .B zkey has been compiled with LUKS2 support enabled. +.TP +.BR \-q ", " \-\-batch\-mode +Suppress cryptsetup confirmation questions. This option is passed to the generated +cryptsetup command(s). . . . diff --git a/zkey/zkey.c b/zkey/zkey.c index b71a323f..6edb7f9f 100644 --- a/zkey/zkey.c +++ b/zkey/zkey.c @@ -71,6 +71,7 @@ static struct zkey_globals { char *volume_type; char *newname; bool run; + bool batch_mode; char *keyfile; long long keyfile_offset; long long keyfile_size; @@ -636,6 +637,13 @@ static struct util_opt opt_vec[] = { .flags = UTIL_OPT_FLAG_NOSHORT, }, #endif + { + .option = {"batch-mode", 0, NULL, 'q'}, + .desc = "Suppresses cryptsetup confirmation questions. " + "This option is passed to the generated cryptsetup " + "command(s)", + .command = COMMAND_CRYPTSETUP, + }, /***********************************************************/ { .flags = UTIL_OPT_FLAG_SECTION, @@ -1436,7 +1444,7 @@ static int command_cryptsetup(void) rc = keystore_cryptsetup(g.keystore, g.volumes, g.run, g.volume_type, g.keyfile, g.keyfile_offset, g.keyfile_size, - g.tries); + g.tries, g.batch_mode); return rc != 0 ? EXIT_FAILURE : EXIT_SUCCESS; } @@ -1669,6 +1677,9 @@ int main(int argc, char *argv[]) } break; #endif + case 'q': + g.batch_mode = 1; + break; case 'h': print_help(command); return EXIT_SUCCESS;