aboutsummaryrefslogtreecommitdiff
path: root/src/clients
diff options
context:
space:
mode:
authorRichard Basch <probe@mit.edu>1997-02-13 19:34:42 +0000
committerRichard Basch <probe@mit.edu>1997-02-13 19:34:42 +0000
commita6f1af41b81206dde3d3fdf528aae304e027fe1d (patch)
treea3529116c8b115e9305b396343b179dd74b16f30 /src/clients
parenta7827d6401791653cb12ceba2ff8052964e411f1 (diff)
downloadkrb5-a6f1af41b81206dde3d3fdf528aae304e027fe1d.zip
krb5-a6f1af41b81206dde3d3fdf528aae304e027fe1d.tar.gz
krb5-a6f1af41b81206dde3d3fdf528aae304e027fe1d.tar.bz2
kinit.c: Added krb5_read_password implementation for win32 console app
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9860 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/clients')
-rw-r--r--src/clients/kinit/ChangeLog4
-rw-r--r--src/clients/kinit/kinit.c88
2 files changed, 92 insertions, 0 deletions
diff --git a/src/clients/kinit/ChangeLog b/src/clients/kinit/ChangeLog
index 20a2466..6e73a85 100644
--- a/src/clients/kinit/ChangeLog
+++ b/src/clients/kinit/ChangeLog
@@ -1,3 +1,7 @@
+Thu Feb 13 14:27:41 1997 Richard Basch <basch@lehman.com>
+
+ * kinit.c: Added krb5_read_password implementation for win32 console.
+
Sat Feb 8 15:37:39 1997 Richard Basch <basch@lehman.com>
* Makefile.in:
diff --git a/src/clients/kinit/kinit.c b/src/clients/kinit/kinit.c
index 42eabf6..0cf45da 100644
--- a/src/clients/kinit/kinit.c
+++ b/src/clients/kinit/kinit.c
@@ -439,3 +439,91 @@ cleanup:
return retval;
}
+
+#ifdef _WIN32
+krb5_error_code
+krb5_read_password(
+ krb5_context context,
+ const char * prompt,
+ const char * prompt2,
+ char * password,
+ int * pwsize)
+{
+ HANDLE handle;
+ DWORD old_mode, new_mode;
+ char *tmpstr = 0;
+ char *ptr;
+ int scratchchar;
+ krb5_error_code errcode = 0;
+
+ handle = GetStdHandle(STD_INPUT_HANDLE);
+ if (handle == INVALID_HANDLE_VALUE)
+ return ENOTTY;
+ if (!GetConsoleMode(handle, &old_mode))
+ return ENOTTY;
+
+ new_mode = old_mode;
+ new_mode |= ( ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT );
+ new_mode &= ~( ENABLE_ECHO_INPUT );
+
+ if (!SetConsoleMode(handle, new_mode))
+ return ENOTTY;
+
+ (void) fputs(prompt, stdout);
+ (void) fflush(stdout);
+ (void) memset(password, 0, *pwsize);
+
+ if (fgets(password, *pwsize, stdin) == NULL) {
+ (void) putchar('\n');
+ errcode = KRB5_LIBOS_CANTREADPWD;
+ goto cleanup;
+ }
+ (void) putchar('\n');
+
+ if ((ptr = strchr(password, '\n')))
+ *ptr = '\0';
+ else /* need to flush */
+ do {
+ scratchchar = getchar();
+ } while (scratchchar != EOF && scratchchar != '\n');
+
+ if (prompt2) {
+ if (! (tmpstr = (char *)malloc(*pwsize))) {
+ errcode = ENOMEM;
+ goto cleanup;
+ }
+ (void) fputs(prompt2, stdout);
+ (void) fflush(stdout);
+ if (fgets(tmpstr, *pwsize, stdin) == NULL) {
+ (void) putchar('\n');
+ errcode = KRB5_LIBOS_CANTREADPWD;
+ goto cleanup;
+ }
+ (void) putchar('\n');
+
+ if ((ptr = strchr(tmpstr, '\n')))
+ *ptr = '\0';
+ else /* need to flush */
+ do {
+ scratchchar = getchar();
+ } while (scratchchar != EOF && scratchchar != '\n');
+
+ if (strncmp(password, tmpstr, *pwsize)) {
+ errcode = KRB5_LIBOS_BADPWDMATCH;
+ goto cleanup;
+ }
+ }
+
+cleanup:
+ (void) SetConsoleMode(handle, old_mode);
+ if (tmpstr) {
+ (void) memset(tmpstr, 0, *pwsize);
+ (void) free(tmpstr);
+ }
+ if (errcode)
+ (void) memset(password, 0, *pwsize);
+ else
+ *pwsize = strlen(password);
+ return errcode;
+}
+#endif