Пример #1
0
        internal static void DemandWriteFileIO(string fileName)
        {
            string full = fileName;

            new EnvironmentPermission(PermissionState.Unrestricted).Assert();
            try {
                full = Path.GetFullPath(fileName);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            new FileIOPermission(FileIOPermissionAccess.Write, full).Demand();
        }
Пример #2
0
        public void SetCodeFinishedHandler(CodeFinishedHandlerObject handler)
        {
            PermissionSet perm = new PermissionSet(PermissionState.None);

            perm.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
            perm.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
            perm.AddPermission(new FileIOPermission(PermissionState.Unrestricted));

            perm.Assert();
            CodeFinished = (CodeFinishedHandlerObject)handler;

            CodeAccessPermission.RevertAssert();
        }
Пример #3
0
 public void ApplicaitonExitCleanupTest()
 {
     //TODO: Finsih the "ApplicationExitCleanupTest" Test as it's not finished.
     try
     {
         (new ImageManagement.Tests.ImageManagerTests()).OutputByteArrayImageToTempDirectoryForReviewTest();
         CodeAccessPermission.RevertAssert();
     }
     catch (Exception e)
     {
     }
     FileSystemManager.ApplicaitonExitCleanup();
 }
        public RSACng(CngKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            LegalKeySizesValue = s_legalKeySizes;

            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
            Key = CngKey.Open(key.Handle, key.IsEphemeral ? CngKeyHandleOpenOptions.EphemeralKey : CngKeyHandleOpenOptions.None);
            CodeAccessPermission.RevertAssert();
        }
Пример #5
0
        internal static FileStream CreateAndOpenTemporaryFile(out string filePath, FileAccess fileAccess = FileAccess.Write, FileOptions fileOptions = FileOptions.None, string extension = null, string subFolder = "WPF")
        {
            int num = 5;

            filePath = null;
            bool   flag = SecurityManager.CurrentThreadRequiresSecurityContextCapture();
            string text = Path.GetTempPath();

            if (!string.IsNullOrEmpty(subFolder))
            {
                string text2 = Path.Combine(text, subFolder);
                if (!Directory.Exists(text2))
                {
                    if (!flag)
                    {
                        Directory.CreateDirectory(text2);
                    }
                    else
                    {
                        new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, text).Assert();
                        Directory.CreateDirectory(text2);
                        CodeAccessPermission.RevertAssert();
                    }
                }
                text = text2;
            }
            if (flag)
            {
                new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, text).Assert();
            }
            FileStream fileStream = null;

            while (fileStream == null)
            {
                string text3 = Path.Combine(text, Path.GetRandomFileName());
                if (!string.IsNullOrEmpty(extension))
                {
                    text3 = Path.ChangeExtension(text3, extension);
                }
                num--;
                try
                {
                    fileStream = new FileStream(text3, FileMode.CreateNew, fileAccess, FileShare.None, 4096, fileOptions);
                    filePath   = text3;
                }
                catch (Exception ex) when(num > 0 && (ex is IOException || ex is UnauthorizedAccessException))
                {
                }
            }
            return(fileStream);
        }
