Ejemplo n.º 1
0
        public void ConfigureSubCollections(ICatalogCollection coll)
        {
            if ((_installFlags & InstallationFlags.ConfigureComponentsOnly) == 0)
            {
                foreach (Type t in _spec.ConfigurableTypes)
                {
                    ICatalogObject     obj     = (ICatalogObject)FindObject(coll, t);
                    ICatalogCollection ifcColl = (ICatalogCollection)(coll.GetCollection(CollectionName.Interfaces, obj.Key()));

                    // Poke the cache so it's up to date...
                    _cache["Component"]     = obj;
                    _cache["ComponentType"] = t;

                    InterfaceConfigCallback cb = new InterfaceConfigCallback(ifcColl, t, _cache, _driver);
                    _driver.ConfigureCollection(ifcColl, cb);

                    if (_cache["SecurityOnMethods"] != null || ServicedComponentInfo.AreMethodsSecure(t))
                    {
                        DBG.Info(DBG.Registration, "Found security on methods for: " + t);
                        FixupMethodSecurity(ifcColl);
                        _cache["SecurityOnMethods"] = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override RealProxy CreateProxy(ObjRef objRef,
                                              Type serverType,
                                              Object serverObject,
                                              Context serverContext)

        {
            DBG.Assert(serverType != null, "server type is null in CreateProxy");

            //
            // If this guy isn't one of our objrefs, then we should use remoting.  Otherwise,
            // go ahead and call GetRealObject on it.
            //
            if (objRef == null)
            {
                return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
            }

            if ((objRef is FastRSCPObjRef) ||
                ((objRef is ServicedComponentMarshaler) &&
                 (!objRef.IsFromThisProcess() || ServicedComponentInfo.IsTypeEventSource(serverType))))
            {
                DBG.Info(DBG.SC, "SCPA: CreateProxy: delegating custom CreateProxy");
                Object otp = objRef.GetRealObject(new StreamingContext(StreamingContextStates.Remoting));
                return(RemotingServices.GetRealProxy(otp));
            }
            else
            {
                DBG.Info(DBG.SC, "SCPA: CreateProxy: delegating standard CreateProxy");
                return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
            }
        }
Ejemplo n.º 3
0
        /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.ServicedComponent"]/*' />
        public ServicedComponent()
        {
            ServicedComponentProxy pxy = RemotingServices.GetRealProxy(this) as ServicedComponentProxy;

            DBG.Assert(pxy != null, "RealProxy() is null during constructor!");
            pxy.SuppressFinalizeServer();

            Type thisType = this.GetType();

            _denyRemoteDispatch = ServicedComponentInfo.AreMethodsSecure(thisType);

            // Get the methodinfo for finalize...
            // REVIEW:  Do we have to do anything special to make sure we
            // get the one furthest down the chain?

            bool bFoundInCache = false;

            _finalize = _finalizeCache.Get(thisType, out bFoundInCache) as MethodInfo;

            if (bFoundInCache == false)
            {
                _finalize = GetDeclaredFinalizer(thisType);
                _finalizeCache.Put(thisType, _finalize);
            }

            _calledDispose = false;
        }
        MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
        {
            RealProxy realProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            int  num               = ServicedComponentInfo.SCICachedLookup(serverType);
            bool fIsJitActivated   = (num & 8) != 0;
            bool fIsPooled         = (num & 0x10) != 0;
            bool fAreMethodsSecure = (num & 0x20) != 0;

            if (fIsJitActivated)
            {
                object obj2 = IdentityTable.FindObject(Proxy.GetCurrentContextToken());
                if (obj2 != null)
                {
                    realProxy = RemotingServices.GetRealProxy(obj2);
                }
            }
            if (realProxy == null)
            {
                realProxy = new ServicedComponentProxy(serverType, fIsJitActivated, fIsPooled, fAreMethodsSecure, true);
            }
            else if (realProxy is ServicedComponentProxy)
            {
                ((ServicedComponentProxy)realProxy).ConstructServer();
            }
            return((MarshalByRefObject)realProxy.GetTransparentProxy());
        }
Ejemplo n.º 5
0
        public override Object GetRealObject(StreamingContext context)
        {
            DBG.Info(DBG.SC, "SCM: GetRealObject()");

            if (!IsMarshaledObject)
            {
                DBG.Info(DBG.SC, "SCM: GetRealObject() returning objref!");
                return(this);
            }
            else
            {
                if (IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(_rt))
                {
                    Object otp = base.GetRealObject(context);
                    // We need to notify the object that there is a managed reference.
                    ((ServicedComponent)otp).DoSetCOMIUnknown(IntPtr.Zero);

                    return(otp);
                }
                else
                {
                    if (_rp == null)
                    {
                        _rp = _um.GetRealProxy();
                    }
                    DBG.Assert(_rp != null, "GetRealObject on a marshaller with no proxy!");
                    return(_rp.GetTransparentProxy());
                }
            }
        }
        private IMessage CrossCtxInvoke(IMessage reqMsg)
        {
            IMessage message = null;

            this.AssertValid();
            message = this.HandleDispose(reqMsg);
            if (message != null)
            {
                return(message);
            }
            message = this.HandleSetCOMIUnknown(reqMsg);
            if (message != null)
            {
                return(message);
            }
            message = this.HandleSpecialMethods(reqMsg);
            if (message != null)
            {
                return(message);
            }
            object     transparentProxy = this.GetTransparentProxy();
            MethodBase methodBase       = ((IMethodMessage)reqMsg).MethodBase;
            MemberInfo mi          = methodBase;
            MemberInfo mb          = mi;
            MemberInfo info3       = null;
            MemberInfo m           = ReflectionCache.ConvertToClassMI(base.GetProxiedType(), mi);
            bool       fIsAutoDone = false;
            int        num         = ServicedComponentInfo.MICachedLookup(m);

            if (reqMsg is IConstructionCallMessage)
            {
                ComMemberType method = ComMemberType.Method;
                mb = Marshal.GetMethodInfoForComSlot(typeof(IManagedObject), 3, ref method);
            }
            else
            {
                info3 = this.AliasCall(methodBase as MethodInfo);
                if (info3 != null)
                {
                    mb = info3;
                }
                else if (this._fUseIntfDispatch || ((num & 4) != 0))
                {
                    mb = ReflectionCache.ConvertToInterfaceMI(mi);
                    if (mb == null)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
                    }
                }
                else
                {
                    fIsAutoDone = (num & 2) != 0;
                }
            }
            return(this._callback.DoCallback(transparentProxy, reqMsg, this._context, fIsAutoDone, mb, this._gitCookie != 0));
        }
        private void ReadTypes()
        {
            ArrayList list  = new ArrayList();
            ArrayList list2 = new ArrayList();

            foreach (Type type in new RegistrationServices().GetRegistrableTypesInAssembly(this._asm))
            {
                if (ServicedComponentInfo.IsTypeServicedComponent(type))
                {
                    object[] customAttributes = type.GetCustomAttributes(typeof(EventClassAttribute), true);
                    if ((customAttributes != null) && (customAttributes.Length > 0))
                    {
                        list.Add(type);
                    }
                    else
                    {
                        list2.Add(type);
                    }
                }
            }
            if (list.Count > 0)
            {
                this._events = new Type[list.Count];
                list.CopyTo(this._events);
            }
            else
            {
                this._events = null;
            }
            if (list2.Count > 0)
            {
                this._normal = new Type[list2.Count];
                list2.CopyTo(this._normal);
            }
            else
            {
                this._normal = null;
            }
            int num = ((this._normal != null) ? this._normal.Length : 0) + ((this._events != null) ? this._events.Length : 0);

            if (num > 0)
            {
                this._cfgtypes = new Type[num];
                if (this._events != null)
                {
                    this._events.CopyTo(this._cfgtypes, 0);
                }
                if (this._normal != null)
                {
                    this._normal.CopyTo(this._cfgtypes, (int)(num - this._normal.Length));
                }
            }
        }
        public void CheckAssemblySCValidity(Assembly asm)
        {
            Type[]               types    = null;
            bool                 flag     = true;
            ArrayList            list     = null;
            RegistrationServices services = new RegistrationServices();

            try
            {
                types = asm.GetTypes();
            }
            catch (ReflectionTypeLoadException exception)
            {
                types = exception.Types;
            }
            foreach (Type type in types)
            {
                if (((null != type) && type.IsClass) && type.IsSubclassOf(typeof(ServicedComponent)))
                {
                    if (!services.TypeRequiresRegistration(type) && !type.IsAbstract)
                    {
                        flag = false;
                        if (list == null)
                        {
                            list = new ArrayList();
                        }
                        RegistrationErrorInfo info = new RegistrationErrorInfo(null, null, type.ToString(), -2147467259);
                        list.Add(info);
                    }
                    ClassInterfaceType classInterfaceType = ServicedComponentInfo.GetClassInterfaceType(type);
                    foreach (MethodInfo info2 in type.GetMethods())
                    {
                        if (ReflectionCache.ConvertToInterfaceMI(info2) == null)
                        {
                            if (ServicedComponentInfo.HasSpecialMethodAttributes(info2))
                            {
                                this.ReportWarning(Resource.FormatString("Reg_NoClassInterfaceSecure", type.FullName, info2.Name));
                            }
                            if ((classInterfaceType == ClassInterfaceType.AutoDispatch) && ServicedComponentInfo.IsMethodAutoDone(info2))
                            {
                                this.ReportWarning(Resource.FormatString("Reg_NoClassInterface", type.FullName, info2.Name));
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                RegistrationErrorInfo[] errorInfo = (RegistrationErrorInfo[])list.ToArray(typeof(RegistrationErrorInfo));
                throw new RegistrationException(Resource.FormatString("Reg_InvalidServicedComponents"), errorInfo);
            }
        }
 internal RemoteServicedComponentProxy(Type serverType, IntPtr pUnk, bool fAttachServer) : base(serverType)
 {
     this._fUseIntfDispatch = ServicedComponentInfo.IsTypeEventSource(serverType) || ServicedComponentInfo.AreMethodsSecure(serverType);
     if (pUnk != IntPtr.Zero)
     {
         this._pUnk   = pUnk;
         this._server = EnterpriseServicesHelper.WrapIUnknownWithComObject(pUnk);
         if (fAttachServer)
         {
             base.AttachServer((MarshalByRefObject)this._server);
             this._fAttachedServer = true;
         }
     }
 }
Ejemplo n.º 10
0
        public ServicedComponent()
        {
            (RemotingServices.GetRealProxy(this) as ServicedComponentProxy).SuppressFinalizeServer();
            Type t = base.GetType();

            this._denyRemoteDispatch = ServicedComponentInfo.AreMethodsSecure(t);
            bool bFound = false;

            this._finalize = _finalizeCache.Get(t, out bFound) as MethodInfo;
            if (!bFound)
            {
                this._finalize = GetDeclaredFinalizer(t);
                _finalizeCache.Put(t, this._finalize);
            }
            this._calledDispose = false;
        }
 public override object GetRealObject(StreamingContext context)
 {
     if (!this.IsMarshaledObject)
     {
         return(this);
     }
     if (base.IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(this._rt))
     {
         object realObject = base.GetRealObject(context);
         ((ServicedComponent)realObject).DoSetCOMIUnknown(IntPtr.Zero);
         return(realObject);
     }
     if (this._rp == null)
     {
         this._rp = this._um.GetRealProxy();
     }
     return(this._rp.GetTransparentProxy());
 }
Ejemplo n.º 12
0
        internal RemoteServicedComponentProxy(Type serverType, IntPtr pUnk, bool fAttachServer)
            : base(serverType)
        {
            DBG.Info(DBG.SC, "RSCP: type = " + serverType);
            DBG.Assert(serverType != null, "server type is null");

            _fUseIntfDispatch = (ServicedComponentInfo.IsTypeEventSource(serverType) ||
                                 ServicedComponentInfo.AreMethodsSecure(serverType));
            DBG.Info(DBG.SC, "RSCP: using interface dispatch = " + _fUseIntfDispatch);
            if (pUnk != IntPtr.Zero)
            {
                _pUnk   = pUnk;
                _server = EnterpriseServicesHelper.WrapIUnknownWithComObject(pUnk);
                if (fAttachServer)
                {
                    AttachServer((MarshalByRefObject)_server);
                    _fAttachedServer = true;
                }
            }
        }
 public void ConfigureSubCollections(ICatalogCollection coll)
 {
     if ((this._installFlags & InstallationFlags.ConfigureComponentsOnly) == InstallationFlags.Default)
     {
         foreach (Type type in this._spec.ConfigurableTypes)
         {
             ICatalogObject     obj2       = (ICatalogObject)this.FindObject(coll, type);
             ICatalogCollection collection = (ICatalogCollection)coll.GetCollection(CollectionName.Interfaces, obj2.Key());
             this._cache["Component"]     = obj2;
             this._cache["ComponentType"] = type;
             InterfaceConfigCallback cb = new InterfaceConfigCallback(collection, type, this._cache, this._driver);
             this._driver.ConfigureCollection(collection, cb);
             if ((this._cache["SecurityOnMethods"] != null) || ServicedComponentInfo.AreMethodsSecure(type))
             {
                 this.FixupMethodSecurity(collection);
                 this._cache["SecurityOnMethods"] = null;
             }
         }
     }
 }
Ejemplo n.º 14
0
        private void CheckMethodAccess(IMessage request)
        {
            MethodBase     mi      = null;
            MethodBase     m       = null;
            IMethodMessage message = request as IMethodMessage;

            if (message == null)
            {
                throw new UnauthorizedAccessException();
            }
            mi = message.MethodBase;
            m  = ReflectionCache.ConvertToClassMI(base.GetType(), mi) as MethodBase;
            if (m == null)
            {
                throw new UnauthorizedAccessException();
            }
            if (ServicedComponentInfo.HasSpecialMethodAttributes(m))
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
            }
            if ((!mi.IsPublic || mi.IsStatic) && !IsMethodAllowedRemotely(mi))
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
            }
            Type declaringType = mi.DeclaringType;

            if (!declaringType.IsPublic && !declaringType.IsNestedPublic)
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
            }
            for (declaringType = mi.DeclaringType.DeclaringType; declaringType != null; declaringType = declaringType.DeclaringType)
            {
                if (!declaringType.IsPublic && !declaringType.IsNestedPublic)
                {
                    throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
                }
            }
        }
        public override IMessage Invoke(IMessage reqMsg)
        {
            this.AssertValid();
            IMessage message = null;

            if (reqMsg is IConstructionCallMessage)
            {
                if (((IConstructionCallMessage)reqMsg).ArgCount > 0)
                {
                    throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments"));
                }
                MarshalByRefObject transparentProxy = (MarshalByRefObject)this.GetTransparentProxy();
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, transparentProxy));
            }
            MethodBase methodBase = ((IMethodMessage)reqMsg).MethodBase;
            MemberInfo mi         = methodBase;

            if (methodBase == _getTypeMethod)
            {
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(this.ProxiedType, null, 0, mcm.LogicalCallContext, mcm));
            }
            if (methodBase == _getHashCodeMethod)
            {
                int hashCode = this.GetHashCode();
                IMethodCallMessage message3 = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(hashCode, null, 0, message3.LogicalCallContext, message3));
            }
            if (methodBase == _isInstanceOfTypeMethod)
            {
                IMethodCallMessage message4 = (IMethodCallMessage)reqMsg;
                Type inArg = (Type)message4.GetInArg(0);
                return(new ReturnMessage(inArg.IsInstanceOfType(this.ProxiedType), null, 0, message4.LogicalCallContext, message4));
            }
            MemberInfo m = ReflectionCache.ConvertToClassMI(this.ProxiedType, mi);

            try
            {
                int num2;
                if ((this._fUseIntfDispatch || (((num2 = ServicedComponentInfo.MICachedLookup(m)) & 4) != 0)) || ((num2 & 8) != 0))
                {
                    MemberInfo info3 = ReflectionCache.ConvertToInterfaceMI(mi);
                    if (info3 == null)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
                    }
                    MethodCallMessageWrapperEx ex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)info3);
                    message = RemotingServices.ExecuteMessage((MarshalByRefObject)this._server, ex);
                }
                else
                {
                    string          str2;
                    bool            flag     = (num2 & 2) != 0;
                    string          s        = ComponentServices.ConvertToString(reqMsg);
                    IRemoteDispatch dispatch = (IRemoteDispatch)this._server;
                    if (flag)
                    {
                        str2 = dispatch.RemoteDispatchAutoDone(s);
                    }
                    else
                    {
                        str2 = dispatch.RemoteDispatchNotAutoDone(s);
                    }
                    message = ComponentServices.ConvertToReturnMessage(str2, reqMsg);
                }
            }
            catch (COMException exception)
            {
                if ((exception.ErrorCode != -2147164158) && (exception.ErrorCode != -2147164157))
                {
                    throw;
                }
                if (!this.IsDisposeRequest(reqMsg))
                {
                    throw;
                }
                IMethodCallMessage message5 = reqMsg as IMethodCallMessage;
                message = new ReturnMessage(null, null, 0, message5.LogicalCallContext, message5);
            }
            if (this.IsDisposeRequest(reqMsg))
            {
                this.Dispose(true);
            }
            return(message);
        }
