|
27 | 27 | #include <string.h>
|
28 | 28 | #include <ctype.h>
|
29 | 29 | #include <unistd.h>
|
| 30 | +#include <termios.h> |
30 | 31 |
|
31 | 32 | #include "fsutils/passwd.h"
|
32 | 33 | #ifdef CONFIG_NSH_CLE
|
@@ -150,6 +151,9 @@ int nsh_login(FAR struct console_stdio_s *pstate)
|
150 | 151 | #endif
|
151 | 152 | int ret;
|
152 | 153 | int i;
|
| 154 | +#ifdef CONFIG_SERIAL_TERMIOS |
| 155 | + struct termios cfg; |
| 156 | +#endif |
153 | 157 |
|
154 | 158 | #ifdef CONFIG_NSH_PLATFORM_SKIP_LOGIN
|
155 | 159 | if (platform_skip_login() == OK)
|
@@ -193,9 +197,37 @@ int nsh_login(FAR struct console_stdio_s *pstate)
|
193 | 197 |
|
194 | 198 | write(OUTFD(pstate), g_passwordprompt, strlen(g_passwordprompt));
|
195 | 199 |
|
| 200 | + /* Disable ECHO if its a tty device */ |
| 201 | + |
| 202 | +#ifdef CONFIG_SERIAL_TERMIOS |
| 203 | + if (isatty(INFD(pstate))) |
| 204 | + { |
| 205 | + if (tcgetattr(INFD(pstate), &cfg) == 0) |
| 206 | + { |
| 207 | + cfg.c_iflag &= ~ECHO; |
| 208 | + tcsetattr(INFD(pstate), TCSANOW, &cfg); |
| 209 | + } |
| 210 | + } |
| 211 | +#endif |
| 212 | + |
196 | 213 | password[0] = '\0';
|
197 |
| - if (readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN, |
198 |
| - INFD(pstate), -1) > 0) |
| 214 | + ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN, |
| 215 | + INFD(pstate), -1); |
| 216 | + |
| 217 | + /* Enable echo again after password */ |
| 218 | + |
| 219 | +#ifdef CONFIG_SERIAL_TERMIOS |
| 220 | + if (isatty(INFD(pstate))) |
| 221 | + { |
| 222 | + if (tcgetattr(INFD(pstate), &cfg) == 0) |
| 223 | + { |
| 224 | + cfg.c_iflag |= ECHO; |
| 225 | + tcsetattr(INFD(pstate), TCSANOW, &cfg); |
| 226 | + } |
| 227 | + } |
| 228 | +#endif |
| 229 | + |
| 230 | + if (ret > 0) |
199 | 231 | {
|
200 | 232 | /* Parse out the password */
|
201 | 233 |
|
|
0 commit comments