Source code of Windows XP (NT5)
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.

407 lines
9.9 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991-1996 **/
  4. /**********************************************************************/
  5. /*
  6. GUsers.cpp : implementation file
  7. CPropertyPage support for Group management wizard
  8. FILE HISTORY:
  9. Jony Apr-1996 created
  10. */
  11. #include "stdafx.h"
  12. #include "Romaine.h"
  13. #include "userlist.h"
  14. #include "GUsers.h"
  15. #include <lmcons.h>
  16. #include <lmaccess.h>
  17. #include <lmerr.h>
  18. #include <lmapibuf.h>
  19. #include <winnetwk.h>
  20. #include <winreg.h>
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CGUsers property page
  28. IMPLEMENT_DYNCREATE(CGUsers, CPropertyPage)
  29. CGUsers::CGUsers() : CPropertyPage(CGUsers::IDD)
  30. {
  31. //{{AFX_DATA_INIT(CGUsers)
  32. // NOTE: the ClassWizard will add member initialization here
  33. //}}AFX_DATA_INIT
  34. }
  35. CGUsers::~CGUsers()
  36. {
  37. }
  38. void CGUsers::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CPropertyPage::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CGUsers)
  42. DDX_Control(pDX, IDC_SELECTED_MEMBERS_LIST, m_lbSelectedUsers);
  43. DDX_Control(pDX, IDC_AVAILABLE_MEMBERS_LIST, m_lbAvailableUsers);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CGUsers, CPropertyPage)
  47. //{{AFX_MSG_MAP(CGUsers)
  48. ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
  49. ON_BN_CLICKED(IDC_REMOVE_BUTTON, OnRemoveButton)
  50. ON_LBN_SETFOCUS(IDC_AVAILABLE_MEMBERS_LIST, OnSetfocusAvailableMembersList)
  51. ON_LBN_SETFOCUS(IDC_SELECTED_MEMBERS_LIST, OnSetfocusSelectedMembersList)
  52. ON_WM_SHOWWINDOW()
  53. ON_LBN_DBLCLK(IDC_AVAILABLE_MEMBERS_LIST, OnDblclkAvailableMembersList)
  54. ON_LBN_DBLCLK(IDC_SELECTED_MEMBERS_LIST, OnDblclkSelectedMembersList)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CGUsers message handlers
  59. // enum users thread
  60. void CGUsers::EnumUsers(TCHAR* lpszPrimaryDC)
  61. {
  62. CString csTemp;
  63. // now enumerate the users on that machine
  64. void* netUserBuffer;
  65. DWORD dwReturnedEntries;
  66. DWORD err = NetQueryDisplayInformation(lpszPrimaryDC, 1,
  67. 0, 100, 100 * sizeof(NET_DISPLAY_USER),
  68. &dwReturnedEntries, &netUserBuffer);
  69. // check return for error
  70. if (err != NERR_Success && err != ERROR_MORE_DATA) return;
  71. // add these users to the dialog
  72. DWORD dwCurrent;
  73. NET_DISPLAY_USER* netUser;
  74. netUser = (NET_DISPLAY_USER*)netUserBuffer;
  75. for (dwCurrent = 0; dwCurrent < dwReturnedEntries; dwCurrent++)
  76. {
  77. csTemp = netUser->usri1_name;
  78. if (netUser->usri1_flags & UF_NORMAL_ACCOUNT) m_lbAvailableUsers.AddString(0, csTemp);
  79. // else m_lbAvailableUsers.AddString(4, csTemp);
  80. netUser++;
  81. }
  82. // add more users?
  83. DWORD dwNext;
  84. while (err == ERROR_MORE_DATA)
  85. {
  86. netUser--;
  87. NetGetDisplayInformationIndex(lpszPrimaryDC, 1, netUser->usri1_name, &dwNext);
  88. NetApiBufferFree(netUserBuffer);
  89. err = NetQueryDisplayInformation(lpszPrimaryDC, 1,
  90. dwNext, 100, 32767,
  91. &dwReturnedEntries, &netUserBuffer);
  92. // check return for error
  93. if (err != NERR_Success && err != ERROR_MORE_DATA) return;
  94. netUser = (NET_DISPLAY_USER*)netUserBuffer;
  95. for (dwCurrent = 0; dwCurrent < dwReturnedEntries; dwCurrent++)
  96. {
  97. csTemp = netUser->usri1_name;
  98. if (netUser->usri1_flags & UF_NORMAL_ACCOUNT) m_lbAvailableUsers.AddString(0, csTemp);
  99. // else m_lbAvailableUsers.AddString(4, csTemp);
  100. netUser++;
  101. }
  102. }
  103. NetApiBufferFree(netUserBuffer);
  104. }
  105. LRESULT CGUsers::OnWizardBack()
  106. {
  107. CRomaineApp* pApp = (CRomaineApp*)AfxGetApp();
  108. if (pApp->m_bServer) return IDD_GROUP_TYPE_DLG;
  109. else if (pApp->m_csCmdLine != L"") return IDD_GROUP_LIST_DIALOG;
  110. else if (pApp->m_sMode == 1) return IDD_GROUP_LIST_DIALOG;
  111. else return IDD_LR_DIALOG;
  112. }
  113. void CGUsers::OnAddButton()
  114. {
  115. UpdateData(TRUE);
  116. USHORT usSel = m_lbAvailableUsers.GetCurSel();
  117. if (usSel == 65535)
  118. {
  119. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  120. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  121. m_lbSelectedUsers.SetCurSel(0);
  122. return;
  123. }
  124. CString csSel;
  125. m_lbAvailableUsers.GetText(usSel, csSel);
  126. ULONG ulBmp = m_lbAvailableUsers.GetItemData(usSel);
  127. m_lbSelectedUsers.AddString(csSel, ulBmp);
  128. m_lbAvailableUsers.DeleteString(usSel);
  129. // anybody left?
  130. if (m_lbAvailableUsers.GetCount() != 0)
  131. m_lbAvailableUsers.SetCurSel(0);
  132. else
  133. {
  134. m_lbSelectedUsers.SetCurSel(0);
  135. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  136. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  137. m_lbAvailableUsers.SetHorizontalExtent(0);
  138. }
  139. }
  140. void CGUsers::OnRemoveButton()
  141. {
  142. UpdateData(TRUE);
  143. USHORT usSel = m_lbSelectedUsers.GetCurSel();
  144. if (usSel == 65535)
  145. {
  146. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  147. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  148. m_lbAvailableUsers.SetCurSel(0);
  149. return;
  150. }
  151. CString csSel;
  152. m_lbSelectedUsers.GetText(usSel, csSel);
  153. ULONG ulBmp = m_lbSelectedUsers.GetItemData(usSel);
  154. m_lbAvailableUsers.AddString(csSel, ulBmp);
  155. m_lbSelectedUsers.DeleteString(usSel);
  156. // anybody left?
  157. if (m_lbSelectedUsers.GetCount() != 0)
  158. m_lbSelectedUsers.SetCurSel(0);
  159. else
  160. {
  161. m_lbAvailableUsers.SetCurSel(0);
  162. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  163. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  164. m_lbSelectedUsers.SetHorizontalExtent(0);
  165. }
  166. }
  167. void CGUsers::OnSetfocusAvailableMembersList()
  168. {
  169. CWnd* pWnd = GetDlgItem(IDC_ADD_BUTTON);
  170. pWnd->EnableWindow(TRUE);
  171. pWnd = GetDlgItem(IDC_REMOVE_BUTTON);
  172. pWnd->EnableWindow(FALSE);
  173. m_lbSelectedUsers.SetCurSel(-1);
  174. }
  175. void CGUsers::OnSetfocusSelectedMembersList()
  176. {
  177. CWnd* pWnd = GetDlgItem(IDC_ADD_BUTTON);
  178. pWnd->EnableWindow(FALSE);
  179. pWnd = GetDlgItem(IDC_REMOVE_BUTTON);
  180. pWnd->EnableWindow(TRUE);
  181. m_lbAvailableUsers.SetCurSel(-1);
  182. }
  183. LRESULT CGUsers::OnWizardNext()
  184. {
  185. UpdateData(TRUE);
  186. CRomaineApp* pApp = (CRomaineApp*)AfxGetApp();
  187. pApp->m_cps1.SetWizardButtons(PSWIZB_FINISH | PSWIZB_BACK);
  188. // empty the list
  189. pApp->m_csaNames.RemoveAll();
  190. // fill with new names.
  191. USHORT us;
  192. CString csTemp;
  193. for (us = 0; us < m_lbSelectedUsers.GetCount(); us++)
  194. {
  195. m_lbSelectedUsers.GetText(us, csTemp);
  196. pApp->m_csaNames.AddHead(csTemp);
  197. }
  198. return CPropertyPage::OnWizardNext();
  199. }
  200. void CGUsers::OnShowWindow(BOOL bShow, UINT nStatus)
  201. {
  202. CPropertyPage::OnShowWindow(bShow, nStatus);
  203. CRomaineApp* pApp = (CRomaineApp*)AfxGetApp();
  204. CWaitCursor wait;
  205. if (bShow)
  206. {
  207. if (m_csServer != pApp->m_csServer)
  208. {
  209. m_csServer = pApp->m_csServer;
  210. m_lbSelectedUsers.ResetContent();
  211. }
  212. // on a rerun clean out the members from the last group
  213. else if (pApp->bRestart2)
  214. {
  215. m_lbSelectedUsers.ResetContent();
  216. pApp->bRestart2 == FALSE;
  217. }
  218. else return;
  219. m_lbAvailableUsers.ResetContent();
  220. TCHAR* pServer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  221. pApp->m_csServer.ReleaseBuffer();
  222. EnumUsers(pServer);
  223. // editing a group? add the current members
  224. if (pApp->m_sMode == 1)
  225. {
  226. DWORD dwEntriesRead;
  227. DWORD dwTotalEntries;
  228. DWORD dwResumeHandle = 0;
  229. m_lbSelectedUsers.ResetContent();
  230. TCHAR* pGroup = pApp->m_csGroupName.GetBuffer(pApp->m_csGroupName.GetLength());
  231. pApp->m_csGroupName.ReleaseBuffer();
  232. PGROUP_USERS_INFO_0 pMembers;
  233. NET_API_STATUS nApi = NetGroupGetUsers(pServer,
  234. pGroup,
  235. 0,
  236. (LPBYTE*)&pMembers,
  237. 5000,
  238. &dwEntriesRead,
  239. &dwTotalEntries,
  240. &dwResumeHandle);
  241. if (nApi != ERROR_SUCCESS)
  242. {
  243. AfxMessageBox(IDS_CANT_GET_USERS);
  244. goto keepgoing;
  245. }
  246. USHORT sIndex;
  247. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  248. {
  249. wchar_t sTemp[150];
  250. swprintf(sTemp, TEXT("%s"), pMembers[sIndex].grui0_name);
  251. m_lbSelectedUsers.AddString(0, sTemp);
  252. }
  253. NetApiBufferFree(pMembers);
  254. while (dwResumeHandle != 0)
  255. {
  256. nApi = NetGroupGetUsers(pServer,
  257. pGroup,
  258. 0,
  259. (LPBYTE*)&pMembers,
  260. 5000,
  261. &dwEntriesRead,
  262. &dwTotalEntries,
  263. &dwResumeHandle);
  264. if (nApi != ERROR_SUCCESS)
  265. {
  266. AfxMessageBox(IDS_CANT_GET_USERS);
  267. goto keepgoing;
  268. }
  269. USHORT sIndex;
  270. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  271. {
  272. wchar_t sTemp[150];
  273. swprintf(sTemp, TEXT("%s"), pMembers[sIndex].grui0_name);
  274. m_lbSelectedUsers.AddString(0, sTemp);
  275. }
  276. NetApiBufferFree(pMembers);
  277. }
  278. }
  279. keepgoing:
  280. m_lbSelectedUsers.SetHorizontalExtent(200);
  281. m_lbAvailableUsers.SetHorizontalExtent(200);
  282. // now clean up list to remove those users already added
  283. USHORT sValueCount = m_lbSelectedUsers.GetCount();
  284. USHORT sCount, sSel;
  285. CString csValue;
  286. for (sCount = 0; sCount < sValueCount; sCount++)
  287. {
  288. m_lbSelectedUsers.GetText(sCount, csValue);
  289. m_lbAvailableUsers.SelectString(-1, csValue);
  290. sSel = m_lbAvailableUsers.GetCurSel();
  291. m_lbAvailableUsers.DeleteString(sSel);
  292. }
  293. m_lbAvailableUsers.SetCurSel(0);
  294. }
  295. }
  296. void CGUsers::OnDblclkAvailableMembersList()
  297. {
  298. UpdateData(TRUE);
  299. USHORT usSel = m_lbAvailableUsers.GetCurSel();
  300. CString csSel;
  301. m_lbAvailableUsers.GetText(usSel, csSel);
  302. ULONG ulBmp = m_lbAvailableUsers.GetItemData(usSel);
  303. m_lbSelectedUsers.AddString(csSel, ulBmp);
  304. m_lbAvailableUsers.DeleteString(usSel);
  305. // anybody left?
  306. if (m_lbAvailableUsers.GetCount() != 0)
  307. m_lbAvailableUsers.SetCurSel(0);
  308. else
  309. {
  310. m_lbSelectedUsers.SetCurSel(0);
  311. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(TRUE);
  312. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(FALSE);
  313. m_lbAvailableUsers.SetHorizontalExtent(0);
  314. }
  315. }
  316. void CGUsers::OnDblclkSelectedMembersList()
  317. {
  318. UpdateData(TRUE);
  319. USHORT usSel = m_lbSelectedUsers.GetCurSel();
  320. CString csSel;
  321. m_lbSelectedUsers.GetText(usSel, csSel);
  322. ULONG ulBmp = m_lbSelectedUsers.GetItemData(usSel);
  323. m_lbAvailableUsers.AddString(csSel, ulBmp);
  324. m_lbSelectedUsers.DeleteString(usSel);
  325. // anybody left?
  326. if (m_lbSelectedUsers.GetCount() != 0)
  327. m_lbSelectedUsers.SetCurSel(0);
  328. else
  329. {
  330. m_lbAvailableUsers.SetCurSel(0);
  331. GetDlgItem(IDC_ADD_BUTTON)->EnableWindow(TRUE);
  332. GetDlgItem(IDC_REMOVE_BUTTON)->EnableWindow(FALSE);
  333. m_lbSelectedUsers.SetHorizontalExtent(0);
  334. }
  335. }