Ejemplo n.º 16
0
        private void CheckMethodAccess(IMessage request)
        {
            MethodBase reqmethod  = null; // Method from the request
            MethodBase implmethod = null; // The implementation we will dispatch on.

            IMethodMessage call = request as IMethodMessage;

            if (call == null)
            {
                throw new UnauthorizedAccessException();
            }

            reqmethod = call.MethodBase;

            // Make sure we investigate the implementation, not the interface
            // for attributes (such as SecureMethod)
            implmethod = ReflectionCache.ConvertToClassMI(GetType(), reqmethod) as MethodBase;
            if (implmethod == null)
            {
                throw new UnauthorizedAccessException();
            }

            // Check implementation for dispatch attributes
            if (ServicedComponentInfo.HasSpecialMethodAttributes(implmethod))
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
            }

            // Verify the method is not private, internal, or static.  Use
            // the method that's being requested here, in case it's an
            // explicit interface implementation (they're all private).
            if (!reqmethod.IsPublic || reqmethod.IsStatic)
            {
                // If this is a special method (such as the FieldGetter or Setter, thne
                // go ahead and let it through.
                if (!IsMethodAllowedRemotely(reqmethod))
                {
                    throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
                }
            }

            // Make sure that the type we're invoking on is public!  This
            // covers invokes on public methods of internal interfaces.
            Type reqtype = reqmethod.DeclaringType;

            if (!reqtype.IsPublic && !reqtype.IsNestedPublic)
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
            }

            // Deal with nested types!  Get the declaring type of the method,
            // and then get the outer type that declared that.  It'll be
            // non-null if this is a nested type.
            reqtype = reqmethod.DeclaringType.DeclaringType;
            while (reqtype != null)
            {
                if (!reqtype.IsPublic && !reqtype.IsNestedPublic)
                {
                    throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
                }

                reqtype = reqtype.DeclaringType;
            }
        }
        protected ServicedComponentMarshaler(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            byte[] buffer = null;
            Type   type   = null;
            bool   flag   = false;

            ComponentServices.InitializeRemotingChannels();
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Name.Equals("servertype"))
                {
                    type = (Type)enumerator.Value;
                }
                else
                {
                    if (enumerator.Name.Equals("dcomInfo"))
                    {
                        buffer = (byte[])enumerator.Value;
                        continue;
                    }
                    if (enumerator.Name.Equals("fIsMarshalled"))
                    {
                        int    num  = 0;
                        object obj2 = enumerator.Value;
                        if (obj2.GetType() == typeof(string))
                        {
                            num = ((IConvertible)obj2).ToInt32(null);
                        }
                        else
                        {
                            num = (int)obj2;
                        }
                        if (num == 0)
                        {
                            flag = true;
                        }
                    }
                }
            }
            if (!flag)
            {
                this._marshalled = true;
            }
            this._um = new SCUnMarshaler(type, buffer);
            this._rt = type;
            if (base.IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(type))
            {
                this._rp = RemotingServices.GetRealProxy(base.GetRealObject(context));
            }
            else
            {
                if (ServicedComponentInfo.IsTypeEventSource(type))
                {
                    this.TypeInfo = new SCMTypeName(type);
                }
                object realObject = base.GetRealObject(context);
                this._rp = RemotingServices.GetRealProxy(realObject);
            }
            this._um.Dispose();
        }
