public static string EnvironmentSetting(string environmentVariable)
        {
            EnvironmentPermission envPermission = new EnvironmentPermission( EnvironmentPermissionAccess.Read,environmentVariable);
             envPermission.Assert();

             return Environment.GetEnvironmentVariable(environmentVariable);
        }
Exemple #2
0
 static XamlSourceInfoHelper()
 {
     // Check environment variable
     const string environmentVariable = "ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO";
     EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, environmentVariable);
     environmentPermission.Assert();
     try
     {
         InitializeEnableXamlSourceInfo(Environment.GetEnvironmentVariable(environmentVariable));
     }
     finally
     {
         EnvironmentPermission.RevertAssert();
     }
 }
        public static void TestAssertAndDeny()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
               EnvironmentPermissionAccess.Read,
               "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Assert();
             try
             {
            SomeSecuredMethods.MethodProtectedByDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on Demand " +
               "with the asserted permission.");

            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on LinkDemand " +
               "with the asserted permission.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine(
               "Caller's Deny protected the library.{0}", e);
             }
        }
        private static string GetWPFInstallPath()
        {
            string path = null;

            // We support a "private CLR" which allows someone to use a different framework
            // location than what is specified in the registry.  The CLR support for this
            // involves two environment variable: COMPLUS_InstallRoot and COMPLUS_Version.
            EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, EnvironmentVariables);
            environmentPermission.Assert(); //Blessed Assert

            try
            {
                string version = Environment.GetEnvironmentVariable(COMPLUS_Version);
                if (!String.IsNullOrEmpty(version))
                {
                    path = Environment.GetEnvironmentVariable(COMPLUS_InstallRoot);
                    if (String.IsNullOrEmpty(path))
                    {
                        // The COMPLUS_Version environment variable was set, but the
                        // COMPLUS_InstallRoot environment variable was not.  We fall back
                        // to getting the framework install root from the registry, but
                        // still use the private CLR version.
                        path = ReadLocalMachineString(DOTNET_RegKey, DOTNET_Install_RegValue);
                    }

                    if (!String.IsNullOrEmpty(path))
                    {
                        path = Path.Combine(path, version);
                    }
                }
            }
            finally
            {
                EnvironmentPermission.RevertAssert();
            }

            if (String.IsNullOrEmpty(path))
            {
                // The COMPLUS_Version environment variable was not set.  We do not support
                // extracting the appropriate version ourselves, since this could come from
                // various places (app config, etc), so we default to 4.0.  The entire path
                // is stored in the registry, under the v4 key.
                path = ReadLocalMachineString(FRAMEWORK_RegKey, FRAMEWORK_InstallPath_RegValue);
            }

            // WPF chose to make a subdirectory for its own DLLs under the framework directory.
            path = Path.Combine(path, WPF_SUBDIR);

            return path;
        }
Exemple #5
0
 public static void A(string text)
 {
     EnvironmentPermission p = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "foo");
     p.Assert();
 }