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