| 1 |
commit b29f4884e9a7637e09f93f8d53973c83a69670d9 |
| 2 |
Author: Samuel Thibault <[email protected]> |
| 3 |
Date: Sun Feb 11 21:32:24 2024 +0100 |
| 4 |
|
| 5 |
Fix testing belonging to the audio group |
| 6 |
|
| 7 |
cuserid() is limited to L_cuserid characters, which is 9. This means that |
| 8 |
users with a longer login were never seen as belonging to the group. |
| 9 |
|
| 10 |
Let us just replace with using getgroups, which allows |
| 11 |
- to actually check the current allowed groups, |
| 12 |
- to compare gids, which don't pose length limitations. |
| 13 |
|
| 14 |
Fixes #4 |
| 15 |
|
| 16 |
diff --git a/src/common.c b/src/common.c |
| 17 |
index a580153..6658c40 100644 |
| 18 |
--- a/src/common.c |
| 19 |
+++ b/src/common.c |
| 20 |
@@ -911,17 +911,18 @@ void get_list_of_sound_devices (misc_t *misc, audio_info_t *sound_devices) |
| 21 |
char *str, *orig_language; |
| 22 |
struct group *grp; |
| 23 |
FILE *p; |
| 24 |
+ int ngroups; |
| 25 |
+ |
| 26 |
+ ngroups = getgroups (0, NULL); |
| 27 |
+ gid_t groups[ngroups]; |
| 28 |
+ getgroups (ngroups, groups); |
| 29 |
|
| 30 |
grp = getgrnam ("audio"); |
| 31 |
- found = 0; |
| 32 |
- for (g = 0; grp->gr_mem[g]; g++) |
| 33 |
- { |
| 34 |
- if (strcmp (grp->gr_mem[g], cuserid (NULL)) == 0) |
| 35 |
- { |
| 36 |
- found = 1; |
| 37 |
- break; |
| 38 |
- } // if |
| 39 |
- } // for |
| 40 |
+ found = getegid () == grp->gr_gid; |
| 41 |
+ |
| 42 |
+ for (g = 0; !found && g < ngroups; g++) |
| 43 |
+ found = groups[g] == grp->gr_gid; |
| 44 |
+ |
| 45 |
if (found == 0) |
| 46 |
{ |
| 47 |
beep (); |