Index: conf/i386-efi.rmk =================================================================== RCS file: /sources/grub/grub2/conf/i386-efi.rmk,v retrieving revision 1.19 diff -u -p -r1.19 i386-efi.rmk --- conf/i386-efi.rmk 2 Aug 2007 19:12:52 -0000 1.19 +++ conf/i386-efi.rmk 5 Aug 2007 15:18:51 -0000 @@ -109,6 +109,7 @@ normal_mod_SOURCES = normal/arg.c normal normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ normal/menu_entry.c normal/misc.c grub_script.tab.c \ + normal/password.c normal/md5.c \ normal/script.c normal/i386/setjmp.S normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_ASFLAGS = $(COMMON_ASFLAGS) Index: conf/i386-pc.rmk =================================================================== RCS file: /sources/grub/grub2/conf/i386-pc.rmk,v retrieving revision 1.86 diff -u -p -r1.86 i386-pc.rmk --- conf/i386-pc.rmk 2 Aug 2007 19:12:52 -0000 1.86 +++ conf/i386-pc.rmk 5 Aug 2007 15:18:52 -0000 @@ -157,6 +157,7 @@ normal_mod_SOURCES = normal/arg.c normal normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ normal/menu_entry.c normal/misc.c grub_script.tab.c \ + normal/password.c normal/md5.c \ normal/script.c normal/i386/setjmp.S normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_ASFLAGS = $(COMMON_ASFLAGS) Index: conf/powerpc-ieee1275.rmk =================================================================== RCS file: /sources/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.69 diff -u -p -r1.69 powerpc-ieee1275.rmk --- conf/powerpc-ieee1275.rmk 2 Aug 2007 19:12:52 -0000 1.69 +++ conf/powerpc-ieee1275.rmk 5 Aug 2007 15:18:52 -0000 @@ -124,6 +124,7 @@ normal_mod_SOURCES = normal/arg.c normal normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ normal/menu_entry.c normal/misc.c grub_script.tab.c \ + normal/password.c normal/md5.c \ normal/script.c normal/powerpc/setjmp.S normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_LDFLAGS = $(COMMON_LDFLAGS) Index: conf/sparc64-ieee1275.rmk =================================================================== RCS file: /sources/grub/grub2/conf/sparc64-ieee1275.rmk,v retrieving revision 1.17 diff -u -p -r1.17 sparc64-ieee1275.rmk --- conf/sparc64-ieee1275.rmk 2 Jul 2007 20:38:01 -0000 1.17 +++ conf/sparc64-ieee1275.rmk 5 Aug 2007 15:18:52 -0000 @@ -156,6 +156,7 @@ normal_mod_SOURCES = normal/arg.c normal normal/completion.c normal/execute.c \ normal/function.c normal/lexer.c normal/main.c normal/menu.c \ normal/menu_entry.c normal/misc.c normal/script.c \ + normal/password.c normal/md5.c \ normal/sparc64/setjmp.S \ grub_script.tab.c normal_mod_CFLAGS = $(COMMON_CFLAGS) Index: normal/command.c =================================================================== RCS file: /sources/grub/grub2/normal/command.c,v retrieving revision 1.19 diff -u -p -r1.19 command.c --- normal/command.c 21 Jul 2007 23:32:29 -0000 1.19 +++ normal/command.c 5 Aug 2007 15:18:52 -0000 @@ -25,6 +25,7 @@ #include #include #include +#include static grub_command_t grub_command_list; @@ -391,4 +392,8 @@ grub_command_init (void) grub_register_command ("lsmod", lsmod_command, GRUB_COMMAND_FLAG_BOTH, "lsmod", "Show loaded modules.", 0); + + grub_register_command ("password", grub_password_command, GRUB_COMMAND_FLAG_MENU, + "password [--MD5] PASSWORD [NEXT_FILE]", "Set a password", + grub_password_arg_options); } Index: normal/menu.c =================================================================== RCS file: /sources/grub/grub2/normal/menu.c,v retrieving revision 1.18 diff -u -p -r1.18 menu.c --- normal/menu.c 21 Jul 2007 23:32:29 -0000 1.18 +++ normal/menu.c 5 Aug 2007 15:18:52 -0000 @@ -24,6 +24,9 @@ #include #include #include +#include + +int ask_and_check_password(void); static void draw_border (void) @@ -76,9 +79,18 @@ print_message (int nested, int edit) grub_printf ("\n\ Use the %C and %C keys to select which entry is highlighted.\n", (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf ("\ + if ( grub_password_is_user_authenticated(0) == 1 ) + { + grub_printf ("\ Press enter to boot the selected OS, \'e\' to edit the\n\ commands before booting or \'c\' for a command-line."); + } + else + { + grub_printf ("\ + Press \'p\' to enter password and unlock command-line and\n\ + menu entry edition."); + } if (nested) grub_printf ("\n\ ESC to return previous menu."); @@ -408,13 +420,46 @@ run_menu (grub_menu_t menu, int nested) break; case 'c': + if ( grub_password_is_user_authenticated(0) != 1 ) + { + if (ask_and_check_password() == 0) + goto proceed_cmdline; + goto refresh; + } + + proceed_cmdline: grub_cmdline_run (1); goto refresh; case 'e': + if ( grub_password_is_user_authenticated(0) != 1 ) + { + if (ask_and_check_password() == 0) + goto proceed_edition; + goto refresh; + } + + proceed_edition: grub_menu_entry_run (get_entry (menu, first + offset)); goto refresh; - + + case 'p': + /* Authenticate voluntarily and go to next file is any */ + if ( grub_password_is_password_set() != 0 ) + { + if (ask_and_check_password() == 0) + { + /* Check if there is a next file specified... */ + char *next_file = grub_password_get_next_file(); + if (next_file == 0) + goto refresh; + + grub_normal_execute( (const char*) next_file, 1); + goto refresh; + } + } + goto refresh; + default: break; } @@ -427,6 +472,38 @@ run_menu (grub_menu_t menu, int nested) return -1; } +int +ask_and_check_password(void) +{ + int ret; + int cmdline_ret; + char entered[GRUB_PASSWORD_MAX_LENGTH + 1]; + grub_memset(entered, 0, sizeof(entered)); + + /* Clear password zone, and prompt for password*/ + grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); + grub_printf ("\ + "); + grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); + cmdline_ret = grub_cmdline_get(" Password : ", + entered, + GRUB_PASSWORD_MAX_LENGTH, + '*', + 0); + if (cmdline_ret == 0) + goto failed; /* User taped ESC */ + + if (grub_password_check_password(entered, 0) == 0) + goto success; + + failed: + return -1; + + success: + return 0; + +} + /* Run a menu entry. */ static void run_menu_entry (grub_menu_entry_t entry)