You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/12/04 11:25:02 UTC
[nuttx-apps] branch master updated (05eadd1bd -> 6aef469c1)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
from 05eadd1bd nxplayer: add mp3 offload playback demo
new 5a623cc9e nshlib:add platform challenge function for nsh login
new 88fff23d3 nshlib:add platform skip login function
new 6aef469c1 nshlib:judge whether nsh login username is a valid input
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
include/nshlib/nshlib.h | 25 +++++++++++++++++++++++++
nshlib/Kconfig | 33 +++++++++++++++++++++++++++++++++
nshlib/nsh_login.c | 28 +++++++++++++++++++++++++++-
nshlib/nsh_stdlogin.c | 26 +++++++++++++++++++++++++-
4 files changed, 110 insertions(+), 2 deletions(-)
[nuttx-apps] 03/03: nshlib:judge whether nsh login username is a valid input
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 6aef469c197a4c5d7a3a8cd766ea04fccb14ed3c
Author: huangjian <hu...@xiaomi.com>
AuthorDate: Fri Nov 4 20:37:04 2022 +0800
nshlib:judge whether nsh login username is a valid input
Signed-off-by: huangjian <hu...@xiaomi.com>
---
nshlib/nsh_login.c | 6 ++++++
nshlib/nsh_stdlogin.c | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/nshlib/nsh_login.c b/nshlib/nsh_login.c
index 3e7e370ca..9793837c4 100644
--- a/nshlib/nsh_login.c
+++ b/nshlib/nsh_login.c
@@ -178,6 +178,12 @@ int nsh_login(FAR struct console_stdio_s *pstate)
nsh_token(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);
diff --git a/nshlib/nsh_stdlogin.c b/nshlib/nsh_stdlogin.c
index d4f93f599..0ae7ae43c 100644
--- a/nshlib/nsh_stdlogin.c
+++ b/nshlib/nsh_stdlogin.c
@@ -187,6 +187,12 @@ int nsh_stdlogin(FAR struct console_stdio_s *pstate)
nsh_stdtoken(pstate, username, sizeof(username));
}
+ if (username[0] == '\0')
+ {
+ i--;
+ continue;
+ }
+
#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
platform_challenge(challenge, sizeof(challenge));
printf("%s", challenge);
[nuttx-apps] 02/03: nshlib:add platform skip login function
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 88fff23d3497de541d74325690c79c0616f31d6a
Author: huangjian <hu...@xiaomi.com>
AuthorDate: Fri Nov 4 20:39:26 2022 +0800
nshlib:add platform skip login function
Signed-off-by: huangjian <hu...@xiaomi.com>
---
nshlib/Kconfig | 11 +++++++++++
nshlib/nsh_login.c | 7 +++++++
nshlib/nsh_stdlogin.c | 7 +++++++
3 files changed, 25 insertions(+)
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index a0ac2a0ec..6a8a14362 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -1285,6 +1285,17 @@ config NSH_PLATFORM_CHALLENGE
which may be included like:
#include "nshlib/nshlib.h"
+
+config NSH_PLATFORM_SKIP_LOGIN
+ bool "Platform skip login"
+ default n
+ ---help---
+ If this option is selected, the NSH will call into platform-specific
+ logic in order to skip login. The function prototype for this
+ call is:
+
+ int platform_skip_login(void);
+
endif # NSH_LOGIN
endif # NSH_LIBRARY
endmenu # NSH Library
diff --git a/nshlib/nsh_login.c b/nshlib/nsh_login.c
index 8f3b48497..3e7e370ca 100644
--- a/nshlib/nsh_login.c
+++ b/nshlib/nsh_login.c
@@ -150,6 +150,13 @@ int nsh_login(FAR struct console_stdio_s *pstate)
int ret;
int i;
+#ifdef CONFIG_NSH_PLATFORM_SKIP_LOGIN
+ if (platform_skip_login() == OK)
+ {
+ return OK;
+ }
+#endif
+
/* Loop for the configured number of retries */
for (i = 0; i < CONFIG_NSH_LOGIN_FAILCOUNT; i++)
diff --git a/nshlib/nsh_stdlogin.c b/nshlib/nsh_stdlogin.c
index 4e79acf39..d4f93f599 100644
--- a/nshlib/nsh_stdlogin.c
+++ b/nshlib/nsh_stdlogin.c
@@ -150,6 +150,13 @@ int nsh_stdlogin(FAR struct console_stdio_s *pstate)
int ret;
int i;
+#ifdef CONFIG_NSH_PLATFORM_SKIP_LOGIN
+ if (platform_skip_login() == OK)
+ {
+ return OK;
+ }
+#endif
+
/* Loop for the configured number of retries */
for (i = 0; i < CONFIG_NSH_LOGIN_FAILCOUNT; i++)
[nuttx-apps] 01/03: nshlib:add platform challenge function for nsh login
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 5a623cc9e3f51845007614de9a1e4c74c262d8e9
Author: huangjian <hu...@xiaomi.com>
AuthorDate: Fri Nov 4 20:35:07 2022 +0800
nshlib:add platform challenge function for nsh login
Signed-off-by: huangjian <hu...@xiaomi.com>
---
include/nshlib/nshlib.h | 25 +++++++++++++++++++++++++
nshlib/Kconfig | 22 ++++++++++++++++++++++
nshlib/nsh_login.c | 15 ++++++++++++++-
nshlib/nsh_stdlogin.c | 13 ++++++++++++-
4 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/include/nshlib/nshlib.h b/include/nshlib/nshlib.h
index 5d1157141..adadb2b52 100644
--- a/include/nshlib/nshlib.h
+++ b/include/nshlib/nshlib.h
@@ -192,6 +192,26 @@ int nsh_telnetstart(sa_family_t family);
void platform_motd(FAR char *buffer, size_t buflen);
#endif
+/****************************************************************************
+ * Name: platform_challenge
+ *
+ * Description:
+ * If CONFIG_NSH_PLATFORM_CHALLENGE is defined, then platform-specific
+ * logic must provide this function in order get the challenge.
+ *
+ * Input Parameters:
+ * buffer - A caller allocated buffer in which to receive the challenge
+ * buflen - The length in bytes of the caller allocated buffer
+ *
+ * Returned value:
+ * None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
+void platform_challenge(FAR char *buffer, size_t buflen);
+#endif
+
/****************************************************************************
* Name: platform_user_verify
*
@@ -211,8 +231,13 @@ void platform_motd(FAR char *buffer, size_t buflen);
****************************************************************************/
#ifdef CONFIG_NSH_LOGIN_PLATFORM
+#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
+int platform_user_verify(FAR const char *username, FAR const char *challenge,
+ FAR const char *password);
+#else
int platform_user_verify(FAR const char *username, FAR const char *password);
#endif
+#endif
/****************************************************************************
* Name: nsh_system
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index 98993e317..a0ac2a0ec 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -1263,6 +1263,28 @@ config NSH_LOGIN_FAILCOUNT
---help---
Number of login retry attempts.
+config NSH_PLATFORM_CHALLENGE
+ bool "Platform challenge"
+ default n
+ depends on NSH_LOGIN_PLATFORM
+ ---help---
+ If this option is selected, the NSH will call into platform-specific
+ logic in order to get the challenge. The function prototype for this
+ call is:
+
+ void platform_challenge(FAR char *buffer, size_t buflen);
+
+ Where buffer is the location to return the challenge and buflen is the
+ length of that buffer. The maximum size of the buffer is determined
+ by NSH_FILEIOSIZE. An appropriate location for the
+ implementation of platform_challenge would be within apps/platform/<board>.
+
+ One newline will be inserted after the platform-supplied message.
+
+ platform_challenge() is prototyped and described in apps/include/nshlib/nshlib.h
+ which may be included like:
+
+ #include "nshlib/nshlib.h"
endif # NSH_LOGIN
endif # NSH_LIBRARY
endmenu # NSH Library
diff --git a/nshlib/nsh_login.c b/nshlib/nsh_login.c
index 37dda4d85..8f3b48497 100644
--- a/nshlib/nsh_login.c
+++ b/nshlib/nsh_login.c
@@ -143,7 +143,10 @@ static void nsh_token(FAR struct console_stdio_s *pstate,
int nsh_login(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 ret;
int i;
@@ -168,6 +171,12 @@ int nsh_login(FAR struct console_stdio_s *pstate)
nsh_token(pstate, username, sizeof(username));
}
+#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
+ platform_challenge(challenge, sizeof(challenge));
+ fputs(challenge, pstate->cn_outstream);
+ fflush(pstate->cn_outstream);
+#endif
+
/* Ask for the login password */
fputs(g_passwordprompt, pstate->cn_outstream);
@@ -188,7 +197,11 @@ int nsh_login(FAR struct console_stdio_s *pstate)
if (PASSWORD_VERIFY_MATCH(ret))
#elif defined(CONFIG_NSH_LOGIN_PLATFORM)
+#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
+ ret = platform_user_verify(username, challenge, password);
+#else
ret = platform_user_verify(username, password);
+#endif
if (PASSWORD_VERIFY_MATCH(ret))
#elif defined(CONFIG_NSH_LOGIN_FIXED)
diff --git a/nshlib/nsh_stdlogin.c b/nshlib/nsh_stdlogin.c
index b4d40e1e6..4e79acf39 100644
--- a/nshlib/nsh_stdlogin.c
+++ b/nshlib/nsh_stdlogin.c
@@ -143,7 +143,10 @@ static void nsh_stdtoken(FAR struct console_stdio_s *pstate,
int nsh_stdlogin(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 ret;
int i;
@@ -177,6 +180,10 @@ int nsh_stdlogin(FAR struct console_stdio_s *pstate)
nsh_stdtoken(pstate, username, sizeof(username));
}
+#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
+ platform_challenge(challenge, sizeof(challenge));
+ printf("%s", challenge);
+#endif
/* Ask for the login password */
printf("%s", g_passwordprompt);
@@ -195,7 +202,11 @@ int nsh_stdlogin(FAR struct console_stdio_s *pstate)
if (PASSWORD_VERIFY_MATCH(ret))
#elif defined(CONFIG_NSH_LOGIN_PLATFORM)
+#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
+ ret = platform_user_verify(username, challenge, password);
+#else
ret = platform_user_verify(username, password);
+#endif
if (PASSWORD_VERIFY_MATCH(ret))
#elif defined(CONFIG_NSH_LOGIN_FIXED)