From 98841593464e1c6d0a7cd518cb32d8648c16d72d Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Thu, 15 Dec 2022 22:17:57 +0800 Subject: [PATCH] nshlib: Add login skip, invalid name ignore and password challenge to telnet login forget in the follow patches: commit 6aef469c197a4c5d7a3a8cd766ea04fccb14ed3c Author: huangjian Date: Fri Nov 4 20:37:04 2022 +0800 nshlib:judge whether nsh login username is a valid input Signed-off-by: huangjian commit 88fff23d3497de541d74325690c79c0616f31d6a Author: huangjian Date: Fri Nov 4 20:39:26 2022 +0800 nshlib:add platform skip login function Signed-off-by: huangjian commit 5a623cc9e3f51845007614de9a1e4c74c262d8e9 Author: huangjian Date: Fri Nov 4 20:35:07 2022 +0800 nshlib:add platform challenge function for nsh login Signed-off-by: huangjian Signed-off-by: Xiang Xiao --- nshlib/nsh_telnetlogin.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/nshlib/nsh_telnetlogin.c b/nshlib/nsh_telnetlogin.c index 3d9a68529..5c50ea56c 100644 --- a/nshlib/nsh_telnetlogin.c +++ b/nshlib/nsh_telnetlogin.c @@ -32,6 +32,7 @@ #include "nsh.h" #include "nsh_console.h" +#include "nshlib/nshlib.h" #ifdef CONFIG_NSH_TELNET_LOGIN @@ -161,9 +162,19 @@ static void nsh_telnettoken(FAR struct console_stdio_s *pstate, int nsh_telnetlogin(FAR struct console_stdio_s *pstate) { char username[16]; - char password[16]; + char password[128]; +#ifdef CONFIG_NSH_PLATFORM_CHALLENGE + char challenge[128]; +#endif int i; +#ifdef CONFIG_NSH_PLATFORM_SKIP_LOGIN + if (platform_skip_login() == OK) + { + return OK; + } +#endif + /* Present the NSH Telnet greeting */ fputs(g_telnetgreeting, pstate->cn_outstream); @@ -187,6 +198,17 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate) nsh_telnettoken(pstate, username, sizeof(username)); } + if (username[0] == '\0') + { + i--; + continue; + } + +#ifdef CONFIG_NSH_PLATFORM_CHALLENGE + platform_challenge(challenge, sizeof(challenge)); + fputs(challenge, pstate->cn_outstream); +#endif + /* Ask for the login password */ fputs(g_passwordprompt, pstate->cn_outstream); @@ -206,8 +228,14 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate) #if defined(CONFIG_NSH_LOGIN_PASSWD) if (PASSWORD_VERIFY_MATCH(passwd_verify(username, password))) #elif defined(CONFIG_NSH_LOGIN_PLATFORM) +# ifdef CONFIG_NSH_PLATFORM_CHALLENGE + if (PASSWORD_VERIFY_MATCH(platform_user_verify(username, + challenge, + password))) +# else if (PASSWORD_VERIFY_MATCH(platform_user_verify(username, password))) +# endif #elif defined(CONFIG_NSH_LOGIN_FIXED) if (strcmp(password, CONFIG_NSH_LOGIN_PASSWORD) == 0 && strcmp(username, CONFIG_NSH_LOGIN_USERNAME) == 0)