Beispiel #1
0
 public PSWorkflowTimer(PSWorkflowInstance instance, object deserializedTimers)
 {
     this.Tracer          = PowerShellTraceSourceFactory.GetTraceSource();
     this.syncLock        = new object();
     this.syncElapsedLock = new object();
     this._instance       = instance;
     this._timers         = new Dictionary <WorkflowTimerType, PSTimer>();
     if (deserializedTimers != null)
     {
         List <object> objs = (List <object>)deserializedTimers;
         foreach (object obj in objs)
         {
             if (obj == null || obj as Dictionary <string, object> == null)
             {
                 continue;
             }
             PSTimer pSTimer = new PSTimer((Dictionary <string, object>)obj, new WorkflowTimerElapsedHandler(this.Timer_WorkflowTimerElapsed));
             this._timers.Add(pSTimer.TimerType, pSTimer);
         }
         return;
     }
     else
     {
         throw new ArgumentNullException("deserializedTimers");
     }
 }
Beispiel #2
0
 private DefinitionCache()
 {
     this._tracer = PowerShellTraceSourceFactory.GetTraceSource();
     this._workflowDetailsCache = new Dictionary <WorkflowJobDefinition, DefinitionCache.WorkflowDetails>(new CompareBasedOnInstanceId());
     this._cachedActivities     = new ConcurrentDictionary <WorkflowJobDefinition, Activity>(new CompareBasedOnInstanceId());
     this._syncObject           = new object();
 }
        internal ActivityHostProcess(int activityHostTimeoutSec, PSLanguageMode?languageMode)
        {
            object obj;

            this._syncObject       = new object();
            this._tracer           = PowerShellTraceSourceFactory.GetTraceSource();
            this._languageMode     = languageMode;
            this._useJobIPCProcess = true;
            this._tracer.WriteMessage("BEGIN Creating new PowerShell process instance");
            this._processInstance = new PowerShellProcessInstance();
            this._tracer.WriteMessage("END Creating new PowerShell process instance ");
            this._runspace = this.CreateRunspace();
            Guid instanceId = this._runspace.InstanceId;

            this._tracer.WriteMessage("New runspace created ", instanceId.ToString());
            Timer timer = new Timer();

            timer.AutoReset      = false;
            timer.Interval       = 300000;
            this._timer          = timer;
            this._timer.Elapsed += new ElapsedEventHandler(this.TimerElapsed);
            Timer timer1 = this._timer;

            if (activityHostTimeoutSec > 0)
            {
                obj = activityHostTimeoutSec * 0x3e8;
            }
            else
            {
                obj = 0x493e0;
            }
            timer1.Interval = (double)obj;
            ActivityHostProcess._perfCountersMgr.UpdateCounterByValue(PSWorkflowPerformanceCounterSetInfo.CounterSetId, 21, (long)1, true);
        }
Beispiel #4
0
 public void UnloadJobStreams()
 {
     if (this._jobStreamsLoaded)
     {
         lock (this.syncObject)
         {
             if (!this._jobStreamsLoaded)
             {
                 return;
             }
             this._jobStreamsLoaded = false;
         }
         try
         {
             this.DoUnloadJobStreams();
         }
         catch (Exception exception)
         {
             using (PowerShellTraceSource source = PowerShellTraceSourceFactory.GetTraceSource())
             {
                 source.TraceException(exception);
             }
         }
     }
 }
Beispiel #5
0
 internal PSWorkflowTrackingParticipant()
 {
     this.Tracer            = PowerShellTraceSourceFactory.GetTraceSource();
     this._structuredTracer = new Tracer();
     object[] objArray = new object[1];
     objArray[0] = "WorkflowTrackingParticipant";
     this.Tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "{0} Created", objArray));
 }
Beispiel #6
0
 internal PSWorkflowTimer(PSWorkflowInstance instance)
 {
     this.Tracer          = PowerShellTraceSourceFactory.GetTraceSource();
     this.syncLock        = new object();
     this.syncElapsedLock = new object();
     this._instance       = instance;
     this._timers         = new Dictionary <WorkflowTimerType, PSTimer>();
 }
