Exemple #1
0
        private static void OnRemoteCmdDataReceived(IntPtr operationContext, int flags, IntPtr error, IntPtr shellOperationHandle, IntPtr commandOperationHandle, IntPtr operationHandle, IntPtr data)
        {
            BaseClientTransportManager.tracer.WriteLine("Remote Command DataReceived callback.", new object[0]);
            long cmdTMId = 0L;
            WSManClientCommandTransportManager cmdTransportManager = null;

            if (!TryGetCmdTransportManager(operationContext, out cmdTransportManager, out cmdTMId))
            {
                BaseClientTransportManager.tracer.WriteLine("Unable to find a transport manager for the given command context {0}.", new object[] { cmdTMId });
            }
            else if (!shellOperationHandle.Equals(cmdTransportManager.wsManShellOperationHandle) || !commandOperationHandle.Equals(cmdTransportManager.wsManCmdOperationHandle))
            {
                BaseClientTransportManager.tracer.WriteLine("CmdReceive callback: ShellOperationHandles are not the same as the Receive is initiated with", new object[0]);
                PSRemotingTransportException   e         = new PSRemotingTransportException(RemotingErrorIdStrings.CommandReceiveExFailed);
                TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(e, TransportMethodEnum.ReceiveCommandOutputEx);
                cmdTransportManager.ProcessWSManTransportError(eventArgs);
            }
            else
            {
                cmdTransportManager.ClearReceiveOrSendResources(flags, false);
                if (cmdTransportManager.isClosed)
                {
                    BaseClientTransportManager.tracer.WriteLine("Client Command TM: Transport manager is closed. So returning", new object[0]);
                }
                else
                {
                    if (IntPtr.Zero != error)
                    {
                        WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error);
                        if (errorStruct.errorCode != 0)
                        {
                            BaseClientTransportManager.tracer.WriteLine("CmdReceive callback: WSMan reported an error: {0}", new object[] { errorStruct.errorDetail });
                            TransportErrorOccuredEventArgs args2 = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, null, errorStruct, TransportMethodEnum.ReceiveCommandOutputEx, RemotingErrorIdStrings.CommandReceiveExCallBackError, new object[] { errorStruct.errorDetail });
                            cmdTransportManager.ProcessWSManTransportError(args2);
                            return;
                        }
                    }
                    if (flags == 0x2000)
                    {
                        cmdTransportManager.isDisconnectedOnInvoke = true;
                        cmdTransportManager.RaiseDelayStreamProcessedEvent();
                    }
                    else
                    {
                        WSManNativeApi.WSManReceiveDataResult result = WSManNativeApi.WSManReceiveDataResult.UnMarshal(data);
                        if (result.data != null)
                        {
                            BaseClientTransportManager.tracer.WriteLine("Cmd Received Data : {0}", new object[] { result.data.Length });
                            object[] args = new object[] { cmdTransportManager.RunspacePoolInstanceId.ToString(), cmdTransportManager.powershellInstanceId.ToString(), result.data.Length.ToString(CultureInfo.InvariantCulture) };
                            PSEtwLog.LogAnalyticInformational(PSEventId.WSManReceiveShellOutputExCallbackReceived, PSOpcode.Receive, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, args);
                            cmdTransportManager.ProcessRawData(result.data, result.stream);
                        }
                    }
                }
            }
        }
        private static void OnRemoteCmdDataReceived(
            IntPtr operationContext,
            int flags,
            IntPtr error,
            IntPtr shellOperationHandle,
            IntPtr commandOperationHandle,
            IntPtr operationHandle,
            IntPtr data)
        {
            BaseClientTransportManager.tracer.WriteLine("Remote Command DataReceived callback.", new object[0]);
            long cmdTMId = 0;
            WSManClientCommandTransportManager cmdTransportManager = (WSManClientCommandTransportManager)null;

            if (!WSManClientCommandTransportManager.TryGetCmdTransportManager(operationContext, out cmdTransportManager, out cmdTMId))
            {
                BaseClientTransportManager.tracer.WriteLine("Unable to find a transport manager for the given command context {0}.", (object)cmdTMId);
            }
            else if (!shellOperationHandle.Equals((object)cmdTransportManager.wsManShellOperationHandle) || !commandOperationHandle.Equals((object)cmdTransportManager.wsManCmdOperationHandle))
            {
                BaseClientTransportManager.tracer.WriteLine("CmdReceive callback: ShellOperationHandles are not the same as the Receive is initiated with", new object[0]);
                TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(new PSRemotingTransportException(PSRemotingErrorId.CommandReceiveExFailed, new object[0]), TransportMethodEnum.ReceiveCommandOutputEx);
                cmdTransportManager.RaiseErrorHandler(eventArgs);
            }
            else
            {
                cmdTransportManager.ClearReceiveOrSendResources(flags, false);
                if (cmdTransportManager.isClosed)
                {
                    BaseClientTransportManager.tracer.WriteLine("Client Command TM: Transport manager is closed. So returning", new object[0]);
                }
                else
                {
                    if (IntPtr.Zero != error)
                    {
                        WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error);
                        if (errorStruct.errorCode != 0)
                        {
                            BaseClientTransportManager.tracer.WriteLine("CmdReceive callback: WSMan reported an error: {0}", (object)errorStruct.errorDetail);
                            TransportErrorOccuredEventArgs eventArgs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, IntPtr.Zero, errorStruct, TransportMethodEnum.ReceiveCommandOutputEx, PSRemotingErrorId.CommandReceiveExCallBackError, (object)errorStruct.errorDetail);
                            cmdTransportManager.RaiseErrorHandler(eventArgs);
                            return;
                        }
                    }
                    WSManNativeApi.WSManReceiveDataResult receiveDataResult = WSManNativeApi.WSManReceiveDataResult.UnMarshal(data);
                    if (receiveDataResult.data == null)
                    {
                        return;
                    }
                    BaseClientTransportManager.tracer.WriteLine("Cmd Received Data : {0}", (object)receiveDataResult.data.Length);
                    BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManReceiveShellOutputExCallbackReceived, PSOpcode.Receive, PSTask.None, (object)cmdTransportManager.RunspacePoolInstanceId, (object)cmdTransportManager.powershellInstanceId, (object)receiveDataResult.data.Length.ToString((IFormatProvider)CultureInfo.InvariantCulture));
                    cmdTransportManager.ProcessRawData(receiveDataResult.data, receiveDataResult.stream);
                }
            }
        }
