1 #define SCALE_FACTOR 31/20
9 Re-written for KFW 2.6 by Jeffrey Altman <jaltman@mit.edu>
11 Contains the callback functions for the EnterPassword an
12 ChangePassword dialog boxes and well as the API function
15 Lsh_Enter_Password_Dialog
16 Lsh_Change_Password_Dialog
18 for calling the dialogs.
20 Also contains the callback for the MITPasswordControl.
24 /* Standard Include files */
29 /* Private Inlclude files */
33 #include "leash-int.h"
41 extern void * Leash_pec_create(HWND hEditCtl);
42 extern void Leash_pec_destroy(void *pAutoComplete);
43 extern void Leash_pec_add_principal(char *principal);
44 extern void Leash_pec_clear_history(void *pec);
46 /* Global Variables. */
47 static long lsh_errno;
48 static char *err_context; /* error context */
49 extern HINSTANCE hLeashInst;
50 extern HINSTANCE hKrb4;
51 extern HINSTANCE hKrb5;
82 long Leash_get_lsh_errno(LONG *err_val)
87 /*/////// ******** API Calls follow here. ******** /////////*/
90 NetId_dialog(LPLSH_DLGINFO lpdlginfo)
96 hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");
97 if (hNetIdMgr != NULL) {
98 char desiredPrincipal[512];
99 NETID_DLGINFO *dlginfo;
100 char *desiredName = 0;
101 char *desiredRealm = 0;
103 DWORD tid = GetCurrentThreadId();
106 strcpy(desiredPrincipal, lpdlginfo->principal);
108 /* do we want a specific client principal? */
109 if (desiredPrincipal[0]) {
111 desiredName = desiredPrincipal;
112 for (p = desiredName; *p && *p != '@'; p++);
119 sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);
121 hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
125 } else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
130 dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,
132 if (dlginfo == NULL) {
137 hForeground = GetForegroundWindow();
139 memset(dlginfo, 0, sizeof(NETID_DLGINFO));
141 dlginfo->size = sizeof(NETID_DLGINFO);
142 if (lpdlginfo->dlgtype == DLGTYPE_PASSWD)
143 dlginfo->dlgtype = NETID_DLGTYPE_TGT;
145 dlginfo->dlgtype = NETID_DLGTYPE_CHPASSWD;
146 dlginfo->in.use_defaults = 1;
148 if (lpdlginfo->title) {
149 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
150 lpdlginfo->title, -1,
151 dlginfo->in.title, NETID_TITLE_SZ);
152 } else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {
153 char mytitle[NETID_TITLE_SZ];
154 sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);
155 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
157 dlginfo->in.title, NETID_TITLE_SZ);
159 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
160 "Obtain Kerberos TGT", -1,
161 dlginfo->in.title, NETID_TITLE_SZ);
164 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
166 dlginfo->in.username, NETID_USERNAME_SZ);
168 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
170 dlginfo->in.realm, NETID_REALM_SZ);
171 lrc = SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);
173 UnmapViewOfFile(dlginfo);
176 SetForegroundWindow(hForeground);
183 NetId_dialog_ex(LPLSH_DLGINFO_EX lpdlginfo)
188 hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");
189 if (hNetIdMgr != NULL) {
190 NETID_DLGINFO *dlginfo;
191 char *desiredName = lpdlginfo->username;
192 char *desiredRealm = lpdlginfo->realm;
197 DWORD tid = GetCurrentThreadId();
200 sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);
202 hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
206 } else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
211 dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,
213 if (dlginfo == NULL) {
218 hForeground = GetForegroundWindow();
220 if (lpdlginfo->size == LSH_DLGINFO_EX_V1_SZ ||
221 lpdlginfo->size == LSH_DLGINFO_EX_V2_SZ)
223 title = lpdlginfo->title;
224 desiredName = lpdlginfo->username;
225 desiredRealm = lpdlginfo->realm;
228 title = lpdlginfo->in.title;
229 desiredName = lpdlginfo->in.username;
230 desiredRealm = lpdlginfo->in.realm;
231 ccache = lpdlginfo->in.ccache;
234 memset(dlginfo, 0, sizeof(NETID_DLGINFO));
236 dlginfo->size = sizeof(NETID_DLGINFO);
237 if (lpdlginfo->dlgtype == DLGTYPE_PASSWD)
238 dlginfo->dlgtype = NETID_DLGTYPE_TGT;
240 dlginfo->dlgtype = NETID_DLGTYPE_CHPASSWD;
242 dlginfo->in.use_defaults = lpdlginfo->use_defaults;
243 dlginfo->in.forwardable = lpdlginfo->forwardable;
244 dlginfo->in.noaddresses = lpdlginfo->noaddresses;
245 dlginfo->in.lifetime = lpdlginfo->lifetime;
246 dlginfo->in.renew_till = lpdlginfo->renew_till;
247 dlginfo->in.proxiable = lpdlginfo->proxiable;
248 dlginfo->in.publicip = lpdlginfo->publicip;
251 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
253 dlginfo->in.title, NETID_TITLE_SZ);
254 } else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {
255 char mytitle[NETID_TITLE_SZ];
256 sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);
257 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
259 dlginfo->in.title, NETID_TITLE_SZ);
261 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
262 "Obtain Kerberos TGT", -1,
263 dlginfo->in.title, NETID_TITLE_SZ);
266 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
268 dlginfo->in.username, NETID_USERNAME_SZ);
270 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
272 dlginfo->in.realm, NETID_REALM_SZ);
274 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
276 dlginfo->in.ccache, NETID_CCACHE_NAME_SZ);
277 lrc = SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);
280 if (lpdlginfo->size == LSH_DLGINFO_EX_V2_SZ)
282 WideCharToMultiByte(CP_ACP, 0, dlginfo->out.username, -1,
283 lpdlginfo->out.username, LEASH_USERNAME_SZ,
285 WideCharToMultiByte(CP_ACP, 0, dlginfo->out.realm, -1,
286 lpdlginfo->out.realm, LEASH_REALM_SZ,
289 if (lpdlginfo->size == LSH_DLGINFO_EX_V3_SZ)
291 WideCharToMultiByte(CP_ACP, 0, dlginfo->out.ccache, -1,
292 lpdlginfo->out.ccache, LEASH_CCACHE_NAME_SZ,
297 UnmapViewOfFile(dlginfo);
300 SetForegroundWindow(hForeground);
307 #define LEASH_DLG_MUTEX_NAME TEXT("Leash_Dialog_Mutex")
308 int Leash_kinit_dlg(HWND hParent, LPLSH_DLGINFO lpdlginfo)
313 rc = NetId_dialog(lpdlginfo);
317 hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
318 if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
319 if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
322 ReleaseMutex(hMutex);
324 return 1; /* pretend the dialog was displayed and succeeded */
327 lpdlginfo->dlgtype = DLGTYPE_PASSWD;
329 /* set the help file */
330 Leash_set_help_file(NULL);
332 /* Call the Dialog box with the DLL's Password Callback and the
333 DLL's instance handle. */
334 rc = DialogBoxParam(hLeashInst, "EnterPasswordDlg", hParent,
335 PasswordProc, (LPARAM)lpdlginfo);
337 ReleaseMutex(hMutex);
343 int Leash_kinit_dlg_ex(HWND hParent, LPLSH_DLGINFO_EX lpdlginfo)
348 rc = NetId_dialog_ex(lpdlginfo);
352 hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
353 if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
354 if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
357 ReleaseMutex(hMutex);
359 return 1; /* pretend the dialog was displayed and succeeded */
362 /* set the help file */
363 Leash_set_help_file(NULL);
365 /* Call the Dialog box with the DLL's Password Callback and the
366 DLL's instance handle. */
367 rc = DialogBoxParam(hLeashInst, MAKEINTRESOURCE(IDD_AUTHENTICATE), hParent,
368 AuthenticateProc, (LPARAM)lpdlginfo);
369 ReleaseMutex(hMutex);
375 int Leash_changepwd_dlg(HWND hParent, LPLSH_DLGINFO lpdlginfo)
380 rc = NetId_dialog(lpdlginfo);
384 hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
385 if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
386 if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
389 ReleaseMutex(hMutex);
391 return 1; /* pretend the dialog was displayed and succeeded */
394 lpdlginfo->dlgtype = DLGTYPE_CHPASSWD;
396 /* Call the Dialog box with the DLL's Password Callback and the
397 DLL's instance handle. */
398 rc = DialogBoxParam(hLeashInst, "CHANGEPASSWORDDLG", hParent,
399 PasswordProc, (LPARAM)lpdlginfo);
400 ReleaseMutex(hMutex);
405 int Leash_changepwd_dlg_ex(HWND hParent, LPLSH_DLGINFO_EX lpdlginfo)
410 rc = NetId_dialog_ex(lpdlginfo);
414 hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
415 if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
416 if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
419 ReleaseMutex(hMutex);
421 return 1; /* pretend the dialog was displayed and succeeded */
424 lpdlginfo->dlgtype = DLGTYPE_CHPASSWD;
426 /* Call the Dialog box with the DLL's Password Callback and the
427 DLL's instance handle. */
428 rc = DialogBoxParam(hLeashInst, MAKEINTRESOURCE(IDD_PASSWORD), hParent,
429 NewPasswordProc, (LPARAM)lpdlginfo);
430 ReleaseMutex(hMutex);
436 /* These little utils are taken from lshutil.c
437 they are added here for the Call back funtion.
438 ****** beginning of added utils from lshutil.c ******/
440 BOOL IsDlgItem(HWND hWnd, WORD id)
444 hChild = GetDlgItem(hWnd, id);
445 return hChild ? IsWindow(hChild) : 0;
448 int lsh_getkeystate(WORD keyid)
450 static BYTE keys[256];
452 GetKeyboardState((LPBYTE) &keys);
453 return (int) keys[keyid];
456 LPSTR krb_err_func(int offset, long code)
461 /****** End of Added utils from leash.c ******/
464 int PaintLogoBitmap( HANDLE hPicFrame )
472 /* Invalidate the drawing space of the picframe. */
473 InvalidateRect( hPicFrame, NULL, TRUE);
474 UpdateWindow( hPicFrame );
476 hdc = GetDC(hPicFrame);
477 hdcMem = CreateCompatibleDC(hdc);
478 GetClientRect(hPicFrame, &rect);
479 hBitmap = LoadBitmap(hLeashInst, "LOGOBITMAP");
480 hOldBitmap = SelectObject(hdcMem, hBitmap);
481 GetObject(hBitmap, sizeof(Bitmap), (LPSTR) &Bitmap);
482 StretchBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0,
483 Bitmap.bmWidth, Bitmap.bmHeight, SRCCOPY);
485 SelectObject(hdcMem, hOldBitmap); /* pbh 8-15-94 */
486 ReleaseDC(hPicFrame, hdc);
487 DeleteObject( hBitmap ); /* pbh 8-15-94 */
488 DeleteDC( hdcMem ); /* pbh 8-15-94 */
494 /* Callback function for the Password Dialog box that initilializes and
506 static POINT Position = { -1, -1 };
509 #define ISCHPASSWD (lpdi->dlgtype == DLGTYPE_CHPASSWD)
511 #define STATE_PRINCIPAL 1
512 #define STATE_OLDPWD 2
513 #define STATE_NEWPWD1 3
514 #define STATE_NEWPWD2 4
515 #define STATE_CLOSED 5
516 #define NEXTSTATE(newstate) SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE, newstate)
517 static int ids[STATE_NEWPWD2 + 1] = {
519 ID_PRINCIPAL, ID_OLDPASSWORD, ID_CONFIRMPASSWORD1,
520 ID_CONFIRMPASSWORD2};
521 static char principal[255], oldpassword[255], newpassword[255],
523 static char *strings[STATE_NEWPWD2 + 1] = {
524 NULL, principal, oldpassword, newpassword, newpassword2};
525 static LPLSH_DLGINFO lpdi;
526 char gbuf[200]; /* global buffer for random stuff. */
529 #define checkfirst(id, stuff) IsDlgItem(hDialog, id) ? stuff : 0
530 #define CGetDlgItemText(hDlg, id, cp, len) checkfirst(id, GetDlgItemText(hDlg, id, cp, len))
531 #define CSetDlgItemText(hDlg, id, cp) checkfirst(id, SetDlgItemText(hDlg, id, cp))
532 #define CSetDlgItemInt(hDlg, id, i, b) checkfirst(id, SetDlgItemInt(hDlg, id, i, b))
533 #define CSendDlgItemMessage(hDlg, id, m, w, l) checkfirst(id, SendDlgItemMessage(hDlg, id, m, w, l))
534 #define CSendMessage(hwnd, m, w, l) IsWindow(hwnd) ? SendMessage(hwnd, m, w, l) : 0
535 #define CShowWindow(hwnd, state) IsWindow(hwnd) ? ShowWindow(hwnd, state) : 0
537 #define GETITEMTEXT(id, cp, maxlen) \
538 GetDlgItemText(hDialog, id, (LPSTR)(cp), maxlen)
539 #define CloseMe(x) SendMessage(hDialog, WM_COMMAND, ID_CLOSEME, x)
542 #define EDITFRAMEIDOFFSET 500
548 *( (LPLSH_DLGINFO far *)(&lpdi) ) = (LPLSH_DLGINFO)(LPSTR)lParam;
549 lpdi->dlgstatemax = ISCHPASSWD ? STATE_NEWPWD2
551 SetWindowText(hDialog, lpdi->title);
552 /* stop at old password for normal password dlg */
554 SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);
557 lstrcpy(principal, lpdi->principal);
561 /* is there a principal already being used? if so, use it. */
564 CSetDlgItemText(hDialog, ID_PRINCIPAL, principal);
566 lifetime = Leash_get_default_lifetime();
568 lifetime = 600; /* 10 hours */
570 CSetDlgItemInt(hDialog, ID_DURATION, lifetime, FALSE);
572 /* setup text of stuff. */
574 if (Position.x > 0 && Position.y > 0 &&
575 Position.x < GetSystemMetrics(SM_CXSCREEN) &&
576 Position.y < GetSystemMetrics(SM_CYSCREEN))
577 SetWindowPos(hDialog, 0, Position.x, Position.y, 0, 0,
578 SWP_NOSIZE | SWP_NOZORDER);
580 /* set window pos to last saved window pos */
583 /* replace standard edit control with our own password edit
584 control for password entry. */
591 for (i = ID_OLDPASSWORD; i <= ids[lpdi->dlgstatemax]; i++)
593 hwnd = GetDlgItem(hDialog, i);
594 GetWindowRect(hwnd, &r);
595 psz.x = r.right - r.left;
596 psz.y = r.bottom - r.top;
598 pxy.x = r.left; pxy.y = r.top;
599 ScreenToClient(hDialog, &pxy);
601 /* create a substitute window: */
604 /* kill off old edit window. */
606 CreateWindow(MIT_PWD_DLL_CLASS, /* our password window :o] */
608 WS_CHILD | WS_VISIBLE | WS_TABSTOP, /* child window, visible,tabstop */
609 pxy.x, pxy.y, /* x, y coords */
610 psz.x, psz.y, /* width, height */
611 hDialog, /* the parent */
612 (HMENU)i, /* same id *//* id offset for the frames */
613 (HANDLE)hLeashInst,/* instance handles */
614 NULL); /* createstruct */
619 NEXTSTATE(STATE_PRINCIPAL);
623 PaintLogoBitmap( GetDlgItem(hDialog, ID_PICFRAME) );
630 WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,
631 ISCHPASSWD ? ID_CHANGEPASSWORD : ID_INITTICKETS);
638 for (i = STATE_PRINCIPAL; i <= lpdi->dlgstatemax; i++)
640 memset(strings[i], '\0', 255);
641 SetDlgItemText(hDialog, ids[i], "");
643 /* I claim these passwords in the name
646 RemoveProp(hDialog, "HANDLES_HELP");
647 state = STATE_CLOSED;
648 EndDialog(hDialog, (int)lParam);
656 case ID_CONFIRMPASSWORD1:
657 case ID_CONFIRMPASSWORD2:
658 if (HIWORD(lParam) == EN_SETFOCUS)
660 /* nothing, for now. */
669 int oldstate = state;
672 idfocus = ids[state];
675 if (state == STATE_NEWPWD2)
676 SendDlgItemMessage(hDialog, ID_CONFIRMPASSWORD1, WM_SETTEXT,
680 for (s = STATE_PRINCIPAL; s <= lpdi->dlgstatemax; s++)
685 SendDlgItemMessage(hDialog, i, WM_SETTEXT, 0,
687 EnableWindow(GetDlgItem(hDialog, i), i == idfocus);
688 ShowWindow(GetDlgItem(hDialog, i),
689 (i <= idfocus ? SW_SHOW : SW_HIDE));
690 /* ShowWindow(GetDlgItem(hDialog, i + CAPTION_OFFSET),
691 (i <= idfocus ? SW_SHOW : SW_HIDE));*/
695 CSetDlgItemText(hDialog, ID_CONFIRMCAPTION1,
696 state < STATE_NEWPWD2 ?
697 "Enter new password:" :
698 "Enter new password again:");
699 if (state == STATE_NEWPWD2)
702 htext = GetDlgItem(hDialog, ID_CONFIRMCAPTION1);
703 FlashAnyWindow(htext);
705 FlashAnyWindow(htext);
709 hfocus = GetDlgItem(hDialog, idfocus);
710 if ( hfocus != (HWND)NULL ){
711 SetFocus(hfocus); /* switch focus */
712 if (idfocus >= ID_OLDPASSWORD)
713 SendMessage(hfocus, WM_SETTEXT, 0, (LPARAM) (LPSTR) "");
716 SendMessage(hfocus, EM_SETSEL, 0, MAKELONG(0, -1));
718 GetWindowRect(hfocus, &redit);
721 hbtn = GetDlgItem(hDialog, IDOK);
722 if( IsWindow(hbtn) ){
723 GetWindowRect(hbtn, &rbtn);
724 p.x = rbtn.left; p.y = redit.top;
725 ScreenToClient(hDialog, &p);
727 SetWindowPos(hbtn, 0, p.x, p.y, 0, 0,
728 SWP_NOSIZE | SWP_NOZORDER);
737 GETITEMTEXT(ids[state], (LPSTR)strings[state], 255);
741 case STATE_PRINCIPAL:
746 "You are not allowed to enter a blank principal.",
748 MB_OK | MB_ICONSTOP);
749 NEXTSTATE(STATE_PRINCIPAL);
753 // Change 'principal' to upper case after checking
754 // "UpperCase" value in the Registry
755 p_Principal = strchr(principal, '@');
757 if (p_Principal && Leash_get_default_uppercaserealm())
766 duration = GetDlgItemInt(hDialog, ID_DURATION, 0, FALSE);
769 MessageBox(hDialog, "You are not allowed to enter a "
772 MB_OK | MB_ICONSTOP);
773 NEXTSTATE(STATE_OLDPWD);
776 if (lpdi->dlgtype == DLGTYPE_CHPASSWD)
777 lsh_errno = Leash_int_checkpwd(principal, oldpassword, 1);
780 lsh_errno = Leash_int_kinit_ex( 0,
785 Leash_get_default_forwardable(),
786 Leash_get_default_proxiable(),
787 Leash_get_default_renew_till(),
788 Leash_get_default_noaddresses(),
789 Leash_get_default_publicip(),
795 int next_state = state;
803 case LSH_INVPRINCIPAL:
804 case LSH_INVINSTANCE:
806 next_state = STATE_PRINCIPAL;
809 capslock = lsh_getkeystate(VK_CAPITAL);
810 /* low-order bit means caps lock is
811 toggled; if so, warn user since there's
815 lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
816 cp = gbuf + lstrlen((LPSTR)gbuf);
819 lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
823 // XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""
824 // XXX : "Ticket initialization failed.");
825 NEXTSTATE(next_state);
830 CloseMe(TRUE); /* success */
838 for( i = 0; i < 255; i++ ){
839 if( newpassword[i] == '\0' ){
842 "Passwords should not contain non-ASCII characters.",
843 "Internationalization Warning",
844 MB_OK | MB_ICONINFORMATION);
848 } else if( !isprint(newpassword[i]) ){
849 memset(newpassword, '\0', 255);
850 /* I claim these passwords in the name of planet '\0'... */
852 "Passwords may not contain non-printable characters.",
854 MB_OK | MB_ICONSTOP);
855 NEXTSTATE(STATE_NEWPWD1);
857 } else if ( newpassword[i] > 127 )
863 if (lstrcmp(newpassword, newpassword2))
865 NEXTSTATE(STATE_NEWPWD1);
867 "The new password was not entered the same way twice.",
868 "Password validation error",
869 MB_OK | MB_ICONSTOP);
874 /* make them type both pwds again if error */
875 int next_state = STATE_NEWPWD1;
879 capslock = lsh_getkeystate(VK_CAPITAL);
880 /* low-order bit means caps lock is
881 toggled; if so, warn user since there's
885 lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
886 cp = gbuf + lstrlen((LPSTR)gbuf);
889 lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
894 Leash_int_changepwd(principal, oldpassword,
900 // XXX - DoNiftyErrorReport(lsh_errno, "Error while changing password.");
901 NEXTSTATE(next_state);
908 /* increment state, but send the old state as a
910 SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE, state + 1);
920 for (i = ID_OLDPASSWORD; i <= ids[lpdi->dlgstatemax]; i++)
921 SetDlgItemText(hDialog, i, "");
922 SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE,
930 if (state != STATE_CLOSED)
932 #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \
933 (pt).y=(SHORT)HIWORD(l))
934 LONG2POINT(lParam,Position);
936 Position = MAKEPOINT(lParam);
944 #define KRB_FILE "KRB.CON"
945 #define KRBREALM_FILE "KRBREALM.CON"
946 #define KRB5_FILE "KRB5.INI"
954 char **configFile = NULL;
956 pkrb5_get_default_config_files(&configFile))
958 GetWindowsDirectory(confname,szConfname);
959 confname[szConfname-1] = '\0';
960 strncat(confname, "\\",sizeof(confname)-strlen(confname));
961 confname[szConfname-1] = '\0';
962 strncat(confname, KRB5_FILE,sizeof(confname)-strlen(confname));
963 confname[szConfname-1] = '\0';
969 if (hKrb5 && configFile)
971 strncpy(confname, *configFile, szConfname);
972 pkrb5_free_config_files(configFile);
977 GetWindowsDirectory(confname,szConfname);
978 confname[szConfname-1] = '\0';
979 strncat(confname, "\\",sizeof(confname)-strlen(confname));
980 confname[szConfname-1] = '\0';
981 strncat(confname, KRB5_FILE,sizeof(confname)-strlen(confname));
982 confname[szConfname-1] = '\0';
996 { // hold krb.con where krb5.ini is located
997 CHAR krbConFile[MAX_PATH]="";
1000 //strcpy(krbConFile, CLeashApp::m_krbv5_profile->first_file->filename);
1001 if (GetProfileFile(krbConFile, sizeof(krbConFile)))
1003 GetWindowsDirectory(krbConFile,sizeof(krbConFile));
1004 krbConFile[MAX_PATH-1] = '\0';
1005 strncat(krbConFile, "\\",sizeof(krbConFile)-strlen(krbConFile));
1006 krbConFile[MAX_PATH-1] = '\0';
1007 strncat(krbConFile, KRB5_FILE,sizeof(krbConFile)-strlen(krbConFile));
1008 krbConFile[MAX_PATH-1] = '\0';
1011 pFind = strrchr(krbConFile, '\\');
1015 strncat(krbConFile, "\\",sizeof(krbConFile)-strlen(krbConFile));
1016 krbConFile[MAX_PATH-1] = '\0';
1017 strncat(krbConFile, KRB_FILE,sizeof(krbConFile)-strlen(krbConFile));
1018 krbConFile[MAX_PATH-1] = '\0';
1023 strncpy(confname, krbConFile, szConfname);
1024 confname[szConfname-1] = '\0';
1037 { // hold krb.con where krb5.ini is located
1038 CHAR krbRealmConFile[MAX_PATH];
1041 //strcpy(krbRealmConFile, CLeashApp::m_krbv5_profile->first_file->filename);
1042 if (GetProfileFile(krbRealmConFile, sizeof(krbRealmConFile)))
1044 GetWindowsDirectory(krbRealmConFile,sizeof(krbRealmConFile));
1045 krbRealmConFile[MAX_PATH-1] = '\0';
1046 strncat(krbRealmConFile, "\\",sizeof(krbRealmConFile)-strlen(krbRealmConFile));
1047 krbRealmConFile[MAX_PATH-1] = '\0';
1048 strncat(krbRealmConFile, KRB5_FILE,sizeof(krbRealmConFile)-strlen(krbRealmConFile));
1049 krbRealmConFile[MAX_PATH-1] = '\0';
1052 pFind = strrchr(krbRealmConFile, '\\');
1056 strncat(krbRealmConFile, "\\", sizeof(krbRealmConFile)-strlen(krbRealmConFile));
1057 krbRealmConFile[MAX_PATH-1] = '\0';
1058 strncat(krbRealmConFile, KRBREALM_FILE, sizeof(krbRealmConFile)-strlen(krbRealmConFile));
1059 krbRealmConFile[MAX_PATH-1] = '\0';
1062 krbRealmConFile[0] = 0;
1064 strncpy(confname, krbRealmConFile, szConfname);
1065 confname[szConfname-1] = '\0';
1071 readstring(FILE * file, char * buf, int len)
1074 memset(buf, '\0', sizeof(buf));
1075 for (i=0, c=fgetc(file); c != EOF ; c=fgetc(file), i++)
1077 if (i < sizeof(buf)) {
1092 if (i > 0 && i < len) {
1103 typedef struct _slider_info {
1109 struct _slider_info * next;
1111 static slider_info * sliders = NULL;
1113 static slider_info *
1114 FreeSlider(slider_info * s)
1116 slider_info * n = NULL;
1126 CleanupSliders(void)
1129 sliders = FreeSlider(sliders);
1133 static unsigned short
1134 NewSliderValue(HWND hDialog, int id)
1137 slider_info * s = sliders;
1139 if (s->slider_id == id) {
1140 int pos = CSendDlgItemMessage( hDialog, id,
1142 (WPARAM) 0, (LPARAM) 0);
1143 value = s->min + (pos * s->increment);
1152 NewSliderString(int id, int pos)
1154 static char buf[64]="";
1158 slider_info * s = sliders;
1160 if (s->slider_id == id) {
1161 value = s->min + pos * s->increment;
1163 if (value >= 60 * 24) {
1164 sprintf(p,"%d day(s) ",value / (60 * 24));
1169 if (must_hours || value >= 60) {
1170 sprintf(p,"%d hour(s) ",value / 60);
1174 sprintf(p,"%d minute(s) ",value);
1183 SetupSlider( HWND hDialog,
1197 slider_info * new_info;
1207 if (range < 5*60) { increment = 1; // 1 s if under 5 m
1208 } else if (range < 30*60) { increment = 5; // 5 s if under 30 m
1209 } else if (range < 60*60) { increment = 15; // 15 s if under 1 h
1210 } else if (range < 2*60*60) { increment = 30; // 30 s if under 2 h
1211 } else if (range < 5*60*60) { increment = 60; // 1 m if under 5 h
1212 } else if (range < 50*60*60) { increment = 5*60; // 5 m if under 50 h
1213 } else if (range < 200*60*60) { increment = 15*60; // 15 m if under 200 h
1214 } else if (range < 500*60*60) { increment = 30*60; // 30 m if under 500 h
1215 } else { increment = 60*60; } // 1 h otherwise
1217 roundedMinimum = (min / increment) * increment;
1218 if (roundedMinimum > min) { roundedMinimum -= increment; }
1219 if (roundedMinimum <= 0) { roundedMinimum += increment; } // make positive
1221 roundedMaximum = (max / increment) * increment;
1222 if (roundedMaximum < max) { roundedMaximum += increment; }
1224 roundedValue = (value / increment) * increment;
1225 if (roundedValue < roundedMinimum) { roundedValue = roundedMinimum; }
1226 if (roundedValue > roundedMaximum) { roundedValue = roundedMaximum; }
1228 if (roundedMinimum == roundedMaximum) {
1229 // [textField setTextColor: [NSColor grayColor]];
1230 EnableWindow(GetDlgItem(hDialog,sliderID),FALSE);
1232 // [textField setTextColor: [NSColor blackColor]];
1233 EnableWindow(GetDlgItem(hDialog,sliderID),TRUE);
1236 CSendDlgItemMessage( hDialog, sliderID,
1240 CSendDlgItemMessage( hDialog, sliderID,
1243 (LPARAM) (roundedMaximum - roundedMinimum) / increment );
1244 CSendDlgItemMessage( hDialog, sliderID,
1247 (LPARAM) (roundedValue - roundedMinimum) / increment);
1249 new_info = (slider_info *) malloc(sizeof(slider_info));
1250 new_info->slider_id = sliderID;
1251 new_info->text_id = textFieldID;
1252 new_info->min = roundedMinimum;
1253 new_info->max = roundedMaximum;
1254 new_info->increment = increment;
1255 new_info->next = sliders;
1258 SetWindowText(GetDlgItem(hDialog, textFieldID),
1259 NewSliderString(sliderID,(roundedValue - roundedMinimum) / increment));
1264 AdjustOptions(HWND hDialog, int show, int hideDiff)
1271 Leash_set_hide_kinit_options(!show);
1273 ShowWindow(GetDlgItem(hDialog,IDC_STATIC_LIFETIME),show);
1274 ShowWindow(GetDlgItem(hDialog,IDC_STATIC_LIFETIME_VALUE),show);
1275 ShowWindow(GetDlgItem(hDialog,IDC_SLIDER_LIFETIME),show);
1276 ShowWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),show);
1277 ShowWindow(GetDlgItem(hDialog,IDC_STATIC_RENEW),show);
1278 ShowWindow(GetDlgItem(hDialog,IDC_STATIC_RENEW_TILL_VALUE),show);
1279 ShowWindow(GetDlgItem(hDialog,IDC_CHECK_FORWARDABLE),show);
1280 ShowWindow(GetDlgItem(hDialog,IDC_CHECK_NOADDRESS),show);
1281 ShowWindow(GetDlgItem(hDialog,IDC_CHECK_RENEWABLE),show);
1282 ShowWindow(GetDlgItem(hDialog,IDC_STATIC_KRB5),show);
1283 ShowWindow(GetDlgItem(hDialog,IDC_BUTTON_CLEAR_HISTORY),show);
1285 GetWindowRect( hDialog, &dlgRect );
1286 diff = dlgRect.top + GetSystemMetrics(SM_CYCAPTION)
1287 + GetSystemMetrics(SM_CYDLGFRAME) + (show ? -1 : 1) * hideDiff;
1289 hwnd = GetDlgItem(hDialog,IDOK);
1290 GetWindowRect(hwnd,&rect);
1291 SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1292 hwnd = GetDlgItem(hDialog,IDCANCEL);
1293 GetWindowRect(hwnd,&rect);
1294 SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1295 hwnd = GetDlgItem(hDialog,IDC_BUTTON_OPTIONS);
1296 GetWindowRect(hwnd,&rect);
1297 SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1298 hwnd = GetDlgItem(hDialog,IDC_STATIC_VERSION);
1299 GetWindowRect(hwnd,&rect);
1300 SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1301 hwnd = GetDlgItem(hDialog,IDC_STATIC_COPYRIGHT);
1302 GetWindowRect(hwnd,&rect);
1303 SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1304 SetWindowPos(hDialog,0,0,0,
1305 dlgRect.right-dlgRect.left,
1306 dlgRect.bottom-dlgRect.top+(show ? 1 : - 1) * hideDiff,
1307 SWP_NOZORDER|SWP_NOMOVE);
1309 CSetDlgItemText(hDialog, IDC_BUTTON_OPTIONS,
1310 show ? "Hide Advanced" : "Show Advanced");
1314 /* Callback function for the Authentication Dialog box that initializes and
1326 static POINT Position = { -1, -1 };
1327 static char principal[256]="";
1328 static char password[256]="";
1329 static int lifetime=0;
1330 static int renew_till=0;
1331 static int forwardable=0;
1332 static int noaddresses=0;
1333 static int proxiable=0;
1334 static int publicip=0;
1335 static LPLSH_DLGINFO_EX lpdi;
1337 static HWND hSliderLifetime=0;
1338 static HWND hSliderRenew=0;
1339 static RECT dlgRect;
1340 static int hideDiff = 0;
1341 static void *pAutoComplete = 0;
1342 long realm_count = 0;
1343 int disable_noaddresses = 0;
1346 BOOL bReadOnlyPrinc=0;
1353 hEditCtrl = GetDlgItem(hDialog, IDC_EDIT_PRINCIPAL);
1355 pAutoComplete = Leash_pec_create(hEditCtrl);
1356 hSliderLifetime = GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE);
1357 hSliderRenew = GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE);
1359 *( (LPLSH_DLGINFO_EX far *)(&lpdi) ) = (LPLSH_DLGINFO_EX)(LPSTR)lParam;
1361 if ((lpdi->size != LSH_DLGINFO_EX_V1_SZ &&
1362 lpdi->size != LSH_DLGINFO_EX_V2_SZ &&
1363 lpdi->size < LSH_DLGINFO_EX_V3_SZ) ||
1364 (lpdi->dlgtype & DLGTYPE_MASK) != DLGTYPE_PASSWD) {
1366 MessageBox(hDialog, "An incorrect initialization data structure was provided.",
1367 "AuthenticateProc()",
1368 MB_OK | MB_ICONSTOP);
1371 bReadOnlyPrinc = (lpdi->dlgtype & DLGFLAG_READONLYPRINC) ?
1374 if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {
1375 lpdi->out.username[0] = 0;
1376 lpdi->out.realm[0] = 0;
1378 if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ ) {
1379 lpdi->out.ccache[0] = 0;
1382 if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ )
1383 SetWindowText(hDialog, lpdi->in.title);
1385 SetWindowText(hDialog, lpdi->title);
1387 SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);
1388 if (lpdi->use_defaults) {
1389 lifetime = Leash_get_default_lifetime();
1391 lifetime = 600; /* 10 hours */
1392 if (Leash_get_default_renewable()) {
1393 renew_till = Leash_get_default_renew_till();
1395 renew_till = 10800; /* 7 days */
1398 forwardable = Leash_get_default_forwardable();
1399 if (forwardable < 0)
1401 noaddresses = Leash_get_default_noaddresses();
1402 if (noaddresses < 0)
1404 proxiable = Leash_get_default_proxiable();
1407 publicip = Leash_get_default_publicip();
1411 forwardable = lpdi->forwardable;
1412 noaddresses = lpdi->noaddresses;
1413 lifetime = lpdi->lifetime;
1414 renew_till = lpdi->renew_till;
1415 proxiable = lpdi->proxiable;
1416 publicip = lpdi->publicip;
1418 if (lpdi->username && (strlen(lpdi->username) > 0) &&
1419 lpdi->realm && (strlen(lpdi->realm) > 0)) {
1420 sprintf_s(principal, sizeof(principal), "%s@%s", lpdi->username,
1425 Edit_SetReadOnly(hEditCtrl, bReadOnlyPrinc);
1426 CSetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal);
1427 CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD, "");
1429 #if 0 /* 20030619 - mjv wishes to return to the default character */
1431 CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD, EM_SETPASSWORDCHAR, 32, 0);
1434 /* Set Lifetime Slider
1440 SetupSlider( hDialog,
1441 IDC_SLIDER_LIFETIME,
1442 IDC_STATIC_LIFETIME_VALUE,
1443 Leash_get_default_life_min(),
1444 Leash_get_default_life_max(),
1447 CheckDlgButton(hDialog, IDC_CHECK_REMEMBER_PRINCIPAL, TRUE);
1448 /* Set Forwardable checkbox */
1449 CheckDlgButton(hDialog, IDC_CHECK_FORWARDABLE, forwardable);
1450 /* Set NoAddress checkbox */
1451 CheckDlgButton(hDialog, IDC_CHECK_NOADDRESS, noaddresses);
1452 if ( disable_noaddresses )
1453 EnableWindow(GetDlgItem(hDialog,IDC_CHECK_NOADDRESS),FALSE);
1454 /* Set Renewable checkbox */
1455 CheckDlgButton(hDialog, IDC_CHECK_RENEWABLE, renew_till);
1456 /* if not renewable, disable Renew Till slider */
1457 /* if renewable, set Renew Till slider
1462 SetupSlider( hDialog,
1463 IDC_SLIDER_RENEWLIFE,
1464 IDC_STATIC_RENEW_TILL_VALUE,
1465 Leash_get_default_renew_min(),
1466 Leash_get_default_renew_max(),
1469 EnableWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),TRUE);
1471 EnableWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),FALSE);
1474 // Compute sizes of items necessary to show/hide the advanced options
1475 GetWindowRect( hDialog, &dlgRect );
1477 RECT okRect, staticRect;
1478 GetWindowRect(GetDlgItem(hDialog,IDC_STATIC_LIFETIME),&staticRect);
1479 GetWindowRect(GetDlgItem(hDialog,IDOK),&okRect);
1480 hideDiff = okRect.top - staticRect.top;
1484 if (Leash_get_hide_kinit_options())
1485 AdjustOptions(hDialog,0,hideDiff);
1487 AdjustOptions(hDialog,0,hideDiff);
1488 EnableWindow(GetDlgItem(hDialog,IDC_BUTTON_OPTIONS),FALSE);
1489 ShowWindow(GetDlgItem(hDialog,IDC_BUTTON_OPTIONS),SW_HIDE);
1492 /* setup text of stuff. */
1494 if (Position.x > 0 && Position.y > 0 &&
1495 Position.x < GetSystemMetrics(SM_CXSCREEN) &&
1496 Position.y < GetSystemMetrics(SM_CYSCREEN))
1497 SetWindowPos(hDialog, HWND_TOP, Position.x, Position.y, 0, 0, SWP_NOSIZE);
1498 else /* Center the window on the desktop */
1499 SetWindowPos(hDialog, HWND_TOP,
1500 (GetSystemMetrics(SM_CXSCREEN) - dlgRect.right + dlgRect.left)/2,
1501 (GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top)/2,
1505 /* Take keyboard focus */
1506 SetActiveWindow(hDialog);
1507 SetForegroundWindow(hDialog);
1508 /* put focus on password if princ is read-only */
1509 hFocusCtrl = (bReadOnlyPrinc || principal[0] != '\0') ?
1510 GetDlgItem(hDialog, IDC_EDIT_PASSWORD) : hEditCtrl;
1511 if (((HWND)wParam) != hFocusCtrl) {
1512 SetFocus(hFocusCtrl);
1517 switch (LOWORD(wParam)) {
1519 case TB_THUMBPOSITION:
1521 long pos = HIWORD(wParam); // the position of the slider
1522 int ctrlID = GetDlgCtrlID((HWND)lParam);
1524 if (ctrlID == IDC_SLIDER_RENEWLIFE) {
1525 SetWindowText(GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE),
1526 NewSliderString(IDC_SLIDER_RENEWLIFE,pos));
1528 if (ctrlID == IDC_SLIDER_LIFETIME) {
1529 SetWindowText(GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE),
1530 NewSliderString(IDC_SLIDER_LIFETIME,pos));
1543 int ctrlID = GetDlgCtrlID((HWND)lParam);
1544 long pos = SendMessage(GetDlgItem(hDialog,ctrlID), TBM_GETPOS, 0, 0); // the position of the slider
1546 if (ctrlID == IDC_SLIDER_RENEWLIFE) {
1547 SetWindowText(GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE),
1548 NewSliderString(IDC_SLIDER_RENEWLIFE,pos));
1550 if (ctrlID == IDC_SLIDER_LIFETIME) {
1551 SetWindowText(GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE),
1552 NewSliderString(IDC_SLIDER_LIFETIME,pos));
1560 case IDC_BUTTON_OPTIONS:
1562 AdjustOptions(hDialog,Leash_get_hide_kinit_options(),hideDiff);
1563 GetWindowRect(hDialog,&dlgRect);
1564 if ( dlgRect.bottom > GetSystemMetrics(SM_CYSCREEN))
1565 SetWindowPos( hDialog,0,
1567 GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top,
1569 SWP_NOZORDER|SWP_NOSIZE);
1573 case IDC_BUTTON_CLEAR_HISTORY:
1574 Leash_pec_clear_history(pAutoComplete);
1576 case IDC_CHECK_RENEWABLE:
1578 if (IsDlgButtonChecked(hDialog, IDC_CHECK_RENEWABLE)) {
1579 EnableWindow(hSliderRenew,TRUE);
1581 EnableWindow(hSliderRenew,FALSE);
1587 WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,
1594 memset(password,0,sizeof(password));
1595 RemoveProp(hDialog, "HANDLES_HELP");
1596 if (pAutoComplete) {
1597 Leash_pec_destroy(pAutoComplete);
1598 pAutoComplete = NULL;
1600 EndDialog(hDialog, (int)lParam);
1608 CGetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal, sizeof(principal));
1609 CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD, password, sizeof(password));
1611 if (!principal[0]) {
1613 "You are not allowed to enter a blank principal.",
1614 "Invalid Principal",
1615 MB_OK | MB_ICONSTOP);
1618 // @TODO: parse realm portion and auto-uppercase
1620 if (Leash_get_default_uppercaserealm())
1630 "You are not allowed to enter a blank password.",
1632 MB_OK | MB_ICONSTOP);
1636 lifetime = NewSliderValue(hDialog, IDC_SLIDER_LIFETIME);
1638 forwardable = proxiable =
1639 IsDlgButtonChecked(hDialog, IDC_CHECK_FORWARDABLE);
1640 noaddresses = IsDlgButtonChecked(hDialog, IDC_CHECK_NOADDRESS);
1641 if (IsDlgButtonChecked(hDialog, IDC_CHECK_RENEWABLE)) {
1642 renew_till = NewSliderValue(hDialog, IDC_SLIDER_RENEWLIFE);
1647 lsh_errno = Leash_int_kinit_ex( 0,
1649 principal, password, lifetime,
1667 case LSH_INVPRINCIPAL:
1668 case LSH_INVINSTANCE:
1669 CSendDlgItemMessage(hDialog, IDC_EDIT_PRINCIPAL, EM_SETSEL, 0, 256);
1670 SetFocus(GetDlgItem(hDialog,IDC_EDIT_PRINCIPAL));
1673 CSendDlgItemMessage(hDialog, IDC_COMBO_REALM, EM_SETSEL, 0, 256);
1674 SetFocus(GetDlgItem(hDialog,IDC_COMBO_REALM));
1677 CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD, EM_SETSEL, 0, 256);
1678 SetFocus(GetDlgItem(hDialog,IDC_EDIT_PASSWORD));
1682 capslock = lsh_getkeystate(VK_CAPITAL);
1683 /* low-order bit means caps lock is
1684 toggled; if so, warn user since there's
1688 lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
1689 cp = gbuf + lstrlen((LPSTR)gbuf);
1692 lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
1696 // XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""
1697 // XXX : "Ticket initialization failed.");
1698 #endif /* COMMENT */
1702 if ( Leash_get_default_preserve_kinit_settings() )
1704 Leash_set_default_lifetime(lifetime);
1705 if ( renew_till > 0 ) {
1706 Leash_set_default_renew_till(renew_till);
1707 Leash_set_default_renewable(1);
1709 Leash_set_default_renewable(0);
1711 Leash_set_default_forwardable(forwardable);
1712 Leash_set_default_noaddresses(noaddresses);
1714 /* @TODO: out username/realm
1715 if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {
1716 strncpy(lpdi->out.username, username, LEASH_USERNAME_SZ);
1717 lpdi->out.username[LEASH_USERNAME_SZ-1] = 0;
1718 strncpy(lpdi->out.realm, realm, LEASH_REALM_SZ);
1719 lpdi->out.realm[LEASH_REALM_SZ-1] = 0;
1722 if (IsDlgButtonChecked(hDialog, IDC_CHECK_REMEMBER_PRINCIPAL))
1723 Leash_pec_add_principal(principal);
1725 CloseMe(TRUE); /* success */
1737 #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \
1738 (pt).y=(SHORT)HIWORD(l))
1739 LONG2POINT(lParam,Position);
1741 Position = MAKEPOINT(lParam);
1748 /* Callback function for the Change Password Dialog box */
1759 static POINT Position = { -1, -1 };
1760 static char password[256]="";
1761 static char password2[256]="";
1762 static char password3[256]="";
1763 static LPLSH_DLGINFO_EX lpdi;
1765 static void *pAutoComplete = NULL;
1766 char principal[256];
1767 long realm_count = 0;
1768 HWND hEditCtrl = NULL;
1775 *( (LPLSH_DLGINFO_EX far *)(&lpdi) ) = (LPLSH_DLGINFO_EX)(LPSTR)lParam;
1777 if ((lpdi->size < LSH_DLGINFO_EX_V3_SZ &&
1778 lpdi->size != LSH_DLGINFO_EX_V1_SZ &&
1779 lpdi->size != LSH_DLGINFO_EX_V2_SZ) ||
1780 lpdi->dlgtype != DLGTYPE_CHPASSWD) {
1782 MessageBox(hDialog, "An incorrect initialization data structure was provided.",
1784 MB_OK | MB_ICONSTOP);
1788 if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {
1789 lpdi->out.username[0] = 0;
1790 lpdi->out.realm[0] = 0;
1792 if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ ) {
1793 lpdi->out.ccache[0] = 0;
1796 if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ )
1797 SetWindowText(hDialog, lpdi->in.title);
1799 SetWindowText(hDialog, lpdi->title);
1801 SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);
1803 if (lpdi->username != NULL && (strlen(lpdi->username) > 0) &&
1804 lpdi->realm != NULL && (strlen(lpdi->realm) > 0)) {
1805 sprintf_s(principal,
1806 sizeof(principal), "%s@%s", lpdi->username, lpdi->realm);
1811 CSetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal);
1812 CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD, "");
1813 CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD2, "");
1814 CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD3, "");
1816 hEditCtrl = GetDlgItem(hDialog, IDC_EDIT_PRINCIPAL);
1818 pAutoComplete = Leash_pec_create(hEditCtrl);
1820 #if 0 /* 20030619 - mjv wishes to return to the default character */
1822 CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD, EM_SETPASSWORDCHAR, 32, 0);
1823 CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD2, EM_SETPASSWORDCHAR, 32, 0);
1824 CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD3, EM_SETPASSWORDCHAR, 32, 0);
1826 /* setup text of stuff. */
1828 if (Position.x > 0 && Position.y > 0 &&
1829 Position.x < GetSystemMetrics(SM_CXSCREEN) &&
1830 Position.y < GetSystemMetrics(SM_CYSCREEN))
1831 SetWindowPos(hDialog, 0, Position.x, Position.y, 0, 0,
1832 SWP_NOSIZE | SWP_NOZORDER);
1833 else { /* Center the window on the desktop */
1835 GetWindowRect( hDialog, &dlgRect );
1836 SetWindowPos(hDialog, 0,
1837 (GetSystemMetrics(SM_CXSCREEN) - dlgRect.right + dlgRect.left)/2,
1838 (GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top)/2,
1840 SWP_NOSIZE | SWP_NOZORDER);
1842 /* set window pos to last saved window pos */
1849 WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,
1856 memset(password,0,sizeof(password));
1857 memset(password2,0,sizeof(password2));
1858 memset(password3,0,sizeof(password3));
1859 RemoveProp(hDialog, "HANDLES_HELP");
1860 EndDialog(hDialog, (int)lParam);
1861 if (pAutoComplete != NULL) {
1862 Leash_pec_destroy(pAutoComplete);
1863 pAutoComplete = NULL;
1874 CGetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal, sizeof(principal));
1875 CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD, password, sizeof(password));
1876 CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD2, password2, sizeof(password2));
1877 CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD3, password3, sizeof(password3));
1881 MessageBox(hDialog, "You are not allowed to enter a "
1883 "Invalid Principal",
1884 MB_OK | MB_ICONSTOP);
1888 if (!password[0] || !password2[0] || !password3[0])
1890 MessageBox(hDialog, "You are not allowed to enter a "
1893 MB_OK | MB_ICONSTOP);
1897 for( i = 0; i < 255; i++ ){
1898 if( password2[i] == '\0' ){
1901 "Passwords should not contain non-ASCII characters.",
1902 "Internationalization Warning",
1903 MB_OK | MB_ICONINFORMATION);
1907 } else if( !isprint(password2[i]) ){
1908 memset(password2, '\0', sizeof(password2));
1909 memset(password3, '\0', sizeof(password3));
1910 /* I claim these passwords in the name of planet '\0'... */
1912 "Passwords may not contain non-printable characters.",
1914 MB_OK | MB_ICONSTOP);
1916 } else if ( password2[i] > 127 )
1920 if (lstrcmp(password2, password3))
1923 "The new password was not entered the same way twice.",
1924 "Password validation error",
1925 MB_OK | MB_ICONSTOP);
1929 lsh_errno = Leash_int_changepwd(principal, password, password2, 0, 1);
1936 #endif /* COMMENT */
1941 case LSH_INVPRINCIPAL:
1942 case LSH_INVINSTANCE:
1949 capslock = lsh_getkeystate(VK_CAPITAL);
1950 /* low-order bit means caps lock is
1951 toggled; if so, warn user since there's
1955 lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
1956 cp = gbuf + lstrlen((LPSTR)gbuf);
1959 lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
1963 // XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""
1964 // XXX : "Ticket initialization failed.");
1965 #endif /* COMMENT */
1968 Leash_pec_add_principal(principal);
1969 MessageBox(NULL, "Password successfully changed.",
1970 "Password change", MB_OK);
1971 CloseMe(TRUE); /* success */
1982 #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \
1983 (pt).y=(SHORT)HIWORD(l))
1984 LONG2POINT(lParam,Position);
1986 Position = MAKEPOINT(lParam);