Blame SOURCES/0126-Make-the-menu-entry-users-option-argument-to-be-opti.patch

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