protected override void EndProcessing()
 {
     if (this.shellsToDisable.Count == 0)
     {
         this.shellsToDisable.Add("Microsoft.PowerShell");
     }
     base.WriteWarning(StringUtil.Format(RemotingErrorIdStrings.DcsWarningMessage, new object[0]));
     base.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.EcsScriptMessageV, "\r\nfunction Disable-PSSessionConfiguration\r\n{{\r\n[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact=\"High\")]\r\nparam(\r\n    [Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]\r\n    [System.String]\r\n    $Name,\r\n\r\n    [Parameter()]\r\n    [bool]\r\n    $Force,\r\n\r\n    [Parameter()]\r\n    [string]\r\n    $restartWinRMMessage,\r\n\r\n    [Parameter()]\r\n    [string]\r\n    $setEnabledTarget,\r\n\r\n    [Parameter()]\r\n    [string]\r\n    $setEnabledAction\r\n)\r\n    \r\n    begin\r\n    {{\r\n        $needWinRMRestart = $false\r\n        if ($force -or $pscmdlet.ShouldProcess($restartWinRMMessage))\r\n        {{\r\n            $svc = get-service winrm\r\n            if ($svc.Status -match \"Stopped\")\r\n            {{\r\n               Restart-Service winrm -force -confirm:$false\r\n            }}\r\n        }}       \r\n    }} #end of Begin block   \r\n\r\n    process\r\n    {{\r\n       Get-PSSessionConfiguration $name | % {{\r\n           \r\n           if ($_.Enabled -and ($force -or $pscmdlet.ShouldProcess($setEnabledTarget, $setEnabledAction)))\r\n           {{\r\n                Set-Item -WarningAction SilentlyContinue -Path \"WSMan:\\localhost\\Plugin\\$name\\Enabled\" -Value $false -confirm:$false\r\n                $needWinRMRestart = $true\r\n           }}\r\n       }} # end of foreach block\r\n    }} #end of process block\r\n\r\n    # restart the winrm to make the config change takes effect immediately\r\n    End\r\n    {{\r\n        if ($needWinRMRestart)\r\n        {{\r\n            Restart-Service winrm -force -confirm:$false\r\n        }}\r\n    }}\r\n}}\r\n\r\n$_ | Disable-PSSessionConfiguration -force $args[0] -whatif:$args[1] -confirm:$args[2] -restartWinRMMessage $args[3] -setEnabledTarget $args[4] -setEnabledAction $args[5]\r\n"));
     bool whatIf = false;
     bool confirm = true;
     PSSessionConfigurationCommandUtilities.CollectShouldProcessParameters(this, out whatIf, out confirm);
     string restartWinRMMessage = RemotingErrorIdStrings.RestartWinRMMessage;
     string setEnabledFalseTarget = RemotingErrorIdStrings.SetEnabledFalseTarget;
     string str3 = StringUtil.Format(RemotingErrorIdStrings.CSShouldProcessAction, "Set-Item");
     disablePluginSb.InvokeUsingCmdlet(this, true, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, this.shellsToDisable, new object[0], AutomationNull.Value, new object[] { this.force, whatIf, confirm, restartWinRMMessage, setEnabledFalseTarget, str3 });
     Tracer tracer = new Tracer();
     StringBuilder builder = new StringBuilder();
     foreach (string str4 in this.Name ?? new string[0])
     {
         builder.Append(str4);
         builder.Append(", ");
     }
     if (builder.Length > 0)
     {
         builder.Remove(builder.Length - 2, 2);
     }
     tracer.EndpointDisabled(builder.ToString(), WindowsIdentity.GetCurrent().Name);
 }
 protected override void EndProcessing()
 {
     if (this.shellsToEnable.Count == 0)
     {
         this.shellsToEnable.Add("Microsoft.PowerShell");
     }
     base.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.EcsScriptMessageV, "\r\nfunction Enable-PSSessionConfiguration\r\n{{\r\n[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact=\"High\")]\r\nparam(\r\n    [Parameter(Position=0, ValueFromPipeline=$true)]\r\n    [System.String]\r\n    $Name,\r\n\r\n    [Parameter()]\r\n    [bool]\r\n    $Force,\r\n    \r\n    [Parameter()]\r\n    [string]\r\n    $sddl,\r\n    \r\n    [Parameter()]\r\n    [bool]\r\n    $isSDDLSpecified,\r\n    \r\n    [Parameter()]\r\n    [string]\r\n    $queryForSet,\r\n    \r\n    [Parameter()]\r\n    [string]\r\n    $captionForSet,\r\n        \r\n    [Parameter()]\r\n    [string]\r\n    $queryForQC,\r\n    \r\n    [Parameter()]\r\n    [string]\r\n    $captionForQC,\r\n\r\n    [Parameter()]\r\n    [string]\r\n    $shouldProcessDescForQC,\r\n\r\n    [Parameter()]\r\n    [string]\r\n    $setEnabledTarget,\r\n\r\n    [Parameter()]\r\n    [string]\r\n    $setEnabledAction,\r\n\r\n    [Parameter()]\r\n    [bool]\r\n    $skipNetworkProfileCheck\r\n    )\r\n     \r\n    begin\r\n    {{\r\n        $needWinRMRestart = $false\r\n        if ($force -or $pscmdlet.ShouldProcess($shouldProcessDescForQC, $queryForQC, $captionForQC))\r\n        {{\r\n            # get the status of winrm before Quick Config. if it is already\r\n            # running..restart the service after Quick Config.\r\n            $svc = get-service winrm\r\n            if ($skipNetworkProfileCheck)\r\n            {{\r\n                {0} -force -SkipNetworkProfileCheck\r\n            }}\r\n            else\r\n            {{\r\n                {0} -force\r\n            }}\r\n            if ($svc.Status -match \"Running\")\r\n            {{\r\n               Restart-Service winrm -force -confirm:$false\r\n            }}\r\n        }}\r\n    }} #end of Begin block   \r\n        \r\n    process\r\n    {{\r\n       Get-PSSessionConfiguration $name | % {{\r\n\r\n          if ($_.Enabled -eq $false -and ($force -or $pscmdlet.ShouldProcess($setEnabledTarget, $setEnabledAction)))\r\n          {{\r\n             Set-Item -WarningAction SilentlyContinue -Path \"WSMan:\\localhost\\Plugin\\$name\\Enabled\" -Value $true -confirm:$false\r\n             $needWinRMRestart = $true\r\n          }}\r\n\r\n          if (!$isSDDLSpecified)\r\n          {{\r\n             $sddlTemp = $null\r\n             if ($_.psobject.members[\"SecurityDescriptorSddl\"])\r\n             {{\r\n                 $sddlTemp = $_.psobject.members[\"SecurityDescriptorSddl\"].Value\r\n             }}\r\n\r\n             $securityIdentifierToPurge = $null\r\n             # strip out Disable-Everyone DACL from the SDDL\r\n             if ($sddlTemp)\r\n             {{\r\n                # construct SID for \"EveryOne\"\r\n                [system.security.principal.wellknownsidtype]$evst = \"worldsid\"\r\n                $everyOneSID = new-object system.security.principal.securityidentifier $evst,$null\r\n                                \r\n                $sd = new-object system.security.accesscontrol.commonsecuritydescriptor $false,$false,$sddlTemp                \r\n                $sd.DiscretionaryAcl | % {{\r\n                    if (($_.acequalifier -eq \"accessdenied\") -and ($_.securityidentifier -match $everyOneSID))\r\n                    {{\r\n                       $securityIdentifierToPurge = $_.securityidentifier\r\n                    }}\r\n                }}\r\n             \r\n                if ($securityIdentifierToPurge)\r\n                {{\r\n                   $sd.discretionaryacl.purge($securityIdentifierToPurge)\r\n\r\n                   # if there is no discretionaryacl..add Builtin Administrators and Remote Management Users\r\n                   # to the DACL group as this is the default WSMan behavior\r\n                   if ($sd.discretionaryacl.count -eq 0)\r\n                   {{\r\n                      # Built-in administrators\r\n                      [system.security.principal.wellknownsidtype]$bast = \"BuiltinAdministratorsSid\"\r\n                      $basid = new-object system.security.principal.securityidentifier $bast,$null\r\n                      $sd.DiscretionaryAcl.AddAccess('Allow',$basid, 268435456, 'none', 'none')\r\n\r\n                      # Remote Management Users, Win8+ only\r\n                      if ([System.Environment]::OSVersion.Version.Major -ge 6 -and [System.Environment]::OSVersion.Version.Minor -ge 2)\r\n                      {{\r\n                          $rmSidId = new-object system.security.principal.securityidentifier \"{1}\"\r\n                          $sd.DiscretionaryAcl.AddAccess('Allow', $rmSidId, 268435456, 'none', 'none')\r\n                      }}\r\n                   }}\r\n\r\n                   $sddl = $sd.GetSddlForm(\"all\")\r\n                }}\r\n             }} # if ($sddlTemp)\r\n          }} # if (!$isSDDLSpecified) \r\n          \r\n          $qMessage = $queryForSet -f $_.name,$sddl\r\n          if (($sddl -or $isSDDLSpecified) -and ($force  -or $pscmdlet.ShouldProcess($qMessage, $captionForSet)))\r\n          {{\r\n              $null = Set-PSSessionConfiguration -Name $_.Name -SecurityDescriptorSddl $sddl -NoServiceRestart -force -WarningAction 0\r\n          }}\r\n       }} #end of Get-PSSessionConfiguration | foreach\r\n    }} # end of Process block\r\n\r\n    # restart the winrm to make the config change takes effect immediately\r\n    End\r\n    {{\r\n        if ($needWinRMRestart)\r\n        {{\r\n            Restart-Service winrm -force -confirm:$false\r\n        }}\r\n    }}\r\n}}\r\n\r\n$_ | Enable-PSSessionConfiguration -force $args[0] -sddl $args[1] -isSDDLSpecified $args[2] -queryForSet $args[3] -captionForSet $args[4] -queryForQC $args[5] -captionForQC $args[6] -whatif:$args[7] -confirm:$args[8] -shouldProcessDescForQC $args[9] -setEnabledTarget $args[10] -setEnabledAction $args[11] -skipNetworkProfileCheck $args[12]\r\n"));
     bool whatIf = false;
     bool confirm = true;
     PSSessionConfigurationCommandUtilities.CollectShouldProcessParameters(this, out whatIf, out confirm);
     string str = StringUtil.Format(RemotingErrorIdStrings.EcsWSManQCCaption, new object[0]);
     string str2 = StringUtil.Format(RemotingErrorIdStrings.EcsWSManQCQuery, "Set-WSManQuickConfig");
     string str3 = StringUtil.Format(RemotingErrorIdStrings.EcsWSManShouldProcessDesc, "Set-WSManQuickConfig");
     string str4 = StringUtil.Format(RemotingErrorIdStrings.CSShouldProcessAction, "Set-PSSessionConfiguration");
     string ecsShouldProcessTarget = RemotingErrorIdStrings.EcsShouldProcessTarget;
     string str6 = StringUtil.Format(RemotingErrorIdStrings.CSShouldProcessAction, "Set-Item");
     string setEnabledTrueTarget = RemotingErrorIdStrings.SetEnabledTrueTarget;
     enablePluginSb.InvokeUsingCmdlet(this, true, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, this.shellsToEnable, new object[0], AutomationNull.Value, new object[] { this.force, this.sddl, this.isSddlSpecified, ecsShouldProcessTarget, str4, str2, str, whatIf, confirm, str3, setEnabledTrueTarget, str6, this.skipNetworkProfileCheck });
     Tracer tracer = new Tracer();
     StringBuilder builder = new StringBuilder();
     foreach (string str8 in this.Name ?? new string[0])
     {
         builder.Append(str8);
         builder.Append(", ");
     }
     if (builder.Length > 0)
     {
         builder.Remove(builder.Length - 2, 2);
     }
     tracer.EndpointEnabled(builder.ToString(), WindowsIdentity.GetCurrent().Name);
 }
		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));
		}
		public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
		{
			Tracer tracer = new Tracer();
			tracer.Correlate();
			if (sessionConfigurationData != null)
			{
				if (senderInfo != null)
				{
					if (!string.IsNullOrEmpty(configProviderId))
					{
						if (Interlocked.CompareExchange(ref PSWorkflowSessionConfiguration._modulesLoaded, 1, 0) == 0)
						{
							try
							{
								PSWorkflowConfigurationProvider configuration = WorkflowJobSourceAdapter.GetInstance().GetPSWorkflowRuntime().Configuration;
								if (configuration != null)
								{
									configuration.Populate(sessionConfigurationData.PrivateData, configProviderId, senderInfo);
									if (sessionConfigurationData.ModulesToImport != null)
									{
										foreach (string modulesToImport in sessionConfigurationData.ModulesToImport)
										{
											PSWorkflowSessionConfiguration.InitialSessionState.ImportPSModulesFromPath(modulesToImport);
										}
									}
								}
								else
								{
									throw new InvalidOperationException("PSWorkflowConfigurationProvider is null");
								}
							}
							catch (Exception exception)
							{
								Interlocked.CompareExchange(ref PSWorkflowSessionConfiguration._modulesLoaded, 0, 1);
								throw;
							}
						}
						if (configProviderId.ToLower(CultureInfo.InvariantCulture).Equals("http://schemas.microsoft.com/powershell/microsoft.windows.servermanagerworkflows"))
						{
							PSSessionConfigurationData.IsServerManager = true;
						}
						return PSWorkflowSessionConfiguration.InitialSessionState;
					}
					else
					{
						throw new ArgumentNullException("configProviderId");
					}
				}
				else
				{
					throw new ArgumentNullException("senderInfo");
				}
			}
			else
			{
				throw new ArgumentNullException("sessionConfigurationData");
			}
		}
