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);
83 if (GetConsoleMode(in, &flags_save))
85 DWORD flags = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
88 flags |= ENABLE_ECHO_INPUT;
90 SetConsoleMode(in, flags);
102 WCHAR *winput = malloc(capacity *
sizeof(WCHAR));
108 status = ReadConsoleW(in, winput, capacity, &len, NULL);
109 WideCharToMultiByte(CP_UTF8, 0, winput, len, input, capacity, NULL, NULL);
114 status = ReadFile(in, input, capacity, &len, NULL);
126 SetConsoleMode(in, flags_save);
149open_tty(
const bool write)
152 ret = fopen(
"/dev/tty",
write ?
"w" :
"r");
155 ret =
write ? stderr : stdin;
169 if (fp != stderr && fp != stdin)
199 bool restore_tty =
false;
201 struct termios tty_tmp, tty_save;
207 if (!isatty(0) && !isatty(2))
209 int fd = open(
"/dev/tty", O_RDWR);
213 "neither stdin nor stderr are a tty device and you have neither a "
214 "controlling tty nor systemd - can't ask for '%s'. If you used --daemon, "
215 "you need to use --askpass to make passphrase-protected keys work, and you "
216 "can not use --auth-nocache.",
222 FILE *fp = open_tty(
true);
223 fprintf(fp,
"%s", prompt);
227 fp = open_tty(
false);
229 if (!echo && (tcgetattr(fileno(fp), &tty_tmp) == 0))
232 tty_tmp.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ISIG);
233 restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0);
236 if (fgets(input, capacity, fp) != NULL)
244 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)