source: trunk/minix/lib/other/setgroups.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 826 bytes
Line 
1/*
2setgroups.c
3*/
4
5#include <errno.h>
6#include <unistd.h>
7#include <string.h>
8#include <grp.h>
9
10int setgroups(int ngroups, const gid_t *gidset)
11{
12 if(ngroups > 1) {
13 /* Supplementary groups not implemented */
14 errno= EINVAL;
15 return -1;
16 }
17
18 if(ngroups == 1)
19 return setgid(gidset[0]);
20
21 return 0;
22}
23
24int initgroups(const char *name, gid_t basegid)
25{
26 struct group *gr;
27 int r, found = 0;
28 if((r = setgid(basegid)) < 0)
29 return r;
30
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;
38 }
39 }
40 }
41 endgrent();
42
43 /* Because supplemental groups aren't implemented, this call
44 * should fail if the user is in any supplemental groups.
45 */
46 if(found) {
47 errno = EINVAL;
48 return -1;
49 }
50
51 return 0;
52}
53
Note: See TracBrowser for help on using the repository browser.