defaultenv-2: add login support
v3 cover defaultenv-2: add login support
HI,
v3:
use glabalvar type params
this will allow to request password when try to interrupt barebox auto boot
This will also allow to set a default password if none in the env and if no /env/bin/init is present request a login
The following changes since commit f0b68f0008f94606f6b927590d1fafb34b1abc55:
usb-imx28: fix enable (2013-09-10 21:03:59 +0200)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git delivery/login
for you to fetch changes up to 8d1ab8f59cc9f3a22e191d389433ca78f74bbc57:
defaultenv-2: add login support (2013-09-17 01:01:08 +0800)
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (5):
globalvar: add globalvar_add_simple_int/bool/enum/ip support
login: add globalvar timeout support
login: disable input console if password wrong login/passwd: add default password support
defaultenv-2: add login support
commands/login.c | 24 ++++++++++++++++++++++-- commands/passwd.c | 8 ++++---- common/Kconfig | 5 +++++ common/Makefile | 20 ++++++++++++++++++++ common/console.c | 6 ++++++ common/console_common.c | 33 +++++++++++++++++++++++++++++++++ common/console_simple.c | 9 ++++++++- common/globalvar.c | 2 +- common/password.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- common/startup.c | 2 ++ defaultenv-2/base/bin/init | 18 ++++++++++++++++++ include/console.h | 3 +++ include/globalvar.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/password.h | 22 +++++++++++++++++----- 14 files changed, 303 insertions(+), 26 deletions(-)
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 1/5 globalvar: add globalvar_add_simple_int/bool/enum/ip support
so we can types var
--- common/globalvar.c | 2 +- include/globalvar.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-)
common/globalvar.c +1 -1
@@ -6,7 +6,7 @@#include <magicvar.h> #include <generated/utsrelease.h> -static struct device_d global_device = { +struct device_d global_device = { .name ="global" , .id =DEVICE_ID_SINGLE , };
include/globalvar.h +83 -0
101 lines not on this page · raw message
Signature · 7 lines
1.8.4.rc1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 2/5 login: add globalvar timeout support
--- commands/login.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
commands/login.c +17 -1
@@ -20,6 +20,10 @@#include <complete.h> #include <password.h> #include <getopt.h> +#include <environment.h> +#include <globalvar.h> +#include <magicvar.h> +#include <init.h> #define PASSWD_MAX_LENGTH (128 + 1)
@@ -31,11 +35,13 @@#define LOGIN_MODE HIDE#endif +static int login_timeout =0 ; +static int do_login (int argc,char *argv[]) {unsigned char passwd[PASSWD_MAX_LENGTH ];int passwd_len, opt; -int timeout =0 ; +int timeout = login_timeout;char *timeout_cmd ="boot" ;if (!is_passwd_enable ()) {
@@ -80,3 +86,13 @@ BAREBOX_CMD_START(login)BAREBOX_CMD_HELP (cmd_login_help)BAREBOX_CMD_COMPLETE (empty_complete )BAREBOX_CMD_END + +static intlogin_global_init (void) +{ +globalvar_add_simple_int ("login.timeout" , &login_timeout,"%d" ); + +return 0 ; +} +late_initcall (login_global_init); + +BAREBOX_MAGICVAR_NAMED (global_login_timeout, global.login.timeout,"timeout to type the password" );
Signature · 7 lines
1.8.4.rc1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 3/5 login: disable input console if password wrong
In reply to Jean-Christophe PLAGNIOL-VILLARDso we guarantee that barebox is secured again user interaction
--- commands/login.c | 6 +++++- common/console.c | 6 ++++++ common/console_common.c | 33 +++++++++++++++++++++++++++++++++ common/console_simple.c | 9 ++++++++- common/startup.c | 2 ++ include/console.h | 3 +++ 6 files changed, 57 insertions(+), 2 deletions(-)
commands/login.c +5 -1
@@ -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 ;
common/console.c +6 -0
@@ -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);
common/console_common.c +33 -0
@@ -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;
common/console_simple.c +8 -1
@@ -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 ;
@@ -48,7 +52,10 @@ int tstc(void)EXPORT_SYMBOL (tstc); int getc(void) -{ + + if (unlikely(!console_is_input_allow())) + return -EPERM; +if (!console)return -EINVAL ;return console->getc (console);
common/startup.c +2 -0
@@ -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 )); } }
include/console.h +3 -0
@@ -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
Signature · 7 lines
1.8.4.rc1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 4/5 login/passwd: add default password support
In reply to Jean-Christophe PLAGNIOL-VILLARDeven if the env is broken you will have a password
--- commands/passwd.c | 8 ++--- common/Kconfig | 5 +++ common/Makefile | 20 ++++++++++++ common/password.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++-------- include/password.h | 22 ++++++++++--- 5 files changed, 127 insertions(+), 22 deletions(-)
commands/passwd.c +4 -4
@@ -63,7 +63,7 @@ static int do_passwd(int argc, char *argv[]) goto err; } - ret =set_passwd (passwd1, passwd1_len); + ret =set_env_passwd (passwd1, passwd1_len);if (ret <0 ) {puts ("Sorry, passwords write failed\n" );
@@ -78,15 +78,15 @@ err:return 1 ; disable: -passwd_disable (); +passwd_env_disable ();puts ("passwd: password disabled\n" );return ret; }static const __maybe_unused char cmd_passwd_help[] ="Usage: passwd\n" -"passwd allow you to specify a password\n" -"to disable it put an empty password\n" +"passwd allow you to specify a password in the env\n" +"to disable it put an empty password will still use the default password if set\n" ;BAREBOX_CMD_START (passwd)
common/Kconfig +5 -0
@@ -385,6 +385,11 @@ config PASSWORD help allow you to have password protection framework +config PASSWORD_DEFAULT + string + prompt "Password default" + depends on PASSWORD + if PASSWORD choice
common/Makefile +20 -0
@@ -114,6 +114,26 @@ cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c default_environment) $(obj)/barebox_default_env.h: $(obj)/barebox_default_env$(barebox_default_env_comp) FORCE $(call if_changed,env_h) +quiet_cmd_pwd_h = PWDH $@ +ifneq ($(CONFIG_PASSWORD_DEFAULT),"") +PASSWD_FILE := $(shell cd $(srctree); find $(CONFIG_PASSWORD_DEFAULT) -type f) +cmd_pwd_h = echo -n "const char default_passwd[] = \"" > $@; \ + cat $< | tr -d '\n' >> $@; \ + echo "\";" >> $@ + +include/generated/passwd.h: $(PASSWD_FILE) + $(call if_changed,pwd_h) +else +cmd_pwd_h = echo "const char default_passwd[] = \"\";" > $@ + +include/generated/passwd.h: FORCE + $(call if_changed,pwd_h) +endif + +targets += include/generated/passwd.h + +$(obj)/password.o: include/generated/passwd.h + # dependencies on generated files need to be listed explicitly $(obj)/version.o: include/generated/compile.h
common/password.c +81 -13
157 lines not on this page · raw message
include/password.h +17 -5
@@ -28,11 +28,23 @@int password (unsigned char *passwd,size_t length,int flags,int timeout);int read_passwd (unsigned char *sum,size_t length); -int write_passwd (unsigned char *sum,size_t length); - -int is_passwd_enable (void ); -int passwd_disable (void );int check_passwd (unsigned char * passwd,size_t length); -int set_passwd (unsigned char * passwd,size_t length); + +int read_env_passwd (unsigned char *sum,size_t length); +int write_env_passwd (unsigned char *sum,size_t length); + +int read_default_passwd (unsigned char *sum,size_t length); +int is_passwd_default_enable (void ); +int check_default_passwd (unsigned char * passwd,size_t length); + +int is_passwd_env_enable (void ); +int passwd_env_disable (void ); +int check_env_passwd (unsigned char * passwd,size_t length); +int set_env_passwd (unsigned char * passwd,size_t length); + +static inline int is_passwd_enable (void ) +{ +return is_passwd_default_enable () ||is_passwd_env_enable (); +}#endif /* __PASSWORD_H__ */
Signature · 7 lines
1.8.4.rc1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 5/5 defaultenv-2: add login support
In reply to Jean-Christophe PLAGNIOL-VILLARDrequest password to login is a timeout is specified and /env/etc/passwd present
ensure we have not console access execpt when allowed
--- defaultenv-2/base/bin/init | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
defaultenv-2/base/bin/init +18 -0
@@ -16,14 +16,24 @@ global editcmd=sedit [ -e /env/config-board ] && /env/config-board /env/config +# request password to login if a timeout is specified and password set +if [ -n ${global.login.timeout} ]; then + [ ${global.login.timeout} -gt 0 ] && login_cmd=login +fi +# allow the input if not +[ -n ${global.console.input_allow} ] && global.console.input_allow=1 + # allow to stop the boot before execute the /env/init/* # but without waiting timeout -s -a -v key 0 if [ "${key}" = "q" ]; then + ${login_cmd} exit fi +[ -n ${login_cmd} ] && global.console.input_allow=0 + for i in /env/init/*; do . $i done
@@ -34,10 +44,15 @@ else echo -e -n "\nHit any key to stop autoboot: " fi +[ -n ${login_cmd} ] && global.console.input_allow=1 + timeout -a $global.autoboot_timeout -v key autoboot="$?" +[ -n ${login_cmd} ] && global.console.input_allow=0 + if [ "${key}" = "q" ]; then + ${login_cmd} exit fi
@@ -46,9 +61,12 @@ if [ "$autoboot" = 0 ]; then fi if [ -e /env/menu ]; then + ${login_cmd} if [ "${key}" != "m" ]; then echo -e "\ntype exit to get to the menu" sh fi /env/menu/mainmenu fi + +${login_cmd}
Signature · 7 lines
1.8.4.rc1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 15 lines · Jean-Christophe PLAGNIOL-VILLARD
HI,
v3:
use glabalvar type paramsthis will allow to request password when try to interrupt barebox auto boot
This will also allow to set a default password if none in the env and if no /env/bin/init is present request a login
The following changes since commit
f0b68f0008f94606f6b927590d1fafb34b1abc55:usb-imx28: fix enable (2013-09-10 21:03:59 +0200)
Quoted 7 lines
are available in the git repository at:
git://git.jcrosoft.org/barebox.gitdelivery/loginfor you to fetch changes up to
8d1ab8f59cc9f3a22e191d389433ca78f74bbc57:defaultenv-2: add login support (2013-09-17 01:01:08 +0800)
Applied, thanks.
include/globalvar lacked a #include <linux/err.h>. Added this while applying.
Sascha
Quoted 33 lines
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (5):
globalvar: add globalvar_add_simple_int/bool/enum/ip support
login: add globalvar timeout support
login: disable input console if password wrong login/passwd: add default password support
defaultenv-2: add login supportcommands/login.c | 24 ++++++++++++++++++++++-- commands/passwd.c | 8 ++++---- common/Kconfig | 5 +++++ common/Makefile | 20 ++++++++++++++++++++ common/console.c | 6 ++++++ common/console_common.c | 33 +++++++++++++++++++++++++++++++++ common/console_simple.c | 9 ++++++++- common/globalvar.c | 2 +- common/password.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- common/startup.c | 2 ++ defaultenv-2/base/bin/init | 18 ++++++++++++++++++ include/console.h | 3 +++ include/globalvar.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/password.h | 22 +++++++++++++++++----- 14 files changed, 303 insertions(+), 26 deletions(-)Best Regards,
J._______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox