zkey: Add batch-mode option to zkey-cryptsetup tool

When re-enciphering or setting LUKS2 volume keys using zkey-cryptsetup,
allow to specify the --batch-mode|-q option to suppress confirmation
questions.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Ingo Franzki
2019-03-19 11:04:37 +01:00
committed by Jan Höppner
parent 11bfa1d3c8
commit e693173eef
2 changed files with 28 additions and 0 deletions
+20
View File
@@ -98,6 +98,7 @@ static struct zkey_cryptsetup_globals {
bool inplace;
bool staged;
char *master_key_file;
bool batch_mode;
bool debug;
bool verbose;
void *lib_csulcca;
@@ -181,6 +182,11 @@ static struct util_opt opt_vec[] = {
.command = COMMAND_REENCIPHER,
},
OPT_PASSPHRASE_ENTRY(COMMAND_REENCIPHER),
{
.option = {"batch-mode", 0, NULL, 'q'},
.desc = "Suppresses all confirmation questions. Use with care!",
.command = COMMAND_REENCIPHER,
},
/***********************************************************/
{
.flags = UTIL_OPT_FLAG_SECTION,
@@ -209,6 +215,11 @@ static struct util_opt opt_vec[] = {
.command = COMMAND_SETKEY,
},
OPT_PASSPHRASE_ENTRY(COMMAND_SETKEY),
{
.option = {"batch-mode", 0, NULL, 'q'},
.desc = "Suppresses all confirmation questions. Use with care!",
.command = COMMAND_SETKEY,
},
/***********************************************************/
{
.flags = UTIL_OPT_FLAG_SECTION,
@@ -1173,6 +1184,12 @@ static bool prompt_for_yes(void)
{
char str[20];
if (g.batch_mode) {
printf("(yes implied because '--batch-mode' | '-q' option is "
"specified)\n");
return true;
}
if (fgets(str, sizeof(str), stdin) == NULL)
return false;
@@ -2236,6 +2253,9 @@ int main(int argc, char *argv[])
case 'm':
g.master_key_file = optarg;
break;
case 'q':
g.batch_mode = true;
break;
case 'D':
g.debug = true;
g.verbose = true;