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 setfsuid() correctly updates the filesystem user ID 12 * to the value given in fsuid argument. 13 */ 14 15 #include <pwd.h> 16 #include "tst_test.h" 17 #include "compat_tst_16.h" 18 19 static uid_t nobody_uid; 20 setup(void)21static void setup(void) 22 { 23 struct passwd *nobody; 24 25 nobody = SAFE_GETPWNAM("nobody"); 26 nobody_uid = nobody->pw_uid; 27 } 28 run(void)29static void run(void) 30 { 31 uid_t uid; 32 33 uid = geteuid(); 34 UID16_CHECK(uid, setfsuid); 35 36 SAFE_SETEUID(0); 37 TST_EXP_VAL(SETFSUID(nobody_uid), uid, "setfsuid(%d)", nobody_uid); 38 TST_EXP_VAL(SETFSUID(-1), nobody_uid); 39 } 40 41 static struct tst_test test = { 42 .setup = setup, 43 .test_all = run, 44 .needs_root = 1 45 }; 46