Ejemplo n.º 18
0
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            // Platform.Assert(Platform.W2K, "ServicedComponent");

            RealProxy          rp = null;
            MarshalByRefObject mo = null;

            DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for managed request");


            ServicedComponentProxy.CleanupQueues(true);

            // First check if the type is configured to be activated remotely or is a well
            // known remote type.
            if ((null != RemotingConfiguration.IsWellKnownClientType(serverType)) ||
                (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType)))
            {
                // It is configured for remote activation. Ask remoting services to do the
                // job of creating a remoting proxy and returning it.
                mo = base.CreateInstance(serverType);
                rp = RemotingServices.GetRealProxy(mo);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri         = "";
                bool   bEventClass = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk        = Thunk.Proxy.CoCreateObject(serverType, !bEventClass, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try {
                        // TODO:  Get rid of this useless foreknowledge requirement
                        // Is there a way we can tell by QI'ing this guy if he's
                        // an event class (or something else we need to artificially
                        // wrap?
                        if (bEventClass)
                        {
                            // events and queued components use RemoteServicedComponentProxy
                            // set up a TP & Remote ServicedComponentProxy pair
                            rp = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            mo = (MarshalByRefObject)rp.GetTransparentProxy();
                        }
                        else
                        {
                            if (bIsAnotherProcess)              // a-ha, we know it should be a RSCP now !!!!
                            {
                                FastRSCPObjRef oref = new FastRSCPObjRef(pUnk, serverType, uri);
                                mo = (MarshalByRefObject)RemotingServices.Unmarshal(oref);

                                DBG.Assert(mo != null, "RemotingServices.Unmarshal returned null!");
                                DBG.Assert(RemotingServices.GetRealProxy(mo) is RemoteServicedComponentProxy, "RemotingServices.Unmarshal did not return an RSCP!");
                            }
                            else        // bummer, this will give us back a SCP
                            {
                                mo = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);

                                DBG.Info(DBG.SC, "ret = " + mo.GetType());
                                DBG.Info(DBG.SC, "st = " + serverType);
                                DBG.Info(DBG.SC, "rt == sc = " + (mo.GetType() == serverType));
                                DBG.Info(DBG.SC, "instanceof = " + serverType.IsInstanceOfType(mo));

                                if (!(serverType.IsInstanceOfType(mo)))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, mo.GetType()));
                                }

                                rp = RemotingServices.GetRealProxy(mo);
                                if (!(rp is ServicedComponentProxy) && !(rp is RemoteServicedComponentProxy))
                                {
                                    // in cross-appdomain scenario, we get back a RemotingProxy, SetCOMIUnknown has not been made on our server!
                                    ServicedComponent sc = (ServicedComponent)mo;
                                    sc.DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }

            if (rp is ServicedComponentProxy)
            {
                // Here, we tell the server proxy that it needs to filter out
                // constructor calls:  We only need to do this if
                // the proxy lives in the same context as the caller,
                // otherwise we'll get an Invoke call and can do the
                // filtering automagically:
                ServicedComponentProxy scp = (ServicedComponentProxy)rp;
                if (scp.HomeToken == Thunk.Proxy.GetCurrentContextToken())
                {
                    scp.FilterConstructors();
                }
            }

            DBG.Assert(mo is ServicedComponent, " CoCI returned an invalid object type");
            DBG.Info(DBG.SC, "SCPA.CreateInstance done.");
            return(mo);
        }
