grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/1] GRUB_SESAME support. (Take 4)


From: Stephen R. van den Berg
Subject: [PATCH 1/1] GRUB_SESAME support. (Take 4)
Date: Thu, 03 Jun 2021 21:50:36 -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.
---
diff -ru grub2-2.04/docs/grub.texi grub2s/docs/grub.texi
--- grub2-2.04/docs/grub.texi   2020-12-04 23:02:29.000000000 +0100
+++ grub2s/docs/grub.texi       2020-12-04 23:05:35.073775016 +0100
@@ -1317,6 +1317,13 @@
 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 -ru grub2-2.04/grub-core/normal/menu.c grub2s/grub-core/normal/menu.c
--- grub2-2.04/grub-core/normal/menu.c  2020-12-04 23:02:29.000000000 +0100
+++ grub2s/grub-core/normal/menu.c      2020-12-04 23:05:35.073775016 +0100
@@ -580,6 +580,9 @@
   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 @@
     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 @@
              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 @@
          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 @@
            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 -ru grub2-2.04/util/grub-mkconfig.in grub2s/util/grub-mkconfig.in
--- grub2-2.04/util/grub-mkconfig.in    2020-12-04 23:02:29.000000000 +0100
+++ grub2s/util/grub-mkconfig.in        2020-12-04 23:05:35.073775016 +0100
@@ -212,6 +212,7 @@
   GRUB_HIDDEN_TIMEOUT_QUIET \
   GRUB_TIMEOUT \
   GRUB_TIMEOUT_STYLE \
+  GRUB_SESAME \
   GRUB_DEFAULT_BUTTON \
   GRUB_HIDDEN_TIMEOUT_BUTTON \
   GRUB_TIMEOUT_BUTTON \
diff -ru grub2-2.04/util/grub.d/00_header.in grub2s/util/grub.d/00_header.in
--- grub2-2.04/util/grub.d/00_header.in 2020-12-04 23:02:29.000000000 +0100
+++ grub2s/util/grub.d/00_header.in     2020-12-04 23:05:35.073775016 +0100
@@ -330,6 +330,11 @@
 
 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}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]