PromiseResult ExpandPromise(EvalContext *ctx, const Promise *pp, PromiseActuator *ActOnPromise, void *param) { Rlist *lists = NULL; Rlist *scalars = NULL; Rlist *containers = NULL; Promise *pcopy = DeRefCopyPromise(ctx, pp); MapIteratorsFromRval(ctx, PromiseGetBundle(pp), (Rval) { pcopy->promiser, RVAL_TYPE_SCALAR }, &scalars, &lists, &containers); if (pcopy->promisee.item != NULL) { MapIteratorsFromRval(ctx, PromiseGetBundle(pp), pp->promisee, &scalars, &lists, &containers); } for (size_t i = 0; i < SeqLength(pcopy->conlist); i++) { Constraint *cp = SeqAt(pcopy->conlist, i); MapIteratorsFromRval(ctx, PromiseGetBundle(pp), cp->rval, &scalars, &lists, &containers); } CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), lists); CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), scalars); CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), containers); PromiseResult result = ExpandPromiseAndDo(ctx, pcopy, lists, containers, ActOnPromise, param); PromiseDestroy(pcopy); RlistDestroy(lists); RlistDestroy(scalars); RlistDestroy(containers); return result; }
void TestExpandVariables() { Promise pp = { 0 }, *pcopy; Rlist *args, *listvars = NULL, *scalarvars = NULL; Constraint *cp; FnCall *fp; strcpy(CFWORKDIR, GetWorkDir()); MapName(CFWORKDIR); /* Still have diagnostic scope */ NewScope("control_common"); printf("%d. Testing variable expansion\n", ++NR); pp.promiser = "the originator"; pp.promisee = (Rval) {"the recipient with $(two)", CF_SCALAR}; pp.classes = "proletariat"; pp.offset.line = 12; pp.audit = NULL; pp.conlist = NULL; pp.agentsubtype = "none"; pp.bundletype = "bundle_type"; pp.bundle = "test_bundle"; pp.ref = "commentary"; pp.agentsubtype = xstrdup("files"); pp.done = false; pp.next = NULL; pp.cache = NULL; pp.inode_cache = NULL; pp.this_server = NULL; pp.donep = &(pp.done); pp.conn = NULL; args = SplitStringAsRList("$(administrator)", ','); fp = NewFnCall("getuid", args); AppendConstraint(&(pp.conlist), "lval1", (Rval) {xstrdup("@(one)"), CF_SCALAR}, "lower classes1", false); AppendConstraint(&(pp.conlist), "lval2", (Rval) {xstrdup("$(four)"), CF_SCALAR}, "upper classes1", false); AppendConstraint(&(pp.conlist), "lval3", (Rval) {fp, CF_FNCALL}, "upper classes2", false); /* Now copy promise and delete */ pcopy = DeRefCopyPromise("diagnostic", &pp); MapIteratorsFromRval("diagnostic", &scalarvars, &listvars, (Rval) {pcopy->promiser, CF_SCALAR}, NULL); if (pcopy->promisee.item != NULL) { MapIteratorsFromRval("diagnostic", &scalarvars, &listvars, pp.promisee, NULL); } for (cp = pcopy->conlist; cp != NULL; cp = cp->next) { MapIteratorsFromRval("diagnostic", &scalarvars, &listvars, cp->rval, NULL); } ExpandPromiseAndDo(cf_common, "diagnostic", pcopy, scalarvars, listvars, NULL); /* No cleanup */ }
PromiseResult ExpandPromise(EvalContext *ctx, const Promise *pp, PromiseActuator *ActOnPromise, void *param) { Log(LOG_LEVEL_VERBOSE, "Evaluating promise '%s'", pp->promiser); if (!IsDefinedClass(ctx, pp->classes)) { if (LEGACY_OUTPUT) { Log(LOG_LEVEL_VERBOSE, ". . . . . . . . . . . . . . . . . . . . . . . . . . . . "); Log(LOG_LEVEL_VERBOSE, "Skipping whole next promise (%s), as context %s is not relevant", pp->promiser, pp->classes); Log(LOG_LEVEL_VERBOSE, ". . . . . . . . . . . . . . . . . . . . . . . . . . . . "); } else { Log(LOG_LEVEL_VERBOSE, "Skipping next promise '%s', as context '%s' is not relevant", pp->promiser, pp->classes); } return PROMISE_RESULT_SKIPPED; } Rlist *lists = NULL; Rlist *scalars = NULL; Rlist *containers = NULL; Promise *pcopy = DeRefCopyPromise(ctx, pp); MapIteratorsFromRval(ctx, PromiseGetBundle(pp), (Rval) { pcopy->promiser, RVAL_TYPE_SCALAR }, &scalars, &lists, &containers); if (pcopy->promisee.item != NULL) { MapIteratorsFromRval(ctx, PromiseGetBundle(pp), pp->promisee, &scalars, &lists, &containers); } for (size_t i = 0; i < SeqLength(pcopy->conlist); i++) { Constraint *cp = SeqAt(pcopy->conlist, i); MapIteratorsFromRval(ctx, PromiseGetBundle(pp), cp->rval, &scalars, &lists, &containers); } CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), lists); CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), scalars); CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), containers); PromiseResult result = ExpandPromiseAndDo(ctx, pcopy, lists, containers, ActOnPromise, param); PromiseDestroy(pcopy); RlistDestroy(lists); RlistDestroy(scalars); RlistDestroy(containers); return result; }
PromiseResult ExpandPromise(EvalContext *ctx, const Promise *pp, PromiseActuator *act_on_promise, void *param) { if (!IsDefinedClass(ctx, pp->classes)) { return PROMISE_RESULT_SKIPPED; } /* 1. Copy the promise while expanding '@' slists and body arguments * (including body inheritance). */ Promise *pcopy = DeRefCopyPromise(ctx, pp); EvalContextStackPushPromiseFrame(ctx, pcopy, true); PromiseIterator *iterctx = PromiseIteratorNew(pcopy); /* 2. Parse all strings (promiser-promisee-constraints), find all unexpanded variables, mangle them if needed (if they are namespaced/scoped), and start the iteration engine (iterctx) to iterate over slists and containers. */ MapIteratorsFromRval(ctx, iterctx, (Rval) { pcopy->promiser, RVAL_TYPE_SCALAR }); if (pcopy->promisee.item != NULL) { MapIteratorsFromRval(ctx, iterctx, pcopy->promisee); } for (size_t i = 0; i < SeqLength(pcopy->conlist); i++) { Constraint *cp = SeqAt(pcopy->conlist, i); MapIteratorsFromRval(ctx, iterctx, cp->rval); } /* 3. GO! */ PutHandleVariable(ctx, pcopy); PromiseResult result = ExpandPromiseAndDo(ctx, iterctx, act_on_promise, param); EvalContextStackPopFrame(ctx); PromiseIteratorDestroy(iterctx); PromiseDestroy(pcopy); return result; }
void ExpandPromise(EvalContext *ctx, Promise *pp, PromiseActuator *ActOnPromise, void *param) { Rlist *listvars = NULL; Rlist *scalars = NULL; Promise *pcopy; // Set a default for packages here...general defaults that need to come before //fix me wth a general function SetMissingDefaults SetAnyMissingDefaults(ctx, pp); ScopeClear("match"); /* in case we expand something expired accidentially */ EvalContextStackPushPromiseFrame(ctx, pp); pcopy = DeRefCopyPromise(ctx, pp); MapIteratorsFromRval(ctx, PromiseGetBundle(pp)->name, &listvars, &scalars, (Rval) { pcopy->promiser, RVAL_TYPE_SCALAR }); if (pcopy->promisee.item != NULL) { MapIteratorsFromRval(ctx, PromiseGetBundle(pp)->name, &listvars, &scalars, pp->promisee); } for (size_t i = 0; i < SeqLength(pcopy->conlist); i++) { Constraint *cp = SeqAt(pcopy->conlist, i); MapIteratorsFromRval(ctx, PromiseGetBundle(pp)->name, &listvars, &scalars, cp->rval); } CopyLocalizedIteratorsToThisScope(ctx, PromiseGetBundle(pp)->name, listvars); CopyLocalizedScalarsToThisScope(ctx, PromiseGetBundle(pp)->name, scalars); ScopePushThis(); ExpandPromiseAndDo(ctx, pcopy, listvars, ActOnPromise, param); ScopePopThis(); PromiseDestroy(pcopy); RlistDestroy(listvars); RlistDestroy(scalars); EvalContextStackPopFrame(ctx); }
void ExpandPromise(EvalContext *ctx, Promise *pp, PromiseActuator *ActOnPromise, void *param) { Rlist *lists = NULL; Rlist *scalars = NULL; Rlist *containers = NULL; // Set a default for packages here...general defaults that need to come before //fix me wth a general function SetMissingDefaults SetAnyMissingDefaults(ctx, pp); Promise *pcopy = DeRefCopyPromise(ctx, pp); MapIteratorsFromRval(ctx, PromiseGetBundle(pp)->name, (Rval) { pcopy->promiser, RVAL_TYPE_SCALAR }, &scalars, &lists, &containers); if (pcopy->promisee.item != NULL) { MapIteratorsFromRval(ctx, PromiseGetBundle(pp)->name, pp->promisee, &scalars, &lists, &containers); } for (size_t i = 0; i < SeqLength(pcopy->conlist); i++) { Constraint *cp = SeqAt(pcopy->conlist, i); MapIteratorsFromRval(ctx, PromiseGetBundle(pp)->name, cp->rval,&scalars, &lists, &containers); } CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), lists); CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), scalars); CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), containers); ExpandPromiseAndDo(ctx, pcopy, lists, containers, ActOnPromise, param); PromiseDestroy(pcopy); RlistDestroy(lists); RlistDestroy(scalars); RlistDestroy(containers); }