Skip to content

Commit

Permalink
Use new fr_getgid() function. Addresses #776
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Sep 2, 2014
1 parent d61c04d commit c85e234
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 52 deletions.
16 changes: 2 additions & 14 deletions src/main/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2142,23 +2142,11 @@ static int command_socket_parse_unix(CONF_SECTION *cs, rad_listen_t *this)
}

if (sock->gid_name) {
struct group *grp;
#ifdef HAVE_GETGRNAM_R
struct group my_group;
char group_buffer[1024];

if (getgrnam_r(sock->gid_name, &my_group, group_buffer, sizeof(group_buffer), &grp) != 0) {
grp = NULL;
}
#else
grp = getgrnam(sock->gid_name);
#endif
if (!grp) {
if (!fr_getgid(sock->gid_name, &sock->gid)) {
ERROR("Failed getting gid for %s: %s",
sock->gid_name, fr_syserror(errno));
sock->gid_name, fr_syserror(errno));
return -1;
}
sock->gid = grp->gr_gid;
} else {
sock->gid = -1;
}
Expand Down
13 changes: 1 addition & 12 deletions src/modules/rlm_detail/rlm_detail.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ static rlm_rcode_t CC_HINT(nonnull) detail_do(void *instance, REQUEST *request,

#ifdef HAVE_GRP_H
gid_t gid;
struct group *grp;
char *endptr;
#endif

Expand Down Expand Up @@ -379,20 +378,10 @@ static rlm_rcode_t CC_HINT(nonnull) detail_do(void *instance, REQUEST *request,
if (inst->group != NULL) {
gid = strtol(inst->group, &endptr, 10);
if (*endptr != '\0') {
#ifdef HAVE_GETGRNAM_R
struct group my_group;

if (getgrnam_r(inst->group, &my_group, buffer, sizeof(buffer), &grp) != 0) {
grp = NULL;
}
#else
grp = getgrnam(inst->group);
#endif
if (!grp) {
if (!fr_getgid(inst->group, &gid)) {
RDEBUG2("Unable to find system group '%s'", inst->group);
goto skip_group;
}
gid = grp->gr_gid;
}

if (chown(buffer, -1, gid) == -1) {
Expand Down
14 changes: 1 addition & 13 deletions src/modules/rlm_linelog/rlm_linelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ static rlm_rcode_t CC_HINT(nonnull) mod_do_linelog(void *instance, REQUEST *requ

#ifdef HAVE_GRP_H
gid_t gid;
struct group *grp;
char *endptr;
#endif

Expand Down Expand Up @@ -282,21 +281,10 @@ static rlm_rcode_t CC_HINT(nonnull) mod_do_linelog(void *instance, REQUEST *requ
if (inst->group != NULL) {
gid = strtol(inst->group, &endptr, 10);
if (*endptr != '\0') {
#ifdef HAVE_GETGRNAM_R
char group_buffer[1024];
struct group my_group;

if (getgrnam_r(inst->group, &my_group, group_buffer, sizeof(group_buffer), &grp) != 0) {
grp = NULL;
}
#else
grp = getgrnam(inst->group);
#endif
if (!grp) {
if (!fr_getgid(inst->group, &gid)) {
RDEBUG2("Unable to find system group \"%s\"", inst->group);
goto skip_group;
}
gid = grp->gr_gid;
}

if (chown(buffer, -1, gid) == -1) {
Expand Down
19 changes: 6 additions & 13 deletions src/modules/rlm_opendirectory/rlm_opendirectory.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,15 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(UNUSED void *instance, REQU
static rlm_rcode_t CC_HINT(nonnull) mod_authorize(UNUSED void *instance, REQUEST *request)
{
struct passwd *userdata = NULL;
struct group *groupdata = NULL;
int ismember = 0;
RADCLIENT *rad_client = NULL;
uuid_t uuid;
uuid_t guid_sacl;
uuid_t guid_nasgroup;
int err;
char host_ipaddr[128] = {0};
#ifdef HAVE_GETGRNAM_R
struct group my_group;
char group_buffer[1024];
#ifdef HAVE_GRP_H
gid_t gid;
#endif
#ifdef HAVE_GETPWNAM_R
struct passwd my_pwd;
Expand All @@ -368,15 +366,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authorize(UNUSED void *instance, REQUEST
/* resolve SACL */
uuid_clear(guid_sacl);

#ifdef HAVE_GETGRNAM_R
if (getgrnam_r(kRadiusSACLName, &my_group, group_buffer, sizeof(group_buffer), &groupdata) != 0) {
groupdata = NULL;
}
#else
groupdata = getgrnam(kRadiusSACLName);
#endif
if (groupdata != NULL) {
err = mbr_gid_to_uuid(groupdata->gr_gid, guid_sacl);
#ifdef HAVE_GRP_H
if (fr_getgid(kRadiusSACLName, &gid)) {
err = mbr_gid_to_uuid(gid, guid_sacl);
if (err != 0) {
ERROR("rlm_opendirectory: The group \"%s\" does not have a GUID.", kRadiusSACLName);
return RLM_MODULE_FAIL;
Expand All @@ -385,6 +377,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authorize(UNUSED void *instance, REQUEST
else {
RDEBUG("The SACL group \"%s\" does not exist on this system.", kRadiusSACLName);
}
#endif /* HAVE_GRP_H */

/* resolve client access list */
uuid_clear(guid_nasgroup);
Expand Down

0 comments on commit c85e234

Please sign in to comment.