summaryrefslogtreecommitdiffstats
path: root/common
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 /common
parentfde45de7351264cd27a9024ea2b6620d170b5269 (diff)
downloadbarebox-c78ef640cd18847a962d3e1fdb84ad6c265b0deb.tar.gz
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 'common')
-rw-r--r--common/password.c87
1 files changed, 48 insertions, 39 deletions
diff --git a/common/password.c b/common/password.c
index 20e398f..ece7704 100644
--- a/common/password.c
+++ b/common/password.c
@@ -27,6 +27,7 @@
#include <digest.h>
#include <malloc.h>
#include <xfuncs.h>
+#include <clock.h>
#if defined(CONFIG_PASSWD_SUM_MD5)
#define PASSWD_SUM "md5"
@@ -36,56 +37,64 @@
#define PASSWD_SUM "sha256"
#endif
-int password(unsigned char *passwd, size_t length, int flags)
+int password(unsigned char *passwd, size_t length, int flags, int timeout)
{
unsigned char *buf = passwd;
int pos = 0;
unsigned char ch;
+ uint64_t start, second;
if (!passwd)
return -EINVAL;
+ start = get_time_ns();
+ second = start;
+
do {
- ch = getc();
-
- switch (ch) {
- case '\r':
- case '\n':
- *buf = '\0';
- puts("\r\n");
- return pos;
- case '\0':
- case '\t':
- continue;
- case CTL_CH('c'):
- passwd[0] = '\0';
- puts("\r\n");
- return 0;
- case CTL_CH('h'):
- case KEY_DEL7:
- case KEY_DEL:
- if (flags & STAR && pos > 0)
- puts("\b \b");
- *buf = '\0';
- buf--;
- pos--;
- continue;
- default:
- if (pos < length - 1) {
- if (flags & STAR)
- putchar('*');
- else if (flags & CLEAR)
- putchar(ch);
-
- *buf = ch;
- buf++;
- pos++;
- } else {
- if (flags & STAR)
- putchar('\a');
+ if (tstc()) {
+ ch = getc();
+
+ switch (ch) {
+ case '\r':
+ case '\n':
+ *buf = '\0';
+ puts("\r\n");
+ return pos;
+ case '\0':
+ case '\t':
+ continue;
+ case CTL_CH('c'):
+ passwd[0] = '\0';
+ puts("\r\n");
+ return 0;
+ case CTL_CH('h'):
+ case KEY_DEL7:
+ case KEY_DEL:
+ if (flags & STAR && pos > 0)
+ puts("\b \b");
+ *buf = '\0';
+ buf--;
+ pos--;
+ continue;
+ default:
+ if (pos < length - 1) {
+ if (flags & STAR)
+ putchar('*');
+ else if (flags & CLEAR)
+ putchar(ch);
+
+ *buf = ch;
+ buf++;
+ pos++;
+ } else {
+ if (flags & STAR)
+ putchar('\a');
+ }
}
}
- } while(1);
+ } while (!is_timeout(start, timeout * SECOND) || timeout == 0);
+
+ return -1;
}
EXPORT_SYMBOL(password);