1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2014 Fujitsu Ltd.
4 * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
5 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6 */
7
8/*\
9 * [Description]
10 *
11 * Verify that setegid() fails with EPERM when the calling process is not
12 * privileged and egid does not match the current real group ID,
13 * current effective group ID, or current saved set-group-ID.
14 */
15
16#include <pwd.h>
17#include "tst_test.h"
18
19static struct passwd *ltpuser;
20
21static void setup(void)
22{
23	ltpuser = SAFE_GETPWNAM("nobody");
24	SAFE_SETEUID(ltpuser->pw_uid);
25}
26
27static void setegid_verify(void)
28{
29	TST_EXP_FAIL(setegid(ltpuser->pw_gid),
30				EPERM,
31				"setegid(%d)",
32				ltpuser->pw_gid);
33}
34
35static struct tst_test test = {
36	.setup = setup,
37	.test_all = setegid_verify,
38	.needs_root = 1
39};
40