cryptsetup: Print message about operation aborted if user did not answer YES.

Thanks Colin Walters for the initial idea in !33.
This commit is contained in:
Milan Broz
2018-01-24 10:08:44 +01:00
parent 8728ba08e2
commit 4e5e8fd8fe
2 changed files with 18 additions and 12 deletions

View File

@@ -884,7 +884,7 @@ static int action_luksRepair(void)
} }
r = yesDialog(_("Really try to repair LUKS device header?"), r = yesDialog(_("Really try to repair LUKS device header?"),
NULL) ? 0 : -EINVAL; _("Operation aborted.\n")) ? 0 : -EINVAL;
if (r == 0) if (r == 0)
r = crypt_repair(cd, luksType(opt_type), NULL); r = crypt_repair(cd, luksType(opt_type), NULL);
out: out:
@@ -964,7 +964,8 @@ static int action_luksFormat(void)
/* Create header file (must contain at least one sector)? */ /* Create header file (must contain at least one sector)? */
if (opt_header_device && stat(opt_header_device, &st) < 0 && errno == ENOENT) { if (opt_header_device && stat(opt_header_device, &st) < 0 && errno == ENOENT) {
if (!opt_batch_mode && if (!opt_batch_mode &&
!yesDialog("Header file does not exist, do you want to create it?", NULL)) !yesDialog("Header file does not exist, do you want to create it?",
_("Operation aborted.\n")))
return -EPERM; return -EPERM;
log_dbg("Creating header file."); log_dbg("Creating header file.");
@@ -987,7 +988,7 @@ static int action_luksFormat(void)
r = -ENOMEM; r = -ENOMEM;
goto out; goto out;
} }
r = yesDialog(msg, NULL) ? 0 : -EINVAL; r = yesDialog(msg, _("Operation aborted.\n")) ? 0 : -EINVAL;
free(msg); free(msg);
if (r < 0) if (r < 0)
goto out; goto out;
@@ -1149,7 +1150,7 @@ out:
} }
static int verify_keyslot(struct crypt_device *cd, int key_slot, static int verify_keyslot(struct crypt_device *cd, int key_slot,
char *msg_last, char *msg_pass, char *msg_last, char *msg_pass, char *msg_fail,
const char *key_file, uint64_t keyfile_offset, const char *key_file, uint64_t keyfile_offset,
int keyfile_size) int keyfile_size)
{ {
@@ -1160,7 +1161,7 @@ static int verify_keyslot(struct crypt_device *cd, int key_slot,
ki = crypt_keyslot_status(cd, key_slot); ki = crypt_keyslot_status(cd, key_slot);
if (ki == CRYPT_SLOT_ACTIVE_LAST && !opt_batch_mode && !key_file && if (ki == CRYPT_SLOT_ACTIVE_LAST && !opt_batch_mode && !key_file &&
msg_last && !yesDialog(msg_last, NULL)) msg_last && !yesDialog(msg_last, msg_fail))
return -EPERM; return -EPERM;
r = tools_get_key(msg_pass, &password, &passwordLen, r = tools_get_key(msg_pass, &password, &passwordLen,
@@ -1220,6 +1221,7 @@ static int action_luksKillSlot(void)
r = verify_keyslot(cd, opt_key_slot, r = verify_keyslot(cd, opt_key_slot,
_("This is the last keyslot. Device will become unusable after purging this key."), _("This is the last keyslot. Device will become unusable after purging this key."),
_("Enter any remaining passphrase: "), _("Enter any remaining passphrase: "),
_("Operation aborted, the keyslot was NOT wiped.\n"),
opt_key_file, opt_keyfile_offset, opt_keyfile_size); opt_key_file, opt_keyfile_offset, opt_keyfile_size);
if (r == -EPIPE && (!opt_key_file || tools_is_stdin(opt_key_file))) { if (r == -EPIPE && (!opt_key_file || tools_is_stdin(opt_key_file))) {
@@ -1273,7 +1275,7 @@ static int action_luksRemoveKey(void)
if (crypt_keyslot_status(cd, opt_key_slot) == CRYPT_SLOT_ACTIVE_LAST && if (crypt_keyslot_status(cd, opt_key_slot) == CRYPT_SLOT_ACTIVE_LAST &&
!yesDialog(_("This is the last keyslot. " !yesDialog(_("This is the last keyslot. "
"Device will become unusable after purging this key."), "Device will become unusable after purging this key."),
NULL)) { _("Operation aborted, the keyslot was NOT wiped.\n"))) {
r = -EPERM; r = -EPERM;
goto out; goto out;
} }
@@ -1458,7 +1460,7 @@ static int action_luksUUID(void)
if ((r = crypt_init(&cd, uuid_or_device_header(NULL)))) if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
goto out; goto out;
crypt_set_confirm_callback(cd, yesDialog, NULL); crypt_set_confirm_callback(cd, yesDialog, _("Operation aborted.\n"));
if ((r = crypt_load(cd, luksType(opt_type), NULL))) if ((r = crypt_load(cd, luksType(opt_type), NULL)))
goto out; goto out;
@@ -1691,7 +1693,7 @@ static int action_luksErase(void)
goto out; goto out;
} }
if (!yesDialog(msg, NULL)) { if (!yesDialog(msg, _("Operation aborted, keyslots were NOT wiped.\n"))) {
r = -EPERM; r = -EPERM;
goto out; goto out;
} }
@@ -1754,7 +1756,7 @@ static int action_luksConvert(void)
return -ENOMEM; return -ENOMEM;
} }
if (yesDialog(msg, NULL)) if (yesDialog(msg, _("Operation aborted, device was NOT converted.\n")))
r = crypt_convert(cd, to_type, NULL); r = crypt_convert(cd, to_type, NULL);
else else
r = -EPERM; r = -EPERM;

View File

@@ -132,8 +132,9 @@ void quiet_log(int level, const char *msg, void *usrptr)
tool_log(level, msg, usrptr); tool_log(level, msg, usrptr);
} }
int yesDialog(const char *msg, void *usrptr __attribute__((unused))) int yesDialog(const char *msg, void *usrptr)
{ {
const char *fail_msg = (const char *)usrptr;
char *answer = NULL; char *answer = NULL;
size_t size = 0; size_t size = 0;
int r = 1, block; int r = 1, block;
@@ -142,7 +143,7 @@ int yesDialog(const char *msg, void *usrptr __attribute__((unused)))
if (block) if (block)
set_int_block(0); set_int_block(0);
if(isatty(STDIN_FILENO) && !opt_batch_mode) { if (isatty(STDIN_FILENO) && !opt_batch_mode) {
log_std("\nWARNING!\n========\n"); log_std("\nWARNING!\n========\n");
log_std("%s\n\nAre you sure? (Type uppercase yes): ", msg); log_std("%s\n\nAre you sure? (Type uppercase yes): ", msg);
fflush(stdout); fflush(stdout);
@@ -153,8 +154,11 @@ int yesDialog(const char *msg, void *usrptr __attribute__((unused)))
log_err(_("Error reading response from terminal.\n")); log_err(_("Error reading response from terminal.\n"));
else else
log_dbg("Query interrupted on signal."); log_dbg("Query interrupted on signal.");
} else if(strcmp(answer, "YES\n")) } else if (strcmp(answer, "YES\n")) {
r = 0; r = 0;
if (fail_msg)
log_err("%s", fail_msg);
}
} }
if (block && !quit) if (block && !quit)