コード例 #1
0
        protected override byte[] GetUpdatedBufferToSend(ArraySegment <byte> buffer)
        {
            try
            {
                byte[] result;
                string text;
                if (this.TryGetUpdatedBufferToSend(buffer, out result, out text))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[RpsOutDataResponseStreamProxy::GetUpdatedBufferToSend] Context={0}, Buffer updated.", base.RequestContext.TraceContext);
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(base.RequestContext.Logger, "FriendlyError", "StreamProxy");

                    return(result);
                }
                if (text != null)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(base.RequestContext.Logger, "FriendlyError", text);
                }
            }
            catch (Exception ex)
            {
                Diagnostics.ReportException(ex, FrontEndHttpProxyEventLogConstants.Tuple_InternalServerError, null, "Exception from RpsOutDataResponseStreamProxy::GetUpdatedBufferToSend event: {0}");
                RequestDetailsLogger logger = base.RequestContext.Logger;
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(logger, "GetUpdatedBufferToSendException", ex.ToString());
            }
            return(base.GetUpdatedBufferToSend(buffer));
        }
コード例 #2
0
 internal void SafeLogUriData(Uri requestUrl)
 {
     if (requestUrl.IsAbsoluteUri)
     {
         this.Set(HttpProxyMetadata.UrlHost, requestUrl.DnsSafeHost);
         this.Set(HttpProxyMetadata.UrlStem, requestUrl.LocalPath);
         this.Set(HttpProxyMetadata.UrlQuery, requestUrl.Query);
         return;
     }
     RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(this, "InvalidRelativeUri", requestUrl.ToString());
 }
コード例 #3
0
 // Token: 0x060005F3 RID: 1523 RVA: 0x00021354 File Offset: 0x0001F554
 private static void InspectNativeProxyFatalError(HttpResponse httpResponse, RequestDetailsLogger requestLogger)
 {
     if (!HttpProxySettings.DiagnosticsEnabled.Value)
     {
         string text = httpResponse.Headers[NativeProxyHelper.NativeProxyStatusHeaders.ProxyErrorHResult];
         if (!string.IsNullOrEmpty(text))
         {
             string arg  = httpResponse.Headers[NativeProxyHelper.NativeProxyStatusHeaders.ProxyErrorLabel];
             string arg2 = httpResponse.Headers[NativeProxyHelper.NativeProxyStatusHeaders.ProxyErrorMessage];
             RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestLogger, "ProxyError", string.Format("[{0}] [{1}] {2}", text, arg, arg2));
         }
     }
 }
