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