summaryrefslogtreecommitdiffstats
path: root/src/appl/gssftp/ftp/getpass.c
diff options
context:
space:
mode:
authorDanilo Almeida <dalmeida@mit.edu>2001-07-24 01:07:16 +0000
committerDanilo Almeida <dalmeida@mit.edu>2001-07-24 01:07:16 +0000
commit226d2461a7ddf2384faad5c20284fa80c5430ea6 (patch)
tree810f544e8e03967ab4449a44cdf60030bb42fe7c /src/appl/gssftp/ftp/getpass.c
parent27dee9d9f20638ec3de1170262ac1ba583776b1d (diff)
downloadkrb5-226d2461a7ddf2384faad5c20284fa80c5430ea6.tar.gz
krb5-226d2461a7ddf2384faad5c20284fa80c5430ea6.tar.xz
krb5-226d2461a7ddf2384faad5c20284fa80c5430ea6.zip
* Makefile.in, cmds.c, ftp.c, ftp_var.h, getpass.c, glob.c,
main.c, ruserpass.c, secure.c, secure.h: Quick and dirty Win32 port. Changes include using sockets more portably; changing the method of getting username, home directory, and temporary filenames; adding password reading code for Win32; directory enumeration via FindNextFile() rather than readdir(); removing OUT labels (which appear to cause problems with MSVC++ 6.0). Since ANSI C, assume we have stdarg.h. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13628 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/appl/gssftp/ftp/getpass.c')
-rw-r--r--src/appl/gssftp/ftp/getpass.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/appl/gssftp/ftp/getpass.c b/src/appl/gssftp/ftp/getpass.c
index 622a32de9..3f2500481 100644
--- a/src/appl/gssftp/ftp/getpass.c
+++ b/src/appl/gssftp/ftp/getpass.c
@@ -8,6 +8,84 @@
static char sccsid[] = "@(#)getpass.c 1.1 90/04/28 SMI"; /* from UCB 5.4 3/7/86 */
#endif /* not lint */
+#ifdef _WIN32
+#include <io.h>
+#include <windows.h>
+#include <stdio.h>
+
+static DWORD old_mode;
+static HANDLE cons_handle;
+
+BOOL WINAPI
+GetPassConsoleControlHandler(DWORD dwCtrlType)
+{
+ switch(dwCtrlType){
+ case CTRL_BREAK_EVENT:
+ case CTRL_C_EVENT:
+ printf("Interrupt\n");
+ fflush(stdout);
+ (void) SetConsoleMode(cons_handle, old_mode);
+ ExitProcess(-1);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+char *
+mygetpass(char *prompt)
+{
+ DWORD new_mode;
+ char *ptr;
+ int scratchchar;
+ static char password[50+1];
+ int pwsize = sizeof(password);
+
+ cons_handle = GetStdHandle(STD_INPUT_HANDLE);
+ if (cons_handle == INVALID_HANDLE_VALUE)
+ return NULL;
+ if (!GetConsoleMode(cons_handle, &old_mode))
+ return NULL;
+
+ new_mode = old_mode;
+ new_mode |= ( ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT );
+ new_mode &= ~( ENABLE_ECHO_INPUT );
+
+ if (!SetConsoleMode(cons_handle, new_mode))
+ return NULL;
+
+ SetConsoleCtrlHandler(&GetPassConsoleControlHandler, TRUE);
+
+ (void) fputs(prompt, stdout);
+ (void) fflush(stdout);
+ (void) memset(password, 0, pwsize);
+
+ if (fgets(password, pwsize, stdin) == NULL) {
+ if (ferror(stdin))
+ goto out;
+ (void) putchar('\n');
+ }
+ else {
+ (void) putchar('\n');
+
+ if ((ptr = strchr(password, '\n')))
+ *ptr = '\0';
+ else /* need to flush */
+ do {
+ scratchchar = getchar();
+ } while (scratchchar != EOF && scratchchar != '\n');
+ }
+
+out:
+ (void) SetConsoleMode(cons_handle, old_mode);
+ SetConsoleCtrlHandler(&GetPassConsoleControlHandler, FALSE);
+
+ return password;
+}
+
+#else /* !_WIN32 */
+
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -76,3 +154,5 @@ char *prompt;
(void) fclose(fi);
return(pbuf);
}
+
+#endif /* !_WIN32 */