Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cf-agent/cf-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ static void KeepControlPromises(EvalContext *ctx, const Policy *policy, GenericA

VarRef *ref = VarRefParseFromScope(cp->lval, "control_agent");
DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

/* If var not found */
Expand Down Expand Up @@ -1831,7 +1831,7 @@ static PromiseResult DefaultVarPromise(EvalContext *ctx, const Promise *pp)
const void *value = NULL;
{
VarRef *ref = VarRefParseFromScope(pp->promiser, "this");
value = EvalContextVariableGet(ctx, ref, &value_type);
value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);
}

Expand Down Expand Up @@ -1891,7 +1891,7 @@ static void LogVariableValue(const EvalContext *ctx, const Promise *pp)
char *out = NULL;

DataType type;
const void *var = EvalContextVariableGet(ctx, ref, &type);
const void *var = EvalContextVariableGetPlaintext(ctx, ref, &type);
switch (type)
{
case CF_DATA_TYPE_INT:
Expand Down
2 changes: 1 addition & 1 deletion cf-agent/verify_packages.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ static PromiseResult HandleOldPackagePromiseType(EvalContext *ctx, const Promise
{
const char *reserved = reserved_vars[c];
VarRef *var_ref = VarRefParseFromScope(reserved, "this");
if (EvalContextVariableGet(ctx, var_ref, NULL))
if (EvalContextVariableGetPlaintext(ctx, var_ref, NULL))
{
Log(LOG_LEVEL_WARNING, "$(%s) variable has a special meaning in packages promises. "
"Things may not work as expected if it is already defined.", reserved);
Expand Down
2 changes: 1 addition & 1 deletion cf-execd/exec-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ ExecConfig *ExecConfigNew(bool scheduled_run, const EvalContext *ctx, const Poli

VarRef *ref = VarRefParseFromScope(cp->lval, "control_executor");
DataType t;
const void *value = EvalContextVariableGet(ctx, ref, &t);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &t);
VarRefDestroy(ref);

if (t == CF_DATA_TYPE_NONE)
Expand Down
2 changes: 1 addition & 1 deletion cf-execd/execd-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ExecdConfig *ExecdConfigNew(const EvalContext *ctx, const Policy *policy)

VarRef *ref = VarRefParseFromScope(cp->lval, "control_executor");
DataType t;
const void *value = EvalContextVariableGet(ctx, ref, &t);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &t);
VarRefDestroy(ref);

if (t == CF_DATA_TYPE_NONE)
Expand Down
2 changes: 1 addition & 1 deletion cf-monitord/cf-monitord.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static void KeepPromises(EvalContext *ctx, const Policy *policy)
}

VarRef *ref = VarRefParseFromScope(cp->lval, "control_monitor");
const void *value = EvalContextVariableGet(ctx, ref, NULL);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, NULL);
VarRefDestroy(ref);
if (!value)
{
Expand Down
2 changes: 1 addition & 1 deletion cf-runagent/cf-runagent.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ static void KeepControlPromises(EvalContext *ctx, const Policy *policy)

VarRef *ref = VarRefParseFromScope(cp->lval, "control_runagent");
DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

/* If var not found, or if it's an empty list. */
Expand Down
2 changes: 1 addition & 1 deletion cf-serverd/server_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ static void KeepControlPromises(EvalContext *ctx, const Policy *policy, GenericA

VarRef *ref = VarRefParseFromScope(cp->lval, "control_server");
DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

if (unresolved_vars != NULL)
Expand Down
7 changes: 3 additions & 4 deletions libenv/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3893,8 +3893,7 @@ static char *FindNextInteger(char *str, char **num)

static void SysOsVersionMajor(EvalContext *ctx)
{
const char *const_flavor = EvalContextVariableGetSpecialString(
ctx, SPECIAL_SCOPE_SYS, "flavor");
const char *const_flavor = EvalContextVariableGetSpecialString(ctx, SPECIAL_SCOPE_SYS, "flavor", true);
char *flavor = SafeStringDuplicate(const_flavor);

char *major;
Expand Down Expand Up @@ -3939,7 +3938,7 @@ static bool SetOsVersionMinorFromOSRelease(EvalContext *ctx)
{

DataType type_out;
const JsonElement *os_release = EvalContextVariableGetSpecial(ctx, SPECIAL_SCOPE_SYS, "os_release", &type_out);
const JsonElement *os_release = EvalContextVariableGetSpecialPlaintext(ctx, SPECIAL_SCOPE_SYS, "os_release", &type_out);

if (os_release == NULL)
{
Expand Down Expand Up @@ -4034,7 +4033,7 @@ void DetectEnvironment(EvalContext *ctx)
static void SysPolicyReleaseId(EvalContext *ctx, Policy *policy)
{
DataType type;
const char *entry_dirname = EvalContextVariableGetSpecial(ctx, SPECIAL_SCOPE_SYS, "policy_entry_dirname", &type);
const char *entry_dirname = EvalContextVariableGetSpecialPlaintext(ctx, SPECIAL_SCOPE_SYS, "policy_entry_dirname", &type);
if (entry_dirname == NULL || policy == NULL)
{
return;
Expand Down
46 changes: 39 additions & 7 deletions libpromises/eval_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -2234,14 +2234,29 @@ bool EvalContextVariablePutSpecialTagsSetWithComment(EvalContext *ctx, SpecialSc
}

const void *EvalContextVariableGetSpecial(
const EvalContext *const ctx,
const SpecialScope scope,
const char *const varname,
DataType *const type_out,
bool get_secret)
{
VarRef *const ref = VarRefParseFromScope(
varname, SpecialScopeToString(scope));
const void *const result = EvalContextVariableGet(ctx, ref, type_out, get_secret);
VarRefDestroy(ref);

return result;
}

const void *EvalContextVariableGetSpecialPlaintext(
const EvalContext *const ctx,
const SpecialScope scope,
const char *const varname,
DataType *const type_out)
{
VarRef *const ref = VarRefParseFromScope(
varname, SpecialScopeToString(scope));
const void *const result = EvalContextVariableGet(ctx, ref, type_out);
const void *const result = EvalContextVariableGet(ctx, ref, type_out, true);
VarRefDestroy(ref);

return result;
Expand All @@ -2254,11 +2269,12 @@ const void *EvalContextVariableGetSpecial(
const char *EvalContextVariableGetSpecialString(
const EvalContext *const ctx,
const SpecialScope scope,
const char *const varname)
const char *const varname,
bool get_secret)
{
DataType type_out;
const void *const result = EvalContextVariableGetSpecial(
ctx, scope, varname, &type_out);
ctx, scope, varname, &type_out, get_secret);
assert(type_out == CF_DATA_TYPE_STRING); // Programming error if not string
return (type_out == CF_DATA_TYPE_STRING) ? result : NULL;
}
Expand Down Expand Up @@ -2660,14 +2676,14 @@ static Variable *VariableResolve(const EvalContext *ctx, const VarRef *ref)
* list is empty. To check if the variable didn't resolve, check if
* #type_out was set to CF_DATA_TYPE_NONE.
*/
const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *ref, DataType *type_out)
const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *ref, DataType *type_out, bool get_secret)
{
Variable *var = VariableResolve(ctx, ref);
if (var)
{
const VarRef *var_ref = VariableGetRef(var);
DataType var_type = VariableGetType(var);
Rval var_rval = VariableGetRval(var, true);
Rval var_rval = VariableGetRval(var, get_secret);

if (var_ref->num_indices == 0 &&
ref->num_indices > 0 &&
Expand All @@ -2688,7 +2704,18 @@ const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *ref, Da
{
if (type_out)
{
*type_out = var_type;
/* When a secret is redacted (get_secret=false + secret variable),
* VariableGetRval returns a scalar sentinel "************".
* Report the actual returned type (string) to avoid type confusion
* in callers that switch on the reported type (e.g., VarRefValueToJson). */
if (!get_secret && VariableIsSecret(var))
{
*type_out = CF_DATA_TYPE_STRING;
}
else
{
*type_out = var_type;
}
}
return var_rval.item;
}
Expand All @@ -2701,6 +2728,11 @@ const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *ref, Da
return NULL;
}

const void *EvalContextVariableGetPlaintext(const EvalContext *ctx, const VarRef *ref, DataType *type_out)
{
return EvalContextVariableGet(ctx, ref, type_out, true);
}

const Promise *EvalContextVariablePromiseGet(const EvalContext *ctx, const VarRef *ref)
{
Variable *var = VariableResolve(ctx, ref);
Expand Down Expand Up @@ -2755,7 +2787,7 @@ const void *EvalContextVariableControlCommonGet(const EvalContext *ctx, CommonCo
assert(lval >= 0 && lval < COMMON_CONTROL_MAX);

VarRef *ref = VarRefParseFromScope(CFG_CONTROLBODY[lval].lval, "control_common");
const void *ret = EvalContextVariableGet(ctx, ref, NULL);
const void *ret = EvalContextVariableGetPlaintext(ctx, ref, NULL);
VarRefDestroy(ref);
return ret;
}
Expand Down
8 changes: 5 additions & 3 deletions libpromises/eval_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ bool EvalContextVariablePutSpecialTagsSetWithComment(EvalContext *ctx, SpecialSc
const char *lval, const void *value,
DataType type, StringSet *tags,
const char *comment);
const void *EvalContextVariableGetSpecial(const EvalContext *ctx, const SpecialScope scope, const char *varname, DataType *type_out);
const char *EvalContextVariableGetSpecialString(const EvalContext *ctx, const SpecialScope scope, const char *varname);
const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *ref, DataType *type_out);
const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *ref, DataType *type_out, bool get_secret);
const void *EvalContextVariableGetPlaintext(const EvalContext *ctx, const VarRef *ref, DataType *type_out);
const void *EvalContextVariableGetSpecial(const EvalContext *ctx, const SpecialScope scope, const char *varname, DataType *type_out, bool get_secret);
const char *EvalContextVariableGetSpecialString(const EvalContext *ctx, const SpecialScope scope, const char *varname, bool get_secret);
const void *EvalContextVariableGetSpecialPlaintext(const EvalContext *ctx, const SpecialScope scope, const char *varname, DataType *type_out);
const Promise *EvalContextVariablePromiseGet(const EvalContext *ctx, const VarRef *ref);
bool EvalContextVariableRemoveSpecial(const EvalContext *ctx, SpecialScope scope, const char *lval);
bool EvalContextVariableRemove(const EvalContext *ctx, const VarRef *ref);
Expand Down
14 changes: 7 additions & 7 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static JsonElement* VarRefValueToJson(const EvalContext *ctx, const FnCall *fp,
assert(ref);

DataType value_type = CF_DATA_TYPE_NONE;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
bool want_type = true;

// Convenience storage for the name of the function, since fp can be NULL
Expand Down Expand Up @@ -2327,7 +2327,7 @@ static FnCallResult FnCallBundlesMatching(EvalContext *ctx, const Policy *policy
VarRef *ref = VarRefParseFromBundle("tags", bp);
VarRefSetMeta(ref, true);
DataType type;
const void *bundle_tags = EvalContextVariableGet(ctx, ref, &type);
const void *bundle_tags = EvalContextVariableGetPlaintext(ctx, ref, &type);
VarRefDestroy(ref);

bool found = false; // case where tag_args are given and the bundle has no tags
Expand Down Expand Up @@ -3695,7 +3695,7 @@ static FnCallResult FnCallGetIndices(EvalContext *ctx, ARG_UNUSED const Policy *
{
VarRef *ref = ResolveAndQualifyVarName(fp, name_str);
DataType type;
EvalContextVariableGet(ctx, ref, &type);
EvalContextVariableGetPlaintext(ctx, ref, &type);

/* A variable holding a data container. */
if (DataTypeToRvalType(type) == RVAL_TYPE_CONTAINER || DataTypeToRvalType(type) == RVAL_TYPE_LIST)
Expand Down Expand Up @@ -4852,7 +4852,7 @@ static FnCallResult FnCallSelectServers(EvalContext *ctx,

VarRef *ref = VarRefParse(naked);
DataType value_type;
const Rlist *hostnameip = EvalContextVariableGet(ctx, ref, &value_type);
const Rlist *hostnameip = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
if (value_type == CF_DATA_TYPE_NONE)
{
Log(LOG_LEVEL_VERBOSE,
Expand Down Expand Up @@ -5933,7 +5933,7 @@ static char *DataTypeStringFromVarName(EvalContext *ctx, const char *var_name, b

VarRef *const var_ref = VarRefParse(var_name);
DataType type;
const void *value = EvalContextVariableGet(ctx, var_ref, &type);
const void *value = EvalContextVariableGetPlaintext(ctx, var_ref, &type);
VarRefDestroy(var_ref);

const char *const type_str =
Expand Down Expand Up @@ -6229,7 +6229,7 @@ static bool CanFormatAsStringList(EvalContext *ctx, const Rlist *arg, const Rlis
const char* const varname = RlistScalarValue(arg);
VarRef *ref = VarRefParse(varname);
DataType type;
*out = EvalContextVariableGet(ctx, ref, &type);
*out = EvalContextVariableGetPlaintext(ctx, ref, &type);
VarRefDestroy(ref);

return type == CF_DATA_TYPE_STRING_LIST;
Expand Down Expand Up @@ -6615,7 +6615,7 @@ static FnCallResult FnCallIsVariable(EvalContext *ctx, ARG_UNUSED const Policy *
{
VarRef *ref = VarRefParse(lval);
DataType value_type;
EvalContextVariableGet(ctx, ref, &value_type);
EvalContextVariableGetPlaintext(ctx, ref, &value_type);
if (value_type != CF_DATA_TYPE_NONE)
{
found = true;
Expand Down
6 changes: 3 additions & 3 deletions libpromises/expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static Rval ExpandListEntry(const EvalContext *ctx,
VarRef *ref = VarRefParseFromScope(naked, scope);

DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

if (value_type != CF_DATA_TYPE_NONE) /* variable found? */
Expand Down Expand Up @@ -567,7 +567,7 @@ char *ExpandScalar(const EvalContext *ctx, const char *ns, const char *scope,
BufferData(current_item),
ns, scope, CF_NS, '.');
DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

switch (DataTypeToRvalType(value_type))
Expand Down Expand Up @@ -639,7 +639,7 @@ Rval EvaluateFinalRval(EvalContext *ctx, const Policy *policy,
{
VarRef *ref = VarRefParseFromScope(naked, scope);
DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

if (DataTypeToRvalType(value_type) == RVAL_TYPE_LIST)
Expand Down
6 changes: 3 additions & 3 deletions libpromises/iteration.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static const void *IterVariableGet(const PromiseIterator *iterctx,
VarRef *ref =
VarRefParseFromNamespaceAndScope(varname, bundle->ns, bundle->name,
CF_MANGLED_NS, CF_MANGLED_SCOPE);
value = EvalContextVariableGet(evalctx, ref, type);
value = EvalContextVariableGetPlaintext(evalctx, ref, type);
VarRefDestroy(ref);

if (*type == CF_DATA_TYPE_NONE) /* did not resolve */
Expand All @@ -383,7 +383,7 @@ static const void *IterVariableGet(const PromiseIterator *iterctx,
* variable that is not an iterable, so it was not mangled in
* ProcessVar(). */
VarRef *ref2 = VarRefParse(varname);
value = EvalContextVariableGet(evalctx, ref2, type);
value = EvalContextVariableGetPlaintext(evalctx, ref2, type);
VarRefDestroy(ref2);
}
}
Expand Down Expand Up @@ -445,7 +445,7 @@ static bool ShouldAddVariableAsIterationWheel(
VarRef *ref = VarRefParseFromBundle(varname,
PromiseGetBundle(iterctx->pp));
DataType t;
ARG_UNUSED const void *value = EvalContextVariableGet(evalctx, ref, &t);
ARG_UNUSED const void *value = EvalContextVariableGetPlaintext(evalctx, ref, &t);
VarRefDestroy(ref);

size_t dollar_paren = FindDollarParen(varname, varname_len);
Expand Down
4 changes: 2 additions & 2 deletions libpromises/mod_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <string_lib.h> // StringStartsWith()
#include <string_sequence.h> // SeqStrginFromString()
#include <policy.h> // Promise
#include <eval_context.h> // cfPS(), EvalContextVariableGet()
#include <eval_context.h> // cfPS(), EvalContextVariableGetPlaintext()
#include <attributes.h> // GetClassContextAttributes(), IsClassesBodyConstraint()
#include <expand.h> // ExpandScalar()
#include <var_expressions.h> // StringContainsUnresolved(), StringIsBareNonScalarRef()
Expand Down Expand Up @@ -685,7 +685,7 @@ static inline bool TryToGetContainerFromScalarRef(const EvalContext *ctx, const
VarRef *ref = VarRefParse(var_ref_str);

DataType type = CF_DATA_TYPE_NONE;
const void *val = EvalContextVariableGet(ctx, ref, &type);
const void *val = EvalContextVariableGetPlaintext(ctx, ref, &type);
free(var_ref_str);
VarRefDestroy(ref);

Expand Down
2 changes: 1 addition & 1 deletion libpromises/rlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ void RlistFlatten(EvalContext *ctx, Rlist **list)

VarRef *ref = VarRefParse(naked);
DataType value_type;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
const void *value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);

if (value_type == CF_DATA_TYPE_NONE)
Expand Down
4 changes: 2 additions & 2 deletions libpromises/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ void ScopeAugment(EvalContext *ctx, const Bundle *bp, const Promise *pp, const R
if (pbp != NULL)
{
VarRef *ref = VarRefParseFromBundle(naked, pbp);
value = EvalContextVariableGet(ctx, ref, &value_type);
value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);
}
else
{
VarRef *ref = VarRefParseFromBundle(naked, bp);
value = EvalContextVariableGet(ctx, ref, &value_type);
value = EvalContextVariableGetPlaintext(ctx, ref, &value_type);
VarRefDestroy(ref);
}

Expand Down
2 changes: 1 addition & 1 deletion libpromises/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ Demand this syntax to work around
if (!IsExpandable(BufferData(inner_value)))
{
VarRef *ref = VarRefParse(BufferData(inner_value));
EvalContextVariableGet(ctx, ref, &dtype);
EvalContextVariableGetPlaintext(ctx, ref, &dtype);
VarRefDestroy(ref);

if (DataTypeToRvalType(dtype) == RVAL_TYPE_LIST)
Expand Down
Loading
Loading