• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  *
5  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
6  * Mountain View, CA  94043, or:
7  *
8  * http://www.sgi.com
9  *
10  * For further information regarding this notice, see:
11  *
12  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
13  *
14  * Author: William Roske
15  * Co-pilot: Dave Fenner
16  */
17 
18 /*
19  * Testcase to test the basic functionality of setregid(2) systemm call.
20  */
21 
22 #include "tst_test.h"
23 #include "compat_tst_16.h"
24 
25 static gid_t gid, egid;	    /* current real and effective group id */
26 static gid_t neg_one = -1;
27 
28 static struct tcase {
29 	gid_t *arg1;
30 	gid_t *arg2;
31 	const char *msg;
32 } tcases[] = {
33 	{&neg_one, &neg_one, "Dont change either real or effective gid" },
34 	{&neg_one, &egid,    "Change effective to effective gid" },
35 	{&gid,     &neg_one, "Change real to real gid" },
36 	{&neg_one, &gid,     "Change effective to real gid" },
37 	{&gid,     &gid,     "Try to change real to current real" }
38 };
39 
run(unsigned int n)40 static void run(unsigned int n)
41 {
42 	struct tcase *tc = &tcases[n];
43 
44 	TEST(SETREGID(*tc->arg1, *tc->arg2));
45 
46 	if (TST_RET == -1)
47 		tst_res(TFAIL | TTERRNO, tc->msg);
48 	else
49 		tst_res(TPASS, tc->msg);
50 }
51 
setup(void)52 static void setup(void)
53 {
54 	gid = getgid();
55 	GID16_CHECK(gid, setregid);
56 
57 	egid = getegid();
58 	GID16_CHECK(egid, setregid);
59 }
60 
61 static struct tst_test test = {
62 	.tcnt = ARRAY_SIZE(tcases),
63 	.test = run,
64 	.setup = setup,
65 };
66