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