Exemple #1
0
        public static void Run(ContextBody callback)
        {
            callback();
            return;

            //WindowsIdentity.RunImpersonated(SafeAccessTokenHandle.InvalidHandle, () => callback());
            return;

            SecurityContext.Run(SecurityContext.Capture(), delegate(object state) {
                WindowsImpersonationContext context = null;
                try
                {
                    try
                    {
                        context = WindowsIdentity.Impersonate(IntPtr.Zero);
                        callback();
                    }
                    finally
                    {
                        if (context != null)
                        {
                            context.Undo();
                        }
                    }
                }
                catch
                {
                    throw;
                }
            }, null);
        }
Exemple #2
0
        public static void RunFromRestrictedCasContext(ContextBody callback)
        {
            callback();
            return;

            SecurityContext.Run(SecurityContext.Capture(), delegate(object state) {
                new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert();
                WindowsImpersonationContext context = null;
                try
                {
                    try
                    {
                        context = WindowsIdentity.Impersonate(IntPtr.Zero);
                        CodeAccessPermission.RevertAssert();
                        callback();
                    }
                    finally
                    {
                        if (context != null)
                        {
                            context.Undo();
                        }
                    }
                }
                catch
                {
                    throw;
                }
            }, null);
            return;

            SecurityContext.Run(SecurityContext.Capture(), delegate(object state)
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode | SecurityPermissionFlag.ControlPrincipal).Assert();
                //WindowsImpersonationContext windowsImpersonationContext = null;
                try
                {
                    try
                    {
                        WindowsIdentity.Impersonate(IntPtr.Zero);
                        //windowsImpersonationContext = WindowsIdentity.Impersonate(IntPtr.Zero);
                        //CodeAccessPermission.RevertAssert();
                        //WindowsIdentity.RunImpersonated(SafeAccessTokenHandle.InvalidHandle, () => callback());
                        //callback();
                    }
                    finally
                    {
                        //if (windowsImpersonationContext != null)
                        //{
                        //    windowsImpersonationContext.Undo();
                        //}
                    }
                }
                catch
                {
                    throw;
                }
            }, null);
        }
Exemple #3
0
 public static void RunFromRestrictedCasContext(ContextBody callback)
 {
     callback();
 }
Exemple #4
0
 public static void Run(ContextBody callback)
 {
     callback();
 }