73 HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
76 || (_write(
orig_stderr, prompt, strlen(prompt)) == -1))
82 bool is_console = (GetFileType(in) == FILE_TYPE_CHAR);
89 if (GetConsoleMode(in, &flags_save))
91 DWORD flags = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
94 flags |= ENABLE_ECHO_INPUT;
96 SetConsoleMode(in, flags);
108 winput = malloc(capacity *
sizeof(WCHAR));
114 status = ReadConsoleW(in, winput, capacity, &len, NULL);
115 WideCharToMultiByte(CP_UTF8, 0, winput, len, input, capacity, NULL, NULL);
120 status = ReadFile(in, input, capacity, &len, NULL);
132 SetConsoleMode(in, flags_save);
212#elif defined(HAVE_TERMIOS_H)
213 bool restore_tty =
false;
214 struct termios tty_tmp, tty_save;
220 if (!isatty(0) && !isatty(2))
222 int fd = open(
"/dev/tty", O_RDWR);
226 "neither stdin nor stderr are a tty device and you have neither a "
227 "controlling tty nor systemd - can't ask for '%s'. If you used --daemon, "
228 "you need to use --askpass to make passphrase-protected keys work, and you "
229 "can not use --auth-nocache.",
235 FILE *fp = open_tty(
true);
236 fprintf(fp,
"%s", prompt);
240 fp = open_tty(
false);
242 if (!echo && (tcgetattr(fileno(fp), &tty_tmp) == 0))
245 tty_tmp.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ISIG);
246 restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0);
249 if (fgets(input, capacity, fp) != NULL)
257 if (tcsetattr(fileno(fp), TCSAFLUSH, &tty_save) == -1)
271 msg(
M_FATAL,
"Sorry, but I can't get console input on this OS (%s)", prompt);
static bool get_console_input_win32(const char *prompt, const bool echo, char *input, const int capacity)
Get input from a Windows console.
static bool get_console_input(const char *prompt, const bool echo, char *input, const int capacity)
Core function for getting input from console.