aboutsummaryrefslogtreecommitdiffstats
path: root/ports/darwin/guts/getgrouplist.c
blob: 85fccc9b2017890030d1130bf89aa2bdaec0d5cc (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
/* 
 * Copyright (c) 2010 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * static int
 * wrap_getgrouplist(const char *name, int basegid, int *groups, int *ngroups) {
 *	int rc = -1;
 */

	int found = 0;
	int found_group = 0;
	char buf[PSEUDO_PWD_MAX];
	struct group grp, *gbuf = &grp;

	setgrent();
	while ((rc = wrap_getgrent_r(gbuf, buf, PSEUDO_PWD_MAX, &gbuf)) == 0) {
		int i = 0;
		for (i = 0; gbuf->gr_mem[i]; ++i) {
			if (!strcmp(gbuf->gr_mem[i], name)) {
				if (found < *ngroups)
					groups[found] = gbuf->gr_gid;
				++found;
				if ((int) gbuf->gr_gid == basegid)
					found_group = 1;
			}
		}
	}
	endgrent();
	if (!found_group) {
		if (found < *ngroups)
			groups[found] = basegid;
		++found;
	}
	if (found >= *ngroups)
		rc = -1;
	else
		rc = found;
	*ngroups = found;

/*	return rc;
 * }
 */