Пример #6
0
        protected void ReadSystemConfig()
        {
            object      obj;
            RegistryKey stylusKey = null; // This object has finalizer to close the key.
            RegistryKey touchKey  = null; // This object has finalizer to close the key.

            // Acquire permissions to read the one key we care about from the registry
            new RegistryPermission(RegistryPermissionAccess.Read, WispKeyAssert).Assert(); // BlessedAssert

            try
            {
                stylusKey = Registry.CurrentUser.OpenSubKey(WispPenSystemEventParametersKey);

                if (stylusKey != null)
                {
                    obj = stylusKey.GetValue(WispDoubleTapDistanceValue);
                    _stylusDoubleTapDelta = (obj == null) ? _stylusDoubleTapDelta : (Int32)obj;      // The default double tap distance is 15 pixels (value is given in pixels)

                    obj = stylusKey.GetValue(WispDoubleTapTimeValue);
                    _stylusDoubleTapDeltaTime = (obj == null) ? _stylusDoubleTapDeltaTime : (Int32)obj;      // The default double tap timeout is 800ms

                    obj          = stylusKey.GetValue(WispCancelDeltaValue);
                    _cancelDelta = (obj == null) ? _cancelDelta : (Int32)obj;      // The default move delta is 40 (4mm)
                }

                touchKey = Registry.CurrentUser.OpenSubKey(WispTouchConfigKey);

                if (touchKey != null)
                {
                    obj = touchKey.GetValue(WispTouchDoubleTapDistanceValue);
                    // min = 70%; max = 130%, these values are taken from Stylus\Biblio.txt - 2
                    _touchDoubleTapDelta = (obj == null) ? _touchDoubleTapDelta : FitToCplCurve(_touchDoubleTapDelta * DoubleTapMinFactor, _touchDoubleTapDelta, _touchDoubleTapDelta * DoubleTapMaxFactor, (Int32)obj);

                    obj = touchKey.GetValue(WispTouchDoubleTapTimeValue);
                    _touchDoubleTapDeltaTime = (obj == null) ? _touchDoubleTapDeltaTime : FitToCplCurve(_touchDoubleTapDeltaTime * DoubleTapMinFactor, _touchDoubleTapDeltaTime, _touchDoubleTapDeltaTime * DoubleTapMaxFactor, (Int32)obj);
                }
            }
            finally
            {
                CodeAccessPermission.RevertAssert();

                if (stylusKey != null)
                {
                    stylusKey.Close();
                }
                if (touchKey != null)
                {
                    touchKey.Close();
                }
            }
        }
Пример #7
0
        public ECDsaCng(CngKey key)
        {
            Contract.Ensures(LegalKeySizesValue != null);
            Contract.Ensures(m_key != null && IsEccAlgorithmGroup(m_key.AlgorithmGroup));

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (!IsEccAlgorithmGroup(key.AlgorithmGroup))
            {
                throw new ArgumentException(SR.GetString(SR.Cryptography_ArgECDsaRequiresECDsaKey), "key");
            }

            if (!NCryptNative.NCryptSupported)
            {
                throw new PlatformNotSupportedException(SR.GetString(SR.Cryptography_PlatformNotSupported));
            }

            LegalKeySizesValue = s_legalKeySizes;

            // Make a copy of the key so that we continue to work if it gets disposed before this algorithm
            //
            // This requires an assert for UnmanagedCode since we'll need to access the raw handles of the key
            // and the handle constructor of CngKey.  The assert is safe since ECDsaCng will never expose the
            // key handles to calling code (without first demanding UnmanagedCode via the Handle property of
            // CngKey).
            //
            // We also need to dispose of the key handle since CngKey.Handle returns a duplicate
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
            using (SafeNCryptKeyHandle keyHandle = key.Handle) {
                Key = CngKey.Open(keyHandle, key.IsEphemeral ? CngKeyHandleOpenOptions.EphemeralKey : CngKeyHandleOpenOptions.None);
            }
            CodeAccessPermission.RevertAssert();

            // Our LegalKeySizes value stores the values that we encoded as being the correct
            // legal key size limitations for this algorithm, as documented on MSDN.
            //
            // But on a new OS version we might not question if our limit is accurate, or MSDN
            // could have been innacurate to start with.
            //
            // Since the key is already loaded, we know that Windows thought it to be valid;
            // therefore we should set KeySizeValue directly to bypass the LegalKeySizes conformance
            // check.
            //
            // For RSA there are known cases where this change matters. RSACryptoServiceProvider can
            // create a 384-bit RSA key, which we consider too small to be legal. It can also create
            // a 1032-bit RSA key, which we consider illegal because it doesn't match our 64-bit
            // alignment requirement. (In both cases Windows loads it just fine)
            KeySizeValue = m_key.KeySize;
        }
