internal override void CloseAsync() { bool flag = false; lock (base.syncObject) { if (base.isClosed) { return; } base.isClosed = true; if (this.stdInWriter == null) { flag = true; } } base.CloseAsync(); if (!flag) { PSEtwLog.LogAnalyticInformational(PSEventId.WSManCloseShell, PSOpcode.Disconnect, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { base.RunspacePoolInstanceId.ToString() }); this._tracer.WriteMessage(string.Concat(new object[] { "OutOfProcessClientSessionTransportManager.CloseAsync, when sending close session packet, progress command count should be zero, current cmd count: ", this.cmdTransportManagers.Count, ", RunSpacePool Id : ", base.RunspacePoolInstanceId })); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateClosePacket(Guid.Empty)); this.closeTimeOutTimer.Start(); } else { base.RaiseCloseCompleted(); } }
private void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid) { string str = "stdin"; if (stream.Equals(DataPriorityType.PromptResponse.ToString(), StringComparison.OrdinalIgnoreCase)) { str = "pr"; } if (Guid.Empty == psGuid) { lock (this._syncObject) { this.sessionTM.ProcessRawData(rawData, str); return; } } AbstractServerTransportManager commandTransportManager = null; lock (this._syncObject) { commandTransportManager = this.sessionTM.GetCommandTransportManager(psGuid); } if (commandTransportManager != null) { commandTransportManager.ProcessRawData(rawData, str); } else { this.originalStdOut.WriteLine(OutOfProcessUtils.CreateDataAckPacket(psGuid)); } }
internal override void SendStopSignal() { PSEtwLog.LogAnalyticInformational(PSEventId.WSManSignal, PSOpcode.Disconnect, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { base.RunspacePoolInstanceId.ToString(), this.powershellInstanceId.ToString(), "stopsignal" }); base.CloseAsync(); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateSignalPacket(base.powershellInstanceId)); this.signalTimeOutTimer.Start(); }
protected void OnSignalPacketReceived(Guid psGuid) { if (psGuid == Guid.Empty) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCNoSignalForSession, RemotingErrorIdStrings.IPCNoSignalForSession, OutOfProcessUtils.PS_OUT_OF_PROC_SIGNAL_TAG); } else { // this is for a command AbstractServerTransportManager cmdTM = null; try { lock (_syncObject) { cmdTM = sessionTM.GetCommandTransportManager(psGuid); } // dont throw if there is no cmdTM as it might have legitimately closed if (cmdTM != null) { cmdTM.Close(null); } } finally { // Always send ack signal to avoid not responding in client. originalStdOut.WriteLine(OutOfProcessUtils.CreateSignalAckPacket(psGuid)); } } }
internal override void SendStopSignal() { BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManSignal, PSOpcode.Disconnect, PSTask.None, (object)this.RunspacePoolInstanceId, (object)this.powershellInstanceId, (object)"stopsignal"); base.CloseAsync(); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateSignalPacket(this.powershellInstanceId)); this.signalTimeOutTimer.Start(); }
internal override void CloseAsync() { bool flag = false; lock (this.syncObject) { if (this.isClosed) { return; } this.isClosed = true; if (this.stdInWriter == null) { flag = true; } } base.CloseAsync(); if (flag) { this.RaiseCloseCompleted(); } else { BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManCloseShell, PSOpcode.Disconnect, PSTask.None, (object)this.RunspacePoolInstanceId); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateClosePacket(Guid.Empty)); this.closeTimeOutTimer.Start(); } }
internal override void Prepare() { if (this.isDataAckSendPending) { this.isDataAckSendPending = false; base.Prepare(); this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateDataAckPacket(this.powershellInstanceId)); } }
internal void CreateCommandTransportManager(Guid powerShellCmdId) { OutOfProcessServerTransportManager transportManager = new OutOfProcessServerTransportManager(this.stdOutWriter, powerShellCmdId, this.TypeTable, this.Fragmentor.FragmentSize, this.CryptoHelper); transportManager.MigrateDataReadyEventHandlers((BaseTransportManager)this); lock (this.syncObject) this.cmdTransportManagers.Add(powerShellCmdId, transportManager); this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateCommandAckPacket(powerShellCmdId)); }
internal override void ProcessRawData(byte[] data, string stream) { this.isDataAckSendPending = true; base.ProcessRawData(data, stream); if (this.isDataAckSendPending) { this.isDataAckSendPending = false; this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateDataAckPacket(this.powershellInstanceId)); } }
private void OnClosePacketReceived(Guid psGuid) { PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource(); if (psGuid == Guid.Empty) { traceSource.WriteMessage("BEGIN calling close on session transport manager"); bool flag = false; lock (this._syncObject) { if (this._inProgressCommandsCount > 0) { flag = true; } } if (flag) { this.allcmdsClosedEvent.WaitOne(); } lock (this._syncObject) { traceSource.WriteMessage(string.Concat(new object[] { "OnClosePacketReceived, in progress commands count should be zero : ", this._inProgressCommandsCount, ", psGuid : ", psGuid.ToString() })); if (this.sessionTM != null) { this.sessionTM.Close(null); } traceSource.WriteMessage("END calling close on session transport manager"); this.sessionTM = null; goto Label_01D5; } } traceSource.WriteMessage("Closing command with GUID " + psGuid.ToString()); AbstractServerTransportManager commandTransportManager = null; lock (this._syncObject) { commandTransportManager = this.sessionTM.GetCommandTransportManager(psGuid); } if (commandTransportManager != null) { commandTransportManager.Close(null); } lock (this._syncObject) { traceSource.WriteMessage(string.Concat(new object[] { "OnClosePacketReceived, in progress commands count should be greater than zero : ", this._inProgressCommandsCount, ", psGuid : ", psGuid.ToString() })); this._inProgressCommandsCount--; if (this._inProgressCommandsCount == 0) { this.allcmdsClosedEvent.Set(); } } Label_01D5: this.originalStdOut.WriteLine(OutOfProcessUtils.CreateCloseAckPacket(psGuid)); }
private void OnSignalPacketReceived(Guid psGuid) { if (psGuid == Guid.Empty) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCNoSignalForSession, new object[1] { (object)"Signal" }); } this.sessionTM.GetCommandTransportManager(psGuid)?.Close((Exception)null); this.originalStdOut.WriteLine(OutOfProcessUtils.CreateSignalAckPacket(psGuid)); }
private void SendData(byte[] data, DataPriorityType priorityType) { BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManSendShellInputEx, PSOpcode.Send, PSTask.None, (object)this.RunspacePoolInstanceId, (object)Guid.Empty, (object)data.Length.ToString((IFormatProvider)CultureInfo.InvariantCulture)); lock (this.syncObject) { if (this.isClosed) { return; } this.stdInWriter.WriteLine(OutOfProcessUtils.CreateDataPacket(data, priorityType, Guid.Empty)); } }
private void OnClosePacketReceived(Guid psGuid) { if (psGuid == Guid.Empty) { this.sessionTM.Close((Exception)null); } else { this.sessionTM.GetCommandTransportManager(psGuid)?.Close((Exception)null); } this.originalStdOut.WriteLine(OutOfProcessUtils.CreateCloseAckPacket(psGuid)); }
private void SendData(byte[] data, DataPriorityType priorityType) { object[] args = new object[] { base.RunspacePoolInstanceId.ToString(), this.powershellInstanceId.ToString(), data.Length.ToString(CultureInfo.InvariantCulture) }; PSEtwLog.LogAnalyticInformational(PSEventId.WSManSendShellInputEx, PSOpcode.Send, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, args); lock (base.syncObject) { if (!base.isClosed) { this.stdInWriter.WriteLine(OutOfProcessUtils.CreateDataPacket(data, priorityType, base.powershellInstanceId)); } } }
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e) { try { OutOfProcessUtils.ProcessData(e.Data, this.dataProcessingCallbacks); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); PSRemotingTransportException exception2 = new PSRemotingTransportException(PSRemotingErrorId.IPCErrorProcessingServerData, RemotingErrorIdStrings.IPCErrorProcessingServerData, new object[] { exception.Message }); this.RaiseErrorHandler(new TransportErrorOccuredEventArgs(exception2, TransportMethodEnum.ReceiveShellOutputEx)); } }
internal override void CloseAsync() { lock (this.syncObject) { if (this.isClosed) { return; } this.isClosed = true; } base.CloseAsync(); BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManCloseCommand, PSOpcode.Disconnect, PSTask.None, (object)this.RunspacePoolInstanceId, (object)this.powershellInstanceId); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateClosePacket(this.powershellInstanceId)); }
private void ProcessingThreadStart(object state) { try { OutOfProcessUtils.ProcessData(state as string, this.callbacks); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); OutOfProcessMediator.ETWTracer.OperationalChannel.WriteError(PSEventId.TransportError, PSOpcode.Open, PSTask.None, (object)Guid.Empty, (object)Guid.Empty, (object)4000, (object)ex.Message, (object)ex.StackTrace); OutOfProcessMediator.ETWTracer.AnalyticChannel.WriteError(PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None, (object)Guid.Empty, (object)Guid.Empty, (object)4000, (object)ex.Message, (object)ex.StackTrace); this.originalStdErr.WriteLine(ex.Message + ex.StackTrace); Environment.Exit(4000); } }
private void ProcessingThreadStart(object state) { try { string data = state as string; OutOfProcessUtils.ProcessData(data, this.callbacks); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); PSEtwLog.LogOperationalError(PSEventId.TransportError, PSOpcode.Open, PSTask.None, PSKeyword.UseAlwaysOperational, new object[] { Guid.Empty.ToString(), Guid.Empty.ToString(), 0xfa0, exception.Message, exception.StackTrace }); PSEtwLog.LogAnalyticError(PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { Guid.Empty.ToString(), Guid.Empty.ToString(), 0xfa0, exception.Message, exception.StackTrace }); this.originalStdErr.WriteLine(exception.Message + exception.StackTrace); Environment.Exit(0xfa0); } }
protected void ProcessingThreadStart(object state) { try { #if !CORECLR // CurrentUICulture is not available in Thread Class in CSS // WinBlue: 621775. Thread culture is not properly set // for local background jobs causing experience differences // between local console and local background jobs. Thread.CurrentThread.CurrentUICulture = Microsoft.PowerShell.NativeCultureResolver.UICulture; Thread.CurrentThread.CurrentCulture = Microsoft.PowerShell.NativeCultureResolver.Culture; #endif string data = state as string; OutOfProcessUtils.ProcessData(data, callbacks); } catch (Exception e) { PSEtwLog.LogOperationalError( PSEventId.TransportError, PSOpcode.Open, PSTask.None, PSKeyword.UseAlwaysOperational, Guid.Empty.ToString(), Guid.Empty.ToString(), OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION, e.Message, e.StackTrace); PSEtwLog.LogAnalyticError( PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, Guid.Empty.ToString(), Guid.Empty.ToString(), OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION, e.Message, e.StackTrace); // notify the remote client of any errors and fail gracefully if (_exitProcessOnError) { originalStdErr.WriteLine(e.Message + e.StackTrace); Environment.Exit(OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION); } } }
internal override void CloseAsync() { lock (base.syncObject) { if (base.isClosed) { return; } base.isClosed = true; } base.CloseAsync(); PSEtwLog.LogAnalyticInformational(PSEventId.WSManCloseCommand, PSOpcode.Disconnect, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { base.RunspacePoolInstanceId.ToString(), this.powershellInstanceId.ToString() }); if (this.stdInWriter != null) { this.stdInWriter.WriteLine(OutOfProcessUtils.CreateClosePacket(base.powershellInstanceId)); } }
private void OnSignalPacketReceived(Guid psGuid) { if (psGuid == Guid.Empty) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCNoSignalForSession, RemotingErrorIdStrings.IPCNoSignalForSession, new object[] { "Signal" }); } AbstractServerTransportManager commandTransportManager = null; lock (this._syncObject) { commandTransportManager = this.sessionTM.GetCommandTransportManager(psGuid); } if (commandTransportManager != null) { commandTransportManager.Close(null); } this.originalStdOut.WriteLine(OutOfProcessUtils.CreateSignalAckPacket(psGuid)); }
protected void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid) { string streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_STDIN; if (stream.Equals(DataPriorityType.PromptResponse.ToString(), StringComparison.OrdinalIgnoreCase)) { streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_PROMPTRESPONSE; } if (Guid.Empty == psGuid) { lock (_syncObject) { sessionTM.ProcessRawData(rawData, streamTemp); } } else { // this is for a command AbstractServerTransportManager cmdTM = null; lock (_syncObject) { cmdTM = sessionTM.GetCommandTransportManager(psGuid); } if (cmdTM != null) { // not throwing when there is no associated command as the command might have // legitimately closed while the client is sending data. however the client // should die after timeout as we are not sending an ACK back. cmdTM.ProcessRawData(rawData, streamTemp); } else { // There is no command transport manager to process the input data. // However, we still need to acknowledge to the client that this input data // was received. This can happen with some cmdlets such as Select-Object -First // where the cmdlet completes before all input data is received. originalStdOut.WriteLine(OutOfProcessUtils.CreateDataAckPacket(psGuid)); } } }
protected void ProcessingThreadStart(object state) { try { string data = state as string; OutOfProcessUtils.ProcessData(data, callbacks); } catch (Exception e) { PSEtwLog.LogOperationalError( PSEventId.TransportError, PSOpcode.Open, PSTask.None, PSKeyword.UseAlwaysOperational, Guid.Empty.ToString(), Guid.Empty.ToString(), OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION, e.Message, e.StackTrace); PSEtwLog.LogAnalyticError( PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, Guid.Empty.ToString(), Guid.Empty.ToString(), OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION, e.Message, e.StackTrace); // notify the remote client of any errors and fail gracefully if (_exitProcessOnError) { originalStdErr.WriteLine(e.Message + e.StackTrace); Environment.Exit(OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION); } } }
protected override void SendDataToClient(byte[] data, bool flush) => this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateDataPacket(data, DataPriorityType.Default, this.powershellInstanceId));
protected void OnClosePacketReceived(Guid psGuid) { PowerShellTraceSource tracer = PowerShellTraceSourceFactory.GetTraceSource(); if (psGuid == Guid.Empty) { tracer.WriteMessage("BEGIN calling close on session transport manager"); bool waitForAllcmdsClosedEvent = false; lock (_syncObject) { if (_inProgressCommandsCount > 0) { waitForAllcmdsClosedEvent = true; } } // Wait outside sync lock if required for all cmds to be closed // if (waitForAllcmdsClosedEvent) { allcmdsClosedEvent.WaitOne(); } lock (_syncObject) { tracer.WriteMessage("OnClosePacketReceived, in progress commands count should be zero : " + _inProgressCommandsCount + ", psGuid : " + psGuid.ToString()); if (sessionTM != null) { // it appears that when closing PowerShell ISE, therefore closing OutOfProcServerMediator, there are 2 Close command requests // changing PSRP/IPC at this point is too risky, therefore protecting about this duplication sessionTM.Close(null); } tracer.WriteMessage("END calling close on session transport manager"); sessionTM = null; } } else { tracer.WriteMessage("Closing command with GUID " + psGuid.ToString()); // this is for a command AbstractServerTransportManager cmdTM = null; lock (_syncObject) { cmdTM = sessionTM.GetCommandTransportManager(psGuid); } // dont throw if there is no cmdTM as it might have legitimately closed if (cmdTM != null) { cmdTM.Close(null); } lock (_syncObject) { tracer.WriteMessage("OnClosePacketReceived, in progress commands count should be greater than zero : " + _inProgressCommandsCount + ", psGuid : " + psGuid.ToString()); _inProgressCommandsCount--; if (_inProgressCommandsCount == 0) { allcmdsClosedEvent.Set(); } } } // send close ack originalStdOut.WriteLine(OutOfProcessUtils.CreateCloseAckPacket(psGuid)); }
protected override void SendDataToClient(byte[] data, bool flush) => this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateDataPacket(data, DataPriorityType.Default, Guid.Empty));
protected override void SendDataToClient(byte[] data, bool flush, bool reportAsPending, bool reportAsDataBoundary) { this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateDataPacket(data, DataPriorityType.Default, Guid.Empty)); }
internal override void ProcessRawData(byte[] data, string stream) { base.ProcessRawData(data, stream); this.stdOutWriter.WriteLine(OutOfProcessUtils.CreateDataAckPacket(Guid.Empty)); }
internal override void CreateAsync() { PSEtwLog.LogAnalyticInformational(PSEventId.WSManCreateCommand, PSOpcode.Connect, PSTask.CreateRunspace, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { base.RunspacePoolInstanceId.ToString(), this.powershellInstanceId.ToString() }); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateCommandPacket(base.powershellInstanceId)); }
internal override void ConnectAsync() { BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManCreateCommand, PSOpcode.Connect, PSTask.CreateRunspace, (object)this.RunspacePoolInstanceId, (object)this.powershellInstanceId); this.stdInWriter.WriteLine(OutOfProcessUtils.CreateCommandPacket(this.powershellInstanceId)); }