1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) International Business Machines Corp., 2001 4 * Ported by Wayne Boyer 5 */ 6 7 /*\ 8 * [Description] 9 * 10 * Test if setgid() system call sets errno to EPERM correctly. 11 * 12 * [Algorithm] 13 * 14 * Call setgid() to set the gid to that of root. Run this test as 15 * nobody, and expect to get EPERM. 16 */ 17 18 #include <pwd.h> 19 #include "tst_test.h" 20 #include "compat_tst_16.h" 21 run(void)22static void run(void) 23 { 24 struct passwd *rootpwent; 25 26 rootpwent = SAFE_GETPWNAM("root"); 27 28 GID16_CHECK(rootpwent->pw_gid, setgid); 29 30 TST_EXP_FAIL(SETGID(rootpwent->pw_gid), EPERM); 31 } 32 setup(void)33static void setup(void) 34 { 35 struct passwd *nobody = SAFE_GETPWNAM("nobody"); 36 37 SAFE_SETGID(nobody->pw_gid); 38 SAFE_SETUID(nobody->pw_uid); 39 } 40 41 static struct tst_test test = { 42 .needs_root = 1, 43 .setup = setup, 44 .test_all = run, 45 }; 46