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 * [Algorithm] 9 * 10 * As a root sets current group id to nobody and expects success. 11 */ 12 13 #include <pwd.h> 14 #include "tst_test.h" 15 #include <compat_tst_16.h> 16 17 static struct passwd *nobody; 18 run(void)19static void run(void) 20 { 21 TST_EXP_PASS(SETGID(nobody->pw_gid)); 22 23 if (getgid() != nobody->pw_gid) 24 tst_res(TFAIL, "setgid failed to set gid to nobody gid"); 25 else 26 tst_res(TPASS, "functionality of getgid() is correct"); 27 } 28 setup(void)29static void setup(void) 30 { 31 nobody = SAFE_GETPWNAM("nobody"); 32 GID16_CHECK(nobody->pw_gid, setgid); 33 } 34 35 static struct tst_test test = { 36 .needs_root = 1, 37 .setup = setup, 38 .test_all = run, 39 }; 40