1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) International Business Machines Corp., 2001 4 * Ported by Wayne Boyer 5 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> 6 */ 7 8 /*\ 9 * [Description] 10 * 11 * Verify that setfsgid() correctly updates the filesystem group ID 12 * to the value given in fsgid argument. 13 */ 14 15 #include <pwd.h> 16 #include <unistd.h> 17 18 #include "tst_test.h" 19 #include "compat_tst_16.h" 20 21 static gid_t nobody_gid; 22 setup(void)23static void setup(void) 24 { 25 struct passwd *nobody; 26 27 nobody = SAFE_GETPWNAM("nobody"); 28 nobody_gid = nobody->pw_gid; 29 } 30 run(void)31static void run(void) 32 { 33 gid_t gid; 34 35 gid = getegid(); 36 GID16_CHECK(gid, setfsgid); 37 38 SAFE_SETEUID(0); 39 TST_EXP_VAL(SETFSGID(nobody_gid), gid); 40 TST_EXP_VAL(SETFSGID(-1), nobody_gid); 41 TST_EXP_VAL_SILENT(SETFSGID(gid), nobody_gid); 42 } 43 44 static struct tst_test test = { 45 .setup = setup, 46 .test_all = run, 47 .needs_root = 1 48 }; 49