1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines  Corp., 2001
4f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2003-2023
5f08c3bdfSopenharmony_ci * 07/2001 Ported by Wayne Boyer
6f08c3bdfSopenharmony_ci */
7f08c3bdfSopenharmony_ci
8f08c3bdfSopenharmony_ci/*\
9f08c3bdfSopenharmony_ci * [Description]
10f08c3bdfSopenharmony_ci *
11f08c3bdfSopenharmony_ci * Check that root process can setgroups() supplementary group ID and verify
12f08c3bdfSopenharmony_ci * that getgroups() returns the previously set ID.
13f08c3bdfSopenharmony_ci */
14f08c3bdfSopenharmony_ci
15f08c3bdfSopenharmony_ci#include <pwd.h>
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ci#include "tst_test.h"
18f08c3bdfSopenharmony_ci#include "compat_tst_16.h"
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_cistatic GID_T *groups_get, *groups_set;
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_cistatic void verify_setgroups(void)
23f08c3bdfSopenharmony_ci{
24f08c3bdfSopenharmony_ci	groups_set[0] = 42;
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_ci	TST_EXP_PASS(SETGROUPS(1, groups_set));
27f08c3bdfSopenharmony_ci
28f08c3bdfSopenharmony_ci	TST_EXP_VAL(GETGROUPS(1, groups_get), 1);
29f08c3bdfSopenharmony_ci
30f08c3bdfSopenharmony_ci	TST_EXP_EQ_LI(groups_get[0], groups_set[0]);
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_ci	groups_get[0] = 0;
33f08c3bdfSopenharmony_ci}
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_cistatic struct tst_test test = {
36f08c3bdfSopenharmony_ci	.test_all = verify_setgroups,
37f08c3bdfSopenharmony_ci	.bufs = (struct tst_buffers []) {
38f08c3bdfSopenharmony_ci		{&groups_get, .size = sizeof(GID_T)},
39f08c3bdfSopenharmony_ci		{&groups_set, .size = sizeof(GID_T)},
40f08c3bdfSopenharmony_ci		{},
41f08c3bdfSopenharmony_ci	},
42f08c3bdfSopenharmony_ci	.needs_root = 1,
43f08c3bdfSopenharmony_ci};
44