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)); }
/// <summary> /// ComparePassword uses native functions to perform a string match on two SecureString passwords /// by doing a strict byte level comparison is done on the two strings. /// The use of ReadByte allows the function to execute without marking the assembly as unsafe. /// </summary> /// <param name="secureString1">Password 1</param> /// <param name="secureString2">Password 2</param> /// <returns>True if they match else false.</returns> internal static bool ComparePassword(SecureString secureString1, SecureString secureString2) { if (secureString1 == null && secureString2 == null) { return(true); } if (secureString1 == null ^ secureString2 == null) { return(false); } Debug.Assert(secureString1 != null && secureString2 != null, "SecureStrings should be != null"); if (secureString1.Length != secureString2.Length) { return(false); } IntPtr bstr1 = IntPtr.Zero; IntPtr bstr2 = IntPtr.Zero; try { bstr1 = Marshal.SecureStringToBSTR(secureString1); bstr2 = Marshal.SecureStringToBSTR(secureString2); int offset = 0; Byte leftHigh, leftLow, rightHigh, rightLow; bool notDone = true; do { leftLow = Marshal.ReadByte(bstr1, offset + 1); rightLow = Marshal.ReadByte(bstr2, offset + 1); leftHigh = Marshal.ReadByte(bstr1, offset); rightHigh = Marshal.ReadByte(bstr2, offset); offset += 2; if (leftLow != rightLow || leftHigh != rightHigh) { return(false); } notDone = leftLow != 0 || leftHigh != 0; // terminator - 2 null characters (0x00)? leftLow = rightLow = leftHigh = rightHigh = 0; } while (notDone); return(true); } catch (Exception e) { using (PowerShellTraceSource tracer = PowerShellTraceSourceFactory.GetTraceSource()) { // SecureStringToBSTR or ReadByte threw exceptions tracer.WriteMessage("Getting an exception while comparing credentials..."); tracer.TraceException(e); return(false); } } finally { if (IntPtr.Zero != bstr1) { Marshal.ZeroFreeBSTR(bstr1); } if (IntPtr.Zero != bstr2) { Marshal.ZeroFreeBSTR(bstr2); } } } // ComparePassword ...
public ActivityInvoker() { this._syncObject = new object(); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
static InstanceStoreCryptography() { InstanceStoreCryptography.Tracer = PowerShellTraceSourceFactory.GetTraceSource(); byte[] numArray = new byte[] { 80, 79, 87, 69, 82, 83, 72, 69, 76, 76, 87, 79, 82, 75, 70, 76, 79, 87 }; InstanceStoreCryptography.s_aditionalEntropy = numArray; }
private static void ProcessElement(XmlReader xmlReader, DataProcessingDelegates callbacks) { PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource(); switch (xmlReader.LocalName) { case "Data": { if (xmlReader.AttributeCount != 2) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForDataElement, RemotingErrorIdStrings.IPCWrongAttributeCountForDataElement, new object[] { "Stream", "PSGuid", "Data" }); } string attribute = xmlReader.GetAttribute("Stream"); string g = xmlReader.GetAttribute("PSGuid"); Guid psGuid = new Guid(g); if (!xmlReader.Read()) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCInsufficientDataforElement, RemotingErrorIdStrings.IPCInsufficientDataforElement, new object[] { "Data" }); } if (xmlReader.NodeType != XmlNodeType.Text) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCOnlyTextExpectedInDataElement, RemotingErrorIdStrings.IPCOnlyTextExpectedInDataElement, new object[] { xmlReader.NodeType, "Data", XmlNodeType.Text }); } string s = xmlReader.Value; traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_DATA received, psGuid : " + psGuid.ToString()); byte[] rawData = Convert.FromBase64String(s); callbacks.DataPacketReceived(rawData, attribute, psGuid); return; } case "DataAck": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "DataAck" }); } string str4 = xmlReader.GetAttribute("PSGuid"); Guid guid2 = new Guid(str4); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_DATA_ACK received, psGuid : " + guid2.ToString()); callbacks.DataAckPacketReceived(guid2); return; } case "Command": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "Command" }); } string str5 = xmlReader.GetAttribute("PSGuid"); Guid guid3 = new Guid(str5); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_COMMAND received, psGuid : " + guid3.ToString()); callbacks.CommandCreationPacketReceived(guid3); return; } case "CommandAck": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "CommandAck" }); } string str6 = xmlReader.GetAttribute("PSGuid"); Guid guid4 = new Guid(str6); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_COMMAND_ACK received, psGuid : " + guid4.ToString()); callbacks.CommandCreationAckReceived(guid4); return; } case "Close": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "Close" }); } string str7 = xmlReader.GetAttribute("PSGuid"); Guid guid5 = new Guid(str7); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_CLOSE received, psGuid : " + guid5.ToString()); callbacks.ClosePacketReceived(guid5); return; } case "CloseAck": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "CloseAck" }); } string str8 = xmlReader.GetAttribute("PSGuid"); Guid guid6 = new Guid(str8); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_CLOSE_ACK received, psGuid : " + guid6.ToString()); callbacks.CloseAckPacketReceived(guid6); return; } case "Signal": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "Signal" }); } string str9 = xmlReader.GetAttribute("PSGuid"); Guid guid7 = new Guid(str9); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_SIGNAL received, psGuid : " + guid7.ToString()); callbacks.SignalPacketReceived(guid7); return; } case "SignalAck": { if (xmlReader.AttributeCount != 1) { throw new PSRemotingTransportException(PSRemotingErrorId.IPCWrongAttributeCountForElement, RemotingErrorIdStrings.IPCWrongAttributeCountForElement, new object[] { "PSGuid", "SignalAck" }); } string str10 = xmlReader.GetAttribute("PSGuid"); Guid guid8 = new Guid(str10); traceSource.WriteMessage("OutOfProcessUtils.ProcessElement : PS_OUT_OF_PROC_SIGNAL_ACK received, psGuid : " + guid8.ToString()); callbacks.SignalAckPacketReceived(guid8); return; } } throw new PSRemotingTransportException(PSRemotingErrorId.IPCUnknownElementReceived, RemotingErrorIdStrings.IPCUnknownElementReceived, new object[] { xmlReader.LocalName }); }
public PSCounterSetInstance(CounterSetRegistrarBase counterSetRegBaseObj) : base(counterSetRegBaseObj) { this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); this.CreateCounterSetInstance(); }
internal static bool ComparePassword(SecureString secureString1, SecureString secureString2) { bool flag; bool flag1; if (secureString1 != null || secureString2 != null) { if (!(secureString1 == null ^ secureString2 == null)) { if (secureString1.Length == secureString2.Length) { IntPtr zero = IntPtr.Zero; IntPtr bSTR = IntPtr.Zero; try { try { zero = Marshal.SecureStringToBSTR(secureString1); bSTR = Marshal.SecureStringToBSTR(secureString2); int num = 0; bool flag2 = true; do { byte num1 = Marshal.ReadByte(zero, num + 1); byte num2 = Marshal.ReadByte(bSTR, num + 1); byte num3 = Marshal.ReadByte(zero, num); byte num4 = Marshal.ReadByte(bSTR, num); num = num + 2; if (num1 != num2 || num3 != num4) { flag = false; return(flag); } else { if (num1 != 0) { flag1 = true; } else { flag1 = num3 != 0; } flag2 = flag1; } }while (flag2); flag = true; } catch (Exception exception1) { Exception exception = exception1; PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource(); using (traceSource) { traceSource.WriteMessage("Getting an exception while comparing credentials..."); traceSource.TraceException(exception); flag = false; } } } finally { if (IntPtr.Zero != zero) { Marshal.ZeroFreeBSTR(zero); } if (IntPtr.Zero != bSTR) { Marshal.ZeroFreeBSTR(bSTR); } } return(flag); } else { return(false); } } else { return(false); } } else { return(true); } }
protected Job2(string command, string name, JobIdentifier token) : base(command, name, token) { this._syncobject = new object(); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
protected Job2(string command, string name, Guid instanceId) : base(command, name, instanceId) { this._syncobject = new object(); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
protected Job2(string command, string name, IList <Job> childJobs) : base(command, name, childJobs) { this._syncobject = new object(); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
protected Job2(string command) : base(command) { this._syncobject = new object(); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }
protected Job2() { this._syncobject = new object(); this._tracer = PowerShellTraceSourceFactory.GetTraceSource(); }