xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/setregid/setregid01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
6*49cdfc7eSAndroid Build Coastguard Worker  * Mountain View, CA  94043, or:
7*49cdfc7eSAndroid Build Coastguard Worker  *
8*49cdfc7eSAndroid Build Coastguard Worker  * http://www.sgi.com
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  * For further information regarding this notice, see:
11*49cdfc7eSAndroid Build Coastguard Worker  *
12*49cdfc7eSAndroid Build Coastguard Worker  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
13*49cdfc7eSAndroid Build Coastguard Worker  *
14*49cdfc7eSAndroid Build Coastguard Worker  * Author: William Roske
15*49cdfc7eSAndroid Build Coastguard Worker  * Co-pilot: Dave Fenner
16*49cdfc7eSAndroid Build Coastguard Worker  */
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker /*\
19*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
20*49cdfc7eSAndroid Build Coastguard Worker  *
21*49cdfc7eSAndroid Build Coastguard Worker  * Verify the basic functionality of setregid(2) system call.
22*49cdfc7eSAndroid Build Coastguard Worker  */
23*49cdfc7eSAndroid Build Coastguard Worker 
24*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
25*49cdfc7eSAndroid Build Coastguard Worker #include "compat_tst_16.h"
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker static gid_t gid, egid;
28*49cdfc7eSAndroid Build Coastguard Worker static gid_t neg_one = -1;
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
31*49cdfc7eSAndroid Build Coastguard Worker 	gid_t *arg1;
32*49cdfc7eSAndroid Build Coastguard Worker 	gid_t *arg2;
33*49cdfc7eSAndroid Build Coastguard Worker 	const char *msg;
34*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
35*49cdfc7eSAndroid Build Coastguard Worker 	{&neg_one, &neg_one, "Leave real and effective both gids unchanged" },
36*49cdfc7eSAndroid Build Coastguard Worker 	{&neg_one, &egid,    "Change effective to effective gid" },
37*49cdfc7eSAndroid Build Coastguard Worker 	{&gid,     &neg_one, "Change real to real gid" },
38*49cdfc7eSAndroid Build Coastguard Worker 	{&neg_one, &gid,     "Change effective to real gid" },
39*49cdfc7eSAndroid Build Coastguard Worker 	{&gid,     &gid,     "Change real and effective both gids to current real gid" }
40*49cdfc7eSAndroid Build Coastguard Worker };
41*49cdfc7eSAndroid Build Coastguard Worker 
run(unsigned int n)42*49cdfc7eSAndroid Build Coastguard Worker static void run(unsigned int n)
43*49cdfc7eSAndroid Build Coastguard Worker {
44*49cdfc7eSAndroid Build Coastguard Worker 	struct tcase *tc = &tcases[n];
45*49cdfc7eSAndroid Build Coastguard Worker 
46*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(SETREGID(*tc->arg1, *tc->arg2), "%s:", tc->msg);
47*49cdfc7eSAndroid Build Coastguard Worker }
48*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)49*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
50*49cdfc7eSAndroid Build Coastguard Worker {
51*49cdfc7eSAndroid Build Coastguard Worker 	gid = getgid();
52*49cdfc7eSAndroid Build Coastguard Worker 	GID16_CHECK(gid, setregid);
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker 	egid = getegid();
55*49cdfc7eSAndroid Build Coastguard Worker 	GID16_CHECK(egid, setregid);
56*49cdfc7eSAndroid Build Coastguard Worker }
57*49cdfc7eSAndroid Build Coastguard Worker 
58*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
59*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
60*49cdfc7eSAndroid Build Coastguard Worker 	.test = run,
61*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
62*49cdfc7eSAndroid Build Coastguard Worker };
63