Skip to content

Commit

Permalink
Change %{poke:} so it writes the previous value to the xlat output bu…
Browse files Browse the repository at this point in the history
…ffer
  • Loading branch information
arr2036 committed Feb 1, 2015
1 parent 40f3f7d commit 2f6318c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/main/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,16 @@ static ssize_t xlat_poke(UNUSED void *instance, REQUEST *request,
char *buffer;
CONF_SECTION *modules;
CONF_PAIR *cp;
CONF_SECTION *cs;
CONF_PARSER const *variables;
size_t len;

rad_assert(outlen > 1);
rad_assert(request != NULL);
rad_assert(fmt != NULL);
rad_assert(out != NULL);

*out = '\0';

if (outlen < 1) return 0;

modules = cf_section_sub_find(request->root->config, "modules");
Expand Down Expand Up @@ -454,12 +457,18 @@ static ssize_t xlat_poke(UNUSED void *instance, REQUEST *request,
goto fail;
}

/*
* Copy the old value to the output buffer, that way
* tests can restore it later, if they need to.
*/
len = strlcpy(out, cf_pair_value(cp), outlen);
if (len >= outlen) out = (outlen - 1);

if (cf_pair_replace(mi->cs, cp, q) < 0) {
RDEBUG("Failed replacing pair");
goto fail;
}

cs = mi->cs;
base = mi->insthandle;
variables = mi->entry->module->config;

Expand All @@ -469,9 +478,8 @@ static ssize_t xlat_poke(UNUSED void *instance, REQUEST *request,
for (i = 0; variables[i].name != NULL; i++) {
int ret;

if (variables[i].type == PW_TYPE_SUBSECTION) {
continue;
} /* else it's a CONF_PAIR */
if (variables[i].type == PW_TYPE_SUBSECTION) continue;
/* else it's a CONF_PAIR */

/*
* Not the pair we want. Skip it.
Expand All @@ -490,18 +498,17 @@ static ssize_t xlat_poke(UNUSED void *instance, REQUEST *request,
/*
* Parse the pair we found, or a default value.
*/
ret = cf_item_parse(cs, variables[i].name, variables[i].type, data, variables[i].dflt);
ret = cf_item_parse(mi->cs, variables[i].name, variables[i].type, data, variables[i].dflt);
if (ret < 0) {
DEBUG2("Failed inserting new value into module instance data");
goto fail;
}

break; /* we found it, don't do any more */
}

talloc_free(buffer);

*out = '\0';
return 0;
return len;
}


Expand Down

0 comments on commit 2f6318c

Please sign in to comment.