Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gSBw1-0005Ad-Ld for mharc-grub-devel@gnu.org; Wed, 28 Nov 2018 21:20:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gS9Zb-0003pb-A2 for grub-devel@gnu.org; Wed, 28 Nov 2018 18:48:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gS9ZH-0008Sr-Om for grub-devel@gnu.org; Wed, 28 Nov 2018 18:48:42 -0500 Received: from aristoteles.cuci.nl ([212.125.128.18]:49603) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gS9ZG-0008Ai-KF for grub-devel@gnu.org; Wed, 28 Nov 2018 18:48:31 -0500 Received: by aristoteles.cuci.nl (Postfix, from userid 500) id B50AE5463; Thu, 29 Nov 2018 00:40:30 +0100 (CET) Date: Thu, 29 Nov 2018 00:40:30 +0100 From: "Stephen R. van den Berg" To: grub-devel@gnu.org Subject: Proposed patch for SESAME support Message-ID: <20181128234030.GA29251@cuci.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 212.125.128.18 X-Mailman-Approved-At: Wed, 28 Nov 2018 21:20:08 -0500 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Nov 2018 23:48:56 -0000 commit 4d9673b72e1dd05489176073ea630ec4cf5b2760 Author: Stephen R. van den Berg Date: Wed Sep 6 01:42:29 2017 +0200 GRUB_SESAME support. diff --git a/docs/grub.texi b/docs/grub.texi index 471d97c95..e13383bec 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1317,6 +1317,13 @@ If the timeout expires before either of these happens, it will boot the default entry. In the @samp{countdown} case, it will show a one-line indication of the remaining time. +@item GRUB_SESAME +Assigning a phrase to this option will only have effect if +@samp{GRUB_TIMEOUT_STYLE} is set to either @samp{countdown} or @samp{hidden}. +If set, it will keep the menu from appearing until the sesame-phrase +has been typed. Entering the phrase needs to have been completed before +@samp{GRUB_TIMEOUT} expires. + @item GRUB_DEFAULT_BUTTON @itemx GRUB_TIMEOUT_BUTTON @itemx GRUB_TIMEOUT_STYLE_BUTTON diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index e7a83c2d6..c1f4d4571 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -580,6 +580,9 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) int default_entry, current_entry; int timeout; enum timeout_style timeout_style; + const char *sesameword; + char *sesamebuf = 0; + unsigned sesamelen; default_entry = get_entry_number (menu, "default"); @@ -597,6 +600,17 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) grub_env_unset ("timeout_style"); timeout_style = get_timeout_style (); + sesameword = grub_env_get ("sesame"); + + if (sesameword) { + if (!*sesameword) + sesameword = 0; + else + { + sesamelen = grub_strlen (sesameword); + sesamebuf = grub_zalloc (sesamelen-- + 1); + } + } if (timeout_style == TIMEOUT_STYLE_COUNTDOWN || timeout_style == TIMEOUT_STYLE_HIDDEN) @@ -620,9 +634,19 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) key = grub_getkey_noblock (); if (key != GRUB_TERM_NO_KEY) { - entry = get_entry_index_by_hotkey (menu, key); - if (entry >= 0) - break; + if (sesameword) + { + grub_memmove (sesamebuf, sesamebuf+1, sesamelen); + sesamebuf[sesamelen] = key; + key = grub_strcmp (sesamebuf, sesameword) + ? GRUB_TERM_NO_KEY : GRUB_TERM_ESC; + } + else + { + entry = get_entry_index_by_hotkey (menu, key); + if (entry >= 0) + break; + } } if (key == GRUB_TERM_ESC) { @@ -642,8 +666,11 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) break; } + if (sesamebuf) + grub_free (sesamebuf); grub_env_unset ("timeout"); grub_env_unset ("timeout_style"); + grub_env_unset ("sesame"); if (entry >= 0) { *auto_boot = 0; diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 33332360e..dc3872ce3 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -203,6 +203,7 @@ export GRUB_DEFAULT \ GRUB_HIDDEN_TIMEOUT_QUIET \ GRUB_TIMEOUT \ GRUB_TIMEOUT_STYLE \ + GRUB_SESAME \ GRUB_DEFAULT_BUTTON \ GRUB_HIDDEN_TIMEOUT_BUTTON \ GRUB_TIMEOUT_BUTTON \ diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 93a90233e..c20d63a27 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -282,6 +282,11 @@ fi make_timeout () { + if [ "x${GRUB_SESAME}" != "x" ] ; then + cat << EOF +set sesame="${GRUB_SESAME}" +EOF + fi if [ "x${3}" != "x" ] ; then timeout="${2}" style="${3}"