#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <grp.h>
#ifdef HAVE_SYS_SYSCALL_H
#include <sys/syscall.h>
#define NUM_THREADS 10
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
struct parm {
int id;
int ready;
assert_int_equal(u, 888);
}
+static void *uwrap_setgroups(void *arg)
+{
+ gid_t glist[] = { 100, 200, 300, 400, 500 };
+ int rc;
+
+ (void) arg; /* unused */
+
+ rc = setgroups(ARRAY_SIZE(glist), glist);
+ assert_int_equal(rc, 0);
+
+ return NULL;
+}
+
+static void *uwrap_getgroups(void *arg)
+{
+ gid_t glist[] = { 100, 200, 300, 400, 500 };
+ gid_t rlist[16];
+ int rc;
+
+ (void) arg; /* unused */
+
+ rc = getgroups(ARRAY_SIZE(rlist), rlist);
+ assert_int_equal(rc, 5);
+
+ assert_memory_equal(glist, rlist, sizeof(glist));
+
+ return NULL;
+}
+
+static void test_sync_setgroups(void **state)
+{
+ gid_t glist[] = { 100, 200, 300, 400, 500 };
+ pthread_t threads[NUM_THREADS];
+ gid_t rlist[16];
+ int rc;
+ int i;
+
+ (void) state; /* unused */
+
+ for (i = 0; i < NUM_THREADS; i++) {
+ pthread_create(&threads[i],
+ NULL,
+ uwrap_setgroups,
+ NULL);
+ }
+
+ /* wait for threaads */
+ for (i = 0; i < NUM_THREADS; i++) {
+ pthread_join(threads[i], NULL);
+ }
+
+ rc = getgroups(ARRAY_SIZE(rlist), rlist);
+ assert_int_equal(rc, 5);
+
+ assert_memory_equal(glist, rlist, sizeof(glist));
+
+ pthread_create(&threads[0],
+ NULL,
+ uwrap_getgroups,
+ NULL);
+
+ pthread_join(threads[0], NULL);
+
+}
+
int main(void) {
int rc;
unit_test(test_sync_setgid),
unit_test(test_sync_setgid_syscall),
unit_test(test_real_sync_setuid),
+ unit_test(test_sync_setgroups),
};
rc = run_tests(tests);