Пример #8
0
            AcquirePrintQueue(
                string printerName
                )
            {
                PrintQueue printQueue = null;

                EnumeratedPrintQueueTypes[] types = new EnumeratedPrintQueueTypes[] {
                    EnumeratedPrintQueueTypes.Local,
                    EnumeratedPrintQueueTypes.Connections
                };

                //
                // This forces us to acquire the cached version of the print queues.
                // This theoretically should prevent crashing in the printing system
                // since all it is doing is reading the registry.
                //
                PrintQueueIndexedProperty[] props = new PrintQueueIndexedProperty[] {
                    PrintQueueIndexedProperty.Name,
                    PrintQueueIndexedProperty.QueueAttributes
                };

                SystemDrawingHelper.NewDefaultPrintingPermission().Assert();  //BlessedAssert
                try
                {
                    //
                    // Get the PrintQueue instance for the printer
                    //
                    using (LocalPrintServer server = new LocalPrintServer())
                    {
                        foreach (PrintQueue queue in server.GetPrintQueues(props, types))
                        {
                            if (printerName.Equals(queue.FullName, StringComparison.OrdinalIgnoreCase))
                            {
                                printQueue = queue;
                                break;
                            }
                        }
                    }
                    if (printQueue != null)
                    {
                        printQueue.InPartialTrust = true;
                    }
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }

                return(printQueue);
            }