Ejemplo n.º 19
0
        // Implement Invoke
        public override IMessage Invoke(IMessage reqMsg)
        {
            AssertValid();
            IMessage retMsg = null;

            // CHECK FOR CTOR
            if (reqMsg is IConstructionCallMessage)
            {
                DBG.Info(DBG.SC, "RSCP: Short circuiting constructor call.");

                if (((IConstructionCallMessage)reqMsg).ArgCount > 0)
                {
                    throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments"));
                }

                // WE don't need dispatch the constructor message, the default .ctor is called
                // by CoCI
                // Create the return message
                MarshalByRefObject retObj = (MarshalByRefObject)GetTransparentProxy();
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, retObj));
            }

            // NON CTOR MESSAGE
            MethodBase mb = ((IMethodMessage)reqMsg).MethodBase;
            MemberInfo m  = (MemberInfo)mb;

            DBG.Assert(m != null, "member info should not be null");

            if (mb == _getTypeMethod)
            {
                DBG.Info(DBG.SC, "RSCP: Hijacking call to GetType");
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(ProxiedType, null, 0, mcm.LogicalCallContext, mcm));
            }

            if (mb == _getHashCodeMethod)
            {
                int hashCode = this.GetHashCode();
                DBG.Info(DBG.SC, "RSCP: Hijacking call to GetHashCode, returning " + hashCode);
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(hashCode, null, 0, mcm.LogicalCallContext, mcm));
            }

            DBG.Info(DBG.SC, "RSCP: Delivering call to " + mb.Name);

            // convert to class member info
            MemberInfo clsMemInfo = ReflectionCache.ConvertToClassMI(ProxiedType, m);

            DBG.Assert(!clsMemInfo.ReflectedType.IsInterface,
                       "Failed to convert interface member info to class member info");

            // dispatch the call
