示例#1
0
        private DelayInfo GetHardQuotaDelay(ICollection <CostType> consideredCostTypes, BudgetTypeSetting budgetTypeSetting)
        {
            OverBudgetException ex = null;

            if (this.TryCheckOverBudget(consideredCostTypes, out ex))
            {
                int      backoffTime = ex.BackoffTime;
                TimeSpan timeSpan    = TimeSpan.FromMilliseconds((double)backoffTime);
                TimeSpan delay       = (timeSpan > budgetTypeSetting.MaxDelay) ? budgetTypeSetting.MaxDelay : timeSpan;
                return(new UserQuotaDelayInfo(delay, ex, true));
            }
            return(DelayInfo.NoDelay);
        }
        // Token: 0x06001594 RID: 5524 RVA: 0x000505B0 File Offset: 0x0004E7B0
        private static LocalizedException WrapOverBudgetException(OverBudgetException originalException, IBudget budget)
        {
            string value = string.Format("{0}{4}(PolicyDN: {1};{4}Snapshot: {2};{4}Computer: {3})", new object[]
            {
                originalException.Message,
                originalException.ThrottlingPolicyDN,
                originalException.Snapshot,
                ThrottlingModule <T> .computerName,
                Environment.NewLine
            });

            return(new OverBudgetException(new LocalizedString(value), budget, originalException.PolicyPart, originalException.PolicyValue, originalException.BackoffTime));
        }
        // Token: 0x060073F6 RID: 29686 RVA: 0x0017E9BC File Offset: 0x0017CBBC
        protected override bool InternalTryCheckOverBudget(ICollection <CostType> consideredCostTypes, out OverBudgetException exception)
        {
            this.Update();
            OverBudgetException ex  = null;
            OverBudgetException ex2 = null;
            OverBudgetException ex3 = null;

            base.InternalTryCheckOverBudget(consideredCostTypes, out ex);
            if (consideredCostTypes.Contains(CostType.ActiveRunspace))
            {
                this.TryCheckOverBudget(CostType.ActiveRunspace, out ex2);
            }
            if (consideredCostTypes.Contains(CostType.CMDLET))
            {
                this.TryCheckOverBudget(CostType.CMDLET, out ex3);
            }
            int num = 0;
            OverBudgetException ex4 = null;

            if (ex != null && ex.BackoffTime > num)
            {
                ex4 = ex;
                num = ex.BackoffTime;
            }
            if (ex2 != null && (ex2.BackoffTime > num || ex2.BackoffTime == -1))
            {
                ex4 = ex2;
                num = ex2.BackoffTime;
            }
            if (ex3 != null && (ex3.BackoffTime > num || ex3.BackoffTime == -1))
            {
                ex4 = ex3;
                num = ex3.BackoffTime;
            }
            exception = ex4;
            return(exception != null);
        }
