summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libcruft/initgroups.c
blob: 932fddfd6f1a5218d7471203edc285b847f6c504 (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
#include <grp.h>
#include <sys/types.h>
#include <string.h>

int initgroups(const char *user, gid_t group) {
  int n=1;
  gid_t grouplist[32];
  struct group *g;
  grouplist[0]=group;
  setgrent();
  while ((g=getgrent())) {
    char **duh=g->gr_mem;
    while (*duh) {
      if (!strcmp(*duh,user)) {
	grouplist[n]=g->gr_gid;
	if (++n>=32)
	  break;
      }
      duh++;
    }
  }
  return setgroups(n,grouplist);
}