Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

867 lines
17 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. ausrdlg.cpp
  5. Abstract:
  6. Add user dialog implementation.
  7. Author:
  8. Don Ryan (donryan) 14-Feb-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. Jeff Parham (jeffparh) 30-Jan-1996
  13. o Added new element to LV_COLUMN_ENTRY to differentiate the string
  14. used for the column header from the string used in the menus
  15. (so that the menu option can contain hot keys).
  16. --*/
  17. #include "stdafx.h"
  18. #include "llsmgr.h"
  19. #include "ausrdlg.h"
  20. static LV_COLUMN_INFO g_userColumnInfo = {0, 0, 1, {0, 0, 0, -1}};
  21. static LV_COLUMN_INFO g_addedColumnInfo = {0, 0, 1, {0, 0, 0, -1}};
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26. BEGIN_MESSAGE_MAP(CAddUsersDialog, CDialog)
  27. //{{AFX_MSG_MAP(CAddUsersDialog)
  28. ON_BN_CLICKED(IDC_ADD_USERS_ADD, OnAdd)
  29. ON_BN_CLICKED(IDC_ADD_USERS_DELETE, OnDelete)
  30. ON_NOTIFY(NM_DBLCLK, IDC_ADD_USERS_ADD_USERS, OnDblclkAddUsers)
  31. ON_NOTIFY(NM_DBLCLK, IDC_ADD_USERS_USERS, OnDblclkUsers)
  32. ON_CBN_SELCHANGE(IDC_ADD_USERS_DOMAINS, OnSelchangeDomains)
  33. ON_NOTIFY(LVN_GETDISPINFO, IDC_ADD_USERS_USERS, OnGetdispinfoUsers)
  34. ON_NOTIFY(NM_KILLFOCUS, IDC_ADD_USERS_USERS, OnKillfocusUsers)
  35. ON_NOTIFY(NM_SETFOCUS, IDC_ADD_USERS_USERS, OnSetfocusUsers)
  36. ON_NOTIFY(NM_KILLFOCUS, IDC_ADD_USERS_ADD_USERS, OnKillfocusAddUsers)
  37. ON_NOTIFY(NM_SETFOCUS, IDC_ADD_USERS_ADD_USERS, OnSetfocusAddUsers)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. CAddUsersDialog::CAddUsersDialog(CWnd* pParent /*=NULL*/)
  41. : CDialog(CAddUsersDialog::IDD, pParent)
  42. /*++
  43. Routine Description:
  44. Constructor for add user dialog.
  45. Arguments:
  46. pParent - parent window handle.
  47. Return Values:
  48. None.
  49. --*/
  50. {
  51. //{{AFX_DATA_INIT(CAddUsersDialog)
  52. m_iDomain = -1;
  53. m_iIndex = 0;
  54. //}}AFX_DATA_INIT
  55. m_pObList = NULL;
  56. m_bIsFocusUserList = FALSE;
  57. m_bIsFocusAddedList = FALSE;
  58. }
  59. void CAddUsersDialog::DoDataExchange(CDataExchange* pDX)
  60. /*++
  61. Routine Description:
  62. Called by framework to exchange dialog data.
  63. Arguments:
  64. pDX - data exchange object.
  65. Return Values:
  66. None.
  67. --*/
  68. {
  69. CDialog::DoDataExchange(pDX);
  70. //{{AFX_DATA_MAP(CAddUsersDialog)
  71. DDX_Control(pDX, IDC_ADD_USERS_ADD, m_addBtn);
  72. DDX_Control(pDX, IDC_ADD_USERS_DELETE, m_delBtn);
  73. DDX_Control(pDX, IDC_ADD_USERS_DOMAINS, m_domainList);
  74. DDX_Control(pDX, IDC_ADD_USERS_ADD_USERS, m_addedList);
  75. DDX_Control(pDX, IDC_ADD_USERS_USERS, m_userList);
  76. DDX_CBIndex(pDX, IDC_ADD_USERS_DOMAINS, m_iDomain);
  77. //}}AFX_DATA_MAP
  78. }
  79. void CAddUsersDialog::InitDialog(CObList* pObList)
  80. /*++
  81. Routine Description:
  82. Initializes return list.
  83. Arguments:
  84. pObList - pointer to return list.
  85. Return Values:
  86. None.
  87. --*/
  88. {
  89. ASSERT_VALID(pObList);
  90. m_pObList = pObList;
  91. }
  92. void CAddUsersDialog::InitDomainList()
  93. /*++
  94. Routine Description:
  95. Initializes list of domains.
  96. Arguments:
  97. None.
  98. Return Values:
  99. VT_BOOL.
  100. --*/
  101. {
  102. NTSTATUS NtStatus = STATUS_SUCCESS;
  103. CDomains* pDomains = NULL;
  104. CDomain* pDomain = NULL;
  105. int iDomain = 0;
  106. //First add the default domain
  107. CString strLabel = "";
  108. strLabel.LoadString(IDS_DEFAULT_DOMAIN);
  109. if ((iDomain = m_domainList.AddString(strLabel)) != CB_ERR)
  110. {
  111. m_domainList.SetCurSel(iDomain);
  112. m_domainList.SetItemDataPtr(iDomain, (LPVOID)-1L);
  113. }
  114. else
  115. {
  116. theApp.DisplayStatus( STATUS_NO_MEMORY );
  117. return;
  118. }
  119. //If FocusDomain, add the trusted domains
  120. if (LlsGetApp()->IsFocusDomain())
  121. {
  122. pDomain = (CDomain*)MKOBJ(LlsGetApp()->GetActiveDomain());
  123. ASSERT(pDomain && pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  124. if (pDomain)
  125. {
  126. VARIANT va;
  127. VariantInit(&va);
  128. pDomains = (CDomains*)MKOBJ(pDomain->GetTrustedDomains(va));
  129. if (pDomains && InsertDomains(pDomains))
  130. {
  131. // Now add active domain itself...
  132. if ((iDomain = m_domainList.AddString(pDomain->m_strName)) != CB_ERR)
  133. m_domainList.SetItemDataPtr(iDomain, pDomain);
  134. else
  135. NtStatus = STATUS_NO_MEMORY;
  136. }
  137. else
  138. NtStatus = LlsGetLastStatus();
  139. if (pDomains)
  140. pDomains->InternalRelease();
  141. pDomain->InternalRelease();
  142. }
  143. else
  144. NtStatus = LlsGetLastStatus();
  145. }
  146. //If not FocusDomain, add all domains
  147. else
  148. {
  149. pDomain = (CDomain*)MKOBJ(LlsGetApp()->GetLocalDomain());
  150. ASSERT(pDomain && pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  151. if (pDomain)
  152. {
  153. VARIANT va;
  154. VariantInit(&va);
  155. pDomains = (CDomains*)MKOBJ(LlsGetApp()->GetDomains(va));
  156. if (pDomains && InsertDomains(pDomains))
  157. {
  158. //
  159. // CODEWORK... scroll to local domain???
  160. //
  161. }
  162. else
  163. NtStatus = LlsGetLastStatus();
  164. if (pDomains)
  165. pDomains->InternalRelease();
  166. pDomain->InternalRelease();
  167. }
  168. else
  169. NtStatus = LlsGetLastStatus();
  170. }
  171. if (!NT_SUCCESS(NtStatus))
  172. {
  173. theApp.DisplayStatus(NtStatus);
  174. m_domainList.ResetContent();
  175. }
  176. }
  177. void CAddUsersDialog::InitUserList()
  178. /*++
  179. Routine Description:
  180. Initializes list of users.
  181. Arguments:
  182. None.
  183. Return Values:
  184. None.
  185. --*/
  186. {
  187. ::LvInitColumns(&m_userList, &g_userColumnInfo);
  188. ::LvInitColumns(&m_addedList, &g_addedColumnInfo);
  189. }
  190. BOOL CAddUsersDialog::InsertDomains(CDomains* pDomains)
  191. /*++
  192. Routine Description:
  193. Inserts domains into domain list.
  194. Arguments:
  195. pDomains - domain collection.
  196. Return Values:
  197. None.
  198. --*/
  199. {
  200. NTSTATUS NtStatus = STATUS_SUCCESS;
  201. ASSERT_VALID(pDomains);
  202. if (pDomains)
  203. {
  204. VARIANT va;
  205. VariantInit(&va);
  206. CDomain* pDomain;
  207. int iDomain;
  208. int nDomains = pDomains->GetCount();
  209. for (va.vt = VT_I4, va.lVal = 0; (va.lVal < nDomains) && NT_SUCCESS(NtStatus); va.lVal++)
  210. {
  211. pDomain = (CDomain*)MKOBJ(pDomains->GetItem(va));
  212. ASSERT(pDomain && pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  213. if (pDomain)
  214. {
  215. if ((iDomain = m_domainList.AddString(pDomain->m_strName)) != CB_ERR)
  216. {
  217. m_domainList.SetItemDataPtr(iDomain, pDomain);
  218. }
  219. else
  220. {
  221. NtStatus = STATUS_NO_MEMORY;
  222. }
  223. pDomain->InternalRelease();
  224. }
  225. else
  226. {
  227. NtStatus = STATUS_NO_MEMORY;
  228. }
  229. }
  230. }
  231. else
  232. {
  233. NtStatus = STATUS_INVALID_PARAMETER;
  234. }
  235. if (!NT_SUCCESS(NtStatus))
  236. {
  237. m_domainList.ResetContent();
  238. LlsSetLastStatus(NtStatus);
  239. return FALSE;
  240. }
  241. return TRUE;
  242. }
  243. void CAddUsersDialog::OnAdd()
  244. /*++
  245. Routine Description:
  246. Message handler for IDC_ADD_USER_ADD.
  247. Arguments:
  248. None.
  249. Return Values:
  250. None.
  251. --*/
  252. {
  253. CUser* pUser;
  254. int iItem = -1;
  255. while (NULL != (pUser = (CUser*)::LvGetNextObj(&m_userList, &iItem)))
  256. {
  257. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  258. LV_FINDINFO lvFindInfo;
  259. lvFindInfo.flags = LVFI_STRING;
  260. lvFindInfo.psz = MKSTR(pUser->m_strName);
  261. if (m_addedList.FindItem(&lvFindInfo, -1) == -1)
  262. {
  263. //
  264. // Make a copy of the user (w/no parent)
  265. //
  266. CUser* pNewUser = new CUser(NULL, pUser->m_strName);
  267. if (pNewUser)
  268. {
  269. LV_ITEM lvItem;
  270. lvItem.mask = LVIF_TEXT|
  271. LVIF_PARAM|
  272. LVIF_IMAGE;
  273. lvItem.iSubItem = 0;
  274. lvItem.lParam = (LPARAM)(LPVOID)pNewUser;
  275. lvItem.iImage = BMPI_USER;
  276. lvItem.pszText = MKSTR(pNewUser->m_strName);
  277. lvItem.iItem = m_iIndex;
  278. m_addedList.InsertItem(&lvItem);
  279. m_iIndex++;
  280. }
  281. else
  282. {
  283. theApp.DisplayStatus( STATUS_NO_MEMORY );
  284. break;
  285. }
  286. }
  287. }
  288. m_userList.SetFocus();
  289. }
  290. void CAddUsersDialog::OnDblclkAddUsers(NMHDR* pNMHDR, LRESULT* pResult)
  291. /*++
  292. Routine Description:
  293. Notification handler for NM_DLBCLK.
  294. Arguments:
  295. pNMHDR - notification header.
  296. pResult - return code.
  297. Return Values:
  298. None.
  299. --*/
  300. {
  301. UNREFERENCED_PARAMETER(pNMHDR);
  302. OnDelete();
  303. ASSERT(NULL != pResult);
  304. *pResult = 0;
  305. }
  306. void CAddUsersDialog::OnDblclkUsers(NMHDR* pNMHDR, LRESULT* pResult)
  307. /*++
  308. Routine Description:
  309. Notification handler for NM_DLBCLK.
  310. Arguments:
  311. pNMHDR - notification header.
  312. pResult - return code.
  313. Return Values:
  314. None.
  315. --*/
  316. {
  317. UNREFERENCED_PARAMETER(pNMHDR);
  318. OnAdd();
  319. ASSERT(NULL != pResult);
  320. *pResult = 0;
  321. }
  322. void CAddUsersDialog::OnDelete()
  323. /*++
  324. Routine Description:
  325. Message handler for IDC_ADD_USER_DELETE.
  326. Arguments:
  327. None.
  328. Return Values:
  329. None.
  330. --*/
  331. {
  332. CUser* pUser;
  333. int iItem = -1;
  334. int iLastItem = 0;
  335. while (NULL != (pUser = (CUser*)::LvGetNextObj(&m_addedList, &iItem)))
  336. {
  337. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  338. pUser->InternalRelease(); // allocated above....
  339. m_addedList.DeleteItem(iItem);
  340. iLastItem = iItem;
  341. iItem = -1;
  342. m_iIndex--;
  343. }
  344. m_addedList.SetItemState(iLastItem, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  345. m_addedList.SetFocus();
  346. }
  347. BOOL CAddUsersDialog::OnInitDialog()
  348. /*++
  349. Routine Description:
  350. Message handler for WM_INITDIALOG.
  351. Arguments:
  352. None.
  353. Return Values:
  354. None.
  355. --*/
  356. {
  357. BeginWaitCursor();
  358. CDialog::OnInitDialog();
  359. InitUserList(); // always construct headers...
  360. InitDomainList();
  361. m_addBtn.EnableWindow(FALSE);
  362. m_delBtn.EnableWindow(FALSE);
  363. if (!RefreshUserList())
  364. theApp.DisplayLastStatus();
  365. m_domainList.SetFocus();
  366. EndWaitCursor();
  367. return FALSE; // set focus to domain list
  368. }
  369. void CAddUsersDialog::OnSelchangeDomains()
  370. /*++
  371. Routine Description:
  372. Message handler for CBN_SELCHANGED.
  373. Arguments:
  374. None.
  375. Return Values:
  376. None.
  377. --*/
  378. {
  379. RefreshUserList();
  380. }
  381. BOOL CAddUsersDialog::RefreshUserList()
  382. /*++
  383. Routine Description:
  384. Refreshs list of users (with currently selected item).
  385. Arguments:
  386. None.
  387. Return Values:
  388. VT_BOOL.
  389. --*/
  390. {
  391. NTSTATUS NtStatus = STATUS_SUCCESS;
  392. m_userList.DeleteAllItems();
  393. int iDomain;
  394. if ((iDomain = m_domainList.GetCurSel()) != CB_ERR)
  395. {
  396. CDomain* pDomain = (CDomain*)m_domainList.GetItemDataPtr(iDomain);
  397. CUsers* pUsers = (CUsers*)NULL;
  398. VARIANT va;
  399. VariantInit(&va);
  400. if (pDomain == (CDomain*)-1L)
  401. {
  402. //
  403. // Enumerate users in license cache...
  404. //
  405. CController* pController = (CController*)MKOBJ(LlsGetApp()->GetActiveController());
  406. if ( pController )
  407. {
  408. pController->InternalRelease(); // held open by CApplication
  409. pUsers = pController->m_pUsers;
  410. pUsers->InternalAddRef(); // released below...
  411. }
  412. }
  413. else
  414. {
  415. //
  416. // Enumerate users in particular domain...
  417. //
  418. ASSERT(pDomain->IsKindOf(RUNTIME_CLASS(CDomain)));
  419. pUsers = (CUsers*)MKOBJ(pDomain->GetUsers(va));
  420. ASSERT(pUsers && pUsers->IsKindOf(RUNTIME_CLASS(CUsers)));
  421. }
  422. if (pUsers)
  423. {
  424. CUser* pUser;
  425. int nUsers = pUsers->GetCount();
  426. LV_ITEM lvItem;
  427. lvItem.mask = LVIF_TEXT|
  428. LVIF_PARAM|
  429. LVIF_IMAGE;
  430. lvItem.iSubItem = 0;
  431. lvItem.pszText = LPSTR_TEXTCALLBACK;
  432. lvItem.cchTextMax = LPSTR_TEXTCALLBACK_MAX;
  433. lvItem.iImage = BMPI_USER;
  434. for (va.vt = VT_I4, va.lVal = 0; (va.lVal < nUsers) && NT_SUCCESS(NtStatus); va.lVal++)
  435. {
  436. pUser = (CUser*)MKOBJ(pUsers->GetItem(va));
  437. ASSERT(pUser && pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  438. if (pUser)
  439. {
  440. lvItem.iItem = va.lVal;
  441. lvItem.lParam = (LPARAM)(LPVOID)pUser;
  442. if (m_userList.InsertItem(&lvItem) == -1)
  443. {
  444. NtStatus = STATUS_NO_MEMORY;
  445. }
  446. pUser->InternalRelease();
  447. }
  448. else
  449. {
  450. NtStatus = STATUS_NO_MEMORY;
  451. }
  452. }
  453. pUsers->InternalRelease();
  454. }
  455. else
  456. {
  457. NtStatus = LlsGetLastStatus();
  458. }
  459. VariantClear(&va);
  460. }
  461. else
  462. {
  463. NtStatus = STATUS_NO_MEMORY;
  464. }
  465. if (!NT_SUCCESS(NtStatus))
  466. {
  467. m_userList.DeleteAllItems();
  468. LlsSetLastStatus(NtStatus);
  469. }
  470. ::LvResizeColumns(&m_userList, &g_userColumnInfo);
  471. return NT_SUCCESS(NtStatus);
  472. }
  473. void CAddUsersDialog::OnOK()
  474. /*++
  475. Routine Description:
  476. Message handler for IDOK.
  477. Arguments:
  478. None.
  479. Return Values:
  480. None.
  481. --*/
  482. {
  483. if (m_pObList)
  484. {
  485. CUser* pUser;
  486. int iItem = -1;
  487. m_pObList->RemoveAll();
  488. while (NULL != (pUser = (CUser*)::LvGetNextObj(&m_addedList, &iItem, LVNI_ALL)))
  489. {
  490. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  491. m_pObList->AddTail(pUser);
  492. }
  493. }
  494. CDialog::OnOK();
  495. }
  496. void CAddUsersDialog::OnCancel()
  497. /*++
  498. Routine Description:
  499. Message handler for IDCANCEL.
  500. Arguments:
  501. None.
  502. Return Values:
  503. None.
  504. --*/
  505. {
  506. CUser* pUser;
  507. int iItem = -1;
  508. while (NULL != (pUser = (CUser*)::LvGetNextObj(&m_addedList, &iItem, LVNI_ALL)))
  509. {
  510. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  511. pUser->InternalRelease();
  512. }
  513. CDialog::OnCancel();
  514. }
  515. void CAddUsersDialog::InitDialogCtrls()
  516. {
  517. int iItem = -1;
  518. if (m_bIsFocusUserList && m_userList.GetItemCount())
  519. {
  520. m_addBtn.EnableWindow(TRUE);
  521. m_delBtn.EnableWindow(FALSE);
  522. }
  523. else if (m_bIsFocusAddedList && m_addedList.GetItemCount())
  524. {
  525. m_addBtn.EnableWindow(FALSE);
  526. m_delBtn.EnableWindow(TRUE);
  527. }
  528. else
  529. {
  530. m_addBtn.EnableWindow(FALSE);
  531. m_delBtn.EnableWindow(FALSE);
  532. }
  533. ::LvResizeColumns(&m_userList, &g_userColumnInfo);
  534. ::LvResizeColumns(&m_addedList, &g_addedColumnInfo);
  535. }
  536. void CAddUsersDialog::OnGetdispinfoUsers(NMHDR* pNMHDR, LRESULT* pResult)
  537. {
  538. ASSERT(NULL != pNMHDR);
  539. LV_ITEM lvItem = ((LV_DISPINFO*)pNMHDR)->item;
  540. if (lvItem.iSubItem == 0)
  541. {
  542. CUser* pUser = (CUser*)lvItem.lParam;
  543. ASSERT(pUser && pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  544. lstrcpyn(lvItem.pszText, pUser->m_strName, lvItem.cchTextMax);
  545. }
  546. ASSERT(NULL != pResult);
  547. *pResult = 0;
  548. }
  549. void CAddUsersDialog::OnKillfocusUsers(NMHDR* pNMHDR, LRESULT* pResult)
  550. {
  551. UNREFERENCED_PARAMETER(pNMHDR);
  552. ASSERT(NULL != pResult);
  553. *pResult = 0;
  554. }
  555. void CAddUsersDialog::OnSetfocusUsers(NMHDR* pNMHDR, LRESULT* pResult)
  556. {
  557. UNREFERENCED_PARAMETER(pNMHDR);
  558. m_bIsFocusUserList = TRUE;
  559. m_bIsFocusAddedList = FALSE;
  560. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  561. ASSERT(NULL != pResult);
  562. *pResult = 0;
  563. }
  564. void CAddUsersDialog::OnKillfocusAddUsers(NMHDR* pNMHDR, LRESULT* pResult)
  565. {
  566. UNREFERENCED_PARAMETER(pNMHDR);
  567. ASSERT(NULL != pResult);
  568. *pResult = 0;
  569. }
  570. void CAddUsersDialog::OnSetfocusAddUsers(NMHDR* pNMHDR, LRESULT* pResult)
  571. {
  572. UNREFERENCED_PARAMETER(pNMHDR);
  573. m_bIsFocusUserList = FALSE;
  574. m_bIsFocusAddedList = TRUE;
  575. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  576. ASSERT(NULL != pResult);
  577. *pResult = 0;
  578. }
  579. BOOL CAddUsersDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  580. {
  581. if (wParam == ID_INIT_CTRLS)
  582. {
  583. InitDialogCtrls();
  584. return TRUE; // processed...
  585. }
  586. return CDialog::OnCommand(wParam, lParam);
  587. }