internal void ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
        {
            Exception reason = (Exception)null;
            bool      flag;

            try
            {
                flag = this.ShouldRun(commandInfo, origin, host, out reason);
            }
            catch (Exception ex)
            {
                CommandProcessorBase.CheckForSevereException(ex);
                flag   = false;
                reason = (Exception)null;
            }
            if (flag)
            {
                return;
            }
            if (reason == null)
            {
                throw new PSSecurityException(ResourceManagerCache.GetResourceString("AuthorizationManagerBase", "AuthorizationManagerDefaultFailureReason"));
            }
            if (reason is PSSecurityException)
            {
                AuthorizationManager.tracer.TraceException(reason);
                throw reason;
            }
            PSSecurityException securityException = new PSSecurityException(reason.Message, reason);

            AuthorizationManager.tracer.TraceException((Exception)securityException);
            throw securityException;
        }
        internal void ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
        {
            bool      flag   = false;
            bool      flag2  = false;
            Exception reason = null;

            try
            {
                lock (this.policyCheckLock)
                {
                    flag = this.ShouldRun(commandInfo, origin, host, out reason);
                }
            }
            catch (Exception exception2)
            {
                CommandProcessorBase.CheckForSevereException(exception2);
                reason = exception2;
                flag2  = true;
                flag   = false;
            }
            if (!flag)
            {
                if (reason == null)
                {
                    throw new PSSecurityException(AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason);
                }
                if (reason is PSSecurityException)
                {
                    throw reason;
                }
                string message = reason.Message;
                if (flag2)
                {
                    message = AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason;
                }
                PSSecurityException exception3 = new PSSecurityException(message, reason);
                throw exception3;
            }
        }
Beispiel #3
0
 internal void ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
 {
     bool flag = false;
     bool flag2 = false;
     Exception reason = null;
     try
     {
         lock (this.policyCheckLock)
         {
             flag = this.ShouldRun(commandInfo, origin, host, out reason);
         }
     }
     catch (Exception exception2)
     {
         CommandProcessorBase.CheckForSevereException(exception2);
         reason = exception2;
         flag2 = true;
         flag = false;
     }
     if (!flag)
     {
         if (reason == null)
         {
             throw new PSSecurityException(AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason);
         }
         if (reason is PSSecurityException)
         {
             throw reason;
         }
         string message = reason.Message;
         if (flag2)
         {
             message = AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason;
         }
         PSSecurityException exception3 = new PSSecurityException(message, reason);
         throw exception3;
     }
 }
        /// <summary>
        /// determine if we should run the specified file
        /// </summary>
        /// <param name="commandInfo">Info on entity to be run.</param>
        /// <param name="origin">The dispatch origin of a command.</param>
        /// <param name="host">Allows access to the host.</param>
        /// <remarks>
        /// This method throws SecurityException in case running is not allowed.
        /// </remarks>
        /// <exception cref="System.Management.Automation.PSSecurityException">
        /// If the derived security manager threw an exception or returned
        /// false with a reason.
        /// </exception>
        internal void ShouldRunInternal(CommandInfo commandInfo,
                                        CommandOrigin origin,
                                        PSHost host)
        {
#if UNIX
            // TODO:PSL this is a workaround since the exception below
            // hides the internal issue of what's going on in terms of
            // execution policy.
            // On non-Windows platform Set/Get-ExecutionPolicy throw
            // PlatformNotSupportedException
            return;
#else
#if DEBUG
            // If we are debugging, let the unit tests swap the file from beneath us
            if (commandInfo.CommandType == CommandTypes.ExternalScript)
            {
                while (Environment.GetEnvironmentVariable("PSCommandDiscoveryPreDelay") != null)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
#endif

            bool      result       = false;
            bool      defaultCatch = false;
            Exception authorizationManagerException = null;

            try
            {
                lock (_policyCheckLock)
                {
                    result = this.ShouldRun(commandInfo, origin, host, out authorizationManagerException);
                }

#if DEBUG
                // If we are debugging, let the unit tests swap the file from beneath us
                if (commandInfo.CommandType == CommandTypes.ExternalScript)
                {
                    while (Environment.GetEnvironmentVariable("PSCommandDiscoveryPostDelay") != null)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
#endif
            }
            catch (Exception e) // Catch-all OK. 3rd party callout
            {
                authorizationManagerException = e;

                defaultCatch = true;
                result       = false;
            }

            if (!result)
            {
                if (authorizationManagerException != null)
                {
                    if (authorizationManagerException is PSSecurityException)
                    {
                        throw authorizationManagerException;
                    }
                    else
                    {
                        string message = authorizationManagerException.Message;
                        if (defaultCatch)
                        {
                            message = AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason;
                        }

                        PSSecurityException securityException = new PSSecurityException(message, authorizationManagerException);
                        throw securityException;
                    }
                }
                else
                {
                    throw new PSSecurityException(AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason);
                }
            }
#endif
        }
Beispiel #5
0
        /// <summary>
        /// determine if we should run the specified file
        /// </summary>
        ///
        /// <param name="commandInfo"> info on entity to be run </param>
        ///
        /// <param name="origin"> the dispatch origin of a command  </param>
        ///
        /// <param name="host"> allows access to the host. </param>
        ///
        /// <remarks>  
        /// This method throws SecurityException in case running is not allowed.
        /// </remarks>
        ///
        /// <exception cref="System.Management.Automation.PSSecurityException">
        /// If the derived security manager threw an exception or returned
        /// false with a reason.
        /// </exception>
        /// 
        internal void ShouldRunInternal(CommandInfo commandInfo,
                                        CommandOrigin origin,
                                        PSHost host)
        {
#if UNIX
            // TODO:PSL this is a workaround since the exception below
            // hides the internal issue of what's going on in terms of
            // execution policy.  
            // On non-Windows platform Set/Get-ExecutionPolicy throw   
            // PlatformNotSupportedException
            return;
#else


#if DEBUG
            // If we are debugging, let the unit tests swap the file from beneath us
            if(commandInfo.CommandType == CommandTypes.ExternalScript)
            {
                while(Environment.GetEnvironmentVariable("PSCommandDiscoveryPreDelay") != null) { System.Threading.Thread.Sleep(100); }
            }
#endif

            bool result = false;
            bool defaultCatch = false;
            Exception authorizationManagerException = null;

            try
            {
                lock (_policyCheckLock)
                {
                    result = this.ShouldRun(commandInfo, origin, host, out authorizationManagerException);
                }

#if DEBUG
                // If we are debugging, let the unit tests swap the file from beneath us
                if(commandInfo.CommandType == CommandTypes.ExternalScript)
                {
                    while(Environment.GetEnvironmentVariable("PSCommandDiscoveryPostDelay") != null) { System.Threading.Thread.Sleep(100); }
                }
#endif
            }
            catch (Exception e) // Catch-all OK. 3rd party callout
            {
                CommandProcessorBase.CheckForSevereException(e);
                authorizationManagerException = e;

                defaultCatch = true;
                result = false;
            }

            if (!result)
            {
                if (authorizationManagerException != null)
                {
                    if (authorizationManagerException is PSSecurityException)
                    {
                        throw authorizationManagerException;
                    }
                    else
                    {
                        string message = authorizationManagerException.Message;
                        if (defaultCatch)
                        {
                            message = AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason;
                        }

                        PSSecurityException securityException = new PSSecurityException(message, authorizationManagerException);
                        throw securityException;
                    }
                }
                else
                {
                    throw new PSSecurityException(AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason);
                }
            }
#endif
        }