1865695bbc89088b9526ea9045410e5afb70a985cplars/* 2865695bbc89088b9526ea9045410e5afb70a985cplars * 3865695bbc89088b9526ea9045410e5afb70a985cplars * Copyright (c) International Business Machines Corp., 2001 4865695bbc89088b9526ea9045410e5afb70a985cplars * 5865695bbc89088b9526ea9045410e5afb70a985cplars * This program is free software; you can redistribute it and/or modify 6865695bbc89088b9526ea9045410e5afb70a985cplars * it under the terms of the GNU General Public License as published by 7865695bbc89088b9526ea9045410e5afb70a985cplars * the Free Software Foundation; either version 2 of the License, or 8865695bbc89088b9526ea9045410e5afb70a985cplars * (at your option) any later version. 9865695bbc89088b9526ea9045410e5afb70a985cplars * 10865695bbc89088b9526ea9045410e5afb70a985cplars * This program is distributed in the hope that it will be useful, 11865695bbc89088b9526ea9045410e5afb70a985cplars * but WITHOUT ANY WARRANTY; without even the implied warranty of 12865695bbc89088b9526ea9045410e5afb70a985cplars * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13865695bbc89088b9526ea9045410e5afb70a985cplars * the GNU General Public License for more details. 14865695bbc89088b9526ea9045410e5afb70a985cplars * 15865695bbc89088b9526ea9045410e5afb70a985cplars * You should have received a copy of the GNU General Public License 16865695bbc89088b9526ea9045410e5afb70a985cplars * along with this program; if not, write to the Free Software 174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18865695bbc89088b9526ea9045410e5afb70a985cplars */ 19865695bbc89088b9526ea9045410e5afb70a985cplars 20865695bbc89088b9526ea9045410e5afb70a985cplars/* 21865695bbc89088b9526ea9045410e5afb70a985cplars * Test Name: mknod04 22865695bbc89088b9526ea9045410e5afb70a985cplars * 23865695bbc89088b9526ea9045410e5afb70a985cplars * Test Description: 244bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * Verify that mknod(2) succeeds when used to create a filesystem 25865695bbc89088b9526ea9045410e5afb70a985cplars * node on a directory with set group-ID bit set. 264bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * The node created should not have group-ID bit set and its gid should be 27865695bbc89088b9526ea9045410e5afb70a985cplars * equal to the effective gid of the process. 28865695bbc89088b9526ea9045410e5afb70a985cplars * 29865695bbc89088b9526ea9045410e5afb70a985cplars * Expected Result: 30865695bbc89088b9526ea9045410e5afb70a985cplars * mknod() should return value 0 on success and node created should not 31865695bbc89088b9526ea9045410e5afb70a985cplars * have set group-ID bit set and its gid should be equal to the effective 32865695bbc89088b9526ea9045410e5afb70a985cplars * gid of the process. 33865695bbc89088b9526ea9045410e5afb70a985cplars * 34865695bbc89088b9526ea9045410e5afb70a985cplars * Algorithm: 35865695bbc89088b9526ea9045410e5afb70a985cplars * Setup: 36865695bbc89088b9526ea9045410e5afb70a985cplars * Setup signal handling. 37865695bbc89088b9526ea9045410e5afb70a985cplars * Create temporary directory. 38865695bbc89088b9526ea9045410e5afb70a985cplars * Pause for SIGUSR1 if option specified. 39865695bbc89088b9526ea9045410e5afb70a985cplars * 40865695bbc89088b9526ea9045410e5afb70a985cplars * Test: 41865695bbc89088b9526ea9045410e5afb70a985cplars * Loop if the proper options are given. 42865695bbc89088b9526ea9045410e5afb70a985cplars * Execute system call 43865695bbc89088b9526ea9045410e5afb70a985cplars * Check return code, if system call failed (return=-1) 4456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak * Log the errno and Issue a FAIL message. 45865695bbc89088b9526ea9045410e5afb70a985cplars * Otherwise, 4656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak * Verify the Functionality of system call 47865695bbc89088b9526ea9045410e5afb70a985cplars * if successful, 4856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak * Issue Functionality-Pass message. 49865695bbc89088b9526ea9045410e5afb70a985cplars * Otherwise, 50865695bbc89088b9526ea9045410e5afb70a985cplars * Issue Functionality-Fail message. 51865695bbc89088b9526ea9045410e5afb70a985cplars * Cleanup: 52865695bbc89088b9526ea9045410e5afb70a985cplars * Print errno log and/or timing stats if options given 53865695bbc89088b9526ea9045410e5afb70a985cplars * Delete the temporary directory created. 54865695bbc89088b9526ea9045410e5afb70a985cplars * 55865695bbc89088b9526ea9045410e5afb70a985cplars * Usage: <for command-line> 56865695bbc89088b9526ea9045410e5afb70a985cplars * mknod04 [-c n] [-f] [-i n] [-I x] [-P x] [-t] 57865695bbc89088b9526ea9045410e5afb70a985cplars * where, -c n : Run n copies concurrently. 58865695bbc89088b9526ea9045410e5afb70a985cplars * -f : Turn off functionality Testing. 59865695bbc89088b9526ea9045410e5afb70a985cplars * -i n : Execute test n times. 60865695bbc89088b9526ea9045410e5afb70a985cplars * -I x : Execute test for x seconds. 61865695bbc89088b9526ea9045410e5afb70a985cplars * -P x : Pause for x seconds between iterations. 62865695bbc89088b9526ea9045410e5afb70a985cplars * -t : Turn on syscall timing. 63865695bbc89088b9526ea9045410e5afb70a985cplars * 64865695bbc89088b9526ea9045410e5afb70a985cplars * HISTORY 65865695bbc89088b9526ea9045410e5afb70a985cplars * 07/2001 Ported by Wayne Boyer 66865695bbc89088b9526ea9045410e5afb70a985cplars * 67865695bbc89088b9526ea9045410e5afb70a985cplars * RESTRICTIONS: 68865695bbc89088b9526ea9045410e5afb70a985cplars * This test should be run by 'super-user' (root) only. 69865695bbc89088b9526ea9045410e5afb70a985cplars * 70865695bbc89088b9526ea9045410e5afb70a985cplars */ 71865695bbc89088b9526ea9045410e5afb70a985cplars 72865695bbc89088b9526ea9045410e5afb70a985cplars#include <stdio.h> 73865695bbc89088b9526ea9045410e5afb70a985cplars#include <stdlib.h> 74865695bbc89088b9526ea9045410e5afb70a985cplars#include <unistd.h> 75865695bbc89088b9526ea9045410e5afb70a985cplars#include <errno.h> 76865695bbc89088b9526ea9045410e5afb70a985cplars#include <string.h> 77865695bbc89088b9526ea9045410e5afb70a985cplars#include <signal.h> 78865695bbc89088b9526ea9045410e5afb70a985cplars#include <pwd.h> 79865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/types.h> 80865695bbc89088b9526ea9045410e5afb70a985cplars#include <sys/stat.h> 81865695bbc89088b9526ea9045410e5afb70a985cplars 82865695bbc89088b9526ea9045410e5afb70a985cplars#include "test.h" 83865695bbc89088b9526ea9045410e5afb70a985cplars 84865695bbc89088b9526ea9045410e5afb70a985cplars#define LTPUSER "nobody" 85865695bbc89088b9526ea9045410e5afb70a985cplars#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO 86865695bbc89088b9526ea9045410e5afb70a985cplars#define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO 87865695bbc89088b9526ea9045410e5afb70a985cplars#define DIR_TEMP "testdir_4" 88865695bbc89088b9526ea9045410e5afb70a985cplars#define TNODE "tnode_%d" 89865695bbc89088b9526ea9045410e5afb70a985cplars 90865695bbc89088b9526ea9045410e5afb70a985cplarsstruct stat buf; /* struct. to hold stat(2) o/p contents */ 91865695bbc89088b9526ea9045410e5afb70a985cplarsstruct passwd *user1; /* struct. to hold getpwnam(3) o/p contents */ 92865695bbc89088b9526ea9045410e5afb70a985cplars 93fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716Cyril Hrubischar *TCID = "mknod04"; 94fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716Cyril Hrubisint TST_TOTAL = 1; 95865695bbc89088b9526ea9045410e5afb70a985cplarschar node_name[PATH_MAX]; /* buffer to hold node name created */ 96865695bbc89088b9526ea9045410e5afb70a985cplars 97865695bbc89088b9526ea9045410e5afb70a985cplarsgid_t group1_gid, group2_gid, mygid; /* user and process group id's */ 98865695bbc89088b9526ea9045410e5afb70a985cplarsuid_t save_myuid, user1_uid; /* user and process user id's */ 99865695bbc89088b9526ea9045410e5afb70a985cplarspid_t mypid; /* process id */ 100865695bbc89088b9526ea9045410e5afb70a985cplars 101865695bbc89088b9526ea9045410e5afb70a985cplarsvoid setup(); /* setup function for the test */ 102865695bbc89088b9526ea9045410e5afb70a985cplarsvoid cleanup(); /* cleanup function for the test */ 103865695bbc89088b9526ea9045410e5afb70a985cplars 10456207cec7732e09c216c751c0b5f88a242bacae6subrata_modakint main(int ac, char **av) 105865695bbc89088b9526ea9045410e5afb70a985cplars{ 10689af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis int lc; 107d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis int fflag; 108865695bbc89088b9526ea9045410e5afb70a985cplars 109d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(ac, av, NULL, NULL); 110865695bbc89088b9526ea9045410e5afb70a985cplars 111865695bbc89088b9526ea9045410e5afb70a985cplars setup(); 112865695bbc89088b9526ea9045410e5afb70a985cplars 113865695bbc89088b9526ea9045410e5afb70a985cplars for (lc = 0; TEST_LOOPING(lc); lc++) { 1142c28215423293e443469a07ae7011135d058b671Garrett Cooper 115d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 116865695bbc89088b9526ea9045410e5afb70a985cplars 117865695bbc89088b9526ea9045410e5afb70a985cplars /* 1184bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * TEST CASE CONDITION: 119865695bbc89088b9526ea9045410e5afb70a985cplars * Attempt to create a filesystem node on a directory 120865695bbc89088b9526ea9045410e5afb70a985cplars * with group id (sgid) bit set such that, 121865695bbc89088b9526ea9045410e5afb70a985cplars * the node created by mknod(2) should not have group id 122865695bbc89088b9526ea9045410e5afb70a985cplars * (sgid) bit set and node's gid should be equal to the 123865695bbc89088b9526ea9045410e5afb70a985cplars * effective gid of the process. 124865695bbc89088b9526ea9045410e5afb70a985cplars */ 125865695bbc89088b9526ea9045410e5afb70a985cplars TEST(mknod(node_name, MODE_RWX, 0)); 126bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 127865695bbc89088b9526ea9045410e5afb70a985cplars /* Check return code from mknod(2) */ 128865695bbc89088b9526ea9045410e5afb70a985cplars if (TEST_RETURN == -1) { 129865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TFAIL, "mknod(%s, %#o, 0) failed, errno=%d : " 130865695bbc89088b9526ea9045410e5afb70a985cplars "%s", node_name, MODE_RWX, TEST_ERRNO, 131865695bbc89088b9526ea9045410e5afb70a985cplars strerror(TEST_ERRNO)); 132865695bbc89088b9526ea9045410e5afb70a985cplars continue; 133865695bbc89088b9526ea9045410e5afb70a985cplars } 134e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* Set the functionality flag */ 135e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis fflag = 1; 136e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis 137e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* Check for node's creation */ 138e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis if (stat(node_name, &buf) < 0) { 139e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TFAIL, "stat() of %s failed, errno:%d", 140e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis node_name, TEST_ERRNO); 141e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* unset fflag */ 142e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis fflag = 0; 143e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis } 144e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis 145e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* Verify mode permissions of node */ 146e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis if (buf.st_mode & S_ISGID) { 147e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TFAIL, "%s: Incorrect modes, setgid " 148e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis "bit set", node_name); 149e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* unset flag as functionality fails */ 150e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis fflag = 0; 151e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis } 152e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis 153e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* Verify group ID of node */ 154e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis if (buf.st_gid != group2_gid) { 155e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TFAIL, "%s: Incorrect group", 156e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis node_name); 157e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis /* unset flag as functionality fails */ 158e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis fflag = 0; 159e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis } 160e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis if (fflag) { 161e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis tst_resm(TPASS, "Functionality of mknod(%s, " 162e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis "%#o, 0) successful", 163e38b961c385192f0d804914b77bd590734b42e75Cyril Hrubis node_name, MODE_RWX); 164865695bbc89088b9526ea9045410e5afb70a985cplars } 165865695bbc89088b9526ea9045410e5afb70a985cplars 166865695bbc89088b9526ea9045410e5afb70a985cplars /* Remove the node for the next go `round */ 167865695bbc89088b9526ea9045410e5afb70a985cplars if (unlink(node_name) == -1) { 168865695bbc89088b9526ea9045410e5afb70a985cplars tst_resm(TWARN, "unlink(%s) failed, errno:%d %s", 16956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak node_name, errno, strerror(errno)); 170865695bbc89088b9526ea9045410e5afb70a985cplars } 17156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak } 172865695bbc89088b9526ea9045410e5afb70a985cplars 173865695bbc89088b9526ea9045410e5afb70a985cplars /* Change the directory back to temporary directory */ 174865695bbc89088b9526ea9045410e5afb70a985cplars chdir(".."); 175865695bbc89088b9526ea9045410e5afb70a985cplars 176865695bbc89088b9526ea9045410e5afb70a985cplars /* 177865695bbc89088b9526ea9045410e5afb70a985cplars * Invoke cleanup() to delete the test directories created 178865695bbc89088b9526ea9045410e5afb70a985cplars * in the setup() and exit main(). 179865695bbc89088b9526ea9045410e5afb70a985cplars */ 180865695bbc89088b9526ea9045410e5afb70a985cplars cleanup(); 181865695bbc89088b9526ea9045410e5afb70a985cplars 1827d0a4a57fbcd47f72b67c08df532e8ef47f6fdaeGarrett Cooper tst_exit(); 1832c28215423293e443469a07ae7011135d058b671Garrett Cooper} 184865695bbc89088b9526ea9045410e5afb70a985cplars 185865695bbc89088b9526ea9045410e5afb70a985cplars/* 1864bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * void 187865695bbc89088b9526ea9045410e5afb70a985cplars * setup(void) - performs all ONE TIME setup for this test. 18856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak * Exit the test program on receipt of unexpected signals. 189865695bbc89088b9526ea9045410e5afb70a985cplars * Create a temporary directory used to hold test directories created 190865695bbc89088b9526ea9045410e5afb70a985cplars * and change the directory to it. 191865695bbc89088b9526ea9045410e5afb70a985cplars * Verify that pid of process executing the test is root. 1924bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * Create a test directory on temporary directory and set the ownership 193865695bbc89088b9526ea9045410e5afb70a985cplars * of test directory to guest user and process, change mode permissions 194865695bbc89088b9526ea9045410e5afb70a985cplars * to set group-id bit on it. 195865695bbc89088b9526ea9045410e5afb70a985cplars * Set the effective uid/gid of the process to that of guest user. 196865695bbc89088b9526ea9045410e5afb70a985cplars */ 197c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid setup(void) 198865695bbc89088b9526ea9045410e5afb70a985cplars{ 199d1e794d62b1bf619df8390535e4c2a58899b1145Cyril Hrubis tst_require_root(); 200865695bbc89088b9526ea9045410e5afb70a985cplars 201865695bbc89088b9526ea9045410e5afb70a985cplars /* Capture unexpected signals */ 202865695bbc89088b9526ea9045410e5afb70a985cplars tst_sig(NOFORK, DEF_HANDLER, cleanup); 203865695bbc89088b9526ea9045410e5afb70a985cplars 204865695bbc89088b9526ea9045410e5afb70a985cplars TEST_PAUSE; 205865695bbc89088b9526ea9045410e5afb70a985cplars 206865695bbc89088b9526ea9045410e5afb70a985cplars /* Make a temp dir and cd to it */ 207865695bbc89088b9526ea9045410e5afb70a985cplars tst_tmpdir(); 208865695bbc89088b9526ea9045410e5afb70a985cplars 20956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak /* fix permissions on the tmpdir */ 21056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak if (chmod(".", 0711) != 0) { 21156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak tst_brkm(TBROK, cleanup, "chmod() failed"); 21256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak } 21305a3b8ba2534b7f3506d9b2aacad5c59a5ce5809plars 214865695bbc89088b9526ea9045410e5afb70a985cplars /* Save the real user id of the current test process */ 21556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak save_myuid = getuid(); 216865695bbc89088b9526ea9045410e5afb70a985cplars 217865695bbc89088b9526ea9045410e5afb70a985cplars /* Save the process id of the current test process */ 21856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak mypid = getpid(); 219865695bbc89088b9526ea9045410e5afb70a985cplars 220865695bbc89088b9526ea9045410e5afb70a985cplars /* Get the node name to be created in the test */ 221865695bbc89088b9526ea9045410e5afb70a985cplars sprintf(node_name, TNODE, mypid); 222865695bbc89088b9526ea9045410e5afb70a985cplars 223865695bbc89088b9526ea9045410e5afb70a985cplars /* Get the uid/gid of ltp user */ 224865695bbc89088b9526ea9045410e5afb70a985cplars if ((user1 = getpwnam(LTPUSER)) == NULL) { 225865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); 226865695bbc89088b9526ea9045410e5afb70a985cplars } 227865695bbc89088b9526ea9045410e5afb70a985cplars user1_uid = user1->pw_uid; 228865695bbc89088b9526ea9045410e5afb70a985cplars group1_gid = user1->pw_gid; 229865695bbc89088b9526ea9045410e5afb70a985cplars 230865695bbc89088b9526ea9045410e5afb70a985cplars /* Get the effective group id of the test process */ 23156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak group2_gid = getegid(); 232865695bbc89088b9526ea9045410e5afb70a985cplars 233865695bbc89088b9526ea9045410e5afb70a985cplars /* 234865695bbc89088b9526ea9045410e5afb70a985cplars * Create a test directory under temporary directory with the 235865695bbc89088b9526ea9045410e5afb70a985cplars * specified mode permissions, with uid/gid set to that of guest 236865695bbc89088b9526ea9045410e5afb70a985cplars * user and the test process. 237865695bbc89088b9526ea9045410e5afb70a985cplars */ 238865695bbc89088b9526ea9045410e5afb70a985cplars if (mkdir(DIR_TEMP, MODE_RWX) < 0) { 239865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP); 240865695bbc89088b9526ea9045410e5afb70a985cplars } 241865695bbc89088b9526ea9045410e5afb70a985cplars if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) { 242865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP); 243865695bbc89088b9526ea9045410e5afb70a985cplars } 244865695bbc89088b9526ea9045410e5afb70a985cplars if (chmod(DIR_TEMP, MODE_SGID) < 0) { 245865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP); 246865695bbc89088b9526ea9045410e5afb70a985cplars } 247865695bbc89088b9526ea9045410e5afb70a985cplars 248865695bbc89088b9526ea9045410e5afb70a985cplars /* 249865695bbc89088b9526ea9045410e5afb70a985cplars * Verify that test directory created with expected permission modes 250865695bbc89088b9526ea9045410e5afb70a985cplars * and ownerships. 251865695bbc89088b9526ea9045410e5afb70a985cplars */ 252865695bbc89088b9526ea9045410e5afb70a985cplars if (stat(DIR_TEMP, &buf) < 0) { 253865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP); 254865695bbc89088b9526ea9045410e5afb70a985cplars } 255865695bbc89088b9526ea9045410e5afb70a985cplars 256865695bbc89088b9526ea9045410e5afb70a985cplars /* Verify modes of test directory */ 257865695bbc89088b9526ea9045410e5afb70a985cplars if (!(buf.st_mode & S_ISGID)) { 258865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, 259865695bbc89088b9526ea9045410e5afb70a985cplars "%s: Incorrect modes, setgid bit not set", DIR_TEMP); 260865695bbc89088b9526ea9045410e5afb70a985cplars } 261865695bbc89088b9526ea9045410e5afb70a985cplars 262865695bbc89088b9526ea9045410e5afb70a985cplars /* Verify group ID */ 263865695bbc89088b9526ea9045410e5afb70a985cplars if (buf.st_gid != group2_gid) { 264865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP); 265865695bbc89088b9526ea9045410e5afb70a985cplars } 266bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 26756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak /* 2684bb656a129f7507823e9e6d6b98b1a02fd80ef89subrata_modak * Set the effective group id and user id of the test process 269865695bbc89088b9526ea9045410e5afb70a985cplars * to that of guest user (nobody) 270865695bbc89088b9526ea9045410e5afb70a985cplars */ 271865695bbc89088b9526ea9045410e5afb70a985cplars if (setgid(group1_gid) < 0) { 272865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, 273865695bbc89088b9526ea9045410e5afb70a985cplars "Unable to set process gid to that of ltp user"); 274865695bbc89088b9526ea9045410e5afb70a985cplars } 275865695bbc89088b9526ea9045410e5afb70a985cplars if (setreuid(-1, user1_uid) < 0) { 276865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, 277865695bbc89088b9526ea9045410e5afb70a985cplars "Unable to set process uid to that of ltp user"); 278865695bbc89088b9526ea9045410e5afb70a985cplars } 279865695bbc89088b9526ea9045410e5afb70a985cplars 280865695bbc89088b9526ea9045410e5afb70a985cplars /* Save the real group ID of the current process */ 281865695bbc89088b9526ea9045410e5afb70a985cplars mygid = getgid(); 282865695bbc89088b9526ea9045410e5afb70a985cplars 283865695bbc89088b9526ea9045410e5afb70a985cplars /* Change directory to DIR_TEMP */ 284865695bbc89088b9526ea9045410e5afb70a985cplars if (chdir(DIR_TEMP) < 0) { 285865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, 286865695bbc89088b9526ea9045410e5afb70a985cplars "Unable to change to %s directory", DIR_TEMP); 287865695bbc89088b9526ea9045410e5afb70a985cplars } 288865695bbc89088b9526ea9045410e5afb70a985cplars} 289865695bbc89088b9526ea9045410e5afb70a985cplars 290865695bbc89088b9526ea9045410e5afb70a985cplars/* 291865695bbc89088b9526ea9045410e5afb70a985cplars * cleanup() - Performs all ONE TIME cleanup for this test at 292865695bbc89088b9526ea9045410e5afb70a985cplars * completion or premature exit. 293865695bbc89088b9526ea9045410e5afb70a985cplars * Print test timing stats and errno log if test executed with options. 294865695bbc89088b9526ea9045410e5afb70a985cplars * Restore the real/effective user id of the process changed during 295865695bbc89088b9526ea9045410e5afb70a985cplars * setup(). 296865695bbc89088b9526ea9045410e5afb70a985cplars * Remove temporary directory and sub-directories/files under it 297865695bbc89088b9526ea9045410e5afb70a985cplars * created during setup(). 298865695bbc89088b9526ea9045410e5afb70a985cplars * Exit the test program with normal exit code. 299865695bbc89088b9526ea9045410e5afb70a985cplars */ 300c57fba5535abf457e33dd7a986b6c512d95cdef6Mike Frysingervoid cleanup(void) 301865695bbc89088b9526ea9045410e5afb70a985cplars{ 302865695bbc89088b9526ea9045410e5afb70a985cplars 303865695bbc89088b9526ea9045410e5afb70a985cplars /* 304865695bbc89088b9526ea9045410e5afb70a985cplars * Restore the effective uid of the process changed in the 305865695bbc89088b9526ea9045410e5afb70a985cplars * setup(). 306865695bbc89088b9526ea9045410e5afb70a985cplars */ 307865695bbc89088b9526ea9045410e5afb70a985cplars if (setreuid(-1, save_myuid) < 0) { 308865695bbc89088b9526ea9045410e5afb70a985cplars tst_brkm(TBROK, cleanup, 309865695bbc89088b9526ea9045410e5afb70a985cplars "resetting process real/effective uid failed"); 310865695bbc89088b9526ea9045410e5afb70a985cplars } 311865695bbc89088b9526ea9045410e5afb70a985cplars 312865695bbc89088b9526ea9045410e5afb70a985cplars tst_rmdir(); 31356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak 314ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 315