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.

1002 lines
32 KiB

  1. #include "precomp.h"
  2. #include "rsop.h"
  3. #include <comdef.h>
  4. #include <tchar.h>
  5. #include "resource.h"
  6. /////////////////////////////////////////////////////////////////////
  7. // precedence page function prototypes for each dialog
  8. // title.cpp
  9. extern HRESULT InitTitlePrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  10. // logo.cpp
  11. extern HRESULT InitSmallLogoPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  12. extern HRESULT InitLargeLogoPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  13. extern HRESULT InitSmallBmpPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  14. extern HRESULT InitLargeBmpPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  15. // btoolbar.cpp
  16. extern HRESULT InitBToolbarPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  17. extern HRESULT InitToolbarBmpPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  18. // cs.cpp
  19. extern HRESULT InitCSPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  20. extern HRESULT InitAutoDetectCfgPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  21. extern HRESULT InitAutoCfgEnablePrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  22. extern HRESULT InitProxyPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  23. // useragnt.cpp
  24. extern HRESULT InitUserAgentPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  25. // favs.cpp
  26. extern HRESULT InitFavsPlacementPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  27. extern HRESULT InitFavsDeletionPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  28. extern HRESULT InitFavsPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  29. // urls.cpp
  30. extern HRESULT InitHomePageUrlPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  31. extern HRESULT InitSearchBarUrlPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  32. extern HRESULT InitSupportPageUrlPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  33. // seczones.cpp
  34. extern HRESULT InitSecZonesPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  35. extern HRESULT InitContentRatPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  36. // secauth.cpp
  37. extern HRESULT InitSecAuthPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  38. extern HRESULT InitAuthLockdownPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  39. // programs.cpp
  40. extern HRESULT InitProgramsPrecPage(CDlgRSoPData *pDRD, HWND hwndList);
  41. /////////////////////////////////////////////////////////////////////
  42. typedef HRESULT (* PRECEDENCE_HANDLER_PROC)(CDlgRSoPData *pDRD, HWND hwndList);
  43. typedef struct _PRECEDENCE_HANDLER
  44. {
  45. INT iDlgID;
  46. INT iPageIndex;
  47. PRECEDENCE_HANDLER_PROC pfnHandler;
  48. } PRECEDENCE_HANDLER, *LPPRECEDENCE_HANDLER;
  49. #define PH_BTITLE 0
  50. #define PH_CUSTICON 1
  51. #define PH_BTOOLBARS 5
  52. #define PH_CONNECTSET 7
  53. #define PH_QUERYAUTOCONFIG 8
  54. #define PH_PROXY 10
  55. #define PH_UASTRDLG 11
  56. #define PH_FAVORITES 12
  57. #define PH_STARTSEARCH 15
  58. #define PH_SECURITY1 18
  59. #define PH_SECURITYAUTH 20
  60. #define PH_PROGRAMS 22
  61. static PRECEDENCE_HANDLER s_PrecHandlers[] =
  62. {
  63. {IDD_BTITLE, 0, InitTitlePrecPage}, // PH_BTITLE = 0
  64. {IDD_CUSTICON, 0, InitSmallLogoPrecPage}, // PH_CUSTICON = 1
  65. {IDD_CUSTICON, 1, InitLargeLogoPrecPage},
  66. {IDD_CUSTICON, 2, InitSmallBmpPrecPage},
  67. {IDD_CUSTICON, 3, InitLargeBmpPrecPage},
  68. {IDD_BTOOLBARS, 0, InitBToolbarPrecPage}, // PH_BTOOLBARS = 5
  69. {IDD_BTOOLBARS, 1, InitToolbarBmpPrecPage},
  70. {IDD_CONNECTSET, 0, InitCSPrecPage}, // PH_CONNECTSET = 7
  71. {IDD_QUERYAUTOCONFIG, 0, InitAutoDetectCfgPrecPage}, // PH_QUERYAUTOCONFIG = 8
  72. {IDD_QUERYAUTOCONFIG, 1, InitAutoCfgEnablePrecPage},
  73. {IDD_PROXY, 0, InitProxyPrecPage}, // PH_PROXY = 10
  74. {IDD_UASTRDLG, 0, InitUserAgentPrecPage}, // PH_UASTRDLG = 11
  75. {IDD_FAVORITES, 0, InitFavsPlacementPrecPage}, // PH_FAVORITES = 12
  76. {IDD_FAVORITES, 1, InitFavsDeletionPrecPage},
  77. {IDD_FAVORITES, 2, InitFavsPrecPage},
  78. {IDD_STARTSEARCH, 0, InitHomePageUrlPrecPage}, // PH_UASTRDLG = 15
  79. {IDD_STARTSEARCH, 1, InitSearchBarUrlPrecPage},
  80. {IDD_STARTSEARCH, 2, InitSupportPageUrlPrecPage},
  81. {IDD_SECURITY1, 0, InitSecZonesPrecPage}, // PH_SECURITY1 = 18
  82. {IDD_SECURITY1, 1, InitContentRatPrecPage},
  83. {IDD_SECURITYAUTH, 0, InitSecAuthPrecPage}, // PH_SECURITYAUTH = 20
  84. {IDD_SECURITYAUTH, 1, InitAuthLockdownPrecPage},
  85. {IDD_PROGRAMS, 0, InitProgramsPrecPage} // PH_PROGRAMS = 22
  86. };
  87. /////////////////////////////////////////////////////////////////////
  88. // global var to store disabled string
  89. TCHAR g_szDisabled[64] = _T("");
  90. TCHAR g_szEnabled[64] = _T("");
  91. LPCTSTR GetDisabledString() {return g_szDisabled;}
  92. LPCTSTR GetEnabledString() {return g_szEnabled;}
  93. /////////////////////////////////////////////////////////////////////
  94. BOOL IsVariantNull(const VARIANT &v) {return (VT_NULL == v.vt) ? TRUE : FALSE;}
  95. /////////////////////////////////////////////////////////////////////
  96. _bstr_t WbemValueToString(VARIANT &v)
  97. {
  98. _bstr_t bstrVal;
  99. __try
  100. {
  101. switch(v.vt)
  102. {
  103. case CIM_STRING:
  104. bstrVal = v.bstrVal;
  105. break;
  106. case CIM_SINT8:
  107. case CIM_SINT16:
  108. case CIM_UINT8:
  109. case CIM_UINT16:
  110. case CIM_SINT32:
  111. case CIM_UINT32:
  112. {
  113. WCHAR wszBuf[32];
  114. switch (v.vt)
  115. {
  116. case CIM_SINT8:
  117. case CIM_SINT16:
  118. wnsprintf(wszBuf, countof(wszBuf), L"%hd", (CIM_SINT8 == v.vt) ? v.cVal : v.iVal); break;
  119. case CIM_UINT8:
  120. case CIM_UINT16:
  121. wnsprintf(wszBuf, countof(wszBuf), L"%hu", (CIM_UINT8 == v.vt) ? v.bVal : v.uiVal); break;
  122. case CIM_SINT32:
  123. wnsprintf(wszBuf, countof(wszBuf), L"%d", v.lVal); break;
  124. case CIM_UINT32:
  125. wnsprintf(wszBuf, countof(wszBuf), L"%u", v.ulVal); break;
  126. }
  127. bstrVal = wszBuf;
  128. break;
  129. }
  130. case CIM_BOOLEAN:
  131. {
  132. TCHAR szBuf[32];
  133. if (!v.boolVal)
  134. LoadString(g_hInstance, IDS_FALSE, szBuf, countof(szBuf));
  135. else
  136. LoadString(g_hInstance, IDS_TRUE, szBuf, countof(szBuf));
  137. bstrVal = szBuf;
  138. break;
  139. }
  140. case CIM_UINT8 | CIM_FLAG_ARRAY:
  141. {
  142. SAFEARRAY *pVec = v.parray;
  143. long iLBound, iUBound;
  144. SafeArrayGetLBound(pVec, 1, &iLBound);
  145. SafeArrayGetUBound(pVec, 1, &iUBound);
  146. TCHAR szBuf[32];
  147. if ((iUBound - iLBound + 1) == 0)
  148. LoadString(g_hInstance, IDS_EMPTY, szBuf, countof(szBuf));
  149. else
  150. LoadString(g_hInstance, IDS_ARRAY, szBuf, countof(szBuf));
  151. bstrVal = szBuf;
  152. break;
  153. }
  154. default:
  155. {
  156. TCHAR szBuf[128];
  157. LoadString(g_hInstance, IDS_CONVERSIONERROR, szBuf, countof(szBuf));
  158. bstrVal = szBuf;
  159. break;
  160. }
  161. }
  162. }
  163. __except(TRUE)
  164. {
  165. }
  166. return bstrVal;
  167. }
  168. /////////////////////////////////////////////////////////////////////
  169. CDlgRSoPData *GetDlgRSoPData(HWND hDlg, CSnapIn *pCS)
  170. {
  171. CDlgRSoPData *pDRD = NULL;
  172. __try
  173. {
  174. HWND hwndPSheet = GetParent(hDlg);
  175. pDRD = (CDlgRSoPData*)GetWindowLongPtr(hwndPSheet, GWLP_USERDATA);
  176. if (NULL == pDRD)
  177. {
  178. pDRD = new CDlgRSoPData(pCS);
  179. SetWindowLongPtr(hwndPSheet, GWLP_USERDATA, (LONG_PTR)pDRD);
  180. }
  181. }
  182. __except(TRUE)
  183. {
  184. }
  185. return pDRD;
  186. }
  187. /////////////////////////////////////////////////////////////////////
  188. void DestroyDlgRSoPData(HWND hDlg)
  189. {
  190. __try
  191. {
  192. // delete RSoP data if stored in parent
  193. HWND hwndPSheet = GetParent(hDlg);
  194. CDlgRSoPData *pDRD = (CDlgRSoPData*)GetWindowLongPtr(hwndPSheet, GWLP_USERDATA);
  195. if (NULL != pDRD)
  196. delete pDRD;
  197. }
  198. __except(TRUE)
  199. {
  200. }
  201. }
  202. /////////////////////////////////////////////////////////////////////
  203. _bstr_t GetGPOSetting(ComPtr<IWbemClassObject> pPSObj, BSTR bstrSettingName)
  204. {
  205. _bstr_t bstrSetting;
  206. __try
  207. {
  208. ASSERT(NULL != pPSObj);
  209. _variant_t vtSetting;
  210. HRESULT hr = pPSObj->Get(bstrSettingName, 0, &vtSetting, NULL, NULL);
  211. if (SUCCEEDED(hr))
  212. {
  213. if (IsVariantNull(vtSetting))
  214. bstrSetting = GetDisabledString();
  215. else
  216. bstrSetting = WbemValueToString(vtSetting);
  217. }
  218. }
  219. __except(TRUE)
  220. {
  221. }
  222. return bstrSetting;
  223. }
  224. /////////////////////////////////////////////////////////////////////
  225. // For a class derived from RSOP_PolicySetting, just use the standard
  226. // 'precedence' property. However, all other IEAK rsop classes should
  227. // have a property which represents its associated PS object's precedence.
  228. // This is typically 'rsopPrecedence', but we'll let the user pass it
  229. // in (bstrProp) because it is custom.
  230. /////////////////////////////////////////////////////////////////////
  231. DWORD GetGPOPrecedence(ComPtr<IWbemClassObject> pPSObj, BSTR bstrProp /*= NULL*/)
  232. {
  233. DWORD dwPrecedence = 0;
  234. __try
  235. {
  236. ASSERT(NULL != pPSObj);
  237. _variant_t vtPrec;
  238. HRESULT hr = NOERROR;
  239. if (NULL == bstrProp)
  240. hr = pPSObj->Get(L"precedence", 0, &vtPrec, NULL, NULL);
  241. else
  242. hr = pPSObj->Get(bstrProp, 0, &vtPrec, NULL, NULL);
  243. if (SUCCEEDED(hr))
  244. dwPrecedence = vtPrec.ulVal;
  245. }
  246. __except(TRUE)
  247. {
  248. }
  249. return dwPrecedence;
  250. }
  251. /////////////////////////////////////////////////////////////////////
  252. HRESULT InitGenericPrecedencePage(CDlgRSoPData *pDRD, HWND hwndList, BSTR bstrPropName)
  253. {
  254. HRESULT hr = NOERROR;
  255. __try
  256. {
  257. _bstr_t bstrClass = L"RSOP_IEAKPolicySetting";
  258. hr = pDRD->GetArrayOfPSObjects(bstrClass);
  259. if (SUCCEEDED(hr))
  260. {
  261. CPSObjData **paPSObj = pDRD->GetPSObjArray();
  262. long nPSObjects = pDRD->GetPSObjCount();
  263. for (long nObj = 0; nObj < nPSObjects; nObj++)
  264. {
  265. _bstr_t bstrGPOName = pDRD->GetGPONameFromPS(paPSObj[nObj]->pObj);
  266. _bstr_t bstrSetting = GetGPOSetting(paPSObj[nObj]->pObj, bstrPropName);
  267. InsertPrecedenceListItem(hwndList, nObj, bstrGPOName, bstrSetting);
  268. }
  269. }
  270. }
  271. __except(TRUE)
  272. {
  273. }
  274. return hr;
  275. }
  276. /////////////////////////////////////////////////////////////////////
  277. void InsertPrecedenceListItem(HWND hwndList, long nItem, LPTSTR szName, LPTSTR szSetting)
  278. {
  279. __try
  280. {
  281. LVITEM lvi;
  282. ZeroMemory(&lvi, sizeof(lvi));
  283. lvi.mask = LVIF_TEXT;
  284. lvi.iItem = nItem;
  285. lvi.pszText = szName;
  286. int iListIndex = ListView_InsertItem(hwndList, &lvi);
  287. if (iListIndex >= 0)
  288. ListView_SetItemText(hwndList, nItem, 1, szSetting);
  289. }
  290. __except(TRUE)
  291. {
  292. }
  293. }
  294. /////////////////////////////////////////////////////////////////////
  295. int CreateINetCplLookALikePage(HWND hwndParent, UINT nID, DLGPROC dlgProc,
  296. LPARAM lParam)
  297. {
  298. int iRet = 0;
  299. __try
  300. {
  301. PROPSHEETPAGE page;
  302. page.dwSize = sizeof(PROPSHEETPAGE);
  303. page.dwFlags = 0;
  304. page.hInstance = g_hInstance;
  305. page.pszTemplate = MAKEINTRESOURCE(nID);
  306. page.pfnDlgProc = dlgProc;
  307. page.pfnCallback = NULL;
  308. page.lParam = lParam;
  309. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&page);
  310. PROPSHEETHEADER psHeader;
  311. memset(&psHeader,0,sizeof(psHeader));
  312. psHeader.dwSize = sizeof(psHeader);
  313. psHeader.dwFlags = PSH_PROPTITLE;
  314. psHeader.hwndParent = hwndParent;
  315. psHeader.hInstance = g_hInstance;
  316. psHeader.nPages = 1;
  317. psHeader.nStartPage = 0;
  318. psHeader.phpage = &hPage;
  319. psHeader.pszCaption = MAKEINTRESOURCE(IDS_INTERNET_LOC);
  320. iRet = (int)PropertySheet(&psHeader);
  321. }
  322. __except(TRUE)
  323. {
  324. }
  325. return iRet;
  326. }
  327. /////////////////////////////////////////////////////////////////////
  328. BOOL GetWMIPropBool(IWbemClassObject *pObj, BSTR bstrProp, BOOL fDefault,
  329. BOOL &fHandled)
  330. {
  331. DWORD fRet = fDefault;
  332. __try
  333. {
  334. BSTR bstrAllocedProp = SysAllocString(bstrProp);
  335. if (NULL != bstrAllocedProp)
  336. {
  337. VARIANT vtValue;
  338. HRESULT hr = pObj->Get(bstrAllocedProp, 0, &vtValue, NULL, NULL);
  339. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  340. {
  341. fHandled = TRUE;
  342. if (0 != vtValue.boolVal)
  343. fRet = TRUE;
  344. else
  345. fRet = FALSE;
  346. }
  347. SysFreeString(bstrAllocedProp);
  348. }
  349. }
  350. __except(TRUE)
  351. {
  352. }
  353. return fRet;
  354. }
  355. /////////////////////////////////////////////////////////////////////
  356. DWORD GetWMIPropUL(IWbemClassObject *pObj, BSTR bstrProp, DWORD dwDefault,
  357. BOOL &fHandled)
  358. {
  359. DWORD dwRet = dwDefault;
  360. __try
  361. {
  362. BSTR bstrAllocedProp = SysAllocString(bstrProp);
  363. if (NULL != bstrAllocedProp)
  364. {
  365. VARIANT vtValue;
  366. HRESULT hr = pObj->Get(bstrAllocedProp, 0, &vtValue, NULL, NULL);
  367. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  368. {
  369. fHandled = TRUE;
  370. dwRet = vtValue.ulVal;
  371. }
  372. SysFreeString(bstrAllocedProp);
  373. }
  374. }
  375. __except(TRUE)
  376. {
  377. }
  378. return dwRet;
  379. }
  380. /////////////////////////////////////////////////////////////////////
  381. void GetWMIPropPWSTR(IWbemClassObject *pObj, BSTR bstrProp, LPWSTR wszBuffer,
  382. DWORD dwBufferLen, LPWSTR wszDefault, BOOL &fHandled)
  383. {
  384. __try
  385. {
  386. if (dwBufferLen > 0)
  387. {
  388. ZeroMemory(wszBuffer, dwBufferLen);
  389. if (NULL != wszDefault)
  390. wcsncpy(wszBuffer, wszDefault, dwBufferLen - 1);
  391. BSTR bstrAllocedProp = SysAllocString(bstrProp);
  392. if (NULL != bstrAllocedProp)
  393. {
  394. VARIANT vtValue;
  395. HRESULT hr = pObj->Get(bstrAllocedProp, 0, &vtValue, NULL, NULL);
  396. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  397. {
  398. fHandled = TRUE;
  399. wcsncpy(wszBuffer, (LPWSTR)vtValue.bstrVal, dwBufferLen - 1);
  400. }
  401. VariantClear(&vtValue);
  402. SysFreeString(bstrAllocedProp);
  403. }
  404. }
  405. }
  406. __except(TRUE)
  407. {
  408. }
  409. }
  410. /////////////////////////////////////////////////////////////////////
  411. void GetWMIPropPTSTR(IWbemClassObject *pObj, BSTR bstrProp, LPTSTR szBuffer,
  412. DWORD dwBufferLen, LPTSTR szDefault, BOOL &fHandled)
  413. {
  414. __try
  415. {
  416. if (dwBufferLen > 0)
  417. {
  418. ZeroMemory(szBuffer, dwBufferLen);
  419. if (NULL != szDefault)
  420. _tcsncpy(szBuffer, szDefault, dwBufferLen - 1);
  421. BSTR bstrAllocedProp = SysAllocString(bstrProp);
  422. if (NULL != bstrAllocedProp)
  423. {
  424. VARIANT vtValue;
  425. HRESULT hr = pObj->Get(bstrAllocedProp, 0, &vtValue, NULL, NULL);
  426. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  427. {
  428. fHandled = TRUE;
  429. #ifdef UNICODE
  430. wcsncpy(szBuffer, (LPWSTR)vtValue.bstrVal, dwBufferLen - 1);
  431. #else
  432. SHUnicodeToAnsi(vtValue.bstrVal, szBuffer, dwBufferLen);
  433. #endif
  434. }
  435. VariantClear(&vtValue);
  436. SysFreeString(bstrAllocedProp);
  437. }
  438. }
  439. }
  440. __except(TRUE)
  441. {
  442. }
  443. }
  444. /////////////////////////////////////////////////////////////////////
  445. CDlgRSoPData::CDlgRSoPData(CSnapIn *pCS):
  446. m_pCS(pCS),
  447. m_pWbemServices(NULL),
  448. m_paPSObj(NULL),
  449. m_nPSObjects(0),
  450. m_pCRatObj(NULL),
  451. m_dwImportedProgSettPrec(0),
  452. m_dwImportedConnSettPrec(0),
  453. m_dwImportedSecZonesPrec(0),
  454. m_dwImportedSecRatingsPrec(0),
  455. m_dwImportedAuthenticodePrec(0),
  456. m_dwImportedSecZones(0),
  457. m_paCSObj(0),
  458. m_nCSObjects(0)
  459. {
  460. __try
  461. {
  462. ASSERT(NULL != pCS);
  463. // WMI Certificate Info storage for each tab
  464. m_pwci[0] = m_pwci[1] = m_pwci[2] = m_pwci[3] = m_pwci[4] = NULL;
  465. }
  466. __except(TRUE)
  467. {
  468. }
  469. }
  470. /////////////////////////////////////////////////////////////////////
  471. CDlgRSoPData::~CDlgRSoPData()
  472. {
  473. __try
  474. {
  475. // clear the cache of RSOP_IEAKPolicySetting objects
  476. for (long nObj = 0; nObj < m_nPSObjects; nObj++)
  477. {
  478. delete m_paPSObj[nObj];
  479. m_paPSObj[nObj] = NULL;
  480. }
  481. if (NULL != m_paPSObj)
  482. CoTaskMemFree(m_paPSObj);
  483. // clear the cache of RSOP_IEConnectionSettings objects
  484. for (long nObj = 0; nObj < m_nCSObjects; nObj++)
  485. {
  486. delete m_paCSObj[nObj];
  487. m_paCSObj[nObj] = NULL;
  488. }
  489. if (NULL != m_paCSObj)
  490. CoTaskMemFree(m_paCSObj);
  491. // free certificate info
  492. UninitCertInfo();
  493. }
  494. __except(TRUE)
  495. {
  496. }
  497. }
  498. //////////////////////////////////////////////////////////////////////
  499. void CDlgRSoPData::UninitCertInfo()
  500. {
  501. __try
  502. {
  503. for (long iTab = 0; iTab < 5; iTab++)
  504. {
  505. WMI_CERT_INFO *pwciToBeDeleted = NULL;
  506. WMI_CERT_INFO *pwci = m_pwci[iTab];
  507. while (pwci)
  508. {
  509. if (NULL != pwci->wszSubject)
  510. {
  511. LocalFree(pwci->wszSubject);
  512. pwci->wszSubject = NULL;
  513. }
  514. if (NULL != pwci->wszIssuer)
  515. {
  516. LocalFree(pwci->wszIssuer);
  517. pwci->wszIssuer = NULL;
  518. }
  519. if (NULL != pwci->wszFriendlyName)
  520. {
  521. LocalFree(pwci->wszFriendlyName);
  522. pwci->wszFriendlyName = NULL;
  523. }
  524. if (NULL != pwci->wszPurposes)
  525. {
  526. LocalFree(pwci->wszPurposes);
  527. pwci->wszPurposes = NULL;
  528. }
  529. pwciToBeDeleted = pwci;
  530. pwci = pwci->pNext;
  531. if (NULL != pwciToBeDeleted)
  532. {
  533. LocalFree(pwciToBeDeleted);
  534. pwciToBeDeleted = NULL;
  535. }
  536. }
  537. m_pwci[iTab] = NULL;
  538. }
  539. }
  540. __except(TRUE)
  541. {
  542. }
  543. }
  544. /////////////////////////////////////////////////////////////////////////////////////////
  545. // If pWbemServices is non-null, the existing value is used for queries
  546. /////////////////////////////////////////////////////////////////////////////////////////
  547. ComPtr<IWbemServices> CDlgRSoPData::ConnectToNamespace()
  548. {
  549. __try
  550. {
  551. // If we haven't already cached the WbemServices ptr, get it
  552. // and cache it.
  553. if (NULL == m_pWbemServices)
  554. {
  555. // Connect to the namespace using the locator's
  556. // ConnectServer method
  557. ComPtr<IWbemLocator> pIWbemLocator = NULL;
  558. if (CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER,
  559. IID_IWbemLocator, (LPVOID *) &pIWbemLocator) == S_OK)
  560. {
  561. BSTR bstrNamespace = GetNamespace();
  562. HRESULT hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL,
  563. 0L, 0L, NULL, NULL,
  564. &m_pWbemServices);
  565. if (FAILED(hr))
  566. {
  567. ASSERT(0);
  568. }
  569. pIWbemLocator = NULL;
  570. }
  571. else
  572. {
  573. ASSERT(0);
  574. }
  575. }
  576. }
  577. __except(TRUE)
  578. {
  579. }
  580. return m_pWbemServices;
  581. }
  582. /////////////////////////////////////////////////////////////////////
  583. _bstr_t CDlgRSoPData::GetGPONameFromPS(ComPtr<IWbemClassObject> pPSObj)
  584. {
  585. _bstr_t bstrGPOName;
  586. __try
  587. {
  588. ASSERT(NULL != pPSObj);
  589. if (NULL != ConnectToNamespace())
  590. {
  591. _variant_t vtGPOID;
  592. HRESULT hr = pPSObj->Get(L"GPOID", 0, &vtGPOID, NULL, NULL);
  593. if (SUCCEEDED(hr))
  594. {
  595. _bstr_t bstrObjPath = L"RSOP_GPO.id=\"";
  596. bstrObjPath += vtGPOID.bstrVal;
  597. bstrObjPath += L"\"";
  598. ComPtr<IWbemClassObject> pGPO = NULL;
  599. hr = m_pWbemServices->GetObject(bstrObjPath, 0L, NULL, (IWbemClassObject**)&pGPO, NULL);
  600. if (SUCCEEDED(hr))
  601. {
  602. _variant_t vtName;
  603. hr = pGPO->Get(L"name", 0, &vtName, NULL, NULL);
  604. if (SUCCEEDED(hr) && VT_BSTR == vtName.vt)
  605. bstrGPOName = vtName.bstrVal;
  606. }
  607. }
  608. }
  609. }
  610. __except(TRUE)
  611. {
  612. }
  613. return bstrGPOName;
  614. }
  615. /////////////////////////////////////////////////////////////////////
  616. _bstr_t CDlgRSoPData::GetGPONameFromPSAssociation(ComPtr<IWbemClassObject> pObj,
  617. BSTR bstrPrecedenceProp)
  618. {
  619. _bstr_t bstrGPOName;
  620. __try
  621. {
  622. ASSERT(NULL != pObj);
  623. if (NULL != ConnectToNamespace())
  624. {
  625. // first get the item's precedence value
  626. _variant_t vtPrecedence;
  627. HRESULT hr = pObj->Get(bstrPrecedenceProp, 0, &vtPrecedence, NULL, NULL);
  628. if (SUCCEEDED(hr))
  629. {
  630. DWORD dwPrec = vtPrecedence.ulVal;
  631. WCHAR wszObjPath[128];
  632. wnsprintf(wszObjPath, countof(wszObjPath), L"RSOP_IEAKPolicySetting.id=\"IEAK\",precedence=%ld", dwPrec);
  633. _bstr_t bstrObjPath = wszObjPath;
  634. ComPtr<IWbemClassObject> pPSObj = NULL;
  635. hr = m_pWbemServices->GetObject(bstrObjPath, 0L, NULL, (IWbemClassObject**)&pPSObj, NULL);
  636. if (SUCCEEDED(hr))
  637. bstrGPOName = GetGPONameFromPS(pPSObj);
  638. }
  639. }
  640. }
  641. __except(TRUE)
  642. {
  643. }
  644. return bstrGPOName;
  645. }
  646. ///////////////////////////////////////////////////////////////////////////////
  647. int CDlgRSoPData::ComparePSObjectsByPrecedence(const void *arg1, const void *arg2)
  648. {
  649. int iRet = 0;
  650. __try
  651. {
  652. if ( (*(CPSObjData **)arg1)->dwPrecedence > (*(CPSObjData **)arg2)->dwPrecedence )
  653. iRet = 1;
  654. else if ( (*(CPSObjData **)arg1)->dwPrecedence < (*(CPSObjData **)arg2)->dwPrecedence )
  655. iRet = -1;
  656. }
  657. __except(TRUE)
  658. {
  659. ASSERT(0);
  660. }
  661. return iRet;
  662. }
  663. /////////////////////////////////////////////////////////////////////
  664. // To ensure a top-level (currently only RSOP_IEAKPolicySetting) object
  665. // is cached in the DRD, just pass in the first param and leave the rest NULL.
  666. // If ppaPSObj is non NULL, it will be set to a new array of objects. The
  667. // caller must call CoTaskMemFree on the returned ptr when it is done with
  668. // it. The 'bstrPrecedenceProp' parameter allows the caller to specify
  669. // a property name other than 'precedence' to get the precedence of the class
  670. // instance (usually rsopPrecedence for non-top-level classes).
  671. /////////////////////////////////////////////////////////////////////
  672. HRESULT CDlgRSoPData::GetArrayOfPSObjects(BSTR bstrClass,
  673. BSTR bstrPrecedenceProp /*= NULL*/,
  674. CPSObjData ***ppaPSObj /*= NULL*/,
  675. long *pnObjCount /*= NULL*/)
  676. {
  677. HRESULT hr = NOERROR;
  678. __try
  679. {
  680. if (NULL == m_paPSObj || NULL != ppaPSObj)
  681. {
  682. hr = E_FAIL;
  683. CPSObjData **paTempPSObj = NULL;
  684. long nTempObjects = 0;
  685. ComPtr<IWbemServices> pWbemServices = ConnectToNamespace();
  686. if (NULL != pWbemServices)
  687. {
  688. ComPtr<IEnumWbemClassObject> pObjEnum = NULL;
  689. hr = pWbemServices->CreateInstanceEnum(bstrClass,
  690. WBEM_FLAG_FORWARD_ONLY,
  691. NULL, &pObjEnum);
  692. if (SUCCEEDED(hr))
  693. {
  694. #define GROW_PSOBJ_ARRAY_BY 5
  695. long nPSArraySize = GROW_PSOBJ_ARRAY_BY;
  696. paTempPSObj = (CPSObjData**)CoTaskMemAlloc(sizeof(CPSObjData*) * GROW_PSOBJ_ARRAY_BY);
  697. ZeroMemory(paTempPSObj, sizeof(CPSObjData*) * GROW_PSOBJ_ARRAY_BY);
  698. // Final Next wil return WBEM_S_FALSE
  699. while (WBEM_S_NO_ERROR == hr)
  700. {
  701. // There should only be one object returned from this query.
  702. ULONG uReturned = (ULONG)-1L;
  703. ComPtr<IWbemClassObject> pPSObj = NULL;
  704. hr = pObjEnum->Next(10000L, 1, &pPSObj, &uReturned);
  705. if (SUCCEEDED(hr) && 1 == uReturned)
  706. {
  707. paTempPSObj[nTempObjects] = new CPSObjData();
  708. paTempPSObj[nTempObjects]->pObj = pPSObj;
  709. if (NULL == bstrPrecedenceProp)
  710. paTempPSObj[nTempObjects]->dwPrecedence = GetGPOPrecedence(pPSObj);
  711. else
  712. paTempPSObj[nTempObjects]->dwPrecedence =
  713. GetGPOPrecedence(pPSObj, bstrPrecedenceProp);
  714. nTempObjects++;
  715. // Grow the array of obj paths if we've outgrown the current array
  716. if (nTempObjects == nPSArraySize)
  717. {
  718. paTempPSObj = (CPSObjData**)CoTaskMemRealloc(paTempPSObj, sizeof(CPSObjData*) *
  719. nPSArraySize + GROW_PSOBJ_ARRAY_BY);
  720. ZeroMemory(paTempPSObj + (nPSArraySize * sizeof(CPSObjData*)),
  721. sizeof(CPSObjData*) * GROW_PSOBJ_ARRAY_BY);
  722. if (NULL != paTempPSObj)
  723. nPSArraySize += GROW_PSOBJ_ARRAY_BY;
  724. }
  725. }
  726. }
  727. // now sort the list by precedence
  728. if (SUCCEEDED(hr))
  729. qsort(paTempPSObj, nTempObjects, sizeof(CPSObjData*), ComparePSObjectsByPrecedence);
  730. }
  731. }
  732. if (NULL == ppaPSObj)
  733. {
  734. if (!StrCmpIW(bstrClass, L"RSOP_IEConnectionSettings"))
  735. {
  736. m_paCSObj = paTempPSObj;
  737. m_nCSObjects = nTempObjects;
  738. }
  739. else
  740. {
  741. m_paPSObj = paTempPSObj;
  742. m_nPSObjects = nTempObjects;
  743. }
  744. }
  745. else
  746. {
  747. *ppaPSObj = paTempPSObj;
  748. *pnObjCount = nTempObjects;
  749. }
  750. }
  751. }
  752. __except(TRUE)
  753. {
  754. }
  755. return hr;
  756. }
  757. /////////////////////////////////////////////////////////////////////
  758. HRESULT CDlgRSoPData::LoadContentRatingsObject()
  759. {
  760. HRESULT hr = NOERROR;
  761. __try
  762. {
  763. if (NULL == m_pCRatObj)
  764. {
  765. // get our stored precedence value
  766. DWORD dwCurGPOPrec = m_dwImportedSecRatingsPrec;
  767. WCHAR wszObjPath[128];
  768. // create the object path of this security zone for this GPO
  769. wnsprintf(wszObjPath, countof(wszObjPath),
  770. L"RSOP_IESecurityContentRatings.rsopID=\"IEAK\",rsopPrecedence=%ld",
  771. dwCurGPOPrec);
  772. _bstr_t bstrObjPath = wszObjPath;
  773. // get the RSOP_IEProgramSettings object and its properties
  774. ComPtr<IWbemServices> pWbemServices = GetWbemServices();
  775. hr = pWbemServices->GetObject(bstrObjPath, 0L, NULL, (IWbemClassObject**)&m_pCRatObj, NULL);
  776. if (FAILED(hr))
  777. m_pCRatObj = NULL;
  778. }
  779. }
  780. __except(TRUE)
  781. {
  782. }
  783. return hr;
  784. }
  785. /////////////////////////////////////////////////////////////////////
  786. // The dlg proc for all IEAK RSOP precedence property pages
  787. /////////////////////////////////////////////////////////////////////
  788. INT_PTR CALLBACK RSoPDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  789. {
  790. wParam = wParam;
  791. lParam = lParam;
  792. // Retrieve Property Sheet Page info for each call into dlg proc.
  793. LPRSOPPAGECOOKIE rpCookie = (LPRSOPPAGECOOKIE)GetWindowLongPtr(hDlg, DWLP_USER);
  794. switch( msg )
  795. {
  796. case WM_INITDIALOG:
  797. {
  798. LPRSOPPAGECOOKIE lpRSOPPageCookie = (LPRSOPPAGECOOKIE)(((LPPROPSHEETPAGE)lParam)->lParam);
  799. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)lpRSOPPageCookie);
  800. // Store Property Sheet Page info for later class into dlgProc.
  801. rpCookie = (LPRSOPPAGECOOKIE)GetWindowLongPtr(hDlg, DWLP_USER);
  802. ASSERT(rpCookie->psCookie->pCS->IsRSoP());
  803. // Initialize the GPO list control
  804. HWND hwndList = GetDlgItem(hDlg, IDC_GPOLIST);
  805. LVCOLUMN lvc;
  806. lvc.mask = LVCF_TEXT | LVCF_WIDTH;
  807. lvc.fmt = LVCFMT_LEFT;
  808. lvc.cx = 200;
  809. TCHAR szHeader[128];
  810. LoadString(g_hInstance, IDS_GPONAME, szHeader, countof(szHeader));
  811. lvc.pszText = szHeader;
  812. ListView_InsertColumn(hwndList, 0, &lvc);
  813. lvc.cx = 300;
  814. LoadString(g_hInstance, IDS_GPOSETTING, szHeader, countof(szHeader));
  815. lvc.pszText = szHeader;
  816. ListView_InsertColumn(hwndList, 1, &lvc);
  817. // Initialize the custom data in the list
  818. if (StrLen(g_szDisabled) <= 0)
  819. LoadString(g_hInstance, IDS_DISABLED, g_szDisabled, countof(g_szDisabled));
  820. if (StrLen(g_szEnabled) <= 0)
  821. LoadString(g_hInstance, IDS_ENABLED, g_szEnabled, countof(g_szEnabled));
  822. CDlgRSoPData *pDRD = GetDlgRSoPData(hDlg, rpCookie->psCookie->pCS);
  823. long nPrecPage = rpCookie->nPageID;
  824. switch(rpCookie->psCookie->lpResultItem->iDlgID)
  825. {
  826. // Browser User Interface
  827. case IDD_BTITLE:
  828. s_PrecHandlers[PH_BTITLE + nPrecPage].pfnHandler(pDRD, hwndList); break;
  829. case IDD_CUSTICON:
  830. s_PrecHandlers[PH_CUSTICON + nPrecPage].pfnHandler(pDRD, hwndList); break;
  831. case IDD_BTOOLBARS:
  832. s_PrecHandlers[PH_BTOOLBARS + nPrecPage].pfnHandler(pDRD, hwndList); break;
  833. // Connection
  834. case IDD_CONNECTSET:
  835. s_PrecHandlers[PH_CONNECTSET + nPrecPage].pfnHandler(pDRD, hwndList); break;
  836. case IDD_QUERYAUTOCONFIG:
  837. s_PrecHandlers[PH_QUERYAUTOCONFIG + nPrecPage].pfnHandler(pDRD, hwndList); break;
  838. case IDD_PROXY:
  839. s_PrecHandlers[PH_PROXY + nPrecPage].pfnHandler(pDRD, hwndList); break;
  840. break;
  841. case IDD_UASTRDLG:
  842. s_PrecHandlers[PH_UASTRDLG + nPrecPage].pfnHandler(pDRD, hwndList); break;
  843. // URLs
  844. case IDD_FAVORITES:
  845. s_PrecHandlers[PH_FAVORITES + nPrecPage].pfnHandler(pDRD, hwndList); break;
  846. case IDD_STARTSEARCH:
  847. s_PrecHandlers[PH_STARTSEARCH + nPrecPage].pfnHandler(pDRD, hwndList); break;
  848. // Security
  849. case IDD_SECURITY1:
  850. s_PrecHandlers[PH_SECURITY1 + nPrecPage].pfnHandler(pDRD, hwndList); break;
  851. case IDD_SECURITYAUTH:
  852. s_PrecHandlers[PH_SECURITYAUTH + nPrecPage].pfnHandler(pDRD, hwndList); break;
  853. // Programs
  854. case IDD_PROGRAMS:
  855. s_PrecHandlers[PH_PROGRAMS + nPrecPage].pfnHandler(pDRD, hwndList); break;
  856. // Advanced
  857. default:
  858. break;
  859. }
  860. break;
  861. }
  862. case WM_NOTIFY:
  863. switch (((LPNMHDR)lParam)->code)
  864. {
  865. case PSN_HELP:
  866. if (rpCookie && rpCookie->psCookie && rpCookie->psCookie->lpResultItem)
  867. {
  868. WCHAR wszHelpTopic[MAX_PATH];
  869. StrCpyW(wszHelpTopic, HELP_FILENAME TEXT("::/"));
  870. StrCatW(wszHelpTopic, rpCookie->psCookie->lpResultItem->pcszHelpTopic);
  871. MMCPropertyHelp((LPOLESTR)wszHelpTopic);
  872. }
  873. break;
  874. }
  875. break;
  876. default:
  877. return FALSE;
  878. }
  879. return TRUE;
  880. }