Beispiel #5
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;
		}
		internal PSOutOfProcessActivityController(PSWorkflowRuntime runtime) : base(runtime)
		{
			this._hostProcesses = new Collection<ActivityHostProcess>();
			this._requests = new ConcurrentQueue<ActivityInvoker>();
			this._structuredTracer = new Tracer();
			this._failedRequests = new ConcurrentQueue<ActivityInvoker>();
			if (runtime != null)
			{
				this._configuration = runtime.Configuration;
				this.InitializeActivityHostProcesses();
				return;
			}
			else
			{
				throw new ArgumentNullException("runtime");
			}
		}
Beispiel #7
0
		static PSWorkflowRuntime()
		{
			PSWorkflowRuntime.syncLock = new object();
			PSWorkflowRuntime._tracer = new Tracer();
			PSWorkflowRuntime._psPerfCountersMgrInst = PSPerfCountersMgr.Instance;
		}
		static PSWorkflowFileInstanceStore()
		{
			PSWorkflowFileInstanceStore.etwTracer = new Tracer();
			PSWorkflowFileInstanceStore.TestMode = false;
			PSWorkflowFileInstanceStore.ObjectCounter = (long)0;
			byte[] numArray = new byte[] { _PrivateImplementationDetails__8AEF7EB8_CA5E_4A0A_BDCE_FF01E6B16089_.__method0x6000694_1 };
			PSWorkflowFileInstanceStore.NullArray = numArray;
			byte[] numArray1 = new byte[1];
			numArray1[0] = 70;
			PSWorkflowFileInstanceStore.EncryptFalse = numArray1;
			PSWorkflowFileInstanceStore.MaxPersistenceStoreSizeLock = new object();
			PSWorkflowFileInstanceStore.CurrentPersistenceStoreSize = (long)0;
			PSWorkflowFileInstanceStore._firstTimeCalculatingCurrentStoreSize = true;
		}
		static PSWorkflowApplicationInstance()
		{
			PSWorkflowApplicationInstance._structuredTracer = new Tracer();
		}
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");
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sessionConfigurationData"></param>
        /// <param name="senderInfo"></param>
        /// <param name="configProviderId"></param>
        /// <returns></returns>
        public override InitialSessionState GetInitialSessionState(PSSessionConfigurationData sessionConfigurationData, PSSenderInfo senderInfo, string configProviderId)
        {
            Tracer structuredTracer = new Tracer();

            structuredTracer.Correlate();

            if (sessionConfigurationData == null)
                throw new ArgumentNullException("sessionConfigurationData");

            if (senderInfo == null)
                throw new ArgumentNullException("senderInfo");

            if (string.IsNullOrEmpty(configProviderId))
                throw new ArgumentNullException("configProviderId");

            if (Interlocked.CompareExchange(ref _modulesLoaded, ModulesLoaded, ModulesNotLoaded) == ModulesNotLoaded)
            {
                // it is sufficient if Populate() is called the first time and
                // modules are loaded once

                try
                {
                    IsWorkflowTypeEndpoint = true;

                    PSWorkflowConfigurationProvider workflowConfiguration = WorkflowJobSourceAdapter.GetInstance().GetPSWorkflowRuntime().Configuration;
                    if (workflowConfiguration == null)
                        throw new InvalidOperationException("PSWorkflowConfigurationProvider is null");

                    workflowConfiguration.Populate(sessionConfigurationData.PrivateData, configProviderId, senderInfo);

                    // now get all the modules in the specified path and import the same
                    if (sessionConfigurationData.ModulesToImport != null)
                    {
                        foreach (var module in sessionConfigurationData.ModulesToImport)
                        {
                            ModuleSpecification moduleSpec = null;
                            if (ModuleSpecification.TryParse(module, out moduleSpec))
                            {
                                var modulesToImport = new Collection<ModuleSpecification> { moduleSpec };
                                InitialSessionState.ImportPSModule(modulesToImport);
                            }
                            else
                            {
                                InitialSessionState.ImportPSModule(new[] { Environment.ExpandEnvironmentVariables(module) });
                            }
                        }
                    }

                    // Start the workflow job manager, if not started, to add an event handler for zero active sessions changed events
                    // This is required to auto shutdown the workflow type shared process when no workflow jobs have scheduled/inprogress and when no active sessions
                    WorkflowJobSourceAdapter.GetInstance().GetJobManager();
                }
                catch(Exception)
                {
                    // if there is an exception in either Populate() or Importing modules
                    // we consider that it is not loaded
                    Interlocked.CompareExchange(ref _modulesLoaded, ModulesNotLoaded, ModulesLoaded);
                    throw;
                }
            }
            
            if (configProviderId.ToLower(CultureInfo.InvariantCulture).Equals("http://schemas.microsoft.com/powershell/microsoft.windows.servermanagerworkflows"))
            {
                PSSessionConfigurationData.IsServerManager = true;
            }

            return InitialSessionState;
        }
