wok-next view openbox/stuff/patches/808138_Replace-getgrent-with-getgroups.patch @ rev 20534
Clean default configure options when site script used.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Mar 30 19:31:50 2018 +0300 (2018-03-30) |
parents | |
children |
line source
1 >From e0cb404f53c9b21a521ea2f14c8cd66fdfb68ea7 Mon Sep 17 00:00:00 2001
2 From: Simon <simondobbss@gmail.com>
3 Date: Tue, 15 Dec 2015 15:46:18 +0100
4 Subject: [PATCH] Replace getgrent with getgroups. Fixes #5978.
6 ---
7 obt/paths.c | 34 +++++++++++++++++++++-------------
8 1 file changed, 21 insertions(+), 13 deletions(-)
10 diff --git a/obt/paths.c b/obt/paths.c
11 index 25cb6b0..d526936 100644
12 --- a/obt/paths.c
13 +++ b/obt/paths.c
14 @@ -108,25 +108,33 @@ static void find_uid_gid(uid_t *u, gid_t **g, guint *n)
15 const gchar *name;
16 struct group *gr;
18 + gid_t gmain;
19 + unsigned int maininc;
20 + int i;
21 +
22 *u = getuid();
23 pw = getpwuid(*u);
24 name = pw->pw_name;
26 - *g = g_new(gid_t, *n=1);
27 - (*g)[0] = getgid();
28 -
29 - while ((gr = getgrent())) {
30 - if (gr->gr_gid != (*g)[0]) { /* skip the main group */
31 - gchar **c;
32 - for (c = gr->gr_mem; *c; ++c)
33 - if (strcmp(*c, name) == 0) {
34 - *g = g_renew(gid_t, *g, ++(*n)); /* save the group */
35 - (*g)[*n-1] = gr->gr_gid;
36 - break;
37 - }
38 + gmain = getgid();
39 +
40 + *n = getgroups(0, *g);
41 + *g = g_new(gid_t, *n);
42 + *n = getgroups(*n, *g);
43 +
44 + /* Check if the effective group ID of the calling process is already
45 + included in the returned list. Add it otherwise. */
46 + maininc = 0;
47 + for (i = 0; i < *n; i++) {
48 + if ( (*g)[i] == gmain ) {
49 + maininc = 1;
50 + break;
51 }
52 }
53 - endgrent();
54 + if (!maininc) {
55 + *g = g_renew(gid_t, *g, ++(*n));
56 + (*g)[*n-1] = gmain;
57 + }
59 qsort(*g, *n, sizeof(gid_t), gid_cmp);
60 }
61 --
62 2.1.4