• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	int proc_flag;
16 
17 	pw = SAFE_GETPWNAM("nobody");
18 
19 	tst_reinit();
20 	if (argc != 3)
21 		tst_brk(TFAIL, "argc is %d, expected 3", argc);
22 
23 	if (!strcmp(argv[2], "Yes"))
24 		proc_flag = 1;
25 	else
26 		proc_flag = 0;
27 	check_no_new_privs(1, argv[1], proc_flag);
28 
29 	TEST(getegid());
30 	if (TST_RET == 0)
31 		tst_res(TFAIL,
32 			"%s getegid() returns 0 unexpectedly, it gains root privileges",
33 			argv[1]);
34 	if (TST_RET == pw->pw_gid)
35 		tst_res(TPASS,
36 			"%s getegid() returns nobody, it doesn't gain root privileges",
37 			argv[1]);
38 
39 	TEST(geteuid());
40 	if (TST_RET == 0)
41 		tst_res(TFAIL,
42 			"%s geteuid() returns 0 unexpectedly, it gains root privileges",
43 			argv[1]);
44 	if (TST_RET == pw->pw_uid)
45 		tst_res(TPASS,
46 			"%s geteuid() returns nobody, it doesn't gain root privileges",
47 			argv[1]);
48 
49 	return 0;
50 }
51