Exemple #3
0
        private static void OnRemoteCmdSendCompleted(IntPtr operationContext, int flags, IntPtr error, IntPtr shellOperationHandle, IntPtr commandOperationHandle, IntPtr operationHandle, IntPtr data)
        {
            BaseClientTransportManager.tracer.WriteLine("SendComplete callback received", new object[0]);
            long cmdTMId = 0L;
            WSManClientCommandTransportManager cmdTransportManager = null;

            if (!TryGetCmdTransportManager(operationContext, out cmdTransportManager, out cmdTMId))
            {
                BaseClientTransportManager.tracer.WriteLine("Unable to find a transport manager for the command context {0}.", new object[] { cmdTMId });
            }
            else
            {
                cmdTransportManager.isSendingInput = false;
                PSEtwLog.LogAnalyticInformational(PSEventId.WSManSendShellInputExCallbackReceived, PSOpcode.Connect, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, new object[] { cmdTransportManager.RunspacePoolInstanceId.ToString(), cmdTransportManager.powershellInstanceId.ToString() });
                if (!shellOperationHandle.Equals(cmdTransportManager.wsManShellOperationHandle) || !commandOperationHandle.Equals(cmdTransportManager.wsManCmdOperationHandle))
                {
                    BaseClientTransportManager.tracer.WriteLine("SendShellInputEx callback: ShellOperationHandles are not the same as the Send is initiated with", new object[0]);
                    PSRemotingTransportException   e         = new PSRemotingTransportException(RemotingErrorIdStrings.CommandSendExFailed);
                    TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(e, TransportMethodEnum.CommandInputEx);
                    cmdTransportManager.ProcessWSManTransportError(eventArgs);
                }
                else
                {
                    cmdTransportManager.ClearReceiveOrSendResources(flags, true);
                    if (cmdTransportManager.isClosed)
                    {
                        BaseClientTransportManager.tracer.WriteLine("Client Command TM: Transport manager is closed. So returning", new object[0]);
                        if (cmdTransportManager.isDisconnectPending)
                        {
                            cmdTransportManager.RaiseReadyForDisconnect();
                        }
                    }
                    else
                    {
                        if (IntPtr.Zero != error)
                        {
                            WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error);
                            if ((errorStruct.errorCode != 0) && (errorStruct.errorCode != 0x3e3))
                            {
                                BaseClientTransportManager.tracer.WriteLine("CmdSend callback: WSMan reported an error: {0}", new object[] { errorStruct.errorDetail });
                                TransportErrorOccuredEventArgs args2 = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, null, errorStruct, TransportMethodEnum.CommandInputEx, RemotingErrorIdStrings.CommandSendExCallBackError, new object[] { WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail) });
                                cmdTransportManager.ProcessWSManTransportError(args2);
                                return;
                            }
                        }
                        cmdTransportManager.shouldStartReceivingData = true;
                        cmdTransportManager.SendOneItem();
                    }
                }
            }
        }
        private static void OnRemoteCmdSendCompleted(
            IntPtr operationContext,
            int flags,
            IntPtr error,
            IntPtr shellOperationHandle,
            IntPtr commandOperationHandle,
            IntPtr operationHandle,
            IntPtr data)
        {
            BaseClientTransportManager.tracer.WriteLine("SendComplete callback received", new object[0]);
            long cmdTMId = 0;
            WSManClientCommandTransportManager cmdTransportManager = (WSManClientCommandTransportManager)null;

            if (!WSManClientCommandTransportManager.TryGetCmdTransportManager(operationContext, out cmdTransportManager, out cmdTMId))
            {
                BaseClientTransportManager.tracer.WriteLine("Unable to find a transport manager for the command context {0}.", (object)cmdTMId);
            }
            else
            {
                BaseTransportManager.ETWTracer.AnalyticChannel.WriteInformation(PSEventId.WSManSendShellInputExCallbackReceived, PSOpcode.Connect, PSTask.None, (object)cmdTransportManager.RunspacePoolInstanceId, (object)cmdTransportManager.powershellInstanceId);
                if (!shellOperationHandle.Equals((object)cmdTransportManager.wsManShellOperationHandle) || !commandOperationHandle.Equals((object)cmdTransportManager.wsManCmdOperationHandle))
                {
                    BaseClientTransportManager.tracer.WriteLine("SendShellInputEx callback: ShellOperationHandles are not the same as the Send is initiated with", new object[0]);
                    TransportErrorOccuredEventArgs eventArgs = new TransportErrorOccuredEventArgs(new PSRemotingTransportException(PSRemotingErrorId.CommandSendExFailed, new object[0]), TransportMethodEnum.CommandInputEx);
                    cmdTransportManager.RaiseErrorHandler(eventArgs);
                }
                else
                {
                    cmdTransportManager.ClearReceiveOrSendResources(flags, true);
                    if (cmdTransportManager.isClosed)
                    {
                        BaseClientTransportManager.tracer.WriteLine("Client Command TM: Transport manager is closed. So returning", new object[0]);
                    }
                    else
                    {
                        if (IntPtr.Zero != error)
                        {
                            WSManNativeApi.WSManError errorStruct = WSManNativeApi.WSManError.UnMarshal(error);
                            if (errorStruct.errorCode != 0 && errorStruct.errorCode != 995)
                            {
                                BaseClientTransportManager.tracer.WriteLine("CmdSend callback: WSMan reported an error: {0}", (object)errorStruct.errorDetail);
                                TransportErrorOccuredEventArgs eventArgs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(WSManClientSessionTransportManager.wsManApiStaticData.WSManAPIHandle, IntPtr.Zero, errorStruct, TransportMethodEnum.CommandInputEx, PSRemotingErrorId.CommandSendExCallBackError, (object)WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(errorStruct.errorDetail));
                                cmdTransportManager.RaiseErrorHandler(eventArgs);
                                return;
                            }
                        }
                        cmdTransportManager.SendOneItem();
                    }
                }
            }
        }