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.

315 lines
7.0 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991-1996 **/
  4. /**********************************************************************/
  5. /*
  6. ExGrp.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 "ExGrp.h"
  15. #include <lmaccess.h>
  16. #include <lmcons.h>
  17. #include <lmapibuf.h>
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CExGrp property page
  25. IMPLEMENT_DYNCREATE(CExGrp, CPropertyPage)
  26. CExGrp::CExGrp() : CPropertyPage(CExGrp::IDD)
  27. {
  28. //{{AFX_DATA_INIT(CExGrp)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. m_pApp = (CRomaineApp*)AfxGetApp();
  32. }
  33. CExGrp::~CExGrp()
  34. {
  35. }
  36. void CExGrp::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CPropertyPage::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CExGrp)
  40. DDX_Control(pDX, IDC_GROUP_LIST, m_lbGroupList);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CExGrp, CPropertyPage)
  44. //{{AFX_MSG_MAP(CExGrp)
  45. ON_BN_CLICKED(IDC_ADD_NEW_BUTTON, OnAddNewButton)
  46. ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
  47. ON_WM_SHOWWINDOW()
  48. ON_LBN_DBLCLK(IDC_GROUP_LIST, OnDblclkGroupList)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CExGrp message handlers
  53. BOOL CExGrp::OnInitDialog()
  54. {
  55. CPropertyPage::OnInitDialog();
  56. /*
  57. int nVal = ClassifyGroup();
  58. if (nVal == 1)
  59. {
  60. pApp->m_nGroupType = 0;
  61. pApp->m_cps1.SetActivePage(6); // global group
  62. }
  63. else if (nVal == 3)
  64. {
  65. pApp->m_nGroupType = 1;
  66. pApp->m_cps1.SetActivePage(5); // local Group
  67. }
  68. */
  69. return TRUE; // return TRUE unless you set the focus to a control
  70. // EXCEPTION: OCX Property Pages should return FALSE
  71. }
  72. LRESULT CExGrp::OnWizardNext()
  73. {
  74. UpdateData(TRUE);
  75. USHORT sSel = m_lbGroupList.GetCurSel();
  76. if (sSel == -1)
  77. {
  78. AfxMessageBox(IDS_NO_GROUP_SELECTED);
  79. return -1;
  80. }
  81. m_pApp->m_csGroupName = m_lbGroupList.GetGroupName(sSel);
  82. int sSelType = m_lbGroupList.GetSelType(sSel);
  83. if (sSelType == 1)
  84. {
  85. m_pApp->m_nGroupType = 0;
  86. return IDD_GLOBAL_USERS; // global group
  87. }
  88. else
  89. {
  90. m_pApp->m_nGroupType = 1;
  91. return IDD_LOCAL_USERS; // local Group
  92. }
  93. return CPropertyPage::OnWizardNext();
  94. }
  95. void CExGrp::OnAddNewButton()
  96. {
  97. m_pApp->m_cps1.SetActivePage(1);
  98. }
  99. void CExGrp::OnDeleteButton()
  100. {
  101. UpdateData(TRUE);
  102. if (AfxMessageBox(IDS_DELETE_GROUP_CONFIRM, MB_YESNO) != IDYES) return;
  103. TCHAR* pServer = m_pApp->m_csServer.GetBuffer(m_pApp->m_csServer.GetLength());
  104. m_pApp->m_csServer.ReleaseBuffer();
  105. USHORT sSel = m_lbGroupList.GetCurSel();
  106. if (sSel == -1)
  107. {
  108. AfxMessageBox(IDS_NO_GROUP_SELECTED);
  109. return;
  110. }
  111. CString csGroupName = m_lbGroupList.GetGroupName(sSel);
  112. TCHAR* pGroupName = csGroupName.GetBuffer(csGroupName.GetLength());
  113. csGroupName.ReleaseBuffer();
  114. int sSelType = m_lbGroupList.GetSelType(sSel);
  115. if (sSelType == 1) // global group
  116. {
  117. if (NetGroupDel(pServer, pGroupName) == 0L)
  118. {
  119. m_lbGroupList.DeleteString(sSel);
  120. AfxMessageBox(IDS_GROUP_DELETED);
  121. }
  122. else AfxMessageBox(IDS_GROUP_NOT_DELETED);
  123. }
  124. else // local Group
  125. {
  126. if (NetLocalGroupDel(pServer, pGroupName) == 0L)
  127. {
  128. m_lbGroupList.DeleteString(sSel);
  129. AfxMessageBox(IDS_GROUP_DELETED);
  130. }
  131. else AfxMessageBox(IDS_GROUP_NOT_DELETED);
  132. }
  133. // set a new selection
  134. if (m_lbGroupList.GetCount() > 0)
  135. {
  136. if (sSel == 0) m_lbGroupList.SetCurSel(0);
  137. else m_lbGroupList.SetCurSel(sSel - 1);
  138. }
  139. else m_pApp->m_cps1.SetWizardButtons(PSWIZB_BACK);
  140. }
  141. int CExGrp::ClassifyGroup()
  142. {
  143. UpdateData(TRUE);
  144. if (m_pApp->m_csCmdLineGroupName == L"") return 0;
  145. unsigned short sCount = m_lbGroupList.GetCount();
  146. unsigned short sCount2 = 0;
  147. while (sCount2 < sCount)
  148. {
  149. if (m_lbGroupList.GetGroupName(sCount2) == m_pApp->m_csCmdLineGroupName)
  150. return m_lbGroupList.GetSelType(sCount2);
  151. sCount2++;
  152. }
  153. return 0;
  154. }
  155. LRESULT CExGrp::OnWizardBack()
  156. {
  157. return IDD_LR_DIALOG;
  158. }
  159. void CExGrp::OnShowWindow(BOOL bShow, UINT nStatus)
  160. {
  161. CPropertyPage::OnShowWindow(bShow, nStatus);
  162. CWaitCursor wait;
  163. if (bShow)
  164. {
  165. // start fresh each time
  166. m_lbGroupList.ResetContent();
  167. DWORD dwEntriesRead;
  168. DWORD dwTotalEntries;
  169. DWORD dwResumeHandle = 0;
  170. TCHAR* pServer = m_pApp->m_csServer.GetBuffer(m_pApp->m_csServer.GetLength());
  171. m_pApp->m_csServer.ReleaseBuffer();
  172. PLOCALGROUP_INFO_1 pInfo;
  173. NET_API_STATUS nApi = NetLocalGroupEnum(pServer, (DWORD)1,
  174. (PBYTE*)&pInfo, (DWORD)5000, &dwEntriesRead,
  175. &dwTotalEntries, &dwResumeHandle);
  176. unsigned long sIndex;
  177. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  178. {
  179. wchar_t sTemp[150];
  180. swprintf(sTemp, TEXT("%s;%s"), pInfo[sIndex].lgrpi1_name, pInfo[sIndex].lgrpi1_comment);
  181. m_lbGroupList.AddString(3, sTemp);
  182. }
  183. NetApiBufferFree(pInfo);
  184. while (dwResumeHandle != 0)
  185. {
  186. nApi = NetLocalGroupEnum(pServer, (DWORD)1,
  187. (PBYTE*)&pInfo, (DWORD)5000, &dwEntriesRead,
  188. &dwTotalEntries, &dwResumeHandle);
  189. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  190. {
  191. wchar_t sTemp[150];
  192. swprintf(sTemp, TEXT("%s;%s"), pInfo[sIndex].lgrpi1_name, pInfo[sIndex].lgrpi1_comment);
  193. m_lbGroupList.AddString(3, sTemp);
  194. }
  195. NetApiBufferFree(pInfo);
  196. }
  197. if (m_pApp->m_bDomain)
  198. {
  199. PGROUP_INFO_1 pGInfo1;
  200. nApi = NetGroupEnum(pServer, (DWORD)1,
  201. (PBYTE*)&pGInfo1, (DWORD)5000, &dwEntriesRead,
  202. &dwTotalEntries, &dwResumeHandle);
  203. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  204. {
  205. wchar_t sTemp[150];
  206. swprintf(sTemp, TEXT("%s;%s"), pGInfo1[sIndex].grpi1_name, pGInfo1[sIndex].grpi1_comment);
  207. m_lbGroupList.AddString(1, sTemp);
  208. }
  209. NetApiBufferFree(pGInfo1);
  210. while (dwResumeHandle != 0)
  211. {
  212. nApi = NetGroupEnum(pServer, (DWORD)1,
  213. (PBYTE*)&pGInfo1, (DWORD)5000, &dwEntriesRead,
  214. &dwTotalEntries, &dwResumeHandle);
  215. for (sIndex = 0; sIndex < dwEntriesRead; sIndex++)
  216. {
  217. wchar_t sTemp[150];
  218. swprintf(sTemp, TEXT("%s;%s"), pGInfo1[sIndex].grpi1_name, pGInfo1[sIndex].grpi1_comment);
  219. m_lbGroupList.AddString(1, sTemp);
  220. }
  221. NetApiBufferFree(pGInfo1);
  222. }
  223. }
  224. m_lbGroupList.SetCurSel(0);
  225. if (m_pApp->m_csCmdLine != L"") m_pApp->m_cps1.SetWizardButtons(PSWIZB_NEXT);
  226. else m_pApp->m_cps1.SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  227. }
  228. else m_pApp->m_cps1.SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  229. }
  230. void CExGrp::OnDblclkGroupList()
  231. {
  232. UpdateData(TRUE);
  233. USHORT sSel = m_lbGroupList.GetCurSel();
  234. m_pApp->m_csGroupName = m_lbGroupList.GetGroupName(sSel);
  235. int sSelType = m_lbGroupList.GetSelType(sSel);
  236. if (sSelType == 1)
  237. {
  238. m_pApp->m_nGroupType = 0;
  239. m_pApp->m_cps1.SetActivePage(7); // global group
  240. }
  241. else
  242. {
  243. m_pApp->m_nGroupType = 1;
  244. m_pApp->m_cps1.SetActivePage(6); // local Group
  245. }
  246. }