1*7f2fe78bSCy Schubert #define SCALE_FACTOR 31/20
2*7f2fe78bSCy Schubert
3*7f2fe78bSCy Schubert /* LSH_PWD.C
4*7f2fe78bSCy Schubert
5*7f2fe78bSCy Schubert Jason Hunter
6*7f2fe78bSCy Schubert 8/2/94
7*7f2fe78bSCy Schubert DCNS/IS MIT
8*7f2fe78bSCy Schubert
9*7f2fe78bSCy Schubert Re-written for KFW 2.6 by Jeffrey Altman <jaltman@mit.edu>
10*7f2fe78bSCy Schubert
11*7f2fe78bSCy Schubert Contains the callback functions for the EnterPassword an
12*7f2fe78bSCy Schubert ChangePassword dialog boxes and well as the API function
13*7f2fe78bSCy Schubert calls:
14*7f2fe78bSCy Schubert
15*7f2fe78bSCy Schubert Lsh_Enter_Password_Dialog
16*7f2fe78bSCy Schubert Lsh_Change_Password_Dialog
17*7f2fe78bSCy Schubert
18*7f2fe78bSCy Schubert for calling the dialogs.
19*7f2fe78bSCy Schubert
20*7f2fe78bSCy Schubert Also contains the callback for the MITPasswordControl.
21*7f2fe78bSCy Schubert
22*7f2fe78bSCy Schubert */
23*7f2fe78bSCy Schubert
24*7f2fe78bSCy Schubert /* Standard Include files */
25*7f2fe78bSCy Schubert #include <windows.h>
26*7f2fe78bSCy Schubert #include <windowsx.h>
27*7f2fe78bSCy Schubert #include <stdio.h>
28*7f2fe78bSCy Schubert #include <string.h>
29*7f2fe78bSCy Schubert
30*7f2fe78bSCy Schubert /* Private Inlclude files */
31*7f2fe78bSCy Schubert #include "leashdll.h"
32*7f2fe78bSCy Schubert #include <leashwin.h>
33*7f2fe78bSCy Schubert #include "leash-int.h"
34*7f2fe78bSCy Schubert #include "leashids.h"
35*7f2fe78bSCy Schubert #include <leasherr.h>
36*7f2fe78bSCy Schubert #include <krb5.h>
37*7f2fe78bSCy Schubert #include <commctrl.h>
38*7f2fe78bSCy Schubert
39*7f2fe78bSCy Schubert extern void * Leash_pec_create(HWND hEditCtl);
40*7f2fe78bSCy Schubert extern void Leash_pec_destroy(void *pAutoComplete);
41*7f2fe78bSCy Schubert extern void Leash_pec_add_principal(char *principal);
42*7f2fe78bSCy Schubert extern void Leash_pec_clear_history(void *pec);
43*7f2fe78bSCy Schubert
44*7f2fe78bSCy Schubert /* Global Variables. */
45*7f2fe78bSCy Schubert static long lsh_errno;
46*7f2fe78bSCy Schubert static char *err_context; /* error context */
47*7f2fe78bSCy Schubert extern HINSTANCE hLeashInst;
48*7f2fe78bSCy Schubert extern HINSTANCE hKrb5;
49*7f2fe78bSCy Schubert
50*7f2fe78bSCy Schubert
51*7f2fe78bSCy Schubert INT_PTR
52*7f2fe78bSCy Schubert CALLBACK
53*7f2fe78bSCy Schubert PasswordProc(
54*7f2fe78bSCy Schubert HWND hwndDlg,
55*7f2fe78bSCy Schubert UINT uMsg,
56*7f2fe78bSCy Schubert WPARAM wParam,
57*7f2fe78bSCy Schubert LPARAM lParam
58*7f2fe78bSCy Schubert );
59*7f2fe78bSCy Schubert
60*7f2fe78bSCy Schubert INT_PTR
61*7f2fe78bSCy Schubert CALLBACK
62*7f2fe78bSCy Schubert AuthenticateProc(
63*7f2fe78bSCy Schubert HWND hwndDlg,
64*7f2fe78bSCy Schubert UINT uMsg,
65*7f2fe78bSCy Schubert WPARAM wParam,
66*7f2fe78bSCy Schubert LPARAM lParam
67*7f2fe78bSCy Schubert );
68*7f2fe78bSCy Schubert
69*7f2fe78bSCy Schubert INT_PTR
70*7f2fe78bSCy Schubert CALLBACK
71*7f2fe78bSCy Schubert NewPasswordProc(
72*7f2fe78bSCy Schubert HWND hwndDlg,
73*7f2fe78bSCy Schubert UINT uMsg,
74*7f2fe78bSCy Schubert WPARAM wParam,
75*7f2fe78bSCy Schubert LPARAM lParam
76*7f2fe78bSCy Schubert );
77*7f2fe78bSCy Schubert
78*7f2fe78bSCy Schubert
Leash_get_lsh_errno(LONG * err_val)79*7f2fe78bSCy Schubert long Leash_get_lsh_errno(LONG *err_val)
80*7f2fe78bSCy Schubert {
81*7f2fe78bSCy Schubert return lsh_errno;
82*7f2fe78bSCy Schubert }
83*7f2fe78bSCy Schubert
84*7f2fe78bSCy Schubert /*/////// ******** API Calls follow here. ******** /////////*/
85*7f2fe78bSCy Schubert
86*7f2fe78bSCy Schubert static int
NetId_dialog(LPLSH_DLGINFO lpdlginfo)87*7f2fe78bSCy Schubert NetId_dialog(LPLSH_DLGINFO lpdlginfo)
88*7f2fe78bSCy Schubert {
89*7f2fe78bSCy Schubert LRESULT lrc;
90*7f2fe78bSCy Schubert HWND hNetIdMgr;
91*7f2fe78bSCy Schubert HWND hForeground;
92*7f2fe78bSCy Schubert
93*7f2fe78bSCy Schubert hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");
94*7f2fe78bSCy Schubert if (hNetIdMgr != NULL) {
95*7f2fe78bSCy Schubert char desiredPrincipal[512];
96*7f2fe78bSCy Schubert NETID_DLGINFO *dlginfo;
97*7f2fe78bSCy Schubert char *desiredName = 0;
98*7f2fe78bSCy Schubert char *desiredRealm = 0;
99*7f2fe78bSCy Schubert HANDLE hMap;
100*7f2fe78bSCy Schubert DWORD tid = GetCurrentThreadId();
101*7f2fe78bSCy Schubert char mapname[256];
102*7f2fe78bSCy Schubert
103*7f2fe78bSCy Schubert strcpy(desiredPrincipal, lpdlginfo->principal);
104*7f2fe78bSCy Schubert
105*7f2fe78bSCy Schubert /* do we want a specific client principal? */
106*7f2fe78bSCy Schubert if (desiredPrincipal[0]) {
107*7f2fe78bSCy Schubert char * p;
108*7f2fe78bSCy Schubert desiredName = desiredPrincipal;
109*7f2fe78bSCy Schubert for (p = desiredName; *p && *p != '@'; p++);
110*7f2fe78bSCy Schubert if ( *p == '@' ) {
111*7f2fe78bSCy Schubert *p = '\0';
112*7f2fe78bSCy Schubert desiredRealm = ++p;
113*7f2fe78bSCy Schubert }
114*7f2fe78bSCy Schubert }
115*7f2fe78bSCy Schubert
116*7f2fe78bSCy Schubert sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);
117*7f2fe78bSCy Schubert
118*7f2fe78bSCy Schubert hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
119*7f2fe78bSCy Schubert 0, 4096, mapname);
120*7f2fe78bSCy Schubert if (hMap == NULL) {
121*7f2fe78bSCy Schubert return -1;
122*7f2fe78bSCy Schubert } else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
123*7f2fe78bSCy Schubert CloseHandle(hMap);
124*7f2fe78bSCy Schubert return -1;
125*7f2fe78bSCy Schubert }
126*7f2fe78bSCy Schubert
127*7f2fe78bSCy Schubert dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,
128*7f2fe78bSCy Schubert 0, 0, 4096, NULL);
129*7f2fe78bSCy Schubert if (dlginfo == NULL) {
130*7f2fe78bSCy Schubert CloseHandle(hMap);
131*7f2fe78bSCy Schubert return -1;
132*7f2fe78bSCy Schubert }
133*7f2fe78bSCy Schubert
134*7f2fe78bSCy Schubert hForeground = GetForegroundWindow();
135*7f2fe78bSCy Schubert
136*7f2fe78bSCy Schubert memset(dlginfo, 0, sizeof(NETID_DLGINFO));
137*7f2fe78bSCy Schubert
138*7f2fe78bSCy Schubert dlginfo->size = sizeof(NETID_DLGINFO);
139*7f2fe78bSCy Schubert if (lpdlginfo->dlgtype == DLGTYPE_PASSWD)
140*7f2fe78bSCy Schubert dlginfo->dlgtype = NETID_DLGTYPE_TGT;
141*7f2fe78bSCy Schubert else
142*7f2fe78bSCy Schubert dlginfo->dlgtype = NETID_DLGTYPE_CHPASSWD;
143*7f2fe78bSCy Schubert dlginfo->in.use_defaults = 1;
144*7f2fe78bSCy Schubert
145*7f2fe78bSCy Schubert if (lpdlginfo->title) {
146*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
147*7f2fe78bSCy Schubert lpdlginfo->title, -1,
148*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
149*7f2fe78bSCy Schubert } else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {
150*7f2fe78bSCy Schubert char mytitle[NETID_TITLE_SZ];
151*7f2fe78bSCy Schubert sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);
152*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
153*7f2fe78bSCy Schubert mytitle, -1,
154*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
155*7f2fe78bSCy Schubert } else {
156*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
157*7f2fe78bSCy Schubert "Obtain Kerberos TGT", -1,
158*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
159*7f2fe78bSCy Schubert }
160*7f2fe78bSCy Schubert if (desiredName)
161*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
162*7f2fe78bSCy Schubert desiredName, -1,
163*7f2fe78bSCy Schubert dlginfo->in.username, NETID_USERNAME_SZ);
164*7f2fe78bSCy Schubert if (desiredRealm)
165*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
166*7f2fe78bSCy Schubert desiredRealm, -1,
167*7f2fe78bSCy Schubert dlginfo->in.realm, NETID_REALM_SZ);
168*7f2fe78bSCy Schubert lrc = SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);
169*7f2fe78bSCy Schubert
170*7f2fe78bSCy Schubert UnmapViewOfFile(dlginfo);
171*7f2fe78bSCy Schubert CloseHandle(hMap);
172*7f2fe78bSCy Schubert
173*7f2fe78bSCy Schubert SetForegroundWindow(hForeground);
174*7f2fe78bSCy Schubert return lrc;
175*7f2fe78bSCy Schubert }
176*7f2fe78bSCy Schubert return -1;
177*7f2fe78bSCy Schubert }
178*7f2fe78bSCy Schubert
179*7f2fe78bSCy Schubert static int
NetId_dialog_ex(LPLSH_DLGINFO_EX lpdlginfo)180*7f2fe78bSCy Schubert NetId_dialog_ex(LPLSH_DLGINFO_EX lpdlginfo)
181*7f2fe78bSCy Schubert {
182*7f2fe78bSCy Schubert HWND hNetIdMgr;
183*7f2fe78bSCy Schubert HWND hForeground;
184*7f2fe78bSCy Schubert
185*7f2fe78bSCy Schubert hNetIdMgr = FindWindow("IDMgrRequestDaemonCls", "IDMgrRequestDaemon");
186*7f2fe78bSCy Schubert if (hNetIdMgr != NULL) {
187*7f2fe78bSCy Schubert NETID_DLGINFO *dlginfo;
188*7f2fe78bSCy Schubert char *desiredName = lpdlginfo->username;
189*7f2fe78bSCy Schubert char *desiredRealm = lpdlginfo->realm;
190*7f2fe78bSCy Schubert LPSTR title;
191*7f2fe78bSCy Schubert char *ccache;
192*7f2fe78bSCy Schubert LRESULT lrc;
193*7f2fe78bSCy Schubert HANDLE hMap;
194*7f2fe78bSCy Schubert DWORD tid = GetCurrentThreadId();
195*7f2fe78bSCy Schubert char mapname[256];
196*7f2fe78bSCy Schubert
197*7f2fe78bSCy Schubert sprintf(mapname,"Local\\NetIDMgr_DlgInfo_%lu",tid);
198*7f2fe78bSCy Schubert
199*7f2fe78bSCy Schubert hMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
200*7f2fe78bSCy Schubert 0, 4096, mapname);
201*7f2fe78bSCy Schubert if (hMap == NULL) {
202*7f2fe78bSCy Schubert return -1;
203*7f2fe78bSCy Schubert } else if (hMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
204*7f2fe78bSCy Schubert CloseHandle(hMap);
205*7f2fe78bSCy Schubert return -1;
206*7f2fe78bSCy Schubert }
207*7f2fe78bSCy Schubert
208*7f2fe78bSCy Schubert dlginfo = (NETID_DLGINFO *)MapViewOfFileEx(hMap, FILE_MAP_READ|FILE_MAP_WRITE,
209*7f2fe78bSCy Schubert 0, 0, 4096, NULL);
210*7f2fe78bSCy Schubert if (dlginfo == NULL) {
211*7f2fe78bSCy Schubert CloseHandle(hMap);
212*7f2fe78bSCy Schubert return -1;
213*7f2fe78bSCy Schubert }
214*7f2fe78bSCy Schubert
215*7f2fe78bSCy Schubert hForeground = GetForegroundWindow();
216*7f2fe78bSCy Schubert
217*7f2fe78bSCy Schubert if (lpdlginfo->size == LSH_DLGINFO_EX_V1_SZ ||
218*7f2fe78bSCy Schubert lpdlginfo->size == LSH_DLGINFO_EX_V2_SZ)
219*7f2fe78bSCy Schubert {
220*7f2fe78bSCy Schubert title = lpdlginfo->title;
221*7f2fe78bSCy Schubert desiredName = lpdlginfo->username;
222*7f2fe78bSCy Schubert desiredRealm = lpdlginfo->realm;
223*7f2fe78bSCy Schubert ccache = NULL;
224*7f2fe78bSCy Schubert } else {
225*7f2fe78bSCy Schubert title = lpdlginfo->in.title;
226*7f2fe78bSCy Schubert desiredName = lpdlginfo->in.username;
227*7f2fe78bSCy Schubert desiredRealm = lpdlginfo->in.realm;
228*7f2fe78bSCy Schubert ccache = lpdlginfo->in.ccache;
229*7f2fe78bSCy Schubert }
230*7f2fe78bSCy Schubert
231*7f2fe78bSCy Schubert memset(dlginfo, 0, sizeof(NETID_DLGINFO));
232*7f2fe78bSCy Schubert
233*7f2fe78bSCy Schubert dlginfo->size = sizeof(NETID_DLGINFO);
234*7f2fe78bSCy Schubert if (lpdlginfo->dlgtype == DLGTYPE_PASSWD)
235*7f2fe78bSCy Schubert dlginfo->dlgtype = NETID_DLGTYPE_TGT;
236*7f2fe78bSCy Schubert else
237*7f2fe78bSCy Schubert dlginfo->dlgtype = NETID_DLGTYPE_CHPASSWD;
238*7f2fe78bSCy Schubert
239*7f2fe78bSCy Schubert dlginfo->in.use_defaults = lpdlginfo->use_defaults;
240*7f2fe78bSCy Schubert dlginfo->in.forwardable = lpdlginfo->forwardable;
241*7f2fe78bSCy Schubert dlginfo->in.noaddresses = lpdlginfo->noaddresses;
242*7f2fe78bSCy Schubert dlginfo->in.lifetime = lpdlginfo->lifetime;
243*7f2fe78bSCy Schubert dlginfo->in.renew_till = lpdlginfo->renew_till;
244*7f2fe78bSCy Schubert dlginfo->in.proxiable = lpdlginfo->proxiable;
245*7f2fe78bSCy Schubert dlginfo->in.publicip = lpdlginfo->publicip;
246*7f2fe78bSCy Schubert
247*7f2fe78bSCy Schubert if (title) {
248*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
249*7f2fe78bSCy Schubert title, -1,
250*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
251*7f2fe78bSCy Schubert } else if (desiredName && (strlen(desiredName) + strlen(desiredRealm) + 32 < NETID_TITLE_SZ)) {
252*7f2fe78bSCy Schubert char mytitle[NETID_TITLE_SZ];
253*7f2fe78bSCy Schubert sprintf(mytitle, "Obtain Kerberos TGT for %s@%s",desiredName,desiredRealm);
254*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
255*7f2fe78bSCy Schubert mytitle, -1,
256*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
257*7f2fe78bSCy Schubert } else {
258*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
259*7f2fe78bSCy Schubert "Obtain Kerberos TGT", -1,
260*7f2fe78bSCy Schubert dlginfo->in.title, NETID_TITLE_SZ);
261*7f2fe78bSCy Schubert }
262*7f2fe78bSCy Schubert if (desiredName)
263*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
264*7f2fe78bSCy Schubert desiredName, -1,
265*7f2fe78bSCy Schubert dlginfo->in.username, NETID_USERNAME_SZ);
266*7f2fe78bSCy Schubert if (desiredRealm)
267*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
268*7f2fe78bSCy Schubert desiredRealm, -1,
269*7f2fe78bSCy Schubert dlginfo->in.realm, NETID_REALM_SZ);
270*7f2fe78bSCy Schubert if (ccache)
271*7f2fe78bSCy Schubert MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
272*7f2fe78bSCy Schubert ccache, -1,
273*7f2fe78bSCy Schubert dlginfo->in.ccache, NETID_CCACHE_NAME_SZ);
274*7f2fe78bSCy Schubert lrc = SendMessage(hNetIdMgr, 32810, 0, (LPARAM) tid);
275*7f2fe78bSCy Schubert
276*7f2fe78bSCy Schubert if (lrc > 0) {
277*7f2fe78bSCy Schubert if (lpdlginfo->size == LSH_DLGINFO_EX_V2_SZ)
278*7f2fe78bSCy Schubert {
279*7f2fe78bSCy Schubert WideCharToMultiByte(CP_ACP, 0, dlginfo->out.username, -1,
280*7f2fe78bSCy Schubert lpdlginfo->out.username, LEASH_USERNAME_SZ,
281*7f2fe78bSCy Schubert NULL, NULL);
282*7f2fe78bSCy Schubert WideCharToMultiByte(CP_ACP, 0, dlginfo->out.realm, -1,
283*7f2fe78bSCy Schubert lpdlginfo->out.realm, LEASH_REALM_SZ,
284*7f2fe78bSCy Schubert NULL, NULL);
285*7f2fe78bSCy Schubert }
286*7f2fe78bSCy Schubert if (lpdlginfo->size == LSH_DLGINFO_EX_V3_SZ)
287*7f2fe78bSCy Schubert {
288*7f2fe78bSCy Schubert WideCharToMultiByte(CP_ACP, 0, dlginfo->out.ccache, -1,
289*7f2fe78bSCy Schubert lpdlginfo->out.ccache, LEASH_CCACHE_NAME_SZ,
290*7f2fe78bSCy Schubert NULL, NULL);
291*7f2fe78bSCy Schubert }
292*7f2fe78bSCy Schubert }
293*7f2fe78bSCy Schubert
294*7f2fe78bSCy Schubert UnmapViewOfFile(dlginfo);
295*7f2fe78bSCy Schubert CloseHandle(hMap);
296*7f2fe78bSCy Schubert
297*7f2fe78bSCy Schubert SetForegroundWindow(hForeground);
298*7f2fe78bSCy Schubert return lrc;
299*7f2fe78bSCy Schubert }
300*7f2fe78bSCy Schubert return -1;
301*7f2fe78bSCy Schubert }
302*7f2fe78bSCy Schubert
303*7f2fe78bSCy Schubert
304*7f2fe78bSCy Schubert #define LEASH_DLG_MUTEX_NAME TEXT("Leash_Dialog_Mutex")
Leash_kinit_dlg(HWND hParent,LPLSH_DLGINFO lpdlginfo)305*7f2fe78bSCy Schubert int Leash_kinit_dlg(HWND hParent, LPLSH_DLGINFO lpdlginfo)
306*7f2fe78bSCy Schubert {
307*7f2fe78bSCy Schubert int rc;
308*7f2fe78bSCy Schubert HANDLE hMutex;
309*7f2fe78bSCy Schubert
310*7f2fe78bSCy Schubert rc = NetId_dialog(lpdlginfo);
311*7f2fe78bSCy Schubert if (rc > -1)
312*7f2fe78bSCy Schubert return rc;
313*7f2fe78bSCy Schubert
314*7f2fe78bSCy Schubert hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
315*7f2fe78bSCy Schubert if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
316*7f2fe78bSCy Schubert if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
317*7f2fe78bSCy Schubert return -1;
318*7f2fe78bSCy Schubert }
319*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
320*7f2fe78bSCy Schubert CloseHandle(hMutex);
321*7f2fe78bSCy Schubert return 1; /* pretend the dialog was displayed and succeeded */
322*7f2fe78bSCy Schubert }
323*7f2fe78bSCy Schubert
324*7f2fe78bSCy Schubert lpdlginfo->dlgtype = DLGTYPE_PASSWD;
325*7f2fe78bSCy Schubert
326*7f2fe78bSCy Schubert /* set the help file */
327*7f2fe78bSCy Schubert Leash_set_help_file(NULL);
328*7f2fe78bSCy Schubert
329*7f2fe78bSCy Schubert /* Call the Dialog box with the DLL's Password Callback and the
330*7f2fe78bSCy Schubert DLL's instance handle. */
331*7f2fe78bSCy Schubert rc = DialogBoxParam(hLeashInst, "EnterPasswordDlg", hParent,
332*7f2fe78bSCy Schubert PasswordProc, (LPARAM)lpdlginfo);
333*7f2fe78bSCy Schubert
334*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
335*7f2fe78bSCy Schubert CloseHandle(hMutex);
336*7f2fe78bSCy Schubert return rc;
337*7f2fe78bSCy Schubert }
338*7f2fe78bSCy Schubert
339*7f2fe78bSCy Schubert
Leash_kinit_dlg_ex(HWND hParent,LPLSH_DLGINFO_EX lpdlginfo)340*7f2fe78bSCy Schubert int Leash_kinit_dlg_ex(HWND hParent, LPLSH_DLGINFO_EX lpdlginfo)
341*7f2fe78bSCy Schubert {
342*7f2fe78bSCy Schubert int rc;
343*7f2fe78bSCy Schubert HANDLE hMutex;
344*7f2fe78bSCy Schubert
345*7f2fe78bSCy Schubert rc = NetId_dialog_ex(lpdlginfo);
346*7f2fe78bSCy Schubert if (rc > -1)
347*7f2fe78bSCy Schubert return rc;
348*7f2fe78bSCy Schubert
349*7f2fe78bSCy Schubert hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
350*7f2fe78bSCy Schubert if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
351*7f2fe78bSCy Schubert if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
352*7f2fe78bSCy Schubert return -1;
353*7f2fe78bSCy Schubert }
354*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
355*7f2fe78bSCy Schubert CloseHandle(hMutex);
356*7f2fe78bSCy Schubert return 1; /* pretend the dialog was displayed and succeeded */
357*7f2fe78bSCy Schubert }
358*7f2fe78bSCy Schubert
359*7f2fe78bSCy Schubert /* set the help file */
360*7f2fe78bSCy Schubert Leash_set_help_file(NULL);
361*7f2fe78bSCy Schubert
362*7f2fe78bSCy Schubert /* Call the Dialog box with the DLL's Password Callback and the
363*7f2fe78bSCy Schubert DLL's instance handle. */
364*7f2fe78bSCy Schubert rc = DialogBoxParam(hLeashInst, MAKEINTRESOURCE(IDD_AUTHENTICATE), hParent,
365*7f2fe78bSCy Schubert AuthenticateProc, (LPARAM)lpdlginfo);
366*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
367*7f2fe78bSCy Schubert CloseHandle(hMutex);
368*7f2fe78bSCy Schubert return rc;
369*7f2fe78bSCy Schubert }
370*7f2fe78bSCy Schubert
371*7f2fe78bSCy Schubert
Leash_changepwd_dlg(HWND hParent,LPLSH_DLGINFO lpdlginfo)372*7f2fe78bSCy Schubert int Leash_changepwd_dlg(HWND hParent, LPLSH_DLGINFO lpdlginfo)
373*7f2fe78bSCy Schubert {
374*7f2fe78bSCy Schubert int rc;
375*7f2fe78bSCy Schubert HANDLE hMutex;
376*7f2fe78bSCy Schubert
377*7f2fe78bSCy Schubert rc = NetId_dialog(lpdlginfo);
378*7f2fe78bSCy Schubert if (rc > -1)
379*7f2fe78bSCy Schubert return rc;
380*7f2fe78bSCy Schubert
381*7f2fe78bSCy Schubert hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
382*7f2fe78bSCy Schubert if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
383*7f2fe78bSCy Schubert if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
384*7f2fe78bSCy Schubert return -1;
385*7f2fe78bSCy Schubert }
386*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
387*7f2fe78bSCy Schubert CloseHandle(hMutex);
388*7f2fe78bSCy Schubert return 1; /* pretend the dialog was displayed and succeeded */
389*7f2fe78bSCy Schubert }
390*7f2fe78bSCy Schubert
391*7f2fe78bSCy Schubert lpdlginfo->dlgtype = DLGTYPE_CHPASSWD;
392*7f2fe78bSCy Schubert
393*7f2fe78bSCy Schubert /* Call the Dialog box with the DLL's Password Callback and the
394*7f2fe78bSCy Schubert DLL's instance handle. */
395*7f2fe78bSCy Schubert rc = DialogBoxParam(hLeashInst, "CHANGEPASSWORDDLG", hParent,
396*7f2fe78bSCy Schubert PasswordProc, (LPARAM)lpdlginfo);
397*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
398*7f2fe78bSCy Schubert CloseHandle(hMutex);
399*7f2fe78bSCy Schubert return rc;
400*7f2fe78bSCy Schubert }
401*7f2fe78bSCy Schubert
Leash_changepwd_dlg_ex(HWND hParent,LPLSH_DLGINFO_EX lpdlginfo)402*7f2fe78bSCy Schubert int Leash_changepwd_dlg_ex(HWND hParent, LPLSH_DLGINFO_EX lpdlginfo)
403*7f2fe78bSCy Schubert {
404*7f2fe78bSCy Schubert int rc;
405*7f2fe78bSCy Schubert HANDLE hMutex;
406*7f2fe78bSCy Schubert
407*7f2fe78bSCy Schubert rc = NetId_dialog_ex(lpdlginfo);
408*7f2fe78bSCy Schubert if (rc > -1)
409*7f2fe78bSCy Schubert return rc;
410*7f2fe78bSCy Schubert
411*7f2fe78bSCy Schubert hMutex = CreateMutex(NULL, TRUE, LEASH_DLG_MUTEX_NAME);
412*7f2fe78bSCy Schubert if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
413*7f2fe78bSCy Schubert if ( WaitForSingleObject( hMutex, INFINITE ) != WAIT_OBJECT_0 ) {
414*7f2fe78bSCy Schubert return -1;
415*7f2fe78bSCy Schubert }
416*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
417*7f2fe78bSCy Schubert CloseHandle(hMutex);
418*7f2fe78bSCy Schubert return 1; /* pretend the dialog was displayed and succeeded */
419*7f2fe78bSCy Schubert }
420*7f2fe78bSCy Schubert
421*7f2fe78bSCy Schubert lpdlginfo->dlgtype = DLGTYPE_CHPASSWD;
422*7f2fe78bSCy Schubert
423*7f2fe78bSCy Schubert /* Call the Dialog box with the DLL's Password Callback and the
424*7f2fe78bSCy Schubert DLL's instance handle. */
425*7f2fe78bSCy Schubert rc = DialogBoxParam(hLeashInst, MAKEINTRESOURCE(IDD_PASSWORD), hParent,
426*7f2fe78bSCy Schubert NewPasswordProc, (LPARAM)lpdlginfo);
427*7f2fe78bSCy Schubert ReleaseMutex(hMutex);
428*7f2fe78bSCy Schubert CloseHandle(hMutex);
429*7f2fe78bSCy Schubert return rc;
430*7f2fe78bSCy Schubert }
431*7f2fe78bSCy Schubert
432*7f2fe78bSCy Schubert
433*7f2fe78bSCy Schubert /* These little utils are taken from lshutil.c
434*7f2fe78bSCy Schubert they are added here for the Call back function.
435*7f2fe78bSCy Schubert ****** beginning of added utils from lshutil.c ******/
436*7f2fe78bSCy Schubert
IsDlgItem(HWND hWnd,WORD id)437*7f2fe78bSCy Schubert BOOL IsDlgItem(HWND hWnd, WORD id)
438*7f2fe78bSCy Schubert {
439*7f2fe78bSCy Schubert HWND hChild;
440*7f2fe78bSCy Schubert
441*7f2fe78bSCy Schubert hChild = GetDlgItem(hWnd, id);
442*7f2fe78bSCy Schubert return hChild ? IsWindow(hChild) : 0;
443*7f2fe78bSCy Schubert }
444*7f2fe78bSCy Schubert
lsh_getkeystate(WORD keyid)445*7f2fe78bSCy Schubert int lsh_getkeystate(WORD keyid)
446*7f2fe78bSCy Schubert {
447*7f2fe78bSCy Schubert static BYTE keys[256];
448*7f2fe78bSCy Schubert
449*7f2fe78bSCy Schubert GetKeyboardState((LPBYTE) &keys);
450*7f2fe78bSCy Schubert return (int) keys[keyid];
451*7f2fe78bSCy Schubert }
452*7f2fe78bSCy Schubert
krb_err_func(int offset,long code)453*7f2fe78bSCy Schubert LPSTR krb_err_func(int offset, long code)
454*7f2fe78bSCy Schubert {
455*7f2fe78bSCy Schubert return(NULL);
456*7f2fe78bSCy Schubert }
457*7f2fe78bSCy Schubert
458*7f2fe78bSCy Schubert /****** End of Added utils from leash.c ******/
459*7f2fe78bSCy Schubert
460*7f2fe78bSCy Schubert
PaintLogoBitmap(HANDLE hPicFrame)461*7f2fe78bSCy Schubert int PaintLogoBitmap( HANDLE hPicFrame )
462*7f2fe78bSCy Schubert {
463*7f2fe78bSCy Schubert HBITMAP hBitmap;
464*7f2fe78bSCy Schubert HBITMAP hOldBitmap;
465*7f2fe78bSCy Schubert BITMAP Bitmap;
466*7f2fe78bSCy Schubert HDC hdc, hdcMem;
467*7f2fe78bSCy Schubert RECT rect;
468*7f2fe78bSCy Schubert
469*7f2fe78bSCy Schubert /* Invalidate the drawing space of the picframe. */
470*7f2fe78bSCy Schubert InvalidateRect( hPicFrame, NULL, TRUE);
471*7f2fe78bSCy Schubert UpdateWindow( hPicFrame );
472*7f2fe78bSCy Schubert
473*7f2fe78bSCy Schubert hdc = GetDC(hPicFrame);
474*7f2fe78bSCy Schubert hdcMem = CreateCompatibleDC(hdc);
475*7f2fe78bSCy Schubert GetClientRect(hPicFrame, &rect);
476*7f2fe78bSCy Schubert hBitmap = LoadBitmap(hLeashInst, "LOGOBITMAP");
477*7f2fe78bSCy Schubert hOldBitmap = SelectObject(hdcMem, hBitmap);
478*7f2fe78bSCy Schubert GetObject(hBitmap, sizeof(Bitmap), (LPSTR) &Bitmap);
479*7f2fe78bSCy Schubert StretchBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0,
480*7f2fe78bSCy Schubert Bitmap.bmWidth, Bitmap.bmHeight, SRCCOPY);
481*7f2fe78bSCy Schubert
482*7f2fe78bSCy Schubert SelectObject(hdcMem, hOldBitmap); /* pbh 8-15-94 */
483*7f2fe78bSCy Schubert ReleaseDC(hPicFrame, hdc);
484*7f2fe78bSCy Schubert DeleteObject( hBitmap ); /* pbh 8-15-94 */
485*7f2fe78bSCy Schubert DeleteDC( hdcMem ); /* pbh 8-15-94 */
486*7f2fe78bSCy Schubert
487*7f2fe78bSCy Schubert return 0;
488*7f2fe78bSCy Schubert }
489*7f2fe78bSCy Schubert
490*7f2fe78bSCy Schubert
491*7f2fe78bSCy Schubert /* Callback function for the Password Dialog box that initilializes and
492*7f2fe78bSCy Schubert renews tickets. */
493*7f2fe78bSCy Schubert
494*7f2fe78bSCy Schubert INT_PTR
495*7f2fe78bSCy Schubert CALLBACK
PasswordProc(HWND hDialog,UINT message,WPARAM wParam,LPARAM lParam)496*7f2fe78bSCy Schubert PasswordProc(
497*7f2fe78bSCy Schubert HWND hDialog,
498*7f2fe78bSCy Schubert UINT message,
499*7f2fe78bSCy Schubert WPARAM wParam,
500*7f2fe78bSCy Schubert LPARAM lParam
501*7f2fe78bSCy Schubert )
502*7f2fe78bSCy Schubert {
503*7f2fe78bSCy Schubert static POINT Position = { -1, -1 };
504*7f2fe78bSCy Schubert static short state;
505*7f2fe78bSCy Schubert int lifetime;
506*7f2fe78bSCy Schubert #define ISCHPASSWD (lpdi->dlgtype == DLGTYPE_CHPASSWD)
507*7f2fe78bSCy Schubert #define STATE_INIT 0
508*7f2fe78bSCy Schubert #define STATE_PRINCIPAL 1
509*7f2fe78bSCy Schubert #define STATE_OLDPWD 2
510*7f2fe78bSCy Schubert #define STATE_NEWPWD1 3
511*7f2fe78bSCy Schubert #define STATE_NEWPWD2 4
512*7f2fe78bSCy Schubert #define STATE_CLOSED 5
513*7f2fe78bSCy Schubert #define NEXTSTATE(newstate) SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE, newstate)
514*7f2fe78bSCy Schubert static int ids[STATE_NEWPWD2 + 1] = {
515*7f2fe78bSCy Schubert 0,
516*7f2fe78bSCy Schubert ID_PRINCIPAL, ID_OLDPASSWORD, ID_CONFIRMPASSWORD1,
517*7f2fe78bSCy Schubert ID_CONFIRMPASSWORD2};
518*7f2fe78bSCy Schubert static char principal[255], oldpassword[255], newpassword[255],
519*7f2fe78bSCy Schubert newpassword2[255];
520*7f2fe78bSCy Schubert static char *strings[STATE_NEWPWD2 + 1] = {
521*7f2fe78bSCy Schubert NULL, principal, oldpassword, newpassword, newpassword2};
522*7f2fe78bSCy Schubert static LPLSH_DLGINFO lpdi;
523*7f2fe78bSCy Schubert char gbuf[200]; /* global buffer for random stuff. */
524*7f2fe78bSCy Schubert
525*7f2fe78bSCy Schubert
526*7f2fe78bSCy Schubert #define checkfirst(id, stuff) IsDlgItem(hDialog, id) ? stuff : 0
527*7f2fe78bSCy Schubert #define CGetDlgItemText(hDlg, id, cp, len) checkfirst(id, GetDlgItemText(hDlg, id, cp, len))
528*7f2fe78bSCy Schubert #define CSetDlgItemText(hDlg, id, cp) checkfirst(id, SetDlgItemText(hDlg, id, cp))
529*7f2fe78bSCy Schubert #define CSetDlgItemInt(hDlg, id, i, b) checkfirst(id, SetDlgItemInt(hDlg, id, i, b))
530*7f2fe78bSCy Schubert #define CSendDlgItemMessage(hDlg, id, m, w, l) checkfirst(id, SendDlgItemMessage(hDlg, id, m, w, l))
531*7f2fe78bSCy Schubert #define CSendMessage(hwnd, m, w, l) IsWindow(hwnd) ? SendMessage(hwnd, m, w, l) : 0
532*7f2fe78bSCy Schubert #define CShowWindow(hwnd, state) IsWindow(hwnd) ? ShowWindow(hwnd, state) : 0
533*7f2fe78bSCy Schubert
534*7f2fe78bSCy Schubert #define GETITEMTEXT(id, cp, maxlen) \
535*7f2fe78bSCy Schubert GetDlgItemText(hDialog, id, (LPSTR)(cp), maxlen)
536*7f2fe78bSCy Schubert #define CloseMe(x) SendMessage(hDialog, WM_COMMAND, ID_CLOSEME, x)
537*7f2fe78bSCy Schubert
538*7f2fe78bSCy Schubert
539*7f2fe78bSCy Schubert #define EDITFRAMEIDOFFSET 500
540*7f2fe78bSCy Schubert
541*7f2fe78bSCy Schubert switch (message) {
542*7f2fe78bSCy Schubert
543*7f2fe78bSCy Schubert case WM_INITDIALOG:
544*7f2fe78bSCy Schubert
545*7f2fe78bSCy Schubert *( (LPLSH_DLGINFO far *)(&lpdi) ) = (LPLSH_DLGINFO)(LPSTR)lParam;
546*7f2fe78bSCy Schubert lpdi->dlgstatemax = ISCHPASSWD ? STATE_NEWPWD2
547*7f2fe78bSCy Schubert : STATE_OLDPWD;
548*7f2fe78bSCy Schubert SetWindowText(hDialog, lpdi->title);
549*7f2fe78bSCy Schubert /* stop at old password for normal password dlg */
550*7f2fe78bSCy Schubert
551*7f2fe78bSCy Schubert SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);
552*7f2fe78bSCy Schubert
553*7f2fe78bSCy Schubert if (lpdi->principal)
554*7f2fe78bSCy Schubert lstrcpy(principal, lpdi->principal);
555*7f2fe78bSCy Schubert else
556*7f2fe78bSCy Schubert {
557*7f2fe78bSCy Schubert principal[0] = '\0';
558*7f2fe78bSCy Schubert /* is there a principal already being used? if so, use it. */
559*7f2fe78bSCy Schubert }
560*7f2fe78bSCy Schubert
561*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, ID_PRINCIPAL, principal);
562*7f2fe78bSCy Schubert
563*7f2fe78bSCy Schubert lifetime = Leash_get_default_lifetime();
564*7f2fe78bSCy Schubert if (lifetime <= 0)
565*7f2fe78bSCy Schubert lifetime = 600; /* 10 hours */
566*7f2fe78bSCy Schubert
567*7f2fe78bSCy Schubert CSetDlgItemInt(hDialog, ID_DURATION, lifetime, FALSE);
568*7f2fe78bSCy Schubert
569*7f2fe78bSCy Schubert /* setup text of stuff. */
570*7f2fe78bSCy Schubert
571*7f2fe78bSCy Schubert if (Position.x > 0 && Position.y > 0 &&
572*7f2fe78bSCy Schubert Position.x < GetSystemMetrics(SM_CXSCREEN) &&
573*7f2fe78bSCy Schubert Position.y < GetSystemMetrics(SM_CYSCREEN))
574*7f2fe78bSCy Schubert SetWindowPos(hDialog, 0, Position.x, Position.y, 0, 0,
575*7f2fe78bSCy Schubert SWP_NOSIZE | SWP_NOZORDER);
576*7f2fe78bSCy Schubert
577*7f2fe78bSCy Schubert /* set window pos to last saved window pos */
578*7f2fe78bSCy Schubert
579*7f2fe78bSCy Schubert
580*7f2fe78bSCy Schubert /* replace standard edit control with our own password edit
581*7f2fe78bSCy Schubert control for password entry. */
582*7f2fe78bSCy Schubert {
583*7f2fe78bSCy Schubert RECT r;
584*7f2fe78bSCy Schubert POINT pxy, psz;
585*7f2fe78bSCy Schubert HWND hwnd;
586*7f2fe78bSCy Schubert int i;
587*7f2fe78bSCy Schubert
588*7f2fe78bSCy Schubert for (i = ID_OLDPASSWORD; i <= ids[lpdi->dlgstatemax]; i++)
589*7f2fe78bSCy Schubert {
590*7f2fe78bSCy Schubert hwnd = GetDlgItem(hDialog, i);
591*7f2fe78bSCy Schubert GetWindowRect(hwnd, &r);
592*7f2fe78bSCy Schubert psz.x = r.right - r.left;
593*7f2fe78bSCy Schubert psz.y = r.bottom - r.top;
594*7f2fe78bSCy Schubert
595*7f2fe78bSCy Schubert pxy.x = r.left; pxy.y = r.top;
596*7f2fe78bSCy Schubert ScreenToClient(hDialog, &pxy);
597*7f2fe78bSCy Schubert
598*7f2fe78bSCy Schubert /* create a substitute window: */
599*7f2fe78bSCy Schubert
600*7f2fe78bSCy Schubert DestroyWindow(hwnd);
601*7f2fe78bSCy Schubert /* kill off old edit window. */
602*7f2fe78bSCy Schubert
603*7f2fe78bSCy Schubert CreateWindow(MIT_PWD_DLL_CLASS, /* our password window :o] */
604*7f2fe78bSCy Schubert "", /* no text */
605*7f2fe78bSCy Schubert WS_CHILD | WS_VISIBLE | WS_TABSTOP, /* child window, visible,tabstop */
606*7f2fe78bSCy Schubert pxy.x, pxy.y, /* x, y coords */
607*7f2fe78bSCy Schubert psz.x, psz.y, /* width, height */
608*7f2fe78bSCy Schubert hDialog, /* the parent */
609*7f2fe78bSCy Schubert (HMENU)i, /* same id *//* id offset for the frames */
610*7f2fe78bSCy Schubert (HANDLE)hLeashInst,/* instance handles */
611*7f2fe78bSCy Schubert NULL); /* createstruct */
612*7f2fe78bSCy Schubert }
613*7f2fe78bSCy Schubert }
614*7f2fe78bSCy Schubert
615*7f2fe78bSCy Schubert state = STATE_INIT;
616*7f2fe78bSCy Schubert NEXTSTATE(STATE_PRINCIPAL);
617*7f2fe78bSCy Schubert break;
618*7f2fe78bSCy Schubert
619*7f2fe78bSCy Schubert case WM_PAINT:
620*7f2fe78bSCy Schubert PaintLogoBitmap( GetDlgItem(hDialog, ID_PICFRAME) );
621*7f2fe78bSCy Schubert break;
622*7f2fe78bSCy Schubert
623*7f2fe78bSCy Schubert case WM_COMMAND:
624*7f2fe78bSCy Schubert switch (wParam) {
625*7f2fe78bSCy Schubert case ID_HELP:
626*7f2fe78bSCy Schubert {
627*7f2fe78bSCy Schubert WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,
628*7f2fe78bSCy Schubert ISCHPASSWD ? ID_CHANGEPASSWORD : ID_INITTICKETS);
629*7f2fe78bSCy Schubert }
630*7f2fe78bSCy Schubert break;
631*7f2fe78bSCy Schubert case ID_CLOSEME:
632*7f2fe78bSCy Schubert {
633*7f2fe78bSCy Schubert int i;
634*7f2fe78bSCy Schubert
635*7f2fe78bSCy Schubert for (i = STATE_PRINCIPAL; i <= lpdi->dlgstatemax; i++)
636*7f2fe78bSCy Schubert {
637*7f2fe78bSCy Schubert memset(strings[i], '\0', 255);
638*7f2fe78bSCy Schubert SetDlgItemText(hDialog, ids[i], "");
639*7f2fe78bSCy Schubert }
640*7f2fe78bSCy Schubert /* I claim these passwords in the name
641*7f2fe78bSCy Schubert of planet '\0'... */
642*7f2fe78bSCy Schubert
643*7f2fe78bSCy Schubert RemoveProp(hDialog, "HANDLES_HELP");
644*7f2fe78bSCy Schubert state = STATE_CLOSED;
645*7f2fe78bSCy Schubert EndDialog(hDialog, (int)lParam);
646*7f2fe78bSCy Schubert return TRUE;
647*7f2fe78bSCy Schubert }
648*7f2fe78bSCy Schubert break;
649*7f2fe78bSCy Schubert case ID_DURATION:
650*7f2fe78bSCy Schubert break;
651*7f2fe78bSCy Schubert case ID_PRINCIPAL:
652*7f2fe78bSCy Schubert case ID_OLDPASSWORD:
653*7f2fe78bSCy Schubert case ID_CONFIRMPASSWORD1:
654*7f2fe78bSCy Schubert case ID_CONFIRMPASSWORD2:
655*7f2fe78bSCy Schubert if (HIWORD(lParam) == EN_SETFOCUS)
656*7f2fe78bSCy Schubert {
657*7f2fe78bSCy Schubert /* nothing, for now. */
658*7f2fe78bSCy Schubert }
659*7f2fe78bSCy Schubert break;
660*7f2fe78bSCy Schubert case ID_NEXTSTATE:
661*7f2fe78bSCy Schubert {
662*7f2fe78bSCy Schubert RECT rbtn, redit;
663*7f2fe78bSCy Schubert POINT p;
664*7f2fe78bSCy Schubert int idfocus, i, s;
665*7f2fe78bSCy Schubert HWND hfocus, hbtn;
666*7f2fe78bSCy Schubert int oldstate = state;
667*7f2fe78bSCy Schubert
668*7f2fe78bSCy Schubert state = (int)lParam;
669*7f2fe78bSCy Schubert idfocus = ids[state];
670*7f2fe78bSCy Schubert
671*7f2fe78bSCy Schubert #ifdef ONE_NEWPWDBOX
672*7f2fe78bSCy Schubert if (state == STATE_NEWPWD2)
673*7f2fe78bSCy Schubert SendDlgItemMessage(hDialog, ID_CONFIRMPASSWORD1, WM_SETTEXT,
674*7f2fe78bSCy Schubert 0, (LONG)(LPSTR)"");
675*7f2fe78bSCy Schubert #endif
676*7f2fe78bSCy Schubert
677*7f2fe78bSCy Schubert for (s = STATE_PRINCIPAL; s <= lpdi->dlgstatemax; s++)
678*7f2fe78bSCy Schubert {
679*7f2fe78bSCy Schubert i = ids[s];
680*7f2fe78bSCy Schubert
681*7f2fe78bSCy Schubert if (s > state)
682*7f2fe78bSCy Schubert SendDlgItemMessage(hDialog, i, WM_SETTEXT, 0,
683*7f2fe78bSCy Schubert (LONG)(LPSTR)"");
684*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog, i), i == idfocus);
685*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog, i),
686*7f2fe78bSCy Schubert (i <= idfocus ? SW_SHOW : SW_HIDE));
687*7f2fe78bSCy Schubert /* ShowWindow(GetDlgItem(hDialog, i + CAPTION_OFFSET),
688*7f2fe78bSCy Schubert (i <= idfocus ? SW_SHOW : SW_HIDE));*/
689*7f2fe78bSCy Schubert /* show caption? */
690*7f2fe78bSCy Schubert }
691*7f2fe78bSCy Schubert #ifdef ONE_NEWPWDBOX
692*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, ID_CONFIRMCAPTION1,
693*7f2fe78bSCy Schubert state < STATE_NEWPWD2 ?
694*7f2fe78bSCy Schubert "Enter new password:" :
695*7f2fe78bSCy Schubert "Enter new password again:");
696*7f2fe78bSCy Schubert if (state == STATE_NEWPWD2)
697*7f2fe78bSCy Schubert {
698*7f2fe78bSCy Schubert HWND htext;
699*7f2fe78bSCy Schubert htext = GetDlgItem(hDialog, ID_CONFIRMCAPTION1);
700*7f2fe78bSCy Schubert FlashAnyWindow(htext);
701*7f2fe78bSCy Schubert WinSleep(50);
702*7f2fe78bSCy Schubert FlashAnyWindow(htext);
703*7f2fe78bSCy Schubert }
704*7f2fe78bSCy Schubert #endif
705*7f2fe78bSCy Schubert
706*7f2fe78bSCy Schubert hfocus = GetDlgItem(hDialog, idfocus);
707*7f2fe78bSCy Schubert if ( hfocus != (HWND)NULL ){
708*7f2fe78bSCy Schubert SetFocus(hfocus); /* switch focus */
709*7f2fe78bSCy Schubert if (idfocus >= ID_OLDPASSWORD)
710*7f2fe78bSCy Schubert SendMessage(hfocus, WM_SETTEXT, 0, (LPARAM) (LPSTR) "");
711*7f2fe78bSCy Schubert else
712*7f2fe78bSCy Schubert {
713*7f2fe78bSCy Schubert SendMessage(hfocus, EM_SETSEL, 0, MAKELONG(0, -1));
714*7f2fe78bSCy Schubert }
715*7f2fe78bSCy Schubert GetWindowRect(hfocus, &redit);
716*7f2fe78bSCy Schubert }
717*7f2fe78bSCy Schubert
718*7f2fe78bSCy Schubert hbtn = GetDlgItem(hDialog, IDOK);
719*7f2fe78bSCy Schubert if( IsWindow(hbtn) ){
720*7f2fe78bSCy Schubert GetWindowRect(hbtn, &rbtn);
721*7f2fe78bSCy Schubert p.x = rbtn.left; p.y = redit.top;
722*7f2fe78bSCy Schubert ScreenToClient(hDialog, &p);
723*7f2fe78bSCy Schubert
724*7f2fe78bSCy Schubert SetWindowPos(hbtn, 0, p.x, p.y, 0, 0,
725*7f2fe78bSCy Schubert SWP_NOSIZE | SWP_NOZORDER);
726*7f2fe78bSCy Schubert }
727*7f2fe78bSCy Schubert }
728*7f2fe78bSCy Schubert break;
729*7f2fe78bSCy Schubert case IDOK:
730*7f2fe78bSCy Schubert {
731*7f2fe78bSCy Schubert char* p_Principal;
732*7f2fe78bSCy Schubert DWORD value = 0;
733*7f2fe78bSCy Schubert
734*7f2fe78bSCy Schubert GETITEMTEXT(ids[state], (LPSTR)strings[state], 255);
735*7f2fe78bSCy Schubert
736*7f2fe78bSCy Schubert switch(state)
737*7f2fe78bSCy Schubert {
738*7f2fe78bSCy Schubert case STATE_PRINCIPAL:
739*7f2fe78bSCy Schubert {
740*7f2fe78bSCy Schubert if (!principal[0])
741*7f2fe78bSCy Schubert {
742*7f2fe78bSCy Schubert MessageBox(hDialog,
743*7f2fe78bSCy Schubert "You are not allowed to enter a blank principal.",
744*7f2fe78bSCy Schubert "Invalid Principal",
745*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
746*7f2fe78bSCy Schubert NEXTSTATE(STATE_PRINCIPAL);
747*7f2fe78bSCy Schubert return TRUE;
748*7f2fe78bSCy Schubert }
749*7f2fe78bSCy Schubert
750*7f2fe78bSCy Schubert // Change 'principal' to upper case after checking
751*7f2fe78bSCy Schubert // "UpperCase" value in the Registry
752*7f2fe78bSCy Schubert p_Principal = strchr(principal, '@');
753*7f2fe78bSCy Schubert
754*7f2fe78bSCy Schubert if (p_Principal && Leash_get_default_uppercaserealm())
755*7f2fe78bSCy Schubert strupr(p_Principal);
756*7f2fe78bSCy Schubert break;
757*7f2fe78bSCy Schubert }
758*7f2fe78bSCy Schubert case STATE_OLDPWD:
759*7f2fe78bSCy Schubert {
760*7f2fe78bSCy Schubert int duration;
761*7f2fe78bSCy Schubert
762*7f2fe78bSCy Schubert if (!ISCHPASSWD)
763*7f2fe78bSCy Schubert duration = GetDlgItemInt(hDialog, ID_DURATION, 0, FALSE);
764*7f2fe78bSCy Schubert if (!oldpassword[0])
765*7f2fe78bSCy Schubert {
766*7f2fe78bSCy Schubert MessageBox(hDialog, "You are not allowed to enter a "
767*7f2fe78bSCy Schubert "blank password.",
768*7f2fe78bSCy Schubert "Invalid Password",
769*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
770*7f2fe78bSCy Schubert NEXTSTATE(STATE_OLDPWD);
771*7f2fe78bSCy Schubert return TRUE;
772*7f2fe78bSCy Schubert }
773*7f2fe78bSCy Schubert if (lpdi->dlgtype == DLGTYPE_CHPASSWD)
774*7f2fe78bSCy Schubert lsh_errno = Leash_int_checkpwd(principal, oldpassword, 1);
775*7f2fe78bSCy Schubert else
776*7f2fe78bSCy Schubert {
777*7f2fe78bSCy Schubert lsh_errno = Leash_int_kinit_ex( 0,
778*7f2fe78bSCy Schubert hDialog,
779*7f2fe78bSCy Schubert principal,
780*7f2fe78bSCy Schubert oldpassword,
781*7f2fe78bSCy Schubert duration,
782*7f2fe78bSCy Schubert Leash_get_default_forwardable(),
783*7f2fe78bSCy Schubert Leash_get_default_proxiable(),
784*7f2fe78bSCy Schubert Leash_get_default_renew_till(),
785*7f2fe78bSCy Schubert Leash_get_default_noaddresses(),
786*7f2fe78bSCy Schubert Leash_get_default_publicip(),
787*7f2fe78bSCy Schubert 1
788*7f2fe78bSCy Schubert );
789*7f2fe78bSCy Schubert }
790*7f2fe78bSCy Schubert if (lsh_errno != 0)
791*7f2fe78bSCy Schubert {
792*7f2fe78bSCy Schubert int next_state = state;
793*7f2fe78bSCy Schubert int capslock;
794*7f2fe78bSCy Schubert char *cp;
795*7f2fe78bSCy Schubert
796*7f2fe78bSCy Schubert err_context = "";
797*7f2fe78bSCy Schubert
798*7f2fe78bSCy Schubert switch(lsh_errno)
799*7f2fe78bSCy Schubert {
800*7f2fe78bSCy Schubert case LSH_INVPRINCIPAL:
801*7f2fe78bSCy Schubert case LSH_INVINSTANCE:
802*7f2fe78bSCy Schubert case LSH_INVREALM:
803*7f2fe78bSCy Schubert next_state = STATE_PRINCIPAL;
804*7f2fe78bSCy Schubert break;
805*7f2fe78bSCy Schubert }
806*7f2fe78bSCy Schubert capslock = lsh_getkeystate(VK_CAPITAL);
807*7f2fe78bSCy Schubert /* low-order bit means caps lock is
808*7f2fe78bSCy Schubert toggled; if so, warn user since there's
809*7f2fe78bSCy Schubert been an error. */
810*7f2fe78bSCy Schubert if (capslock & 1)
811*7f2fe78bSCy Schubert {
812*7f2fe78bSCy Schubert lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
813*7f2fe78bSCy Schubert cp = gbuf + lstrlen((LPSTR)gbuf);
814*7f2fe78bSCy Schubert if (cp != gbuf)
815*7f2fe78bSCy Schubert *cp++ = ' ';
816*7f2fe78bSCy Schubert lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
817*7f2fe78bSCy Schubert err_context = gbuf;
818*7f2fe78bSCy Schubert }
819*7f2fe78bSCy Schubert
820*7f2fe78bSCy Schubert // XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""
821*7f2fe78bSCy Schubert // XXX : "Ticket initialization failed.");
822*7f2fe78bSCy Schubert NEXTSTATE(next_state);
823*7f2fe78bSCy Schubert return TRUE;
824*7f2fe78bSCy Schubert }
825*7f2fe78bSCy Schubert if (ISCHPASSWD)
826*7f2fe78bSCy Schubert break;
827*7f2fe78bSCy Schubert CloseMe(TRUE); /* success */
828*7f2fe78bSCy Schubert }
829*7f2fe78bSCy Schubert break;
830*7f2fe78bSCy Schubert case STATE_NEWPWD1:
831*7f2fe78bSCy Schubert {
832*7f2fe78bSCy Schubert int i = 0;
833*7f2fe78bSCy Schubert int bit8 = 0;
834*7f2fe78bSCy Schubert
835*7f2fe78bSCy Schubert for( i = 0; i < 255; i++ ){
836*7f2fe78bSCy Schubert if( newpassword[i] == '\0' ){
837*7f2fe78bSCy Schubert if ( bit8 ) {
838*7f2fe78bSCy Schubert MessageBox(hDialog,
839*7f2fe78bSCy Schubert "Passwords should not contain non-ASCII characters.",
840*7f2fe78bSCy Schubert "Internationalization Warning",
841*7f2fe78bSCy Schubert MB_OK | MB_ICONINFORMATION);
842*7f2fe78bSCy Schubert }
843*7f2fe78bSCy Schubert i = 255;
844*7f2fe78bSCy Schubert break;
845*7f2fe78bSCy Schubert } else if( !isprint(newpassword[i]) ){
846*7f2fe78bSCy Schubert memset(newpassword, '\0', 255);
847*7f2fe78bSCy Schubert /* I claim these passwords in the name of planet '\0'... */
848*7f2fe78bSCy Schubert MessageBox(hDialog,
849*7f2fe78bSCy Schubert "Passwords may not contain non-printable characters.",
850*7f2fe78bSCy Schubert "Invalid Password",
851*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
852*7f2fe78bSCy Schubert NEXTSTATE(STATE_NEWPWD1);
853*7f2fe78bSCy Schubert return TRUE;
854*7f2fe78bSCy Schubert } else if ( newpassword[i] > 127 )
855*7f2fe78bSCy Schubert bit8 = 1;
856*7f2fe78bSCy Schubert }
857*7f2fe78bSCy Schubert }
858*7f2fe78bSCy Schubert break;
859*7f2fe78bSCy Schubert case STATE_NEWPWD2:
860*7f2fe78bSCy Schubert if (lstrcmp(newpassword, newpassword2))
861*7f2fe78bSCy Schubert {
862*7f2fe78bSCy Schubert NEXTSTATE(STATE_NEWPWD1);
863*7f2fe78bSCy Schubert MessageBox(hDialog,
864*7f2fe78bSCy Schubert "The new password was not entered the same way twice.",
865*7f2fe78bSCy Schubert "Password validation error",
866*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
867*7f2fe78bSCy Schubert return TRUE;
868*7f2fe78bSCy Schubert }
869*7f2fe78bSCy Schubert else
870*7f2fe78bSCy Schubert {
871*7f2fe78bSCy Schubert /* make them type both pwds again if error */
872*7f2fe78bSCy Schubert int next_state = STATE_NEWPWD1;
873*7f2fe78bSCy Schubert int capslock;
874*7f2fe78bSCy Schubert char *cp;
875*7f2fe78bSCy Schubert
876*7f2fe78bSCy Schubert capslock = lsh_getkeystate(VK_CAPITAL);
877*7f2fe78bSCy Schubert /* low-order bit means caps lock is
878*7f2fe78bSCy Schubert toggled; if so, warn user since there's
879*7f2fe78bSCy Schubert been an error. */
880*7f2fe78bSCy Schubert if (capslock & 1)
881*7f2fe78bSCy Schubert {
882*7f2fe78bSCy Schubert lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
883*7f2fe78bSCy Schubert cp = gbuf + lstrlen((LPSTR)gbuf);
884*7f2fe78bSCy Schubert if (cp != gbuf)
885*7f2fe78bSCy Schubert *cp++ = ' ';
886*7f2fe78bSCy Schubert lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
887*7f2fe78bSCy Schubert err_context = gbuf;
888*7f2fe78bSCy Schubert }
889*7f2fe78bSCy Schubert
890*7f2fe78bSCy Schubert if ((lsh_errno =
891*7f2fe78bSCy Schubert Leash_int_changepwd(principal, oldpassword,
892*7f2fe78bSCy Schubert newpassword, 0, 1))
893*7f2fe78bSCy Schubert == 0){
894*7f2fe78bSCy Schubert CloseMe(TRUE);
895*7f2fe78bSCy Schubert }
896*7f2fe78bSCy Schubert else {
897*7f2fe78bSCy Schubert // XXX - DoNiftyErrorReport(lsh_errno, "Error while changing password.");
898*7f2fe78bSCy Schubert NEXTSTATE(next_state);
899*7f2fe78bSCy Schubert return TRUE;
900*7f2fe78bSCy Schubert
901*7f2fe78bSCy Schubert }
902*7f2fe78bSCy Schubert }
903*7f2fe78bSCy Schubert break;
904*7f2fe78bSCy Schubert }
905*7f2fe78bSCy Schubert /* increment state, but send the old state as a
906*7f2fe78bSCy Schubert parameter */
907*7f2fe78bSCy Schubert SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE, state + 1);
908*7f2fe78bSCy Schubert }
909*7f2fe78bSCy Schubert break;
910*7f2fe78bSCy Schubert case IDCANCEL:
911*7f2fe78bSCy Schubert CloseMe(FALSE);
912*7f2fe78bSCy Schubert break;
913*7f2fe78bSCy Schubert case ID_RESTART:
914*7f2fe78bSCy Schubert {
915*7f2fe78bSCy Schubert int i;
916*7f2fe78bSCy Schubert
917*7f2fe78bSCy Schubert for (i = ID_OLDPASSWORD; i <= ids[lpdi->dlgstatemax]; i++)
918*7f2fe78bSCy Schubert SetDlgItemText(hDialog, i, "");
919*7f2fe78bSCy Schubert SendMessage(hDialog, WM_COMMAND, ID_NEXTSTATE,
920*7f2fe78bSCy Schubert STATE_PRINCIPAL);
921*7f2fe78bSCy Schubert }
922*7f2fe78bSCy Schubert break;
923*7f2fe78bSCy Schubert }
924*7f2fe78bSCy Schubert break;
925*7f2fe78bSCy Schubert
926*7f2fe78bSCy Schubert case WM_MOVE:
927*7f2fe78bSCy Schubert if (state != STATE_CLOSED)
928*7f2fe78bSCy Schubert #ifdef _WIN32
929*7f2fe78bSCy Schubert #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \
930*7f2fe78bSCy Schubert (pt).y=(SHORT)HIWORD(l))
931*7f2fe78bSCy Schubert LONG2POINT(lParam,Position);
932*7f2fe78bSCy Schubert #else
933*7f2fe78bSCy Schubert Position = MAKEPOINT(lParam);
934*7f2fe78bSCy Schubert #endif
935*7f2fe78bSCy Schubert break;
936*7f2fe78bSCy Schubert }
937*7f2fe78bSCy Schubert return FALSE;
938*7f2fe78bSCy Schubert }
939*7f2fe78bSCy Schubert
940*7f2fe78bSCy Schubert
941*7f2fe78bSCy Schubert #define KRB_FILE "KRB.CON"
942*7f2fe78bSCy Schubert #define KRBREALM_FILE "KRBREALM.CON"
943*7f2fe78bSCy Schubert #define KRB5_FILE "KRB5.INI"
944*7f2fe78bSCy Schubert
945*7f2fe78bSCy Schubert BOOL
GetProfileFile(LPSTR confname,UINT szConfname)946*7f2fe78bSCy Schubert GetProfileFile(
947*7f2fe78bSCy Schubert LPSTR confname,
948*7f2fe78bSCy Schubert UINT szConfname
949*7f2fe78bSCy Schubert )
950*7f2fe78bSCy Schubert {
951*7f2fe78bSCy Schubert char **configFile = NULL;
952*7f2fe78bSCy Schubert if (hKrb5 &&
953*7f2fe78bSCy Schubert pkrb5_get_default_config_files(&configFile))
954*7f2fe78bSCy Schubert {
955*7f2fe78bSCy Schubert GetWindowsDirectory(confname,szConfname);
956*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
957*7f2fe78bSCy Schubert strncat(confname, "\\",sizeof(confname)-strlen(confname));
958*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
959*7f2fe78bSCy Schubert strncat(confname, KRB5_FILE,sizeof(confname)-strlen(confname));
960*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
961*7f2fe78bSCy Schubert return FALSE;
962*7f2fe78bSCy Schubert }
963*7f2fe78bSCy Schubert
964*7f2fe78bSCy Schubert *confname = 0;
965*7f2fe78bSCy Schubert
966*7f2fe78bSCy Schubert if (hKrb5 && configFile)
967*7f2fe78bSCy Schubert {
968*7f2fe78bSCy Schubert strncpy(confname, *configFile, szConfname);
969*7f2fe78bSCy Schubert pkrb5_free_config_files(configFile);
970*7f2fe78bSCy Schubert }
971*7f2fe78bSCy Schubert
972*7f2fe78bSCy Schubert if (!*confname)
973*7f2fe78bSCy Schubert {
974*7f2fe78bSCy Schubert GetWindowsDirectory(confname,szConfname);
975*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
976*7f2fe78bSCy Schubert strncat(confname, "\\",sizeof(confname)-strlen(confname));
977*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
978*7f2fe78bSCy Schubert strncat(confname, KRB5_FILE,sizeof(confname)-strlen(confname));
979*7f2fe78bSCy Schubert confname[szConfname-1] = '\0';
980*7f2fe78bSCy Schubert }
981*7f2fe78bSCy Schubert
982*7f2fe78bSCy Schubert return FALSE;
983*7f2fe78bSCy Schubert }
984*7f2fe78bSCy Schubert
985*7f2fe78bSCy Schubert int
readstring(FILE * file,char * buf,int len)986*7f2fe78bSCy Schubert readstring(FILE * file, char * buf, int len)
987*7f2fe78bSCy Schubert {
988*7f2fe78bSCy Schubert int c,i;
989*7f2fe78bSCy Schubert memset(buf, '\0', sizeof(buf));
990*7f2fe78bSCy Schubert for (i=0, c=fgetc(file); c != EOF ; c=fgetc(file), i++)
991*7f2fe78bSCy Schubert {
992*7f2fe78bSCy Schubert if (i < sizeof(buf)) {
993*7f2fe78bSCy Schubert if (c == '\n') {
994*7f2fe78bSCy Schubert buf[i] = '\0';
995*7f2fe78bSCy Schubert return i;
996*7f2fe78bSCy Schubert } else {
997*7f2fe78bSCy Schubert buf[i] = c;
998*7f2fe78bSCy Schubert }
999*7f2fe78bSCy Schubert } else {
1000*7f2fe78bSCy Schubert if (c == '\n') {
1001*7f2fe78bSCy Schubert buf[len-1] = '\0';
1002*7f2fe78bSCy Schubert return(i);
1003*7f2fe78bSCy Schubert }
1004*7f2fe78bSCy Schubert }
1005*7f2fe78bSCy Schubert }
1006*7f2fe78bSCy Schubert if (c == EOF) {
1007*7f2fe78bSCy Schubert if (i > 0 && i < len) {
1008*7f2fe78bSCy Schubert buf[i] = '\0';
1009*7f2fe78bSCy Schubert return(i);
1010*7f2fe78bSCy Schubert } else {
1011*7f2fe78bSCy Schubert buf[len-1] = '\0';
1012*7f2fe78bSCy Schubert return(-1);
1013*7f2fe78bSCy Schubert }
1014*7f2fe78bSCy Schubert }
1015*7f2fe78bSCy Schubert return(-1);
1016*7f2fe78bSCy Schubert }
1017*7f2fe78bSCy Schubert
1018*7f2fe78bSCy Schubert typedef struct _slider_info {
1019*7f2fe78bSCy Schubert int slider_id;
1020*7f2fe78bSCy Schubert int text_id;
1021*7f2fe78bSCy Schubert int min;
1022*7f2fe78bSCy Schubert int max;
1023*7f2fe78bSCy Schubert int increment;
1024*7f2fe78bSCy Schubert struct _slider_info * next;
1025*7f2fe78bSCy Schubert } slider_info;
1026*7f2fe78bSCy Schubert static slider_info * sliders = NULL;
1027*7f2fe78bSCy Schubert
1028*7f2fe78bSCy Schubert static slider_info *
FreeSlider(slider_info * s)1029*7f2fe78bSCy Schubert FreeSlider(slider_info * s)
1030*7f2fe78bSCy Schubert {
1031*7f2fe78bSCy Schubert slider_info * n = NULL;
1032*7f2fe78bSCy Schubert
1033*7f2fe78bSCy Schubert if (s) {
1034*7f2fe78bSCy Schubert n = s->next;
1035*7f2fe78bSCy Schubert free(s);
1036*7f2fe78bSCy Schubert }
1037*7f2fe78bSCy Schubert return n;
1038*7f2fe78bSCy Schubert }
1039*7f2fe78bSCy Schubert
1040*7f2fe78bSCy Schubert static void
CleanupSliders(void)1041*7f2fe78bSCy Schubert CleanupSliders(void)
1042*7f2fe78bSCy Schubert {
1043*7f2fe78bSCy Schubert while(sliders)
1044*7f2fe78bSCy Schubert sliders = FreeSlider(sliders);
1045*7f2fe78bSCy Schubert }
1046*7f2fe78bSCy Schubert
1047*7f2fe78bSCy Schubert
1048*7f2fe78bSCy Schubert static unsigned short
NewSliderValue(HWND hDialog,int id)1049*7f2fe78bSCy Schubert NewSliderValue(HWND hDialog, int id)
1050*7f2fe78bSCy Schubert {
1051*7f2fe78bSCy Schubert int value = 0;
1052*7f2fe78bSCy Schubert slider_info * s = sliders;
1053*7f2fe78bSCy Schubert while(s) {
1054*7f2fe78bSCy Schubert if (s->slider_id == id) {
1055*7f2fe78bSCy Schubert int pos = CSendDlgItemMessage( hDialog, id,
1056*7f2fe78bSCy Schubert TBM_GETPOS,
1057*7f2fe78bSCy Schubert (WPARAM) 0, (LPARAM) 0);
1058*7f2fe78bSCy Schubert value = s->min + (pos * s->increment);
1059*7f2fe78bSCy Schubert break;
1060*7f2fe78bSCy Schubert }
1061*7f2fe78bSCy Schubert s = s->next;
1062*7f2fe78bSCy Schubert }
1063*7f2fe78bSCy Schubert return(value);
1064*7f2fe78bSCy Schubert }
1065*7f2fe78bSCy Schubert
1066*7f2fe78bSCy Schubert static const char *
NewSliderString(int id,int pos)1067*7f2fe78bSCy Schubert NewSliderString(int id, int pos)
1068*7f2fe78bSCy Schubert {
1069*7f2fe78bSCy Schubert static char buf[64]="";
1070*7f2fe78bSCy Schubert char * p = buf;
1071*7f2fe78bSCy Schubert int value = 0;
1072*7f2fe78bSCy Schubert int must_hours = 0;
1073*7f2fe78bSCy Schubert slider_info * s = sliders;
1074*7f2fe78bSCy Schubert while(s) {
1075*7f2fe78bSCy Schubert if (s->slider_id == id) {
1076*7f2fe78bSCy Schubert value = s->min + pos * s->increment;
1077*7f2fe78bSCy Schubert *p = 0;
1078*7f2fe78bSCy Schubert if (value >= 60 * 24) {
1079*7f2fe78bSCy Schubert sprintf(p,"%d day(s) ",value / (60 * 24));
1080*7f2fe78bSCy Schubert value %= (60 * 24);
1081*7f2fe78bSCy Schubert p += strlen(p);
1082*7f2fe78bSCy Schubert must_hours = 1;
1083*7f2fe78bSCy Schubert }
1084*7f2fe78bSCy Schubert if (must_hours || value >= 60) {
1085*7f2fe78bSCy Schubert sprintf(p,"%d hour(s) ",value / 60);
1086*7f2fe78bSCy Schubert value %= 60;
1087*7f2fe78bSCy Schubert p += strlen(p);
1088*7f2fe78bSCy Schubert }
1089*7f2fe78bSCy Schubert sprintf(p,"%d minute(s) ",value);
1090*7f2fe78bSCy Schubert break;
1091*7f2fe78bSCy Schubert }
1092*7f2fe78bSCy Schubert s = s->next;
1093*7f2fe78bSCy Schubert }
1094*7f2fe78bSCy Schubert return(buf);
1095*7f2fe78bSCy Schubert }
1096*7f2fe78bSCy Schubert
1097*7f2fe78bSCy Schubert static void
SetupSlider(HWND hDialog,int sliderID,int textFieldID,int minimum,int maximum,int value)1098*7f2fe78bSCy Schubert SetupSlider( HWND hDialog,
1099*7f2fe78bSCy Schubert int sliderID,
1100*7f2fe78bSCy Schubert int textFieldID,
1101*7f2fe78bSCy Schubert int minimum,
1102*7f2fe78bSCy Schubert int maximum,
1103*7f2fe78bSCy Schubert int value)
1104*7f2fe78bSCy Schubert {
1105*7f2fe78bSCy Schubert int min = minimum;
1106*7f2fe78bSCy Schubert int max = maximum;
1107*7f2fe78bSCy Schubert int increment = 0;
1108*7f2fe78bSCy Schubert int range;
1109*7f2fe78bSCy Schubert int roundedMinimum;
1110*7f2fe78bSCy Schubert int roundedMaximum;
1111*7f2fe78bSCy Schubert int roundedValue;
1112*7f2fe78bSCy Schubert slider_info * new_info;
1113*7f2fe78bSCy Schubert
1114*7f2fe78bSCy Schubert if (max < min) {
1115*7f2fe78bSCy Schubert // swap values
1116*7f2fe78bSCy Schubert int temp = max;
1117*7f2fe78bSCy Schubert max = min;
1118*7f2fe78bSCy Schubert min = temp;
1119*7f2fe78bSCy Schubert }
1120*7f2fe78bSCy Schubert range = max - min;
1121*7f2fe78bSCy Schubert
1122*7f2fe78bSCy Schubert if (range < 5*60) { increment = 1; // 1 s if under 5 m
1123*7f2fe78bSCy Schubert } else if (range < 30*60) { increment = 5; // 5 s if under 30 m
1124*7f2fe78bSCy Schubert } else if (range < 60*60) { increment = 15; // 15 s if under 1 h
1125*7f2fe78bSCy Schubert } else if (range < 2*60*60) { increment = 30; // 30 s if under 2 h
1126*7f2fe78bSCy Schubert } else if (range < 5*60*60) { increment = 60; // 1 m if under 5 h
1127*7f2fe78bSCy Schubert } else if (range < 50*60*60) { increment = 5*60; // 5 m if under 50 h
1128*7f2fe78bSCy Schubert } else if (range < 200*60*60) { increment = 15*60; // 15 m if under 200 h
1129*7f2fe78bSCy Schubert } else if (range < 500*60*60) { increment = 30*60; // 30 m if under 500 h
1130*7f2fe78bSCy Schubert } else { increment = 60*60; } // 1 h otherwise
1131*7f2fe78bSCy Schubert
1132*7f2fe78bSCy Schubert roundedMinimum = (min / increment) * increment;
1133*7f2fe78bSCy Schubert if (roundedMinimum > min) { roundedMinimum -= increment; }
1134*7f2fe78bSCy Schubert if (roundedMinimum <= 0) { roundedMinimum += increment; } // make positive
1135*7f2fe78bSCy Schubert
1136*7f2fe78bSCy Schubert roundedMaximum = (max / increment) * increment;
1137*7f2fe78bSCy Schubert if (roundedMaximum < max) { roundedMaximum += increment; }
1138*7f2fe78bSCy Schubert
1139*7f2fe78bSCy Schubert roundedValue = (value / increment) * increment;
1140*7f2fe78bSCy Schubert if (roundedValue < roundedMinimum) { roundedValue = roundedMinimum; }
1141*7f2fe78bSCy Schubert if (roundedValue > roundedMaximum) { roundedValue = roundedMaximum; }
1142*7f2fe78bSCy Schubert
1143*7f2fe78bSCy Schubert if (roundedMinimum == roundedMaximum) {
1144*7f2fe78bSCy Schubert // [textField setTextColor: [NSColor grayColor]];
1145*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog,sliderID),FALSE);
1146*7f2fe78bSCy Schubert } else {
1147*7f2fe78bSCy Schubert // [textField setTextColor: [NSColor blackColor]];
1148*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog,sliderID),TRUE);
1149*7f2fe78bSCy Schubert }
1150*7f2fe78bSCy Schubert
1151*7f2fe78bSCy Schubert CSendDlgItemMessage( hDialog, sliderID,
1152*7f2fe78bSCy Schubert TBM_SETRANGEMIN,
1153*7f2fe78bSCy Schubert (WPARAM) FALSE,
1154*7f2fe78bSCy Schubert (LPARAM) 0 );
1155*7f2fe78bSCy Schubert CSendDlgItemMessage( hDialog, sliderID,
1156*7f2fe78bSCy Schubert TBM_SETRANGEMAX,
1157*7f2fe78bSCy Schubert (WPARAM) FALSE,
1158*7f2fe78bSCy Schubert (LPARAM) (roundedMaximum - roundedMinimum) / increment );
1159*7f2fe78bSCy Schubert CSendDlgItemMessage( hDialog, sliderID,
1160*7f2fe78bSCy Schubert TBM_SETPOS,
1161*7f2fe78bSCy Schubert (WPARAM) TRUE,
1162*7f2fe78bSCy Schubert (LPARAM) (roundedValue - roundedMinimum) / increment);
1163*7f2fe78bSCy Schubert
1164*7f2fe78bSCy Schubert new_info = (slider_info *) malloc(sizeof(slider_info));
1165*7f2fe78bSCy Schubert new_info->slider_id = sliderID;
1166*7f2fe78bSCy Schubert new_info->text_id = textFieldID;
1167*7f2fe78bSCy Schubert new_info->min = roundedMinimum;
1168*7f2fe78bSCy Schubert new_info->max = roundedMaximum;
1169*7f2fe78bSCy Schubert new_info->increment = increment;
1170*7f2fe78bSCy Schubert new_info->next = sliders;
1171*7f2fe78bSCy Schubert sliders = new_info;
1172*7f2fe78bSCy Schubert
1173*7f2fe78bSCy Schubert SetWindowText(GetDlgItem(hDialog, textFieldID),
1174*7f2fe78bSCy Schubert NewSliderString(sliderID,(roundedValue - roundedMinimum) / increment));
1175*7f2fe78bSCy Schubert }
1176*7f2fe78bSCy Schubert
1177*7f2fe78bSCy Schubert
1178*7f2fe78bSCy Schubert static void
AdjustOptions(HWND hDialog,int show,int hideDiff)1179*7f2fe78bSCy Schubert AdjustOptions(HWND hDialog, int show, int hideDiff)
1180*7f2fe78bSCy Schubert {
1181*7f2fe78bSCy Schubert RECT rect;
1182*7f2fe78bSCy Schubert RECT dlgRect;
1183*7f2fe78bSCy Schubert HWND hwnd;
1184*7f2fe78bSCy Schubert int diff;
1185*7f2fe78bSCy Schubert
1186*7f2fe78bSCy Schubert Leash_set_hide_kinit_options(!show);
1187*7f2fe78bSCy Schubert
1188*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_STATIC_LIFETIME),show);
1189*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_STATIC_LIFETIME_VALUE),show);
1190*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_SLIDER_LIFETIME),show);
1191*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),show);
1192*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_STATIC_RENEW),show);
1193*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_STATIC_RENEW_TILL_VALUE),show);
1194*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_CHECK_FORWARDABLE),show);
1195*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_CHECK_NOADDRESS),show);
1196*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_CHECK_RENEWABLE),show);
1197*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_STATIC_KRB5),show);
1198*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_BUTTON_CLEAR_HISTORY),show);
1199*7f2fe78bSCy Schubert
1200*7f2fe78bSCy Schubert GetWindowRect( hDialog, &dlgRect );
1201*7f2fe78bSCy Schubert diff = dlgRect.top + GetSystemMetrics(SM_CYCAPTION)
1202*7f2fe78bSCy Schubert + GetSystemMetrics(SM_CYDLGFRAME) + (show ? -1 : 1) * hideDiff;
1203*7f2fe78bSCy Schubert
1204*7f2fe78bSCy Schubert hwnd = GetDlgItem(hDialog,IDOK);
1205*7f2fe78bSCy Schubert GetWindowRect(hwnd,&rect);
1206*7f2fe78bSCy Schubert SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1207*7f2fe78bSCy Schubert hwnd = GetDlgItem(hDialog,IDCANCEL);
1208*7f2fe78bSCy Schubert GetWindowRect(hwnd,&rect);
1209*7f2fe78bSCy Schubert SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1210*7f2fe78bSCy Schubert hwnd = GetDlgItem(hDialog,IDC_BUTTON_OPTIONS);
1211*7f2fe78bSCy Schubert GetWindowRect(hwnd,&rect);
1212*7f2fe78bSCy Schubert SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1213*7f2fe78bSCy Schubert hwnd = GetDlgItem(hDialog,IDC_STATIC_VERSION);
1214*7f2fe78bSCy Schubert GetWindowRect(hwnd,&rect);
1215*7f2fe78bSCy Schubert SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1216*7f2fe78bSCy Schubert hwnd = GetDlgItem(hDialog,IDC_STATIC_COPYRIGHT);
1217*7f2fe78bSCy Schubert GetWindowRect(hwnd,&rect);
1218*7f2fe78bSCy Schubert SetWindowPos(hwnd,0,rect.left-dlgRect.left-GetSystemMetrics(SM_CXDLGFRAME),rect.top-diff,0,0,SWP_NOZORDER|SWP_NOSIZE);
1219*7f2fe78bSCy Schubert SetWindowPos(hDialog,0,0,0,
1220*7f2fe78bSCy Schubert dlgRect.right-dlgRect.left,
1221*7f2fe78bSCy Schubert dlgRect.bottom-dlgRect.top+(show ? 1 : - 1) * hideDiff,
1222*7f2fe78bSCy Schubert SWP_NOZORDER|SWP_NOMOVE);
1223*7f2fe78bSCy Schubert
1224*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_BUTTON_OPTIONS,
1225*7f2fe78bSCy Schubert show ? "Hide Advanced" : "Show Advanced");
1226*7f2fe78bSCy Schubert
1227*7f2fe78bSCy Schubert }
1228*7f2fe78bSCy Schubert
1229*7f2fe78bSCy Schubert /* Callback function for the Authentication Dialog box that initializes and
1230*7f2fe78bSCy Schubert renews tickets. */
1231*7f2fe78bSCy Schubert
1232*7f2fe78bSCy Schubert INT_PTR
1233*7f2fe78bSCy Schubert CALLBACK
AuthenticateProc(HWND hDialog,UINT message,WPARAM wParam,LPARAM lParam)1234*7f2fe78bSCy Schubert AuthenticateProc(
1235*7f2fe78bSCy Schubert HWND hDialog,
1236*7f2fe78bSCy Schubert UINT message,
1237*7f2fe78bSCy Schubert WPARAM wParam,
1238*7f2fe78bSCy Schubert LPARAM lParam
1239*7f2fe78bSCy Schubert )
1240*7f2fe78bSCy Schubert {
1241*7f2fe78bSCy Schubert static POINT Position = { -1, -1 };
1242*7f2fe78bSCy Schubert static char principal[256]="";
1243*7f2fe78bSCy Schubert static char password[256]="";
1244*7f2fe78bSCy Schubert static int lifetime=0;
1245*7f2fe78bSCy Schubert static int renew_till=0;
1246*7f2fe78bSCy Schubert static int forwardable=0;
1247*7f2fe78bSCy Schubert static int noaddresses=0;
1248*7f2fe78bSCy Schubert static int proxiable=0;
1249*7f2fe78bSCy Schubert static int publicip=0;
1250*7f2fe78bSCy Schubert static LPLSH_DLGINFO_EX lpdi;
1251*7f2fe78bSCy Schubert static HWND hDlg=0;
1252*7f2fe78bSCy Schubert static HWND hSliderLifetime=0;
1253*7f2fe78bSCy Schubert static HWND hSliderRenew=0;
1254*7f2fe78bSCy Schubert static RECT dlgRect;
1255*7f2fe78bSCy Schubert static int hideDiff = 0;
1256*7f2fe78bSCy Schubert static void *pAutoComplete = 0;
1257*7f2fe78bSCy Schubert long realm_count = 0;
1258*7f2fe78bSCy Schubert int disable_noaddresses = 0;
1259*7f2fe78bSCy Schubert HWND hEditCtrl=0;
1260*7f2fe78bSCy Schubert HWND hFocusCtrl=0;
1261*7f2fe78bSCy Schubert BOOL bReadOnlyPrinc=0;
1262*7f2fe78bSCy Schubert
1263*7f2fe78bSCy Schubert switch (message) {
1264*7f2fe78bSCy Schubert
1265*7f2fe78bSCy Schubert case WM_INITDIALOG:
1266*7f2fe78bSCy Schubert hDlg = hDialog;
1267*7f2fe78bSCy Schubert
1268*7f2fe78bSCy Schubert hEditCtrl = GetDlgItem(hDialog, IDC_EDIT_PRINCIPAL);
1269*7f2fe78bSCy Schubert if (hEditCtrl)
1270*7f2fe78bSCy Schubert pAutoComplete = Leash_pec_create(hEditCtrl);
1271*7f2fe78bSCy Schubert hSliderLifetime = GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE);
1272*7f2fe78bSCy Schubert hSliderRenew = GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE);
1273*7f2fe78bSCy Schubert
1274*7f2fe78bSCy Schubert *( (LPLSH_DLGINFO_EX far *)(&lpdi) ) = (LPLSH_DLGINFO_EX)(LPSTR)lParam;
1275*7f2fe78bSCy Schubert
1276*7f2fe78bSCy Schubert if ((lpdi->size != LSH_DLGINFO_EX_V1_SZ &&
1277*7f2fe78bSCy Schubert lpdi->size != LSH_DLGINFO_EX_V2_SZ &&
1278*7f2fe78bSCy Schubert lpdi->size < LSH_DLGINFO_EX_V3_SZ) ||
1279*7f2fe78bSCy Schubert (lpdi->dlgtype & DLGTYPE_MASK) != DLGTYPE_PASSWD) {
1280*7f2fe78bSCy Schubert
1281*7f2fe78bSCy Schubert MessageBox(hDialog, "An incorrect initialization data structure was provided.",
1282*7f2fe78bSCy Schubert "AuthenticateProc()",
1283*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1284*7f2fe78bSCy Schubert return FALSE;
1285*7f2fe78bSCy Schubert }
1286*7f2fe78bSCy Schubert bReadOnlyPrinc = (lpdi->dlgtype & DLGFLAG_READONLYPRINC) ?
1287*7f2fe78bSCy Schubert TRUE : FALSE;
1288*7f2fe78bSCy Schubert
1289*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {
1290*7f2fe78bSCy Schubert lpdi->out.username[0] = 0;
1291*7f2fe78bSCy Schubert lpdi->out.realm[0] = 0;
1292*7f2fe78bSCy Schubert }
1293*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ ) {
1294*7f2fe78bSCy Schubert lpdi->out.ccache[0] = 0;
1295*7f2fe78bSCy Schubert }
1296*7f2fe78bSCy Schubert
1297*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ )
1298*7f2fe78bSCy Schubert SetWindowText(hDialog, lpdi->in.title);
1299*7f2fe78bSCy Schubert else
1300*7f2fe78bSCy Schubert SetWindowText(hDialog, lpdi->title);
1301*7f2fe78bSCy Schubert
1302*7f2fe78bSCy Schubert SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);
1303*7f2fe78bSCy Schubert if (lpdi->use_defaults) {
1304*7f2fe78bSCy Schubert lifetime = Leash_get_default_lifetime();
1305*7f2fe78bSCy Schubert if (lifetime <= 0)
1306*7f2fe78bSCy Schubert lifetime = 600; /* 10 hours */
1307*7f2fe78bSCy Schubert if (Leash_get_default_renewable()) {
1308*7f2fe78bSCy Schubert renew_till = Leash_get_default_renew_till();
1309*7f2fe78bSCy Schubert if (renew_till < 0)
1310*7f2fe78bSCy Schubert renew_till = 10800; /* 7 days */
1311*7f2fe78bSCy Schubert } else
1312*7f2fe78bSCy Schubert renew_till = 0;
1313*7f2fe78bSCy Schubert forwardable = Leash_get_default_forwardable();
1314*7f2fe78bSCy Schubert if (forwardable < 0)
1315*7f2fe78bSCy Schubert forwardable = 0;
1316*7f2fe78bSCy Schubert noaddresses = Leash_get_default_noaddresses();
1317*7f2fe78bSCy Schubert if (noaddresses < 0)
1318*7f2fe78bSCy Schubert noaddresses = 0;
1319*7f2fe78bSCy Schubert proxiable = Leash_get_default_proxiable();
1320*7f2fe78bSCy Schubert if (proxiable < 0)
1321*7f2fe78bSCy Schubert proxiable = 0;
1322*7f2fe78bSCy Schubert publicip = Leash_get_default_publicip();
1323*7f2fe78bSCy Schubert if (publicip < 0)
1324*7f2fe78bSCy Schubert publicip = 0;
1325*7f2fe78bSCy Schubert } else {
1326*7f2fe78bSCy Schubert forwardable = lpdi->forwardable;
1327*7f2fe78bSCy Schubert noaddresses = lpdi->noaddresses;
1328*7f2fe78bSCy Schubert lifetime = lpdi->lifetime;
1329*7f2fe78bSCy Schubert renew_till = lpdi->renew_till;
1330*7f2fe78bSCy Schubert proxiable = lpdi->proxiable;
1331*7f2fe78bSCy Schubert publicip = lpdi->publicip;
1332*7f2fe78bSCy Schubert }
1333*7f2fe78bSCy Schubert if (lpdi->username && (strlen(lpdi->username) > 0) &&
1334*7f2fe78bSCy Schubert lpdi->realm && (strlen(lpdi->realm) > 0)) {
1335*7f2fe78bSCy Schubert sprintf_s(principal, sizeof(principal), "%s@%s", lpdi->username,
1336*7f2fe78bSCy Schubert lpdi->realm);
1337*7f2fe78bSCy Schubert } else {
1338*7f2fe78bSCy Schubert principal[0] = 0;
1339*7f2fe78bSCy Schubert }
1340*7f2fe78bSCy Schubert Edit_SetReadOnly(hEditCtrl, bReadOnlyPrinc);
1341*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal);
1342*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD, "");
1343*7f2fe78bSCy Schubert
1344*7f2fe78bSCy Schubert /* Set Lifetime Slider
1345*7f2fe78bSCy Schubert * min value = 5
1346*7f2fe78bSCy Schubert * max value = 1440
1347*7f2fe78bSCy Schubert * current value
1348*7f2fe78bSCy Schubert */
1349*7f2fe78bSCy Schubert
1350*7f2fe78bSCy Schubert SetupSlider( hDialog,
1351*7f2fe78bSCy Schubert IDC_SLIDER_LIFETIME,
1352*7f2fe78bSCy Schubert IDC_STATIC_LIFETIME_VALUE,
1353*7f2fe78bSCy Schubert Leash_get_default_life_min(),
1354*7f2fe78bSCy Schubert Leash_get_default_life_max(),
1355*7f2fe78bSCy Schubert lifetime );
1356*7f2fe78bSCy Schubert
1357*7f2fe78bSCy Schubert CheckDlgButton(hDialog, IDC_CHECK_REMEMBER_PRINCIPAL, TRUE);
1358*7f2fe78bSCy Schubert /* Set Forwardable checkbox */
1359*7f2fe78bSCy Schubert CheckDlgButton(hDialog, IDC_CHECK_FORWARDABLE, forwardable);
1360*7f2fe78bSCy Schubert /* Set NoAddress checkbox */
1361*7f2fe78bSCy Schubert CheckDlgButton(hDialog, IDC_CHECK_NOADDRESS, noaddresses);
1362*7f2fe78bSCy Schubert if ( disable_noaddresses )
1363*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog,IDC_CHECK_NOADDRESS),FALSE);
1364*7f2fe78bSCy Schubert /* Set Renewable checkbox */
1365*7f2fe78bSCy Schubert CheckDlgButton(hDialog, IDC_CHECK_RENEWABLE, renew_till);
1366*7f2fe78bSCy Schubert /* if not renewable, disable Renew Till slider */
1367*7f2fe78bSCy Schubert /* if renewable, set Renew Till slider
1368*7f2fe78bSCy Schubert * min value
1369*7f2fe78bSCy Schubert * max value
1370*7f2fe78bSCy Schubert * current value
1371*7f2fe78bSCy Schubert */
1372*7f2fe78bSCy Schubert SetupSlider( hDialog,
1373*7f2fe78bSCy Schubert IDC_SLIDER_RENEWLIFE,
1374*7f2fe78bSCy Schubert IDC_STATIC_RENEW_TILL_VALUE,
1375*7f2fe78bSCy Schubert Leash_get_default_renew_min(),
1376*7f2fe78bSCy Schubert Leash_get_default_renew_max(),
1377*7f2fe78bSCy Schubert renew_till);
1378*7f2fe78bSCy Schubert if (renew_till) {
1379*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),TRUE);
1380*7f2fe78bSCy Schubert } else {
1381*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog,IDC_SLIDER_RENEWLIFE),FALSE);
1382*7f2fe78bSCy Schubert }
1383*7f2fe78bSCy Schubert
1384*7f2fe78bSCy Schubert // Compute sizes of items necessary to show/hide the advanced options
1385*7f2fe78bSCy Schubert GetWindowRect( hDialog, &dlgRect );
1386*7f2fe78bSCy Schubert {
1387*7f2fe78bSCy Schubert RECT okRect, staticRect;
1388*7f2fe78bSCy Schubert GetWindowRect(GetDlgItem(hDialog,IDC_STATIC_LIFETIME),&staticRect);
1389*7f2fe78bSCy Schubert GetWindowRect(GetDlgItem(hDialog,IDOK),&okRect);
1390*7f2fe78bSCy Schubert hideDiff = okRect.top - staticRect.top;
1391*7f2fe78bSCy Schubert }
1392*7f2fe78bSCy Schubert
1393*7f2fe78bSCy Schubert if ( hKrb5 ) {
1394*7f2fe78bSCy Schubert if (Leash_get_hide_kinit_options())
1395*7f2fe78bSCy Schubert AdjustOptions(hDialog,0,hideDiff);
1396*7f2fe78bSCy Schubert } else {
1397*7f2fe78bSCy Schubert AdjustOptions(hDialog,0,hideDiff);
1398*7f2fe78bSCy Schubert EnableWindow(GetDlgItem(hDialog,IDC_BUTTON_OPTIONS),FALSE);
1399*7f2fe78bSCy Schubert ShowWindow(GetDlgItem(hDialog,IDC_BUTTON_OPTIONS),SW_HIDE);
1400*7f2fe78bSCy Schubert }
1401*7f2fe78bSCy Schubert
1402*7f2fe78bSCy Schubert /* setup text of stuff. */
1403*7f2fe78bSCy Schubert
1404*7f2fe78bSCy Schubert if (Position.x > 0 && Position.y > 0 &&
1405*7f2fe78bSCy Schubert Position.x < GetSystemMetrics(SM_CXSCREEN) &&
1406*7f2fe78bSCy Schubert Position.y < GetSystemMetrics(SM_CYSCREEN))
1407*7f2fe78bSCy Schubert SetWindowPos(hDialog, HWND_TOP, Position.x, Position.y, 0, 0, SWP_NOSIZE);
1408*7f2fe78bSCy Schubert else /* Center the window on the desktop */
1409*7f2fe78bSCy Schubert SetWindowPos(hDialog, HWND_TOP,
1410*7f2fe78bSCy Schubert (GetSystemMetrics(SM_CXSCREEN) - dlgRect.right + dlgRect.left)/2,
1411*7f2fe78bSCy Schubert (GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top)/2,
1412*7f2fe78bSCy Schubert 0, 0,
1413*7f2fe78bSCy Schubert SWP_NOSIZE);
1414*7f2fe78bSCy Schubert
1415*7f2fe78bSCy Schubert /* Take keyboard focus */
1416*7f2fe78bSCy Schubert SetActiveWindow(hDialog);
1417*7f2fe78bSCy Schubert SetForegroundWindow(hDialog);
1418*7f2fe78bSCy Schubert /* put focus on password if princ is read-only */
1419*7f2fe78bSCy Schubert hFocusCtrl = (bReadOnlyPrinc || principal[0] != '\0') ?
1420*7f2fe78bSCy Schubert GetDlgItem(hDialog, IDC_EDIT_PASSWORD) : hEditCtrl;
1421*7f2fe78bSCy Schubert if (((HWND)wParam) != hFocusCtrl) {
1422*7f2fe78bSCy Schubert SetFocus(hFocusCtrl);
1423*7f2fe78bSCy Schubert }
1424*7f2fe78bSCy Schubert break;
1425*7f2fe78bSCy Schubert
1426*7f2fe78bSCy Schubert case WM_HSCROLL:
1427*7f2fe78bSCy Schubert switch (LOWORD(wParam)) {
1428*7f2fe78bSCy Schubert case TB_THUMBTRACK:
1429*7f2fe78bSCy Schubert case TB_THUMBPOSITION:
1430*7f2fe78bSCy Schubert {
1431*7f2fe78bSCy Schubert long pos = HIWORD(wParam); // the position of the slider
1432*7f2fe78bSCy Schubert int ctrlID = GetDlgCtrlID((HWND)lParam);
1433*7f2fe78bSCy Schubert
1434*7f2fe78bSCy Schubert if (ctrlID == IDC_SLIDER_RENEWLIFE) {
1435*7f2fe78bSCy Schubert SetWindowText(GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE),
1436*7f2fe78bSCy Schubert NewSliderString(IDC_SLIDER_RENEWLIFE,pos));
1437*7f2fe78bSCy Schubert }
1438*7f2fe78bSCy Schubert if (ctrlID == IDC_SLIDER_LIFETIME) {
1439*7f2fe78bSCy Schubert SetWindowText(GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE),
1440*7f2fe78bSCy Schubert NewSliderString(IDC_SLIDER_LIFETIME,pos));
1441*7f2fe78bSCy Schubert }
1442*7f2fe78bSCy Schubert }
1443*7f2fe78bSCy Schubert break;
1444*7f2fe78bSCy Schubert case TB_BOTTOM:
1445*7f2fe78bSCy Schubert case TB_TOP:
1446*7f2fe78bSCy Schubert case TB_ENDTRACK:
1447*7f2fe78bSCy Schubert case TB_LINEDOWN:
1448*7f2fe78bSCy Schubert case TB_LINEUP:
1449*7f2fe78bSCy Schubert case TB_PAGEDOWN:
1450*7f2fe78bSCy Schubert case TB_PAGEUP:
1451*7f2fe78bSCy Schubert default:
1452*7f2fe78bSCy Schubert {
1453*7f2fe78bSCy Schubert int ctrlID = GetDlgCtrlID((HWND)lParam);
1454*7f2fe78bSCy Schubert long pos = SendMessage(GetDlgItem(hDialog,ctrlID), TBM_GETPOS, 0, 0); // the position of the slider
1455*7f2fe78bSCy Schubert
1456*7f2fe78bSCy Schubert if (ctrlID == IDC_SLIDER_RENEWLIFE) {
1457*7f2fe78bSCy Schubert SetWindowText(GetDlgItem(hDialog, IDC_STATIC_RENEW_TILL_VALUE),
1458*7f2fe78bSCy Schubert NewSliderString(IDC_SLIDER_RENEWLIFE,pos));
1459*7f2fe78bSCy Schubert }
1460*7f2fe78bSCy Schubert if (ctrlID == IDC_SLIDER_LIFETIME) {
1461*7f2fe78bSCy Schubert SetWindowText(GetDlgItem(hDialog, IDC_STATIC_LIFETIME_VALUE),
1462*7f2fe78bSCy Schubert NewSliderString(IDC_SLIDER_LIFETIME,pos));
1463*7f2fe78bSCy Schubert }
1464*7f2fe78bSCy Schubert }
1465*7f2fe78bSCy Schubert }
1466*7f2fe78bSCy Schubert break;
1467*7f2fe78bSCy Schubert
1468*7f2fe78bSCy Schubert case WM_COMMAND:
1469*7f2fe78bSCy Schubert switch (wParam) {
1470*7f2fe78bSCy Schubert case IDC_BUTTON_OPTIONS:
1471*7f2fe78bSCy Schubert {
1472*7f2fe78bSCy Schubert AdjustOptions(hDialog,Leash_get_hide_kinit_options(),hideDiff);
1473*7f2fe78bSCy Schubert GetWindowRect(hDialog,&dlgRect);
1474*7f2fe78bSCy Schubert if ( dlgRect.bottom > GetSystemMetrics(SM_CYSCREEN))
1475*7f2fe78bSCy Schubert SetWindowPos( hDialog,0,
1476*7f2fe78bSCy Schubert dlgRect.left,
1477*7f2fe78bSCy Schubert GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top,
1478*7f2fe78bSCy Schubert 0,0,
1479*7f2fe78bSCy Schubert SWP_NOZORDER|SWP_NOSIZE);
1480*7f2fe78bSCy Schubert
1481*7f2fe78bSCy Schubert }
1482*7f2fe78bSCy Schubert break;
1483*7f2fe78bSCy Schubert case IDC_BUTTON_CLEAR_HISTORY:
1484*7f2fe78bSCy Schubert Leash_pec_clear_history(pAutoComplete);
1485*7f2fe78bSCy Schubert break;
1486*7f2fe78bSCy Schubert case IDC_CHECK_RENEWABLE:
1487*7f2fe78bSCy Schubert {
1488*7f2fe78bSCy Schubert if (IsDlgButtonChecked(hDialog, IDC_CHECK_RENEWABLE)) {
1489*7f2fe78bSCy Schubert EnableWindow(hSliderRenew,TRUE);
1490*7f2fe78bSCy Schubert } else {
1491*7f2fe78bSCy Schubert EnableWindow(hSliderRenew,FALSE);
1492*7f2fe78bSCy Schubert }
1493*7f2fe78bSCy Schubert }
1494*7f2fe78bSCy Schubert break;
1495*7f2fe78bSCy Schubert case ID_HELP:
1496*7f2fe78bSCy Schubert {
1497*7f2fe78bSCy Schubert WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,
1498*7f2fe78bSCy Schubert ID_INITTICKETS);
1499*7f2fe78bSCy Schubert }
1500*7f2fe78bSCy Schubert break;
1501*7f2fe78bSCy Schubert case ID_CLOSEME:
1502*7f2fe78bSCy Schubert {
1503*7f2fe78bSCy Schubert CleanupSliders();
1504*7f2fe78bSCy Schubert memset(password,0,sizeof(password));
1505*7f2fe78bSCy Schubert RemoveProp(hDialog, "HANDLES_HELP");
1506*7f2fe78bSCy Schubert if (pAutoComplete) {
1507*7f2fe78bSCy Schubert Leash_pec_destroy(pAutoComplete);
1508*7f2fe78bSCy Schubert pAutoComplete = NULL;
1509*7f2fe78bSCy Schubert }
1510*7f2fe78bSCy Schubert EndDialog(hDialog, (int)lParam);
1511*7f2fe78bSCy Schubert return TRUE;
1512*7f2fe78bSCy Schubert }
1513*7f2fe78bSCy Schubert break;
1514*7f2fe78bSCy Schubert case IDOK:
1515*7f2fe78bSCy Schubert {
1516*7f2fe78bSCy Schubert DWORD value = 0;
1517*7f2fe78bSCy Schubert
1518*7f2fe78bSCy Schubert CGetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal, sizeof(principal));
1519*7f2fe78bSCy Schubert CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD, password, sizeof(password));
1520*7f2fe78bSCy Schubert
1521*7f2fe78bSCy Schubert if (!principal[0]) {
1522*7f2fe78bSCy Schubert MessageBox(hDialog,
1523*7f2fe78bSCy Schubert "You are not allowed to enter a blank principal.",
1524*7f2fe78bSCy Schubert "Invalid Principal",
1525*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1526*7f2fe78bSCy Schubert return TRUE;
1527*7f2fe78bSCy Schubert }
1528*7f2fe78bSCy Schubert // @TODO: parse realm portion and auto-uppercase
1529*7f2fe78bSCy Schubert /*
1530*7f2fe78bSCy Schubert if (Leash_get_default_uppercaserealm())
1531*7f2fe78bSCy Schubert {
1532*7f2fe78bSCy Schubert // found
1533*7f2fe78bSCy Schubert strupr(realm);
1534*7f2fe78bSCy Schubert }
1535*7f2fe78bSCy Schubert */
1536*7f2fe78bSCy Schubert
1537*7f2fe78bSCy Schubert if (!password[0])
1538*7f2fe78bSCy Schubert {
1539*7f2fe78bSCy Schubert MessageBox(hDialog,
1540*7f2fe78bSCy Schubert "You are not allowed to enter a blank password.",
1541*7f2fe78bSCy Schubert "Invalid Password",
1542*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1543*7f2fe78bSCy Schubert return TRUE;
1544*7f2fe78bSCy Schubert }
1545*7f2fe78bSCy Schubert
1546*7f2fe78bSCy Schubert lifetime = NewSliderValue(hDialog, IDC_SLIDER_LIFETIME);
1547*7f2fe78bSCy Schubert
1548*7f2fe78bSCy Schubert forwardable = proxiable =
1549*7f2fe78bSCy Schubert IsDlgButtonChecked(hDialog, IDC_CHECK_FORWARDABLE);
1550*7f2fe78bSCy Schubert noaddresses = IsDlgButtonChecked(hDialog, IDC_CHECK_NOADDRESS);
1551*7f2fe78bSCy Schubert if (IsDlgButtonChecked(hDialog, IDC_CHECK_RENEWABLE)) {
1552*7f2fe78bSCy Schubert renew_till = NewSliderValue(hDialog, IDC_SLIDER_RENEWLIFE);
1553*7f2fe78bSCy Schubert } else {
1554*7f2fe78bSCy Schubert renew_till= 0;
1555*7f2fe78bSCy Schubert }
1556*7f2fe78bSCy Schubert
1557*7f2fe78bSCy Schubert lsh_errno = Leash_int_kinit_ex( 0,
1558*7f2fe78bSCy Schubert hDialog,
1559*7f2fe78bSCy Schubert principal, password, lifetime,
1560*7f2fe78bSCy Schubert forwardable,
1561*7f2fe78bSCy Schubert proxiable,
1562*7f2fe78bSCy Schubert renew_till,
1563*7f2fe78bSCy Schubert noaddresses,
1564*7f2fe78bSCy Schubert publicip,
1565*7f2fe78bSCy Schubert 1
1566*7f2fe78bSCy Schubert );
1567*7f2fe78bSCy Schubert if (lsh_errno != 0)
1568*7f2fe78bSCy Schubert {
1569*7f2fe78bSCy Schubert #ifdef COMMENT
1570*7f2fe78bSCy Schubert char gbuf[256];
1571*7f2fe78bSCy Schubert int capslock;
1572*7f2fe78bSCy Schubert char *cp;
1573*7f2fe78bSCy Schubert #endif
1574*7f2fe78bSCy Schubert err_context = "";
1575*7f2fe78bSCy Schubert switch(lsh_errno)
1576*7f2fe78bSCy Schubert {
1577*7f2fe78bSCy Schubert case LSH_INVPRINCIPAL:
1578*7f2fe78bSCy Schubert case LSH_INVINSTANCE:
1579*7f2fe78bSCy Schubert CSendDlgItemMessage(hDialog, IDC_EDIT_PRINCIPAL, EM_SETSEL, 0, 256);
1580*7f2fe78bSCy Schubert SetFocus(GetDlgItem(hDialog,IDC_EDIT_PRINCIPAL));
1581*7f2fe78bSCy Schubert break;
1582*7f2fe78bSCy Schubert case LSH_INVREALM:
1583*7f2fe78bSCy Schubert CSendDlgItemMessage(hDialog, IDC_COMBO_REALM, EM_SETSEL, 0, 256);
1584*7f2fe78bSCy Schubert SetFocus(GetDlgItem(hDialog,IDC_COMBO_REALM));
1585*7f2fe78bSCy Schubert break;
1586*7f2fe78bSCy Schubert default:
1587*7f2fe78bSCy Schubert CSendDlgItemMessage(hDialog, IDC_EDIT_PASSWORD, EM_SETSEL, 0, 256);
1588*7f2fe78bSCy Schubert SetFocus(GetDlgItem(hDialog,IDC_EDIT_PASSWORD));
1589*7f2fe78bSCy Schubert return(TRUE);
1590*7f2fe78bSCy Schubert }
1591*7f2fe78bSCy Schubert #ifdef COMMENT
1592*7f2fe78bSCy Schubert capslock = lsh_getkeystate(VK_CAPITAL);
1593*7f2fe78bSCy Schubert /* low-order bit means caps lock is
1594*7f2fe78bSCy Schubert toggled; if so, warn user since there's
1595*7f2fe78bSCy Schubert been an error. */
1596*7f2fe78bSCy Schubert if (capslock & 1)
1597*7f2fe78bSCy Schubert {
1598*7f2fe78bSCy Schubert lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
1599*7f2fe78bSCy Schubert cp = gbuf + lstrlen((LPSTR)gbuf);
1600*7f2fe78bSCy Schubert if (cp != gbuf)
1601*7f2fe78bSCy Schubert *cp++ = ' ';
1602*7f2fe78bSCy Schubert lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
1603*7f2fe78bSCy Schubert err_context = gbuf;
1604*7f2fe78bSCy Schubert }
1605*7f2fe78bSCy Schubert
1606*7f2fe78bSCy Schubert // XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""
1607*7f2fe78bSCy Schubert // XXX : "Ticket initialization failed.");
1608*7f2fe78bSCy Schubert #endif /* COMMENT */
1609*7f2fe78bSCy Schubert return TRUE;
1610*7f2fe78bSCy Schubert }
1611*7f2fe78bSCy Schubert
1612*7f2fe78bSCy Schubert if ( Leash_get_default_preserve_kinit_settings() )
1613*7f2fe78bSCy Schubert {
1614*7f2fe78bSCy Schubert Leash_set_default_lifetime(lifetime);
1615*7f2fe78bSCy Schubert if ( renew_till > 0 ) {
1616*7f2fe78bSCy Schubert Leash_set_default_renew_till(renew_till);
1617*7f2fe78bSCy Schubert Leash_set_default_renewable(1);
1618*7f2fe78bSCy Schubert } else {
1619*7f2fe78bSCy Schubert Leash_set_default_renewable(0);
1620*7f2fe78bSCy Schubert }
1621*7f2fe78bSCy Schubert Leash_set_default_forwardable(forwardable);
1622*7f2fe78bSCy Schubert Leash_set_default_noaddresses(noaddresses);
1623*7f2fe78bSCy Schubert }
1624*7f2fe78bSCy Schubert /* @TODO: out username/realm
1625*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {
1626*7f2fe78bSCy Schubert strncpy(lpdi->out.username, username, LEASH_USERNAME_SZ);
1627*7f2fe78bSCy Schubert lpdi->out.username[LEASH_USERNAME_SZ-1] = 0;
1628*7f2fe78bSCy Schubert strncpy(lpdi->out.realm, realm, LEASH_REALM_SZ);
1629*7f2fe78bSCy Schubert lpdi->out.realm[LEASH_REALM_SZ-1] = 0;
1630*7f2fe78bSCy Schubert }
1631*7f2fe78bSCy Schubert */
1632*7f2fe78bSCy Schubert if (IsDlgButtonChecked(hDialog, IDC_CHECK_REMEMBER_PRINCIPAL))
1633*7f2fe78bSCy Schubert Leash_pec_add_principal(principal);
1634*7f2fe78bSCy Schubert
1635*7f2fe78bSCy Schubert CloseMe(TRUE); /* success */
1636*7f2fe78bSCy Schubert return FALSE;
1637*7f2fe78bSCy Schubert }
1638*7f2fe78bSCy Schubert break;
1639*7f2fe78bSCy Schubert case IDCANCEL:
1640*7f2fe78bSCy Schubert CloseMe(FALSE);
1641*7f2fe78bSCy Schubert break;
1642*7f2fe78bSCy Schubert }
1643*7f2fe78bSCy Schubert break;
1644*7f2fe78bSCy Schubert
1645*7f2fe78bSCy Schubert case WM_MOVE:
1646*7f2fe78bSCy Schubert #ifdef _WIN32
1647*7f2fe78bSCy Schubert #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \
1648*7f2fe78bSCy Schubert (pt).y=(SHORT)HIWORD(l))
1649*7f2fe78bSCy Schubert LONG2POINT(lParam,Position);
1650*7f2fe78bSCy Schubert #else
1651*7f2fe78bSCy Schubert Position = MAKEPOINT(lParam);
1652*7f2fe78bSCy Schubert #endif
1653*7f2fe78bSCy Schubert break;
1654*7f2fe78bSCy Schubert }
1655*7f2fe78bSCy Schubert return FALSE;
1656*7f2fe78bSCy Schubert }
1657*7f2fe78bSCy Schubert
1658*7f2fe78bSCy Schubert /* Callback function for the Change Password Dialog box */
1659*7f2fe78bSCy Schubert
1660*7f2fe78bSCy Schubert INT_PTR
1661*7f2fe78bSCy Schubert CALLBACK
NewPasswordProc(HWND hDialog,UINT message,WPARAM wParam,LPARAM lParam)1662*7f2fe78bSCy Schubert NewPasswordProc(
1663*7f2fe78bSCy Schubert HWND hDialog,
1664*7f2fe78bSCy Schubert UINT message,
1665*7f2fe78bSCy Schubert WPARAM wParam,
1666*7f2fe78bSCy Schubert LPARAM lParam
1667*7f2fe78bSCy Schubert )
1668*7f2fe78bSCy Schubert {
1669*7f2fe78bSCy Schubert static POINT Position = { -1, -1 };
1670*7f2fe78bSCy Schubert static char password[256]="";
1671*7f2fe78bSCy Schubert static char password2[256]="";
1672*7f2fe78bSCy Schubert static char password3[256]="";
1673*7f2fe78bSCy Schubert static LPLSH_DLGINFO_EX lpdi;
1674*7f2fe78bSCy Schubert static HWND hDlg=0;
1675*7f2fe78bSCy Schubert static void *pAutoComplete = NULL;
1676*7f2fe78bSCy Schubert char principal[256];
1677*7f2fe78bSCy Schubert long realm_count = 0;
1678*7f2fe78bSCy Schubert HWND hEditCtrl = NULL;
1679*7f2fe78bSCy Schubert
1680*7f2fe78bSCy Schubert switch (message) {
1681*7f2fe78bSCy Schubert
1682*7f2fe78bSCy Schubert case WM_INITDIALOG:
1683*7f2fe78bSCy Schubert hDlg = hDialog;
1684*7f2fe78bSCy Schubert
1685*7f2fe78bSCy Schubert *( (LPLSH_DLGINFO_EX far *)(&lpdi) ) = (LPLSH_DLGINFO_EX)(LPSTR)lParam;
1686*7f2fe78bSCy Schubert
1687*7f2fe78bSCy Schubert if ((lpdi->size < LSH_DLGINFO_EX_V3_SZ &&
1688*7f2fe78bSCy Schubert lpdi->size != LSH_DLGINFO_EX_V1_SZ &&
1689*7f2fe78bSCy Schubert lpdi->size != LSH_DLGINFO_EX_V2_SZ) ||
1690*7f2fe78bSCy Schubert lpdi->dlgtype != DLGTYPE_CHPASSWD) {
1691*7f2fe78bSCy Schubert
1692*7f2fe78bSCy Schubert MessageBox(hDialog, "An incorrect initialization data structure was provided.",
1693*7f2fe78bSCy Schubert "PasswordProc()",
1694*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1695*7f2fe78bSCy Schubert return FALSE;
1696*7f2fe78bSCy Schubert }
1697*7f2fe78bSCy Schubert
1698*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V2_SZ ) {
1699*7f2fe78bSCy Schubert lpdi->out.username[0] = 0;
1700*7f2fe78bSCy Schubert lpdi->out.realm[0] = 0;
1701*7f2fe78bSCy Schubert }
1702*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ ) {
1703*7f2fe78bSCy Schubert lpdi->out.ccache[0] = 0;
1704*7f2fe78bSCy Schubert }
1705*7f2fe78bSCy Schubert
1706*7f2fe78bSCy Schubert if ( lpdi->size >= LSH_DLGINFO_EX_V3_SZ )
1707*7f2fe78bSCy Schubert SetWindowText(hDialog, lpdi->in.title);
1708*7f2fe78bSCy Schubert else
1709*7f2fe78bSCy Schubert SetWindowText(hDialog, lpdi->title);
1710*7f2fe78bSCy Schubert
1711*7f2fe78bSCy Schubert SetProp(hDialog, "HANDLES_HELP", (HANDLE)1);
1712*7f2fe78bSCy Schubert
1713*7f2fe78bSCy Schubert if (lpdi->username != NULL && (strlen(lpdi->username) > 0) &&
1714*7f2fe78bSCy Schubert lpdi->realm != NULL && (strlen(lpdi->realm) > 0)) {
1715*7f2fe78bSCy Schubert sprintf_s(principal,
1716*7f2fe78bSCy Schubert sizeof(principal), "%s@%s", lpdi->username, lpdi->realm);
1717*7f2fe78bSCy Schubert } else {
1718*7f2fe78bSCy Schubert principal[0] = 0;
1719*7f2fe78bSCy Schubert }
1720*7f2fe78bSCy Schubert
1721*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal);
1722*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD, "");
1723*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD2, "");
1724*7f2fe78bSCy Schubert CSetDlgItemText(hDialog, IDC_EDIT_PASSWORD3, "");
1725*7f2fe78bSCy Schubert
1726*7f2fe78bSCy Schubert hEditCtrl = GetDlgItem(hDialog, IDC_EDIT_PRINCIPAL);
1727*7f2fe78bSCy Schubert if (hEditCtrl)
1728*7f2fe78bSCy Schubert pAutoComplete = Leash_pec_create(hEditCtrl);
1729*7f2fe78bSCy Schubert
1730*7f2fe78bSCy Schubert /* setup text of stuff. */
1731*7f2fe78bSCy Schubert
1732*7f2fe78bSCy Schubert if (Position.x > 0 && Position.y > 0 &&
1733*7f2fe78bSCy Schubert Position.x < GetSystemMetrics(SM_CXSCREEN) &&
1734*7f2fe78bSCy Schubert Position.y < GetSystemMetrics(SM_CYSCREEN))
1735*7f2fe78bSCy Schubert SetWindowPos(hDialog, 0, Position.x, Position.y, 0, 0,
1736*7f2fe78bSCy Schubert SWP_NOSIZE | SWP_NOZORDER);
1737*7f2fe78bSCy Schubert else { /* Center the window on the desktop */
1738*7f2fe78bSCy Schubert RECT dlgRect;
1739*7f2fe78bSCy Schubert GetWindowRect( hDialog, &dlgRect );
1740*7f2fe78bSCy Schubert SetWindowPos(hDialog, 0,
1741*7f2fe78bSCy Schubert (GetSystemMetrics(SM_CXSCREEN) - dlgRect.right + dlgRect.left)/2,
1742*7f2fe78bSCy Schubert (GetSystemMetrics(SM_CYSCREEN) - dlgRect.bottom + dlgRect.top)/2,
1743*7f2fe78bSCy Schubert 0, 0,
1744*7f2fe78bSCy Schubert SWP_NOSIZE | SWP_NOZORDER);
1745*7f2fe78bSCy Schubert }
1746*7f2fe78bSCy Schubert /* set window pos to last saved window pos */
1747*7f2fe78bSCy Schubert break;
1748*7f2fe78bSCy Schubert
1749*7f2fe78bSCy Schubert case WM_COMMAND:
1750*7f2fe78bSCy Schubert switch (wParam) {
1751*7f2fe78bSCy Schubert case ID_HELP:
1752*7f2fe78bSCy Schubert {
1753*7f2fe78bSCy Schubert WinHelp(GetWindow(hDialog,GW_OWNER), KRB_HelpFile, HELP_CONTEXT,
1754*7f2fe78bSCy Schubert ID_INITTICKETS);
1755*7f2fe78bSCy Schubert }
1756*7f2fe78bSCy Schubert break;
1757*7f2fe78bSCy Schubert case ID_CLOSEME:
1758*7f2fe78bSCy Schubert {
1759*7f2fe78bSCy Schubert CleanupSliders();
1760*7f2fe78bSCy Schubert memset(password,0,sizeof(password));
1761*7f2fe78bSCy Schubert memset(password2,0,sizeof(password2));
1762*7f2fe78bSCy Schubert memset(password3,0,sizeof(password3));
1763*7f2fe78bSCy Schubert RemoveProp(hDialog, "HANDLES_HELP");
1764*7f2fe78bSCy Schubert EndDialog(hDialog, (int)lParam);
1765*7f2fe78bSCy Schubert if (pAutoComplete != NULL) {
1766*7f2fe78bSCy Schubert Leash_pec_destroy(pAutoComplete);
1767*7f2fe78bSCy Schubert pAutoComplete = NULL;
1768*7f2fe78bSCy Schubert }
1769*7f2fe78bSCy Schubert return TRUE;
1770*7f2fe78bSCy Schubert }
1771*7f2fe78bSCy Schubert break;
1772*7f2fe78bSCy Schubert case IDOK:
1773*7f2fe78bSCy Schubert {
1774*7f2fe78bSCy Schubert DWORD value = 0;
1775*7f2fe78bSCy Schubert int i = 0;
1776*7f2fe78bSCy Schubert int bit8 = 0;
1777*7f2fe78bSCy Schubert
1778*7f2fe78bSCy Schubert CGetDlgItemText(hDialog, IDC_EDIT_PRINCIPAL, principal, sizeof(principal));
1779*7f2fe78bSCy Schubert CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD, password, sizeof(password));
1780*7f2fe78bSCy Schubert CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD2, password2, sizeof(password2));
1781*7f2fe78bSCy Schubert CGetDlgItemText(hDialog, IDC_EDIT_PASSWORD3, password3, sizeof(password3));
1782*7f2fe78bSCy Schubert
1783*7f2fe78bSCy Schubert if (!principal[0])
1784*7f2fe78bSCy Schubert {
1785*7f2fe78bSCy Schubert MessageBox(hDialog, "You are not allowed to enter a "
1786*7f2fe78bSCy Schubert "blank username.",
1787*7f2fe78bSCy Schubert "Invalid Principal",
1788*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1789*7f2fe78bSCy Schubert return TRUE;
1790*7f2fe78bSCy Schubert }
1791*7f2fe78bSCy Schubert
1792*7f2fe78bSCy Schubert if (!password[0] || !password2[0] || !password3[0])
1793*7f2fe78bSCy Schubert {
1794*7f2fe78bSCy Schubert MessageBox(hDialog, "You are not allowed to enter a "
1795*7f2fe78bSCy Schubert "blank password.",
1796*7f2fe78bSCy Schubert "Invalid Password",
1797*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1798*7f2fe78bSCy Schubert return TRUE;
1799*7f2fe78bSCy Schubert }
1800*7f2fe78bSCy Schubert
1801*7f2fe78bSCy Schubert for( i = 0; i < 255; i++ ){
1802*7f2fe78bSCy Schubert if( password2[i] == '\0' ){
1803*7f2fe78bSCy Schubert if ( bit8 ) {
1804*7f2fe78bSCy Schubert MessageBox(hDialog,
1805*7f2fe78bSCy Schubert "Passwords should not contain non-ASCII characters.",
1806*7f2fe78bSCy Schubert "Internationalization Warning",
1807*7f2fe78bSCy Schubert MB_OK | MB_ICONINFORMATION);
1808*7f2fe78bSCy Schubert }
1809*7f2fe78bSCy Schubert i = 255;
1810*7f2fe78bSCy Schubert break;
1811*7f2fe78bSCy Schubert } else if( !isprint(password2[i]) ){
1812*7f2fe78bSCy Schubert memset(password2, '\0', sizeof(password2));
1813*7f2fe78bSCy Schubert memset(password3, '\0', sizeof(password3));
1814*7f2fe78bSCy Schubert /* I claim these passwords in the name of planet '\0'... */
1815*7f2fe78bSCy Schubert MessageBox(hDialog,
1816*7f2fe78bSCy Schubert "Passwords may not contain non-printable characters.",
1817*7f2fe78bSCy Schubert "Invalid Password",
1818*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1819*7f2fe78bSCy Schubert return TRUE;
1820*7f2fe78bSCy Schubert } else if ( password2[i] > 127 )
1821*7f2fe78bSCy Schubert bit8 = 1;
1822*7f2fe78bSCy Schubert }
1823*7f2fe78bSCy Schubert
1824*7f2fe78bSCy Schubert if (lstrcmp(password2, password3))
1825*7f2fe78bSCy Schubert {
1826*7f2fe78bSCy Schubert MessageBox(hDialog,
1827*7f2fe78bSCy Schubert "The new password was not entered the same way twice.",
1828*7f2fe78bSCy Schubert "Password validation error",
1829*7f2fe78bSCy Schubert MB_OK | MB_ICONSTOP);
1830*7f2fe78bSCy Schubert return TRUE;
1831*7f2fe78bSCy Schubert }
1832*7f2fe78bSCy Schubert
1833*7f2fe78bSCy Schubert lsh_errno = Leash_int_changepwd(principal, password, password2, 0, 1);
1834*7f2fe78bSCy Schubert if (lsh_errno != 0)
1835*7f2fe78bSCy Schubert {
1836*7f2fe78bSCy Schubert #ifdef COMMENT
1837*7f2fe78bSCy Schubert char gbuf[256];
1838*7f2fe78bSCy Schubert int capslock;
1839*7f2fe78bSCy Schubert char *cp;
1840*7f2fe78bSCy Schubert #endif /* COMMENT */
1841*7f2fe78bSCy Schubert
1842*7f2fe78bSCy Schubert err_context = "";
1843*7f2fe78bSCy Schubert switch(lsh_errno)
1844*7f2fe78bSCy Schubert {
1845*7f2fe78bSCy Schubert case LSH_INVPRINCIPAL:
1846*7f2fe78bSCy Schubert case LSH_INVINSTANCE:
1847*7f2fe78bSCy Schubert case LSH_INVREALM:
1848*7f2fe78bSCy Schubert break;
1849*7f2fe78bSCy Schubert default:
1850*7f2fe78bSCy Schubert return(TRUE);
1851*7f2fe78bSCy Schubert }
1852*7f2fe78bSCy Schubert #ifdef COMMENT
1853*7f2fe78bSCy Schubert capslock = lsh_getkeystate(VK_CAPITAL);
1854*7f2fe78bSCy Schubert /* low-order bit means caps lock is
1855*7f2fe78bSCy Schubert toggled; if so, warn user since there's
1856*7f2fe78bSCy Schubert been an error. */
1857*7f2fe78bSCy Schubert if (capslock & 1)
1858*7f2fe78bSCy Schubert {
1859*7f2fe78bSCy Schubert lstrcpy((LPSTR)gbuf, (LPSTR)err_context);
1860*7f2fe78bSCy Schubert cp = gbuf + lstrlen((LPSTR)gbuf);
1861*7f2fe78bSCy Schubert if (cp != gbuf)
1862*7f2fe78bSCy Schubert *cp++ = ' ';
1863*7f2fe78bSCy Schubert lstrcpy(cp, "(This may be because your CAPS LOCK key is down.)");
1864*7f2fe78bSCy Schubert err_context = gbuf;
1865*7f2fe78bSCy Schubert }
1866*7f2fe78bSCy Schubert
1867*7f2fe78bSCy Schubert // XXX DoNiftyErrorReport(lsh_errno, ISCHPASSWD ? ""
1868*7f2fe78bSCy Schubert // XXX : "Ticket initialization failed.");
1869*7f2fe78bSCy Schubert #endif /* COMMENT */
1870*7f2fe78bSCy Schubert return TRUE;
1871*7f2fe78bSCy Schubert }
1872*7f2fe78bSCy Schubert Leash_pec_add_principal(principal);
1873*7f2fe78bSCy Schubert MessageBox(NULL, "Password successfully changed.",
1874*7f2fe78bSCy Schubert "Password change", MB_OK);
1875*7f2fe78bSCy Schubert CloseMe(TRUE); /* success */
1876*7f2fe78bSCy Schubert }
1877*7f2fe78bSCy Schubert break;
1878*7f2fe78bSCy Schubert case IDCANCEL:
1879*7f2fe78bSCy Schubert CloseMe(FALSE);
1880*7f2fe78bSCy Schubert break;
1881*7f2fe78bSCy Schubert }
1882*7f2fe78bSCy Schubert break;
1883*7f2fe78bSCy Schubert
1884*7f2fe78bSCy Schubert case WM_MOVE:
1885*7f2fe78bSCy Schubert #ifdef _WIN32
1886*7f2fe78bSCy Schubert #define LONG2POINT(l,pt) ((pt).x=(SHORT)LOWORD(l), \
1887*7f2fe78bSCy Schubert (pt).y=(SHORT)HIWORD(l))
1888*7f2fe78bSCy Schubert LONG2POINT(lParam,Position);
1889*7f2fe78bSCy Schubert #else
1890*7f2fe78bSCy Schubert Position = MAKEPOINT(lParam);
1891*7f2fe78bSCy Schubert #endif
1892*7f2fe78bSCy Schubert break;
1893*7f2fe78bSCy Schubert }
1894*7f2fe78bSCy Schubert return FALSE;
1895*7f2fe78bSCy Schubert }
1896