Skip to content

Commit

Permalink
Fix testing belonging to the audio group
Browse files Browse the repository at this point in the history
cuserid() is limited to L_cuserid characters, which is 9.  This means that
users with a longer login were never seen as belonging to the group.

Let us just replace with using getgroups, which allows
- to actually check the current allowed groups,
- to compare gids, which don't pose length limitations.

Fixes #4
  • Loading branch information
sthibaul committed Feb 11, 2024
1 parent 33441a8 commit 91e6804
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,17 +925,18 @@ void get_list_of_sound_devices (misc_t *misc, audio_info_t *sound_devices)
char *str;
struct group *grp;
FILE *p;
int ngroups;

ngroups = getgroups (0, NULL);
gid_t groups[ngroups];
getgroups (ngroups, groups);

grp = getgrnam ("audio");
found = 0;
for (g = 0; grp->gr_mem[g]; g++)
{
if (strcmp (grp->gr_mem[g], cuserid (NULL)) == 0)
{
found = 1;
break;
} // if
} // for
found = getegid () == grp->gr_gid;

for (g = 0; !found && g < ngroups; g++)
found = groups[g] == grp->gr_gid;

if (found == 0)
{
beep ();
Expand Down

0 comments on commit 91e6804

Please sign in to comment.