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 9bb730fb6b75145d9748cfe3995a7904a4be2ae8 Author: Huang Qi <[email protected]> AuthorDate: Fri Mar 3 14:19:24 2023 +0800 nsh: Don't echo password during login Signed-off-by: Huang Qi <[email protected]> --- nshlib/nsh_login.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh_login.c b/nshlib/nsh_login.c index 7edb9676b..c1feb0d54 100644 --- a/nshlib/nsh_login.c +++ b/nshlib/nsh_login.c @@ -27,6 +27,7 @@ #include <string.h> #include <ctype.h> #include <unistd.h> +#include <termios.h> #include "fsutils/passwd.h" #ifdef CONFIG_NSH_CLE @@ -150,6 +151,9 @@ int nsh_login(FAR struct console_stdio_s *pstate) #endif int ret; int i; +#ifdef CONFIG_SERIAL_TERMIOS + struct termios cfg; +#endif #ifdef CONFIG_NSH_PLATFORM_SKIP_LOGIN if (platform_skip_login() == OK) @@ -193,9 +197,37 @@ int nsh_login(FAR struct console_stdio_s *pstate) write(OUTFD(pstate), g_passwordprompt, strlen(g_passwordprompt)); + /* Disable ECHO if its a tty device */ + +#ifdef CONFIG_SERIAL_TERMIOS + if (isatty(INFD(pstate))) + { + if (tcgetattr(INFD(pstate), &cfg) == 0) + { + cfg.c_iflag &= ~ECHO; + tcsetattr(INFD(pstate), TCSANOW, &cfg); + } + } +#endif + password[0] = '\0'; - if (readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN, - INFD(pstate), -1) > 0) + ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN, + INFD(pstate), -1); + + /* Enable echo again after password */ + +#ifdef CONFIG_SERIAL_TERMIOS + if (isatty(INFD(pstate))) + { + if (tcgetattr(INFD(pstate), &cfg) == 0) + { + cfg.c_iflag |= ECHO; + tcsetattr(INFD(pstate), TCSANOW, &cfg); + } + } +#endif + + if (ret > 0) { /* Parse out the password */
