summaryrefslogtreecommitdiff
path: root/sysutils/accountsservice/patches/patch-src_util.c
blob: bba4d1cfe52fa1b30cd34449827a07b9373382dd (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
$NetBSD: patch-src_util.c,v 1.1 2018/06/26 09:54:30 jperkin Exp $

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

--- src/util.c.orig	2013-10-15 20:25:19.000000000 +0000
+++ src/util.c
@@ -259,6 +259,46 @@ spawn_with_login_uid (GDBusMethodInvocat
         return ret;
 }
 
+#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
+
 gint
 get_user_groups (const gchar  *user,
                  gid_t         group,