Proposed patch for SESAME support
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
@@ -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
@@ -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
@@ -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
@@ -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}"
Quoted 5 lines · Stephen R. van den Berg
commit
4d9673b72e1dd05489176073ea630ec4cf5b2760Author: Stephen R. van den Berg <[email protected]> Date: Wed Sep 6 01:42:29 2017 +0200
GRUB_SESAMEsupport.
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
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
docs/grub.texi +7 -0
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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}
PATCH 1/1 GRUB_SESAME support. (Take 4)
In reply to Daniel KiperIf 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
@@ -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
@@ -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
@@ -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
@@ -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}