summaryrefslogtreecommitdiff
path: root/security/polkit/patches/patch-src_polkitbackend_polkitbackendjsauthority.cpp
blob: 8eabd20ce92ae2596df51b7c16a0d981ab206a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$NetBSD: patch-src_polkitbackend_polkitbackendjsauthority.cpp,v 1.2 2019/03/14 10:15:19 jperkin Exp $

Provide getgrouplist for SunOS.  This is available in newer Solaris,
so if that becomes a problem we'll need to add a configure test.

--- src/polkitbackend/polkitbackendjsauthority.cpp.orig	2018-04-03 20:57:57.000000000 +0000
+++ src/polkitbackend/polkitbackendjsauthority.cpp
@@ -55,6 +55,46 @@
 #error "This code is not safe in SpiderMonkey exact stack rooting configurations"
 #endif
 
+#ifdef __sun
+int
+getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
+{
+	const struct group *grp;
+	int i, maxgroups, ngroups, ret;
+
+	ret = 0;
+	ngroups = 0;
+	maxgroups = *grpcnt;
+	groups ? groups[ngroups++] = agroup : ngroups++;
+	if (maxgroups > 1)
+		groups ? groups[ngroups++] = agroup : ngroups++;
+	setgrent();
+	while ((grp = getgrent()) != NULL) {
+		if (groups) {
+			for (i = 0; i < ngroups; i++) {
+				if (grp->gr_gid == groups[i])
+					goto skip;
+			}
+		}
+		for (i = 0; grp->gr_mem[i]; i++) {
+			if (!strcmp(grp->gr_mem[i], uname)) {
+				if (ngroups >= maxgroups) {
+					ret = -1;
+					break;
+				}
+				groups ? groups[ngroups++] = grp->gr_gid : ngroups++;
+				break;
+			}
+		}
+skip:
+		;
+	}
+	endgrent();
+	*grpcnt = ngroups;
+	return (ret);
+}
+#endif
+
 /**
  * SECTION:polkitbackendjsauthority
  * @title: PolkitBackendJsAuthority
@@ -813,7 +853,11 @@ subject_to_jsval (PolkitBackendJsAuthori
 
       if (getgrouplist (passwd->pw_name,
                         passwd->pw_gid,
+#ifdef __APPLE__
+                        (int *)gids,
+#else
                         gids,
+#endif
                         &num_gids) < 0)
         {
           g_warning ("Error looking up groups for uid %d: %m", (gint) uid);