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 "mch_create.h"
21 * DEFINITIONS ________________________________________________________________
28 USERPROPINFO Advanced;
29 } CREATEMACHINEDLG, *LPCREATEMACHINEDLG;
31 #define UID_AUTOSELECT ((int)0)
35 * PROTOTYPES _________________________________________________________________
39 BOOL CALLBACK Machine_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
40 void Machine_Create_OnInitDialog (HWND hDlg);
41 void Machine_Create_OnNames (HWND hDlg);
42 void Machine_Create_OnID (HWND hDlg);
43 void Machine_Create_OnAdvanced (HWND hDlg);
44 BOOL Machine_Create_OnOK (HWND hDlg);
45 void Machine_Create_OnEndTask_ObjectGet (HWND hDlg, LPTASKPACKET ptp);
49 * ROUTINES ___________________________________________________________________
53 void Machine_SetDefaultCreateParams (LPUSERPROPINFO lpp)
55 memset (lpp, 0x00, sizeof(USERPROPINFO));
58 lpp->fGrantTickets = TRUE;
60 lpp->cGroupQuota = cGROUPQUOTA_DEFAULT;
61 lpp->aaStatus = aaANYONE;
62 lpp->aaOwned = aaANYONE;
63 lpp->aaMember = aaANYONE;
64 lpp->fCreateKAS = FALSE;
65 lpp->fCreatePTS = TRUE;
67 // All the KAS stuff is zero
69 lpp->csecLifetime = 0;
70 lpp->fExpires = FALSE;
71 lpp->fCanChangePw = 0;
72 lpp->fCanReusePw = FALSE;
73 lpp->cdayPwExpires = 0;
75 lpp->csecFailLock = 0;
79 void Machine_ShowCreate (HWND hParent)
81 LPCREATEMACHINEDLG lpp = New (CREATEMACHINEDLG);
82 memset (lpp, 0x00, sizeof(CREATEMACHINEDLG));
83 memcpy (&lpp->Advanced, &gr.CreateMachine, sizeof(USERPROPINFO));
84 lpp->uid = UID_AUTOSELECT;
85 lpp->Advanced.pGroupsMember = NULL;
86 lpp->Advanced.pGroupsOwner = NULL;
88 (void)ModalDialogParam (IDD_NEWMACHINE, hParent, (DLGPROC)Machine_Create_DlgProc, (LPARAM)lpp);
90 if (lpp->Advanced.pGroupsMember)
91 asc_AsidListFree (&lpp->Advanced.pGroupsMember);
92 if (lpp->Advanced.pGroupsOwner)
93 asc_AsidListFree (&lpp->Advanced.pGroupsOwner);
98 BOOL CALLBACK Machine_Create_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
100 if (AfsAppLib_HandleHelp (IDD_NEWMACHINE, hDlg, msg, wp, lp))
106 SetWindowLong (hDlg, DWL_USER, lp);
107 Machine_Create_OnInitDialog (hDlg);
112 if ((ptp = (LPTASKPACKET)lp) != NULL)
114 if (ptp->idTask == taskOBJECT_GET)
115 Machine_Create_OnEndTask_ObjectGet (hDlg, ptp);
116 FreeTaskPacket (ptp);
124 if (Machine_Create_OnOK (hDlg))
125 EndDialog (hDlg, IDOK);
129 EndDialog (hDlg, IDCANCEL);
133 Machine_Create_OnAdvanced (hDlg);
136 case IDC_NEWUSER_NAME:
137 Machine_Create_OnNames (hDlg);
140 case IDC_NEWUSER_ID_AUTO:
141 case IDC_NEWUSER_ID_MANUAL:
142 Machine_Create_OnID (hDlg);
152 void Machine_Create_OnInitDialog (HWND hDlg)
154 LPCREATEMACHINEDLG lpp = (LPCREATEMACHINEDLG)GetWindowLong (hDlg, DWL_USER);
156 // Fix the title of the dialog
159 TCHAR szName[ cchNAME ];
160 asc_CellNameGet_Fast (g.idClient, g.idCell, szName, &status);
162 TCHAR szText[ cchRESOURCE ];
163 GetDlgItemText (hDlg, IDC_NEWUSER_TITLE, szText, cchRESOURCE);
165 LPTSTR pszText = FormatString (szText, TEXT("%s"), szName);
166 SetDlgItemText (hDlg, IDC_NEWUSER_TITLE, pszText);
167 FreeString (pszText);
169 // Attach a spinner to the ID control
171 CheckDlgButton (hDlg, IDC_NEWUSER_ID_AUTO, TRUE);
172 CreateSpinner (GetDlgItem (hDlg, IDC_NEWUSER_ID), 10, FALSE, 1, 1, (int)-1);
173 Machine_Create_OnID (hDlg);
175 StartTask (taskOBJECT_GET, hDlg, (PVOID)(g.idCell));
179 void Machine_Create_OnNames (HWND hDlg)
181 TCHAR szSeparators[ cchRESOURCE ];
182 GetString (szSeparators, IDS_SEPARATORS);
183 lstrcat (szSeparators, TEXT(" \t"));
185 LPTSTR pszNames = GetEditText (GetDlgItem (hDlg, IDC_NEWUSER_NAME));
186 EnableWindow (GetDlgItem (hDlg, IDOK), (pszNames && *pszNames));
188 BOOL fMultiple = FALSE;
189 for (LPTSTR psz = pszNames; !fMultiple && psz && *psz; ++psz)
191 if (lstrchr (szSeparators, *psz))
194 FreeString (pszNames);
196 EnableWindow (GetDlgItem (hDlg, IDC_NEWUSER_ID_AUTO), !fMultiple);
197 EnableWindow (GetDlgItem (hDlg, IDC_NEWUSER_ID_MANUAL), !fMultiple);
200 CheckDlgButton (hDlg, IDC_NEWUSER_ID_AUTO, TRUE);
201 CheckDlgButton (hDlg, IDC_NEWUSER_ID_MANUAL, FALSE);
202 Machine_Create_OnID (hDlg);
207 void Machine_Create_OnID (HWND hDlg)
209 BOOL fEnable = IsDlgButtonChecked (hDlg, IDC_NEWUSER_ID_MANUAL);
210 EnableWindow (GetDlgItem (hDlg, IDC_NEWUSER_ID), fEnable);
214 void Machine_Create_OnAdvanced (HWND hDlg)
216 LPCREATEMACHINEDLG lpp = (LPCREATEMACHINEDLG)GetWindowLong (hDlg, DWL_USER);
217 lpp->Advanced.pUserList = NULL;
218 lpp->Advanced.fDeleteMeOnClose = FALSE;
219 lpp->Advanced.fShowModal = TRUE;
220 lpp->Advanced.hParent = hDlg;
221 lpp->Advanced.fMachine = TRUE;
222 lpp->Advanced.fApplyGeneral = FALSE;
223 lpp->Advanced.fApplyAdvanced = FALSE;
224 User_ShowProperties (&lpp->Advanced, uptMEMBERSHIP);
228 BOOL Machine_Create_OnOK (HWND hDlg)
230 LPCREATEMACHINEDLG lpp = (LPCREATEMACHINEDLG)GetWindowLong (hDlg, DWL_USER);
232 // Start a background task to do all this work.
234 LPUSER_CREATE_PARAMS pTask = New (USER_CREATE_PARAMS);
235 memset (pTask, 0x00, sizeof(USER_CREATE_PARAMS));
237 lstrcpy (pTask->szPassword, TEXT(""));
239 if (IsDlgButtonChecked (hDlg, IDC_NEWUSER_ID_AUTO))
240 pTask->idUser = UID_AUTOSELECT;
241 else // (IsDlgButtonChecked (hDlg, IDC_NEWUSER_ID_MANUAL))
242 pTask->idUser = SP_GetPos (GetDlgItem (hDlg, IDC_NEWUSER_ID));
244 pTask->Properties.cgroupCreationQuota = lpp->Advanced.cGroupQuota;
245 pTask->Properties.aaListStatus = lpp->Advanced.aaStatus;
246 pTask->Properties.aaGroupsOwned = lpp->Advanced.aaOwned;
247 pTask->Properties.aaMembership = lpp->Advanced.aaMember;
249 // All the KAS stuff is zero
251 pTask->Properties.fIsAdmin = FALSE;
252 pTask->Properties.fCanGetTickets = FALSE;
253 pTask->Properties.fEncrypt = FALSE;
254 pTask->Properties.fCanChangePassword = FALSE;
255 pTask->Properties.fCanReusePasswords = FALSE;
256 pTask->Properties.cdayPwExpire = 0;
257 pTask->Properties.csecTicketLifetime = 0;
258 pTask->Properties.cFailLogin = 0;
259 pTask->Properties.csecFailLoginLock = 0;
260 memset (&pTask->Properties.timeExpires, 0x00, sizeof(SYSTEMTIME));
262 // Copy over any lists-of-groups
264 if (lpp->Advanced.pGroupsMember)
265 asc_AsidListCopy (&pTask->pGroupsMember, &lpp->Advanced.pGroupsMember);
267 pTask->pGroupsMember = NULL;
269 if (lpp->Advanced.pGroupsOwner)
270 asc_AsidListCopy (&pTask->pGroupsOwner, &lpp->Advanced.pGroupsOwner);
272 pTask->pGroupsOwner = NULL;
274 // Crack the specified list of user names into a multi-string
276 TCHAR szSeparators[ cchRESOURCE ];
277 GetString (szSeparators, IDS_SEPARATORS);
278 lstrcat (szSeparators, TEXT(" \t"));
280 LPTSTR pszNames = GetEditText (GetDlgItem (hDlg, IDC_NEWUSER_NAME));
281 LPCTSTR pszStart = pszNames;
282 while (lstrchr (szSeparators, *pszStart))
287 // Find the first non-name character
289 LPCTSTR pszEnd = pszStart;
290 while (*pszEnd && !lstrchr(szSeparators, *pszEnd))
293 // Copy off this particular name
295 TCHAR szName[ cchNAME ];
296 lstrcpy (szName, pszStart);
297 szName[ pszEnd - pszStart ] = TEXT('\0');
300 FormatMultiString (&pTask->mszNames, FALSE, TEXT("%1"), TEXT("%s"), szName);
302 // Find the next valid-name character
305 while (lstrchr(szSeparators, *pszStart))
308 FreeString (pszNames);
310 // Do the real work of creating the user(s)
312 pTask->fCreateKAS = FALSE;
313 pTask->fCreatePTS = TRUE;
314 StartTask (taskUSER_CREATE, NULL, pTask);
316 // Store these creation parameters as the new defaults
318 memcpy (&gr.CreateMachine, &lpp->Advanced, sizeof(USERPROPINFO));
323 void Machine_Create_OnEndTask_ObjectGet (HWND hDlg, LPTASKPACKET ptp)
327 TCHAR szText[ cchRESOURCE ];
328 GetDlgItemText (hDlg, IDC_NEWUSER_ID_AUTO, szText, cchRESOURCE);
330 LPTSTR pszText = FormatString (TEXT("%1 (%2)"), TEXT("%s%ld"), szText, TASKDATA(ptp)->Properties.u.CellProperties.idUserMax+1);
331 SetDlgItemText (hDlg, IDC_NEWUSER_ID_AUTO, pszText);
332 FreeString (pszText);
334 if (!IsWindowEnabled (GetDlgItem (hDlg, IDC_NEWUSER_ID)))
335 SP_SetPos (GetDlgItem (hDlg, IDC_NEWUSER_ID), TASKDATA(ptp)->Properties.u.CellProperties.idUserMax+1);