Skip to content

Commit

Permalink
Fix use of talloc buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Sep 2, 2014
1 parent 5a63d34 commit cee69ff
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/modules/rlm_unix/rlm_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,24 @@ static const CONF_PARSER module_config[] = {


#ifndef HAVE_GETGRNAM_R
#define fr_getgrnam getgrnam
#define fr_getgrnam(_a, _b) getgrnam(_b)
#else
static struct group *fr_getgrnam(char const *name)
static struct group *fr_getgrnam(TALLOC_CTX *ctx, char const *name)
{
struct group *grp, my_group;
char *group_buffer;
size_t group_size = 1024;

grp = NULL;
group_buffer = talloc_array(NULL, char, group_size);
group_buffer = talloc_array(ctx, char, group_size);
while (group_buffer) {
int err;

err = getgrnam_r(name, &my_group, group_buffer, group_size, &grp);
if (err == ERANGE) {
group_size *= 2;
group_buffer = talloc_realloc(NULL, group_buffer, char, group_size);
talloc_free(group_buffer);
group_buffer = talloc_array(ctx, char, group_size);
continue;
}

Expand Down Expand Up @@ -132,7 +133,7 @@ static int groupcmp(UNUSED void *instance, REQUEST *req, UNUSED VALUE_PAIR *requ
if (!pwd)
return -1;

grp = fr_getgrnam(check->vp_strvalue);
grp = fr_getgrnam(req, check->vp_strvalue);
if (!grp)
return -1;

Expand All @@ -144,10 +145,6 @@ static int groupcmp(UNUSED void *instance, REQUEST *req, UNUSED VALUE_PAIR *requ
}
}

#ifdef HAVE_GETGRNAM_R
talloc_free(grp);
#endif

return retval;
}

Expand Down

0 comments on commit cee69ff

Please sign in to comment.