ms_fnmatch test program
[tridge/junkcode.git] / maxgroups.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <grp.h>
5 #include <pwd.h>
6 #include <grp.h>
7 #include <sys/types.h>
8
9
10 static int trygroups(int n)
11 {
12         gid_t *gids;
13         int i;
14
15         gids = malloc(sizeof(gid_t) * n);
16         for (i=0;i<n;i++) {
17                 gids[i] = i;
18         }
19         if (setgroups(n, gids) != 0) {
20                 free(gids);
21                 return -1;
22         }
23
24         memset(gids, 0, sizeof(gid_t) * n);
25
26         if (getgroups(n, gids) != n) {
27                 free(gids);
28                 return -1;
29         }
30
31         free(gids);
32         return 0;
33 }
34
35
36 int main(int argc, char *argv[])
37 {
38         int i;
39         
40         if (geteuid() != 0) {
41                 printf("You must run this as root\n");
42                 exit(1);
43         }
44
45
46         for (i=0;i<1000000;i++) {
47                 if (trygroups(i) != 0) {
48                         printf("\nmax of %d supplementary groups\n", i-1);
49                         exit(0);
50                 }
51                 printf("%d\r", i);
52                 fflush(stdout);
53         }
54         printf("\nno limit on supplementary groups!?\n");
55         return 0;
56 }