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.

1100 lines
31 KiB

  1. #include "precomp.h"
  2. #include <comdef.h>
  3. #include "wbemcli.h"
  4. extern INT_PTR CALLBACK SaveDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  5. extern void ExportSettings();
  6. extern GUID g_guidRSoPSnapinExt;
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // //
  9. // CComponentData object implementation //
  10. // //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. CComponentData::CComponentData(BOOL bIsRSoP):
  13. m_bIsRSoP(bIsRSoP),
  14. m_pRSOPInformation(NULL),
  15. m_bstrRSoPNamespace(NULL)
  16. {
  17. m_cRef = 1;
  18. InterlockedIncrement(&g_cRefThisDll);
  19. m_hwndFrame = NULL;
  20. m_pScope = NULL;
  21. m_pConsole = NULL;
  22. m_hRoot = NULL;
  23. m_pGPTInformation = NULL;
  24. m_lpCookieList = NULL;
  25. m_hLock = INVALID_HANDLE_VALUE;
  26. }
  27. CComponentData::~CComponentData()
  28. {
  29. if (NULL != m_bstrRSoPNamespace)
  30. SysFreeString(m_bstrRSoPNamespace);
  31. DeleteCookieList(m_lpCookieList);
  32. if (m_pScope != NULL)
  33. {
  34. m_pScope->Release();
  35. }
  36. if (m_pConsole != NULL)
  37. {
  38. m_pConsole->Release();
  39. }
  40. if (m_pGPTInformation != NULL)
  41. {
  42. m_pGPTInformation->Release();
  43. }
  44. InterlockedDecrement(&g_cRefThisDll);
  45. }
  46. ///////////////////////////////////////////////////////////////////////////////
  47. // //
  48. // CComponentData object implementation (IUnknown) //
  49. // //
  50. ///////////////////////////////////////////////////////////////////////////////
  51. HRESULT CComponentData::QueryInterface (REFIID riid, void **ppv)
  52. {
  53. if (IsEqualIID(riid, IID_IComponentData) || IsEqualIID(riid, IID_IUnknown))
  54. {
  55. *ppv = (LPCOMPONENT)this;
  56. m_cRef++;
  57. return S_OK;
  58. }
  59. else if (IsEqualIID(riid, IID_IPersistStreamInit))
  60. {
  61. *ppv = (LPPERSISTSTREAMINIT)this;
  62. m_cRef++;
  63. return S_OK;
  64. }
  65. else if (IsEqualIID(riid, IID_IExtendContextMenu))
  66. {
  67. *ppv = (LPEXTENDCONTEXTMENU)this;
  68. m_cRef++;
  69. return S_OK;
  70. }
  71. else if (IsEqualIID(riid, IID_ISnapinHelp))
  72. {
  73. *ppv = (LPSNAPINHELP)this;
  74. m_cRef++;
  75. return S_OK;
  76. }
  77. else
  78. {
  79. *ppv = NULL;
  80. return E_NOINTERFACE;
  81. }
  82. }
  83. ULONG CComponentData::AddRef (void)
  84. {
  85. return ++m_cRef;
  86. }
  87. ULONG CComponentData::Release (void)
  88. {
  89. if (--m_cRef == 0) {
  90. delete this;
  91. return 0;
  92. }
  93. return m_cRef;
  94. }
  95. ///////////////////////////////////////////////////////////////////////////////
  96. // //
  97. // CComponentData object implementation (IComponentData) //
  98. // //
  99. ///////////////////////////////////////////////////////////////////////////////
  100. STDMETHODIMP CComponentData::Initialize(LPUNKNOWN pUnknown)
  101. {
  102. HRESULT hr;
  103. HBITMAP bmp16x16;
  104. HBITMAP bmp32x32;
  105. LPIMAGELIST lpScopeImage;
  106. //
  107. // QI for IConsoleNameSpace
  108. //
  109. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (LPVOID *)&m_pScope);
  110. if (FAILED(hr))
  111. return hr;
  112. //
  113. // QI for IConsole
  114. //
  115. hr = pUnknown->QueryInterface(IID_IConsole, (LPVOID *)&m_pConsole);
  116. if (FAILED(hr))
  117. {
  118. m_pScope->Release();
  119. m_pScope = NULL;
  120. return hr;
  121. }
  122. m_pConsole->GetMainWindow (&m_hwndFrame);
  123. //
  124. // Query for the scope imagelist interface
  125. //
  126. hr = m_pConsole->QueryScopeImageList(&lpScopeImage);
  127. if (FAILED(hr))
  128. {
  129. m_pScope->Release();
  130. m_pScope = NULL;
  131. m_pConsole->Release();
  132. m_pConsole=NULL;
  133. return hr;
  134. }
  135. // Load the bitmaps from the dll
  136. bmp16x16 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_IEAKSNAPINEXT_16));
  137. bmp32x32 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_IEAKSNAPINEXT_32));
  138. // Set the images
  139. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(bmp16x16),
  140. reinterpret_cast<LONG_PTR *>(bmp32x32),
  141. 0, RGB(255, 0, 255));
  142. lpScopeImage->Release();
  143. return S_OK;
  144. }
  145. STDMETHODIMP CComponentData::Destroy(VOID)
  146. {
  147. return S_OK;
  148. }
  149. STDMETHODIMP CComponentData::CreateComponent(LPCOMPONENT *ppComponent)
  150. {
  151. HRESULT hr;
  152. CSnapIn *pSnapIn;
  153. //
  154. // Initialize
  155. //
  156. *ppComponent = NULL;
  157. //
  158. // Create the snapin view
  159. //
  160. pSnapIn = new CSnapIn(this);
  161. if (pSnapIn == NULL)
  162. return E_OUTOFMEMORY;
  163. //
  164. // QI for IComponent
  165. //
  166. hr = pSnapIn->QueryInterface(IID_IComponent, (LPVOID *)ppComponent);
  167. pSnapIn->Release(); // release QI
  168. return hr;
  169. }
  170. STDMETHODIMP CComponentData::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  171. LPDATAOBJECT* ppDataObject)
  172. {
  173. HRESULT hr = E_NOINTERFACE;
  174. CDataObject *pDataObject;
  175. LPIEAKDATAOBJECT pIEAKDataObject;
  176. //
  177. // Create a new DataObject
  178. //
  179. pDataObject = new CDataObject(this); // ref == 1
  180. if (!pDataObject)
  181. return E_OUTOFMEMORY;
  182. //
  183. // QI for the private IEAKDataObject interface so we can set the cookie
  184. // and type information.
  185. //
  186. hr = pDataObject->QueryInterface(IID_IIEAKDataObject, (LPVOID *)&pIEAKDataObject);
  187. if (FAILED(hr))
  188. {
  189. pDataObject->Release();
  190. return (hr);
  191. }
  192. pIEAKDataObject->SetType(type);
  193. pIEAKDataObject->SetCookie(cookie);
  194. pIEAKDataObject->Release();
  195. //
  196. // QI for a normal IDataObject to return.
  197. //
  198. hr = pDataObject->QueryInterface(IID_IDataObject, (LPVOID *)ppDataObject);
  199. pDataObject->Release(); // release initial ref
  200. return hr;
  201. }
  202. STDMETHODIMP CComponentData::AddMenuItems(LPDATAOBJECT lpDataObject,
  203. LPCONTEXTMENUCALLBACK piCallback, long *pInsertionAllowed)
  204. {
  205. LPIEAKDATAOBJECT pIEAKDataObject;
  206. if (SUCCEEDED(lpDataObject->QueryInterface(IID_IIEAKDataObject,
  207. (LPVOID *)&pIEAKDataObject)))
  208. {
  209. HRESULT hr = S_OK;
  210. pIEAKDataObject->Release();
  211. // check insertion point so we don't insert ourselves twice in the result pane
  212. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  213. {
  214. TCHAR szMenuItem[128];
  215. TCHAR szDescription[256];
  216. CONTEXTMENUITEM item;
  217. LoadString(g_hInstance, IDS_CONTEXT_EXPORT, szMenuItem, ARRAYSIZE(szMenuItem));
  218. LoadString(g_hInstance, IDS_CONTEXT_EXPORT_DESC, szDescription, ARRAYSIZE(szDescription));
  219. item.strName = szMenuItem;
  220. item.strStatusBarText = szDescription;
  221. item.lCommandID = IDM_CONTEXTSAVE;
  222. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  223. item.fFlags = 0;
  224. item.fSpecialFlags = 0;
  225. hr = piCallback->AddItem(&item);
  226. // if in RSOP mode, these 2 menu choices aren't allowed
  227. if (!IsRSoP())
  228. {
  229. LoadString(g_hInstance, IDS_CONTEXT_ONCE, szMenuItem, ARRAYSIZE(szMenuItem));
  230. LoadString(g_hInstance, IDS_CONTEXT_ONCE_DESC, szDescription, ARRAYSIZE(szDescription));
  231. item.strName = szMenuItem;
  232. item.strStatusBarText = szDescription;
  233. item.lCommandID = IDM_CONTEXTONCE;
  234. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  235. m_fOneTimeApply = !InsIsKeyEmpty(IS_BRANDING, IK_GPE_ONETIME_GUID, m_szInsFile);
  236. item.fFlags = m_fOneTimeApply ? MF_CHECKED : MF_UNCHECKED;
  237. item.fSpecialFlags = 0;
  238. hr = piCallback->AddItem(&item);
  239. LoadString(g_hInstance, IDS_CONTEXT_RESET, szMenuItem, ARRAYSIZE(szMenuItem));
  240. LoadString(g_hInstance, IDS_CONTEXT_RESET_DESC, szDescription, ARRAYSIZE(szDescription));
  241. item.strName = szMenuItem;
  242. item.strStatusBarText = szDescription;
  243. item.lCommandID = IDM_CONTEXTRESET;
  244. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  245. item.fFlags = PathFileExists(m_szInsFile) ? MF_ENABLED : MF_GRAYED;
  246. item.fSpecialFlags = 0;
  247. hr = piCallback->AddItem(&item);
  248. }
  249. }
  250. return (hr);
  251. }
  252. return S_FALSE;
  253. }
  254. STDMETHODIMP CComponentData::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  255. {
  256. HRESULT hr = S_OK;
  257. switch(event)
  258. {
  259. case MMCN_EXPAND:
  260. if (TRUE == arg)
  261. {
  262. if (IsRSoP())
  263. {
  264. if (!m_pRSOPInformation)
  265. {
  266. //
  267. // Query for the IRSOPInformation interface
  268. //
  269. lpDataObject->QueryInterface(IID_IRSOPInformation, (LPVOID *)&m_pRSOPInformation);
  270. if (NULL != m_pRSOPInformation)
  271. {
  272. DWORD dwFlags;
  273. if(SUCCEEDED(m_pRSOPInformation->GetFlags(&dwFlags)))
  274. {
  275. m_bPlanningMode = (dwFlags != RSOP_INFO_FLAG_DIAGNOSTIC_MODE);
  276. }
  277. // 350 is a magic number - reason for the size?
  278. #define MAX_NAMESPACE_SIZE 350
  279. LPOLESTR szNamespace = (LPOLESTR) LocalAlloc (LPTR, MAX_NAMESPACE_SIZE * sizeof(TCHAR));
  280. if (NULL != szNamespace)
  281. {
  282. //
  283. // Retreive the namespace from the main snap-in
  284. //
  285. if (S_OK == m_pRSOPInformation->GetNamespace(GPO_SECTION_USER,
  286. szNamespace,
  287. MAX_NAMESPACE_SIZE))
  288. {
  289. m_bstrRSoPNamespace = SysAllocString(szNamespace);
  290. }
  291. }
  292. }
  293. }
  294. if (NULL != m_bstrRSoPNamespace)
  295. {
  296. hr = EnumerateScopePane(lpDataObject, (HSCOPEITEM)param);
  297. }
  298. }
  299. else
  300. {
  301. if (NULL == m_pGPTInformation)
  302. lpDataObject->QueryInterface(IID_IGPEInformation, (LPVOID *)&m_pGPTInformation);
  303. if (NULL != m_pGPTInformation)
  304. hr = EnumerateScopePane(lpDataObject, (HSCOPEITEM)param);
  305. }
  306. }
  307. break;
  308. case MMCN_REMOVE_CHILDREN:
  309. {
  310. //
  311. // In RSoP, we may get called to refresh the scope pane when the query
  312. // is re-executed -- if this happens, current nodes will be removed and
  313. // we must reset all of our cached information. We reset the relevant
  314. // information below
  315. //
  316. if (IsRSoP() && (m_pRSOPInformation != NULL) )
  317. {
  318. m_pRSOPInformation->Release();
  319. SysFreeString(m_bstrRSoPNamespace);
  320. m_hRoot = NULL;
  321. m_bstrRSoPNamespace = NULL;
  322. m_pRSOPInformation = NULL;
  323. }
  324. }
  325. break;
  326. default:
  327. break;
  328. }
  329. return hr;
  330. }
  331. HRESULT CComponentData::SetInsFile()
  332. {
  333. if (m_pGPTInformation != NULL)
  334. {
  335. m_pGPTInformation->GetFileSysPath(GPO_SECTION_USER, m_szInsFile, ARRAYSIZE(m_szInsFile));
  336. PathAppend(m_szInsFile, IEAK_SUBDIR);
  337. if (!PathFileExists(m_szInsFile))
  338. PathCreatePath(m_szInsFile);
  339. PathAppend(m_szInsFile, INS_NAME);
  340. }
  341. else
  342. {
  343. if (!IsRSoP())
  344. {
  345. ASSERT(FALSE);
  346. }
  347. }
  348. return S_OK;
  349. }
  350. STDMETHODIMP CComponentData::Command(long lCommandID, LPDATAOBJECT lpDataObject)
  351. {
  352. LPIEAKDATAOBJECT pIEAKDataObject;
  353. HANDLE hMutex;
  354. if (FAILED(lpDataObject->QueryInterface(IID_IIEAKDataObject,
  355. (LPVOID *)&pIEAKDataObject)))
  356. {
  357. return S_FALSE;
  358. }
  359. pIEAKDataObject->Release();
  360. // set the ins file
  361. SetInsFile();
  362. // read in our flag variables
  363. switch (lCommandID)
  364. {
  365. case IDM_CONTEXTSAVE:
  366. // allow only one save at a time
  367. hMutex = CreateMutex(NULL, TRUE, TEXT("IEAKGPEContextMenu.Mutex"));
  368. if ((hMutex != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS))
  369. {
  370. CloseHandle(hMutex);
  371. SIEErrorMessageBox(NULL, IDS_ERROR_CONTEXTMENU);
  372. }
  373. else
  374. {
  375. if ((lCommandID == IDM_CONTEXTSAVE) &&
  376. (DialogBoxParam(g_hUIInstance, MAKEINTRESOURCE(IDD_SAVEAS), NULL,
  377. SaveDlgProc, (LPARAM)m_szInsFile) == 0))
  378. {
  379. if (AcquireWriteCriticalSection(NULL, this, FALSE))
  380. {
  381. ExportSettings();
  382. ReleaseWriteCriticalSection(this, FALSE, FALSE);
  383. }
  384. }
  385. if (hMutex != NULL)
  386. CloseHandle(hMutex);
  387. }
  388. break;
  389. case IDM_CONTEXTONCE:
  390. if (PathFileExists(m_szInsFile))
  391. {
  392. SIEErrorMessageBox(NULL, IDS_ERROR_NEEDRESET);
  393. }
  394. else if (AcquireWriteCriticalSection(NULL, this, TRUE))
  395. {
  396. m_fOneTimeApply = !m_fOneTimeApply;
  397. if (!m_fOneTimeApply)
  398. {
  399. InsDeleteKey(IS_BRANDING, IK_GPE_ONETIME_GUID, m_szInsFile);
  400. m_pScope->DeleteItem(m_ahChildren[ADM_NAMESPACE_ITEM], TRUE);
  401. }
  402. else
  403. {
  404. TCHAR szGuid[128];
  405. GUID guid;
  406. SCOPEDATAITEM item;
  407. LPIEAKMMCCOOKIE lpCookie = (LPIEAKMMCCOOKIE)CoTaskMemAlloc(sizeof(IEAKMMCCOOKIE));
  408. lpCookie->lpItem = ULongToPtr(ADM_NAMESPACE_ITEM);
  409. lpCookie->lpParentItem = this;
  410. lpCookie->pNext = NULL;
  411. AddItemToCookieList(&(m_lpCookieList), lpCookie);
  412. item.mask = SDI_STR | SDI_STATE | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM | SDI_CHILDREN;
  413. item.displayname = MMC_CALLBACK;
  414. item.nImage = 6;
  415. item.nOpenImage = 6;
  416. item.nState = 0;
  417. item.cChildren = g_NameSpace[ADM_NAMESPACE_ITEM].cChildren;
  418. item.lParam = (LPARAM)lpCookie;
  419. item.relativeID = m_ahChildren[0];
  420. m_pScope->InsertItem(&item);
  421. m_ahChildren[ADM_NAMESPACE_ITEM] = item.ID;
  422. if (CoCreateGuid(&guid) == NOERROR)
  423. CoStringFromGUID(guid, szGuid, countof(szGuid));
  424. else
  425. szGuid[64] = TEXT('\0');
  426. InsWriteString(IS_BRANDING, IK_GPE_ONETIME_GUID, szGuid, m_szInsFile);
  427. }
  428. InsFlushChanges(m_szInsFile);
  429. ReleaseWriteCriticalSection(this, TRUE, FALSE);
  430. }
  431. break;
  432. case IDM_CONTEXTRESET:
  433. if ((SIEErrorMessageBox(NULL, IDS_RESET_WARN, MB_SETFOREGROUND | MB_YESNO) == IDYES) &&
  434. (AcquireWriteCriticalSection(NULL, this, TRUE)))
  435. {
  436. TCHAR szFilePath[MAX_PATH];
  437. LPTSTR pszFile;
  438. BOOL fPreferenceMode;
  439. // delete the advanced node if it's showing in preference mode
  440. fPreferenceMode = !InsIsKeyEmpty(IS_BRANDING, IK_GPE_ONETIME_GUID, m_szInsFile);
  441. if (fPreferenceMode)
  442. m_pScope->DeleteItem(m_ahChildren[ADM_NAMESPACE_ITEM], TRUE);
  443. StrCpy(szFilePath, m_szInsFile);
  444. DeleteFile(szFilePath);
  445. PathRemoveFileSpec(szFilePath);
  446. pszFile = PathAddBackslash(szFilePath);
  447. // we have the GPO path now, but we can't just do a delnode because we
  448. // have to leave the cookie file
  449. StrCpy(pszFile, IEAK_GPE_BRANDING_SUBDIR);
  450. PathRemovePath(szFilePath, ADN_DEL_UNC_PATHS);
  451. StrCpy(pszFile, IEAK_GPE_DESKTOP_SUBDIR);
  452. PathRemovePath(szFilePath, ADN_DEL_UNC_PATHS);
  453. ReleaseWriteCriticalSection(this, TRUE, !fPreferenceMode, FALSE, TRUE,
  454. &g_guidClientExt, IsRSoP() ? &g_guidRSoPSnapinExt : &g_guidSnapinExt);
  455. }
  456. break;
  457. default:
  458. return E_INVALIDARG;
  459. }
  460. return S_OK;
  461. }
  462. STDMETHODIMP CComponentData::GetDisplayInfo(LPSCOPEDATAITEM pItem)
  463. {
  464. DWORD dwIndex;
  465. if (pItem == NULL)
  466. return E_POINTER;
  467. dwIndex = PtrToUlong(((LPIEAKMMCCOOKIE)pItem->lParam)->lpItem);
  468. if (dwIndex >= NUM_NAMESPACE_ITEMS)
  469. pItem->displayname = NULL;
  470. else
  471. CreateBufandLoadString(g_hInstance, g_NameSpace[dwIndex].iNameID,
  472. &g_NameSpace[dwIndex].pszName, &pItem->displayname, MAX_DISPLAYNAME_SIZE);
  473. return S_OK;
  474. }
  475. STDMETHODIMP CComponentData::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  476. {
  477. HRESULT hr = S_FALSE;
  478. LPIEAKDATAOBJECT pIEAKDataObjectA, pIEAKDataObjectB;
  479. MMC_COOKIE cookie1, cookie2;
  480. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  481. return E_POINTER;
  482. //
  483. // QI for the private IEAKDataObject interface
  484. //
  485. if (FAILED(lpDataObjectA->QueryInterface(IID_IIEAKDataObject,
  486. (LPVOID *)&pIEAKDataObjectA)))
  487. {
  488. return S_FALSE;
  489. }
  490. if (FAILED(lpDataObjectB->QueryInterface(IID_IIEAKDataObject,
  491. (LPVOID *)&pIEAKDataObjectB)))
  492. {
  493. pIEAKDataObjectA->Release();
  494. return S_FALSE;
  495. }
  496. pIEAKDataObjectA->GetCookie(&cookie1);
  497. pIEAKDataObjectB->GetCookie(&cookie2);
  498. if (cookie1 == cookie2)
  499. hr = S_OK;
  500. else
  501. {
  502. LPIEAKMMCCOOKIE lpCookie1 = (LPIEAKMMCCOOKIE)cookie1;
  503. LPIEAKMMCCOOKIE lpCookie2 = (LPIEAKMMCCOOKIE)cookie2;
  504. if ((lpCookie1->lpItem == lpCookie2->lpItem)&&
  505. (lpCookie1->lpParentItem == lpCookie2->lpParentItem))
  506. hr = S_OK;
  507. }
  508. pIEAKDataObjectA->Release();
  509. pIEAKDataObjectB->Release();
  510. return hr;
  511. }
  512. ///////////////////////////////////////////////////////////////////////////////
  513. // //
  514. // CComponentData object implementation (IPersistStreamInit) //
  515. // //
  516. ///////////////////////////////////////////////////////////////////////////////
  517. STDMETHODIMP CComponentData::GetClassID(CLSID *pClassID)
  518. {
  519. if (!pClassID)
  520. {
  521. return E_FAIL;
  522. }
  523. if (IsRSoP())
  524. *pClassID = CLSID_IEAKRSoPSnapinExt;
  525. else
  526. *pClassID = CLSID_IEAKSnapinExt;
  527. return S_OK;
  528. }
  529. STDMETHODIMP CComponentData::IsDirty(VOID)
  530. {
  531. return S_FALSE;
  532. }
  533. STDMETHODIMP CComponentData::Load(IStream *pStm)
  534. {
  535. UNREFERENCED_PARAMETER(pStm);
  536. return S_OK;
  537. }
  538. STDMETHODIMP CComponentData::Save(IStream *pStm, BOOL fClearDirty)
  539. {
  540. UNREFERENCED_PARAMETER(pStm);
  541. UNREFERENCED_PARAMETER(fClearDirty);
  542. return S_OK;
  543. }
  544. STDMETHODIMP CComponentData::GetSizeMax(ULARGE_INTEGER *pcbSize)
  545. {
  546. DWORD dwSize = 0;
  547. if (pcbSize == NULL)
  548. {
  549. return E_FAIL;
  550. }
  551. ULISet32(*pcbSize, dwSize);
  552. return S_OK;
  553. }
  554. STDMETHODIMP CComponentData::InitNew(void)
  555. {
  556. return S_OK;
  557. }
  558. ///////////////////////////////////////////////////////////////////////////////
  559. // //
  560. // CComponentData object implementation (ISnapinHelp) //
  561. // //
  562. ///////////////////////////////////////////////////////////////////////////////
  563. STDMETHODIMP CComponentData::GetHelpTopic(LPOLESTR *lpCompiledHelpFile)
  564. {
  565. static TCHAR s_szHelpPath[MAX_PATH] = TEXT("");
  566. USES_CONVERSION;
  567. if (lpCompiledHelpFile == NULL)
  568. return E_POINTER;
  569. if (ISNULL(s_szHelpPath))
  570. {
  571. if (0 == GetWindowsDirectory(s_szHelpPath, countof(s_szHelpPath)))
  572. return E_UNEXPECTED;
  573. PathAppend(s_szHelpPath, TEXT("Help\\") HELP_FILENAME);
  574. ASSERT(PathFileExists(s_szHelpPath));
  575. }
  576. if ((*lpCompiledHelpFile = (LPOLESTR)CoTaskMemAlloc((StrLen(s_szHelpPath)+1) * sizeof(WCHAR))) == NULL)
  577. return E_OUTOFMEMORY;
  578. StrCpyW(*lpCompiledHelpFile, T2OLE(s_szHelpPath));
  579. return S_OK;
  580. }
  581. ///////////////////////////////////////////////////////////////////////////////
  582. // //
  583. // CComponentData object implementation (Internal functions) //
  584. // //
  585. ///////////////////////////////////////////////////////////////////////////////
  586. HRESULT CComponentData::EnumerateScopePane (LPDATAOBJECT lpDataObject, HSCOPEITEM hParent)
  587. {
  588. SCOPEDATAITEM item;
  589. HRESULT hr;
  590. DWORD dwIndex, i;
  591. BOOL fShowAdv = FALSE;
  592. UNREFERENCED_PARAMETER(lpDataObject);
  593. if (m_hRoot == NULL)
  594. m_hRoot = hParent;
  595. if (m_hRoot == hParent)
  596. {
  597. LPIEAKMMCCOOKIE lpCookie = (LPIEAKMMCCOOKIE)CoTaskMemAlloc(sizeof(IEAKMMCCOOKIE));
  598. lpCookie->lpItem = 0;
  599. lpCookie->lpParentItem = this;
  600. lpCookie->pNext = NULL;
  601. AddItemToCookieList(&m_lpCookieList, lpCookie);
  602. item.mask = SDI_STR | SDI_STATE | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM | SDI_CHILDREN;
  603. item.displayname = MMC_CALLBACK;
  604. item.nImage = 0;
  605. item.nOpenImage = 0;
  606. item.nState = 0;
  607. item.cChildren = g_NameSpace[0].cChildren;
  608. item.lParam = (LPARAM)lpCookie;
  609. item.relativeID = hParent;
  610. m_pScope->InsertItem (&item);
  611. m_ahChildren[0] = item.ID;
  612. return S_OK;
  613. }
  614. else
  615. {
  616. item.mask = SDI_PARAM;
  617. item.ID = hParent;
  618. hr = m_pScope->GetItem (&item);
  619. if (FAILED(hr))
  620. return hr;
  621. dwIndex = PtrToUlong(((LPIEAKMMCCOOKIE)item.lParam)->lpItem);
  622. }
  623. if (m_pGPTInformation != NULL)
  624. {
  625. TCHAR szInsFile[MAX_PATH];
  626. m_pGPTInformation->GetFileSysPath(GPO_SECTION_USER, szInsFile, ARRAYSIZE(szInsFile));
  627. PathAppend(szInsFile, IEAK_SUBDIR TEXT("\\") INS_NAME);
  628. fShowAdv = !InsIsKeyEmpty(IS_BRANDING, IK_GPE_ONETIME_GUID, szInsFile);
  629. }
  630. else if (m_bIsRSoP)
  631. {
  632. if (g_NameSpace[1].dwParent == dwIndex)
  633. fShowAdv = IsRSoPViewInPreferenceMode();
  634. }
  635. // start with 1 so we don't reinsert the top level root node
  636. for (i = 1; i < NUM_NAMESPACE_ITEMS; i++)
  637. {
  638. if ((g_NameSpace[i].dwParent == dwIndex) &&
  639. (fShowAdv || (i != ADM_NAMESPACE_ITEM)))
  640. {
  641. LPIEAKMMCCOOKIE lpCookie = (LPIEAKMMCCOOKIE)CoTaskMemAlloc(sizeof(IEAKMMCCOOKIE));
  642. lpCookie->lpItem = ULongToPtr(i);
  643. lpCookie->lpParentItem = this;
  644. lpCookie->pNext = NULL;
  645. AddItemToCookieList(&m_lpCookieList, lpCookie);
  646. item.mask = SDI_STR | SDI_STATE | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM | SDI_CHILDREN;
  647. item.displayname = MMC_CALLBACK;
  648. item.nImage = i;
  649. item.nOpenImage = i;
  650. item.nState = 0;
  651. item.cChildren = g_NameSpace[i].cChildren;
  652. item.lParam = (LPARAM)lpCookie;
  653. item.relativeID = hParent;
  654. m_pScope->InsertItem (&item);
  655. m_ahChildren[i] = item.ID;
  656. }
  657. }
  658. return S_OK;
  659. }
  660. HANDLE CComponentData::GetLockHandle()
  661. {
  662. return m_hLock;
  663. }
  664. HRESULT CComponentData::SetLockHandle(HANDLE hLock)
  665. {
  666. m_hLock = hLock;
  667. return S_OK;
  668. }
  669. HRESULT CComponentData::SignalPolicyChanged(BOOL bMachine, BOOL bAdd, GUID *pGuidExtension,
  670. GUID *pGuidSnapin)
  671. {
  672. return m_pGPTInformation->PolicyChanged(bMachine, bAdd, pGuidExtension, pGuidSnapin);
  673. }
  674. ///////////////////////////////////////////////////////////////////////////////
  675. BOOL CComponentData::IsRSoPViewInPreferenceMode()
  676. {
  677. BOOL bRet = FALSE;
  678. __try
  679. {
  680. ASSERT(m_bIsRSoP);
  681. if (NULL != m_bstrRSoPNamespace)
  682. {
  683. HRESULT hr = NOERROR;
  684. ComPtr<IWbemServices> pWbemServices = NULL;
  685. // Connect to the namespace using the locator's
  686. // ConnectServer method
  687. ComPtr<IWbemLocator> pIWbemLocator = NULL;
  688. if (CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER,
  689. IID_IWbemLocator, (LPVOID *) &pIWbemLocator) == S_OK)
  690. {
  691. hr = pIWbemLocator->ConnectServer(m_bstrRSoPNamespace, NULL, NULL,
  692. 0L, 0L, NULL, NULL,
  693. &pWbemServices);
  694. if (SUCCEEDED(hr))
  695. {
  696. }
  697. else
  698. {
  699. ASSERT(0);
  700. }
  701. pIWbemLocator = NULL;
  702. }
  703. else
  704. {
  705. ASSERT(0);
  706. }
  707. // If any RSOP_IEAKPolicySetting instance is in preference mode, stop and
  708. // return TRUE;
  709. if (NULL != pWbemServices)
  710. {
  711. _bstr_t bstrClass = L"RSOP_IEAKPolicySetting";
  712. ComPtr<IEnumWbemClassObject> pObjEnum = NULL;
  713. hr = pWbemServices->CreateInstanceEnum(bstrClass,
  714. WBEM_FLAG_FORWARD_ONLY,
  715. NULL, &pObjEnum);
  716. if (SUCCEEDED(hr))
  717. {
  718. // Final Next wil return WBEM_S_FALSE
  719. while (WBEM_S_NO_ERROR == hr)
  720. {
  721. // There should only be one object returned from this query.
  722. ULONG uReturned = (ULONG)-1L;
  723. ComPtr<IWbemClassObject> pPSObj = NULL;
  724. hr = pObjEnum->Next(10000L, 1, &pPSObj, &uReturned);
  725. if (SUCCEEDED(hr) && 1 == uReturned)
  726. {
  727. _variant_t vtPrecMode;
  728. hr = pPSObj->Get(L"preferenceMode", 0, &vtPrecMode, NULL, NULL);
  729. if (SUCCEEDED(hr) && VT_BOOL == vtPrecMode.vt)
  730. {
  731. if ((bool)vtPrecMode)
  732. {
  733. bRet = TRUE;
  734. break;
  735. }
  736. }
  737. }
  738. }
  739. }
  740. }
  741. }
  742. }
  743. __except(TRUE)
  744. {
  745. }
  746. return bRet;
  747. }
  748. ///////////////////////////////////////////////////////////////////////////////
  749. // //
  750. // Class factory object implementation //
  751. // //
  752. ///////////////////////////////////////////////////////////////////////////////
  753. CComponentDataCF::CComponentDataCF(BOOL bIsRSoP):
  754. m_bIsRSoP(bIsRSoP)
  755. {
  756. m_cRef = 1;
  757. InterlockedIncrement(&g_cRefThisDll);
  758. }
  759. CComponentDataCF::~CComponentDataCF()
  760. {
  761. InterlockedDecrement(&g_cRefThisDll);
  762. }
  763. ///////////////////////////////////////////////////////////////////////////////
  764. // //
  765. // Class factory object implementation (IUnknown) //
  766. // //
  767. ///////////////////////////////////////////////////////////////////////////////
  768. STDMETHODIMP_(ULONG)
  769. CComponentDataCF::AddRef()
  770. {
  771. return ++m_cRef;
  772. }
  773. STDMETHODIMP_(ULONG)
  774. CComponentDataCF::Release()
  775. {
  776. if (--m_cRef == 0)
  777. {
  778. delete this;
  779. return 0;
  780. }
  781. return m_cRef;
  782. }
  783. STDMETHODIMP
  784. CComponentDataCF::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  785. {
  786. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  787. {
  788. *ppv = (LPCLASSFACTORY)this;
  789. m_cRef++;
  790. return S_OK;
  791. }
  792. else
  793. {
  794. *ppv = NULL;
  795. return E_NOINTERFACE;
  796. }
  797. }
  798. ///////////////////////////////////////////////////////////////////////////////
  799. // //
  800. // Class factory object implementation (IClassFactory) //
  801. // //
  802. ///////////////////////////////////////////////////////////////////////////////
  803. STDMETHODIMP
  804. CComponentDataCF::CreateInstance(LPUNKNOWN pUnkOuter,
  805. REFIID riid,
  806. LPVOID FAR* ppvObj)
  807. {
  808. *ppvObj = NULL;
  809. if (pUnkOuter)
  810. return CLASS_E_NOAGGREGATION;
  811. CComponentData *pComponentData = new CComponentData(m_bIsRSoP); // ref count == 1
  812. if (!pComponentData)
  813. return E_OUTOFMEMORY;
  814. HRESULT hr = pComponentData->QueryInterface(riid, ppvObj);
  815. pComponentData->Release(); // release initial ref
  816. return hr;
  817. }
  818. STDMETHODIMP
  819. CComponentDataCF::LockServer(BOOL fLock)
  820. {
  821. UNREFERENCED_PARAMETER(fLock);
  822. return E_NOTIMPL;
  823. }
  824. ///////////////////////////////////////////////////////////////////////////////
  825. // //
  826. // Class factory object creation (IClassFactory) //
  827. // //
  828. ///////////////////////////////////////////////////////////////////////////////
  829. HRESULT CreateComponentDataClassFactory (REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  830. {
  831. HRESULT hr;
  832. if (IsEqualCLSID (rclsid, CLSID_IEAKSnapinExt))
  833. {
  834. CComponentDataCF *pComponentDataCF = new CComponentDataCF(FALSE); // ref == 1
  835. if (pComponentDataCF == NULL)
  836. return E_OUTOFMEMORY;
  837. hr = pComponentDataCF->QueryInterface(riid, ppv);
  838. pComponentDataCF->Release(); // release initial ref
  839. return hr;
  840. }
  841. if (IsEqualCLSID (rclsid, CLSID_IEAKRSoPSnapinExt))
  842. {
  843. CComponentDataCF *pComponentDataCF = new CComponentDataCF(TRUE); // ref == 1
  844. if (pComponentDataCF == NULL)
  845. return E_OUTOFMEMORY;
  846. hr = pComponentDataCF->QueryInterface(riid, ppv);
  847. pComponentDataCF->Release(); // release initial ref
  848. return hr;
  849. }
  850. if (IsEqualCLSID (rclsid, CLSID_AboutIEAKSnapinExt))
  851. {
  852. CAboutIEAKSnapinExtCF *pAboutIEAKSnapinExtCF = new CAboutIEAKSnapinExtCF(); // ref == 1
  853. if (pAboutIEAKSnapinExtCF == NULL)
  854. return E_OUTOFMEMORY;
  855. hr = pAboutIEAKSnapinExtCF->QueryInterface(riid, ppv);
  856. pAboutIEAKSnapinExtCF->Release(); // release initial ref
  857. return hr;
  858. }
  859. return CLASS_E_CLASSNOTAVAILABLE;
  860. }