From: Richard Basch Date: Tue, 25 Feb 1997 06:16:30 +0000 (+0000) Subject: win-pwd.rc: Windows dialog information for password prompting X-Git-Tag: krb5-1.1-beta1~1220 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a5411452348001e4992f6fd13536e92928e3641;p=krb5.git win-pwd.rc: Windows dialog information for password prompting win-pwd.h: supporting definitions for Windows dialog read_pwd.c: Support Windows dialog & console-mode input for krb5_read_password Makefile.in: Link in win-pwd.obj (win32) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9971 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 9861fbf55..c2c6e115c 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,9 @@ +Tue Feb 25 00:29:33 1997 Richard Basch + + * read_pwd.c: Define Windows interface for krb5_read_password + * win-pwd.rc: Resource file for Windows password dialog box + * win-pwd.h: Support definitions for Windows krb5_read_password + Sat Feb 22 22:41:02 1997 Richard Basch * Makefile.in: Use some of the new library list build rules in diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index c75b86ada..f5efb6621 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -5,7 +5,7 @@ PROG_RPATH=$(KRB5_LIBDIR) ##DOS##BUILDTOP = ..\..\.. ##DOS##PREFIXDIR=os -##DOS##OBJFILE=..\$(MYNAME).lst +##DOS##OBJFILE=..\$(PREFIXDIR).lst ##WIN16##LIBNAME=..\krb5.lib STLIBOBJS= \ @@ -128,7 +128,12 @@ SRCS= \ $(srcdir)/ustime.c \ $(srcdir)/write_msg.c -##DOS##LIBOBJS = $(OBJS) +##WIN16##LIBOBJS = $(OBJS) +##WIN32##LIBOBJS = $(OBJS) win-pwd.obj + +##WIN32##.rc.obj: +##WIN32## $(RC) $(CPPFLAGS) /r $** +##WIN32## $(CVTRES) /nologo /out:$@ $*.res all-unix:: all-libobjs clean-unix:: clean-libobjs diff --git a/src/lib/krb5/os/read_pwd.c b/src/lib/krb5/os/read_pwd.c index 202b1f9f4..4ce84f50d 100644 --- a/src/lib/krb5/os/read_pwd.c +++ b/src/lib/krb5/os/read_pwd.c @@ -25,7 +25,9 @@ */ #include "k5-int.h" -#if !defined(_MSDOS) && !defined(_WIN32) && !defined(_MACINTOSH) + +#if defined(unix) || defined(_AIX) +#define DEFINED_KRB5_READ_PASSWORD #include #include #include @@ -155,11 +157,217 @@ cleanup: *size_return = strlen(return_pwd); return errcode; } -#else /* MSDOS */ -/* Don't expect to be called, just define it for sanity and the linker. -*/ +#endif -krb5_error_code +#ifdef _WIN32 /* defined(_MSDOS) || defined(_WIN32) */ +#define DEFINED_KRB5_READ_PASSWORD + +#include +#include "win-pwd.h" + +typedef struct { + char *pwd_prompt; + char *pwd_prompt2; + char *pwd_return_pwd; + int *pwd_size_return; +} pwd_params; + +void center_dialog(HWND hwnd) +{ + int scrwidth, scrheight; + int dlgwidth, dlgheight; + RECT r; + HDC hdc; + + if (hwnd == NULL) + return; + + GetWindowRect(hwnd, &r); + dlgwidth = r.right - r.left; + dlgheight = r.bottom - r.top ; + hdc = GetDC(NULL); + scrwidth = GetDeviceCaps(hdc, HORZRES); + scrheight = GetDeviceCaps(hdc, VERTRES); + ReleaseDC(NULL, hdc); + r.left = (scrwidth - dlgwidth) / 2; + r.top = (scrheight - dlgheight) / 2; + MoveWindow(hwnd, r.left, r.top, dlgwidth, dlgheight, TRUE); +} + +#ifdef _WIN32 +static krb5_error_code +read_console_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 + +static char *pwd_prompt; +static char *pwd_prompt2; +static char *pwd_return_pwd; +static int *pwd_size_return; + +static int CALLBACK +read_pwd_proc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + pwd_params FAR *dp = (pwd_params FAR *) lParam; + + switch(msg) { + case WM_INITDIALOG: + SetWindowLong(hdlg, DWL_USER, lParam); + SetDlgItemText(hdlg, ID_READ_PWD_PROMPT, dp->pwd_prompt); + SetDlgItemText(hdlg, ID_READ_PWD_PROMPT2, dp->pwd_prompt2); + SetDlgItemText(hdlg, ID_READ_PWD_PWD, ""); + center_dialog(hdlg); + return TRUE; + + case WM_COMMAND: + switch (wParam) { + case IDOK: + *(dp->pwd_size_return) = + GetDlgItemText(hdlg, ID_READ_PWD_PWD, + pwd_return_pwd, *pwd_size_return); + EndDialog(hdlg, TRUE); + break; + + case IDCANCEL: + memset(dp->pwd_return_pwd, 0 , *(dp->pwd_size_return)); + *(dp->pwd_size_return) = 0; + EndDialog(hdlg, FALSE); + break; + } + return TRUE; + + default: + return FALSE; + } +} + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_read_password(context, prompt, prompt2, return_pwd, size_return) + krb5_context context; + const char *prompt; + const char *prompt2; + char *return_pwd; + int *size_return; +{ + DLGPROC dlgproc; + HINSTANCE hinst; + pwd_params dps; + int rc; + +#ifdef _WIN32 + if (_isatty(_fileno(stdin))) + return(read_console_password + (context, prompt, prompt2, return_pwd, size_return)); +#endif + + dps.pwd_prompt = prompt; + dps.pwd_prompt2 = prompt2; + dps.pwd_return_pwd = return_pwd; + dps.pwd_size_return = size_return; + + hinst = get_lib_instance(); +#ifdef _WIN32 + dlgproc = read_pwd_proc; +#else + dlgproc = (FARPROC) MakeProcInstance(read_pwd_proc, hinst); +#endif + rc = DialogBoxParam(hinst, MAKEINTRESOURCE(ID_READ_PWD_DIALOG), 0, + dlgproc, (LPARAM) &dps); +#ifndef _WIN32 + FreeProcInstance ((FARPROC) dlgproc); +#endif + return 0; +} +#endif + +#ifndef DEFINED_KRB5_READ_PASSWORD +#define DEFINED_KRB5_READ_PASSWORD +/* + * Don't expect to be called, just define it for sanity and the linker. + */ +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_read_password(context, prompt, prompt2, return_pwd, size_return) krb5_context context; const char *prompt; @@ -168,6 +376,6 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) int *size_return; { *size_return = 0; - return 0; + return KRB5_LIBOS_CANTREADPWD; } -#endif /* !MSDOS */ +#endif diff --git a/src/lib/krb5/os/win-pwd.h b/src/lib/krb5/os/win-pwd.h new file mode 100644 index 000000000..73ebf4abc --- /dev/null +++ b/src/lib/krb5/os/win-pwd.h @@ -0,0 +1,28 @@ +/* + * lib/krb5/os/win-pwd.h + * + * Copyright 1997 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +#define ID_READ_PWD_DIALOG 10000 +#define ID_READ_PWD_PROMPT 10001 +#define ID_READ_PWD_PROMPT2 10002 +#define ID_READ_PWD_PWD 10003 diff --git a/src/lib/krb5/os/win-pwd.rc b/src/lib/krb5/os/win-pwd.rc new file mode 100644 index 000000000..53e20365a --- /dev/null +++ b/src/lib/krb5/os/win-pwd.rc @@ -0,0 +1,40 @@ +/* + * lib/krb5/os/win-pwd.h + * + * Copyright 1997 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +#include "win-pwd.h" +#include + +ID_READ_PWD_DIALOG DIALOG 60, 72, 200, 84 +STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | + DS_SETFONT +CAPTION "Kerberos Password/Challenge" +FONT 8, "Helv" +{ + LTEXT "", ID_READ_PWD_PROMPT, 10, 8, 180, 10 + LTEXT "", ID_READ_PWD_PROMPT2, 10, 24, 180, 10 + EDITTEXT ID_READ_PWD_PWD, 10, 42, 180, 12, ES_AUTOHSCROLL | ES_PASSWORD | + WS_BORDER | WS_TABSTOP + DEFPUSHBUTTON "&OK", IDOK, 55, 61, 40, 14 + PUSHBUTTON "&Cancel", IDCANCEL, 107, 61, 40, 14 +}