Beispiel #7
0
 public PSActivityContext()
 {
     this._tracer       = PowerShellTraceSourceFactory.GetTraceSource();
     this.UserVariables = new Dictionary <string, object>();
     this.exceptions    = new List <Exception>();
     this.errors        = new PSDataCollection <ErrorRecord>();
     this.AsyncResults  = new ConcurrentQueue <IAsyncResult>();
     this.SyncRoot      = new object();
 }
 internal PersistenceVersion(bool enableEncryption, bool enableCompression)
 {
     this.Tracer            = PowerShellTraceSourceFactory.GetTraceSource();
     this.syncLock          = new object();
     this.StoreVersion      = new Version(1, 0);
     this.CLRVersion        = Environment.Version;
     this.EnableEncryption  = enableEncryption;
     this.EnableCompression = enableCompression;
 }
 internal LocalRunspaceProvider(int timeoutSeconds, int maxRunspaces, PSLanguageMode?languageMode)
 {
     this._requests      = new ConcurrentQueue <LocalRunspaceAsyncResult>();
     this._callbacks     = new ConcurrentQueue <LocalRunspaceAsyncResult>();
     this._tracer        = PowerShellTraceSourceFactory.GetTraceSource();
     this._runspaceCache = new TimeBasedCache <Runspace>(timeoutSeconds);
     this._maxRunspaces  = maxRunspaces;
     this._languageMode  = languageMode;
 }
Beispiel #10
0
 internal Connection(ConnectionManager manager)
 {
     this._syncObject       = new object();
     this._instanceId       = Guid.NewGuid();
     this._tracer           = PowerShellTraceSourceFactory.GetTraceSource();
     this._structuredTracer = new Tracer();
     this._retryInterval    = 1;
     this._manager          = manager;
     this._tracer.WriteMessage("PSW Conn: Creating new connection");
 }
Beispiel #11
0
 internal WorkflowJobSourceAdapter()
 {
     this._tracer            = PowerShellTraceSourceFactory.GetTraceSource();
     this._structuredTracer  = new Tracer();
     this._jobRepository     = new WorkflowJobSourceAdapter.ContainerParentJobRepository("WorkflowJobSourceAdapterRepository");
     this._syncObject        = new object();
     this._syncRemoveChilJob = new object();
     WSManServerChannelEvents.add_ShuttingDown(new EventHandler(this.OnWSManServerShuttingDownEventRaised));
     base.Name = "PSWorkflowJob";
 }
        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));
        }
Beispiel #13
0
        static PSWorkflowValidator()
        {
            PSWorkflowValidator.Facility          = "WorkflowValidation : ";
            PSWorkflowValidator.Tracer            = PowerShellTraceSourceFactory.GetTraceSource();
            PSWorkflowValidator._structuredTracer = new Tracer();
            List <string> strs = new List <string>();

            strs.Add("DynamicActivity");
            strs.Add("DoWhile");
            strs.Add("ForEach`1");
            strs.Add("If");
            strs.Add("Parallel");
            strs.Add("ParallelForEach`1");
            strs.Add("Sequence");
            strs.Add("Switch`1");
            strs.Add("While");
            strs.Add("Assign");
            strs.Add("Assign`1");
            strs.Add("Delay");
            strs.Add("InvokeMethod");
            strs.Add("TerminateWorkflow");
            strs.Add("WriteLine");
            strs.Add("Rethrow");
            strs.Add("Throw");
            strs.Add("TryCatch");
            strs.Add("Literal`1");
            strs.Add("VisualBasicValue`1");
            strs.Add("VisualBasicReference`1");
            strs.Add("LocationReferenceValue`1");
            strs.Add("VariableValue`1");
            strs.Add("VariableReference`1");
            strs.Add("LocationReferenceReference`1");
            strs.Add("LambdaValue`1");
            strs.Add("Flowchart");
            strs.Add("FlowDecision");
            strs.Add("FlowSwitch`1");
            strs.Add("AddToCollection`1");
            strs.Add("ExistsInCollection`1");
            strs.Add("RemoveFromCollection`1");
            strs.Add("ClearCollection`1");
            PSWorkflowValidator.AllowedSystemActivities = strs;
            HashSet <string> strs1 = new HashSet <string>();

            strs1.Add("microsoft.powershell.activities");
            strs1.Add("microsoft.powershell.core.activities");
            strs1.Add("microsoft.powershell.diagnostics.activities");
            strs1.Add("microsoft.powershell.management.activities");
            strs1.Add("microsoft.powershell.security.activities");
            strs1.Add("microsoft.powershell.utility.activities");
            strs1.Add("microsoft.wsman.management.activities");
            PSWorkflowValidator.PowerShellActivitiesAssemblies = strs1;
            PSWorkflowValidator.TestMode      = false;
            PSWorkflowValidator.ObjectCounter = (long)0;
        }
