예제 #1
0
        internal static int MapUrlToZoneWrapper(Uri uri)
        {
            int pdwZone = 0;
            int num     = 0;

            num = UnsafeNativeMethods.CoInternetCreateSecurityManager(null, out var ppISecurityManager, 0);
            if (MS.Win32.NativeMethods.Failed(num))
            {
                throw new Win32Exception(num);
            }
            UnsafeNativeMethods.IInternetSecurityManager internetSecurityManager = (MS.Win32.UnsafeNativeMethods.IInternetSecurityManager)ppISecurityManager;
            string pwszUrl = BindUriHelper.UriToString(uri);

            if (uri.IsFile)
            {
                internetSecurityManager.MapUrlToZone(pwszUrl, out pdwZone, 1);
            }
            else
            {
                internetSecurityManager.MapUrlToZone(pwszUrl, out pdwZone, 0);
            }
            if (pdwZone < 0)
            {
                throw new SecurityException(SR.Get("Invalid_URI"));
            }
            internetSecurityManager = null;
            ppISecurityManager      = null;
            return(pdwZone);
        }
예제 #2
0
        internal static int MapUrlToZoneWrapper(Uri uri)
        {
            int    targetZone = NativeMethods.URLZONE_LOCAL_MACHINE; // fail securely this is the most priveleged zone
            int    hr         = NativeMethods.S_OK;
            object curSecMgr  = null;

            hr = UnsafeNativeMethods.CoInternetCreateSecurityManager(
                null,
                out curSecMgr,
                0);
            if (NativeMethods.Failed(hr))
            {
                throw new Win32Exception(hr);
            }

            UnsafeNativeMethods.IInternetSecurityManager pSec = (UnsafeNativeMethods.IInternetSecurityManager)curSecMgr;

            string uriString = BindUriHelper.UriToString(uri);

            //
            // special case the condition if file is on local machine or UNC to ensure that content with mark of the web
            // does not yield with an internet zone result
            //
            if (uri.IsFile)
            {
                pSec.MapUrlToZone(uriString, out targetZone, MS.Win32.NativeMethods.MUTZ_NOSAVEDFILECHECK);
            }
            else
            {
                pSec.MapUrlToZone(uriString, out targetZone, 0);
            }
            //
            // This is the condition for Invalid zone
            //
            if (targetZone < 0)
            {
                throw new SecurityException(SR.Get(SRID.Invalid_URI));
            }
            pSec      = null;
            curSecMgr = null;
            return(targetZone);
        }