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"
17 #include "usr_create.h"
21 * DEFINITIONS ________________________________________________________________
27 TCHAR szPassword[ cchRESOURCE ];
29 USERPROPINFO Advanced;
30 } CREATEUSERDLG, *LPCREATEUSERDLG;
32 #define UID_AUTOSELECT ((int)0)
36 * PROTOTYPES _________________________________________________________________
40 BOOL CALLBACK User_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
41 void User_Create_OnInitDialog (HWND hDlg);
42 void User_Create_OnNames (HWND hDlg);
43 void User_Create_OnID (HWND hDlg);
44 void User_Create_OnAdvanced (HWND hDlg);
45 BOOL User_Create_OnOK (HWND hDlg);
46 void User_Create_OnEndTask_ObjectGet (HWND hDlg, LPTASKPACKET ptp);
50 * ROUTINES ___________________________________________________________________
54 void User_SetDefaultCreateParams (LPUSERPROPINFO lpp)
56 memset (lpp, 0x00, sizeof(USERPROPINFO));
59 lpp->fGrantTickets = TRUE;
60 lpp->csecLifetime = csecTICKETLIFETIME_DEFAULT;
61 lpp->cGroupQuota = cGROUPQUOTA_DEFAULT;
62 lpp->fExpires = FALSE;
63 lpp->aaStatus = aaANYONE;
64 lpp->aaOwned = aaANYONE;
65 lpp->aaMember = aaANYONE;
66 lpp->fCreateKAS = TRUE;
67 lpp->fCreatePTS = TRUE;
68 lpp->fCanChangePw = TRUE;
69 lpp->fCanReusePw = FALSE;
70 lpp->cdayPwExpires = 0;
72 lpp->csecFailLock = 0;
76 void User_ShowCreate (HWND hParent)
78 LPCREATEUSERDLG lpp = New (CREATEUSERDLG);
79 memset (lpp, 0x00, sizeof(CREATEUSERDLG));
80 memcpy (&lpp->Advanced, &gr.CreateUser, sizeof(USERPROPINFO));
81 lpp->uid = UID_AUTOSELECT;
82 lpp->Advanced.pGroupsMember = NULL;
83 lpp->Advanced.pGroupsOwner = NULL;
85 (void)ModalDialogParam (IDD_NEWUSER, hParent, (DLGPROC)User_Create_DlgProc, (LPARAM)lpp);
87 if (lpp->Advanced.pGroupsMember)
88 asc_AsidListFree (&lpp->Advanced.pGroupsMember);
89 if (lpp->Advanced.pGroupsOwner)
90 asc_AsidListFree (&lpp->Advanced.pGroupsOwner);
95 BOOL CALLBACK User_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
97 if (AfsAppLib_HandleHelp (IDD_NEWUSER, hDlg, msg, wp, lp))
103 SetWindowLongPtr (hDlg, DWLP_USER, lp);
104 User_Create_OnInitDialog (hDlg);
109 if ((ptp = (LPTASKPACKET)lp) != NULL)
111 if (ptp->idTask == taskOBJECT_GET)
112 User_Create_OnEndTask_ObjectGet (hDlg, ptp);
113 FreeTaskPacket (ptp);
121 if (User_Create_OnOK (hDlg))
122 EndDialog (hDlg, IDOK);
126 EndDialog (hDlg, IDCANCEL);
130 User_Create_OnAdvanced (hDlg);
133 case IDC_NEWUSER_NAME:
134 User_Create_OnNames (hDlg);
137 case IDC_NEWUSER_ID_AUTO:
138 case IDC_NEWUSER_ID_MANUAL:
139 User_Create_OnID (hDlg);
149 void User_Create_OnInitDialog (HWND hDlg)
151 LPCREATEUSERDLG lpp = (LPCREATEUSERDLG)GetWindowLongPtr (hDlg, DWLP_USER);
153 // Fix the title of the dialog
156 TCHAR szName[ cchNAME ];
157 asc_CellNameGet_Fast (g.idClient, g.idCell, szName, &status);
159 TCHAR szText[ cchRESOURCE ];
160 GetDlgItemText (hDlg, IDC_NEWUSER_TITLE, szText, cchRESOURCE);
162 LPTSTR pszText = FormatString (szText, TEXT("%s"), szName);
163 SetDlgItemText (hDlg, IDC_NEWUSER_TITLE, pszText);
164 FreeString (pszText);
166 // Attach a spinner to the ID control
168 CheckDlgButton (hDlg, IDC_NEWUSER_ID_AUTO, TRUE);
169 CreateSpinner (GetDlgItem (hDlg, IDC_NEWUSER_ID), 10, FALSE, 1, 1, (int)-1);
170 User_Create_OnID (hDlg);
172 StartTask (taskOBJECT_GET, hDlg, (PVOID)(g.idCell));
176 void User_Create_OnNames (HWND hDlg)
178 TCHAR szSeparators[ cchRESOURCE ];
179 GetString (szSeparators, IDS_SEPARATORS);
180 lstrcat (szSeparators, TEXT(" \t"));
182 LPTSTR pszNames = GetEditText (GetDlgItem (hDlg, IDC_NEWUSER_NAME));
183 EnableWindow (GetDlgItem (hDlg, IDOK), (pszNames && *pszNames));
185 BOOL fMultiple = FALSE;
186 for (LPTSTR psz = pszNames; !fMultiple && psz && *psz; ++psz)
188 if (lstrchr (szSeparators, *psz))
191 FreeString (pszNames);
193 EnableWindow (GetDlgItem (hDlg, IDC_NEWUSER_ID_AUTO), !fMultiple);
194 EnableWindow (GetDlgItem (hDlg, IDC_NEWUSER_ID_MANUAL), !fMultiple);
197 CheckDlgButton (hDlg, IDC_NEWUSER_ID_AUTO, TRUE);
198 CheckDlgButton (hDlg, IDC_NEWUSER_ID_MANUAL, FALSE);
199 User_Create_OnID (hDlg);
204 void User_Create_OnID (HWND hDlg)
206 BOOL fEnable = IsDlgButtonChecked (hDlg, IDC_NEWUSER_ID_MANUAL);
207 EnableWindow (GetDlgItem (hDlg, IDC_NEWUSER_ID), fEnable);
211 void User_Create_OnAdvanced (HWND hDlg)
213 LPCREATEUSERDLG lpp = (LPCREATEUSERDLG)GetWindowLongPtr (hDlg, DWLP_USER);
214 lpp->Advanced.pUserList = NULL;
215 lpp->Advanced.fDeleteMeOnClose = FALSE;
216 lpp->Advanced.fShowModal = TRUE;
217 lpp->Advanced.hParent = hDlg;
218 lpp->Advanced.fMachine = FALSE;
219 lpp->Advanced.fApplyGeneral = FALSE;
220 lpp->Advanced.fApplyAdvanced = FALSE;
221 User_ShowProperties (&lpp->Advanced, uptMEMBERSHIP);
225 BOOL User_Create_OnOK (HWND hDlg)
227 LPCREATEUSERDLG lpp = (LPCREATEUSERDLG)GetWindowLongPtr (hDlg, DWLP_USER);
229 // First do a little validation of the dialog's entries
231 TCHAR szPw1[ cchRESOURCE ];
232 GetDlgItemText (hDlg, IDC_NEWUSER_PW1, szPw1, cchRESOURCE);
233 TCHAR szPw2[ cchRESOURCE ];
234 GetDlgItemText (hDlg, IDC_NEWUSER_PW2, szPw2, cchRESOURCE);
238 ErrorDialog (ERROR_INVALID_PASSWORDNAME, IDS_ERROR_NO_PASSWORD_GIVEN);
241 if (lstrcmp (szPw1, szPw2))
243 ErrorDialog (ERROR_INVALID_PASSWORDNAME, IDS_ERROR_MISMATCH_PASSWORD_GIVEN);
247 // Then start a background task to do all this work.
249 LPUSER_CREATE_PARAMS pTask = New (USER_CREATE_PARAMS);
250 memset (pTask, 0x00, sizeof(USER_CREATE_PARAMS));
252 lstrcpy (pTask->szPassword, szPw1);
254 if (IsDlgButtonChecked (hDlg, IDC_NEWUSER_ID_AUTO))
255 pTask->idUser = UID_AUTOSELECT;
256 else // (IsDlgButtonChecked (hDlg, IDC_NEWUSER_ID_MANUAL))
257 pTask->idUser = SP_GetPos (GetDlgItem (hDlg, IDC_NEWUSER_ID));
259 pTask->Properties.fIsAdmin = lpp->Advanced.fAdmin;
260 pTask->Properties.fCanGetTickets = lpp->Advanced.fGrantTickets;
261 pTask->Properties.fEncrypt = lpp->Advanced.fSeal;
262 pTask->Properties.fCanChangePassword = lpp->Advanced.fCanChangePw;
263 pTask->Properties.fCanReusePasswords = lpp->Advanced.fCanReusePw;
264 memcpy (&pTask->Properties.timeExpires, &lpp->Advanced.stExpires, sizeof(SYSTEMTIME));
265 pTask->Properties.cdayPwExpire = lpp->Advanced.cdayPwExpires;
266 pTask->Properties.csecTicketLifetime = lpp->Advanced.csecLifetime;
267 pTask->Properties.cFailLogin = lpp->Advanced.cFailLock;
268 pTask->Properties.csecFailLoginLock = lpp->Advanced.csecFailLock;
269 pTask->Properties.cgroupCreationQuota = lpp->Advanced.cGroupQuota;
270 pTask->Properties.aaListStatus = lpp->Advanced.aaStatus;
271 pTask->Properties.aaGroupsOwned = lpp->Advanced.aaOwned;
272 pTask->Properties.aaMembership = lpp->Advanced.aaMember;
273 pTask->fCreateKAS = lpp->Advanced.fCreateKAS;
274 pTask->fCreatePTS = lpp->Advanced.fCreatePTS;
276 if (lpp->Advanced.pGroupsMember)
277 asc_AsidListCopy (&pTask->pGroupsMember, &lpp->Advanced.pGroupsMember);
279 pTask->pGroupsMember = NULL;
281 if (lpp->Advanced.pGroupsOwner)
282 asc_AsidListCopy (&pTask->pGroupsOwner, &lpp->Advanced.pGroupsOwner);
284 pTask->pGroupsOwner = NULL;
286 // Crack the specified list of user names into a multi-string
288 TCHAR szSeparators[ cchRESOURCE ];
289 GetString (szSeparators, IDS_SEPARATORS);
290 lstrcat (szSeparators, TEXT(" \t"));
292 LPTSTR pszNames = GetEditText (GetDlgItem (hDlg, IDC_NEWUSER_NAME));
293 LPCTSTR pszStart = pszNames;
294 while (lstrchr (szSeparators, *pszStart))
299 // Find the first non-name character
301 LPCTSTR pszEnd = pszStart;
302 while (*pszEnd && !lstrchr(szSeparators, *pszEnd))
305 // Copy off this particular name
307 TCHAR szName[ cchNAME ];
308 lstrcpy (szName, pszStart);
309 szName[ pszEnd - pszStart ] = TEXT('\0');
312 FormatMultiString (&pTask->mszNames, FALSE, TEXT("%1"), TEXT("%s"), szName);
314 // Find the next valid-name character
317 while (lstrchr(szSeparators, *pszStart))
320 FreeString (pszNames);
322 // Do the real work of creating the user(s)
324 StartTask (taskUSER_CREATE, NULL, pTask);
326 // Store these creation parameters as the new defaults
328 memcpy (&gr.CreateUser, &lpp->Advanced, sizeof(USERPROPINFO));
333 void User_Create_OnEndTask_ObjectGet (HWND hDlg, LPTASKPACKET ptp)
337 TCHAR szText[ cchRESOURCE ];
338 GetDlgItemText (hDlg, IDC_NEWUSER_ID_AUTO, szText, cchRESOURCE);
340 LPTSTR pszText = FormatString (TEXT("%1 (%2)"), TEXT("%s%ld"), szText, TASKDATA(ptp)->Properties.u.CellProperties.idUserMax+1);
341 SetDlgItemText (hDlg, IDC_NEWUSER_ID_AUTO, pszText);
342 FreeString (pszText);
344 if (!IsWindowEnabled (GetDlgItem (hDlg, IDC_NEWUSER_ID)))
345 SP_SetPos (GetDlgItem (hDlg, IDC_NEWUSER_ID), TASKDATA(ptp)->Properties.u.CellProperties.idUserMax+1);