コード例 #4
0
ファイル: ProxyModule.cs プロジェクト: YHZX2013/exchange_diff
        private void OnBeginRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                LatencyTracker latencyTracker = new LatencyTracker();
                latencyTracker.StartTracking(LatencyTrackerKey.ProxyModuleLatency, false);
                AspNetHelper.AddTimestampHeaderIfNecessary(httpContext.Request.Headers, "X-FrontEnd-Begin");
                if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug <string, Uri, int>((long)this.GetHashCode(), "[ProxyModule::OnBeginRequest]: Method {0}; Url {1}; Context {2};", httpContext.Request.HttpMethod, httpContext.Request.Url, httpContext.GetHashCode());
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    HealthCheckResponder.Instance.CheckHealthStateAndRespond(httpContext);
                    return;
                }
                RequestDetailsLogger requestDetailsLogger = RequestDetailsLoggerBase <RequestDetailsLogger> .InitializeRequestLogger();
                requestDetailsLogger.LogCurrentTime("BeginRequest");
                httpContext.Items[Constants.TraceContextKey] = httpContext.GetHashCode();
                httpContext.Items[Constants.LatencyTrackerContextKeyName] = latencyTracker;
                requestDetailsLogger.ActivityScope.UpdateFromMessage(httpContext.Request);
                requestDetailsLogger.ActivityScope.SerializeTo(httpContext.Response);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SetCurrent(httpContext, requestDetailsLogger);
                httpContext.Items[typeof(ActivityScope)] = requestDetailsLogger.ActivityScope;
                httpContext.Items[Constants.RequestIdHttpContextKeyName] = requestDetailsLogger.ActivityScope.ActivityId;
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.Protocol, HttpProxyGlobals.ProtocolType);
                requestDetailsLogger.SafeLogUriData(httpContext.Request.Url);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, ServiceCommonMetadata.HttpMethod, httpContext.Request.HttpMethod);
                string requestCorrelationId = AspNetHelper.GetRequestCorrelationId(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "CorrelationID", requestCorrelationId);
                httpContext.Response.AppendToLog(Constants.CorrelationIdKeyForIISLogs + requestCorrelationId + ";");
                string cookieValueAndSetIfNull = ClientIdCookie.GetCookieValueAndSetIfNull(httpContext);
                httpContext.Response.AppendToLog(string.Format("&{0}={1}", "ClientId", cookieValueAndSetIfNull));
                UrlUtilities.SaveOriginalRequestHostSchemePortToContext(httpContext);
                try
                {
                    this.OnBeginRequestInternal(httpApplication);
                }
                catch (Exception ex)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestDetailsLogger, "OnBeginRequestInternal", ex.ToString());
                    requestDetailsLogger.AsyncCommit(false);
                    throw;
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
コード例 #5
0
        internal static void SafeAppendGenericError(string key, string value, bool isUnhandledException)
        {
            if (!LoggerSettings.LogEnabled)
            {
                return;
            }
            string genericErrorKey = Diagnostics.GetGenericErrorKey(key, isUnhandledException);

            if (LoggerSettings.IsPowerShellWebService)
            {
                RequestDetailsLoggerBase <PswsLogger> .SafeAppendGenericError(RequestDetailsLoggerBase <PswsLogger> .Current, genericErrorKey, value);

                return;
            }
            RequestDetailsLoggerBase <RpsHttpLogger> .SafeAppendGenericError(RequestDetailsLoggerBase <RpsHttpLogger> .Current, genericErrorKey, value);
        }
コード例 #6
0
        // Token: 0x06000237 RID: 567 RVA: 0x0000B090 File Offset: 0x00009290
        public void Remove(Guid database, IRequestContext requestContext)
        {
            string key = database.ToString();

            if (this.TryRemoveFromInMemoryCache(key))
            {
                this.UpdateInMemoryCacheSizeCounter();
            }
            SharedCacheDiagnostics sharedCacheDiagnostics;

            if (this.TryRemoveFromSharedCache(key, out sharedCacheDiagnostics))
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestContext.Logger, "SharedCache", "MailboxServerCacheEntryRemovalSuccess");
            }
            else
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestContext.Logger, "SharedCache", "MailboxServerCacheEntryRemovalFailure");
            }
            MailboxServerCache.LogSharedCacheDiagnostics(requestContext, sharedCacheDiagnostics);
        }
コード例 #7
0
        internal static void SafeAppendGenericError(Guid cmdletUniqueId, string key, string value, bool isUnhandledException)
        {
            if (!LoggerSettings.LogEnabled)
            {
                return;
            }
            string genericErrorKey = Diagnostics.GetGenericErrorKey(key, isUnhandledException);

            if (LoggerHelper.IsPswsNormalRequest)
            {
                RequestDetailsLoggerBase <PswsLogger> .SafeAppendGenericError(RequestDetailsLoggerBase <PswsLogger> .Current, genericErrorKey, value);

                return;
            }
            RpsCmdletLoggerBuffer rpsCmdletLoggerBuffer = RpsCmdletLoggerBuffer.Get(cmdletUniqueId);

            if (rpsCmdletLoggerBuffer != null)
            {
                rpsCmdletLoggerBuffer.AppendGenericError(genericErrorKey, value);
            }
        }