示例#4
0
 // Token: 0x06007402 RID: 29698 RVA: 0x0017EE79 File Offset: 0x0017D079
 public bool TryCheckOverBudget(CostType costType, out OverBudgetException exception)
 {
     return(base.GetInnerBudget().TryCheckOverBudget(costType, out exception));
 }
        // Token: 0x060073F5 RID: 29685 RVA: 0x0017E74C File Offset: 0x0017C94C
        internal bool TryCheckOverBudget(CostType costType, out OverBudgetException exception)
        {
            exception = null;
            this.Update();
            if (base.CasTokenBucket.Locked)
            {
                int num = (int)(base.CasTokenBucket.LockedUntilUtc.Value - TimeProvider.UtcNow).TotalMilliseconds;
                if (num > 0)
                {
                    exception = base.CreateOverBudgetException("LocalTime", base.ThrottlingPolicy.CutoffBalance.ToString(), num);
                    return(true);
                }
            }
            switch (costType)
            {
            case CostType.CMDLET:
            {
                int    num2        = 0;
                string text        = null;
                string policyValue = null;
                if (this.IsDestructiveCmdletPerTimePeriodEnabled() && this.destructiveCmdletsRemaining < 0L)
                {
                    int backoffTime = this.GetBackoffTime(this.powerShellMaxDestructiveCmdletsTimePeriodPolicyValue.Value, this.lastTimeFrameDestructiveCmdlets);
                    if (backoffTime > num2)
                    {
                        num2        = backoffTime;
                        text        = "MaxDestructiveCmdletsTimePeriod";
                        policyValue = string.Format("{0}/{1}s", this.powerShellMaxDestructiveCmdletsPolicyValue, this.powerShellMaxDestructiveCmdletsTimePeriodPolicyValue);
                    }
                }
                bool flag  = this.IsCmdletPerTimePeriodEnabled() && this.cmdletsRemaining < 0L;
                bool flag2 = this.IsExchangeCmdletPerTimePeriodEnabled() && this.exchangeCmdletsRemaining < 0L;
                if (flag || flag2)
                {
                    int backoffTime = this.GetBackoffTime(this.powerShellMaxCmdletsTimePeriodPolicyValue.Value, this.lastTimeFrame);
                    if (backoffTime > num2)
                    {
                        num2        = backoffTime;
                        text        = (flag ? "PowerShellMaxCmdlets" : "ExchangeMaxCmdlets");
                        policyValue = string.Format("{0}/{1}s", flag ? this.powerShellMaxCmdletsPolicyValue : this.exchangeMaxCmdletsPolicyValue, this.powerShellMaxCmdletsTimePeriodPolicyValue);
                    }
                }
                if (!string.IsNullOrEmpty(text))
                {
                    exception = base.CreateOverBudgetException(text, policyValue, num2);
                }
                return(exception != null);
            }

            case CostType.ActiveRunspace:
                if (this.IsMaxConcurrencyEnabled() && (long)this.activeRunspaces >= (long)((ulong)this.activeRunspacesPolicyValue.Value))
                {
                    exception = base.CreateOverBudgetException(this.MaxConcurrencyOverBudgetReason, this.activeRunspacesPolicyValue.Value.ToString(), int.MaxValue);
                }
                else if (this.IsMaxRunspacesPerTimePeriodEnabled() && this.runspacesRemaining <= 0L)
                {
                    int backoffTime2 = this.GetBackoffTime(this.powerShellMaxRunspacesTimePeriodPolicyValue.Value, this.lastTimeFrameRunspaces);
                    exception = base.CreateOverBudgetException(this.MaxRunspacesTimePeriodOverBudgetReason, string.Format("{0}/{1}s", this.powerShellMaxRunspacesPolicyValue, this.powerShellMaxRunspacesTimePeriodPolicyValue), backoffTime2);
                }
                return(exception != null);

            default:
                throw new ArgumentException("[PowerShellBudget.TryCheckOverBudget] Unsupported CostType: " + costType.ToString(), "costType");
            }
        }
示例#6
0
 internal bool CheckOverBudget(AuthZPluginUserToken userToken, CostType costType, out OverBudgetException exception)
 {
     exception = null;
     if (!this.ShouldThrottling(userToken))
     {
         return(false);
     }
     lock (this.instanceLock)
     {
         IPowerShellBudget budget = this.GetBudget(userToken, false, false);
         if (budget != null)
         {
             return(budget.TryCheckOverBudget(costType, out exception));
         }
         ExTraceGlobals.PublicPluginAPITracer.TraceDebug <string>(0L, "Try to check overbudget for key {0}. But the budget doesn't exist.", this.CreateKey(userToken));
     }
     return(false);
 }
