From bb89ea62a0b7e5c6fcedfe1a28b6dd82236247ce Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Mon, 16 Sep 2013 19:49:58 +0200 Subject: login: disable input console if password wrong so we guarantee that barebox is secured again user interaction Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- common/console_common.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'common/console_common.c') diff --git a/common/console_common.c b/common/console_common.c index d139d1a8fe..d1b823ef8a 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -21,9 +21,42 @@ #include #include #include +#include +#include +#include +#include +#include +#include #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; -- cgit v1.2.3 From 666f12e0c19a19f4431e05f6e5b37e657a62038f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Feb 2013 13:47:26 +0100 Subject: introduce runtime loglevel With this the verbosity of barebox can be controlled during runtime using the 'loglevel' globalvar. Signed-off-by: Sascha Hauer --- common/Kconfig | 18 +++++++++++++++++- common/console_common.c | 27 +++++++++++++++++++++++++++ drivers/base/driver.c | 6 +++++- include/console.h | 2 ++ include/printk.h | 9 ++++++--- 5 files changed, 57 insertions(+), 5 deletions(-) (limited to 'common/console_common.c') diff --git a/common/Kconfig b/common/Kconfig index 5d922847e8..87abaf0b27 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -607,7 +607,7 @@ endmenu menu "Debugging" config COMPILE_LOGLEVEL - int "loglevel" + int "compile loglevel" default 6 help This defines the maximum loglevel compiled into the binary. Less important @@ -622,6 +622,22 @@ config COMPILE_LOGLEVEL 6 informational (info) 7 debug-level messages (debug) +config DEFAULT_LOGLEVEL + int "default loglevel" + default 7 + help + This defines the default runtime loglevel. It can be changed using the + global.loglevel variable. Available logelevels are: + + 0 system is unusable (emerg) + 1 action must be taken immediately (alert) + 2 critical conditions (crit) + 3 error conditions (err) + 4 warning conditions (warn) + 5 normal but significant condition (notice) + 6 informational (info) + 7 debug-level messages (debug) + config DEBUG_INFO bool prompt "enable debug symbols" diff --git a/common/console_common.c b/common/console_common.c index d1b823ef8a..18b76766d6 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -57,6 +57,33 @@ void console_allow_input(bool val) console_input_allow = val; } +int barebox_loglevel = CONFIG_DEFAULT_LOGLEVEL; + +int pr_print(int level, const char *fmt, ...) +{ + va_list args; + uint i; + char printbuffer[CFG_PBSIZE]; + + if (level > barebox_loglevel) + return 0; + + va_start(args, fmt); + i = vsprintf(printbuffer, fmt, args); + va_end(args); + + /* Print the string */ + puts(printbuffer); + + return i; +} + +static int loglevel_init(void) +{ + return globalvar_add_simple_int("loglevel", &barebox_loglevel, "%d"); +} +device_initcall(loglevel_init); + int printf(const char *fmt, ...) { va_list args; diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 16b7f06c4a..e587e3acc1 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -370,11 +371,14 @@ const char *dev_id(const struct device_d *dev) return buf; } -int dev_printf(const struct device_d *dev, const char *format, ...) +int dev_printf(int level, const struct device_d *dev, const char *format, ...) { va_list args; int ret = 0; + if (level > barebox_loglevel) + return 0; + if (dev->driver && dev->driver->name) ret += printf("%s ", dev->driver->name); diff --git a/include/console.h b/include/console.h index e94c5aec75..393579bb7f 100644 --- a/include/console.h +++ b/include/console.h @@ -57,4 +57,6 @@ extern struct list_head console_list; bool console_is_input_allow(void); void console_allow_input(bool val); +extern int barebox_loglevel; + #endif diff --git a/include/printk.h b/include/printk.h index 86bf208425..f550f07bb8 100644 --- a/include/printk.h +++ b/include/printk.h @@ -18,12 +18,15 @@ /* debugging and troubleshooting/diagnostic helpers. */ -int dev_printf(const struct device_d *dev, const char *format, ...) +int pr_print(int level, const char *format, ...) __attribute__ ((format(__printf__, 2, 3))); +int dev_printf(int level, const struct device_d *dev, const char *format, ...) + __attribute__ ((format(__printf__, 3, 4))); + #define __dev_printf(level, dev, format, args...) \ ({ \ - (level) <= LOGLEVEL ? dev_printf((dev), (format), ##args) : 0; \ + (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \ }) @@ -46,7 +49,7 @@ int dev_printf(const struct device_d *dev, const char *format, ...) #define __pr_printk(level, format, args...) \ ({ \ - (level) <= LOGLEVEL ? printk((format), ##args) : 0; \ + (level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \ }) #ifndef pr_fmt -- cgit v1.2.3