Example #1
0
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            IPrincipal principal = null;
            IMessage   message2  = null;

            try
            {
                IMethodCallMessage methodCallMessage = reqMsg as IMethodCallMessage;
                if (methodCallMessage != null)
                {
                    LogicalCallContext logicalCallContext = methodCallMessage.LogicalCallContext;
                    if (logicalCallContext != null)
                    {
                        principal = logicalCallContext.RemovePrincipalIfNotSerializable();
                    }
                }
                MemoryStream memoryStream = null;
                SmuggledMethodCallMessage smuggledMethodCallMessage = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg);
                if (smuggledMethodCallMessage == null)
                {
                    memoryStream = CrossAppDomainSerializer.SerializeMessage(reqMsg);
                }
                LogicalCallContext          logicalCallContext2 = CallContext.SetLogicalCallContext(null);
                byte[]                      array = null;
                SmuggledMethodReturnMessage smuggledMethodReturnMessage;
                try
                {
                    if (smuggledMethodCallMessage != null)
                    {
                        array = this.DoTransitionDispatch(null, smuggledMethodCallMessage, out smuggledMethodReturnMessage);
                    }
                    else
                    {
                        array = this.DoTransitionDispatch(memoryStream.GetBuffer(), null, out smuggledMethodReturnMessage);
                    }
                }
                finally
                {
                    CallContext.SetLogicalCallContext(logicalCallContext2);
                }
                if (smuggledMethodReturnMessage != null)
                {
                    ArrayList deserializedArgs = smuggledMethodReturnMessage.FixupForNewAppDomain();
                    message2 = new MethodResponse((IMethodCallMessage)reqMsg, smuggledMethodReturnMessage, deserializedArgs);
                }
                else if (array != null)
                {
                    MemoryStream stm = new MemoryStream(array);
                    message2 = CrossAppDomainSerializer.DeserializeMessage(stm, reqMsg as IMethodCallMessage);
                }
            }
            catch (Exception e)
            {
                try
                {
                    message2 = new ReturnMessage(e, reqMsg as IMethodCallMessage);
                }
                catch (Exception)
                {
                }
            }
            if (principal != null)
            {
                IMethodReturnMessage methodReturnMessage = message2 as IMethodReturnMessage;
                if (methodReturnMessage != null)
                {
                    LogicalCallContext logicalCallContext3 = methodReturnMessage.LogicalCallContext;
                    logicalCallContext3.Principal = principal;
                }
            }
            return(message2);
        }
Example #2
0
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            if (message != null)
            {
                return(message);
            }
            IPrincipal principal = null;
            IMessage   message2  = null;

            try
            {
                SmuggledMethodReturnMessage message5;
                IMethodCallMessage          message3 = reqMsg as IMethodCallMessage;
                if (message3 != null)
                {
                    LogicalCallContext logicalCallContext = message3.LogicalCallContext;
                    if (logicalCallContext != null)
                    {
                        principal = logicalCallContext.RemovePrincipalIfNotSerializable();
                    }
                }
                MemoryStream stream = null;
                SmuggledMethodCallMessage smuggledMcm = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg);
                if (smuggledMcm == null)
                {
                    stream = CrossAppDomainSerializer.SerializeMessage(reqMsg);
                }
                LogicalCallContext callCtx = CallContext.SetLogicalCallContext(null);
                MemoryStream       stm     = null;
                byte[]             buffer  = null;
                try
                {
                    if (smuggledMcm != null)
                    {
                        buffer = this.DoTransitionDispatch(null, smuggledMcm, out message5);
                    }
                    else
                    {
                        buffer = this.DoTransitionDispatch(stream.GetBuffer(), null, out message5);
                    }
                }
                finally
                {
                    CallContext.SetLogicalCallContext(callCtx);
                }
                if (message5 != null)
                {
                    ArrayList deserializedArgs = message5.FixupForNewAppDomain();
                    message2 = new MethodResponse((IMethodCallMessage)reqMsg, message5, deserializedArgs);
                }
                else if (buffer != null)
                {
                    stm      = new MemoryStream(buffer);
                    message2 = CrossAppDomainSerializer.DeserializeMessage(stm, reqMsg as IMethodCallMessage);
                }
            }
            catch (Exception exception)
            {
                try
                {
                    message2 = new ReturnMessage(exception, reqMsg as IMethodCallMessage);
                }
                catch (Exception)
                {
                }
            }
            if (principal != null)
            {
                IMethodReturnMessage message6 = message2 as IMethodReturnMessage;
                if (message6 != null)
                {
                    message6.LogicalCallContext.Principal = principal;
                }
            }
            return(message2);
        }
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            Message.DebugOut("\n::::::::::::::::::::::::: CrossAppDomain Channel: [....] call starting");
            IMessage errMsg = InternalSink.ValidateMessage(reqMsg);

            if (errMsg != null)
            {
                return(errMsg);
            }


            // currentPrincipal is used to save the current principal. It should be
            //   restored on the reply message.
            IPrincipal currentPrincipal = null;


            IMessage desRetMsg = null;

            try
            {
                IMethodCallMessage mcmReqMsg = reqMsg as IMethodCallMessage;
                if (mcmReqMsg != null)
                {
                    LogicalCallContext lcc = mcmReqMsg.LogicalCallContext;
                    if (lcc != null)
                    {
                        // Special case Principal since if might not be serializable
                        currentPrincipal = lcc.RemovePrincipalIfNotSerializable();
                    }
                }

                MemoryStream reqStm = null;
                SmuggledMethodCallMessage smuggledMcm = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg);

                if (smuggledMcm == null)
                {
                    //*********************** SERIALIZE REQ-MSG ****************
                    // Deserialization of objects requires permissions that users
                    // of remoting are not guaranteed to possess. Since remoting
                    // can guarantee that it's users can't abuse deserialization
                    // (since it won't allow them to pass in raw blobs of
                    // serialized data), it should assert the permissions
                    // necessary before calling the deserialization code. This
                    // will terminate the security stackwalk caused when
                    // serialization checks for the correct permissions at the
                    // remoting stack frame so the check won't continue on to
                    // the user and fail. <EMAIL>[from [....]]</EMAIL>
                    // We will hold off from doing this for x-process channels
                    // until the big picture of distributed security is finalized.

                    reqStm = CrossAppDomainSerializer.SerializeMessage(reqMsg);
                }

                // Retrieve calling caller context here, where it is safe from the view
                // of app domain checking code
                LogicalCallContext oldCallCtx = CallContext.SetLogicalCallContext(null);

                // Call helper method here, to avoid confusion with stack frames & app domains
                MemoryStream retStm        = null;
                byte[]       responseBytes = null;
                SmuggledMethodReturnMessage smuggledMrm;

                try
                {
                    if (smuggledMcm != null)
                    {
                        responseBytes = DoTransitionDispatch(null, smuggledMcm, out smuggledMrm);
                    }
                    else
                    {
                        responseBytes = DoTransitionDispatch(reqStm.GetBuffer(), null, out smuggledMrm);
                    }
                }
                finally
                {
                    CallContext.SetLogicalCallContext(oldCallCtx);
                }

                if (smuggledMrm != null)
                {
                    ArrayList deserializedArgs = smuggledMrm.FixupForNewAppDomain();
                    desRetMsg = new MethodResponse((IMethodCallMessage)reqMsg,
                                                   smuggledMrm,
                                                   deserializedArgs);
                }
                else
                {
                    if (responseBytes != null)
                    {
                        retStm = new MemoryStream(responseBytes);

                        Message.DebugOut("::::::::::::::::::::::::::: CrossAppDomain Channel: [....] call returning!!\n");
                        //*********************** DESERIALIZE RET-MSG **************
                        desRetMsg = CrossAppDomainSerializer.DeserializeMessage(retStm, reqMsg as IMethodCallMessage);
                    }
                }
            }
            catch (Exception e)
            {
                Message.DebugOut("Arrgh.. XAppDomainSink::throwing exception " + e + "\n");
                try
                {
                    desRetMsg = new ReturnMessage(e, (reqMsg as IMethodCallMessage));
                }
                catch (Exception)
                {
                    // Fatal Error .. can't do much here
                }
            }

            // restore the principal if necessary.
            if (currentPrincipal != null)
            {
                IMethodReturnMessage mrmRetMsg = desRetMsg as IMethodReturnMessage;
                if (mrmRetMsg != null)
                {
                    LogicalCallContext lcc = mrmRetMsg.LogicalCallContext;
                    lcc.Principal = currentPrincipal;
                }
            }

            return(desRetMsg);
        }