示例#7
0
        private void ThrottleRequest(HttpContext context)
        {
            ExTraceGlobals.HttpModuleTracer.TraceFunction((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Enter");
            WinRMInfo winRMInfo = context.Items["X-RemotePS-WinRMInfo"] as WinRMInfo;

            if (winRMInfo == null)
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo = null.");
                return;
            }
            string action = winRMInfo.Action;

            if (string.IsNullOrEmpty(action))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo.Action = null.");
                return;
            }
            if (!action.EndsWith(":Command", StringComparison.OrdinalIgnoreCase) && !action.Equals("Command", StringComparison.OrdinalIgnoreCase))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug <string>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Not Command Request. WinRMInfo.Action = {0}.", action);
                return;
            }
            IPowerShellBudget   powerShellBudget = null;
            OverBudgetException ex = null;

            try
            {
                try
                {
                    using (new MonitoredScope("ThrottlingHttpModule", "GetBudget", HttpModuleHelper.HttpPerfMonitors))
                    {
                        powerShellBudget = this.GetBudget(context);
                    }
                    if (powerShellBudget == null)
                    {
                        ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] budget = null.");
                        return;
                    }
                    using (new MonitoredScope("ThrottlingHttpModule", "CheckBudgetAndStartCmdlet", HttpModuleHelper.HttpPerfMonitors))
                    {
                        powerShellBudget.StartCmdlet(null);
                        powerShellBudget.TryCheckOverBudget(CostType.CMDLET, out ex);
                    }
                }
                finally
                {
                    if (powerShellBudget != null)
                    {
                        powerShellBudget.Dispose();
                    }
                }
                if (ex != null)
                {
                    string windowsLiveId = context.CurrentUserToken().WindowsLiveId;
                    if (windowsLiveId != null)
                    {
                        FailFastUserCache.Instance.AddUserToCache(windowsLiveId, BlockedType.NewRequest, TimeSpan.Zero);
                        HttpLogger.SafeAppendColumn(RpsCommonMetadata.ContributeToFailFast, "AuthZ-UserSelf", LoggerHelper.GetContributeToFailFastValue("User", windowsLiveId, BlockedType.NewRequest.ToString(), -1.0));
                    }
                    HttpModuleHelper.EndPowerShellRequestWithFriendlyError(context, FailureCategory.AuthZ, ex.GetType().Name, Strings.ErrorOperationTarpitting(ex.BackoffTime / 1000) + string.Format("{2}Policy: {0}; {2}Snapshot: {1}", ex.ThrottlingPolicyDN, ex.Snapshot, Environment.NewLine), "ThrottlingHttpModule", false);
                }
            }
            catch (Exception ex2)
            {
                if (!(ex2 is ThreadAbortException))
                {
                    HttpLogger.SafeAppendGenericError("ThrottlingHttpModule", ex2, new Func <Exception, bool>(KnownException.IsUnhandledException));
                    ExTraceGlobals.HttpModuleTracer.TraceError <Exception>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Get un-Excpected Exception. {0}", ex2);
                }
            }
        }
示例#8
0
        public bool TryCheckOverBudget(ICollection <CostType> consideredCostTypes, out OverBudgetException exception)
        {
            T t = this.GetInnerBudget();

            return(t.TryCheckOverBudget(consideredCostTypes, out exception));
        }
示例#9
0
 public bool TryCheckOverBudget(out OverBudgetException exception)
 {
     return(this.TryCheckOverBudget(Budget.AllCostTypes, out exception));
 }
示例#10
0
 public UserQuotaDelayInfo(TimeSpan delay, OverBudgetException exception, bool required) : base(delay, required)
 {
     this.OverBudgetException = exception;
 }
