68 HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
71 || (_write(
orig_stderr, prompt, (
unsigned int)strlen(prompt)) == -1))
77 bool is_console = (GetFileType(in) == FILE_TYPE_CHAR);
84 if (GetConsoleMode(in, &flags_save))
86 DWORD flags = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
89 flags |= ENABLE_ECHO_INPUT;
91 SetConsoleMode(in, flags);
103 winput = malloc(capacity *
sizeof(WCHAR));
109 status = ReadConsoleW(in, winput, capacity, &len, NULL);
110 WideCharToMultiByte(CP_UTF8, 0, winput, len, input, capacity, NULL, NULL);
115 status = ReadFile(in, input, capacity, &len, NULL);
127 SetConsoleMode(in, flags_save);
153open_tty(
const bool write)
156 ret = fopen(
"/dev/tty",
write ?
"w" :
"r");
159 ret =
write ? stderr : stdin;
173 if (fp != stderr && fp != stdin)
202#elif !defined(HAVE_TERMIOS_H)
203 msg(
M_FATAL,
"Sorry, but I can't get console input on this OS (%s)", prompt);
205 bool restore_tty =
false;
207 struct termios tty_tmp, tty_save;
213 if (!isatty(0) && !isatty(2))
215 int fd = open(
"/dev/tty", O_RDWR);
219 "neither stdin nor stderr are a tty device and you have neither a "
220 "controlling tty nor systemd - can't ask for '%s'. If you used --daemon, "
221 "you need to use --askpass to make passphrase-protected keys work, and you "
222 "can not use --auth-nocache.",
228 FILE *fp = open_tty(
true);
229 fprintf(fp,
"%s", prompt);
233 fp = open_tty(
false);
235 if (!echo && (tcgetattr(fileno(fp), &tty_tmp) == 0))
238 tty_tmp.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ISIG);
239 restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0);
242 if (fgets(input, capacity, fp) != NULL)
250 if (tcsetattr(fileno(fp), TCSAFLUSH, &tty_save) == -1)
void string_null_terminate(char *str, int len, int capacity)
Null-terminate a fixed-length string buffer.
void chomp(char *str)
Remove trailing newline and carriage-return characters from a string.
Buffer management functions and garbage collection.
struct _query_user query_user[QUERY_USER_NUMSLOTS]
Global variable, declared in console.c.
#define QUERY_USER_NUMSLOTS
bool query_user_exec_builtin(void)
Wrapper function enabling query_user_exec() if no alternative methods have been enabled.
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.
static SERVICE_STATUS status
int get_orig_stderr(void)
char * response
The user's response.
bool win32_service_interrupt(struct win32_signal *ws)