2010-09-07 19:15:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2010 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
complete: add empty complete support
for cpuinfo, clear, dhcp, false, login, lsmod, meminfo, passwd, pwd, reginfo,
reset, true, usb, version
for mach-imx and mach-mxs: dump_clocks
for u_serial: mycdev
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2011-06-07 09:32:02 +00:00
|
|
|
#include <complete.h>
|
2010-09-07 19:15:09 +00:00
|
|
|
#include <password.h>
|
2011-08-10 10:47:08 +00:00
|
|
|
#include <getopt.h>
|
2013-09-16 17:49:57 +00:00
|
|
|
#include <environment.h>
|
|
|
|
#include <globalvar.h>
|
|
|
|
#include <magicvar.h>
|
|
|
|
#include <init.h>
|
2013-09-16 17:49:58 +00:00
|
|
|
#include <console.h>
|
2010-09-07 19:15:09 +00:00
|
|
|
|
|
|
|
#define PASSWD_MAX_LENGTH (128 + 1)
|
|
|
|
|
|
|
|
#if defined(CONFIG_PASSWD_MODE_STAR)
|
|
|
|
#define LOGIN_MODE STAR
|
|
|
|
#elif defined(CONFIG_PASSWD_MODE_CLEAR)
|
|
|
|
#define LOGIN_MODE CLEAR
|
|
|
|
#else
|
|
|
|
#define LOGIN_MODE HIDE
|
|
|
|
#endif
|
|
|
|
|
2013-09-16 17:49:57 +00:00
|
|
|
static int login_timeout = 0;
|
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_login(int argc, char *argv[])
|
2010-09-07 19:15:09 +00:00
|
|
|
{
|
|
|
|
unsigned char passwd[PASSWD_MAX_LENGTH];
|
2011-08-10 10:47:08 +00:00
|
|
|
int passwd_len, opt;
|
2013-09-16 17:49:57 +00:00
|
|
|
int timeout = login_timeout;
|
2011-08-10 10:47:08 +00:00
|
|
|
char *timeout_cmd = "boot";
|
2010-09-07 19:15:09 +00:00
|
|
|
|
2013-09-16 17:49:58 +00:00
|
|
|
console_allow_input(true);
|
2010-09-07 19:15:09 +00:00
|
|
|
if (!is_passwd_enable()) {
|
|
|
|
puts("login: password not set\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-10 10:47:08 +00:00
|
|
|
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];
|
|
|
|
|
2010-09-07 19:15:09 +00:00
|
|
|
do {
|
|
|
|
puts("Password: ");
|
2011-08-10 10:47:08 +00:00
|
|
|
passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout);
|
|
|
|
|
2013-09-16 17:49:58 +00:00
|
|
|
if (passwd_len < 0) {
|
|
|
|
console_allow_input(false);
|
2011-08-10 10:47:08 +00:00
|
|
|
run_command(timeout_cmd, 0);
|
2013-09-16 17:49:58 +00:00
|
|
|
}
|
2010-09-07 19:15:09 +00:00
|
|
|
|
|
|
|
if (check_passwd(passwd, passwd_len))
|
|
|
|
return 0;
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const __maybe_unused char cmd_login_help[] =
|
2011-09-24 07:04:46 +00:00
|
|
|
"Usage: login [-t timeout [<command>]]\n"
|
|
|
|
"If a timeout is specified and expired the command will be executed;\n"
|
|
|
|
"\"boot\" by default\n"
|
2011-08-10 10:47:08 +00:00
|
|
|
;
|
2010-09-07 19:15:09 +00:00
|
|
|
|
|
|
|
BAREBOX_CMD_START(login)
|
|
|
|
.cmd = do_login,
|
|
|
|
.usage = "login",
|
|
|
|
BAREBOX_CMD_HELP(cmd_login_help)
|
complete: add empty complete support
for cpuinfo, clear, dhcp, false, login, lsmod, meminfo, passwd, pwd, reginfo,
reset, true, usb, version
for mach-imx and mach-mxs: dump_clocks
for u_serial: mycdev
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2011-06-07 09:32:02 +00:00
|
|
|
BAREBOX_CMD_COMPLETE(empty_complete)
|
2010-09-07 19:15:09 +00:00
|
|
|
BAREBOX_CMD_END
|
2013-09-16 17:49:57 +00:00
|
|
|
|
|
|
|
static int login_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");
|