示例#11
0
 public static UserQuotaDelayInfo CreateInfinite(OverBudgetException exception)
 {
     return(new UserQuotaDelayInfo(Budget.IndefiniteDelay, exception, true));
 }
        // Token: 0x0600097E RID: 2430 RVA: 0x00020CF4 File Offset: 0x0001EEF4
        internal static void HandleException(RequestContext requestContext, Exception exception)
        {
            if (exception is HttpException && (exception.InnerException is SlabManifestException || exception.InnerException is FlightConfigurationException))
            {
                exception = exception.InnerException;
            }
            ErrorHandlerUtilities.RecordException(requestContext, exception);
            ExTraceGlobals.CoreTracer.TraceDebug <Type, Exception>(0L, "Exception: Type: {0} Error: {1}.", exception.GetType(), exception);
            HttpContext httpContext = requestContext.HttpContext;

            HttpUtilities.MakePageNoCacheNoStore(httpContext.Response);
            if (exception is HttpException)
            {
                HttpUtilities.EndResponse(httpContext, HttpStatusCode.BadRequest);
                return;
            }
            if (exception is OwaInvalidRequestException || exception is OwaInvalidIdFormatException)
            {
                HttpUtilities.EndResponse(httpContext, HttpStatusCode.BadRequest);
                return;
            }
            if (exception is MailboxInSiteFailoverException && requestContext.UserContext != null)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "User {0}'s mailbox in-site failover occurs.", requestContext.UserContext.ExchangePrincipal.LegacyDn);
                if (requestContext.UserContext != null)
                {
                    requestContext.UserContext.DisconnectMailboxSession();
                }
            }
            if (exception is MailboxCrossSiteFailoverException || exception is WrongServerException)
            {
                if (requestContext.UserContext != null)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "User {0}'s mailbox cross-site failover occurs.", requestContext.UserContext.ExchangePrincipal.LegacyDn);
                }
                UserContextCookie userContextCookie = UserContextCookie.GetUserContextCookie(httpContext);
                if (userContextCookie != null)
                {
                    HttpUtilities.DeleteCookie(httpContext.Response, userContextCookie.CookieName);
                }
            }
            if (exception is OverBudgetException)
            {
                OverBudgetException ex = (OverBudgetException)exception;
                httpContext.Response.AppendToLog(string.Format("&OverBudget({0}/{1}),Owner:{2}[{3}]", new object[]
                {
                    ex.IsServiceAccountBudget ? "ServiceAccount" : "Normal",
                    ex.PolicyPart,
                    ex.Owner,
                    ex.Snapshot
                }));
            }
            ErrorInformation exceptionHandlingInformation = ErrorHandlerUtilities.GetExceptionHandlingInformation(exception, requestContext);

            try
            {
                if (!requestContext.ErrorSent)
                {
                    requestContext.ErrorSent = true;
                    httpContext.Response.Clear();
                    try
                    {
                        if (RequestDispatcherUtilities.GetRequestType(httpContext.Request) != OwaRequestType.ServiceRequest && RequestDispatcherUtilities.GetRequestType(httpContext.Request) != OwaRequestType.Oeh && !httpContext.Request.Path.Contains(OwaUrl.SessionDataPage.ImplicitUrl))
                        {
                            StringBuilder stringBuilder = new StringBuilder("/owa/auth/errorfe.aspx");
                            stringBuilder.Append("?");
                            stringBuilder.Append("httpCode");
                            stringBuilder.Append("=");
                            stringBuilder.Append(500);
                            if (exceptionHandlingInformation.SharePointApp)
                            {
                                stringBuilder.Append("&sharepointapp=true");
                            }
                            if (exceptionHandlingInformation.SiteMailbox)
                            {
                                stringBuilder.Append("&sm=true");
                            }
                            if (exceptionHandlingInformation.GroupMailboxDestination != null)
                            {
                                stringBuilder.Append("&gm=");
                                stringBuilder.Append(HttpUtility.UrlEncode(exceptionHandlingInformation.GroupMailboxDestination));
                            }
                            if (exceptionHandlingInformation.MessageId != null)
                            {
                                stringBuilder.Append("&");
                                stringBuilder.Append("msg");
                                stringBuilder.Append("=");
                                stringBuilder.Append((long)exceptionHandlingInformation.MessageId.Value);
                                if (!string.IsNullOrWhiteSpace(exceptionHandlingInformation.MessageParameter))
                                {
                                    stringBuilder.Append("&");
                                    stringBuilder.Append("msgParam");
                                    stringBuilder.Append("=");
                                    stringBuilder.Append(HttpUtility.UrlEncode(exceptionHandlingInformation.MessageParameter));
                                }
                            }
                            if (!string.IsNullOrWhiteSpace(httpContext.Response.Headers["X-OWA-Error"]))
                            {
                                stringBuilder.Append("&owaError=");
                                stringBuilder.Append(httpContext.Response.Headers["X-OWA-Error"]);
                            }
                            stringBuilder.Append("&owaVer=");
                            stringBuilder.Append(Globals.ApplicationVersion);
                            stringBuilder.Append("&be=");
                            stringBuilder.Append(Environment.MachineName);
                            stringBuilder.Append("&ts=");
                            stringBuilder.Append(DateTime.UtcNow.ToFileTimeUtc());
                            if (!string.IsNullOrWhiteSpace(exceptionHandlingInformation.Lids))
                            {
                                httpContext.Response.AppendToLog(string.Format("&lids={0}", exceptionHandlingInformation.Lids));
                            }
                            if (exceptionHandlingInformation.SupportLevel != null && exceptionHandlingInformation.SupportLevel != SupportLevel.Unknown)
                            {
                                httpContext.Response.AppendHeader("X-OWASuppLevel", exceptionHandlingInformation.SupportLevel.ToString());
                                httpContext.Response.AppendToLog(string.Format("&{0}={1}", "suplvl", exceptionHandlingInformation.SupportLevel.ToString()));
                            }
                            httpContext.Response.Redirect(stringBuilder.ToString(), false);
                        }
                        else
                        {
                            httpContext.Response.Write(exceptionHandlingInformation.Message);
                            httpContext.Response.StatusCode = 500;
                            if (exceptionHandlingInformation.MessageId != null)
                            {
                                httpContext.Response.AddHeader(WellKnownHeader.XOWAErrorMessageID, exceptionHandlingInformation.MessageId.ToString());
                            }
                            httpContext.Response.TrySkipIisCustomErrors = true;
                            httpContext.Response.Flush();
                        }
                        httpContext.ApplicationInstance.CompleteRequest();
                    }
                    catch (HttpException arg)
                    {
                        ExTraceGlobals.CoreTracer.TraceDebug <HttpException>(0L, "Failed to flush and send response to client after submitting watson and rendering error page. {0}", arg);
                    }
                }
            }
            finally
            {
                if (exceptionHandlingInformation.SendWatsonReport && Globals.SendWatsonReports)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug(0L, "Sending watson report");
                    ReportOptions options = (exception is AccessViolationException || exception is InvalidProgramException || exception is TypeInitializationException) ? ReportOptions.ReportTerminateAfterSend : ReportOptions.None;
                    ExWatson.SendReport(exception, options, null);
                }
                if (exception is AccessViolationException)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug(0L, "Shutting down OWA due to unrecoverable exception");
                    ErrorHandlerUtilities.TerminateProcess();
                }
                else if ((exception is InvalidProgramException || exception is TypeInitializationException) && Interlocked.Exchange(ref ErrorHandlerUtilities.queuedDelayedRestart, 1) == 0)
                {
                    new Thread(new ThreadStart(ErrorHandlerUtilities.DelayedRestartUponUnexecutableCode)).Start();
                }
                httpContext.Response.End();
            }
        }