コード例 #8
0
        // Token: 0x06000218 RID: 536 RVA: 0x0000A8E0 File Offset: 0x00008AE0
        public void Remove(string key, IRequestContext requestContext)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (this.TryRemoveFromInMemoryCache(key))
            {
                this.UpdateInMemoryCacheSizeCounter();
            }
            SharedCacheDiagnostics sharedCacheDiagnostics;

            if (this.TryRemoveFromSharedCache(key, out sharedCacheDiagnostics))
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestContext.Logger, "SharedCache", "AMCacheRemovalSuccess");
            }
            else
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestContext.Logger, "SharedCache", "AMCacheRemovalFailure");
            }
            AnchorMailboxCache.LogSharedCacheDiagnostics(requestContext, sharedCacheDiagnostics);
        }
コード例 #9
0
        // Token: 0x060001E0 RID: 480 RVA: 0x00008C98 File Offset: 0x00006E98
        public override AnchorMailbox CreateAuthModuleSpecificAnchorMailbox(IRequestContext requestContext)
        {
            HttpContext          httpContext = requestContext.HttpContext;
            OAuthPreAuthIdentity oauthPreAuthIdentity;

            if (HttpContextUserParser.TryGetOAuthPreAuthIdentity(httpContext.User, ref oauthPreAuthIdentity))
            {
                try
                {
                    string externalDirectoryObjectId;
                    if (!RequestHeaderParser.TryGetExternalDirectoryObjectId(httpContext.Request.Headers, ref externalDirectoryObjectId))
                    {
                        OAuthPreAuthType preAuthType = oauthPreAuthIdentity.PreAuthType;
                        switch (preAuthType)
                        {
                        case 1:
                            requestContext.Logger.SafeSet(3, "PreAuth-Smtp");
                            return(new SmtpAnchorMailbox(oauthPreAuthIdentity.LookupValue, requestContext));

                        case 2:
                            requestContext.Logger.SafeSet(3, "PreAuth-LiveID");
                            return(new LiveIdMemberNameAnchorMailbox(oauthPreAuthIdentity.LookupValue, null, requestContext));

                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                            break;

                        case 8:
                            requestContext.Logger.SafeSet(3, "PreAuth-TenantGuid");
                            return(new DomainAnchorMailbox(oauthPreAuthIdentity.TenantGuid.ToString(), requestContext));

                        case 9:
                            requestContext.Logger.SafeSet(3, "PreAuth-TenantDomain");
                            return(new DomainAnchorMailbox(oauthPreAuthIdentity.TenantDomain, requestContext));

                        case 10:
                            requestContext.Logger.SafeSet(3, "PreAuth-ExternalDirectoryObjectIdTenantGuid");
                            return(new ExternalDirectoryObjectIdAnchorMailbox(oauthPreAuthIdentity.LookupValue, oauthPreAuthIdentity.TenantGuid, requestContext));

                        case 11:
                            requestContext.Logger.SafeSet(3, "PreAuth-ExternalDirectoryObjectIdTenantDomain");
                            return(new ExternalDirectoryObjectIdAnchorMailbox(oauthPreAuthIdentity.LookupValue, oauthPreAuthIdentity.TenantDomain, requestContext));

                        default:
                            switch (preAuthType)
                            {
                            case 99:
                            {
                                string arg = "Unable to parse OAuth token to locate routing key, extended error data=" + oauthPreAuthIdentity.ExtendedErrorInformation;
                                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestContext.Logger, "OAuthError", oauthPreAuthIdentity.ExtendedErrorInformation);

                                MSDiagnosticsHeader.SetStandardOAuthDiagnosticsResponse(httpContext, 2000001, string.Format(OAuthErrorsUtil.GetDescription(2007), arg), null, null);
                                requestContext.Logger.SafeSet(3, "PreAuth-AnonymousAnchorMailbox");
                                return(new AnonymousAnchorMailbox(requestContext));
                            }

                            case 100:
                                requestContext.Logger.SafeSet(3, "PreAuth-PuidAndDomain");
                                return(new PuidAnchorMailbox(oauthPreAuthIdentity.LookupValue, oauthPreAuthIdentity.TenantDomain, requestContext, string.Empty));

                            case 101:
                                requestContext.Logger.SafeSet(3, "PreAuth-PuidAndTenantGuid");
                                return(new PuidAnchorMailbox(oauthPreAuthIdentity.LookupValue, oauthPreAuthIdentity.TenantGuid, requestContext, string.Empty));
                            }
                            break;
                        }
                        throw new InvalidOperationException("unknown preauth type");
                    }
                    requestContext.Logger.SafeSet(3, "PreAuth-ExternalDirectoryObjectId-Header");
                    if (!string.IsNullOrEmpty(oauthPreAuthIdentity.TenantDomain))
                    {
                        return(new ExternalDirectoryObjectIdAnchorMailbox(externalDirectoryObjectId, oauthPreAuthIdentity.TenantDomain, requestContext));
                    }
                    if (oauthPreAuthIdentity.TenantGuid != Guid.Empty)
                    {
                        return(new ExternalDirectoryObjectIdAnchorMailbox(externalDirectoryObjectId, oauthPreAuthIdentity.TenantGuid, requestContext));
                    }
                    throw new InvalidOperationException("unknown preauth type");
                }
                finally
                {
                    if (!string.IsNullOrEmpty(oauthPreAuthIdentity.LoggingInfo))
                    {
                        requestContext.Logger.AppendGenericInfo("OAuthInfo", oauthPreAuthIdentity.LoggingInfo);
                    }
                }
            }
            return(null);
        }