#if _DEBUG
            if (clsMemInfo != m)
            {
                DBG.Info(DBG.SC, "RSCP: converted interface to class call: " + clsMemInfo.Name);
            }
#endif

            try
            {
                int iMethodInfo;
                // check for rolebased security
                if (_fUseIntfDispatch ||
                    (((iMethodInfo = ServicedComponentInfo.MICachedLookup(clsMemInfo)) & ServicedComponentInfo.MI_HASSPECIALATTRIBUTES) != 0) ||
                    ((iMethodInfo & ServicedComponentInfo.MI_EXECUTEMESSAGEVALID) != 0)
                    )
                {
                    // role based security implies we dispatch through an interface
                    MemberInfo intfMemInfo = ReflectionCache.ConvertToInterfaceMI(m);
                    if (intfMemInfo == null)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
                    }
                    //retMsg = EnterpriseServicesHelper.DispatchRemoteCall(reqMsg, intfMemInfo, _server);
                    MethodCallMessageWrapperEx msgex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)intfMemInfo);
                    retMsg = RemotingServices.ExecuteMessage((MarshalByRefObject)_server, (IMethodCallMessage)msgex);
                }
                else
                {
                    // check for AutoDone
                    bool fAutoDone = (iMethodInfo & ServicedComponentInfo.MI_AUTODONE) != 0;

                    String s = ComponentServices.ConvertToString(reqMsg);

                    IRemoteDispatch iremDisp = (IRemoteDispatch)_server;

                    String sret;
                    if (fAutoDone)
                    {
                        sret = iremDisp.RemoteDispatchAutoDone(s);
                    }
                    else
                    {
                        sret = iremDisp.RemoteDispatchNotAutoDone(s);
                    }
                    retMsg = ComponentServices.ConvertToReturnMessage(sret, reqMsg);
                }
            }
            catch (COMException e)
            {
                if (!(e.ErrorCode == Util.CONTEXT_E_ABORTED || e.ErrorCode == Util.CONTEXT_E_ABORTING))
                {
                    throw;
                }
                if (IsDisposeRequest(reqMsg))
                {
                    IMethodCallMessage mcm = reqMsg as IMethodCallMessage;
                    retMsg = new ReturnMessage(null, null, 0, mcm.LogicalCallContext, mcm);
                }
                else
                {
                    throw;
                }
            }

            // if disposing, we need to release this side of the world.
            if (IsDisposeRequest(reqMsg))
            {
                Dispose(true);
            }

            return(retMsg);
        }