示例#13
0
        // Token: 0x060071E4 RID: 29156 RVA: 0x001793B8 File Offset: 0x001775B8
        protected virtual bool InternalTryCheckOverBudget(ICollection <CostType> costTypes, out OverBudgetException exception)
        {
            exception = null;
            bool   flag = false;
            int    num  = 0;
            string text = null;

            ExTraceGlobals.FaultInjectionTracer.TraceTest <int>(4238748989U, ref num);
            bool flag2 = false;

            ExTraceGlobals.FaultInjectionTracer.TraceTest <bool>(3871747389U, ref flag2);
            if (flag2)
            {
                exception = this.CreateOverBudgetException("LocalTime", "faultInjection", num);
                return(true);
            }
            ExTraceGlobals.FaultInjectionTracer.TraceTest <bool>(3165007165U, ref flag);
            if (flag)
            {
                ExTraceGlobals.FaultInjectionTracer.TraceTest <string>(2628136253U, ref text);
                if (num != 0 && !string.IsNullOrEmpty(text))
                {
                    exception = this.CreateOverBudgetException(text, "faultInjection", num);
                    return(true);
                }
            }
            DateTime?lockedUntilUtc = this.casTokenBucket.LockedUntilUtc;

            if (lockedUntilUtc != null && costTypes.Contains(CostType.CAS))
            {
                DateTime value    = lockedUntilUtc.Value;
                TimeSpan timeSpan = value - TimeProvider.UtcNow;
                if (value == DateTime.MaxValue || timeSpan.TotalMilliseconds > 2147483647.0)
                {
                    num = int.MaxValue;
                }
                else
                {
                    num = Math.Max(0, (int)timeSpan.TotalMilliseconds);
                }
                if (num > 0)
                {
                    this.CheckLeakedActions();
                    exception = this.CreateOverBudgetException("LocalTime", this.ThrottlingPolicy.CutoffBalance.ToString(), num);
                }
            }
            return(exception != null);
        }