Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jVf1H-0000Gu-Me for mharc-grub-devel@gnu.org; Mon, 04 May 2020 13:36:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVf1F-0000Dw-J1 for grub-devel@gnu.org; Mon, 04 May 2020 13:36:41 -0400 Received: from aristoteles.cuci.nl ([212.125.128.18]:55939) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVf1D-00034e-Js for grub-devel@gnu.org; Mon, 04 May 2020 13:36:40 -0400 Received: by aristoteles.cuci.nl (Postfix, from userid 500) id 3CC555463; Mon, 4 May 2020 19:29:25 +0200 (CEST) Date: Mon, 4 May 2020 19:29:25 +0200 From: "Stephen R. van den Berg" To: grub-devel@gnu.org Cc: Daniel Kiper Subject: [PATCH 1/1] GRUB_SESAME support. (Take 2) Message-ID: <20200504172925.GA27968@cuci.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181205114325.j4zofobzpl52nfzk@tomti.i.net-space.pl> User-Agent: Mutt/1.5.21 (2010-09-15) Received-SPF: pass client-ip=212.125.128.18; envelope-from=srb@cuci.nl; helo=aristoteles.cuci.nl X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/04 13:29:25 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2020 17:36:41 -0000 If set, it will keep the menu from appearing until the sesame-phrase has been typed. The intended usage is so that you can have two devices both running grub/Linux, each device with a single serial port. Connect both serial ports against each other, and the two devices will not accidentally trigger grub to do anything, unless the sesame-phrase will have been entered. --- debian/changelog | 6 ++++++ docs/grub.texi | 7 +++++++ grub-core/normal/menu.c | 35 +++++++++++++++++++++++++++++++---- util/grub-mkconfig.in | 1 + util/grub.d/00_header.in | 5 +++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0d25df0fe..f8fee9919 100644 diff --git a/docs/grub.texi b/docs/grub.texi index f1216d19d..d9283c5b1 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1315,6 +1315,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 906a480a2..17087e1e2 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) @@ -652,7 +666,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) mods |= term->getkeystatus (term); } - if (mods >= 0 && + if (mods >= 0 && !sesameword && (mods & (GRUB_TERM_STATUS_LSHIFT | GRUB_TERM_STATUS_RSHIFT)) != 0) { @@ -663,9 +677,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) { @@ -685,8 +709,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 ad716384b..7e29680c4 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -211,6 +211,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 674a76140..d8ec4bb77 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -328,6 +328,11 @@ fi make_timeout () { + if [ "x${GRUB_SESAME}" != "x" ] ; then + cat << EOF +set sesame="${GRUB_SESAME}" +EOF + fi cat << EOF if [ "\${recordfail}" = 1 ] ; then set timeout=${GRUB_RECORDFAIL_TIMEOUT:-30} -- 2.20.1