get rid of the runtime test for broken getgroups() and add a compile
[samba.git] / source / tests / getgroups.c
1 /* this tests whether getgroups actually returns lists of integers
2    rather than gid_t. The test only works if the user running
3    the test is in at least 1 group 
4
5    The test is designed to check for those broken OSes that define
6    getgroups() as returning an array of gid_t but actually return a
7    array of ints! Ultrix is one culprit
8   */
9
10 #include <sys/types.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <grp.h>
14
15 main()
16 {
17         int i;
18         int *igroups;
19         char *cgroups;
20         int grp = 0;
21         int  ngroups = getgroups(0,&grp);
22
23         if (sizeof(gid_t) == sizeof(int)) {
24                 fprintf(stderr,"gid_t and int are the same size\n");
25                 exit(1);
26         }
27
28         if (ngroups <= 0)
29                 ngroups = 32;
30
31         igroups = (int *)malloc(sizeof(int)*ngroups);
32
33         for (i=0;i<ngroups;i++)
34                 igroups[i] = 0x42424242;
35
36         ngroups = getgroups(ngroups,(gid_t *)igroups);
37
38         if (igroups[0] == 0x42424242)
39                 ngroups = 0;
40
41         if (ngroups == 0) {
42                 printf("WARNING: can't determine getgroups return type\n");
43                 exit(1);
44         }
45         
46         cgroups = (char *)igroups;
47
48         if (ngroups == 1 && 
49             cgroups[2] == 0x42 && cgroups[3] == 0x42) {
50                 fprintf(stderr,"getgroups returns gid_t\n");
51                 exit(1);
52         }
53           
54         for (i=0;i<ngroups;i++) {
55                 if (igroups[i] == 0x42424242) {
56                         fprintf(stderr,"getgroups returns gid_t\n");
57                         exit(1);
58                 }
59         }
60
61         exit(0);
62 }