Пример #9
0
        private static Switch[] GetSwitchesFromLoadedAssemblies()
        {
            ArrayList list = new ArrayList();

            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

            new ReflectionPermission(PermissionState.Unrestricted).Assert();
            try {
                foreach (Assembly assembly in assemblies)
                {
                    Module[] modules = assembly.GetLoadedModules();

                    foreach (Module module in modules)
                    {
                        if (module != null)
                        {
                            foreach (Type type in module.GetTypes())
                            {
                                if (type != null)
                                {
                                    MemberInfo[] members = type.FindMembers(MemberTypes.Field,
                                                                            BindingFlags.Static
                                                                            | BindingFlags.Public
                                                                            | BindingFlags.NonPublic,
                                                                            new MemberFilter(Filter),
                                                                            null);

                                    foreach (MemberInfo member in members)
                                    {
                                        if (member != null && member is FieldInfo)
                                        {
                                            FieldInfo field = (FieldInfo)member;
                                            object    value = field.GetValue(null);
                                            if (value != null)
                                            {
                                                list.Add(value);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            return((Switch[])list.ToArray(typeof(Switch)));
        }
Пример #10
0
        internal static string GetTempAssemblyPath(string baseDir, Assembly assembly, string defaultNamespace)
        {
            if (assembly.IsDynamic)
            {
                throw new InvalidOperationException(Res.GetString(Res.XmlPregenAssemblyDynamic));
            }

            PermissionSet perms = new PermissionSet(PermissionState.None);

            perms.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
            perms.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
            perms.Assert();

            try {
                if (baseDir != null && baseDir.Length > 0)
                {
                    // check that the dirsctory exists
                    if (!Directory.Exists(baseDir))
                    {
                        throw new UnauthorizedAccessException(Res.GetString(Res.XmlPregenMissingDirectory, baseDir));
                    }
                }
                else
                {
                    baseDir = Path.GetTempPath();
                    // check that the dirsctory exists
                    if (!Directory.Exists(baseDir))
                    {
                        throw new UnauthorizedAccessException(Res.GetString(Res.XmlPregenMissingTempDirectory));
                    }
                }

#if MONO
                baseDir = Path.Combine(baseDir, GetTempAssemblyName(assembly.GetName(), defaultNamespace));
#else
                if (baseDir.EndsWith("\\", StringComparison.Ordinal))
                {
                    baseDir += GetTempAssemblyName(assembly.GetName(), defaultNamespace);
                }
                else
                {
                    baseDir += "\\" + GetTempAssemblyName(assembly.GetName(), defaultNamespace);
                }
#endif
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            return(baseDir + ".dll");
        }
        internal static string UnsafeGetFullPath(string fileName)
        {
            string full = fileName;

            FileIOPermission fiop = new FileIOPermission(PermissionState.None)
            {
                AllFiles = FileIOPermissionAccess.PathDiscovery
            };

            fiop.Assert();
            try { full = Path.GetFullPath(fileName); }
            finally { CodeAccessPermission.RevertAssert(); }
            return(full);
        }
        private string[] GetRolesForUserCore(string username)
        {
            object clientContext = this.GetClientContext(username);

            if (clientContext == null)
            {
                return(new string[0]);
            }
            object obj3 = this.CallMethod(clientContext, "GetRoles", new object[] { this._ScopeName });

            if ((obj3 == null) || !(obj3 is IEnumerable))
            {
                return(new string[0]);
            }
            StringCollection strings = new StringCollection();

            try
            {
                if (HostingEnvironment.IsHosted && (this._XmlFileName != null))
                {
                    InternalSecurityPermissions.Unrestricted.Assert();
                }
                try
                {
                    IEnumerable enumerable = (IEnumerable)obj3;
                    foreach (object obj4 in enumerable)
                    {
                        string str = (string)obj4;
                        if (str != null)
                        {
                            strings.Add(str);
                        }
                    }
                }
                finally
                {
                    if (HostingEnvironment.IsHosted && (this._XmlFileName != null))
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            catch
            {
                throw;
            }
            string[] array = new string[strings.Count];
            strings.CopyTo(array, 0);
            return(array);
        }
Пример #13
0
            public void Prepare(Socket socket)
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();

                try
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
            }
        private static void DoUserInitiatedNavigation(object sender)
        {
            CodeAccessPermission codeAccessPermission = SecurityHelper.CreateUserInitiatedNavigationPermission();

            codeAccessPermission.Assert();
            try
            {
                Hyperlink.DispatchNavigation(sender);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
        }
Пример #15
0
        static void InitializeComponentFromXamlResource(Type componentType, string resource, object componentInstance, XamlSchemaContext schemaContext)
        {
            Stream           initializeXaml = componentType.Assembly.GetManifestResourceStream(resource);
            XmlReader        xmlReader      = null;
            XamlReader       reader         = null;
            XamlObjectWriter objectWriter   = null;

            try
            {
                xmlReader = XmlReader.Create(initializeXaml, new XmlReaderSettings {
                    XmlResolver = null
                });
                XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings();
                readerSettings.LocalAssembly = componentType.Assembly;
                readerSettings.AllowProtectedMembersOnRoot = true;
                reader = new XamlXmlReader(xmlReader, schemaContext, readerSettings);
                XamlObjectWriterSettings writerSettings = new XamlObjectWriterSettings();
                writerSettings.RootObjectInstance = componentInstance;
                writerSettings.AccessLevel        = XamlAccessLevel.PrivateAccessTo(componentType);
                objectWriter = new XamlObjectWriter(schemaContext, writerSettings);

                // We need the XamlLoadPermission for the assembly we are dealing with.
                XamlLoadPermission perm = new XamlLoadPermission(XamlAccessLevel.PrivateAccessTo(componentType));
                perm.Assert();
                try
                {
                    XamlServices.Transform(reader, objectWriter);
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
            }
            finally
            {
                if ((xmlReader != null))
                {
                    ((IDisposable)(xmlReader)).Dispose();
                }
                if ((reader != null))
                {
                    ((IDisposable)(reader)).Dispose();
                }
                if ((objectWriter != null))
                {
                    ((IDisposable)(objectWriter)).Dispose();
                }
            }
        }
Пример #16
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        private bool IsUserInRoleCore(string username, string roleName)
        {
            object objClientContext = GetClientContext(username);

            if (objClientContext == null)
            {
                return(false);
            }
            object objAllRoles = CallMethod(objClientContext, "GetRoles", new object[] { _ScopeName });

            if (objAllRoles == null || !(objAllRoles is IEnumerable))
            {
                return(false);
            }

            try
            {
                if (HostingEnvironment.IsHosted && _XmlFileName != null)
                {
                    InternalSecurityPermissions.Unrestricted.Assert();
                }

                try
                {
                    IEnumerable allRoles = (IEnumerable)objAllRoles;

                    foreach (object objRoleName in allRoles)
                    {
                        string strRoleName = (string)objRoleName;
                        if (strRoleName != null && StringUtil.EqualsIgnoreCase(strRoleName, roleName))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
                finally
                {
                    if (HostingEnvironment.IsHosted && _XmlFileName != null)
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Пример #17
0
 private static int AdjustWndProcFlagsFromRegistry(int wndProcFlags)
 {
     new RegistryPermission(PermissionState.Unrestricted).Assert();
     try
     {
         RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\.NETFramework");
         if (key == null)
         {
             return(wndProcFlags);
         }
         try
         {
             object obj2 = key.GetValue("DbgJITDebugLaunchSetting");
             if (obj2 != null)
             {
                 int num = 0;
                 try
                 {
                     num = (int)obj2;
                 }
                 catch (InvalidCastException)
                 {
                     num = 1;
                 }
                 if (num != 1)
                 {
                     wndProcFlags |= 2;
                     wndProcFlags |= 8;
                 }
                 return(wndProcFlags);
             }
             if (key.GetValue("DbgManagedDebugger") != null)
             {
                 wndProcFlags |= 2;
                 wndProcFlags |= 8;
             }
             return(wndProcFlags);
         }
         finally
         {
             key.Close();
         }
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
     return(wndProcFlags);
 }
Пример #18
0
        internal override object GetBitmapFromBitmapSource(object source)
        {
            BitmapSource contentImage = (BitmapSource)source;
            int          imageWidth   = (int)contentImage.Width;
            int          imageHeight  = (int)contentImage.Height;

            Bitmap bitmapFinal = new Bitmap(
                imageWidth,
                imageHeight,
                System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            BitmapData bmData = bitmapFinal.LockBits(
                new Rectangle(0, 0, imageWidth, imageHeight),
                ImageLockMode.WriteOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            FormatConvertedBitmap formatConverter = new FormatConvertedBitmap();

            formatConverter.BeginInit();
            formatConverter.Source            = contentImage;
            formatConverter.DestinationFormat = System.Windows.Media.PixelFormats.Bgr32;
            formatConverter.EndInit();

            CodeAccessPermission mediaAccessPermission = SecurityHelper.CreateMediaAccessPermission(null);

            if (mediaAccessPermission != null)
            {
                mediaAccessPermission.Assert(); //BlessedAssert
            }
            try
            {
                formatConverter.CopyPixels(
                    new Int32Rect(0, 0, imageWidth, imageHeight),
                    bmData.Scan0,
                    bmData.Stride * (bmData.Height - 1) + (bmData.Width * 4),
                    bmData.Stride);
            }
            finally
            {
                if (mediaAccessPermission != null)
                {
                    CodeAccessPermission.RevertAssert();
                }
            }

            bitmapFinal.UnlockBits(bmData);

            return(bitmapFinal);
        }
Пример #19
0
            void InitDynamicModule(string asmName)
            {
                // See http://blogs.msdn.com/Microsoft/archive/2005/02/03/366429.aspx for a simple example
                // of debuggable reflection-emit.
                Fx.Assert(dynamicModule == null, "can only be initialized once");

                // create a dynamic assembly and module
                AssemblyName assemblyName = new AssemblyName();

                assemblyName.Name = asmName;

                AssemblyBuilder assemblyBuilder;

                // The temporary assembly needs to be Transparent.
                ConstructorInfo transparentCtor =
                    typeof(SecurityTransparentAttribute).GetConstructor(
                        Type.EmptyTypes);
                CustomAttributeBuilder transparent = new CustomAttributeBuilder(
                    transparentCtor,
                    new Object[] { });

                assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run, null, true, new CustomAttributeBuilder[] { transparent });

                // Mark generated code as debuggable.
                // See http://blogs.msdn.com/rmbyers/archive/2005/06/26/432922.aspx for explanation.
                Type                   debuggableAttributeType = typeof(DebuggableAttribute);
                ConstructorInfo        constructorInfo         = debuggableAttributeType.GetConstructor(new Type[] { typeof(DebuggableAttribute.DebuggingModes) });
                CustomAttributeBuilder builder = new CustomAttributeBuilder(constructorInfo, new object[] {
                    DebuggableAttribute.DebuggingModes.DisableOptimizations |
                    DebuggableAttribute.DebuggingModes.Default
                });

                assemblyBuilder.SetCustomAttribute(builder);

                // We need UnmanagedCode permissions because we are asking for Symbols to be emitted.
                // We are protecting the dynamicModule so that only Critical code modifies it.
                PermissionSet unmanagedCodePermissionSet = new PermissionSet(PermissionState.None);

                unmanagedCodePermissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
                unmanagedCodePermissionSet.Assert();
                try
                {
                    dynamicModule = assemblyBuilder.DefineDynamicModule(asmName, true); // <-- pass 'true' to track debug info.
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
            }
Пример #20
0
        internal static Stream GetFileStream(string filename)
        {
            Stream stream;

            new FileIOPermission(FileIOPermissionAccess.Read, filename).Assert();
            try
            {
                stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(stream);
        }
Пример #21
0
 /// <summary>
 ///
 /// </summary>
 public static void PlayAsync(IEnumerable <byte[]> soundDatas)
 {
     UnmanagedCode.Assert();
     try
     {
         foreach (var soundData in soundDatas)
         {
             PlayAsync(soundData);
         }
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
 }
Пример #22
0
        public void RandomAccess()
        {
            try
            {
                ReflectionPermission LReflectionPermission = new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess | ReflectionPermissionFlag.AllFlags);
                LReflectionPermission.Assert();

                new RandomFixedSizeCacheAccess(new FixedSizeCache <string, string>(50), 50, 100000, 100).Run();
                Assert.True(ValidateList());
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
        }
Пример #23
0
 static internal string GetCurrentName()
 {
     try {                                                                           // try-filter-finally so and catch-throw
         (new SecurityPermission(SecurityPermissionFlag.ControlPrincipal)).Assert(); // MDAC 66683
         try {
             return(WindowsIdentity.GetCurrent().Name);
         }
         finally { // RevertAssert w/ catch-throw
             CodeAccessPermission.RevertAssert();
         }
     }
     catch { // MDAC 80973, 81286
         throw;
     }
 }
Пример #24
0
        private static Win32Exception CreateSafeWin32Exception()
        {
            Win32Exception exception = null;

            new SecurityPermission(PermissionState.Unrestricted).Assert();
            try
            {
                exception = new Win32Exception();
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(exception);
        }
Пример #25
0
 static private ITransaction ContextTransaction()                                 // MDAC 80681, 81288
 {
     try {                                                                        // try-filter-finally so and catch-throw
         (new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)).Assert(); // MDAC 62028
         try {
             return((ITransaction)ContextUtil.Transaction);
         }
         finally { // RevertAssert w/ catch-throw
             CodeAccessPermission.RevertAssert();
         }
     }
     catch { // MDAC 80973, 81286
         throw;
     }
 }
Пример #26
0
    internal static string UnsafeGetFullPath(string fileName)
    {
        FileIOPermission fileIOPermission = new FileIOPermission(PermissionState.None);

        fileIOPermission.AllFiles = FileIOPermissionAccess.PathDiscovery;
        fileIOPermission.Assert();
        try
        {
            return(Path.GetFullPath(fileName));
        }
        finally
        {
            CodeAccessPermission.RevertAssert();
        }
    }
Пример #27
0
        internal override DrawingGroup GetDrawing()
        {
            new UIPermission(UIPermissionWindow.AllWindows).Assert();
            DrawingGroup drawing;

            try
            {
                drawing = base.GetDrawing();
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(drawing);
        }
Пример #28
0
            internal virtual object CreateWebOC()
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
                object result;

                try
                {
                    result = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("8856f961-340a-11d0-a96b-00c04fd705a2")));
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
                return(result);
            }
Пример #29
0
        public override object InitializeLifetimeService()
        {
            ILease lease = (ILease)base.InitializeLifetimeService();

            new SecurityPermission(PermissionState.Unrestricted).Assert();
            try
            {
                lease.InitialLeaseTime = TimeSpan.Zero;
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(lease);
        }
Пример #30
0
        public Page1()
        {
            InitializeComponent();

            //<SnippetPermission>
            FileIOPermission fp = new FileIOPermission(PermissionState.Unrestricted);

            fp.Assert();

            // Perform operation that uses the assert

            // Revert the assert when operation is completed
            CodeAccessPermission.RevertAssert();
            //</SnippetPermission>
        }