private RealProxy UnmarshalRemoteReference() { DBG.Info(DBG.SC, "SCM: UnmarshalRemoteReference()"); IntPtr pUnk = IntPtr.Zero; RealProxy rp = null; try { _fUnMarshaled = true; if (buffer != null) { pUnk = Thunk.Proxy.UnmarshalObject(buffer); } // set up a remote serviced component proxy rp = new RemoteServicedComponentProxy(servertype, pUnk, false); } finally { // now get rid of the pUnk if (pUnk != IntPtr.Zero) { Marshal.Release(pUnk); } // if we have the dcom buffer get rid of it buffer = null; } return(rp); }
public static void AddObject(IntPtr key, Object val) { _rwlock.AcquireWriterLock(Timeout.Infinite); try { WeakReference wf = _table[key] as WeakReference; if (wf == null) { DBG.Info(DBG.SC, "LookupTable.AddObject(): Adding new entry for " + key); // We didn't find an entry, we need to add a new one: wf = new WeakReference(val, false); _table.Add(key, wf); } else { DBG.Info(DBG.SC, "LookupTable.AddObject(): Reusing entry for " + key); // We found an entry, it better be the same or null: DBG.Assert(wf.Target == null || wf.Target == val, "different live TP found in table"); if (wf.Target == null) { wf.Target = val; } } } finally { _rwlock.ReleaseWriterLock(); } }
private void EnsureRole(Hashtable cache) { ICatalogCollection appColl = null; ICatalogObject app = null; ICatalogCollection roleColl = null; // Check to see if we've cached the existence of the role: Hashtable appRoleCache = (Hashtable)(cache[RoleCacheString]); if (appRoleCache == null) { appRoleCache = new Hashtable(); cache[RoleCacheString] = appRoleCache; } if (appRoleCache[_role] != null) { return; } appColl = (ICatalogCollection)(cache["ApplicationCollection"]); app = (ICatalogObject)(cache["Application"]); DBG.Info(DBG.Registration, "Getting roles for app: " + app.Key()); roleColl = (ICatalogCollection)(appColl.GetCollection(CollectionName.Roles, app.Key())); roleColl.Populate(); ICatalogObject newRole = Search(roleColl, "Name", _role); if (newRole == null) { // We didn't find it, we need to try to add a new role: newRole = (ICatalogObject)(roleColl.Add()); newRole.SetValue("Name", _role); if (_description != null) { newRole.SetValue("Description", _description); } roleColl.SaveChanges(); if (_setEveryoneAccess) { DBG.Info(DBG.Registration, "\tAdding everyone to the role!"); ICatalogCollection userColl = (ICatalogCollection)(roleColl.GetCollection(CollectionName.UsersInRole, newRole.Key())); userColl.Populate(); // Add the Everyone user to this guy, so that activation will // subsequently succeed: ICatalogObject newUser = (ICatalogObject)(userColl.Add()); newUser.SetValue("User", EveryoneAccount); userColl.SaveChanges(); } } // Mark this guy in the cache. appRoleCache[_role] = (Object)true; }
// TODO: @cleanup: Move to ServicedComponentProxy private static void ReconnectForPooling(ServicedComponentProxy scp) { Type serverType = scp.GetProxiedType(); bool fIsJitActivated = scp.IsJitActivated; bool fIsTypePooled = scp.IsObjectPooled; bool fAreMethodsSecure = scp.AreMethodsSecure; ProxyTearoff tearoff = null; DBG.Assert(fIsTypePooled == true, "CS.ReconnectForPooling called on a non-pooled proxy!"); DBG.Info(DBG.SC, "CS.ReconnectForPooling (type is pooled) " + serverType); ServicedComponent server = scp.DisconnectForPooling(ref tearoff); // now setup a new SCP that we can add to the pool // with the current server object and the CCW ServicedComponentProxy newscp = new ServicedComponentProxy(serverType, fIsJitActivated, fIsTypePooled, fAreMethodsSecure, false); DBG.Info(DBG.SC, "CS.ReconnectForPooling (calling newscp.ConnectForPooling)"); newscp.ConnectForPooling(scp, server, tearoff, false); // switch the CCW from oldtp to new tp DBG.Info(DBG.SC, "CS.ReconnectForPooling (SwitchingWrappers)"); EnterpriseServicesHelper.SwitchWrappers(scp, newscp); // Strengthen the CCW: The only reference now held is // the reference from the pool. if (tearoff != null) { Marshal.ChangeWrapperHandleStrength(tearoff, false); } Marshal.ChangeWrapperHandleStrength(newscp.GetTransparentProxy(), false); }
private Type FindInterfaceByName(ICatalogObject ifcObj, Type t, Type[] interfaces) { String name = (String)(ifcObj.GetValue("Name")); foreach (Type ifc in interfaces) { if (ifc.IsInterface) { DBG.Info(DBG.Registration, "Matching " + ifc.Name + " against " + name + " on " + ifc); if (ifc.Name == name) { return(ifc); } } else { DBG.Info(DBG.Registration, "Matching _" + ifc.Name + " against " + name + " on " + ifc); if ("_" + ifc.Name == name) { return(ifc); } } } return(null); }
// TODO: Move to ServicedComponent static method public static void DeactivateObject(Object otp, bool disposing) { RealProxy rp = RemotingServices.GetRealProxy(otp); ServicedComponentProxy scp = rp as ServicedComponentProxy; DBG.Assert(scp != null, "CS.DeactivateObject called on a non-ServicedComponentProxy"); if (!scp.IsProxyDeactivated) { DBG.Assert(scp.HomeToken == Thunk.Proxy.GetCurrentContextToken(), "Deactivate called from wrong context"); if (scp.IsObjectPooled) { DBG.Info(DBG.SC, "CS.DeactivateObject calling ReconnectForPooling"); ReconnectForPooling(scp); } // this would wack the real server also so do this last DBG.Info(DBG.SC, "CS.DeactivateObject calling scp.DeactivateProxy"); scp.DeactivateProxy(disposing); } DBG.Assert(scp.IsProxyDeactivated, "scp not deactive"); }
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)); } }
public InterfaceConfigCallback(ICatalogCollection coll, Type t, Hashtable cache, RegistrationDriver driver) { _type = t; _coll = coll; _cache = cache; _driver = driver; // TODO: Populate w/ QueryByKey // TODO: Build cache for FindObject() _ifcs = GetInteropInterfaces(_type); // Check to see if one of the interfaces is IProcessInitializer foreach (Type ifc in _ifcs) { if (Marshal.GenerateGuidForType(ifc) == IID_IProcessInitializer) { DBG.Info(DBG.Registration, "Setting component " + cache["ComponentType"] + " up as process initializer"); try { ICatalogObject comp = cache["Component"] as ICatalogObject; ICatalogCollection compColl = cache["ComponentCollection"] as ICatalogCollection; comp.SetValue("InitializesServerApplication", 1); compColl.SaveChanges(); } catch (Exception e) { throw new RegistrationException(Resource.FormatString("Reg_FailPIT", _type), e); } } } RegistrationDriver.Populate(_coll); }
/// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.DisposeObject"]/*' /> public static void DisposeObject(ServicedComponent sc) { RealProxy rp = RemotingServices.GetRealProxy(sc); if (rp is ServicedComponentProxy) { DBG.Info(DBG.SC, "DisposeObject(): Disposing ServicedComponentProxy"); ServicedComponentProxy scp = (ServicedComponentProxy)rp; RemotingServices.Disconnect(sc); // dispose the actual proxy scp.Dispose(true); } else if (rp is RemoteServicedComponentProxy) { DBG.Info(DBG.SC, "DisposeObject(): Disposing RemoteServicedComponentProxy"); RemoteServicedComponentProxy rscp = (RemoteServicedComponentProxy)rp; // dispose the remote instance first sc.Dispose(); // then dispose the local proxy rscp.Dispose(true); } else // We're off in magic land, with no proxy of our own. { sc.Dispose(); } }
public void ConfigureDefaults(Object a, Object key) { DBG.Assert(!(Platform.IsLessThan(Platform.W2K)), "Configuring interfaces on non-w2k platform!"); if (!Platform.IsLessThan(Platform.W2K)) { bool setQdefault = true; ICatalogObject obj = (ICatalogObject)key; // If this type (a) has been touched by the parent component, // we don't want to set this value... if (_cache[_type] != null) { Object co = _cache[_type]; if (co is Hashtable && ((Hashtable)co)[a] != null) { DBG.Info(DBG.Registration, "*** not setting queue defaults!"); setQdefault = false; } } if (setQdefault) { obj.SetValue("QueuingEnabled", false); } } }
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; } } } }
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()); } } }
String IRemoteDispatch.RemoteDispatchNotAutoDone(String s) { bool failed = false; DBG.Info(DBG.SC, "SC: RemoteDispatch - NotAutoDone"); return(RemoteDispatchHelper(s, out failed)); }
void IObjPool.PutEndTx(Object p) { DBG.Assert(p != null, "ComExposedPool: EndTx delivered a null object!"); // Release, cause this guy's not in the pool any longer. DBG.Info(DBG.Pool, "Returing object on tx end!"); _cb(p); ReleaseToken(); }
internal RegistrationThreadWrapper(RegistrationHelper helper, RegistrationConfig regConfig) { DBG.Info(DBG.Registration, "STA Thread! jumping onto MTA for registration"); _regConfig = regConfig; _helper = helper; _exception = null; }
internal void DoSetCOMIUnknown(IntPtr pUnk) { // this call needs to be intercepted by the proxy, before we come into the context // Unless the client and component live in the same context (but in different AppDomains) // then the proxy will not be able to intercept, so we need to do this here. DBG.Info(DBG.SC, "ServicedComponent.DoSetCOMIUnknown, setting it in the proxy myself. Punk=" + pUnk); RealProxy rp = RemotingServices.GetRealProxy(this); rp.SetCOMIUnknown(pUnk); }
// copied from ServicedComponentMarshaler above directly // IF YOU MAK ANY CHANGES TO THIS, KEEP THE OTHER COPY IN SYNC public override void GetObjectData(SerializationInfo info, StreamingContext context) { DBG.Info(DBG.SC, "FSCM: GetObjectData"); ComponentServices.InitializeRemotingChannels(); if (info == null) { throw new ArgumentNullException("info"); } // Check to see if this is a remoting channel, if so, then we // should use the standard objref marshal (cause we're going over SOAP // or another remoting channel). object oClientIsClr = CallContext.GetData("__ClientIsClr"); DBG.Info(DBG.SC, "FSCM: GetObjectData: oClientIsClr = " + oClientIsClr); bool bUseStandardObjRef = (oClientIsClr == null)?false:(bool)oClientIsClr; if (bUseStandardObjRef) { RemoteServicedComponentProxy rscp = _rp as RemoteServicedComponentProxy; if (rscp != null) { DBG.Info(DBG.SC, "FSCM: GetObjectData: intermediary objref"); ObjRef std = RemotingServices.Marshal((MarshalByRefObject)(rscp.RemotingIntermediary.GetTransparentProxy()), null, null); std.GetObjectData(info, context); } else { DBG.Info(DBG.SC, "FSCM: GetObjectData: Using standard objref"); base.GetObjectData(info, context); } } else { DBG.Info(DBG.SC, "FSCM: GetObjectData: Using custom objref"); base.GetObjectData(info, context); //*** base.GetObjectData sets the type to be itself // now wack the type to be us info.SetType(typeof(ServicedComponentMarshaler)); DBG.Assert(_rp != null, "_rp is null"); info.AddValue("servertype", _rp.GetProxiedType()); byte[] dcomBuffer = ComponentServices.GetDCOMBuffer((MarshalByRefObject)_rp.GetTransparentProxy()); DBG.Assert(dcomBuffer != null, "dcomBuffer is null"); if (dcomBuffer != null) { info.AddValue("dcomInfo", dcomBuffer); } } }
internal static void Assert(Version platform, String function) { Initialize(); if (_current.Major < platform.Major || ((_current.Major == platform.Major) && (_current.Minor < platform.Minor))) { DBG.Info(DBG.Platform, "Platform: Failed assertion: '" + function + "'"); DBG.Info(DBG.Platform, "Platform: Required '" + platform + "' when current is '" + _current + "'"); Assert(false, function); } }
public override void SetCOMIUnknown(IntPtr pUnk) { if (_server == null) { DBG.Info(DBG.SC, "RSCP: SetCOMIUnknown: storing pUnk."); _pUnk = pUnk; _server = EnterpriseServicesHelper.WrapIUnknownWithComObject(pUnk); // add this to our table of weak references //IdentityTable.AddObject(_pUnk, GetTransparentProxy()); } }
private static void Initialize() { if (!_initialized) { lock (typeof(Platform)) { if (!_initialized) { IntPtr hToken = IntPtr.Zero; _mts1 = new Version(1, 1); _mts = new Version(2, 0); _w2k = new Version(3, 0); _whistler = new Version(4, 0); try { try { // We need to do this as the process, rather than the // impersonation token hToken = Thunk.Security.SuspendImpersonation(); Admin.IMtsCatalog c = (Admin.IMtsCatalog)(new Admin.xMtsCatalog()); _current = new Version(c.MajorVersion(), c.MinorVersion()); DBG.Info(DBG.Platform, "Platform: Current version = " + _current); } catch (COMException e) { DBG.Info(DBG.Platform, "Current platform check failed: " + e); // If e is a ClassNotRegistered exception, we're not // installed at all, so we should note that: _current = new Version(0, 0); } finally { Thunk.Security.ResumeImpersonation(hToken); } } catch (Exception) { // This is a security precaution. If there is // unpriveleged code above us, while we have // suspended the impersonation, if an exception // is thrown, a user exception handler could run. // It would run in the unimpersonated context. throw; } _initialized = true; } } } }
public override Object GetRealObject(StreamingContext context) { DBG.Info(DBG.SC, "FSCM: GetRealObject"); DBG.Assert(_pUnk != IntPtr.Zero, "pUnk is zero!"); DBG.Assert(_serverType != null, "_serverType is null!"); RealProxy rp = new RemoteServicedComponentProxy(_serverType, _pUnk, false); _rp = rp; return((MarshalByRefObject)rp.GetTransparentProxy()); }
bool IConfigurationAttribute.IsValidTarget(String s) { if (s == "Component" || s == "Method" || s == "Application" || s == "Interface") { DBG.Info(DBG.Registration, "Setting security for target: " + s); return(true); } DBG.Info(DBG.Registration, "Not setting security for target: " + s); return(false); }
// itnerop methods public override IntPtr GetCOMIUnknown(bool fIsMarshalled) { DBG.Info(DBG.SC, "RSCP: GetCOMIUnknown"); // sub -class should override if (_server != null) { return(Marshal.GetIUnknownForObject(_server)); } else { return(IntPtr.Zero); } }
bool IConfigurationAttribute.Apply(Hashtable cache) { // If this is a method, we need to make sure that we've enabled // the marshaler role: String target = (String)(cache["CurrentTarget"]); if (target == "Method") { cache["SecurityOnMethods"] = (Object)true; DBG.Info(DBG.Registration, "Add SecurityOnMethods for " + cache["ComponentType"]); } return(false); }
// helper to dispatch an autodone method on a remote object String IRemoteDispatch.RemoteDispatchAutoDone(String s) { bool failed = false; DBG.Info(DBG.SC, "SC: RemoteDispatch - AutoDone"); String r = RemoteDispatchHelper(s, out failed); if (failed) { ContextUtil.SetAbort(); } return(r); }
// Implement Invoke public override IMessage Invoke(IMessage reqmsg) { DBG.Info(DBG.SC, "Intermediary: Invoke: forwarding call..."); IMessage retmsg = HandleSpecialMessages(reqmsg); if (retmsg != null) { return(retmsg); } return(_pxy.Invoke(reqmsg)); }
public ISerializationSurrogate GetSurrogate(Type type, StreamingContext ctx, out ISurrogateSelector selector) { selector = null; DBG.Info(DBG.SC, "CSS: GetSurrogate(" + type + ")"); if (type.IsCOMObject) { selector = this; return(this); } return(_deleg.GetSurrogate(type, ctx, out selector)); }
internal void UninstallThread() { try { Thread.CurrentThread.ApartmentState = ApartmentState.MTA; DBG.Info(DBG.Registration, "UninstallThread(): recursing install assembly..."); _helper.UninstallAssemblyFromConfig(ref _regConfig); DBG.Info(DBG.Registration, "UninstallThread(): Finished with install assembly."); } catch (Exception e) { DBG.Info(DBG.Registration, "UninstallThread(): Caught failure in InstallAssembly."); _exception = e; } }
internal byte[] MarshalToBuffer(Object o, out long numBytes) { DBG.Info(DBG.SC, "MarshalToBuffer(): " + o.GetType()); SetStream(null); _formatter.SurrogateSelector = _selector; _formatter.AssemblyFormat = FormatterAssemblyStyle.Full; _formatter.Serialize(_stream, o, null); numBytes = _stream.Position; if ((numBytes % 2) != 0) // we want to make sure we're encoding even-sized buffers { _stream.WriteByte(0); numBytes++; } return(_stream.GetBuffer()); }
// We should never need to have a deserialization constructor, since // we never deserialize one of these guys. public override void GetObjectData(SerializationInfo info, StreamingContext ctx) { object oClientIsClr = CallContext.GetData("__ClientIsClr"); DBG.Info(DBG.SC, "SCM: GetObjectData: oClientIsClr = " + oClientIsClr); bool bUseStandardObjRef = (oClientIsClr == null)?false:(bool)oClientIsClr; if (bUseStandardObjRef) { base.GetObjectData(info, ctx); } else { _custom.GetObjectData(info, ctx); } }