mailing list of musl libc
 help / color / mirror / Atom feed
301824cec5ac1e973492aa3d252416faa6eb18ac blob 1774 bytes (raw)

 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
#define _GNU_SOURCE
#include "pwf.h"
#include <grp.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <byteswap.h>
#include <errno.h>
#include "nscd.h"

int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
{
	int rv, nlim, ret = -1;
	ssize_t i, n = 1;
	struct group gr;
	struct group *res;
	FILE *f;
	int swap = 0;
	int32_t resp[INITGR_LEN];
	uint32_t *nscdbuf = 0;
	char *buf = 0;
	char **mem = 0;
	size_t nmem = 0;
	size_t size;
	nlim = *ngroups;
	if (nlim >= 1) *groups++ = gid;

	f = __nscd_query(GETINITGR, user, resp, sizeof resp, &swap);
	if (!f) goto cleanup;
	if (resp[INITGRFOUND]) {
		nscdbuf = calloc(resp[INITGRNGRPS], sizeof(uint32_t));
		if (!nscdbuf) goto cleanup;
		size_t nbytes = sizeof(*nscdbuf)*resp[INITGRNGRPS];
		if (nbytes && !fread(nscdbuf, nbytes, 1, f)) {
			if (!ferror(f)) errno = EIO;
			goto cleanup;
		}
		if (swap) {
			for (i = 0; i < resp[INITGRNGRPS]; i++)
				nscdbuf[i] = bswap_32(nscdbuf[i]);
		}
	}
	fclose(f);

	f = fopen("/etc/group", "rbe");
	if (!f && errno != ENOENT && errno != ENOTDIR)
		goto cleanup;

	if (f) {
		while (!(rv = __getgrent_a(f, &gr, &buf, &size, &mem, &nmem, &res)) && res) {
			if (nscdbuf)
				for (i=0; i < resp[INITGRNGRPS]; i++) {
					if (nscdbuf[i] == gr.gr_gid) nscdbuf[i] = gid;
				}
			for (i=0; gr.gr_mem[i] && strcmp(user, gr.gr_mem[i]); i++);
			if (!gr.gr_mem[i]) continue;
			if (++n <= nlim) *groups++ = gr.gr_gid;
		}
		if (rv) {
			errno = rv;
			goto cleanup;
		}
	}
	if (nscdbuf) {
		for(i=0; i < resp[INITGRNGRPS]; i++) {
			if (nscdbuf[i] != gid)
				if(++n <= nlim) *groups++ = nscdbuf[i];
		}
	}

	ret = n > nlim ? -1 : n;
	*ngroups = n;

cleanup:
	if (f) fclose(f);
	free(nscdbuf);
	free(buf);
	free(mem);
	return ret;
}
debug log:

solving 301824ce ...
found 301824ce in https://git.vuxu.org/mirror/musl/

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ https://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git