r25493: Fix typo in Jeremy's thread-safe winbind patch:
[Samba/nascimento.git] / source3 / tests / getgroups.c
blobc73cd21650d75b43375ddb9458542da6839a70d0
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
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 */
10 #if defined(HAVE_UNISTD_H)
11 #include <unistd.h>
12 #endif
14 #if defined(HAVE_STDLIB_H)
15 #include <stdlib.h>
16 #endif
18 #include <sys/types.h>
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <grp.h>
23 main()
25 int i;
26 int *igroups;
27 char *cgroups;
28 int grp = 0;
29 int ngroups = getgroups(0,&grp);
31 if (sizeof(gid_t) == sizeof(int)) {
32 fprintf(stderr,"gid_t and int are the same size\n");
33 return 1;
36 if (ngroups <= 0)
37 ngroups = 32;
39 igroups = (int *)malloc(sizeof(int)*ngroups);
41 for (i=0;i<ngroups;i++)
42 igroups[i] = 0x42424242;
44 ngroups = getgroups(ngroups,(gid_t *)igroups);
46 if (igroups[0] == 0x42424242)
47 ngroups = 0;
49 if (ngroups == 0) {
50 printf("WARNING: can't determine getgroups return type\n");
51 return 1;
54 cgroups = (char *)igroups;
56 if (ngroups == 1 &&
57 cgroups[2] == 0x42 && cgroups[3] == 0x42) {
58 fprintf(stderr,"getgroups returns gid_t\n");
59 return 1;
62 for (i=0;i<ngroups;i++) {
63 if (igroups[i] == 0x42424242) {
64 fprintf(stderr,"getgroups returns gid_t\n");
65 return 1;
69 return 0;