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 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")); } } }
// 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); }
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; } }
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); }