Example #4
0
        public virtual IMessage SyncProcessMessage(IMessage reqMsg)
        {
            IMessage message1 = InternalSink.ValidateMessage(reqMsg);

            if (message1 != null)
            {
                return(message1);
            }
            IPrincipal principal = (IPrincipal)null;
            IMessage   message2  = (IMessage)null;

            try
            {
                IMethodCallMessage methodCallMessage = reqMsg as IMethodCallMessage;
                if (methodCallMessage != null)
                {
                    LogicalCallContext logicalCallContext = methodCallMessage.LogicalCallContext;
                    if (logicalCallContext != null)
                    {
                        principal = logicalCallContext.RemovePrincipalIfNotSerializable();
                    }
                }
                MemoryStream memoryStream             = (MemoryStream)null;
                SmuggledMethodCallMessage smuggledMcm = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg);
                if (smuggledMcm == null)
                {
                    memoryStream = CrossAppDomainSerializer.SerializeMessage(reqMsg);
                }
                LogicalCallContext          callCtx = CallContext.SetLogicalCallContext((LogicalCallContext)null);
                byte[]                      buffer  = (byte[])null;
                SmuggledMethodReturnMessage smuggledMrm;
                try
                {
                    buffer = smuggledMcm == null?this.DoTransitionDispatch(memoryStream.GetBuffer(), (SmuggledMethodCallMessage)null, out smuggledMrm) : this.DoTransitionDispatch((byte[])null, smuggledMcm, out smuggledMrm);
                }
                finally
                {
                    CallContext.SetLogicalCallContext(callCtx);
                }
                if (smuggledMrm != null)
                {
                    ArrayList deserializedArgs = smuggledMrm.FixupForNewAppDomain();
                    message2 = (IMessage) new MethodResponse((IMethodCallMessage)reqMsg, smuggledMrm, deserializedArgs);
                }
                else if (buffer != null)
                {
                    message2 = CrossAppDomainSerializer.DeserializeMessage(new MemoryStream(buffer), reqMsg as IMethodCallMessage);
                }
            }
            catch (Exception ex1)
            {
                try
                {
                    message2 = (IMessage) new ReturnMessage(ex1, reqMsg as IMethodCallMessage);
                }
                catch (Exception ex2)
                {
                }
            }
            if (principal != null)
            {
                IMethodReturnMessage methodReturnMessage = message2 as IMethodReturnMessage;
                if (methodReturnMessage != null)
                {
                    methodReturnMessage.LogicalCallContext.Principal = principal;
                }
            }
            return(message2);
        }