} // CoreBeginProcessing /// <summary> /// Create a throttle operation using NewProcessConnectionInfo /// ie., Out-Of-Process runspace. /// </summary> protected override void CreateHelpersForSpecifiedComputerNames() { // If we're in ConstrainedLanguage mode and the system is in lockdown mode, // ensure that they haven't specified a ScriptBlock or InitScript - as // we can't protect that boundary if ((Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce) && ((ScriptBlock != null) || (InitializationScript != null))) { ThrowTerminatingError( new ErrorRecord( new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode), "CannotStartJobInconsistentLanguageMode", ErrorCategory.PermissionDenied, Context.LanguageMode)); } NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential); connectionInfo.RunAs32 = _shouldRunAs32; connectionInfo.InitializationScript = _initScript; connectionInfo.AuthenticationMechanism = this.Authentication; connectionInfo.PSVersion = this.PSVersion; RemoteRunspace remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, this.Host, Utils.GetTypeTableFromExecutionContextTLS()); remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived; Pipeline pipeline = CreatePipeline(remoteRunspace); IThrottleOperation operation = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline); Operations.Add(operation); }
public static RemoteRunspace FromPSObjectForRemoting(PSObject obj) { int id = RemotingDecoder.GetPropertyValue <int> (obj, "Id"); string name = RemotingDecoder.GetPropertyValue <string> (obj, "Name"); PSPrimitiveDictionary appArgs = RemotingDecoder.GetPropertyValue <PSPrimitiveDictionary> (obj, "ApplicationArguments"); string connectionInfoType = RemotingDecoder.GetPropertyValue <string> (obj, "ConnectionInfoType"); PSObject connectionObj = RemotingDecoder.GetPropertyValue <PSObject> (obj, "ConnectionInfo"); RunspaceConnectionInfo connectionInfo = null; if (connectionInfoType == "WSManConnectionInfo") { connectionInfo = WSManConnectionInfo.FromPSObjectForRemoting(connectionObj); } else { var securePassord = new System.Security.SecureString(); securePassord.AppendChar('z'); connectionInfo = new NewProcessConnectionInfo(new PSCredential("Anonymous", securePassord)); } var runspace = new RemoteRunspace(new TypeTable(), connectionInfo, null, appArgs, name, id); runspace._version = RemotingDecoder.GetPropertyValue <Version>(obj, "Version"); runspace.ApartmentState = RemotingDecoder.GetPropertyValue <ApartmentState>(obj, "ApartmentState"); runspace.InstanceId = RemotingDecoder.GetPropertyValue <Guid>(obj, "InstanceId"); runspace._shouldCloseOnPop = RemotingDecoder.GetPropertyValue <bool>(obj, "ShouldCloseOnPop"); runspace._runspaceStateInfo = new System.Management.Automation.Runspaces.RunspaceStateInfo(RemotingDecoder.GetPropertyValue <RunspaceState>(obj, "RunspaceStateInfo")); runspace._runspaceAvailability = RemotingDecoder.GetPropertyValue <RunspaceAvailability>(obj, "RunspaceAvailability"); runspace.ThreadOptions = RemotingDecoder.GetPropertyValue <PSThreadOptions>(obj, "ThreadOptions"); runspace.EngineActivityId = RemotingDecoder.GetPropertyValue <Guid>(obj, "EngineActivityId"); runspace._bSessionStateProxyCallInProgress = RemotingDecoder.GetPropertyValue <bool>(obj, "SessionStateProxyCallInProgress"); runspace._bypassRunspaceStateCheck = RemotingDecoder.GetPropertyValue <bool>(obj, "ByPassRunspaceStateCheck"); PSEtwLog.SetActivityIdForCurrentThread(runspace.InstanceId); string originalConnectionInfoType = RemotingDecoder.GetPropertyValue <string> (obj, "OriginalConnectionInfoType"); PSObject originalConnectionObj = RemotingDecoder.GetPropertyValue <PSObject> (obj, "OriginalConnectionInfo"); RunspaceConnectionInfo originalConnectionInfo = null; if (originalConnectionInfoType == "WSManConnectionInfo") { originalConnectionInfo = WSManConnectionInfo.FromPSObjectForRemoting(originalConnectionObj); } else { var securePassord = new System.Security.SecureString(); securePassord.AppendChar('z'); originalConnectionInfo = new NewProcessConnectionInfo(new PSCredential("Anonymous", securePassord)); } runspace._originalConnectionInfo = originalConnectionInfo; runspace.RunspacePool.RemoteRunspacePoolInternal.SetStateInfo(new RunspacePoolStateInfo(RunspacePoolState.Opened, null)); return(runspace); }
protected override void CreateHelpersForSpecifiedComputerNames() { if (((base.Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce)) && ((this.ScriptBlock != null) || (this.InitializationScript != null))) { base.ThrowTerminatingError(new ErrorRecord(new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode), "CannotStartJobInconsistentLanguageMode", ErrorCategory.PermissionDenied, base.Context.LanguageMode)); } NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential) { RunAs32 = this.shouldRunAs32, InitializationScript = this.initScript, AuthenticationMechanism = this.Authentication, PSVersion = this.PSVersion }; RemoteRunspace remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, base.Host, Utils.GetTypeTableFromExecutionContextTLS()); remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived); Pipeline pipeline = base.CreatePipeline(remoteRunspace); IThrottleOperation item = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, false); base.Operations.Add(item); }
internal OutOfProcessClientSessionTransportManager(Guid runspaceId, NewProcessConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper) : base(runspaceId, cryptoHelper) { this._processCreated = true; this.onDataAvailableToSendCallback = new System.Management.Automation.Remoting.PrioritySendDataCollection.OnDataAvailableCallback(this.OnDataAvailableCallback); this.cmdTransportManagers = new Dictionary <Guid, OutOfProcessClientCommandTransportManager>(); this.connectionInfo = connectionInfo; this.dataProcessingCallbacks = new OutOfProcessUtils.DataProcessingDelegates(); this.dataProcessingCallbacks.DataPacketReceived = (OutOfProcessUtils.DataPacketReceived)Delegate.Combine(this.dataProcessingCallbacks.DataPacketReceived, new OutOfProcessUtils.DataPacketReceived(this.OnDataPacketReceived)); this.dataProcessingCallbacks.DataAckPacketReceived = (OutOfProcessUtils.DataAckPacketReceived)Delegate.Combine(this.dataProcessingCallbacks.DataAckPacketReceived, new OutOfProcessUtils.DataAckPacketReceived(this.OnDataAckPacketReceived)); this.dataProcessingCallbacks.CommandCreationPacketReceived = (OutOfProcessUtils.CommandCreationPacketReceived)Delegate.Combine(this.dataProcessingCallbacks.CommandCreationPacketReceived, new OutOfProcessUtils.CommandCreationPacketReceived(this.OnCommandCreationPacketReceived)); this.dataProcessingCallbacks.CommandCreationAckReceived = (OutOfProcessUtils.CommandCreationAckReceived)Delegate.Combine(this.dataProcessingCallbacks.CommandCreationAckReceived, new OutOfProcessUtils.CommandCreationAckReceived(this.OnCommandCreationAckReceived)); this.dataProcessingCallbacks.SignalPacketReceived = (OutOfProcessUtils.SignalPacketReceived)Delegate.Combine(this.dataProcessingCallbacks.SignalPacketReceived, new OutOfProcessUtils.SignalPacketReceived(this.OnSignalPacketReceived)); this.dataProcessingCallbacks.SignalAckPacketReceived = (OutOfProcessUtils.SignalAckPacketReceived)Delegate.Combine(this.dataProcessingCallbacks.SignalAckPacketReceived, new OutOfProcessUtils.SignalAckPacketReceived(this.OnSiganlAckPacketReceived)); this.dataProcessingCallbacks.ClosePacketReceived = (OutOfProcessUtils.ClosePacketReceived)Delegate.Combine(this.dataProcessingCallbacks.ClosePacketReceived, new OutOfProcessUtils.ClosePacketReceived(this.OnClosePacketReceived)); this.dataProcessingCallbacks.CloseAckPacketReceived = (OutOfProcessUtils.CloseAckPacketReceived)Delegate.Combine(this.dataProcessingCallbacks.CloseAckPacketReceived, new OutOfProcessUtils.CloseAckPacketReceived(this.OnCloseAckReceived)); base.dataToBeSent.Fragmentor = base.Fragmentor; base.ReceivedDataCollection.MaximumReceivedDataSize = null; base.ReceivedDataCollection.MaximumReceivedObjectSize = 0xa00000; this.closeTimeOutTimer = new Timer(60000.0); this.closeTimeOutTimer.Elapsed += new ElapsedEventHandler(this.OnCloseTimeOutTimerElapsed); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
internal OutOfProcessClientSessionTransportManager( Guid runspaceId, NewProcessConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper) : base(runspaceId, cryptoHelper) { this.onDataAvailableToSendCallback = new PrioritySendDataCollection.OnDataAvailableCallback(this.OnDataAvailableCallback); this.cmdTransportManagers = new Dictionary <Guid, OutOfProcessClientCommandTransportManager>(); this.connectionInfo = connectionInfo; this.dataProcessingCallbacks = new OutOfProcessUtils.DataProcessingDelegates(); this.dataProcessingCallbacks.DataPacketReceived += new OutOfProcessUtils.DataPacketReceived(this.OnDataPacketReceived); this.dataProcessingCallbacks.DataAckPacketReceived += new OutOfProcessUtils.DataAckPacketReceived(this.OnDataAckPacketReceived); this.dataProcessingCallbacks.CommandCreationPacketReceived += new OutOfProcessUtils.CommandCreationPacketReceived(this.OnCommandCreationPacketReceived); this.dataProcessingCallbacks.CommandCreationAckReceived += new OutOfProcessUtils.CommandCreationAckReceived(this.OnCommandCreationAckReceived); this.dataProcessingCallbacks.SignalPacketReceived += new OutOfProcessUtils.SignalPacketReceived(this.OnSignalPacketReceived); this.dataProcessingCallbacks.SignalAckPacketReceived += new OutOfProcessUtils.SignalAckPacketReceived(this.OnSiganlAckPacketReceived); this.dataProcessingCallbacks.ClosePacketReceived += new OutOfProcessUtils.ClosePacketReceived(this.OnClosePacketReceived); this.dataProcessingCallbacks.CloseAckPacketReceived += new OutOfProcessUtils.CloseAckPacketReceived(this.OnCloseAckReceived); this.dataToBeSent.Fragmentor = this.Fragmentor; this.ReceivedDataCollection.MaximumReceivedDataSize = new int?(); this.ReceivedDataCollection.MaximumReceivedObjectSize = new int?(10485760); this.closeTimeOutTimer = new System.Timers.Timer(60000.0); this.closeTimeOutTimer.Elapsed += new ElapsedEventHandler(this.OnCloseTimeOutTimerElapsed); }