Skip to contentSkip to conversation

Proposed patch for SESAME support

PATCH New Stephen R. van den Berg 2 participants 5 messages Nov 29, 2018 – Jun 3, 2021

lore
Share & tools
lore
#0 lore raw

commit 4d9673b72e1dd05489176073ea630ec4cf5b2760

Author: Stephen R. van den Berg <[email protected]>
Date:   Wed Sep 6 01:42:29 2017 +0200

GRUB_SESAME support.

docs/grub.texi +7 -0
index 471d97c95..e13383bec 100644
@@ -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
grub-core/normal/menu.c +30 -3
index e7a83c2d6..c1f4d4571 100644
@@ -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;
util/grub-mkconfig.in +1 -0
index 33332360e..dc3872ce3 100644
@@ -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 \
util/grub.d/00_header.in +5 -0
index 93a90233e..c20d63a27 100644
@@ -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}"
#1 lore raw
Quoted 5 lines · Stephen R. van den Berg

commit 4d9673b72e1dd05489176073ea630ec4cf5b2760

Author: Stephen R. van den Berg <[email protected]>
Date:   Wed Sep 6 01:42:29 2017 +0200

GRUB_SESAME support.

OK, nice but I do not really know what problem this patch solves. So, please explain that in the commit message. Then I will take closer look at the code itself.

Daniel

#2 lore raw

PATCH 1/1 GRUB_SESAME support. (Take 2)

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(-)
debian/changelog +0 -0
index 0d25df0fe..f8fee9919 100644
docs/grub.texi +7 -0
index f1216d19d..d9283c5b1 100644
@@ -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
grub-core/normal/menu.c +31 -4
index 906a480a2..17087e1e2 100644
@@ -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;
util/grub-mkconfig.in +1 -0
index ad716384b..7e29680c4 100644
@@ -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 \
util/grub.d/00_header.in +5 -0
index 674a76140..d8ec4bb77 100644
@@ -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}
Signature · 1 line
2.20.1
#3 lore raw

PATCH 1/1 GRUB_SESAME support. (Take 3)

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.
---

docs/grub.texi +7 -0
diff -ru grub2-2.04/docs/grub.texi grub2s/docs/grub.texi
@@ -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
grub-core/normal/menu.c +31 -4
diff -ru grub2-2.04/grub-core/normal/menu.c grub2s/grub-core/normal/menu.c
@@ -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;
util/grub-mkconfig.in +1 -0
diff -ru grub2-2.04/util/grub-mkconfig.in grub2s/util/grub-mkconfig.in
@@ -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 \
util/grub.d/00_header.in +5 -0
diff -ru grub2-2.04/util/grub.d/00_header.in grub2s/util/grub.d/00_header.in
@@ -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}
#4 lore raw

PATCH 1/1 GRUB_SESAME support. (Take 4)

In reply to Daniel Kiper

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.
---

docs/grub.texi +7 -0
diff -ru grub2-2.04/docs/grub.texi grub2s/docs/grub.texi
@@ -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
grub-core/normal/menu.c +31 -4
diff -ru grub2-2.04/grub-core/normal/menu.c grub2s/grub-core/normal/menu.c
@@ -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;
util/grub-mkconfig.in +1 -0
diff -ru grub2-2.04/util/grub-mkconfig.in grub2s/util/grub-mkconfig.in
@@ -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 \
util/grub.d/00_header.in +5 -0
diff -ru grub2-2.04/util/grub.d/00_header.in grub2s/util/grub.d/00_header.in
@@ -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}