diff options
author | Andrew Tridgell <tridge@samba.org> | 2003-08-13 01:53:07 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2003-08-13 01:53:07 +0000 |
commit | ef2e26c91b80556af033d3335e55f5dfa6fff31d (patch) | |
tree | faa21bfd7e7b5247250b47c7891dc1a5ebee6be9 /source4/build/tests/getgroups.c | |
download | samba-ef2e26c91b80556af033d3335e55f5dfa6fff31d.tar.gz samba-ef2e26c91b80556af033d3335e55f5dfa6fff31d.tar.bz2 samba-ef2e26c91b80556af033d3335e55f5dfa6fff31d.zip |
first public release of samba4 code
(This used to be commit b0510b5428b3461aeb9bbe3cc95f62fc73e2b97f)
Diffstat (limited to 'source4/build/tests/getgroups.c')
-rw-r--r-- | source4/build/tests/getgroups.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/source4/build/tests/getgroups.c b/source4/build/tests/getgroups.c new file mode 100644 index 0000000000..343fd5a184 --- /dev/null +++ b/source4/build/tests/getgroups.c @@ -0,0 +1,66 @@ +/* this tests whether getgroups actually returns lists of integers + rather than gid_t. The test only works if the user running + the test is in at least 1 group + + The test is designed to check for those broken OSes that define + getgroups() as returning an array of gid_t but actually return a + array of ints! Ultrix is one culprit + */ + +#if defined(HAVE_UNISTD_H) +#include <unistd.h> +#endif + +#include <sys/types.h> +#include <stdio.h> +#include <unistd.h> +#include <grp.h> + +main() +{ + int i; + int *igroups; + char *cgroups; + int grp = 0; + int ngroups = getgroups(0,&grp); + + if (sizeof(gid_t) == sizeof(int)) { + fprintf(stderr,"gid_t and int are the same size\n"); + exit(1); + } + + if (ngroups <= 0) + ngroups = 32; + + igroups = (int *)malloc(sizeof(int)*ngroups); + + for (i=0;i<ngroups;i++) + igroups[i] = 0x42424242; + + ngroups = getgroups(ngroups,(gid_t *)igroups); + + if (igroups[0] == 0x42424242) + ngroups = 0; + + if (ngroups == 0) { + printf("WARNING: can't determine getgroups return type\n"); + exit(1); + } + + cgroups = (char *)igroups; + + if (ngroups == 1 && + cgroups[2] == 0x42 && cgroups[3] == 0x42) { + fprintf(stderr,"getgroups returns gid_t\n"); + exit(1); + } + + for (i=0;i<ngroups;i++) { + if (igroups[i] == 0x42424242) { + fprintf(stderr,"getgroups returns gid_t\n"); + exit(1); + } + } + + exit(0); +} |