Beispiel #12
0
		static PSWorkflowTimer()
		{
			PSWorkflowTimer.StructuredTracer = new Tracer();
		}
Beispiel #13
0
		static PSActivity()
		{
			PSActivity.PSBookmarkPrefix = "Microsoft_PowerShell_Workflow_Bookmark_";
			PSActivity.PSSuspendBookmarkPrefix = "Microsoft_PowerShell_Workflow_Bookmark_Suspend_";
			PSActivity.PSPersistBookmarkPrefix = "Microsoft_PowerShell_Workflow_Bookmark_PSPersist_";
			PSActivity._structuredTracer = new Tracer();
			HashSet<string> strs = new HashSet<string>();
			strs.Add("Verbose");
			strs.Add("Debug");
			strs.Add("ErrorAction");
			strs.Add("WarningAction");
			strs.Add("ErrorVariable");
			strs.Add("WarningVariable");
			strs.Add("OutVariable");
			strs.Add("OutBuffer");
			PSActivity._commonCommandParameters = strs;
			PSActivity.Iss = InitialSessionState.CreateDefault();
			PSActivity.ArgsTableForRunspaces = new ConcurrentDictionary<Guid, RunCommandsArguments>();
			char[] chrArray = new char[1];
			chrArray[0] = ':';
			PSActivity.Delimiter = chrArray;
			PSActivity.ArgsTable = new ConcurrentDictionary<Guid, RunCommandsArguments>();
		}
Beispiel #14
0
		static ImportWorkflowCommand()
		{
			ImportWorkflowCommand.Tracer = PowerShellTraceSourceFactory.GetTraceSource();
			ImportWorkflowCommand._structuredTracer = new Tracer();
			ImportWorkflowCommand.FunctionCache = new ConcurrentDictionary<string, ImportWorkflowCommand.FunctionDetails>(StringComparer.OrdinalIgnoreCase);
			ImportWorkflowCommand.compiledAssemblyCache = new ConcurrentDictionary<string, WorkflowRuntimeCompilation>();
		}
Beispiel #15
0
		static PSWorkflowJob()
		{
			PSWorkflowJob.StructuredTracer = new Tracer();
			PSWorkflowJob._perfCountersMgr = PSPerfCountersMgr.Instance;
		}