9
0
Fork 0

login: disable input console if password wrong

so we guarantee that barebox is secured again user interaction

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2013-09-16 19:49:58 +02:00 committed by Sascha Hauer
parent 54385ace4b
commit bb89ea62a0
6 changed files with 56 additions and 1 deletions

View File

@ -24,6 +24,7 @@
#include <globalvar.h>
#include <magicvar.h>
#include <init.h>
#include <console.h>
#define PASSWD_MAX_LENGTH (128 + 1)
@ -44,6 +45,7 @@ static int do_login(int argc, char *argv[])
int timeout = login_timeout;
char *timeout_cmd = "boot";
console_allow_input(true);
if (!is_passwd_enable()) {
puts("login: password not set\n");
return 0;
@ -64,8 +66,10 @@ static int do_login(int argc, char *argv[])
puts("Password: ");
passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout);
if (passwd_len < 0)
if (passwd_len < 0) {
console_allow_input(false);
run_command(timeout_cmd, 0);
}
if (check_passwd(passwd, passwd_len))
return 0;

View File

@ -236,6 +236,9 @@ int getc(void)
unsigned char ch;
uint64_t start;
if (unlikely(!console_is_input_allow()))
return -EPERM;
/*
* For 100us we read the characters from the serial driver
* into a kfifo. This helps us not to lose characters
@ -270,6 +273,9 @@ EXPORT_SYMBOL(fgetc);
int tstc(void)
{
if (unlikely(!console_is_input_allow()))
return 0;
return kfifo_len(console_input_fifo) || tstc_raw();
}
EXPORT_SYMBOL(tstc);

View File

@ -21,9 +21,42 @@
#include <common.h>
#include <fs.h>
#include <errno.h>
#include <console.h>
#include <init.h>
#include <environment.h>
#include <globalvar.h>
#include <magicvar.h>
#include <password.h>
#ifndef CONFIG_CONSOLE_NONE
static int console_input_allow;
static int console_global_init(void)
{
if (IS_ENABLED(CONFIG_CMD_LOGIN) && is_passwd_enable())
console_input_allow = 0;
else
console_input_allow = 1;
globalvar_add_simple_bool("console.input_allow", &console_input_allow);
return 0;
}
late_initcall(console_global_init);
BAREBOX_MAGICVAR_NAMED(global_console_input_allow, global.console.input_allow, "console input allowed");
bool console_is_input_allow(void)
{
return console_input_allow;
}
void console_allow_input(bool val)
{
console_input_allow = val;
}
int printf(const char *fmt, ...)
{
va_list args;

View File

@ -3,6 +3,7 @@
#include <fs.h>
#include <errno.h>
#include <debug_ll.h>
#include <console.h>
LIST_HEAD(console_list);
EXPORT_SYMBOL(console_list);
@ -40,6 +41,9 @@ EXPORT_SYMBOL(console_putc);
int tstc(void)
{
if (unlikely(!console_is_input_allow()))
return 0;
if (!console)
return 0;
@ -49,6 +53,9 @@ EXPORT_SYMBOL(tstc);
int getc(void)
{
if (unlikely(!console_is_input_allow()))
return -EPERM;
if (!console)
return -EINVAL;
return console->getc(console);

View File

@ -138,6 +138,8 @@ void __noreturn start_barebox(void)
run_command("source /env/bin/init", 0);
} else {
pr_err("/env/bin/init not found\n");
if (IS_ENABLED(CONFIG_CMD_LOGIN))
while(run_command("login -t 0", 0));
}
}

View File

@ -54,4 +54,7 @@ extern struct list_head console_list;
#define CFG_PBSIZE (CONFIG_CBSIZE+sizeof(CONFIG_PROMPT)+16)
bool console_is_input_allow(void);
void console_allow_input(bool val);
#endif