LINUX: afs_create infinite fetchStatus loop
[pkg-k5-afs_openafs.git] / src / WINNT / afsusrmgr / usr_cpw.cpp
blob8a4f904348ef4415746335602f24c3a590fc43f8
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
15 #include "TaAfsUsrMgr.h"
16 #include "usr_cpw.h"
17 #include "usr_col.h"
21 * DEFINITIONS ________________________________________________________________
27 * PROTOTYPES _________________________________________________________________
31 BOOL CALLBACK User_Password_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
32 void User_Password_OnInitDialog (HWND hDlg);
33 BOOL User_Password_OnOK (HWND hDlg);
34 void User_Password_OnSelectVer (HWND hDlg);
35 void User_Password_OnSelectType (HWND hDlg);
36 void User_Password_OnType (HWND hDlg);
37 void User_Password_OnRandom (HWND hDlg);
38 void User_Password_OnEndTask_Random (HWND hDlg, LPTASKPACKET ptp);
42 * ROUTINES ___________________________________________________________________
46 void User_ShowChangePassword (HWND hParent, ASID idUser)
48 ModalDialogParam (IDD_USER_PASSWORD, hParent, (DLGPROC)User_Password_DlgProc, (LPARAM)idUser);
52 BOOL CALLBACK User_Password_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
54 if (AfsAppLib_HandleHelp (IDD_USER_PASSWORD, hDlg, msg, wp, lp))
55 return TRUE;
57 switch (msg)
59 case WM_INITDIALOG:
60 SetWindowLongPtr (hDlg, DWLP_USER, lp);
61 User_Password_OnInitDialog (hDlg);
62 break;
64 case WM_ENDTASK:
65 LPTASKPACKET ptp;
66 if ((ptp = (LPTASKPACKET)lp) != NULL)
68 if (ptp->idTask == taskGET_RANDOM_KEY)
69 User_Password_OnEndTask_Random (hDlg, ptp);
70 FreeTaskPacket (ptp);
72 break;
74 case WM_COMMAND:
75 switch (LOWORD(wp))
77 case IDOK:
78 if (User_Password_OnOK (hDlg))
79 EndDialog (hDlg, IDOK);
80 break;
82 case IDCANCEL:
83 EndDialog (hDlg, IDCANCEL);
84 break;
86 case IDC_CPW_VERSION_AUTO:
87 case IDC_CPW_VERSION_MANUAL:
88 User_Password_OnSelectVer (hDlg);
89 break;
91 case IDC_CPW_BYSTRING:
92 case IDC_CPW_BYDATA:
93 User_Password_OnSelectType (hDlg);
94 break;
96 case IDC_CPW_STRING:
97 case IDC_CPW_DATA:
98 User_Password_OnType (hDlg);
99 break;
101 case IDC_CPW_RANDOM:
102 User_Password_OnRandom (hDlg);
103 break;
105 break;
108 return FALSE;
112 void User_Password_OnInitDialog (HWND hDlg)
114 ASID idUser = (ASID)GetWindowLongPtr (hDlg, DWLP_USER);
116 // Get the current properties for this user
118 ULONG status;
119 TCHAR szName[ cchNAME ];
120 User_GetDisplayName (szName, idUser);
122 ASOBJPROP Properties;
123 if (!asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, idUser, &Properties, &status))
125 ErrorDialog (status, IDS_ERROR_CANT_GET_USERPROP, TEXT("%s"), szName);
126 EndDialog (hDlg, IDCANCEL);
127 return;
130 // Fill in the text at the top of the dialog
132 TCHAR szOld[ cchRESOURCE ];
133 GetDlgItemText (hDlg, IDC_CPW_TITLE, szOld, cchRESOURCE);
135 LPTSTR pszText = FormatString (szOld, TEXT("%s"), szName);
136 SetDlgItemText (hDlg, IDC_CPW_TITLE, pszText);
137 FreeString (pszText);
139 // Check the appropriate radio buttons, etc
141 CheckDlgButton (hDlg, IDC_CPW_VERSION_AUTO, TRUE);
142 CheckDlgButton (hDlg, IDC_CPW_BYSTRING, TRUE);
143 CreateSpinner (GetDlgItem (hDlg, IDC_CPW_VERSION), 10, FALSE, 1, 1+Properties.u.UserProperties.KASINFO.keyVersion, 255);
144 User_Password_OnSelectType (hDlg);
145 User_Password_OnSelectVer (hDlg);
149 void User_Password_OnSelectVer (HWND hDlg)
151 EnableWindow (GetDlgItem (hDlg, IDC_CPW_VERSION), IsDlgButtonChecked (hDlg, IDC_CPW_VERSION_MANUAL));
155 void User_Password_OnSelectType (HWND hDlg)
157 EnableWindow (GetDlgItem (hDlg, IDC_CPW_STRING), IsDlgButtonChecked (hDlg, IDC_CPW_BYSTRING));
158 EnableWindow (GetDlgItem (hDlg, IDC_CPW_DATA), IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA));
159 EnableWindow (GetDlgItem (hDlg, IDC_CPW_RANDOM), IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA));
160 User_Password_OnType (hDlg);
164 void User_Password_OnType (HWND hDlg)
166 BOOL fEnable = FALSE;
168 if (IsDlgButtonChecked (hDlg, IDC_CPW_BYSTRING))
170 TCHAR szKey[ cchRESOURCE ];
171 GetDlgItemText (hDlg, IDC_CPW_STRING, szKey, cchRESOURCE);
172 if (szKey[0] != TEXT('\0'))
173 fEnable = TRUE;
175 else // (IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA))
177 TCHAR szKey[ cchRESOURCE ];
178 GetDlgItemText (hDlg, IDC_CPW_DATA, szKey, cchRESOURCE);
180 BYTE key[ ENCRYPTIONKEYLENGTH ];
181 if (ScanServerKey (key, szKey))
182 fEnable = TRUE;
185 EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
189 void User_Password_OnRandom (HWND hDlg)
191 StartTask (taskGET_RANDOM_KEY, hDlg, 0);
195 BOOL User_Password_OnOK (HWND hDlg)
197 ASID idUser = (ASID)GetWindowLongPtr (hDlg, DWLP_USER);
199 LPUSER_CPW_PARAMS lpp = New (USER_CPW_PARAMS);
200 memset (lpp, 0x00, sizeof(USER_CPW_PARAMS));
201 lpp->idUser = idUser;
203 if (IsDlgButtonChecked (hDlg, IDC_CPW_VERSION_MANUAL))
204 lpp->keyVersion = (int) SP_GetPos (GetDlgItem (hDlg, IDC_CPW_VERSION));
205 else // (IsDlgButtonChecked (hDlg, IDC_CPW_VERSION_AUTO))
206 lpp->keyVersion = 0;
208 if (IsDlgButtonChecked (hDlg, IDC_CPW_BYSTRING))
210 GetDlgItemText (hDlg, IDC_CPW_STRING, lpp->keyString, cchRESOURCE);
212 else // (IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA))
214 TCHAR szKey[ cchRESOURCE ];
215 GetDlgItemText (hDlg, IDC_CPW_DATA, szKey, cchRESOURCE);
217 if (!ScanServerKey (lpp->keyData, szKey))
219 Delete (lpp);
220 return FALSE;
224 StartTask (taskUSER_CPW, NULL, lpp);
225 return TRUE;
229 void User_Password_OnEndTask_Random (HWND hDlg, LPTASKPACKET ptp)
231 if (!ptp->rc)
233 ErrorDialog (ptp->status, IDS_ERROR_CANT_GET_RANDOM_KEY);
234 EnableWindow (GetDlgItem (hDlg, IDC_CPW_RANDOM), FALSE);
236 else
238 TCHAR szKey[ cchRESOURCE ];
239 FormatServerKey (szKey, TASKDATA(ptp)->key);
240 SetDlgItemText (hDlg, IDC_CPW_DATA, szKey);