1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
4  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
5  *
6  * dummy program which is used by prctl06 testcase
7  */
8 #define TST_NO_DEFAULT_MAIN
9 #include "prctl06.h"
10 
11 
main(int argc,char ** argv)12 int main(int argc, char **argv)
13 {
14 	struct passwd *pw;
15 
16 	pw = SAFE_GETPWNAM("nobody");
17 
18 	tst_reinit();
19 	if (argc != 2)
20 		tst_brk(TFAIL, "argc is %d, expected 2", argc);
21 
22 	check_no_new_privs(1, argv[1]);
23 
24 	TEST(getegid());
25 	if (TST_RET == 0)
26 		tst_res(TFAIL,
27 			"%s getegid() returns 0 unexpectedly, it gains root privileges",
28 			argv[1]);
29 	if (TST_RET == pw->pw_gid)
30 		tst_res(TPASS,
31 			"%s getegid() returns nobody, it doesn't gain root privileges",
32 			argv[1]);
33 
34 	TEST(geteuid());
35 	if (TST_RET == 0)
36 		tst_res(TFAIL,
37 			"%s geteuid() returns 0 unexpectedly, it gains root privileges",
38 			argv[1]);
39 	if (TST_RET == pw->pw_uid)
40 		tst_res(TPASS,
41 			"%s geteuid() returns nobody, it doesn't gain root privileges",
42 			argv[1]);
43 
44 	return 0;
45 }
46