Skip to contentSkip to conversation

defaultenv-2: add login support

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 4 messages Sep 4, 2013 – Sep 6, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover defaultenv-2: add login support

HI,

this will allow to request password when try to interrupt barebox auto boot

defaultenv-2: add login support (2013-09-04 17:55:11 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (2):
login: add globalvar timeout support
defaultenv-2: add login support

 commands/login.c           | 26 ++++++++++++++++++++++++++
 defaultenv-2/base/bin/init |  9 +++++++++
 2 files changed, 35 insertions(+)

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/2 login: add globalvar timeout support

---
 commands/login.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
commands/login.c +26 -0
index fb6bb35..f5429bc 100644
@@ -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,6 +35,16 @@
 #define LOGIN_MODE HIDE
 #endif
 
+static void login_getenv_int(const char *name, int *i)
+{
+	const char* str = getenv(name);
+
+	if (!str)
+		return;
+
+	*i = simple_strtoul(str, NULL, 10);
+}
+
 static int do_login(int argc, char *argv[])
 {
 	unsigned char passwd[PASSWD_MAX_LENGTH];
@@ -38,6 +52,8 @@ static int do_login(int argc, char *argv[])
 	int timeout = 0;
 	char *timeout_cmd = "boot";
 
+	login_getenv_int("global.login.timeout", &timeout);
+
 	if (!is_passwd_enable()) {
 		puts("login: password not set\n");
 		return 0;
@@ -80,3 +96,13 @@ BAREBOX_CMD_START(login)
 	BAREBOX_CMD_HELP(cmd_login_help)
 	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
+
+static int login_global_init(void)
+{
+	globalvar_add_simple("login.timeout");
+
+	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
#2 lore raw

PATCH 2/2 defaultenv-2: add login support

request password to login is a timeout is specified and /env/etc/passwd present

---
 defaultenv-2/base/bin/init | 9 +++++++++
 1 file changed, 9 insertions(+)
defaultenv-2/base/bin/init +9 -0
index ca02ba6..e696dce 100644
@@ -16,11 +16,15 @@ global editcmd=sedit
 [ -e /env/config-board ] && /env/config-board
 /env/config
 
+# request password to login is a timeout is specified and /env/etc/passwd present
+[ -n ${global.login.timeout} ] && login_cmd=login
+
 # 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
 
@@ -38,6 +42,7 @@ timeout -a $global.autoboot_timeout -v key
 autoboot="$?"
 
 if [ "${key}" = "q" ]; then
+	${login_cmd}
 	exit
 fi
 
@@ -48,7 +53,11 @@ fi
 if [ -e /env/menu ]; then
 	if [ "${key}" != "m" ]; then
 		echo -e "\ntype exit to get to the menu"
+		${login_cmd}
 		sh
 	fi
+	${login_cmd}
 	/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
#3 lore raw
Quoted 37 lines · Jean-Christophe PLAGNIOL-VILLARD

request password to login is a timeout is specified and /env/etc/passwd present

---
 defaultenv-2/base/bin/init | 9 +++++++++
 1 file changed, 9 insertions(+)
defaultenv-2/base/bin/init +5 -0
index ca02ba6..e696dce 100644
@@ -16,11 +16,15 @@ global editcmd=sedit
 [ -e /env/config-board ] && /env/config-board
 /env/config
 
+# request password to login is a timeout is specified and /env/etc/passwd present
+[ -n ${global.login.timeout} ] && login_cmd=login
+
 # 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
 
@@ -38,6 +42,7 @@ timeout -a $global.autoboot_timeout -v key
 autoboot="$?"
 
 if [ "${key}" = "q" ]; then
+	${login_cmd}
 	exit
 fi
 

defaultenv-2/base/bin/init fi · line 60

Quoted 8 lines
defaultenv-2/base/bin/init +2 -0
@@ -48,7 +53,11 @@ fi
 if [ -e /env/menu ]; then
 	if [ "${key}" != "m" ]; then
 		echo -e "\ntype exit to get to the menu"
+		${login_cmd}
 		sh
 	fi
+	${login_cmd}
 	/env/menu/mainmenu

You should do it like this:

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

Otherwise you get prompted for a password when entering the shell and agin when going to the menu.

Sascha

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