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.

1182 lines
35 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: result.cpp
  7. //
  8. // Contents: implementation of the result pane
  9. //
  10. // Classes: CResultPane
  11. //
  12. // History: 03-17-1998 stevebl Created
  13. // 07-16-1998 rahulth added calls to IGPEInformation::PolicyChanged()
  14. //
  15. //---------------------------------------------------------------------------
  16. #include "precomp.hxx"
  17. #include <shlobj.h>
  18. #include <atlimpl.cpp>
  19. #include <wbemcli.h>
  20. #include "rsoputil.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. const int HeaderWidths [] =
  27. {
  28. 200, //name
  29. 60, //size
  30. 100, //type
  31. 100 //modified date
  32. };
  33. const int RSOPHeaderWidths [] =
  34. {
  35. 150, // precedence
  36. 200, // redirected path
  37. 100, // group
  38. 75, // setting
  39. 100, // gpo
  40. 60, // exclusive
  41. 50, // move
  42. 150 // policy removal
  43. };
  44. long CResultPane::lDataObjectRefCount = 0;
  45. // Internal private format
  46. const wchar_t* SNAPIN_INTERNAL = L"FDE_INTERNAL";
  47. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  48. //+--------------------------------------------------------------------------
  49. //
  50. // Function: ExtractInternalFormat
  51. //
  52. // Synopsis: Returns a pointer to our private object format given an
  53. // LPDATAOBJECT
  54. //
  55. // Arguments: [lpDataObject] - pointer to a DATAOBJECT, generally from a
  56. // MMC call.
  57. //
  58. // Returns: A pointer to INTERNAL, our internal object structure.
  59. // NULL - if the object doesn't contain one of our objects
  60. // (wasn't created by us)
  61. //
  62. // History: 3-13-1998 stevebl Commented
  63. //
  64. //---------------------------------------------------------------------------
  65. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject)
  66. {
  67. INTERNAL* internal = NULL;
  68. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  69. FORMATETC formatetc = { (CLIPFORMAT)CDataObject::m_cfInternal, NULL,
  70. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  71. };
  72. if (!lpDataObject)
  73. return NULL;
  74. // Allocate memory for the stream
  75. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, sizeof(INTERNAL));
  76. // Attempt to get data from the object
  77. do
  78. {
  79. if (stgmedium.hGlobal == NULL)
  80. break;
  81. if (FAILED(lpDataObject->GetDataHere(&formatetc, &stgmedium)))
  82. break;
  83. internal = reinterpret_cast<INTERNAL*>(stgmedium.hGlobal);
  84. if (internal == NULL)
  85. break;
  86. } while (FALSE);
  87. return internal;
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CResultPane's IComponent implementation
  91. STDMETHODIMP CResultPane::GetResultViewType(MMC_COOKIE cookie, BSTR* ppViewType, LONG * pViewOptions)
  92. {
  93. // Use default view
  94. return S_FALSE;
  95. }
  96. STDMETHODIMP CResultPane::Initialize(LPCONSOLE lpConsole)
  97. {
  98. ASSERT(lpConsole != NULL);
  99. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  100. // Save the IConsole pointer
  101. m_pConsole = lpConsole;
  102. m_pConsole->AddRef();
  103. // Load resource strings
  104. LoadResources();
  105. // QI for a IHeaderCtrl
  106. HRESULT hr = m_pConsole->QueryInterface(IID_IHeaderCtrl,
  107. reinterpret_cast<void**>(&m_pHeader));
  108. // Give the console the header control interface pointer
  109. if (SUCCEEDED(hr))
  110. m_pConsole->SetHeader(m_pHeader);
  111. m_pConsole->QueryInterface(IID_IResultData,
  112. reinterpret_cast<void**>(&m_pResult));
  113. hr = m_pConsole->QueryConsoleVerb(&m_pConsoleVerb);
  114. ASSERT(hr == S_OK);
  115. return S_OK;
  116. }
  117. STDMETHODIMP CResultPane::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  118. {
  119. HRESULT hr = S_OK;
  120. MMC_COOKIE cookie;
  121. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  122. if (event == MMCN_PROPERTY_CHANGE)
  123. {
  124. hr = OnPropertyChange(param);
  125. }
  126. else if (event == MMCN_VIEW_CHANGE)
  127. {
  128. hr = OnUpdateView(lpDataObject);
  129. }
  130. else
  131. {
  132. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  133. if (pInternal == NULL)
  134. {
  135. cookie = 0;
  136. }
  137. else
  138. {
  139. cookie = pInternal->m_cookie;
  140. }
  141. switch(event)
  142. {
  143. case MMCN_ACTIVATE:
  144. hr = OnActivate(cookie, arg, param);
  145. break;
  146. case MMCN_CLICK:
  147. hr = OnResultItemClkOrDblClk(cookie, FALSE);
  148. break;
  149. case MMCN_DBLCLICK:
  150. if (pInternal && pInternal->m_type == CCT_RESULT)
  151. hr = OnResultItemClkOrDblClk(cookie, TRUE);
  152. else
  153. hr = S_FALSE;
  154. break;
  155. case MMCN_ADD_IMAGES:
  156. hr = OnAddImages(cookie, arg, param);
  157. break;
  158. case MMCN_SHOW:
  159. hr = OnShow (cookie, arg, param);
  160. break;
  161. case MMCN_MINIMIZED:
  162. hr = OnMinimize(cookie, arg, param);
  163. break;
  164. case MMCN_SELECT:
  165. if (pInternal)
  166. hr = OnSelect(pInternal->m_type, cookie, arg, param);
  167. else
  168. hr = S_FALSE;
  169. break;
  170. case MMCN_COLUMNS_CHANGED:
  171. // Let MMC do its default thing.
  172. hr = S_FALSE;
  173. break;
  174. case MMCN_COLUMN_CLICK:
  175. // retain column number and sort option flags so we can pass
  176. // them in to sort in the event we need to trigger a resort of
  177. // the result pane
  178. m_nSortColumn = arg;
  179. m_dwSortOptions = param;
  180. break;
  181. case MMCN_CONTEXTHELP:
  182. hr = OnContextHelp();
  183. break;
  184. // Note - Future expansion of notify types possible
  185. default:
  186. //perform the default action
  187. hr = S_FALSE;
  188. break;
  189. }
  190. if (pInternal)
  191. {
  192. FREE_INTERNAL(pInternal);
  193. }
  194. }
  195. return hr;
  196. }
  197. STDMETHODIMP CResultPane::Destroy(MMC_COOKIE cookie)
  198. {
  199. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  200. // Release the interfaces that we QI'ed
  201. if (m_pConsole != NULL)
  202. {
  203. // Tell the console to release the header control interface
  204. m_pConsole->SetHeader(NULL);
  205. SAFE_RELEASE(m_pHeader);
  206. SAFE_RELEASE(m_pResult);
  207. SAFE_RELEASE(m_pConsoleVerb);
  208. // Release the IConsole interface last
  209. SAFE_RELEASE(m_pConsole);
  210. if (m_pScopePane)
  211. {
  212. ((IComponentData*)m_pScopePane)->Release(); // QI'ed in IComponentDataImpl::CreateComponent
  213. }
  214. }
  215. return S_OK;
  216. }
  217. STDMETHODIMP CResultPane::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  218. LPDATAOBJECT* ppDataObject)
  219. {
  220. ASSERT(ppDataObject != NULL);
  221. CComObject<CDataObject>* pObject = NULL;
  222. CComObject<CDataObject>::CreateInstance(&pObject);
  223. ASSERT(pObject != NULL);
  224. if (!pObject)
  225. return E_UNEXPECTED;
  226. // Save cookie and type for delayed rendering
  227. pObject->SetType(type);
  228. pObject->SetCookie(cookie);
  229. return pObject->QueryInterface(IID_IDataObject,
  230. reinterpret_cast<void**>(ppDataObject));
  231. }
  232. /////////////////////////////////////////////////////////////////////////////
  233. // CResultPane's implementation specific members
  234. DEBUG_DECLARE_INSTANCE_COUNTER(CResultPane);
  235. CResultPane::CResultPane()
  236. {
  237. DEBUG_INCREMENT_INSTANCE_COUNTER(CResultPane);
  238. CResultPane::lDataObjectRefCount = 0;
  239. m_lViewMode = LVS_REPORT;
  240. m_nSortColumn = 0;
  241. m_dwSortOptions = 0;
  242. m_nIndex = 0;
  243. Construct();
  244. }
  245. CResultPane::~CResultPane()
  246. {
  247. #if DBG
  248. ASSERT(dbg_cRef == 0);
  249. #endif
  250. DEBUG_DECREMENT_INSTANCE_COUNTER(CResultPane);
  251. // Make sure the interfaces have been released
  252. ASSERT(m_pConsole == NULL);
  253. ASSERT(m_pHeader == NULL);
  254. Construct();
  255. ASSERT(CResultPane::lDataObjectRefCount == 0);
  256. }
  257. void CResultPane::Construct()
  258. {
  259. #if DBG
  260. dbg_cRef = 0;
  261. #endif
  262. m_pConsole = NULL;
  263. m_pHeader = NULL;
  264. m_pResult = NULL;
  265. m_pScopePane = NULL;
  266. m_hCurrScopeItem = -1;
  267. }
  268. void CResultPane::LoadResources()
  269. {
  270. // Load strings from resources
  271. int i, j;
  272. for (j = 0, i = IDS_FIRST_COL; i < IDS_LAST_COL; i++, j++)
  273. m_columns[j].LoadString(i);
  274. for (j = 0, i = IDS_FIRST_RSOP_COL; i < IDS_LAST_RSOP_COL; i++, j++)
  275. m_RSOP_columns[j].LoadString(i);
  276. m_szFolderTitle.LoadString(IDS_FOLDER_TITLE);
  277. }
  278. HRESULT CResultPane::InitializeHeaders(MMC_COOKIE cookie)
  279. {
  280. HRESULT hr = S_OK;
  281. int i;
  282. ASSERT(m_pHeader);
  283. // Put the correct headers depending on the cookie
  284. // Note - cookie ignored for this sample
  285. if (m_pScopePane->m_fRSOP && cookie != IDS_FOLDER_TITLE)
  286. {
  287. for (i = 0; i < RSOPCOLUMNID(IDS_LAST_RSOP_COL); i++)
  288. m_pHeader->InsertColumn(i, m_RSOP_columns[i], LVCFMT_LEFT, RSOPHeaderWidths[i]); //add the columns
  289. }
  290. else
  291. {
  292. for (i = 0; i < COLUMNID(IDS_LAST_COL); i++)
  293. m_pHeader->InsertColumn(i, m_columns[i], LVCFMT_LEFT, HeaderWidths[i]); //add the columns
  294. }
  295. return hr;
  296. }
  297. /////////////////////////////////////////////////////////////////////////////
  298. // IExtendContextMenu Implementation
  299. STDMETHODIMP CResultPane::AddMenuItems(LPDATAOBJECT pDataObject,
  300. LPCONTEXTMENUCALLBACK pContextMenuCallback, LONG * pInsertionAllowed)
  301. {
  302. //we do not have any special commands on the menu
  303. return S_OK;
  304. }
  305. STDMETHODIMP CResultPane::Command(long nCommandID, LPDATAOBJECT pDataObject)
  306. {
  307. //we do not have any special commands on the menu
  308. return S_OK;
  309. }
  310. HRESULT CResultPane::OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  311. {
  312. //
  313. // If any code ever gets added here, make sure that IDS_FOLDER_TITLE cookies
  314. // are handled correctly
  315. //
  316. if (arg == 0)
  317. {
  318. return E_INVALIDARG;
  319. }
  320. // add the images for the scope tree
  321. CBitmap bmp16x16;
  322. CBitmap bmp32x32;
  323. LPIMAGELIST lpScopeImage = (LPIMAGELIST)arg;
  324. // Load the bitmaps from the dll
  325. bmp16x16.LoadBitmap(IDB_16x16);
  326. bmp32x32.LoadBitmap(IDB_32x32);
  327. // Set the images
  328. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmp16x16)),
  329. reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmp32x32)),
  330. 0, RGB(255,0,255));
  331. return S_OK;
  332. }
  333. /////////////////////////////////////////////////////////////////////////////
  334. // IExtendPropertySheet Implementation
  335. // Result item property pages:
  336. STDMETHODIMP CResultPane::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  337. LONG_PTR handle,
  338. LPDATAOBJECT lpIDataObject)
  339. {
  340. if (!m_pScopePane->m_fRSOP)
  341. return S_FALSE;
  342. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  343. HRESULT hr = S_FALSE;
  344. INTERNAL* pInternal = ExtractInternalFormat(lpIDataObject);
  345. if (! pInternal)
  346. return S_FALSE;
  347. DWORD cookie = pInternal->m_cookie;
  348. LONG i;
  349. BOOL fShowPage = FALSE;
  350. AFX_OLDPROPSHEETPAGE * pPsp;
  351. CRSOPInfo * pRSOPInfo;
  352. //it is one of the folders
  353. pRSOPInfo = &(m_RSOPData[cookie]);
  354. if (!pRSOPInfo->m_pRsopProp) //make sure that the property page is not already up.
  355. {
  356. pRSOPInfo->m_pRsopProp = new CRsopProp;
  357. pRSOPInfo->m_pRsopProp->m_ppThis = &(pRSOPInfo->m_pRsopProp);
  358. pRSOPInfo->m_pRsopProp->m_pInfo = pRSOPInfo;
  359. pRSOPInfo->m_pRsopProp->m_szFolder = pRSOPInfo->m_pRsopProp->m_pInfo->m_szFolder;
  360. fShowPage = TRUE;
  361. pPsp = (AFX_OLDPROPSHEETPAGE *)&(pRSOPInfo->m_pRsopProp->m_psp);
  362. }
  363. if (fShowPage) //show page if it is not already up.
  364. {
  365. hr = SetPropPageToDeleteOnClose (pPsp);
  366. if (SUCCEEDED(hr))
  367. {
  368. HPROPSHEETPAGE hProp = CreateThemedPropertySheetPage(pPsp);
  369. if (NULL == hProp)
  370. hr = E_UNEXPECTED;
  371. else
  372. {
  373. lpProvider->AddPage(hProp);
  374. hr = S_OK;
  375. }
  376. }
  377. }
  378. FREE_INTERNAL(pInternal);
  379. return hr;
  380. }
  381. // Result items property pages:
  382. STDMETHODIMP CResultPane::QueryPagesFor(LPDATAOBJECT lpDataObject)
  383. {
  384. if (!m_pScopePane->m_fRSOP)
  385. return S_FALSE;
  386. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  387. if (! pInternal)
  388. return S_FALSE;
  389. MMC_COOKIE cookie = pInternal->m_cookie;
  390. HRESULT hr = S_FALSE;
  391. CError error;
  392. if (CCT_RESULT == pInternal->m_type)
  393. {
  394. hr = S_OK;
  395. }
  396. FREE_INTERNAL(pInternal);
  397. return hr;
  398. }
  399. STDMETHODIMP CResultPane::CompareObjects(LPDATAOBJECT lpDataObjectA,
  400. LPDATAOBJECT lpDataObjectB)
  401. {
  402. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  403. return E_POINTER;
  404. // Make sure both data object are mine
  405. INTERNAL* pA;
  406. INTERNAL* pB;
  407. HRESULT hr = S_FALSE;
  408. pA = ExtractInternalFormat(lpDataObjectA);
  409. pB = ExtractInternalFormat(lpDataObjectB);
  410. if (pA != NULL && pB != NULL)
  411. hr = ((pA->m_type == pB->m_type) && (pA->m_cookie == pB->m_cookie)) ? S_OK : S_FALSE;
  412. FREE_INTERNAL(pA);
  413. FREE_INTERNAL(pB);
  414. return hr;
  415. }
  416. STDMETHODIMP CResultPane::Compare(LPARAM lUserParam,
  417. MMC_COOKIE cookieA,
  418. MMC_COOKIE cookieB,
  419. int* pnResult)
  420. {
  421. if (pnResult == NULL)
  422. {
  423. ASSERT(FALSE);
  424. return E_POINTER;
  425. }
  426. // check col range
  427. int nCol = *pnResult;
  428. *pnResult = 0;
  429. // Retrieve the objects referred to by the two cookies and compare them
  430. // based upon the data that's associated with nCol. (The values you
  431. // compare depends on which column the caller asks for.)
  432. CString szA, szB;
  433. CRSOPInfo &dataA = m_RSOPData[cookieA];
  434. CRSOPInfo &dataB = m_RSOPData[cookieB];
  435. switch (nCol)
  436. {
  437. case 0: // precedence
  438. *pnResult = dataA.m_nPrecedence - dataB.m_nPrecedence;
  439. return S_OK;
  440. case 1: // redirected path
  441. szA = dataA.m_szPath;
  442. szB = dataB.m_szPath;
  443. break;
  444. case 2: // group
  445. szA = dataA.m_szGroup;
  446. szB = dataB.m_szGroup;
  447. break;
  448. case 3: // GPO
  449. szA = dataA.m_szGPO;
  450. szB = dataB.m_szGPO;
  451. break;
  452. case 4: // setting
  453. szA.LoadString(dataA.m_nInstallationType + IDS_SETTINGS);
  454. szB.LoadString(dataB.m_nInstallationType + IDS_SETTINGS);
  455. break;
  456. case 5: // exclusive
  457. szA.LoadString(dataA.m_fGrantType ? IDS_YES : IDS_NO);
  458. szB.LoadString(dataB.m_fGrantType ? IDS_YES : IDS_NO);
  459. break;
  460. case 6: // move
  461. szA.LoadString(dataA.m_fMoveType ? IDS_YES : IDS_NO);
  462. szB.LoadString(dataB.m_fMoveType ? IDS_YES : IDS_NO);
  463. break;
  464. case 7: // policy removal
  465. szA.LoadString(IDS_ONPOLICYREMOVAL + dataA.m_nPolicyRemoval);
  466. szB.LoadString(IDS_ONPOLICYREMOVAL + dataB.m_nPolicyRemoval);
  467. break;
  468. }
  469. *pnResult = szA.CompareNoCase(szB);
  470. return S_OK;
  471. }
  472. STDMETHODIMP CResultPane::GetDisplayInfo(LPRESULTDATAITEM pResult)
  473. {
  474. AFX_MANAGE_STATE (AfxGetStaticModuleState());
  475. static CString sz;
  476. CString szExt;
  477. ASSERT(pResult != NULL);
  478. ASSERT(pResult->bScopeItem);
  479. if (pResult)
  480. {
  481. if (pResult->bScopeItem)
  482. {
  483. switch (pResult->nCol)
  484. {
  485. case 0: //display name
  486. if (IDS_FOLDER_TITLE == pResult->lParam)
  487. sz.LoadString (IDS_FOLDER_TITLE);
  488. else
  489. sz = m_pScopePane->m_FolderData[GETINDEX(pResult->lParam)].m_szDisplayname;
  490. break;
  491. case 1: //type
  492. sz = m_pScopePane->m_FolderData[GETINDEX(pResult->lParam)].m_szTypename;
  493. break;
  494. default:
  495. sz = TEXT("");
  496. break;
  497. }
  498. }
  499. else
  500. {
  501. CRSOPInfo &data = m_RSOPData[pResult->lParam];
  502. switch (pResult->nCol)
  503. {
  504. case 0: // precedence
  505. sz.Format(TEXT("(%u) %s"), data.m_nPrecedence, data.m_szFolder);
  506. break;
  507. case 1: // redirected path
  508. sz = data.m_szPath;
  509. break;
  510. case 2: // group
  511. sz = data.m_szGroup;
  512. break;
  513. case 3: // GPO
  514. sz = data.m_szGPO;
  515. break;
  516. case 4: // setting
  517. sz.LoadString(data.m_nInstallationType + IDS_SETTINGS);
  518. break;
  519. case 5: // exclusive
  520. sz.LoadString(data.m_fGrantType ? IDS_YES : IDS_NO);
  521. break;
  522. case 6: // move
  523. sz.LoadString(data.m_fMoveType ? IDS_YES : IDS_NO);
  524. break;
  525. case 7: // policy removal
  526. sz.LoadString(IDS_ONPOLICYREMOVAL + data.m_nPolicyRemoval);
  527. break;
  528. default:
  529. sz = TEXT("");
  530. break;
  531. }
  532. }
  533. pResult->str = (unsigned short *)((LPCOLESTR)sz);
  534. }
  535. return S_OK;
  536. }
  537. HRESULT CResultPane::OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  538. {
  539. ASSERT(FALSE);
  540. return S_OK;
  541. }
  542. HRESULT CResultPane::TestForRSOPData(MMC_COOKIE cookie)
  543. {
  544. HRESULT hr = S_OK;
  545. ASSERT(m_pScopePane != NULL);
  546. // Test for RSOP data for this folder
  547. RESULTDATAITEM resultItem;
  548. memset(&resultItem, 0, sizeof(resultItem));
  549. resultItem.mask = RDI_STR | RDI_PARAM;
  550. resultItem.str = MMC_CALLBACK;
  551. IWbemLocator * pLocator = NULL;
  552. IWbemServices * pNamespace = NULL;
  553. IWbemClassObject * pObj = NULL;
  554. IEnumWbemClassObject * pEnum = NULL;
  555. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  556. CString szQuery = TEXT("SELECT * FROM RSOP_FolderRedirectionPolicySetting");
  557. if (cookie && (cookie != IDS_FOLDER_TITLE))
  558. {
  559. szQuery = TEXT("SELECT * FROM RSOP_FolderRedirectionPolicySetting where id = \"");
  560. szQuery += g_szEnglishNames[GETINDEX(cookie)];
  561. szQuery += TEXT("\"");
  562. }
  563. BSTR strQuery = SysAllocString(szQuery);
  564. BSTR strNamespace = SysAllocString(m_pScopePane->m_szRSOPNamespace);
  565. ULONG n = 0;
  566. hr = CoCreateInstance(CLSID_WbemLocator,
  567. 0,
  568. CLSCTX_INPROC_SERVER,
  569. IID_IWbemLocator,
  570. (LPVOID *) & pLocator);
  571. if (FAILED(hr))
  572. {
  573. goto cleanup;
  574. }
  575. hr = pLocator->ConnectServer(strNamespace,
  576. NULL,
  577. NULL,
  578. NULL,
  579. 0,
  580. NULL,
  581. NULL,
  582. &pNamespace);
  583. if (FAILED(hr))
  584. {
  585. goto cleanup;
  586. }
  587. // Set the proper security to encrypt the data
  588. hr = CoSetProxyBlanket(pNamespace,
  589. RPC_C_AUTHN_DEFAULT,
  590. RPC_C_AUTHZ_DEFAULT,
  591. COLE_DEFAULT_PRINCIPAL,
  592. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  593. RPC_C_IMP_LEVEL_IMPERSONATE,
  594. NULL,
  595. 0);
  596. if (FAILED(hr))
  597. {
  598. goto cleanup;
  599. }
  600. hr = pNamespace->ExecQuery(strQueryLanguage,
  601. strQuery,
  602. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  603. NULL,
  604. &pEnum);
  605. if (FAILED(hr))
  606. {
  607. goto cleanup;
  608. }
  609. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &n);
  610. if (FAILED(hr))
  611. {
  612. goto cleanup;
  613. }
  614. if (n == 0)
  615. {
  616. hr = E_FAIL;
  617. }
  618. cleanup:
  619. SysFreeString(strQueryLanguage);
  620. SysFreeString(strQuery);
  621. SysFreeString(strNamespace);
  622. if (pObj)
  623. {
  624. pObj->Release();
  625. }
  626. if (pEnum)
  627. {
  628. pEnum->Release();
  629. }
  630. if (pNamespace)
  631. {
  632. pNamespace->Release();
  633. }
  634. if (pLocator)
  635. {
  636. pLocator->Release();
  637. }
  638. m_pResult->Sort(m_nSortColumn, m_dwSortOptions, -1);
  639. return hr;
  640. }
  641. HRESULT CResultPane::OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  642. {
  643. HRESULT hr = S_OK;
  644. // Note - arg is TRUE when it is time to enumerate
  645. //
  646. // If we received the show notification for the top level FR node, then
  647. // return S_FALSE and let MMC do its thing. We really have nothing to show
  648. // in the result pane in this case.
  649. //
  650. if (IDS_FOLDER_TITLE == cookie)
  651. return S_FALSE;
  652. if (arg == TRUE)
  653. {
  654. // Show the headers for this nodetype
  655. ASSERT(m_pScopePane != NULL);
  656. m_pResult->SetViewMode(m_lViewMode);
  657. InitializeHeaders(cookie);
  658. m_hCurrScopeItem = m_pScopePane->m_FolderData[GETINDEX(cookie)].m_scopeID;
  659. if (m_pScopePane->m_fRSOP)
  660. {
  661. // Enumerate the RSOP data for this folder
  662. // and add a result item for each entry
  663. RESULTDATAITEM resultItem;
  664. memset(&resultItem, 0, sizeof(resultItem));
  665. resultItem.mask = RDI_STR | RDI_PARAM;
  666. resultItem.str = MMC_CALLBACK;
  667. IWbemLocator * pLocator = NULL;
  668. IWbemServices * pNamespace = NULL;
  669. IWbemClassObject * pObj = NULL;
  670. IEnumWbemClassObject * pEnum = NULL;
  671. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  672. CString szQuery = TEXT("SELECT * FROM RSOP_FolderRedirectionPolicySetting where name = \"");
  673. szQuery += g_szEnglishNames[GETINDEX(cookie)];
  674. szQuery += TEXT("\"");
  675. BSTR strQuery = SysAllocString(szQuery);
  676. BSTR strNamespace = SysAllocString(m_pScopePane->m_szRSOPNamespace);
  677. ULONG n = 0;
  678. hr = CoCreateInstance(CLSID_WbemLocator,
  679. 0,
  680. CLSCTX_INPROC_SERVER,
  681. IID_IWbemLocator,
  682. (LPVOID *) & pLocator);
  683. if (FAILED(hr))
  684. {
  685. goto cleanup;
  686. }
  687. hr = pLocator->ConnectServer(strNamespace,
  688. NULL,
  689. NULL,
  690. NULL,
  691. 0,
  692. NULL,
  693. NULL,
  694. &pNamespace);
  695. if (FAILED(hr))
  696. {
  697. goto cleanup;
  698. }
  699. // Set the proper security to encrypt the data
  700. hr = CoSetProxyBlanket(pNamespace,
  701. RPC_C_AUTHN_DEFAULT,
  702. RPC_C_AUTHZ_DEFAULT,
  703. COLE_DEFAULT_PRINCIPAL,
  704. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  705. RPC_C_IMP_LEVEL_IMPERSONATE,
  706. NULL,
  707. 0);
  708. if (FAILED(hr))
  709. {
  710. goto cleanup;
  711. }
  712. // First perform the query
  713. hr = pNamespace->ExecQuery(strQueryLanguage,
  714. strQuery,
  715. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  716. NULL,
  717. &pEnum);
  718. if (FAILED(hr))
  719. {
  720. goto cleanup;
  721. }
  722. do
  723. {
  724. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &n);
  725. if (FAILED(hr))
  726. {
  727. goto cleanup;
  728. }
  729. if (n > 0)
  730. {
  731. // process the data
  732. UINT nPrecedence;
  733. LPTSTR pszGPOName = NULL;
  734. CString szGPOID;
  735. UINT nGroups = 0;
  736. TCHAR * * rgszGroups = NULL;
  737. UINT nPaths = 0;
  738. TCHAR * * rgszPaths = NULL;
  739. BOOL fGrantType;
  740. BOOL fMoveType;
  741. UINT nPolicyRemoval;
  742. UINT nInstallationType;
  743. CString ResultantPath;
  744. CString RedirectingGroup;
  745. hr = GetParameter(pObj,
  746. TEXT("GPOID"),
  747. szGPOID);
  748. hr = GetGPOFriendlyName(pNamespace,
  749. (LPTSTR)((LPCTSTR) szGPOID),
  750. strQueryLanguage,
  751. &pszGPOName);
  752. hr = GetParameter(pObj,
  753. TEXT("Precedence"),
  754. nPrecedence);
  755. hr = GetParameter(pObj,
  756. TEXT("GrantType"),
  757. fGrantType);
  758. hr = GetParameter(pObj,
  759. TEXT("MoveType"),
  760. fMoveType);
  761. hr = GetParameter(pObj,
  762. TEXT("PolicyRemoval"),
  763. nPolicyRemoval);
  764. hr = GetParameter(pObj,
  765. TEXT("securityGroups"),
  766. nGroups,
  767. rgszGroups);
  768. hr = GetParameter(pObj,
  769. TEXT("RedirectedPaths"),
  770. nPaths,
  771. rgszPaths);
  772. hr = GetParameter(pObj,
  773. TEXT("installationType"),
  774. nInstallationType);
  775. hr = GetParameter(pObj,
  776. TEXT("resultantPath"),
  777. ResultantPath);
  778. hr = GetParameter(pObj,
  779. TEXT("redirectingGroup"),
  780. RedirectingGroup);
  781. if (nInstallationType != 2)
  782. {
  783. // force a valid value
  784. nInstallationType = 1;
  785. }
  786. if (nPaths != nGroups)
  787. {
  788. // If we don't have the same number of paths
  789. // as groups then we have a problem.
  790. hr = E_UNEXPECTED;
  791. }
  792. CString szDir;
  793. CString szAcct;
  794. CRSOPInfo & info = m_RSOPData[m_nIndex++];
  795. info.m_nPrecedence = nPrecedence;
  796. info.m_szPath = ResultantPath;
  797. if (STATUS_SUCCESS == GetFriendlyNameFromStringSid(
  798. RedirectingGroup,
  799. szDir,
  800. szAcct))
  801. {
  802. if (!szDir.IsEmpty())
  803. szAcct = szDir + '\\' + szAcct;
  804. }
  805. else //just display the unfriendly string if the friendly name cannot be obtained
  806. {
  807. szAcct = RedirectingGroup;
  808. szAcct.MakeUpper();
  809. }
  810. info.m_szGroup = szAcct;
  811. info.m_szGPO = pszGPOName;
  812. info.m_fGrantType = FALSE != fGrantType;
  813. info.m_fMoveType = FALSE != fMoveType;
  814. info.m_nPolicyRemoval = nPolicyRemoval;
  815. info.m_nInstallationType = nInstallationType;
  816. info.m_szFolder = m_pScopePane->m_FolderData[GETINDEX(cookie)].m_szDisplayname;
  817. resultItem.lParam = m_nIndex - 1;;
  818. m_pResult->InsertItem(&resultItem);
  819. // erase allocated data
  820. OLESAFE_DELETE(pszGPOName);
  821. while (nPaths--)
  822. {
  823. OLESAFE_DELETE(rgszPaths[nPaths]);
  824. }
  825. OLESAFE_DELETE(rgszPaths);
  826. while (nGroups--)
  827. {
  828. OLESAFE_DELETE(rgszGroups[nGroups]);
  829. }
  830. OLESAFE_DELETE(rgszGroups);
  831. }
  832. } while (n > 0);
  833. cleanup:
  834. SysFreeString(strQueryLanguage);
  835. SysFreeString(strQuery);
  836. SysFreeString(strNamespace);
  837. if (pObj)
  838. {
  839. pObj->Release();
  840. }
  841. if (pEnum)
  842. {
  843. pEnum->Release();
  844. }
  845. if (pNamespace)
  846. {
  847. pNamespace->Release();
  848. }
  849. if (pLocator)
  850. {
  851. pLocator->Release();
  852. }
  853. m_pResult->Sort(m_nSortColumn, m_dwSortOptions, -1);
  854. }
  855. }
  856. else
  857. {
  858. m_pResult->GetViewMode(&m_lViewMode);
  859. }
  860. return hr;
  861. }
  862. HRESULT CResultPane::OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  863. {
  864. //
  865. // If any code ever gets added here, make sure that IDS_FOLDER_TITLE cookies
  866. // are handled correctly
  867. //
  868. return S_OK;
  869. }
  870. HRESULT CResultPane::OnResultItemClkOrDblClk(MMC_COOKIE cookie, BOOL fDblClick)
  871. {
  872. //
  873. // If any code ever gets added here, make sure that IDS_FOLDER_TITLE cookies
  874. // are handled correctly
  875. //
  876. return S_FALSE;
  877. }
  878. HRESULT CResultPane::OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  879. {
  880. //
  881. // If any code ever gets added here, make sure that IDS_FOLDER_TITLE cookies
  882. // are handled correctly
  883. //
  884. return S_OK;
  885. }
  886. HRESULT CResultPane::OnSelect(DATA_OBJECT_TYPES type, MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  887. {
  888. if (m_pConsoleVerb)
  889. {
  890. if (m_pScopePane->m_fRSOP)
  891. {
  892. if (type == CCT_RESULT)
  893. {
  894. // Set the default verb to properties
  895. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  896. // Enable the properties verb.
  897. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, FALSE);
  898. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  899. }
  900. else
  901. {
  902. // Set the default verb to open
  903. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  904. // disable the properties verb
  905. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  906. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, FALSE);
  907. }
  908. }
  909. else
  910. {
  911. if (type == CCT_SCOPE)
  912. {
  913. // Set the default verb to open
  914. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  915. if (IDS_FOLDER_TITLE != cookie)
  916. {
  917. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, HIDDEN, FALSE);
  918. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  919. }
  920. else
  921. {
  922. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, HIDDEN, TRUE);
  923. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  924. }
  925. }
  926. }
  927. }
  928. return S_OK;
  929. }
  930. HRESULT CResultPane::OnPropertyChange(LPARAM param) // param is the cookie of the item that changed
  931. {
  932. HRESULT hr = S_OK;
  933. // UNDONE - Make any updates to internal structures or visual
  934. // representation that might be necessary.
  935. m_pResult->Sort(m_nSortColumn, m_dwSortOptions, -1);
  936. return hr;
  937. }
  938. HRESULT CResultPane::OnUpdateView(LPDATAOBJECT lpDataObject)
  939. {
  940. if (m_pScopePane->m_fRSOP)
  941. {
  942. return S_OK;
  943. }
  944. INTERNAL* pInternal = ExtractInternalFormat (lpDataObject);
  945. if (!pInternal)
  946. return E_UNEXPECTED;
  947. if (m_hCurrScopeItem == pInternal->m_scopeID)
  948. {
  949. //also update the folders
  950. m_pScopePane->m_pScope->DeleteItem (pInternal->m_scopeID, FALSE);
  951. m_pScopePane->EnumerateScopePane (pInternal->m_cookie, pInternal->m_scopeID);
  952. //reenumerate the scope pane
  953. m_pConsole->SelectScopeItem (pInternal->m_scopeID);
  954. }
  955. FREE_INTERNAL (pInternal);
  956. return S_OK;
  957. }
  958. HRESULT CResultPane::OnContextHelp(void)
  959. {
  960. LPOLESTR lpHelpTopic;
  961. LPCTSTR pszHelpTopic = L"gpedit.chm::/Folder.htm";
  962. ULONG ulNoBytes = sizeof(pszHelpTopic);
  963. ASSERT (m_pDisplayHelp);
  964. lpHelpTopic = (LPOLESTR) CoTaskMemAlloc (ulNoBytes);
  965. if (!lpHelpTopic)
  966. {
  967. DbgMsg((TEXT("CScopePane::OnContexHelp: Failed to allocate memory.")));
  968. return E_OUTOFMEMORY;
  969. }
  970. HRESULT hr;
  971. hr = StringCbCopy(lpHelpTopic, ulNoBytes, pszHelpTopic);
  972. ASSERT(SUCCEEDED(hr));
  973. return m_pScopePane->m_pDisplayHelp->ShowTopic (lpHelpTopic);
  974. }
  975. // This code is needed to ensure that property pages get cleaned up properly.
  976. // This ensures that when the property sheet is closed all my of property
  977. // pages that are associated with that property sheet will get deleted.
  978. LPFNPSPCALLBACK _MMCHookProp;
  979. UINT CALLBACK HookPropertySheetProp(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  980. {
  981. UINT i = _MMCHookProp(hwnd, uMsg, ppsp);
  982. switch (uMsg)
  983. {
  984. case PSPCB_RELEASE:
  985. delete (CPropertyPage *) ppsp->lParam;
  986. return TRUE;
  987. default:
  988. break;
  989. }
  990. return i;
  991. }
  992. LRESULT SetPropPageToDeleteOnClose(void * vpsp)
  993. {
  994. HRESULT hr = MMCPropPageCallback(vpsp);
  995. if (SUCCEEDED(hr))
  996. {
  997. if (vpsp == NULL)
  998. return E_POINTER;
  999. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE)vpsp;
  1000. if ((void*)psp->pfnCallback == (void*)HookPropertySheetProp)
  1001. return E_UNEXPECTED;
  1002. _MMCHookProp = psp->pfnCallback;
  1003. psp->pfnCallback = HookPropertySheetProp;
  1004. }
  1005. return hr;
  1006. }