mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zkey: Add batch-mode option to cryptsetup command
When generating cryptsetup commands, allow to specify the --batch-mode|-q option and pass it to the generated commands. Closes: https://github.com/ibm-s390-tools/s390-tools/pull/59 Fixes: https://github.com/ibm-s390-tools/s390-tools/issues/58 Suggested-by: Dimitri John Ledkov <xnox@ubuntu.com> Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
b0c7965234
commit
5a0c93443c
+8
-3
@@ -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;
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+9
-2
@@ -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).
|
||||
.
|
||||
.
|
||||
.
|
||||
|
||||
+12
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user