Exemplo n.º 1
0
        HandlerResult ExecuteHandlerProcess_(SecurityContext parentSecurityContext, ActionItem a, Dictionary <string, string> dynamicData, bool dryRun = false)
        {
            HandlerResult returnResult = HandlerResult.Emtpy;

            string parms = ResolveConfigAndParameters(a, dynamicData);

            IHandlerRuntime rt = CreateHandlerRuntime(a.Name, a.Handler);

            rt.Progress += rt_Progress;

            if (!WantsStopOrPause())
            {
                SecurityContext sc = a.HasRunAs ? a.RunAs : parentSecurityContext;
                sc?.Impersonate();
                HandlerResult r = rt.Execute(parms, dryRun);
                sc?.Undo();

                if (r.Status > returnResult.Status)
                {
                    returnResult = r;
                }
            }

            return(returnResult);
        }
Exemplo n.º 2
0
        ExecuteResult ExecuteHandlerProcessInProc(SecurityContext parentSecurityContext, ActionItem a,
                                                  Dictionary <string, string> dynamicData, object parentExitData, bool dryRun = false)
        {
            try
            {
                //string parms = ResolveConfigAndParameters( a, dynamicData );
                string parms = a.Parameters.GetSerializedValues(Crypto, out string safeSerializedValues);

                IHandlerRuntime rt = CreateHandlerRuntime(a);
                rt.Progress   += rt_Progress;
                rt.LogMessage += rt_LogMessage;

                if (!WantsStopOrPause())
                {
                    a.IngestParentSecurityContext(parentSecurityContext);
                    SecurityContext sc = a.RunAs; //just an alias
                    sc?.Crypto?.InheritSettingsIfRequired(Crypto);

                    HandlerStartInfo startInfo = new HandlerStartInfo(StartInfo)
                    {
                        Parameters     = parms,
                        IsDryRun       = dryRun,
                        PlanInstanceId = InstanceId,
                        InstanceId     = a.InstanceId,
                        ParentExitData = parentExitData,
                        RunAs          = sc,
                        Crypto         = a.Parameters?.Crypto
                    };
                    a.Handler.StartInfo = new HandlerStartInfoData(startInfo);

                    sc?.Impersonate(Crypto);

                    a.Result = rt.Execute(startInfo);

                    a.Handler.StartInfo.Parameters = safeSerializedValues; //avoids serializing decrypted values to the History Plan (bug #93)
                    a.Result.BranchStatus          = a.Result.Status;
                    a.Result.SecurityContext       = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

                    SaveExitDataAs(a);

                    sc?.Undo();
                }

                return(a.Result);
            }
            catch (Exception ex)
            {
                WriteUnhandledActionException(a, ex);
                return(new ExecuteResult()
                {
                    Status = StatusType.Failed, ExitData = ex.Message
                });
            }
        }
Exemplo n.º 3
0
        public ExecuteResult ExecuteHandlerProcess_SingleAction(ActionItem a, Dictionary <string, string> dynamicData, string parentExitData, bool dryRun = false)
        {
            ExecuteResult returnResult = new ExecuteResult();

            ResolveConfigAndParameters(a, dynamicData, parentExitData);

            IHandlerRuntime rt = CreateHandlerRuntime(a);

            rt.Progress   += rt_Progress;
            rt.LogMessage += rt_LogMessage;

            if (!WantsStopOrPause())
            {
                try
                {
                    HandlerStartInfo startInfo = new HandlerStartInfo(StartInfo)
                    {
                        Parameters     = a.Parameters.GetSerializedValues(Crypto),
                        IsDryRun       = dryRun,
                        PlanInstanceId = InstanceId,
                        InstanceId     = a.InstanceId,
                        ParentExitData = parentExitData
                    };
                    a.RunAs?.Impersonate(Crypto);
                    ExecuteResult r = rt.Execute(startInfo);

                    SaveExitDataAs(a);

                    a.RunAs?.Undo();

                    if (r.Status > returnResult.Status)
                    {
                        returnResult = r;
                    }
                }
                catch (Exception ex)
                {
                    WriteUnhandledActionException(a, ex);
                    returnResult = new ExecuteResult()
                    {
                        Status = StatusType.Failed
                    };
                }
            }

            return(returnResult);
        }
Exemplo n.º 4
0
        HandlerResult ProcessRecursive(List <ActionItem> actions, HandlerResult result, Dictionary <string, string> dynamicData, bool dryRun = false)
        {
            if (CheckStopOrPause())
            {
                return(result);
            }

            HandlerResult            returnResult = HandlerResult.Emtpy;
            IEnumerable <ActionItem> actionList   = actions.Where(a => a.ExecuteCase == result.Status);

            foreach (ActionItem a in actionList)
            {
                if (CheckStopOrPause())
                {
                    break;
                }

                string parms = ResolveConfigAndParameters(a, dynamicData);

                IHandlerRuntime rt = CreateHandlerRuntime(a.Name, a.Handler);
                rt.Progress += rt_Progress;

                if (CheckStopOrPause())
                {
                    break;
                }
                HandlerResult r = rt.Execute(parms, dryRun);

                if (r.Status > returnResult.Status)
                {
                    returnResult = r;
                }

                if (a.HasActions)
                {
                    r = ProcessRecursive(a.Actions, r, dynamicData, dryRun);
                    if (r.Status > returnResult.Status)
                    {
                        returnResult = r;
                    }
                }
            }

            return(returnResult);
        }