コード例 #10
0
        private void OnEndRequest(object sender, EventArgs e)
        {
            HttpContext  httpContext = HttpContext.Current;
            HttpResponse response    = httpContext.Response;

            if (response == null)
            {
                return;
            }
            RequestDetailsLogger current = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);

            RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "OnEndRequest.Start.ContentType", response.ContentType);

            if (response.Headers["X-RemotePS-RevisedAction"] != null)
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, HttpProxyMetadata.ProtocolAction, response.Headers["X-RemotePS-RevisedAction"]);
            }
            bool flag = httpContext.Items.Contains("X-HeaderPreSent") && (bool)httpContext.Items["X-HeaderPreSent"];

            if (flag)
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "FriendlyError", "Skip-HeaderPreSent");

                return;
            }
            try
            {
                int statusCode = response.StatusCode;
                int num;
                if (WinRMHelper.TryConvertStatusCode(statusCode, out num))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int, int>((long)this.GetHashCode(), "[RpsFriendlyErrorModule::OnEndRequest]: Convert status code from {0} to {1}.", statusCode, num);
                    response.StatusCode = num;
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, ServiceCommonMetadata.HttpStatus, statusCode);
                }
                if (statusCode >= 400 && !"Ping".Equals(response.Headers["X-RemotePS-Ping"], StringComparison.OrdinalIgnoreCase) && !"Possible-Ping".Equals(response.Headers["X-RemotePS-Ping"], StringComparison.OrdinalIgnoreCase))
                {
                    response.ContentType = "application/soap+xml;charset=UTF-8";
                    if (!WinRMHelper.DiagnosticsInfoHasBeenWritten(response.Headers))
                    {
                        string diagnosticsInfo = WinRMHelper.GetDiagnosticsInfo(httpContext);
                        ExTraceGlobals.VerboseTracer.TraceDebug <int, string>((long)this.GetHashCode(), "[RpsFriendlyErrorModule::OnEndRequest]: Original Status Code: {0}, Append diagnostics info: {1}.", statusCode, diagnosticsInfo);
                        if (statusCode == 401)
                        {
                            response.Output.Write(diagnosticsInfo + HttpProxyStrings.ErrorAccessDenied);
                        }
                        else
                        {
                            response.Output.Write(diagnosticsInfo);
                        }
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "FriendlyError", "HttpModule");
                    }
                }
            }
            catch (Exception ex)
            {
                ExTraceGlobals.VerboseTracer.TraceError <Exception>((long)this.GetHashCode(), "[RpsFriendlyErrorModule::OnEndRequest]: Exception = {0}", ex);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(current, "RpsFriendlyErrorModule.OnEndRequest", ex.Message);
            }
            finally
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "OnEndRequest.End.ContentType", response.ContentType);
            }
        }