Ejemplo n.º 20
0
        MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
        {
            // Platform.Assert(Platform.W2K, "ServicedComponent");

            DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for unmanaged request");

            DBG.Assert(ServicedComponentInfo.IsTypeServicedComponent(serverType),
                       "unconfigured type passed to ICustomFactory.CreateInstance");

            RealProxy rp = null;

            // The reason we don't want to cleanup GIT cookies from inside here (passing false) is
            // because we will already be in a new context, and RevokeInterfaceFromGlobal will be very expensive
            // (like 5x), as it needs to switch context.  A more appropriate place to do this is in the managed CreateInstance
            // before we even call CoCreateInstance

            ServicedComponentProxy.CleanupQueues(false);



            int iSCInfo = ServicedComponentInfo.SCICachedLookup(serverType);

            bool fIsTypeJITActivated = (iSCInfo & ServicedComponentInfo.SCI_JIT) != 0;
            bool fIsTypePooled       = (iSCInfo & ServicedComponentInfo.SCI_OBJECTPOOLED) != 0;
            bool fAreMethodsSecure   = (iSCInfo & ServicedComponentInfo.SCI_METHODSSECURE) != 0;

            if (fIsTypeJITActivated)
            {
                // NOTE: If the component is JIT activated, we may be trying
                // to connect a new backing object to an existing TP held
                // by a managed client.  So we look in our handy table
                // to see if there is a component registered for this context.
                // Because it is JIT activated, COM+ ensures that it will
                // have been the distinguished object in this context.

                IntPtr token = Thunk.Proxy.GetCurrentContextToken();

                DBG.Info(DBG.SC, "SCPA.CreateInstance looking for JIT object in IdentityTable. token=" + token);

                Object otp = IdentityTable.FindObject(token);

                if (otp != null)
                {
                    DBG.Info(DBG.SC, "SCPA.CreateInstance found JIT object in IdentityTable.");
                    rp = RemotingServices.GetRealProxy(otp);

                    DBG.Assert(rp is ServicedComponentProxy, "Cached something that wasn't a serviced component proxy in the ID table!");
                    DBG.Assert(rp != null, " GetTransparentProxy.. real proxy is null");
                    DBG.Assert(serverType == rp.GetProxiedType(), "Invalid type found in Deactivated list");
                }
            }

            if (rp == null)
            {
                DBG.Info(DBG.SC, "SCPA.CreateInstance creating new SCP fJIT=" + fIsTypeJITActivated + " fPooled=" + fIsTypePooled + " fMethodsSecure=" + fAreMethodsSecure);
                rp = new ServicedComponentProxy(serverType, fIsTypeJITActivated, fIsTypePooled, fAreMethodsSecure, true);
            }
            else if (rp is ServicedComponentProxy)
            {
                ServicedComponentProxy scp = (ServicedComponentProxy)rp;
                scp.ConstructServer();
            }

            MarshalByRefObject mo = (MarshalByRefObject)rp.GetTransparentProxy();

            DBG.Assert(mo != null, " GetTransparentProxy returned NULL");

            DBG.Info(DBG.SC, "SCPA.ICustomFactory.CreateInstance done.");

            return(mo);
        }
 public override RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)
 {
     if (objRef == null)
     {
         return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
     }
     if (!(objRef is FastRSCPObjRef) && (!(objRef is ServicedComponentMarshaler) || (objRef.IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(serverType))))
     {
         return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
     }
     return(RemotingServices.GetRealProxy(objRef.GetRealObject(new StreamingContext(StreamingContextStates.Remoting))));
 }
