nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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