Beispiel #14
0
 internal void SetJobState(JobState state, Exception reason)
 {
     using (PowerShellTraceSource source = PowerShellTraceSourceFactory.GetTraceSource())
     {
         this.AssertNotDisposed();
         bool flag = false;
         System.Management.Automation.JobStateInfo stateInfo = this.stateInfo;
         lock (this.syncObject)
         {
             this.stateInfo = new System.Management.Automation.JobStateInfo(state, reason);
             if (state == JobState.Running)
             {
                 if (!this.PSBeginTime.HasValue)
                 {
                     this.PSBeginTime = new DateTime?(DateTime.Now);
                 }
             }
             else if (this.IsFinishedState(state))
             {
                 flag = true;
                 if (!this.PSEndTime.HasValue)
                 {
                     this.PSEndTime = new DateTime?(DateTime.Now);
                 }
             }
         }
         if (flag)
         {
             this.CloseAllStreams();
         }
         try
         {
             source.WriteMessage("Job", "SetJobState", Guid.Empty, this, "Invoking StateChanged event", null);
             this.StateChanged.SafeInvoke <JobStateEventArgs>(this, new JobStateEventArgs(this.stateInfo.Clone(), stateInfo));
         }
         catch (Exception exception)
         {
             source.WriteMessage("Job", "SetJobState", Guid.Empty, this, "Some Job StateChange event handler threw an unhandled exception.", null);
             source.TraceException(exception);
             CommandProcessorBase.CheckForSevereException(exception);
         }
         if (flag)
         {
             lock (this.syncObject)
             {
                 if (this.finished != null)
                 {
                     this.finished.Set();
                 }
             }
         }
     }
 }
Beispiel #15
0
        internal PSChildJobProxy(string command, PSObject o) : base(command)
        {
            string str;

            this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
            this._syncObject = new object();
            PSJobProxy.TryGetJobPropertyValue <string>(o, "StatusMessage", out this._statusMessage);
            PSJobProxy.TryGetJobPropertyValue <string>(o, "Location", out this._location);
            PSJobProxy.TryGetJobPropertyValue <string>(o, "Name", out str);
            base.Name                = str;
            base.Output.DataAdded   += new EventHandler <DataAddedEventArgs>(this.OutputAdded);
            base.Error.DataAdded    += new EventHandler <DataAddedEventArgs>(this.ErrorAdded);
            base.Warning.DataAdded  += new EventHandler <DataAddedEventArgs>(this.WarningAdded);
            base.Verbose.DataAdded  += new EventHandler <DataAddedEventArgs>(this.VerboseAdded);
            base.Progress.DataAdded += new EventHandler <DataAddedEventArgs>(this.ProgressAdded);
            base.Debug.DataAdded    += new EventHandler <DataAddedEventArgs>(this.DebugAdded);
        }
 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();
 }
 static WorkflowRuntimeCompilation()
 {
     WorkflowRuntimeCompilation.Tracer      = PowerShellTraceSourceFactory.GetTraceSource();
     WorkflowRuntimeCompilation._syncObject = new object();
 }
Beispiel #18
0
 protected Job2(string command, string name, IList <Job> childJobs) : base(command, name, childJobs)
 {
     this._syncobject = new object();
     this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
 }
Beispiel #19
0
 protected Job2(string command, string name, Guid instanceId) : base(command, name, instanceId)
 {
     this._syncobject = new object();
     this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
 }
Beispiel #20
0
 protected Job2(string command, string name, JobIdentifier token) : base(command, name, token)
 {
     this._syncobject = new object();
     this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
 }
        public void WriteCommandDetail(string text)
        {
            PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource();

            traceSource.WriteMessage(text);
        }
Beispiel #22
0
 public ActivityInvoker()
 {
     this._syncObject = new object();
     this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
 }
        /// <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 ...
Beispiel #24
0
        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 });
        }
Beispiel #25
0
 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;
 }
Beispiel #26
0
 protected Job2(string command) : base(command)
 {
     this._syncobject = new object();
     this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
 }
Beispiel #27
0
 public PSCounterSetInstance(CounterSetRegistrarBase counterSetRegBaseObj) : base(counterSetRegBaseObj)
 {
     this._tracer = PowerShellTraceSourceFactory.GetTraceSource();
     this.CreateCounterSetInstance();
 }
Beispiel #28
0
        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);
            }
        }
Beispiel #29
0
        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));
        }
Beispiel #30
0
 protected Job2()
 {
     this._syncobject = new object();
     this._tracer     = PowerShellTraceSourceFactory.GetTraceSource();
 }