2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afs/param.h>
15 #include "TaAfsUsrMgr.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
))
60 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
61 User_Password_OnInitDialog (hDlg
);
66 if ((ptp
= (LPTASKPACKET
)lp
) != NULL
)
68 if (ptp
->idTask
== taskGET_RANDOM_KEY
)
69 User_Password_OnEndTask_Random (hDlg
, ptp
);
78 if (User_Password_OnOK (hDlg
))
79 EndDialog (hDlg
, IDOK
);
83 EndDialog (hDlg
, IDCANCEL
);
86 case IDC_CPW_VERSION_AUTO
:
87 case IDC_CPW_VERSION_MANUAL
:
88 User_Password_OnSelectVer (hDlg
);
91 case IDC_CPW_BYSTRING
:
93 User_Password_OnSelectType (hDlg
);
98 User_Password_OnType (hDlg
);
102 User_Password_OnRandom (hDlg
);
112 void User_Password_OnInitDialog (HWND hDlg
)
114 ASID idUser
= (ASID
)GetWindowLongPtr (hDlg
, DWLP_USER
);
116 // Get the current properties for this user
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
);
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'))
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
))
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))
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
))
224 StartTask (taskUSER_CPW
, NULL
, lpp
);
229 void User_Password_OnEndTask_Random (HWND hDlg
, LPTASKPACKET ptp
)
233 ErrorDialog (ptp
->status
, IDS_ERROR_CANT_GET_RANDOM_KEY
);
234 EnableWindow (GetDlgItem (hDlg
, IDC_CPW_RANDOM
), FALSE
);
238 TCHAR szKey
[ cchRESOURCE
];
239 FormatServerKey (szKey
, TASKDATA(ptp
)->key
);
240 SetDlgItemText (hDlg
, IDC_CPW_DATA
, szKey
);