From 89eaef025376339ef25d07cdc4748920fceaa968 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 12 Jan 2010 18:16:45 +1100 Subject: s4:heimdal: import lorikeet-heimdal-201001120029 (commit a5e675fed7c5db8a7370b77ed0bfa724196aa84d) --- source4/heimdal/lib/hcrypto/ui.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source4/heimdal/lib/hcrypto/ui.c') diff --git a/source4/heimdal/lib/hcrypto/ui.c b/source4/heimdal/lib/hcrypto/ui.c index ca8c8442b5..f6f8a1ffe2 100644 --- a/source4/heimdal/lib/hcrypto/ui.c +++ b/source4/heimdal/lib/hcrypto/ui.c @@ -37,10 +37,15 @@ #include #include #include +#ifdef HAVE_TERMIOS_H #include +#endif #include #include +#ifdef HAVE_CONIO_H +#include +#endif static sig_atomic_t intr_flag; @@ -50,6 +55,53 @@ intr(int sig) intr_flag++; } +#ifdef HAVE_CONIO_H + +/* + * Windows does console slightly different then then unix case. + */ + +static int +read_string(const char *preprompt, const char *prompt, + char *buf, size_t len, int echo) +{ + int of = 0; + int c; + char *p; + void (*oldsigintr)(int); + + _cprintf("%s%s", preprompt, prompt); + + oldsigintr = signal(SIGINT, intr); + + p = buf; + while(intr_flag == 0){ + c = ((echo)? _getche(): _getch()); + if(c == '\n') + break; + if(of == 0) + *p++ = c; + of = (p == buf + len); + } + if(of) + p--; + *p = 0; + + if(echo == 0){ + printf("\n"); + } + + signal(SIGINT, oldsigintr); + + if(intr_flag) + return -2; + if(of) + return -1; + return 0; +} + +#else /* !HAVE_CONIO_H */ + #ifndef NSIG #define NSIG 47 #endif @@ -135,6 +187,8 @@ read_string(const char *preprompt, const char *prompt, return 0; } +#endif /* HAVE_CONIO_H */ + int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify) { -- cgit