[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 3/7] cryptodisk: Improve error messaging in cryptomount invoca
From: |
Glenn Washburn |
Subject: |
[PATCH v4 3/7] cryptodisk: Improve error messaging in cryptomount invocations |
Date: |
Sat, 4 Dec 2021 01:15:46 -0600 |
Update such that "cryptomount -u UUID" will not print two error messages
when an invalid passphrase is given and the most relevant error message
will be displayed.
Improve error message which is displayed when a UUID is specified, but no
cryptodisk backends find a disk with that UUID.
Also, make cryptomount return failure when no cryptodisk modules are loaded,
which allows an error to be displayed notifying the user that they'll want
to load a backend module to make cryptomount useful.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/disk/cryptodisk.c | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index 9224105ac..aa086837d 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -1100,11 +1100,15 @@ grub_cryptodisk_scan_device (const char *name,
grub_disk_close (source);
- /*
- * Do not print error when err is GRUB_ERR_BAD_MODULE to avoid many unhelpful
- * error messages.
- */
- if (err != GRUB_ERR_NONE && err != GRUB_ERR_EXISTS && err !=
GRUB_ERR_BAD_MODULE)
+ if (err == GRUB_ERR_NONE || err == GRUB_ERR_EXISTS)
+ ; /* Success, skip the error handling */
+ else if (err == GRUB_ERR_BAD_MODULE)
+ /* Do nothing to avoid printing unhelpful error messages */
+ grub_errno = GRUB_ERR_NONE;
+ else if (cargs->search_uuid != NULL)
+ /* Push error onto stack to save for cryptomount */
+ grub_error_push();
+ else
grub_print_error ();
return (err == GRUB_ERR_NONE && search_uuid != NULL);
}
@@ -1117,6 +1121,9 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int
argc, char **args)
if (argc < 1 && !state[1].set && !state[2].set)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
+ if (grub_cryptodisk_list == NULL)
+ return grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk modules loaded");
+
if (state[0].set)
{
int found_uuid;
@@ -1135,9 +1142,19 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int
argc, char **args)
found_uuid = grub_device_iterate (&grub_cryptodisk_scan_device, NULL);
search_uuid = NULL;
- if (!found_uuid)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk found");
- return GRUB_ERR_NONE;
+ if (found_uuid)
+ return GRUB_ERR_NONE;
+ else if (grub_errno == GRUB_ERR_NONE)
+ {
+ /*
+ * Try to pop the next error on the stack. If there is not one, then
+ * no device matched the given UUID.
+ */
+ grub_error_pop();
+ if (grub_errno == GRUB_ERR_NONE)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk
found, perhaps a needed disk or cryptodisk module is not loaded");
+ }
+ return grub_errno;
}
else if (state[1].set || (argc == 0 && state[2].set))
{
--
2.27.0
[PATCH v4 4/7] cryptodisk: Add infrastructure to pass data from cryptomount to cryptodisk modules, Glenn Washburn, 2021/12/04
[PATCH v4 5/7] cryptodisk: Refactor password input out of crypto dev modules into cryptodisk, Glenn Washburn, 2021/12/04
[PATCH v4 6/7] cryptodisk: Move global variables into grub_cryptomount_args struct, Glenn Washburn, 2021/12/04