Ejemplo n.º 22
0
        protected ServicedComponentMarshaler(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            byte[] buffer              = null;
            Type   servertype          = null;
            bool   bFoundFIsMarshalled = false;

            DBG.Info(DBG.SC, "SCM: construct");
            ComponentServices.InitializeRemotingChannels();
            SerializationInfoEnumerator e = info.GetEnumerator();

            while (e.MoveNext())
            {
                DBG.Info(DBG.SC, "SCM: ctor: name = " + e.Name + " value = " + e.Value);
                if (e.Name.Equals("servertype"))
                {
                    servertype = (Type)e.Value;
                }
                else if (e.Name.Equals("dcomInfo"))
                {
                    buffer = (byte[])e.Value;
                }
                else if (e.Name.Equals("fIsMarshalled"))
                {
                    int    value = 0;
                    Object o     = e.Value;
                    if (o.GetType() == typeof(String))
                    {
                        value = ((IConvertible)o).ToInt32(null);
                    }
                    else
                    {
                        value = (int)o;
                    }

                    if (value == 0)
                    {
                        bFoundFIsMarshalled = true;
                    }
                }
            }

            if (!bFoundFIsMarshalled)
            {
                DBG.Info(DBG.SC, "SCM: ctor: didn't find fIsMarshalled.");
                _marshalled = true;
            }

            _um = new SCUnMarshaler(servertype, buffer);

            _rt = servertype;


            if (IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(servertype))
            {
                _rp = RemotingServices.GetRealProxy(base.GetRealObject(context));
            }
            else
            {
                DBG.Assert(servertype != null, "SCM: server type is null during marshal.");
                if (ServicedComponentInfo.IsTypeEventSource(servertype))
                {
                    TypeInfo = (IRemotingTypeInfo) new SCMTypeName(servertype);
                }
                Object otp = base.GetRealObject(context);
                _rp = RemotingServices.GetRealProxy(otp);
            }
            // cleanup the buffer, in case we found an existing rp
            _um.Dispose();
        }
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            RealProxy          realProxy        = null;
            MarshalByRefObject transparentProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            if ((RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (RemotingConfiguration.IsRemotelyActivatedClientType(serverType) != null))
            {
                transparentProxy = base.CreateInstance(serverType);
                realProxy        = RemotingServices.GetRealProxy(transparentProxy);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri   = "";
                bool   flag2 = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk  = Proxy.CoCreateObject(serverType, !flag2, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try
                    {
                        if (flag2)
                        {
                            realProxy        = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            transparentProxy = (MarshalByRefObject)realProxy.GetTransparentProxy();
                        }
                        else
                        {
                            bool flag3 = (RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType));
                            if (bIsAnotherProcess && !flag3)
                            {
                                FastRSCPObjRef objectRef = new FastRSCPObjRef(pUnk, serverType, uri);
                                transparentProxy = (MarshalByRefObject)RemotingServices.Unmarshal(objectRef);
                            }
                            else
                            {
                                transparentProxy = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);
                                if (!serverType.IsInstanceOfType(transparentProxy))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, transparentProxy.GetType()));
                                }
                                realProxy = RemotingServices.GetRealProxy(transparentProxy);
                                if ((!bIsAnotherProcess && !(realProxy is ServicedComponentProxy)) && !(realProxy is RemoteServicedComponentProxy))
                                {
                                    ((ServicedComponent)transparentProxy).DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }
            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                if (proxy2.HomeToken == Proxy.GetCurrentContextToken())
                {
                    proxy2.FilterConstructors();
                }
            }
            return(transparentProxy);
        }