Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2525 lines
89 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1995 **
  4. //*********************************************************************
  5. //
  6. // SECURITY.cpp - "Security" Property Sheet
  7. //
  8. // HISTORY:
  9. //
  10. // 6/22/96 t-gpease moved to this file
  11. // 5/14/97 t-ashlm new dialog
  12. #include "inetcplp.h"
  13. #include "inetcpl.h" // for LSDFLAGS
  14. #include "intshcut.h"
  15. #include "permdlg.h" // java permissions
  16. #include "pdlgguid.h" // guids for Java VM permissions dlg
  17. #include <cryptui.h>
  18. #include <mluisupp.h>
  19. void LaunchSecurityDialogEx(HWND hDlg, DWORD dwZone, BOOL bForceUI, BOOL bDisableAddSites);
  20. //
  21. // Private Functions and Structures
  22. //
  23. INT_PTR CALLBACK SecurityAddSitesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  24. INT_PTR CALLBACK SecurityCustomSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  25. INT_PTR CALLBACK SecurityAddSitesIntranetDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  26. void SecurityChanged();
  27. TCHAR *MyIntToStr(TCHAR *pBuf, BYTE iVal);
  28. BOOL SecurityDlgInit(HWND hDlg);
  29. #define WIDETEXT(x) L ## x
  30. #define REGSTR_PATH_SECURITY_LOCKOUT TEXT("Software\\Policies\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
  31. #define REGSTR_VAL_OPTIONS_EDIT TEXT("Security_options_edit")
  32. #define REGSTR_VAL_ZONES_MAP_EDIT TEXT("Security_zones_map_edit")
  33. #define REGSTR_VAL_HKLM_ONLY TEXT("Security_HKLM_only")
  34. #define REGSTR_PATH_SO TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\SO")
  35. #define REGSTR_PATH_SOIEAK TEXT("Sofwtare\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\SOIEAK")
  36. ///////////////////////////////////////////////////////////////////////////////////////
  37. //
  38. // Structures
  39. //
  40. ///////////////////////////////////////////////////////////////////////////////////////
  41. typedef struct tagSECURITYZONESETTINGS
  42. {
  43. BOOL dwFlags; // from the ZONEATTRIBUTES struct
  44. DWORD dwZoneIndex; // as defined by ZoneManager
  45. DWORD dwSecLevel; // current level (High, Medium, Low, Custom)
  46. DWORD dwPrevSecLevel;
  47. DWORD dwMinSecLevel; // current min level (High, Medium, Low, Custom)
  48. DWORD dwRecSecLevel; // current recommended level (High, Medium, Low, Custom)
  49. TCHAR szDescription[MAX_ZONE_DESCRIPTION];
  50. TCHAR szDisplayName[MAX_ZONE_PATH];
  51. HICON hicon;
  52. } SECURITYZONESETTINGS, *LPSECURITYZONESETTINGS;
  53. // structure for main security page
  54. typedef struct tagSECURITYPAGE
  55. {
  56. HWND hDlg; // handle to window
  57. LPURLZONEMANAGER pInternetZoneManager; // pointer to InternetZoneManager
  58. IInternetSecurityManager *pInternetSecurityManager; // pointer to InternetSecurityManager
  59. HIMAGELIST himl; // imagelist for Zones combobox
  60. HWND hwndZones; // zones combo box hwnd
  61. LPSECURITYZONESETTINGS pszs; // current settings for displayed zone
  62. INT iZoneSel; // selected zone (as defined by ComboBox)
  63. DWORD dwZoneCount; // number of zones
  64. BOOL fChanged;
  65. BOOL fPendingChange; // to prevent the controls sending multiple sets (for cancel, mostly)
  66. HINSTANCE hinstUrlmon;
  67. BOOL fNoEdit; // hklm lockout of level edit
  68. BOOL fNoAddSites; // hklm lockout of addsites
  69. BOOL fNoZoneMapEdit; // hklm lockout of zone map edits
  70. HFONT hfontBolded; // special bolded font created for the zone title
  71. BOOL fForceUI; // Force every zone to show ui?
  72. BOOL fDisableAddSites; // Automatically diable add sites button?
  73. } SECURITYPAGE, *LPSECURITYPAGE;
  74. // structure for Intranet Add Sites
  75. typedef struct tagADDSITESINTRANETINFO {
  76. HWND hDlg; // handle to window
  77. BOOL fUseIntranet; // Use local defined intranet addresses (in reg)
  78. BOOL fUseProxyExclusion; // Use proxy exclusion list
  79. BOOL fUseUNC; // Include UNC in intranet
  80. LPSECURITYPAGE pSec;
  81. } ADDSITESINTRANETINFO, *LPADDSITESINTRANETINFO;
  82. // structure for Add Sites
  83. typedef struct tagADDSITESINFO {
  84. HWND hDlg; // handle to window
  85. BOOL fRequireServerVerification; // Require Server Verification on sites in zone
  86. HWND hwndWebSites; // handle to list
  87. HWND hwndAdd; // handle to edit
  88. TCHAR szWebSite[MAX_ZONE_PATH]; // text in edit control
  89. BOOL fRSVOld;
  90. LPSECURITYPAGE pSec;
  91. } ADDSITESINFO, *LPADDSITESINFO;
  92. // structure for Custom Settings
  93. typedef struct tagCUSTOMSETTINGSINFO {
  94. HWND hDlg; // handle to window
  95. HWND hwndTree;
  96. LPSECURITYPAGE pSec;
  97. HWND hwndCombo;
  98. INT iLevelSel;
  99. IRegTreeOptions *pTO;
  100. BOOL fUseHKLM; // get/set settings from HKLM
  101. DWORD dwJavaPolicy; // Java policy selected
  102. BOOL fChanged;
  103. } CUSTOMSETTINGSINFO, *LPCUSTOMSETTINGSINFO;
  104. BOOL SecurityEnableControls(LPSECURITYPAGE pSec, BOOL fSetFocus);
  105. BOOL SecurityDlgApplyNow(LPSECURITYPAGE pSec, BOOL bPrompt);
  106. // global variables
  107. extern DWORD g_dwtlsSecInitFlags;
  108. extern BOOL g_fSecurityChanged; // flag indicating that Active Security has changed.
  109. //////////////////////////////////////////////////////////////////////////////
  110. //
  111. // Main Security Page Helper Functions
  112. //
  113. //////////////////////////////////////////////////////////////////////////////
  114. #define NUM_TEMPLATE_LEVELS 4
  115. TCHAR g_szLevel[3][64];
  116. TCHAR LEVEL_DESCRIPTION0[300];
  117. TCHAR LEVEL_DESCRIPTION1[300];
  118. TCHAR LEVEL_DESCRIPTION2[300];
  119. TCHAR LEVEL_DESCRIPTION3[300];
  120. LPTSTR LEVEL_DESCRIPTION[NUM_TEMPLATE_LEVELS] = {
  121. LEVEL_DESCRIPTION0,
  122. LEVEL_DESCRIPTION1,
  123. LEVEL_DESCRIPTION2,
  124. LEVEL_DESCRIPTION3
  125. };
  126. TCHAR CUSTOM_DESCRIPTION[300];
  127. TCHAR LEVEL_NAME0[30];
  128. TCHAR LEVEL_NAME1[30];
  129. TCHAR LEVEL_NAME2[30];
  130. TCHAR LEVEL_NAME3[30];
  131. LPTSTR LEVEL_NAME[NUM_TEMPLATE_LEVELS] = {
  132. LEVEL_NAME0,
  133. LEVEL_NAME1,
  134. LEVEL_NAME2,
  135. LEVEL_NAME3
  136. };
  137. TCHAR CUSTOM_NAME[30];
  138. // Some accessibility related prototypes.
  139. // Our override of the slider window proc.
  140. LRESULT CALLBACK SliderSubWndProc (HWND hwndSlider, UINT uMsg, WPARAM wParam, LPARAM lParam, WPARAM uID, ULONG_PTR dwRefData );
  141. extern BOOL g_fAttemptedOleAccLoad ;
  142. extern HMODULE g_hOleAcc;
  143. // Can't find value for WM_GETOBJECT in the headers. Need to figure out the right header to include
  144. // here.
  145. #ifndef WM_GETOBJECT
  146. #define WM_GETOBJECT 0x03d
  147. #endif
  148. // Prototype for CreateStdAccessibleProxy.
  149. // A and W versions are available - pClassName can be ANSI or UNICODE
  150. // string. This is a TCHAR-style prototype, but you can do a A or W
  151. // specific one if desired.
  152. typedef HRESULT (WINAPI *PFNCREATESTDACCESSIBLEPROXY) (
  153. HWND hWnd,
  154. LPTSTR pClassName,
  155. LONG idObject,
  156. REFIID riid,
  157. void ** ppvObject
  158. );
  159. /*
  160. * Arguments:
  161. *
  162. * HWND hWnd
  163. * Handle of window to return IAccessible for.
  164. *
  165. * LPTSTR pClassName
  166. * Class name indicating underlying class of the window. For
  167. * example, if "LISTBOX" is used here, the returned object will
  168. * behave appropriately for a listbox, and will expect the given
  169. * hWnd to support listbox messages and styles. This argument
  170. * nearly always reflects the window class from which the control
  171. * is derived.
  172. *
  173. * LONG idObject
  174. * Always OBJID_CLIENT
  175. *
  176. * REFIID riid
  177. * Always IID_IAccessible
  178. *
  179. * void ** ppvObject
  180. * Out pointer used to return an IAccessible to a newly-created
  181. * object which represents the control hWnd as though it were of
  182. * window class pClassName.
  183. *
  184. * If successful,
  185. * returns S_OK, *ppvObject != NULL;
  186. * otherwise returns error HRESULT.
  187. *
  188. *
  189. */
  190. // Same for LresultFromObject...
  191. typedef LRESULT (WINAPI *PFNLRESULTFROMOBJECT)(
  192. REFIID riid,
  193. WPARAM wParam,
  194. LPUNKNOWN punk
  195. );
  196. PRIVATE PFNCREATESTDACCESSIBLEPROXY s_pfnCreateStdAccessibleProxy = NULL;
  197. PRIVATE PFNLRESULTFROMOBJECT s_pfnLresultFromObject = NULL;
  198. // Simple accessibility wrapper class which returns the right string values
  199. class CSecurityAccessibleWrapper: public CAccessibleWrapper
  200. {
  201. // Want to remember the hwnd of the trackbar...
  202. HWND m_hWnd;
  203. public:
  204. CSecurityAccessibleWrapper( HWND hWnd, IAccessible * pAcc );
  205. ~CSecurityAccessibleWrapper();
  206. STDMETHODIMP get_accValue(VARIANT varChild, BSTR* pszValue);
  207. };
  208. // Ctor - pass through the IAccessible we're wrapping to the
  209. // CAccessibleWrapper base class; also remember the trackbar hwnd.
  210. CSecurityAccessibleWrapper::CSecurityAccessibleWrapper( HWND hWnd, IAccessible * pAcc )
  211. : CAccessibleWrapper( pAcc ),
  212. m_hWnd( hWnd )
  213. {
  214. // Do nothing
  215. }
  216. // Nothing to do here - but if we do need to do cleanup, this is the
  217. // place for it.
  218. CSecurityAccessibleWrapper::~CSecurityAccessibleWrapper()
  219. {
  220. // Do nothing
  221. }
  222. // Overridden get_accValue method...
  223. STDMETHODIMP CSecurityAccessibleWrapper::get_accValue(VARIANT varChild, BSTR* pszValue)
  224. {
  225. // varChild.lVal specifies which sub-part of the component
  226. // is being queried.
  227. // CHILDID_SELF (0) specifies the overall component - other
  228. // non-0 values specify a child.
  229. // In a trackbar, CHILDID_SELF refers to the overall trackbar
  230. // (which is what we want), whereas other values refer to the
  231. // sub-components - the actual slider 'thumb', and the 'page
  232. // up/page down' areas to the left/right of it.
  233. if( varChild.vt == VT_I4 && varChild.lVal == CHILDID_SELF )
  234. {
  235. // Get the scrollbar value...
  236. int iPos = (int)SendMessage( m_hWnd, TBM_GETPOS , 0, 0 );
  237. // Check that it's in range...
  238. // (It's possible that we may get this request after the
  239. // trackbar has been created, bu before we've set it to
  240. // a meaningful value.)
  241. if( iPos < 0 || iPos >= NUM_TEMPLATE_LEVELS )
  242. {
  243. TCHAR rgchUndefined[40];
  244. int cch = MLLoadString(IDS_TEMPLATE_NAME_UNDEFINED, rgchUndefined, ARRAYSIZE(rgchUndefined));
  245. if (cch != 0)
  246. {
  247. *pszValue = SysAllocString(rgchUndefined);
  248. }
  249. else
  250. {
  251. // Load String failed, for some reason.
  252. return HRESULT_FROM_WIN32(GetLastError());
  253. }
  254. }
  255. else
  256. {
  257. *pszValue = SysAllocString( LEVEL_NAME[iPos]);
  258. }
  259. // All done!
  260. return S_OK;
  261. }
  262. else
  263. {
  264. // Pass requests about the sub-components to the
  265. // base class (which will forward to the 'original'
  266. // IAccessible for us).
  267. return CAccessibleWrapper::get_accValue(varChild, pszValue);
  268. }
  269. }
  270. // Converting the Security Level DWORD identitifiers to slider levels, and vice versa
  271. int SecLevelToSliderPos(DWORD dwLevel)
  272. {
  273. switch(dwLevel)
  274. {
  275. case URLTEMPLATE_LOW:
  276. return 3;
  277. case URLTEMPLATE_MEDLOW:
  278. return 2;
  279. case URLTEMPLATE_MEDIUM:
  280. return 1;
  281. case URLTEMPLATE_HIGH:
  282. return 0;
  283. case URLTEMPLATE_CUSTOM:
  284. return -1;
  285. default:
  286. return -2;
  287. }
  288. }
  289. DWORD SliderPosToSecLevel(int iPos)
  290. {
  291. switch(iPos)
  292. {
  293. case 3:
  294. return URLTEMPLATE_LOW;
  295. case 2:
  296. return URLTEMPLATE_MEDLOW;
  297. case 1:
  298. return URLTEMPLATE_MEDIUM;
  299. case 0:
  300. return URLTEMPLATE_HIGH;
  301. default:
  302. return URLTEMPLATE_CUSTOM;
  303. }
  304. }
  305. int ZoneIndexToGuiIndex(DWORD dwZoneIndex)
  306. // Product testing asked for the zones in a specific order in the list box;
  307. // This function returns the desired gui position for a given zone
  308. // Unrecognized zones are added to the front
  309. {
  310. int iGuiIndex = -1;
  311. switch(dwZoneIndex)
  312. {
  313. // Intranet: 2nd spot
  314. case 1:
  315. iGuiIndex = 1;
  316. break;
  317. // Internet: 1st spot
  318. case 3:
  319. iGuiIndex = 0;
  320. break;
  321. // Trusted Sites: 3rd Spot
  322. case 2:
  323. iGuiIndex = 2;
  324. break;
  325. // Restricted Sites: 4th Spot
  326. case 4:
  327. iGuiIndex = 3;
  328. break;
  329. // unknown zone
  330. default:
  331. iGuiIndex = -1;
  332. break;
  333. }
  334. return iGuiIndex;
  335. }
  336. // Initialize the global variables (to be destroyed at WM_DESTROY)
  337. // pSec, Urlmon, pSec->pInternetZoneManager, pSec->hIml
  338. // and set up the proper relationships among them
  339. BOOL SecurityInitGlobals(LPSECURITYPAGE * ppSec, HWND hDlg, SECURITYINITFLAGS * psif)
  340. {
  341. DWORD cxIcon;
  342. DWORD cyIcon;
  343. LPSECURITYPAGE pSec = NULL;
  344. *ppSec = (LPSECURITYPAGE)LocalAlloc(LPTR, sizeof(SECURITYPAGE));
  345. pSec = *ppSec;
  346. if (!pSec)
  347. {
  348. return FALSE; // no memory?
  349. }
  350. // make sure Urlmon stays around until we're done with it.
  351. pSec->hinstUrlmon = LoadLibrary(TEXT("URLMON.DLL"));
  352. if(pSec->hinstUrlmon == NULL)
  353. {
  354. return FALSE; // no urlmon?
  355. }
  356. // Get the zone manager
  357. if (FAILED(CoInternetCreateZoneManager(NULL, &(pSec->pInternetZoneManager),0)))
  358. {
  359. return FALSE; // no zone manager?
  360. }
  361. // get our zones hwnd
  362. pSec->hwndZones = GetDlgItem(hDlg, IDC_LIST_ZONE);
  363. if(! pSec->hwndZones)
  364. {
  365. ASSERT(FALSE);
  366. return FALSE; // no list box?
  367. }
  368. // Get the internet secrity manager (for telling if a zone is empty,
  369. // and deciphering the current URL
  370. if(FAILED(CoInternetCreateSecurityManager(NULL, &(pSec->pInternetSecurityManager), 0)))
  371. pSec->pInternetSecurityManager = NULL;
  372. // tell dialog where to get info
  373. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pSec);
  374. // save the handle to the page
  375. pSec->hDlg = hDlg;
  376. pSec->fPendingChange = FALSE;
  377. // set dialog options: force ui and disable add sites
  378. if(psif)
  379. {
  380. pSec->fForceUI = psif->fForceUI;
  381. pSec->fDisableAddSites = psif->fDisableAddSites;
  382. }
  383. // create an imagelist for the ListBox
  384. cxIcon = GetSystemMetrics(SM_CXICON);
  385. cyIcon = GetSystemMetrics(SM_CYICON);
  386. #ifndef UNIX
  387. UINT flags = ILC_COLOR32|ILC_MASK;
  388. if(IS_WINDOW_RTL_MIRRORED(hDlg))
  389. {
  390. flags |= ILC_MIRROR;
  391. }
  392. pSec->himl = ImageList_Create(cxIcon, cyIcon, flags, pSec->dwZoneCount, 0);
  393. #else
  394. pSec->himl = ImageList_Create(cxIcon, cyIcon, ILC_COLOR|ILC_MASK, pSec->dwZoneCount, 0);
  395. #endif
  396. if(! pSec->himl)
  397. {
  398. return FALSE; // Image list not created
  399. }
  400. SendMessage(pSec->hwndZones, LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)pSec->himl);
  401. return TRUE;
  402. }
  403. // Set up the variables in pSec about whether the zone settings can be editted
  404. void SecuritySetEdit(LPSECURITYPAGE pSec)
  405. {
  406. // if these calls fail then we'll use the default of zero which means no lockout
  407. DWORD cb;
  408. cb = SIZEOF(pSec->fNoEdit);
  409. SHGetValue(HKEY_LOCAL_MACHINE, REGSTR_PATH_SECURITY_LOCKOUT, REGSTR_VAL_OPTIONS_EDIT,
  410. NULL, &(pSec->fNoEdit), &cb);
  411. // also allow g_restrict to restrict changing settings
  412. pSec->fNoEdit += g_restrict.fSecChangeSettings;
  413. SHGetValue(HKEY_LOCAL_MACHINE, REGSTR_PATH_SECURITY_LOCKOUT, REGSTR_VAL_OPTIONS_EDIT,
  414. NULL, &(pSec->fNoAddSites), &cb);
  415. cb = SIZEOF(pSec->fNoZoneMapEdit);
  416. SHGetValue(HKEY_LOCAL_MACHINE, REGSTR_PATH_SECURITY_LOCKOUT, REGSTR_VAL_ZONES_MAP_EDIT,
  417. NULL, &(pSec->fNoZoneMapEdit), &cb);
  418. // also allow the g_restrict to restrict edit
  419. pSec->fNoAddSites += g_restrict.fSecAddSites;
  420. }
  421. // Fill a zone with information from the zone manager and add it to the
  422. // ordered list going to the listbox
  423. // REturn values:
  424. // S_OK indicates success
  425. // S_FALSE indicates a good state, but the zone was not added (example: flag ZAFLAGS_NO_UI)
  426. // E_OUTOFMEMORY
  427. // E_FAIL - other failure
  428. HRESULT SecurityInitZone(DWORD dwIndex, LPSECURITYPAGE pSec, DWORD dwZoneEnumerator,
  429. LV_ITEM * plviZones, BOOL * pfSpotTaken)
  430. {
  431. DWORD dwZone;
  432. ZONEATTRIBUTES za = {0};
  433. HICON hiconSmall = NULL;
  434. HICON hiconLarge = NULL;
  435. LPSECURITYZONESETTINGS pszs;
  436. WORD iIcon=0;
  437. LPWSTR psz;
  438. TCHAR szIconPath[MAX_PATH];
  439. int iSpot;
  440. LV_ITEM * plvItem;
  441. HRESULT hr = 0;
  442. // get the zone attributes for this zone
  443. za.cbSize = sizeof(ZONEATTRIBUTES);
  444. pSec->pInternetZoneManager->GetZoneAt(dwZoneEnumerator, dwIndex, &dwZone);
  445. hr = pSec->pInternetZoneManager->GetZoneAttributes(dwZone, &za);
  446. if(FAILED(hr))
  447. {
  448. return S_FALSE;
  449. }
  450. // if no ui, then ignore
  451. if ((za.dwFlags & ZAFLAGS_NO_UI) && !pSec->fForceUI)
  452. {
  453. return S_FALSE;
  454. }
  455. // create a structure for zone settings
  456. pszs = (LPSECURITYZONESETTINGS)LocalAlloc(LPTR, sizeof(*pszs));
  457. if (!pszs)
  458. {
  459. return E_OUTOFMEMORY;
  460. }
  461. // store settings for later use
  462. pszs->dwFlags = za.dwFlags;
  463. pszs->dwZoneIndex = dwZone;
  464. pszs->dwSecLevel = za.dwTemplateCurrentLevel;
  465. pszs->dwMinSecLevel = za.dwTemplateMinLevel;
  466. pszs->dwRecSecLevel = za.dwTemplateRecommended;
  467. StrCpyN(pszs->szDescription, za.szDescription, ARRAYSIZE(pszs->szDescription));
  468. StrCpyN(pszs->szDisplayName, za.szDisplayName, ARRAYSIZE(pszs->szDisplayName));
  469. // load the icon
  470. psz = za.szIconPath;
  471. if (*psz)
  472. {
  473. // search for the '#'
  474. while ((psz[0] != WIDETEXT('#')) && (psz[0] != WIDETEXT('\0')))
  475. psz++;
  476. // if we found it, then we have the foo.dll#00001200 format
  477. if (psz[0] == WIDETEXT('#'))
  478. {
  479. psz[0] = WIDETEXT('\0');
  480. StrCpyN(szIconPath, za.szIconPath, ARRAYSIZE(szIconPath));
  481. iIcon = (WORD)StrToIntW(psz+1);
  482. CHAR szPath[MAX_PATH];
  483. SHUnicodeToAnsi(szIconPath, szPath, ARRAYSIZE(szPath));
  484. ExtractIconExA(szPath,(UINT)(-1*iIcon), &hiconLarge, &hiconSmall, 1);
  485. }
  486. else
  487. {
  488. hiconLarge = (HICON)ExtractAssociatedIcon(ghInstance, szIconPath, (LPWORD)&iIcon);
  489. }
  490. }
  491. // no icons?! well, just use the generic icon
  492. if (!hiconSmall && !hiconLarge)
  493. {
  494. hiconLarge = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_ZONE));
  495. if(! hiconLarge)
  496. {
  497. LocalFree((HLOCAL)pszs);
  498. return S_FALSE; // no icon found for this zone, not even the generic one
  499. }
  500. }
  501. // we want to save the Large icon if possible for use in the subdialogs
  502. pszs->hicon = hiconLarge ? hiconLarge : hiconSmall;
  503. // Find the proper index for the zone in the listbox (there is a user-preferred order)
  504. iSpot = ZoneIndexToGuiIndex(dwIndex);
  505. if(iSpot == -1)
  506. {
  507. // if not a recognized zone, add it to the end of the list
  508. iSpot = pSec->dwZoneCount - 1;
  509. }
  510. // Make sure there are no collisisons
  511. while(iSpot >= 0 && pfSpotTaken[iSpot] == TRUE)
  512. {
  513. iSpot--;
  514. }
  515. // Don't go past beginning of array
  516. if(iSpot < 0)
  517. {
  518. // It can be proven that it is impossible to get here, unless there is
  519. // something wrong with the function ZoneIndexToGuiIndex
  520. ASSERT(FALSE);
  521. LocalFree((HLOCAL)pszs);
  522. if(hiconSmall)
  523. DestroyIcon(hiconSmall);
  524. if(hiconLarge)
  525. DestroyIcon(hiconLarge);
  526. return E_FAIL;
  527. }
  528. plvItem = &(plviZones[iSpot]);
  529. pfSpotTaken[iSpot] = TRUE;
  530. // init the List Box item and save it for later addition
  531. plvItem->mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  532. plvItem->iItem = iSpot;
  533. plvItem->iSubItem = 0;
  534. // large icons prefered for the icon view (if switch back to report view, prefer small icons)
  535. plvItem->iImage = ImageList_AddIcon(pSec->himl, hiconLarge ? hiconLarge : hiconSmall);
  536. plvItem->pszText = new TCHAR[MAX_PATH];
  537. if(! plvItem->pszText)
  538. {
  539. LocalFree((HLOCAL)pszs);
  540. if(hiconSmall)
  541. DestroyIcon(hiconSmall);
  542. if(hiconLarge)
  543. DestroyIcon(hiconLarge);
  544. return E_OUTOFMEMORY;
  545. }
  546. MLLoadString( IDS_ZONENAME_LOCAL + dwIndex, plvItem->pszText, MAX_PATH);
  547. plvItem->lParam = (LPARAM)pszs; // save the zone settings here
  548. // if we created a small icon, destroy it, since the system does not save the handle
  549. // when it is added to the imagelist (see ImageList_AddIcon in VC help)
  550. // Keep it around if we had to use it in place of the large icon
  551. if (hiconSmall && hiconLarge)
  552. DestroyIcon(hiconSmall);
  553. return S_OK;
  554. }
  555. // Find the current zone from, in order of preference,
  556. // Current URL
  557. // Parameter passed in through dwZone
  558. // Default of internet
  559. void SecurityFindCurrentZone(LPSECURITYPAGE pSec, SECURITYINITFLAGS * psif)
  560. {
  561. INT_PTR iItem;
  562. DWORD dwZone=0;
  563. HRESULT hr = E_FAIL;
  564. // Check for zone selection in psif
  565. if(psif)
  566. {
  567. dwZone = psif->dwZone;
  568. hr = S_OK;
  569. }
  570. // check for current url, and if found, make it's zone the current (overwriting any request from
  571. // psif)
  572. if (g_szCurrentURL[0] && (pSec->pInternetSecurityManager != NULL))
  573. {
  574. LPWSTR pwsz;
  575. #ifndef UNICODE
  576. WCHAR wszCurrentURL[MAX_URL_STRING];
  577. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, g_szCurrentURL, -1, wszCurrentURL, ARRAYSIZE(wszCurrentURL));
  578. pwsz = wszCurrentURL;
  579. #else
  580. pwsz = g_szCurrentURL;
  581. #endif
  582. hr = pSec->pInternetSecurityManager->MapUrlToZone(pwsz, (LPDWORD)&dwZone, 0);
  583. }
  584. // If there is an active zone, then dwZone now holds the zone's identifier
  585. // if there is no active zone, check to see if there was a zone requested in dwZone
  586. iItem = -1;
  587. if (SUCCEEDED(hr)) // then we have a zone to display
  588. {
  589. ZONEATTRIBUTES za = {0};
  590. LPTSTR pszText;
  591. LV_FINDINFO lvfiName;
  592. za.cbSize = (ULONG) sizeof(ZONEATTRIBUTES);
  593. if(pSec->pInternetZoneManager->GetZoneAttributes(dwZone, &za) != E_FAIL)
  594. {
  595. #ifdef UNICODE
  596. pszText = za.szDisplayName;
  597. #else
  598. CHAR szDisplayName[MAX_ZONE_PATH];
  599. WideCharToMultiByte(CP_ACP, 0, za.szDisplayName, -1, szDisplayName, ARRAYSIZE(szDisplayName), NULL, NULL);
  600. pszText = szDisplayName;
  601. #endif // UNICODE
  602. // Create a find info structure to find the index of the Zone
  603. lvfiName.flags = LVFI_STRING;
  604. lvfiName.psz = pszText;
  605. iItem = SendMessage(pSec->hwndZones, LVM_FINDITEM, (WPARAM)-1, (LPARAM)&lvfiName);
  606. }
  607. }
  608. if (iItem < 0)
  609. {
  610. iItem = 0;
  611. // 0 is the the index (in the listbox) of the "Internet" zone, which we want to come up by default
  612. }
  613. // Sundown: typecast OK since zone values restricted
  614. pSec->iZoneSel = (int) iItem;
  615. }
  616. // To make the slider control accessbile we have to subclass it and over-ride
  617. // the accessiblity object
  618. void SecurityInitSlider(LPSECURITYPAGE pSec)
  619. {
  620. HWND hwndSlider = GetDlgItem(pSec->hDlg, IDC_SLIDER);
  621. ASSERT(hwndSlider != NULL);
  622. // Sub-class the control
  623. BOOL fSucceeded = SetWindowSubclass(hwndSlider, SliderSubWndProc, 0, NULL);
  624. // Shouldn't fail normally. If we fail we will just fall through and use the
  625. // base slider control.
  626. ASSERT(fSucceeded);
  627. // Initialize the slider control (set number of levels, and frequency one tick per level)
  628. SendDlgItemMessage(pSec->hDlg, IDC_SLIDER, TBM_SETRANGE, (WPARAM) (BOOL) FALSE, (LPARAM) MAKELONG(0, NUM_TEMPLATE_LEVELS - 1));
  629. SendDlgItemMessage(pSec->hDlg, IDC_SLIDER, TBM_SETTICFREQ, (WPARAM) 1, (LPARAM) 0);
  630. }
  631. void SecurityInitControls(LPSECURITYPAGE pSec)
  632. {
  633. LV_COLUMN lvCasey;
  634. LV_ITEM lvItem;
  635. // select the item in the listbox
  636. lvItem.mask = LVIF_STATE;
  637. lvItem.stateMask = LVIS_SELECTED;
  638. lvItem.state = LVIS_SELECTED;
  639. SendMessage(pSec->hwndZones, LVM_SETITEMSTATE, (WPARAM)pSec->iZoneSel, (LPARAM)&lvItem);
  640. // get the zone settings for the selected item
  641. lvItem.mask = LVIF_PARAM;
  642. lvItem.iItem = pSec->iZoneSel;
  643. lvItem.iSubItem = 0;
  644. SendMessage(pSec->hwndZones, LVM_GETITEM, (WPARAM)0, (LPARAM)&lvItem);
  645. pSec->pszs = (LPSECURITYZONESETTINGS)lvItem.lParam;
  646. // Initialize the local strings to carry the Level Descriptions
  647. MLLoadString(IDS_TEMPLATE_DESC_HI, LEVEL_DESCRIPTION0, ARRAYSIZE(LEVEL_DESCRIPTION0));
  648. MLLoadString(IDS_TEMPLATE_DESC_MED, LEVEL_DESCRIPTION1, ARRAYSIZE(LEVEL_DESCRIPTION1));
  649. MLLoadString(IDS_TEMPLATE_DESC_MEDLOW, LEVEL_DESCRIPTION2, ARRAYSIZE(LEVEL_DESCRIPTION2));
  650. MLLoadString(IDS_TEMPLATE_DESC_LOW, LEVEL_DESCRIPTION3, ARRAYSIZE(LEVEL_DESCRIPTION3));
  651. MLLoadString(IDS_TEMPLATE_DESC_CUSTOM, CUSTOM_DESCRIPTION, ARRAYSIZE(CUSTOM_DESCRIPTION));
  652. MLLoadString(IDS_TEMPLATE_NAME_HI, LEVEL_NAME0, ARRAYSIZE(LEVEL_NAME0));
  653. MLLoadString(IDS_TEMPLATE_NAME_MED, LEVEL_NAME1, ARRAYSIZE(LEVEL_NAME1));
  654. MLLoadString(IDS_TEMPLATE_NAME_MEDLOW, LEVEL_NAME2, ARRAYSIZE(LEVEL_NAME2));
  655. MLLoadString(IDS_TEMPLATE_NAME_LOW, LEVEL_NAME3, ARRAYSIZE(LEVEL_NAME3));
  656. MLLoadString(IDS_TEMPLATE_NAME_CUSTOM, CUSTOM_NAME, ARRAYSIZE(CUSTOM_NAME));
  657. // Initialize text boxes and icons for the current zone
  658. WCHAR wszBuffer[ MAX_PATH*2];
  659. MLLoadString( IDS_ZONEDESC_LOCAL + pSec->pszs->dwZoneIndex, wszBuffer, ARRAYSIZE(wszBuffer));
  660. SetDlgItemText(pSec->hDlg, IDC_ZONE_DESCRIPTION, wszBuffer);
  661. MLLoadString( IDS_ZONENAME_LOCAL + pSec->pszs->dwZoneIndex, wszBuffer, ARRAYSIZE(wszBuffer));
  662. SetDlgItemText(pSec->hDlg, IDC_ZONELABEL, wszBuffer);
  663. SendDlgItemMessage(pSec->hDlg, IDC_ZONE_ICON, STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)pSec->pszs->hicon);
  664. // Initialize the slider control
  665. SecurityInitSlider(pSec);
  666. // Initialize the list view (add column 0 for icon and text, and autosize it)
  667. lvCasey.mask = 0;
  668. SendDlgItemMessage(pSec->hDlg, IDC_LIST_ZONE, LVM_INSERTCOLUMN, (WPARAM) 0, (LPARAM) &lvCasey);
  669. SendDlgItemMessage(pSec->hDlg, IDC_LIST_ZONE, LVM_SETCOLUMNWIDTH, (WPARAM) 0, (LPARAM) MAKELPARAM(LVSCW_AUTOSIZE, 0));
  670. // Set the font of the name to the bold font
  671. pSec->hfontBolded = NULL;
  672. HFONT hfontOrig = (HFONT) SendDlgItemMessage(pSec->hDlg, IDC_STATIC_EMPTY, WM_GETFONT, (WPARAM) 0, (LPARAM) 0);
  673. if(hfontOrig == NULL)
  674. hfontOrig = (HFONT) GetStockObject(SYSTEM_FONT);
  675. // set the zone name and level font to bolded
  676. if(hfontOrig)
  677. {
  678. LOGFONT lfData;
  679. if(GetObject(hfontOrig, SIZEOF(lfData), &lfData) != 0)
  680. {
  681. // The distance from 400 (normal) to 700 (bold)
  682. lfData.lfWeight += 300;
  683. if(lfData.lfWeight > 1000)
  684. lfData.lfWeight = 1000;
  685. pSec->hfontBolded = CreateFontIndirect(&lfData);
  686. if(pSec->hfontBolded)
  687. {
  688. // the zone level and zone name text boxes should have the same font, so this is okat
  689. SendDlgItemMessage(pSec->hDlg, IDC_ZONELABEL, WM_SETFONT, (WPARAM) pSec->hfontBolded, (LPARAM) MAKELPARAM(FALSE, 0));
  690. SendDlgItemMessage(pSec->hDlg, IDC_LEVEL_NAME, WM_SETFONT, (WPARAM) pSec->hfontBolded, (LPARAM) MAKELPARAM(FALSE, 0));
  691. }
  692. }
  693. }
  694. /*
  695. {
  696. // calculate the postions of the static text boxes for the "The current level is:" "<bold>(Level)</bold>" message
  697. TCHAR * pszText = NULL;
  698. LONG lLength = 30;
  699. HDC hdc = NULL;
  700. SIZE size;
  701. RECT rect;
  702. LONG lNameLeftPos = 0;
  703. // Get the text from the "The current level is" box.
  704. lLength = SendDlgItemMessage(pSec->hDlg, IDC_SEC_STATIC_CURRENT_LEVEL, WM_GETTEXTLENGTH,
  705. (WPARAM) 0, (LPARAM) 0);
  706. pszText = new TCHAR[lLength + 1];
  707. if(!pszText)
  708. goto Exit; // E_OUTOFMEMORY
  709. SendDlgItemMessage(pSec->hDlg, IDC_SEC_STATIC_CURRENT_LEVEL, WM_GETTEXT, (WPARAM) lLength,
  710. (LPARAM) pszText);
  711. // get the device context
  712. hdc = GetDC(GetDlgItem(pSec->hDlg, IDC_SEC_STATIC_CURRENT_LEVEL));
  713. if(! hdc)
  714. goto Exit;
  715. // get the length of the text from the device context; assumes the proper font is already in
  716. if(GetTextExtentPoint32(hdc, pszText, lLength, &size) == 0)
  717. goto Exit;
  718. // set the width of the "The current level is" box
  719. GetClientRect(GetDlgItem(pSec->hDlg, IDC_SEC_STATIC_CURRENT_LEVEL), &rect);
  720. rect.right = rect.left + size.cx;
  721. lNameLeftPos = rect.right;
  722. if(MoveWindow(GetDlgItem(pSec->hDlg, IDC_SEC_STATIC_CURRENT_LEVEL), rect.left, rect.top,
  723. rect.right - rect.left, rect.top - rect.bottom, FALSE) == 0)
  724. goto Exit;
  725. // set the x position of the level name box
  726. GetClientRect(GetDlgItem(pSec->hDlg, IDC_LEVEL_NAME), &rect);
  727. rect.left = lNameLeftPos;
  728. if(MoveWindow(GetDlgItem(pSec->hDlg, IDC_LEVEL_NAME), rect.left,
  729. rect.top, rect.right - rect.left, rect.top - rect.bottom, FALSE) == 0)
  730. goto Exit;
  731. Exit:
  732. if(hdc)
  733. ReleaseDC(GetDlgItem(pSec->hDlg, IDC_SEC_STATIC_CURRENT_LEVEL), hdc);
  734. if(pszText)
  735. delete pszText;
  736. }
  737. */
  738. }
  739. //
  740. // SecurityDlgInit()
  741. //
  742. // Does initalization for Security Dlg.
  743. //
  744. // History:
  745. //
  746. // 6/17/96 t-gpease remove 'gPrefs', cleaned up code
  747. // 6/20/96 t-gpease UI changes
  748. // 5/14/97 t-ashlm UI changes
  749. //
  750. // 7/02/97 t-mattp UI changes (slider, listbox)
  751. //
  752. // hDlg is the handle to the SecurityDialog window
  753. // psif holds initialization parameters. In the case of our entry point
  754. // from shdocvw (ie, double click browser zone icon, view-internetoptions-security, or right click
  755. // on desktop icon), it can be NULL
  756. BOOL SecurityDlgInit(HWND hDlg, SECURITYINITFLAGS * psif)
  757. {
  758. LPSECURITYPAGE pSec = NULL;
  759. UINT iIndex = 0;
  760. HRESULT hr = 0;
  761. DWORD dwZoneEnumerator;
  762. // Initialize globals variables (to be destroyed at WM_DESTROY)
  763. if(SecurityInitGlobals(&pSec, hDlg, psif) == FALSE)
  764. {
  765. EndDialog(hDlg, 0);
  766. return FALSE; // Initialization failed
  767. }
  768. // Get a (local) enumerator for the zones
  769. if (FAILED(pSec->pInternetZoneManager->
  770. CreateZoneEnumerator(&dwZoneEnumerator, &(pSec->dwZoneCount), 0)))
  771. {
  772. EndDialog(hDlg, 0);
  773. return FALSE; // no zone enumerator?
  774. }
  775. // Set up the variables in pSec about whether the zone settings can be editted
  776. SecuritySetEdit(pSec);
  777. // Add the Listbox items for the zones
  778. // The zones have to be added in a particular order
  779. // Array used to order zones for adding
  780. LV_ITEM * plviZones = new LV_ITEM[pSec->dwZoneCount];
  781. BOOL * pfSpotTaken = new BOOL[pSec->dwZoneCount];
  782. for(iIndex =0; iIndex < pSec->dwZoneCount; iIndex++)
  783. pfSpotTaken[iIndex] = FALSE;
  784. // propogate zone dropdown
  785. for (DWORD dwIndex=0; dwIndex < pSec->dwZoneCount; dwIndex++)
  786. {
  787. if(FAILED(SecurityInitZone(dwIndex, pSec, dwZoneEnumerator, plviZones, pfSpotTaken)))
  788. {
  789. // Delete all memory allocated for any previous zones (which have not yet been added to
  790. // the listbox)
  791. for(iIndex = 0; iIndex < pSec->dwZoneCount; iIndex++)
  792. {
  793. if(pfSpotTaken[iIndex] && (LPSECURITYZONESETTINGS) (plviZones[iIndex].lParam) != NULL)
  794. {
  795. LocalFree((LPSECURITYZONESETTINGS) (plviZones[iIndex].lParam));
  796. plviZones[iIndex].lParam = NULL;
  797. if(plviZones[iIndex].pszText)
  798. delete [] plviZones[iIndex].pszText;
  799. }
  800. }
  801. delete [] plviZones;
  802. delete [] pfSpotTaken;
  803. pSec->pInternetZoneManager->DestroyZoneEnumerator(dwZoneEnumerator);
  804. EndDialog(hDlg, 0);
  805. return FALSE;
  806. }
  807. }
  808. pSec->pInternetZoneManager->DestroyZoneEnumerator(dwZoneEnumerator);
  809. // Add all of the arrayed listitems to the listbox
  810. for(iIndex = 0; iIndex < pSec->dwZoneCount; iIndex++)
  811. {
  812. if(pfSpotTaken[iIndex])
  813. {
  814. SendMessage(pSec->hwndZones, LVM_INSERTITEM, (WPARAM)0, (LPARAM)&(plviZones[iIndex]));
  815. delete [] plviZones[iIndex].pszText;
  816. }
  817. }
  818. delete [] plviZones;
  819. delete [] pfSpotTaken;
  820. SecurityFindCurrentZone(pSec, psif);
  821. SecurityInitControls(pSec);
  822. SecurityEnableControls(pSec, FALSE);
  823. return TRUE;
  824. }
  825. void SecurityChanged()
  826. {
  827. TCHAR szClassName[32];
  828. HWND hwnd = GetTopWindow(GetDesktopWindow());
  829. //
  830. // FEATURE: These should be gotten from some place that is public
  831. // to both MSHTML and INETCPL.
  832. //
  833. while (hwnd) {
  834. GetClassName(hwnd, szClassName, ARRAYSIZE(szClassName));
  835. // notify all "browser" windows that security has changed
  836. if (!StrCmpI(szClassName, TEXT("ExploreWClass")) ||
  837. !StrCmpI(szClassName, TEXT("IEFrame")) ||
  838. !StrCmpI(szClassName, TEXT("CabinetWClass")))
  839. {
  840. // yes... post it a message..
  841. PostMessage(hwnd, CWM_GLOBALSTATECHANGE, CWMF_SECURITY, 0L );
  842. }
  843. hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
  844. }
  845. }
  846. int SecurityWarning(LPSECURITYPAGE pSec)
  847. {
  848. TCHAR szWarning[64];
  849. TCHAR szBuf[512];
  850. TCHAR szMessage[512];
  851. TCHAR szLevel[64];
  852. // Load "Warning!"
  853. MLLoadShellLangString(IDS_WARNING, szWarning, ARRAYSIZE(szWarning));
  854. // Load "It is not recommended...."
  855. MLLoadShellLangString(IDS_SECURITY_WARNING, szBuf, ARRAYSIZE(szBuf));
  856. // Load level: "High, Medium, Medium Low, Low"
  857. if (pSec->pszs->dwMinSecLevel == URLTEMPLATE_HIGH)
  858. MLLoadShellLangString(IDS_TEMPLATE_NAME_HI, szLevel, ARRAYSIZE(szLevel));
  859. else if (pSec->pszs->dwMinSecLevel == URLTEMPLATE_MEDIUM)
  860. MLLoadShellLangString(IDS_TEMPLATE_NAME_MED, szLevel, ARRAYSIZE(szLevel));
  861. else if (pSec->pszs->dwMinSecLevel == URLTEMPLATE_MEDLOW)
  862. MLLoadShellLangString(IDS_TEMPLATE_NAME_MEDLOW, szLevel, ARRAYSIZE(szLevel));
  863. else
  864. MLLoadShellLangString(IDS_TEMPLATE_NAME_LOW, szLevel, ARRAYSIZE(szLevel));
  865. wnsprintf(szMessage, ARRAYSIZE(szMessage), szBuf, szLevel);
  866. return MessageBox(pSec->hDlg,szMessage,szWarning, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
  867. }
  868. int RegWriteWarning(HWND hParent)
  869. {
  870. TCHAR szWarning[64];
  871. TCHAR szWriteWarning[128];
  872. // load "Warning!"
  873. MLLoadShellLangString(IDS_WARNING, szWarning, ARRAYSIZE(szWarning));
  874. // Load "You are about to write..."
  875. MLLoadShellLangString(IDS_WRITE_WARNING, szWriteWarning, ARRAYSIZE(szWriteWarning));
  876. return MessageBox(hParent,szWriteWarning, szWarning, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
  877. }
  878. BOOL SecurityEnableControls(LPSECURITYPAGE pSec, BOOL fSetFocus)
  879. // Duties:
  880. // Make the controls (slider, en/disabled buttons) match the data for the current zone
  881. // Make the views (Level description text) match the data for the current zone
  882. // Set focus (to slider, if enabled, else custom settings button, if enabled, else
  883. // listbox) if fSetFocus is TRUE
  884. // Note: the zone descriptions are not set here; those are handled by the code responsible
  885. // for changing zones
  886. {
  887. int iLevel = -1;
  888. if (pSec && pSec->pszs)
  889. {
  890. HWND hwndSlider = GetDlgItem(pSec->hDlg, IDC_SLIDER);
  891. iLevel = SecLevelToSliderPos(pSec->pszs->dwSecLevel);
  892. ASSERT(iLevel > -2);
  893. // Set the level of the slider to the setting for the current zone
  894. // Show or hide the slider for preset levels/custom
  895. // Set the level description text
  896. if(iLevel >= 0)
  897. {
  898. SendMessage(hwndSlider, TBM_SETPOS, (WPARAM) (BOOL) TRUE, (LPARAM) (LONG) iLevel);
  899. // Make sure the slider is visible
  900. ShowWindow(hwndSlider, SW_SHOW);
  901. ShowWindow(GetDlgItem(pSec->hDlg, IDC_STATIC_SLIDERMOVETEXT), SW_SHOW);
  902. SetDlgItemText(pSec->hDlg, IDC_LEVEL_DESCRIPTION, LEVEL_DESCRIPTION[iLevel]);
  903. SetDlgItemText(pSec->hDlg, IDC_LEVEL_NAME, LEVEL_NAME[iLevel]);
  904. }
  905. else
  906. {
  907. // Hide the slider for custom
  908. ShowWindow(hwndSlider, SW_HIDE);
  909. ShowWindow(GetDlgItem(pSec->hDlg, IDC_STATIC_SLIDERMOVETEXT), SW_HIDE);
  910. SetDlgItemText(pSec->hDlg, IDC_LEVEL_DESCRIPTION, CUSTOM_DESCRIPTION);
  911. SetDlgItemText(pSec->hDlg, IDC_LEVEL_NAME, CUSTOM_NAME);
  912. }
  913. // If the zone is empty, show the "zone is empty" string
  914. // Default is to not show the sting (if something goes wrong)
  915. // Empty zone not possible for internet, intranet, or local zones
  916. if((pSec->pszs->dwZoneIndex != URLZONE_INTRANET &&
  917. pSec->pszs->dwZoneIndex != URLZONE_INTERNET) &&
  918. pSec->pszs->dwZoneIndex != URLZONE_LOCAL_MACHINE &&
  919. (pSec->pInternetSecurityManager != NULL))
  920. {
  921. IEnumString * piesZones = NULL;
  922. LPOLESTR ppszDummy[1];
  923. pSec->pInternetSecurityManager->GetZoneMappings(pSec->pszs->dwZoneIndex, &piesZones, 0);
  924. // If enumerator can not get 1 item, zone is empty (not valid for internet and intranet)
  925. if(piesZones && (piesZones->Next(1, ppszDummy, NULL) == S_FALSE))
  926. {
  927. ShowWindow(GetDlgItem(pSec->hDlg, IDC_STATIC_EMPTY), SW_SHOW);
  928. }
  929. else
  930. {
  931. ShowWindow(GetDlgItem(pSec->hDlg, IDC_STATIC_EMPTY), SW_HIDE);
  932. }
  933. if(piesZones)
  934. piesZones->Release();
  935. }
  936. else
  937. {
  938. ShowWindow(GetDlgItem(pSec->hDlg, IDC_STATIC_EMPTY), SW_HIDE);
  939. }
  940. // If we were told to set focus then move focus to the slider.
  941. if (fSetFocus)
  942. {
  943. if(!pSec->fNoEdit)
  944. {
  945. if(iLevel >= 0)
  946. SetFocus(hwndSlider);
  947. else if(pSec->pszs->dwFlags & ZAFLAGS_CUSTOM_EDIT)
  948. SetFocus(GetDlgItem(pSec->hDlg, IDC_BUTTON_SETTINGS));
  949. else
  950. SetFocus(GetDlgItem(pSec->hDlg, IDC_LIST_ZONE));
  951. }
  952. else // No focus is allowed, set focus to the list box
  953. {
  954. SetFocus(GetDlgItem(pSec->hDlg, IDC_LIST_ZONE));
  955. }
  956. }
  957. EnableWindow(hwndSlider, (iLevel >= 0) && !pSec->fNoEdit);
  958. EnableWindow(GetDlgItem(pSec->hDlg, IDC_ZONE_RESET),
  959. !pSec->fNoEdit && (pSec->pszs->dwSecLevel != pSec->pszs->dwRecSecLevel));
  960. EnableWindow(GetDlgItem(pSec->hDlg, IDC_BUTTON_SETTINGS),
  961. (pSec->pszs->dwFlags & ZAFLAGS_CUSTOM_EDIT) && !pSec->fNoEdit);
  962. EnableWindow(GetDlgItem(pSec->hDlg, IDC_BUTTON_ADD_SITES),
  963. (pSec->pszs->dwFlags & ZAFLAGS_ADD_SITES) && !pSec->fDisableAddSites);
  964. return TRUE;
  965. }
  966. return FALSE;
  967. }
  968. void SecuritySetLevel(DWORD dwLevel, LPSECURITYPAGE pSec)
  969. {
  970. // All calls to this function are requests to change the security
  971. // level for the current zone
  972. // dwLevel = requested level template (URLTEMPLATE_???)
  973. int iPos = SecLevelToSliderPos(dwLevel);
  974. ASSERT(iPos != -2);
  975. BOOL bCanceled = FALSE;
  976. // Do nothing if the requested level is equal to the current level
  977. if(dwLevel != pSec->pszs->dwSecLevel)
  978. {
  979. // Pop up warning box if under recommended min level and lowering security (custom N/A)
  980. if((pSec->pszs->dwMinSecLevel > dwLevel) && (pSec->pszs->dwSecLevel > dwLevel)
  981. && (dwLevel != URLTEMPLATE_CUSTOM))
  982. {
  983. if(SecurityWarning(pSec) == IDNO)
  984. {
  985. bCanceled = TRUE;
  986. }
  987. }
  988. if(! bCanceled)
  989. {
  990. // Set the level
  991. pSec->pszs->dwPrevSecLevel = pSec->pszs->dwSecLevel;
  992. pSec->pszs->dwSecLevel = dwLevel;
  993. ENABLEAPPLY(pSec->hDlg);
  994. //Tell apply and ok that settings have been changed
  995. pSec->fChanged = TRUE;
  996. }
  997. // Sync the controls to the new level (or back to the old if cancelled)
  998. SecurityEnableControls(pSec, TRUE);
  999. }
  1000. // Record that the change request has been handled
  1001. pSec->fPendingChange = FALSE;
  1002. }
  1003. //
  1004. // SecurityDlgApplyNow()
  1005. //
  1006. // Retrieves the user's choices in dlg ctls,
  1007. // and saves them through SecurityManager interfaces
  1008. // If bSaveAll is true, the data for all zones is saved,
  1009. // if false, only the current
  1010. // Return value is whether the changes were okayed
  1011. //
  1012. BOOL SecurityDlgApplyNow(LPSECURITYPAGE pSec, BOOL bSaveAll)
  1013. {
  1014. if (pSec->fChanged)
  1015. {
  1016. for (int iIndex = (int)SendMessage(pSec->hwndZones, LVM_GETITEMCOUNT, 0, 0) - 1;
  1017. iIndex >= 0; iIndex--)
  1018. {
  1019. if(!((bSaveAll) || (iIndex == pSec->iZoneSel)))
  1020. continue;
  1021. LV_ITEM lvItem = {0};
  1022. ZONEATTRIBUTES za = {0};
  1023. LPSECURITYZONESETTINGS pszs;
  1024. // get the item settings
  1025. lvItem.mask = LVIF_PARAM;
  1026. lvItem.iItem = iIndex;
  1027. lvItem.iSubItem = 0;
  1028. if(SendMessage(pSec->hwndZones, LVM_GETITEM, (WPARAM)0, (LPARAM)&lvItem))
  1029. {
  1030. pszs = (LPSECURITYZONESETTINGS)lvItem.lParam;
  1031. za.cbSize = sizeof(ZONEATTRIBUTES);
  1032. pSec->pInternetZoneManager->GetZoneAttributes(pszs->dwZoneIndex, &za);
  1033. za.dwTemplateCurrentLevel = pszs->dwSecLevel;
  1034. pSec->pInternetZoneManager->SetZoneAttributes(pszs->dwZoneIndex, &za);
  1035. // Custom settings are saved on exit from the Custom Settings window
  1036. }
  1037. }
  1038. UpdateAllWindows();
  1039. SecurityChanged();
  1040. if (bSaveAll)
  1041. {
  1042. // if bSaveAll is false, that means we're saving the info for one zone, but not
  1043. // the others. This happens when you have custom settings for a particular zone
  1044. // However, other zones may have been changed to only one of the standard settings
  1045. // We need to ensure that those settings also get saved when the user clicks OK/Apply.
  1046. pSec->fChanged = FALSE;
  1047. }
  1048. }
  1049. return TRUE;
  1050. }
  1051. //
  1052. // SecurityOnCommand()
  1053. //
  1054. // Handles Security Dialog's window messages
  1055. //
  1056. // History:
  1057. //
  1058. // 6/17/96 t-gpease created
  1059. // 5/14/97 t-ashlm ui changes
  1060. //
  1061. void SecurityOnCommand(LPSECURITYPAGE pSec, UINT id, UINT nCmd)
  1062. {
  1063. switch (id)
  1064. {
  1065. case IDC_BUTTON_ADD_SITES:
  1066. {
  1067. if (pSec->pszs->dwZoneIndex == URLZONE_INTRANET)
  1068. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SECURITY_INTRANET), pSec->hDlg,
  1069. SecurityAddSitesIntranetDlgProc, (LPARAM)pSec);
  1070. else
  1071. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SECURITY_ADD_SITES), pSec->hDlg,
  1072. SecurityAddSitesDlgProc, (LPARAM)pSec);
  1073. // Resynch controls (in case the "zone is empty" message needs to be updated)
  1074. SecurityEnableControls(pSec, FALSE);
  1075. }
  1076. break;
  1077. case IDC_BUTTON_SETTINGS:
  1078. {
  1079. // Note: messages to change the level from preset to custom as a result of this call
  1080. // are sent by the CustomSettings dialog
  1081. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SECURITY_CUSTOM_SETTINGS), pSec->hDlg,
  1082. SecurityCustomSettingsDlgProc, (LPARAM)pSec);
  1083. break;
  1084. }
  1085. case IDC_ZONE_RESET:
  1086. if(!pSec->fPendingChange && pSec->pszs->dwSecLevel != pSec->pszs->dwRecSecLevel)
  1087. {
  1088. pSec->fPendingChange = TRUE;
  1089. PostMessage(pSec->hDlg, WM_APP, (WPARAM) 0, (LPARAM) pSec->pszs->dwRecSecLevel);
  1090. }
  1091. break;
  1092. case IDOK:
  1093. SecurityDlgApplyNow(pSec, TRUE);
  1094. EndDialog(pSec->hDlg, IDOK);
  1095. break;
  1096. case IDCANCEL:
  1097. EndDialog(pSec->hDlg, IDCANCEL);
  1098. break;
  1099. case IDC_SLIDER:
  1100. {
  1101. // Get the current slider position
  1102. // Sundown: forced typecast to int, slider positions are restricted
  1103. int iPos = (int) SendDlgItemMessage(pSec->hDlg, IDC_SLIDER, TBM_GETPOS, (WPARAM) 0, (LPARAM) 0);
  1104. if(nCmd == TB_THUMBTRACK)
  1105. {
  1106. // on Mouse Move, change the level description only
  1107. SetDlgItemText(pSec->hDlg, IDC_LEVEL_DESCRIPTION, LEVEL_DESCRIPTION[iPos]);
  1108. SetDlgItemText(pSec->hDlg, IDC_LEVEL_NAME, LEVEL_NAME[iPos]);
  1109. }
  1110. else
  1111. {
  1112. // Request that the current zone's security level be set to the corresponding level
  1113. DWORD_PTR dwLevel = SliderPosToSecLevel(iPos);
  1114. if(! pSec->fPendingChange)
  1115. {
  1116. pSec->fPendingChange = TRUE;
  1117. PostMessage(pSec->hDlg, WM_APP, (WPARAM) 0, (LPARAM) dwLevel);
  1118. }
  1119. }
  1120. }
  1121. break;
  1122. case IDC_LIST_ZONE:
  1123. {
  1124. // Sundown: coercion to int-- selection is range-restricted
  1125. int iNewSelection = (int) SendMessage(pSec->hwndZones, LVM_GETNEXTITEM, (WPARAM)-1,
  1126. MAKELPARAM(LVNI_SELECTED, 0));
  1127. if ((iNewSelection != pSec->iZoneSel) && (iNewSelection != -1))
  1128. {
  1129. LV_ITEM lvItem;
  1130. lvItem.iItem = iNewSelection;
  1131. lvItem.iSubItem = 0;
  1132. lvItem.mask = LVIF_PARAM;
  1133. SendMessage(pSec->hwndZones, LVM_GETITEM, (WPARAM)0, (LPARAM)&lvItem);
  1134. pSec->pszs = (LPSECURITYZONESETTINGS)lvItem.lParam;
  1135. pSec->iZoneSel = iNewSelection;
  1136. WCHAR wszBuffer[ MAX_PATH*2];
  1137. MLLoadString( IDS_ZONEDESC_LOCAL + pSec->pszs->dwZoneIndex, wszBuffer, ARRAYSIZE(wszBuffer));
  1138. SetDlgItemText(pSec->hDlg, IDC_ZONE_DESCRIPTION, wszBuffer);
  1139. MLLoadString( IDS_ZONENAME_LOCAL + pSec->pszs->dwZoneIndex, wszBuffer, ARRAYSIZE(wszBuffer));
  1140. SetDlgItemText(pSec->hDlg, IDC_ZONELABEL, wszBuffer);
  1141. SendDlgItemMessage(pSec->hDlg, IDC_ZONE_ICON, STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)pSec->pszs->hicon);
  1142. SecurityEnableControls(pSec, FALSE);
  1143. }
  1144. break;
  1145. }
  1146. }
  1147. } // SecurityOnCommand()
  1148. //
  1149. // SecurityDlgProc()
  1150. //
  1151. // Handles Security Dialog's window messages
  1152. //
  1153. // History:
  1154. //
  1155. // 6/17/96 t-gpease created
  1156. // 5/14/97 t-ashlm ui changes
  1157. //
  1158. INT_PTR CALLBACK SecurityDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1159. {
  1160. LPSECURITYPAGE pSec;
  1161. if (uMsg == WM_INITDIALOG)
  1162. {
  1163. // A hack forced by PropertyPage:
  1164. // PropertyPage creates this dialog in mainwnd.cpp when the dialog is entered from
  1165. // the desktop e's properties, the browser's menu view-internetoptions-security, or
  1166. // right clicking on the browser's zone icon.
  1167. // In the property page case, lParam (our only route to get initialization information
  1168. // in) is a pointer to a PROPERTYSHEETHEADER, more or less, and of entirely no use to us.
  1169. // However, when called from our exported function LaunchSecurityDialogEx, using
  1170. // CreateDialogParamWrapW, we want to pass useful information in. The only way to make sure
  1171. // we our dealing with useful information is to make the passed in pointer be to a
  1172. // structure we know and love, and hence could not possibly be pointed to by PropertyPage.
  1173. // We use a ThreadLocalStorage object, as our information reference
  1174. SECURITYINITFLAGS * psif = NULL;
  1175. if(g_dwtlsSecInitFlags != (DWORD) -1)
  1176. psif = (SECURITYINITFLAGS *) TlsGetValue(g_dwtlsSecInitFlags);
  1177. if((SECURITYINITFLAGS *) lParam != psif)
  1178. psif = NULL;
  1179. return SecurityDlgInit(hDlg, psif);
  1180. }
  1181. pSec = (LPSECURITYPAGE)GetWindowLongPtr(hDlg, DWLP_USER);
  1182. if (!pSec)
  1183. return FALSE;
  1184. switch (uMsg)
  1185. {
  1186. case WM_COMMAND:
  1187. SecurityOnCommand(pSec, LOWORD(wParam), HIWORD(wParam));
  1188. return TRUE;
  1189. case WM_NOTIFY:
  1190. {
  1191. NMHDR *lpnm = (NMHDR *) lParam;
  1192. ASSERT(lpnm);
  1193. // List Box Messages
  1194. if(lpnm->idFrom == IDC_LIST_ZONE)
  1195. {
  1196. NM_LISTVIEW * lplvnm = (NM_LISTVIEW *) lParam;
  1197. if(lplvnm->hdr.code == LVN_ITEMCHANGED)
  1198. {
  1199. // If an item's state has changed, and it is now selected
  1200. if(((lplvnm->uChanged & LVIF_STATE) != 0) && ((lplvnm->uNewState & LVIS_SELECTED) != 0))
  1201. {
  1202. SecurityOnCommand(pSec, IDC_LIST_ZONE, LVN_ITEMCHANGED);
  1203. }
  1204. }
  1205. }
  1206. else
  1207. {
  1208. switch (lpnm->code)
  1209. {
  1210. case PSN_QUERYCANCEL:
  1211. case PSN_KILLACTIVE:
  1212. case PSN_RESET:
  1213. SetWindowLongPtr(pSec->hDlg, DWLP_MSGRESULT, FALSE);
  1214. return TRUE;
  1215. case PSN_APPLY:
  1216. // Hitting the apply button runs this code
  1217. SecurityDlgApplyNow(pSec, TRUE);
  1218. break;
  1219. }
  1220. }
  1221. }
  1222. break;
  1223. case WM_HELP: // F1
  1224. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1225. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1226. break;
  1227. case WM_APP:
  1228. // A message needs to be posted, because the set tools sometimes send two messages
  1229. // hence we need delayed action and a pending change boolean
  1230. // lParam is the level to set for this message
  1231. // wParam is not used
  1232. SecuritySetLevel((DWORD) lParam, pSec);
  1233. break;
  1234. case WM_VSCROLL:
  1235. // Slider Messages
  1236. SecurityOnCommand(pSec, IDC_SLIDER, LOWORD(wParam));
  1237. return TRUE;
  1238. case WM_CONTEXTMENU: // right mouse click
  1239. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  1240. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1241. break;
  1242. case WM_DESTROY:
  1243. if(! pSec)
  1244. break;
  1245. if(pSec->hwndZones)
  1246. {
  1247. for (int iIndex = (int)SendMessage(pSec->hwndZones, LVM_GETITEMCOUNT, 0, 0) - 1;
  1248. iIndex >= 0; iIndex--)
  1249. {
  1250. LV_ITEM lvItem;
  1251. // get security zone settings object for this item and release it
  1252. lvItem.mask = LVIF_PARAM;
  1253. lvItem.iItem = iIndex;
  1254. lvItem.iSubItem = 0;
  1255. if (SendMessage(pSec->hwndZones, LVM_GETITEM, (WPARAM)0, (LPARAM)&lvItem) == TRUE)
  1256. {
  1257. LPSECURITYZONESETTINGS pszs = (LPSECURITYZONESETTINGS)lvItem.lParam;
  1258. if (pszs)
  1259. {
  1260. if (pszs->hicon)
  1261. DestroyIcon(pszs->hicon);
  1262. LocalFree((HLOCAL)pszs);
  1263. pszs = NULL;
  1264. }
  1265. }
  1266. }
  1267. }
  1268. if(pSec->pInternetZoneManager)
  1269. pSec->pInternetZoneManager->Release();
  1270. if(pSec->pInternetSecurityManager)
  1271. pSec->pInternetSecurityManager->Release();
  1272. if(pSec->himl)
  1273. ImageList_Destroy(pSec->himl);
  1274. if(pSec->hfontBolded)
  1275. DeleteObject(pSec->hfontBolded);
  1276. // ok, we're done with URLMON
  1277. if(pSec->hinstUrlmon)
  1278. FreeLibrary(pSec->hinstUrlmon);
  1279. LocalFree(pSec);
  1280. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)NULL);
  1281. break;
  1282. }
  1283. return FALSE;
  1284. }
  1285. // Subclassed window proc for the slider. This is used to take over the
  1286. // accessibility wrapper for the class so we can return the right zone
  1287. // string ( i.e. High, Medium, Low, etc). Just trap WM_GETOBJECT and pass
  1288. // in our override of the accessibility wrapper.
  1289. LRESULT CALLBACK SliderSubWndProc (HWND hwndSlider, UINT uMsg, WPARAM wParam, LPARAM lParam, WPARAM uID, ULONG_PTR dwRefData)
  1290. {
  1291. ASSERT(uID == 0);
  1292. ASSERT(dwRefData == 0);
  1293. switch (uMsg)
  1294. {
  1295. case WM_GETOBJECT:
  1296. if ( lParam == OBJID_CLIENT )
  1297. {
  1298. // At this point we will try to load oleacc and get the functions
  1299. // we need.
  1300. if (!g_fAttemptedOleAccLoad)
  1301. {
  1302. g_fAttemptedOleAccLoad = TRUE;
  1303. ASSERT(s_pfnCreateStdAccessibleProxy == NULL);
  1304. ASSERT(s_pfnLresultFromObject == NULL);
  1305. g_hOleAcc = LoadLibrary(TEXT("OLEACC"));
  1306. if (g_hOleAcc != NULL)
  1307. {
  1308. #ifdef UNICODE
  1309. s_pfnCreateStdAccessibleProxy = (PFNCREATESTDACCESSIBLEPROXY)
  1310. GetProcAddress(g_hOleAcc, "CreateStdAccessibleProxyW");
  1311. #else
  1312. s_pfnCreateStdAccessibleProxy = (PFNCREATESTDACCESSIBLEPROXY)
  1313. GetProcAddress(g_hOleAcc, "CreateStdAccessibleProxyA");
  1314. #endif
  1315. s_pfnLresultFromObject = (PFNLRESULTFROMOBJECT)
  1316. GetProcAddress(g_hOleAcc, "LresultFromObject");
  1317. }
  1318. if (s_pfnLresultFromObject == NULL || s_pfnCreateStdAccessibleProxy == NULL)
  1319. {
  1320. // No point holding on to Oleacc since we can't use it.
  1321. FreeLibrary(g_hOleAcc);
  1322. g_hOleAcc = NULL;
  1323. s_pfnLresultFromObject = NULL;
  1324. s_pfnCreateStdAccessibleProxy = NULL;
  1325. }
  1326. }
  1327. if (g_hOleAcc && s_pfnCreateStdAccessibleProxy && s_pfnLresultFromObject)
  1328. {
  1329. IAccessible *pAcc = NULL;
  1330. HRESULT hr;
  1331. // Create default slider proxy.
  1332. hr = s_pfnCreateStdAccessibleProxy(
  1333. hwndSlider,
  1334. TEXT("msctls_trackbar32"),
  1335. OBJID_CLIENT,
  1336. IID_IAccessible,
  1337. (void **)&pAcc
  1338. );
  1339. if (SUCCEEDED(hr) && pAcc)
  1340. {
  1341. // now wrap it up in our customized wrapper...
  1342. IAccessible * pWrapAcc = new CSecurityAccessibleWrapper( hwndSlider, pAcc );
  1343. // Release our ref to proxy (wrapper has its own addref'd ptr)...
  1344. pAcc->Release();
  1345. if (pWrapAcc != NULL)
  1346. {
  1347. // ...and return the wrapper via LresultFromObject...
  1348. LRESULT lr = s_pfnLresultFromObject( IID_IAccessible, wParam, pWrapAcc );
  1349. // Release our interface pointer - OLEACC has its own addref to the object
  1350. pWrapAcc->Release();
  1351. // Return the lresult, which 'contains' a reference to our wrapper object.
  1352. return lr;
  1353. // All done!
  1354. }
  1355. // If it didn't work, fall through to default behavior instead.
  1356. }
  1357. }
  1358. }
  1359. break;
  1360. case WM_DESTROY:
  1361. RemoveWindowSubclass(hwndSlider, SliderSubWndProc, uID);
  1362. break;
  1363. } /* end switch */
  1364. return DefSubclassProc(hwndSlider, uMsg, wParam, lParam);
  1365. }
  1366. HRESULT _AddSite(LPADDSITESINFO pasi)
  1367. {
  1368. HRESULT hr = S_OK;
  1369. LPWSTR psz;
  1370. SendMessage(pasi->hwndAdd, WM_GETTEXT, MAX_ZONE_PATH, (LPARAM)pasi->szWebSite);
  1371. #ifndef UNICODE
  1372. WCHAR wszMapping[MAX_ZONE_PATH];
  1373. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pasi->szWebSite, sizeof(pasi->szWebSite), wszMapping, ARRAYSIZE(wszMapping));
  1374. psz = wszMapping;
  1375. #else
  1376. psz = pasi->szWebSite;
  1377. #endif
  1378. if (*psz)
  1379. {
  1380. pasi->fRSVOld = pasi->fRequireServerVerification;
  1381. pasi->fRequireServerVerification = IsDlgButtonChecked(pasi->hDlg, IDC_CHECK_REQUIRE_SERVER_VERIFICATION);
  1382. // if the state of RequireServerVer has changed, then do a SetZoneAttr so we'll get the correct error codes
  1383. if (pasi->fRSVOld != pasi->fRequireServerVerification)
  1384. {
  1385. ZONEATTRIBUTES za;
  1386. za.cbSize = sizeof(ZONEATTRIBUTES);
  1387. pasi->pSec->pInternetZoneManager->GetZoneAttributes(pasi->pSec->pszs->dwZoneIndex, &za);
  1388. if (pasi->fRequireServerVerification)
  1389. za.dwFlags |= ZAFLAGS_REQUIRE_VERIFICATION;
  1390. else
  1391. za.dwFlags &= ~ZAFLAGS_REQUIRE_VERIFICATION;
  1392. pasi->pSec->pInternetZoneManager->SetZoneAttributes(pasi->pSec->pszs->dwZoneIndex, &za);
  1393. }
  1394. hr = pasi->pSec->pInternetSecurityManager->SetZoneMapping(pasi->pSec->pszs->dwZoneIndex,
  1395. psz, SZM_CREATE);
  1396. if (FAILED(hr))
  1397. {
  1398. UINT id = IDS_MAPPINGFAIL;
  1399. if (hr == URL_E_INVALID_SYNTAX)
  1400. {
  1401. id = IDS_INVALIDURL;
  1402. }
  1403. else if (hr == E_INVALIDARG)
  1404. {
  1405. id = IDS_INVALIDWILDCARD;
  1406. }
  1407. else if (hr == E_ACCESSDENIED)
  1408. {
  1409. id = IDS_HTTPSREQ;
  1410. }
  1411. else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS))
  1412. {
  1413. id = IDS_SITEEXISTS;
  1414. }
  1415. MLShellMessageBox(pasi->hDlg, MAKEINTRESOURCEW(id), NULL, MB_ICONSTOP|MB_OK);
  1416. Edit_SetSel(pasi->hwndAdd, 0, -1);
  1417. }
  1418. else
  1419. {
  1420. SendMessage(pasi->hwndWebSites, LB_ADDSTRING, (WPARAM)0, (LPARAM)pasi->szWebSite);
  1421. SendMessage(pasi->hwndAdd, WM_SETTEXT, (WPARAM)0, (LPARAM)NULL);
  1422. SetFocus(pasi->hwndAdd);
  1423. }
  1424. }
  1425. return hr;
  1426. }
  1427. INT_PTR CALLBACK SecurityAddSitesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  1428. {
  1429. LPADDSITESINFO pasi;
  1430. if (uMsg == WM_INITDIALOG)
  1431. {
  1432. pasi = (LPADDSITESINFO)LocalAlloc(LPTR, sizeof(*pasi));
  1433. if (!pasi)
  1434. {
  1435. EndDialog(hDlg, IDCANCEL);
  1436. return FALSE;
  1437. }
  1438. // tell dialog where to get info
  1439. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pasi);
  1440. // save the handle to the page
  1441. pasi->hDlg = hDlg;
  1442. pasi->pSec = (LPSECURITYPAGE)lParam;
  1443. pasi->hwndWebSites = GetDlgItem(hDlg, IDC_LIST_WEBSITES);
  1444. pasi->hwndAdd = GetDlgItem(hDlg, IDC_EDIT_ADD_SITE);
  1445. // cross-lang platform support
  1446. SHSetDefaultDialogFont(hDlg, IDC_EDIT_ADD_SITE);
  1447. // limit the text so it will fit
  1448. SendMessage(pasi->hwndAdd, EM_SETLIMITTEXT, (WPARAM)sizeof(pasi->szWebSite), (LPARAM)0);
  1449. pasi->fRequireServerVerification = pasi->pSec->pszs->dwFlags & ZAFLAGS_REQUIRE_VERIFICATION;
  1450. CheckDlgButton(hDlg, IDC_CHECK_REQUIRE_SERVER_VERIFICATION, pasi->fRequireServerVerification);
  1451. // hide the checkbox if it doesn't support server verification
  1452. if (!(pasi->pSec->pszs->dwFlags & ZAFLAGS_SUPPORTS_VERIFICATION))
  1453. ShowWindow(GetDlgItem(hDlg, IDC_CHECK_REQUIRE_SERVER_VERIFICATION), SW_HIDE);
  1454. SendMessage(hDlg, WM_SETTEXT, (WPARAM)0, (LPARAM)pasi->pSec->pszs->szDisplayName);
  1455. SetDlgItemText(hDlg, IDC_ADDSITES_GROUPBOX,(LPTSTR)pasi->pSec->pszs->szDisplayName);
  1456. SendDlgItemMessage(hDlg, IDC_ZONE_ICON, STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)pasi->pSec->pszs->hicon);
  1457. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_REMOVE), FALSE);
  1458. if (pasi->pSec->pInternetSecurityManager || SUCCEEDED(CoInternetCreateSecurityManager(NULL, &(pasi->pSec->pInternetSecurityManager), 0)))
  1459. {
  1460. IEnumString *pEnum;
  1461. if (SUCCEEDED(pasi->pSec->pInternetSecurityManager->GetZoneMappings(pasi->pSec->pszs->dwZoneIndex, &pEnum, 0)))
  1462. {
  1463. LPOLESTR pszMapping;
  1464. #ifndef UNICODE
  1465. CHAR szMapping[MAX_URL_STRING];
  1466. #endif
  1467. LPTSTR psz;
  1468. while (pEnum->Next(1, &pszMapping, NULL) == S_OK)
  1469. {
  1470. #ifndef UNICODE
  1471. WideCharToMultiByte(CP_ACP, 0, pszMapping, -1, szMapping, ARRAYSIZE(szMapping), NULL, NULL);
  1472. psz = szMapping;
  1473. #else
  1474. psz = pszMapping;
  1475. #endif // UNICODE
  1476. SendMessage(pasi->hwndWebSites, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)psz);
  1477. CoTaskMemFree(pszMapping);
  1478. }
  1479. pEnum->Release();
  1480. }
  1481. }
  1482. if (pasi->pSec->fNoAddSites || pasi->pSec->fNoZoneMapEdit)
  1483. {
  1484. EnableDlgItem(hDlg, IDC_EDIT_ADD_SITE, FALSE);
  1485. EnableDlgItem(hDlg, IDC_BUTTON_REMOVE, FALSE);
  1486. }
  1487. if (pasi->pSec->fNoZoneMapEdit)
  1488. {
  1489. EnableDlgItem(hDlg, IDC_CHECK_REQUIRE_SERVER_VERIFICATION, FALSE);
  1490. EnableDlgItem(hDlg, IDS_STATIC_ADDSITE, FALSE);
  1491. }
  1492. SHAutoComplete(GetDlgItem(hDlg, IDC_EDIT_ADD_SITE), SHACF_DEFAULT);
  1493. }
  1494. else
  1495. pasi = (LPADDSITESINFO)GetWindowLongPtr(hDlg, DWLP_USER);
  1496. if (!pasi)
  1497. return FALSE;
  1498. switch (uMsg)
  1499. {
  1500. case WM_COMMAND:
  1501. switch (LOWORD(wParam))
  1502. {
  1503. case IDOK:
  1504. {
  1505. ZONEATTRIBUTES za;
  1506. pasi->fRequireServerVerification = IsDlgButtonChecked(hDlg, IDC_CHECK_REQUIRE_SERVER_VERIFICATION);
  1507. if (pasi->fRequireServerVerification)
  1508. pasi->pSec->pszs->dwFlags |= ZAFLAGS_REQUIRE_VERIFICATION;
  1509. else
  1510. pasi->pSec->pszs->dwFlags &= ~ZAFLAGS_REQUIRE_VERIFICATION;
  1511. za.cbSize = sizeof(ZONEATTRIBUTES);
  1512. pasi->pSec->pInternetZoneManager->GetZoneAttributes(pasi->pSec->pszs->dwZoneIndex, &za);
  1513. za.dwFlags = pasi->pSec->pszs->dwFlags;
  1514. pasi->pSec->pInternetZoneManager->SetZoneAttributes(pasi->pSec->pszs->dwZoneIndex, &za);
  1515. if (SUCCEEDED(_AddSite(pasi)))
  1516. {
  1517. SecurityChanged();
  1518. EndDialog(hDlg, IDOK);
  1519. }
  1520. break;
  1521. }
  1522. case IDCANCEL:
  1523. {
  1524. ZONEATTRIBUTES za;
  1525. // reset to original state of RequireServerVerification on cancel
  1526. za.cbSize = sizeof(ZONEATTRIBUTES);
  1527. pasi->pSec->pInternetZoneManager->GetZoneAttributes(pasi->pSec->pszs->dwZoneIndex, &za);
  1528. za.dwFlags = pasi->pSec->pszs->dwFlags;
  1529. pasi->pSec->pInternetZoneManager->SetZoneAttributes(pasi->pSec->pszs->dwZoneIndex, &za);
  1530. EndDialog(hDlg, IDCANCEL);
  1531. break;
  1532. }
  1533. case IDC_LIST_WEBSITES:
  1534. switch (HIWORD(wParam))
  1535. {
  1536. case LBN_SELCHANGE:
  1537. case LBN_SELCANCEL:
  1538. if (!pasi->pSec->fNoAddSites && !pasi->pSec->fNoZoneMapEdit)
  1539. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_REMOVE), SendDlgItemMessage(hDlg, IDC_LIST_WEBSITES, LB_GETCURSEL, 0, 0) != -1);
  1540. break;
  1541. }
  1542. break;
  1543. case IDC_EDIT_ADD_SITE:
  1544. switch(HIWORD(wParam))
  1545. {
  1546. case EN_CHANGE:
  1547. BOOL fEnable = GetWindowTextLength(GetDlgItem(hDlg, IDC_EDIT_ADD_SITE)) ? TRUE:FALSE;
  1548. EnableWindow(GetDlgItem(hDlg,IDC_BUTTON_ADD), fEnable);
  1549. SendMessage(hDlg, DM_SETDEFID, fEnable ? IDC_BUTTON_ADD : IDOK, 0);
  1550. break;
  1551. }
  1552. break;
  1553. case IDC_BUTTON_ADD:
  1554. _AddSite(pasi);
  1555. break;
  1556. case IDC_BUTTON_REMOVE:
  1557. {
  1558. TCHAR szMapping[MAX_ZONE_PATH];
  1559. LPWSTR psz;
  1560. INT_PTR iSel = SendMessage(pasi->hwndWebSites, LB_GETCURSEL, 0, 0);
  1561. if (iSel != -1)
  1562. {
  1563. SendMessage(pasi->hwndWebSites, LB_GETTEXT, (WPARAM)iSel, (LPARAM)szMapping);
  1564. #ifndef UNICODE
  1565. WCHAR wszMapping[MAX_ZONE_PATH];
  1566. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szMapping, sizeof(szMapping), wszMapping, ARRAYSIZE(wszMapping));
  1567. psz = wszMapping;
  1568. #else
  1569. psz = szMapping;
  1570. #endif
  1571. SendMessage(pasi->hwndWebSites, LB_DELETESTRING, iSel , 0);
  1572. SendMessage(pasi->hwndWebSites, LB_SETCURSEL, iSel-1, 0);
  1573. if (!pasi->pSec->fNoAddSites && !pasi->pSec->fNoZoneMapEdit)
  1574. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_REMOVE), SendDlgItemMessage(hDlg, IDC_LIST_WEBSITES, LB_GETCURSEL, 0, 0) != -1);
  1575. pasi->pSec->pInternetSecurityManager->SetZoneMapping(pasi->pSec->pszs->dwZoneIndex,
  1576. psz, SZM_DELETE);
  1577. }
  1578. break;
  1579. }
  1580. default:
  1581. return FALSE;
  1582. }
  1583. return TRUE;
  1584. break;
  1585. case WM_HELP: // F1
  1586. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1587. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1588. break;
  1589. case WM_CONTEXTMENU: // right mouse click
  1590. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  1591. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1592. break;
  1593. case WM_DESTROY:
  1594. SHRemoveDefaultDialogFont(hDlg);
  1595. if (pasi)
  1596. {
  1597. LocalFree(pasi);
  1598. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)NULL);
  1599. }
  1600. break;
  1601. }
  1602. return FALSE;
  1603. }
  1604. INT_PTR CALLBACK SecurityAddSitesIntranetDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  1605. {
  1606. LPADDSITESINTRANETINFO pasii;
  1607. if (uMsg == WM_INITDIALOG)
  1608. {
  1609. pasii = (LPADDSITESINTRANETINFO)LocalAlloc(LPTR, sizeof(*pasii));
  1610. if (!pasii)
  1611. {
  1612. EndDialog(hDlg, IDCANCEL);
  1613. return FALSE;
  1614. }
  1615. // tell dialog where to get info
  1616. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pasii);
  1617. // save the handle to the page
  1618. pasii->hDlg = hDlg;
  1619. pasii->pSec = (LPSECURITYPAGE)lParam;
  1620. SendMessage(hDlg, WM_SETTEXT, (WPARAM)0, (LPARAM)pasii->pSec->pszs->szDisplayName);
  1621. CheckDlgButton(hDlg, IDC_CHECK_USEINTRANET, pasii->pSec->pszs->dwFlags & ZAFLAGS_INCLUDE_INTRANET_SITES);
  1622. CheckDlgButton(hDlg, IDC_CHECK_PROXY, pasii->pSec->pszs->dwFlags & ZAFLAGS_INCLUDE_PROXY_OVERRIDE);
  1623. CheckDlgButton(hDlg, IDC_CHECK_UNC, pasii->pSec->pszs->dwFlags & ZAFLAGS_UNC_AS_INTRANET);
  1624. SendDlgItemMessage(hDlg, IDC_ZONE_ICON, STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)pasii->pSec->pszs->hicon);
  1625. if (pasii->pSec->fNoAddSites || pasii->pSec->fNoZoneMapEdit)
  1626. {
  1627. EnableDlgItem(hDlg, IDC_CHECK_USEINTRANET, FALSE);
  1628. EnableDlgItem(hDlg, IDC_CHECK_PROXY, FALSE);
  1629. }
  1630. if (pasii->pSec->fNoZoneMapEdit)
  1631. {
  1632. EnableDlgItem(hDlg, IDC_CHECK_UNC, FALSE);
  1633. }
  1634. return TRUE;
  1635. }
  1636. else
  1637. pasii = (LPADDSITESINTRANETINFO)GetWindowLongPtr(hDlg, DWLP_USER);
  1638. if (!pasii)
  1639. return FALSE;
  1640. switch (uMsg) {
  1641. case WM_COMMAND:
  1642. switch (LOWORD(wParam))
  1643. {
  1644. case IDOK:
  1645. {
  1646. ZONEATTRIBUTES za;
  1647. pasii->fUseIntranet = IsDlgButtonChecked(hDlg, IDC_CHECK_USEINTRANET);
  1648. pasii->fUseProxyExclusion = IsDlgButtonChecked(hDlg, IDC_CHECK_PROXY);
  1649. pasii->fUseUNC = IsDlgButtonChecked(hDlg, IDC_CHECK_UNC);
  1650. if (pasii->fUseIntranet)
  1651. pasii->pSec->pszs->dwFlags |= ZAFLAGS_INCLUDE_INTRANET_SITES;
  1652. else
  1653. pasii->pSec->pszs->dwFlags &= ~ZAFLAGS_INCLUDE_INTRANET_SITES;
  1654. if (pasii->fUseProxyExclusion)
  1655. pasii->pSec->pszs->dwFlags |= ZAFLAGS_INCLUDE_PROXY_OVERRIDE;
  1656. else
  1657. pasii->pSec->pszs->dwFlags &= ~ZAFLAGS_INCLUDE_PROXY_OVERRIDE;
  1658. if (pasii->fUseUNC)
  1659. pasii->pSec->pszs->dwFlags |= ZAFLAGS_UNC_AS_INTRANET;
  1660. else
  1661. pasii->pSec->pszs->dwFlags &= ~ZAFLAGS_UNC_AS_INTRANET;
  1662. za.cbSize = sizeof(ZONEATTRIBUTES);
  1663. pasii->pSec->pInternetZoneManager->GetZoneAttributes(pasii->pSec->pszs->dwZoneIndex, &za);
  1664. za.dwFlags = pasii->pSec->pszs->dwFlags;
  1665. pasii->pSec->pInternetZoneManager->SetZoneAttributes(pasii->pSec->pszs->dwZoneIndex, &za);
  1666. SecurityChanged();
  1667. EndDialog(hDlg, IDOK);
  1668. break;
  1669. }
  1670. case IDCANCEL:
  1671. EndDialog(hDlg, IDCANCEL);
  1672. break;
  1673. case IDC_INTRANET_ADVANCED:
  1674. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SECURITY_ADD_SITES), hDlg,
  1675. SecurityAddSitesDlgProc, (LPARAM)pasii->pSec);
  1676. break;
  1677. default:
  1678. return FALSE;
  1679. }
  1680. return TRUE;
  1681. break;
  1682. case WM_HELP: // F1
  1683. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1684. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1685. break;
  1686. case WM_CONTEXTMENU: // right mouse click
  1687. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  1688. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1689. break;
  1690. case WM_DESTROY:
  1691. if (pasii)
  1692. {
  1693. LocalFree(pasii);
  1694. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)NULL);
  1695. }
  1696. break;
  1697. }
  1698. return FALSE;
  1699. }
  1700. VOID ShowJavaZonePermissionsDialog (HWND hdlg, LPCUSTOMSETTINGSINFO pcsi)
  1701. {
  1702. HRESULT hr;
  1703. IJavaZonePermissionEditor *zoneeditor;
  1704. hr = CoCreateInstance(
  1705. CLSID_JavaRuntimeConfiguration,
  1706. NULL,
  1707. CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,
  1708. IID_IJavaZonePermissionEditor,
  1709. (PVOID*)&zoneeditor
  1710. );
  1711. if (SUCCEEDED(hr))
  1712. {
  1713. hr = zoneeditor->ShowUI(
  1714. hdlg,
  1715. 0,
  1716. 0,
  1717. pcsi->fUseHKLM ? URLZONEREG_HKLM : URLZONEREG_DEFAULT,
  1718. pcsi->pSec->pszs->dwZoneIndex,
  1719. pcsi->dwJavaPolicy | URLACTION_JAVA_PERMISSIONS,
  1720. pcsi->pSec->pInternetZoneManager
  1721. );
  1722. zoneeditor->Release();
  1723. }
  1724. }
  1725. void ShowCustom(LPCUSTOMSETTINGSINFO pcsi, HTREEITEM hti)
  1726. {
  1727. TV_ITEM tvi;
  1728. tvi.hItem = hti;
  1729. tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_IMAGE;
  1730. TreeView_GetItem( pcsi->hwndTree, &tvi );
  1731. // If it's not selected don't bother.
  1732. if (tvi.iImage != IDRADIOON)
  1733. return;
  1734. TCHAR szValName[64];
  1735. DWORD cb = SIZEOF(szValName);
  1736. DWORD dwChecked;
  1737. if (SHRegQueryUSValue((HUSKEY)tvi.lParam,
  1738. TEXT("ValueName"),
  1739. NULL,
  1740. (LPBYTE)szValName,
  1741. &cb,
  1742. pcsi->fUseHKLM,
  1743. NULL,
  1744. 0) == ERROR_SUCCESS)
  1745. {
  1746. if (!(StrCmp(szValName, TEXT("1C00"))))
  1747. {
  1748. cb = SIZEOF(dwChecked);
  1749. if (SHRegQueryUSValue((HUSKEY)tvi.lParam,
  1750. TEXT("CheckedValue"),
  1751. NULL,
  1752. (LPBYTE)&dwChecked,
  1753. &cb,
  1754. pcsi->fUseHKLM,
  1755. NULL,
  1756. 0) == ERROR_SUCCESS)
  1757. {
  1758. #ifndef UNIX
  1759. HWND hCtl = GetDlgItem(pcsi->hDlg, IDC_JAVACUSTOM);
  1760. ShowWindow(hCtl,
  1761. (dwChecked == URLPOLICY_JAVA_CUSTOM) && (tvi.iImage == IDRADIOON) ? SW_SHOWNA : SW_HIDE);
  1762. EnableWindow(hCtl, dwChecked==URLPOLICY_JAVA_CUSTOM ? TRUE : FALSE);
  1763. pcsi->dwJavaPolicy = dwChecked;
  1764. #endif
  1765. }
  1766. }
  1767. }
  1768. }
  1769. void _FindCustomRecursive(
  1770. LPCUSTOMSETTINGSINFO pcsi,
  1771. HTREEITEM htvi
  1772. )
  1773. {
  1774. HTREEITEM hctvi; // child
  1775. // step through the children
  1776. hctvi = TreeView_GetChild( pcsi->hwndTree, htvi );
  1777. while ( hctvi )
  1778. {
  1779. _FindCustomRecursive(pcsi,hctvi);
  1780. hctvi = TreeView_GetNextSibling( pcsi->hwndTree, hctvi );
  1781. }
  1782. ShowCustom(pcsi, htvi);
  1783. }
  1784. void _FindCustom(
  1785. LPCUSTOMSETTINGSINFO pcsi
  1786. )
  1787. {
  1788. HTREEITEM hti = TreeView_GetRoot( pcsi->hwndTree );
  1789. // and walk the list of other roots
  1790. while (hti)
  1791. {
  1792. // recurse through its children
  1793. _FindCustomRecursive(pcsi, hti);
  1794. // get the next root
  1795. hti = TreeView_GetNextSibling(pcsi->hwndTree, hti );
  1796. }
  1797. }
  1798. BOOL SecurityCustomSettingsInitDialog(HWND hDlg, LPARAM lParam)
  1799. {
  1800. LPCUSTOMSETTINGSINFO pcsi = (LPCUSTOMSETTINGSINFO)LocalAlloc(LPTR, sizeof(*pcsi));
  1801. HRESULT hr;
  1802. if (!pcsi)
  1803. {
  1804. EndDialog(hDlg, IDCANCEL);
  1805. return FALSE;
  1806. }
  1807. // tell dialog where to get info
  1808. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pcsi);
  1809. // save the handle to the page
  1810. pcsi->hDlg = hDlg;
  1811. pcsi->pSec = (LPSECURITYPAGE)lParam;
  1812. // save dialog handle
  1813. pcsi->hwndTree = GetDlgItem(pcsi->hDlg, IDC_TREE_SECURITY_SETTINGS);
  1814. CoInitialize(0);
  1815. hr = CoCreateInstance(CLSID_CRegTreeOptions, NULL, CLSCTX_INPROC_SERVER,
  1816. IID_IRegTreeOptions, (LPVOID *)&(pcsi->pTO));
  1817. DWORD cb = SIZEOF(pcsi->fUseHKLM);
  1818. SHGetValue(HKEY_LOCAL_MACHINE,
  1819. REGSTR_PATH_SECURITY_LOCKOUT,
  1820. REGSTR_VAL_HKLM_ONLY,
  1821. NULL,
  1822. &(pcsi->fUseHKLM),
  1823. &cb);
  1824. // if this fails, we'll just use the default of fUseHKLM == 0
  1825. if (SUCCEEDED(hr))
  1826. {
  1827. CHAR szZone[32];
  1828. wnsprintfA(szZone, ARRAYSIZE(szZone), "%ld", pcsi->pSec->pszs->dwZoneIndex);
  1829. // use the SOHKLM tree when fUseHKLM==TRUE for IEAK
  1830. hr = pcsi->pTO->InitTree(pcsi->hwndTree, HKEY_LOCAL_MACHINE,
  1831. pcsi->fUseHKLM ?
  1832. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\SOIEAK" :
  1833. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\SO",
  1834. szZone);
  1835. }
  1836. // find the first root and make sure that it is visible
  1837. TreeView_EnsureVisible( pcsi->hwndTree, TreeView_GetRoot( pcsi->hwndTree ) );
  1838. pcsi->hwndCombo = GetDlgItem(hDlg, IDC_COMBO_RESETLEVEL);
  1839. SendMessage(pcsi->hwndCombo, CB_INSERTSTRING, (WPARAM)0, (LPARAM)LEVEL_NAME[3]);
  1840. SendMessage(pcsi->hwndCombo, CB_INSERTSTRING, (WPARAM)0, (LPARAM)LEVEL_NAME[2]);
  1841. SendMessage(pcsi->hwndCombo, CB_INSERTSTRING, (WPARAM)0, (LPARAM)LEVEL_NAME[1]);
  1842. SendMessage(pcsi->hwndCombo, CB_INSERTSTRING, (WPARAM)0, (LPARAM)LEVEL_NAME[0]);
  1843. switch (pcsi->pSec->pszs->dwRecSecLevel)
  1844. {
  1845. case URLTEMPLATE_LOW:
  1846. pcsi->iLevelSel = 3;
  1847. break;
  1848. case URLTEMPLATE_MEDLOW:
  1849. pcsi->iLevelSel = 2;
  1850. break;
  1851. case URLTEMPLATE_MEDIUM:
  1852. pcsi->iLevelSel = 1;
  1853. break;
  1854. case URLTEMPLATE_HIGH:
  1855. pcsi->iLevelSel = 0;
  1856. break;
  1857. default:
  1858. pcsi->iLevelSel = 0;
  1859. break;
  1860. }
  1861. _FindCustom(pcsi);
  1862. SendMessage(pcsi->hwndCombo, CB_SETCURSEL, (WPARAM)pcsi->iLevelSel, (LPARAM)0);
  1863. if (pcsi->pSec->fNoEdit)
  1864. {
  1865. EnableDlgItem(hDlg, IDC_COMBO_RESETLEVEL, FALSE);
  1866. EnableDlgItem(hDlg, IDC_BUTTON_APPLY, FALSE);
  1867. }
  1868. pcsi->fChanged = FALSE;
  1869. return TRUE;
  1870. }
  1871. INT_PTR CALLBACK SecurityCustomSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  1872. {
  1873. LPCUSTOMSETTINGSINFO pcsi;
  1874. if (uMsg == WM_INITDIALOG)
  1875. return SecurityCustomSettingsInitDialog(hDlg, lParam);
  1876. else
  1877. pcsi = (LPCUSTOMSETTINGSINFO)GetWindowLongPtr(hDlg, DWLP_USER);
  1878. if (!pcsi)
  1879. return FALSE;
  1880. switch (uMsg) {
  1881. case WM_NOTIFY:
  1882. {
  1883. LPNMHDR psn = (LPNMHDR)lParam;
  1884. switch( psn->code )
  1885. {
  1886. case TVN_KEYDOWN:
  1887. {
  1888. TV_KEYDOWN *pnm = (TV_KEYDOWN*)psn;
  1889. if (pnm->wVKey == VK_SPACE) {
  1890. if (!pcsi->pSec->fNoEdit)
  1891. {
  1892. HTREEITEM hti = (HTREEITEM)SendMessage(pcsi->hwndTree, TVM_GETNEXTITEM, TVGN_CARET, NULL);
  1893. pcsi->pTO->ToggleItem(hti);
  1894. ShowCustom(pcsi, hti);
  1895. pcsi->fChanged = TRUE;
  1896. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_APPLY),TRUE);
  1897. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE); // eat the key
  1898. return TRUE;
  1899. }
  1900. }
  1901. break;
  1902. }
  1903. case NM_CLICK:
  1904. case NM_DBLCLK:
  1905. { // is this click in our tree?
  1906. if ( psn->idFrom == IDC_TREE_SECURITY_SETTINGS )
  1907. { // yes...
  1908. TV_HITTESTINFO ht;
  1909. HTREEITEM hti;
  1910. if (!pcsi->pSec->fNoEdit)
  1911. {
  1912. GetCursorPos( &ht.pt ); // get where we were hit
  1913. ScreenToClient( pcsi->hwndTree, &ht.pt ); // translate it to our window
  1914. // retrieve the item hit
  1915. hti = TreeView_HitTest( pcsi->hwndTree, &ht);
  1916. pcsi->pTO->ToggleItem(hti);
  1917. pcsi->fChanged = TRUE;
  1918. ShowCustom(pcsi, hti);
  1919. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_APPLY),TRUE);
  1920. }
  1921. }
  1922. }
  1923. break;
  1924. }
  1925. }
  1926. break;
  1927. case WM_COMMAND:
  1928. switch (LOWORD(wParam))
  1929. {
  1930. case IDOK:
  1931. if(pcsi->pSec->fPendingChange)
  1932. break;
  1933. if(pcsi->fChanged && RegWriteWarning(pcsi->pSec->hDlg) == IDNO)
  1934. break;
  1935. // we use send message instead of post because there is no chance of this button
  1936. // receiving multiple signals at one click, and we need the change level message to be
  1937. // processed before the apply message below
  1938. pcsi->pSec->fPendingChange = TRUE;
  1939. SendMessage(pcsi->pSec->hDlg, WM_APP, (WPARAM) 0, (LPARAM) URLTEMPLATE_CUSTOM);
  1940. if(pcsi->fChanged)
  1941. {
  1942. pcsi->pTO->WalkTree( WALK_TREE_SAVE );
  1943. }
  1944. // Saves custom to registry and Handles updateallwindows
  1945. // and securitychanged calls
  1946. // APPCOMPAT: Force a call to SetZoneAttributes when anything in custom changes.
  1947. // This forces the security manager to flush any caches it has for that zone.
  1948. pcsi->pSec->fChanged = TRUE;
  1949. SecurityDlgApplyNow(pcsi->pSec, FALSE);
  1950. EndDialog(hDlg, IDOK);
  1951. break;
  1952. case IDCANCEL:
  1953. EndDialog(hDlg, IDCANCEL);
  1954. break;
  1955. case IDC_COMBO_RESETLEVEL:
  1956. switch (HIWORD(wParam))
  1957. {
  1958. case CBN_SELCHANGE:
  1959. {
  1960. // Sundown: coercion to integer since cursor selection is 32b
  1961. int iNewSelection = (int) SendMessage(pcsi->hwndCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  1962. if (iNewSelection != pcsi->iLevelSel)
  1963. {
  1964. pcsi->iLevelSel = iNewSelection;
  1965. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_APPLY),TRUE);
  1966. }
  1967. break;
  1968. }
  1969. }
  1970. break;
  1971. case IDC_JAVACUSTOM:
  1972. ShowJavaZonePermissionsDialog(hDlg, pcsi);
  1973. break;
  1974. case IDC_BUTTON_APPLY:
  1975. {
  1976. TCHAR szLevel[64];
  1977. ZONEATTRIBUTES za;
  1978. if(pcsi->pSec->fPendingChange == TRUE)
  1979. break;
  1980. if(RegWriteWarning(hDlg) == IDNO)
  1981. {
  1982. break;
  1983. }
  1984. pcsi->pSec->fPendingChange = TRUE;
  1985. SendMessage(pcsi->hwndCombo, WM_GETTEXT, (WPARAM)ARRAYSIZE(szLevel), (LPARAM)szLevel);
  1986. za.cbSize = sizeof(ZONEATTRIBUTES);
  1987. pcsi->pSec->pInternetZoneManager->GetZoneAttributes(pcsi->pSec->pszs->dwZoneIndex, &za);
  1988. if (!StrCmp(szLevel, LEVEL_NAME[3]))
  1989. za.dwTemplateCurrentLevel = URLTEMPLATE_LOW;
  1990. else if (!StrCmp(szLevel, LEVEL_NAME[2]))
  1991. za.dwTemplateCurrentLevel = URLTEMPLATE_MEDLOW;
  1992. else if (!StrCmp(szLevel, LEVEL_NAME[1]))
  1993. za.dwTemplateCurrentLevel = URLTEMPLATE_MEDIUM;
  1994. else if (!StrCmp(szLevel, LEVEL_NAME[0]))
  1995. za.dwTemplateCurrentLevel = URLTEMPLATE_HIGH;
  1996. else
  1997. za.dwTemplateCurrentLevel = URLTEMPLATE_CUSTOM;
  1998. pcsi->pSec->pInternetZoneManager->SetZoneAttributes(pcsi->pSec->pszs->dwZoneIndex, &za);
  1999. pcsi->pTO->WalkTree(WALK_TREE_REFRESH);
  2000. // find the first root and make sure that it is visible
  2001. TreeView_EnsureVisible( pcsi->hwndTree, TreeView_GetRoot( pcsi->hwndTree ) );
  2002. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_APPLY), FALSE);
  2003. SendMessage(hDlg, DM_SETDEFID, IDOK, 0);
  2004. SetFocus(GetDlgItem(hDlg, IDOK)); // since we grayout the reset button, might have keyboard
  2005. // focus, so we should set focus somewhere else
  2006. _FindCustom(pcsi);
  2007. // BUG #57358. We tell the Zone Manager to change to [High/Med/Low] level because we want
  2008. // the policy values for those, but we don't want it to change the level from
  2009. // custom. So, after it changes the setting from Custom, we change it back.
  2010. // Save the level as custom
  2011. // we use send message instead of post because there is no chance of this button
  2012. // receiving multiple signals at one click, and we need the change level message to be
  2013. // processed before the apply message below
  2014. SendMessage(pcsi->pSec->hDlg, WM_APP, (WPARAM) 0, (LPARAM) URLTEMPLATE_CUSTOM);
  2015. // Saves custom to registry and Handles updateallwindows
  2016. // and securitychanged calls
  2017. // APPCOMPAT: Force a call to SetZoneAttributes when anything in custom changes.
  2018. // This forces the security manager to flush any caches it has for that zone.
  2019. pcsi->pSec->fChanged = TRUE;
  2020. SecurityDlgApplyNow(pcsi->pSec, TRUE);
  2021. pcsi->fChanged = FALSE;
  2022. break;
  2023. }
  2024. default:
  2025. return FALSE;
  2026. }
  2027. return TRUE;
  2028. break;
  2029. case WM_HELP: // F1
  2030. {
  2031. LPHELPINFO lphelpinfo;
  2032. lphelpinfo = (LPHELPINFO)lParam;
  2033. TV_HITTESTINFO ht;
  2034. HTREEITEM hItem;
  2035. // If this help is invoked through the F1 key.
  2036. if (GetAsyncKeyState(VK_F1) < 0)
  2037. {
  2038. // Yes we need to give help for the currently selected item.
  2039. hItem = TreeView_GetSelection(pcsi->hwndTree);
  2040. }
  2041. else
  2042. {
  2043. // Else we need to give help for the item at current cursor position
  2044. ht.pt =((LPHELPINFO)lParam)->MousePos;
  2045. ScreenToClient(pcsi->hwndTree, &ht.pt); // Translate it to our window
  2046. hItem = TreeView_HitTest(pcsi->hwndTree, &ht);
  2047. }
  2048. if (FAILED(pcsi->pTO->ShowHelp(hItem , HELP_WM_HELP)))
  2049. {
  2050. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  2051. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  2052. }
  2053. break;
  2054. }
  2055. case WM_CONTEXTMENU: // right mouse click
  2056. {
  2057. TV_HITTESTINFO ht;
  2058. GetCursorPos( &ht.pt ); // get where we were hit
  2059. ScreenToClient( pcsi->hwndTree, &ht.pt ); // translate it to our window
  2060. // retrieve the item hit
  2061. if (FAILED(pcsi->pTO->ShowHelp(TreeView_HitTest( pcsi->hwndTree, &ht),HELP_CONTEXTMENU)))
  2062. {
  2063. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  2064. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  2065. }
  2066. break;
  2067. }
  2068. case WM_DESTROY:
  2069. if (pcsi)
  2070. {
  2071. if (pcsi->pTO)
  2072. {
  2073. pcsi->pTO->WalkTree( WALK_TREE_DELETE );
  2074. pcsi->pTO->Release();
  2075. pcsi->pTO=NULL;
  2076. }
  2077. LocalFree(pcsi);
  2078. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)NULL);
  2079. CoUninitialize();
  2080. }
  2081. break;
  2082. }
  2083. return FALSE;
  2084. }
  2085. #ifdef UNIX
  2086. extern "C"
  2087. #endif
  2088. BOOL LaunchSecurityDialogEx(HWND hDlg, DWORD dwZone, DWORD dwFlags)
  2089. {
  2090. INITCOMMONCONTROLSEX icex;
  2091. SECURITYINITFLAGS * psif = NULL;
  2092. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  2093. icex.dwICC = ICC_USEREX_CLASSES|ICC_NATIVEFNTCTL_CLASS;
  2094. InitCommonControlsEx(&icex);
  2095. if(g_dwtlsSecInitFlags != (DWORD) -1)
  2096. psif = (SECURITYINITFLAGS *) TlsGetValue(g_dwtlsSecInitFlags);
  2097. if(psif)
  2098. {
  2099. psif->fForceUI = dwFlags & LSDFLAG_FORCEUI;
  2100. psif->fDisableAddSites = dwFlags & LSDFLAG_NOADDSITES;
  2101. psif->dwZone = dwZone;
  2102. }
  2103. // passing in a NULL psif is okay
  2104. DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SECSTANDALONE), hDlg,
  2105. SecurityDlgProc, (LPARAM) psif);
  2106. return TRUE;
  2107. }
  2108. // backwards compatability
  2109. #ifdef UNIX
  2110. extern "C"
  2111. #endif
  2112. void LaunchSecurityDialog(HWND hDlg, DWORD dwZone)
  2113. {
  2114. LaunchSecurityDialogEx(hDlg, dwZone, LSDFLAG_DEFAULT);
  2115. }
  2116. #ifdef UNIX
  2117. extern "C"
  2118. #endif
  2119. void LaunchSiteCertDialog(HWND hDlg)
  2120. {
  2121. CRYPTUI_CERT_MGR_STRUCT ccm = {0};
  2122. ccm.dwSize = sizeof(ccm);
  2123. ccm.hwndParent = hDlg;
  2124. CryptUIDlgCertMgr(&ccm);
  2125. }