コード例 #11
0
        // Token: 0x060006EE RID: 1774 RVA: 0x00028810 File Offset: 0x00026A10
        protected override void AddProtocolSpecificHeadersToServerRequest(WebHeaderCollection headers)
        {
            if (base.ClientRequest.IsAuthenticated && base.ProxyToDownLevel)
            {
                IIdentity          callerIdentity     = this.GetCallerIdentity();
                WindowsIdentity    windowsIdentity    = callerIdentity as WindowsIdentity;
                GenericSidIdentity genericSidIdentity = callerIdentity as GenericSidIdentity;
                IPrincipal         user = base.HttpContext.User;
                if (windowsIdentity != null)
                {
                    string text;
                    if (HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text))
                    {
                        headers["X-RemotePS-GenericIdentity"] = windowsIdentity.User.ToString();
                    }
                    else
                    {
                        headers["X-RemotePS-WindowsIdentity"] = this.GetSerializedAccessTokenString();
                    }
                }
                else if (genericSidIdentity != null)
                {
                    headers["X-RemotePS-GenericIdentity"] = genericSidIdentity.Sid.ToString();
                }
                else
                {
                    headers["X-RemotePS-GenericIdentity"] = IIdentityExtensions.GetSafeName(base.HttpContext.User.Identity, true);
                }
            }
            if (this.isSyndicatedAdminManageDownLevelTarget)
            {
                headers["msExchCafeForceRouteToLogonAccount"] = "1";
            }
            if (LoggerHelper.IsProbePingRequest(base.ClientRequest))
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(base.Logger, 21, "ProbePingBackend");
            }
            else if (WinRMHelper.WinRMParserEnabled.Value)
            {
                try
                {
                    this.winRMInfo = base.ParseClientRequest <WinRMInfo>(new Func <Stream, WinRMInfo>(this.ParseWinRMInfo), 10000);
                }
                catch (InvalidOperationException ex)
                {
                    if (ExTraceGlobals.ExceptionTracer.IsTraceEnabled(3))
                    {
                        ExTraceGlobals.ExceptionTracer.TraceError <InvalidOperationException>((long)this.GetHashCode(), "[RemotePowerShellProxyRequestHandler::AddProtocolSpecificHeadersToServerRequest] ParseClientRequest throws exception {0}", ex);
                    }
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(base.Logger, "ParseClientRequestException", ex.ToString());
                }
                if (this.winRMInfo != null)
                {
                    WinRMInfo.StampToHttpHeaders(this.winRMInfo, headers);
                }
            }
            DatabaseBasedAnchorMailbox databaseBasedAnchorMailbox = base.AnchoredRoutingTarget.AnchorMailbox as DatabaseBasedAnchorMailbox;

            if (databaseBasedAnchorMailbox != null)
            {
                ADObjectId database = databaseBasedAnchorMailbox.GetDatabase();
                if (database != null)
                {
                    headers["X-DatabaseGuid"] = database.ObjectGuid.ToString();
                }
            }
            if (!base.ShouldRetryOnError)
            {
                headers["X-Cafe-Last-Retry"] = "Y";
            }
            base.AddProtocolSpecificHeadersToServerRequest(headers);
        }