1f092ca
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
1f092ca
From: Javier Martinez Canillas <javierm@redhat.com>
1f092ca
Date: Mon, 26 Nov 2018 10:06:42 +0100
1f092ca
Subject: [PATCH] Make the menu entry users option argument to be optional
1f092ca
1f092ca
The --users option is used to restrict the access to specific menu entries
1f092ca
only to a set of users. But the option requires an argument to either be a
1f092ca
constant or a variable that has been set. So for example the following:
1f092ca
1f092ca
  menuentry "May be run by superusers or users in $users" --users $users {
1f092ca
  	    linux /vmlinuz
1f092ca
  }
1f092ca
1f092ca
Would fail if $users is not defined and grub would discard the menu entry.
1f092ca
Instead, allow the --users option to have an optional argument and ignore
1f092ca
the option if the argument was not set.
1f092ca
1f092ca
Related: rhbz#1652434
1f092ca
1f092ca
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
1f092ca
---
1f092ca
 grub-core/commands/menuentry.c | 4 ++--
1f092ca
 1 file changed, 2 insertions(+), 2 deletions(-)
1f092ca
1f092ca
diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c
1f092ca
index 8d242b0187e..7004e08ce78 100644
1f092ca
--- a/grub-core/commands/menuentry.c
1f092ca
+++ b/grub-core/commands/menuentry.c
1f092ca
@@ -29,7 +29,7 @@ static const struct grub_arg_option options[] =
1f092ca
   {
1f092ca
     {"class", 1, GRUB_ARG_OPTION_REPEATABLE,
1f092ca
      N_("Menu entry type."), N_("STRING"), ARG_TYPE_STRING},
1f092ca
-    {"users", 2, 0,
1f092ca
+    {"users", 2, GRUB_ARG_OPTION_OPTIONAL,
1f092ca
      N_("List of users allowed to boot this entry."), N_("USERNAME[,USERNAME]"),
1f092ca
      ARG_TYPE_STRING},
1f092ca
     {"hotkey", 3, 0,
1f092ca
@@ -280,7 +280,7 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
1f092ca
   if (! ctxt->state[3].set && ! ctxt->script)
1f092ca
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "no menuentry definition");
1f092ca
 
1f092ca
-  if (ctxt->state[1].set)
1f092ca
+  if (ctxt->state[1].set && ctxt->state[1].arg)
1f092ca
     users = ctxt->state[1].arg;
1f092ca
   else if (ctxt->state[5].set)
1f092ca
     users = NULL;