Last change
on this file since 741 was 414, checked in by Herwig Bauernfeind, 15 years ago |
Samba 3.5.0: Initial import
|
File size:
1.3 KB
|
Line | |
---|
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 | #if defined(HAVE_UNISTD_H)
|
---|
11 | #include <unistd.h>
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | #include <sys/types.h>
|
---|
15 | #include <stdio.h>
|
---|
16 | #include <unistd.h>
|
---|
17 | #include <grp.h>
|
---|
18 |
|
---|
19 | main()
|
---|
20 | {
|
---|
21 | int i;
|
---|
22 | int *igroups;
|
---|
23 | char *cgroups;
|
---|
24 | int grp = 0;
|
---|
25 | int ngroups = getgroups(0,&grp);
|
---|
26 |
|
---|
27 | if (sizeof(gid_t) == sizeof(int)) {
|
---|
28 | fprintf(stderr,"gid_t and int are the same size\n");
|
---|
29 | exit(1);
|
---|
30 | }
|
---|
31 |
|
---|
32 | if (ngroups <= 0)
|
---|
33 | ngroups = 32;
|
---|
34 |
|
---|
35 | igroups = (int *)malloc(sizeof(int)*ngroups);
|
---|
36 |
|
---|
37 | for (i=0;i<ngroups;i++)
|
---|
38 | igroups[i] = 0x42424242;
|
---|
39 |
|
---|
40 | ngroups = getgroups(ngroups,(gid_t *)igroups);
|
---|
41 |
|
---|
42 | if (igroups[0] == 0x42424242)
|
---|
43 | ngroups = 0;
|
---|
44 |
|
---|
45 | if (ngroups == 0) {
|
---|
46 | printf("WARNING: can't determine getgroups return type\n");
|
---|
47 | exit(1);
|
---|
48 | }
|
---|
49 |
|
---|
50 | cgroups = (char *)igroups;
|
---|
51 |
|
---|
52 | if (ngroups == 1 &&
|
---|
53 | cgroups[2] == 0x42 && cgroups[3] == 0x42) {
|
---|
54 | fprintf(stderr,"getgroups returns gid_t\n");
|
---|
55 | exit(1);
|
---|
56 | }
|
---|
57 |
|
---|
58 | for (i=0;i<ngroups;i++) {
|
---|
59 | if (igroups[i] == 0x42424242) {
|
---|
60 | fprintf(stderr,"getgroups returns gid_t\n");
|
---|
61 | exit(1);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | exit(0);
|
---|
66 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.