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.

266 lines
8.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2000.
  5. //
  6. // File: prec.cpp
  7. //
  8. // Contents: precedence property pane (RSOP mode only)
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 02-16-2000 stevebl Created
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "precomp.hxx"
  18. #include <wbemcli.h>
  19. #include "rsoputil.h"
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CPrecedence property page
  22. IMPLEMENT_DYNCREATE(CPrecedence, CPropertyPage)
  23. CPrecedence::CPrecedence() : CPropertyPage(CPrecedence::IDD)
  24. {
  25. //{{AFX_DATA_INIT(CPrecedence)
  26. m_szTitle = _T("");
  27. //}}AFX_DATA_INIT
  28. m_hConsoleHandle = NULL;
  29. }
  30. CPrecedence::~CPrecedence()
  31. {
  32. *m_ppThis = NULL;
  33. }
  34. void CPrecedence::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPage::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CPrecedence)
  38. DDX_Control(pDX, IDC_LIST1, m_list);
  39. DDX_Text(pDX, IDC_TITLE, m_szTitle);
  40. //}}AFX_DATA_MAP
  41. }
  42. int CALLBACK ComparePrecedenceItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  43. {
  44. CListCtrl * pList = (CListCtrl *)lParamSort;
  45. DWORD dw1, dw2;
  46. return lParam1 - lParam2;
  47. }
  48. BEGIN_MESSAGE_MAP(CPrecedence, CPropertyPage)
  49. //{{AFX_MSG_MAP(CPrecedence)
  50. ON_WM_CONTEXTMENU()
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CPrecedence message handlers
  55. LRESULT CPrecedence::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  56. {
  57. // TODO: Add your specialized code here and/or call the base class
  58. switch (message )
  59. {
  60. case WM_HELP:
  61. StandardHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, IDD, TRUE);
  62. return 0;
  63. }
  64. return CPropertyPage::WindowProc(message, wParam, lParam);
  65. }
  66. BOOL CPrecedence::OnInitDialog()
  67. {
  68. CPropertyPage::OnInitDialog();
  69. // TODO: Add extra initialization here
  70. RECT rect;
  71. m_list.GetClientRect(&rect);
  72. // add columns to the precedence pane
  73. CString szTemp;
  74. szTemp.LoadString(IDS_PRECEDENCE_COL1);
  75. m_list.InsertColumn(0, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.125);
  76. szTemp.LoadString(IDS_PRECEDENCE_COL2);
  77. m_list.InsertColumn(1, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.29);
  78. szTemp.LoadString(IDS_PRECEDENCE_COL3);
  79. m_list.InsertColumn(2, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.29);
  80. szTemp.LoadString(IDS_PRECEDENCE_COL4);
  81. m_list.InsertColumn(3, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.29);
  82. int i = 0;
  83. HRESULT hr = S_OK;
  84. IWbemLocator * pLocator = NULL;
  85. IWbemServices * pNamespace = NULL;
  86. IWbemClassObject * pObj = NULL;
  87. IEnumWbemClassObject * pEnum = NULL;
  88. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  89. szTemp = TEXT("SELECT * FROM RSOP_ApplicationManagementPolicySetting WHERE Id=\"")
  90. + m_pData->m_szDeploymentGroupID + TEXT("\"");
  91. switch (m_iViewState)
  92. {
  93. case IDM_WINNER:
  94. szTemp += TEXT(" AND EntryType=1");
  95. break;
  96. case IDM_FAILED:
  97. szTemp += TEXT(" AND EntryType=4");
  98. break;
  99. case IDM_REMOVED:
  100. szTemp += TEXT(" AND EntryType=2");
  101. break;
  102. case IDM_ARP:
  103. szTemp += TEXT(" AND EntryType=3");
  104. break;
  105. }
  106. BSTR strQuery = SysAllocString(szTemp);
  107. BSTR strNamespace = SysAllocString(m_szRSOPNamespace);
  108. ULONG n = 0;
  109. hr = CoCreateInstance(CLSID_WbemLocator,
  110. 0,
  111. CLSCTX_INPROC_SERVER,
  112. IID_IWbemLocator,
  113. (LPVOID *) & pLocator);
  114. if (FAILED(hr))
  115. {
  116. goto cleanup;
  117. }
  118. hr = pLocator->ConnectServer(strNamespace,
  119. NULL,
  120. NULL,
  121. NULL,
  122. 0,
  123. NULL,
  124. NULL,
  125. &pNamespace);
  126. if (FAILED(hr))
  127. {
  128. goto cleanup;
  129. }
  130. // Set the proper security to encrypt the data
  131. hr = CoSetProxyBlanket(pNamespace,
  132. RPC_C_AUTHN_DEFAULT,
  133. RPC_C_AUTHZ_DEFAULT,
  134. COLE_DEFAULT_PRINCIPAL,
  135. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  136. RPC_C_IMP_LEVEL_IMPERSONATE,
  137. NULL,
  138. 0);
  139. if (FAILED(hr))
  140. {
  141. goto cleanup;
  142. }
  143. hr = pNamespace->ExecQuery(strQueryLanguage,
  144. strQuery,
  145. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  146. NULL,
  147. &pEnum);
  148. if (FAILED(hr))
  149. {
  150. goto cleanup;
  151. }
  152. do
  153. {
  154. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &n);
  155. if (FAILED(hr))
  156. {
  157. goto cleanup;
  158. }
  159. if (n > 0)
  160. {
  161. // prepare the data entry and populate all the fields
  162. CString szPackageName;
  163. CString szGPOID;
  164. CString szGPOName;
  165. CString szCreation;
  166. BSTR bstrCreation = NULL;
  167. ULONG ulPrecedence;
  168. hr = GetParameter(pObj,
  169. TEXT("precedence"),
  170. ulPrecedence);
  171. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameter(\"precedence\") failed with 0x%x"), hr));
  172. hr = GetParameter(pObj,
  173. TEXT("Name"),
  174. szPackageName);
  175. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameter(\"Name\") failed with 0x%x"), hr));
  176. hr = GetParameter(pObj,
  177. TEXT("GPOID"),
  178. szGPOID);
  179. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameter(\"GPOID\") failed with 0x%x"), hr));
  180. hr = GetParameterBSTR(pObj,
  181. TEXT("creationtime"),
  182. bstrCreation);
  183. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameterBSTR(\"creationtime\") failed with 0x%x"), hr));
  184. hr = CStringFromWBEMTime(szCreation, bstrCreation, TRUE);
  185. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: CStringFromWBEMTime failed with 0x%x"), hr));
  186. LPTSTR pszGPOName = NULL;
  187. hr = GetGPOFriendlyName(pNamespace,
  188. (LPTSTR)((LPCTSTR) szGPOID),
  189. strQueryLanguage,
  190. &pszGPOName);
  191. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetGPOFriendlyName failed with 0x%x"), hr));
  192. if (SUCCEEDED(hr))
  193. {
  194. szGPOName = pszGPOName;
  195. OLESAFE_DELETE(pszGPOName);
  196. }
  197. // insert the entry in the list
  198. CString szPrecedence;
  199. szPrecedence.Format(TEXT("%lu"), ulPrecedence);
  200. i = m_list.InsertItem(i, szPrecedence);
  201. m_list.SetItemText(i, 1, szPackageName);
  202. m_list.SetItemText(i, 2, szGPOName);
  203. m_list.SetItemText(i, 3, szCreation);
  204. m_list.SetItemData(i, ulPrecedence);
  205. ulPrecedence = m_list.GetItemData(i);
  206. i++;
  207. if (bstrCreation)
  208. {
  209. SysFreeString(bstrCreation);
  210. }
  211. }
  212. } while (n > 0);
  213. m_list.SortItems(ComparePrecedenceItems, (LPARAM)&m_list);
  214. cleanup:
  215. SysFreeString(strQuery);
  216. SysFreeString(strQueryLanguage);
  217. SysFreeString(strNamespace);
  218. if (pObj)
  219. {
  220. pObj->Release();
  221. }
  222. if (pEnum)
  223. {
  224. pEnum->Release();
  225. }
  226. if (pNamespace)
  227. {
  228. pNamespace->Release();
  229. }
  230. if (pLocator)
  231. {
  232. pLocator->Release();
  233. }
  234. return TRUE; // return TRUE unless you set the focus to a control
  235. // EXCEPTION: OCX Property Pages should return FALSE
  236. }
  237. void CPrecedence::OnContextMenu(CWnd* pWnd, CPoint point)
  238. {
  239. StandardContextMenu(pWnd->m_hWnd, IDD_PRECEDENCE, TRUE);
  240. }