summaryrefslogtreecommitdiffstats
path: root/commands/login.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2011-08-10 12:47:08 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2011-08-11 09:22:07 +0200
commitc78ef640cd18847a962d3e1fdb84ad6c265b0deb (patch)
tree54c4ea48cb1ebfdaaaab05ff47e8dcb6be06ef3a /commands/login.c
parentfde45de7351264cd27a9024ea2b6620d170b5269 (diff)
downloadbarebox-c78ef640cd18847a962d3e1fdb84ad6c265b0deb.tar.gz
barebox-c78ef640cd18847a962d3e1fdb84ad6c265b0deb.tar.xz
login: add timeout support
If a timeout is specified and expired the command will be executed by default boot Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/login.c')
-rw-r--r--commands/login.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/commands/login.c b/commands/login.c
index 7d99b73921..610fb9ed73 100644
--- a/commands/login.c
+++ b/commands/login.c
@@ -21,6 +21,7 @@
#include <common.h>
#include <command.h>
#include <password.h>
+#include <getopt.h>
#define PASSWD_MAX_LENGTH (128 + 1)
@@ -35,16 +36,32 @@
static int do_login(struct command *cmdtp, int argc, char *argv[])
{
unsigned char passwd[PASSWD_MAX_LENGTH];
- int passwd_len;
+ int passwd_len, opt;
+ int timeout = 0;
+ char *timeout_cmd = "boot";
if (!is_passwd_enable()) {
puts("login: password not set\n");
return 0;
}
+ while((opt = getopt(argc, argv, "t:")) > 0) {
+ switch(opt) {
+ case 't':
+ timeout = simple_strtoul(optarg, NULL, 10);
+ break;
+ }
+ }
+
+ if (optind != argc)
+ timeout_cmd = argv[optind];
+
do {
puts("Password: ");
- passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE);
+ passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout);
+
+ if (passwd_len < 0)
+ run_command(timeout_cmd, 0);
if (check_passwd(passwd, passwd_len))
return 0;
@@ -54,7 +71,10 @@ static int do_login(struct command *cmdtp, int argc, char *argv[])
}
static const __maybe_unused char cmd_login_help[] =
-"";
+"Usage: login [[-t timeout] <command>]\n"
+"If a timeout is specified and expired the command will be executed\n"
+"by default boot\n"
+;
BAREBOX_CMD_START(login)
.cmd = do_login,