summaryrefslogtreecommitdiffstats
path: root/source/tests
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-07-29 05:05:36 +0000
committerAndrew Tridgell <tridge@samba.org>1998-07-29 05:05:36 +0000
commit8b25fe734166b76ceebf8d9543c706ebe0fddc96 (patch)
treeafcb4704429fd8eace29fbe503458a85afc00b88 /source/tests
parent19aa9a1c95d357e1041e9a3ece89d7bb3cc6f6ac (diff)
downloadsamba-8b25fe734166b76ceebf8d9543c706ebe0fddc96.tar.gz
samba-8b25fe734166b76ceebf8d9543c706ebe0fddc96.tar.xz
samba-8b25fe734166b76ceebf8d9543c706ebe0fddc96.zip
get rid of the runtime test for broken getgroups() and add a compile
time test instead. This also allows us to get rid of the igroups element of a couple of structures.
Diffstat (limited to 'source/tests')
-rw-r--r--source/tests/getgroups.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/tests/getgroups.c b/source/tests/getgroups.c
new file mode 100644
index 00000000000..37990e010b8
--- /dev/null
+++ b/source/tests/getgroups.c
@@ -0,0 +1,62 @@
+/* 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
+ */
+
+#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);
+}