Skip to content

Commit

Permalink
use nesting when creating SQL pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Sep 18, 2023
1 parent eefb31a commit 4af8179
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/modules/rlm_sql/rlm_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static int _sql_map_proc_get_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
fr_pair_t *vp;
char const *value = uctx;

vp = fr_pair_afrom_da(ctx, tmpl_attr_tail_da(map->lhs));
vp = fr_pair_afrom_da_nested(ctx, out, tmpl_attr_tail_da(map->lhs));
if (!vp) return -1;

/*
Expand All @@ -357,14 +357,10 @@ static int _sql_map_proc_get_value(TALLOC_CTX *ctx, fr_pair_list_t *out,
*/
if (fr_pair_value_from_str(vp, value, strlen(value), NULL, true) < 0) {
RPEDEBUG("Failed parsing value \"%pV\" for attribute %s",
fr_box_strvalue_buffer(value), tmpl_attr_tail_da(map->lhs)->name);
talloc_free(vp);

fr_box_strvalue_buffer(value), vp->da->name);
return -1;
}

fr_pair_append(out, vp);

return 0;
}

Expand Down
13 changes: 5 additions & 8 deletions src/modules/rlm_sql/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ static int sql_pair_afrom_row(TALLOC_CTX *ctx, request_t *request, fr_pair_list_

my_list = &(*relative_vp)->vp_group;
my_ctx = *relative_vp;

MEM(vp = fr_pair_afrom_da(my_ctx, da));
fr_pair_append(my_list, vp);
} else {
/*
* Search in our local dictionary
Expand All @@ -231,9 +234,10 @@ static int sql_pair_afrom_row(TALLOC_CTX *ctx, request_t *request, fr_pair_list_

my_list = out;
my_ctx = ctx;

MEM(vp = fr_pair_afrom_da_nested(my_ctx, my_list, da));
}

MEM(vp = fr_pair_afrom_da(my_ctx, da));
vp->op = op;

if ((vp->vp_type == FR_TYPE_TLV) && !*value) {
Expand All @@ -248,17 +252,10 @@ static int sql_pair_afrom_row(TALLOC_CTX *ctx, request_t *request, fr_pair_list_
} else {
if (fr_pair_value_from_str(vp, value, strlen(value), NULL, true) < 0) {
RPEDEBUG("Error parsing value");

talloc_free(vp);
return -1;
}
}

/*
* Add the pair into the packet
*/
fr_pair_append(my_list, vp);

/*
* Update the relative vp.
*/
Expand Down

0 comments on commit 4af8179

Please sign in to comment.