For /dev/mem, map in memory to be copied to memory's own address space
[minix3.git] / lib / other / setgroups.c
blob25107ffe46f409e8ab6edcba0d721878c4621387
1 /*
2 setgroups.c
3 */
5 #include <errno.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include <grp.h>
10 int setgroups(int ngroups, const gid_t *gidset)
12 if(ngroups > 1) {
13 /* Supplementary groups not implemented */
14 errno= EINVAL;
15 return -1;
18 if(ngroups == 1)
19 return setgid(gidset[0]);
21 return 0;
24 int initgroups(const char *name, gid_t basegid)
26 struct group *gr;
27 int r, found = 0;
28 if((r = setgid(basegid)) < 0)
29 return r;
31 setgrent();
32 while (!found && (gr = getgrent()) != NULL) {
33 char **mem;
34 for(mem = gr->gr_mem; mem && *mem; mem++) {
35 if(!strcmp(name, *mem)) {
36 found = 1;
37 break;
41 endgrent();
43 /* Because supplemental groups aren't implemented, this call
44 * should fail if the user is in any supplemental groups.
46 if(found) {
47 errno = EINVAL;
48 return -1;
51 return 0;