1 /* 2 * Copyright (C) Bull S.A. 2001 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 21 * Test Name: setgroups04 22 * 23 * Test Description: 24 * Verify that, setgroups() fails with -1 and sets errno to EFAULT if the list has an invalid address. 25 * 26 * Expected Result: 27 * setgroups() should fail with return value -1 and set expected errno. 28 * 29 * Algorithm: 30 * Setup: 31 * Setup signal handling. 32 * Pause for SIGUSR1 if option specified. 33 * 34 * Test: 35 * Loop if the proper options are given. 36 * Execute system call 37 * Check return code, if system call failed (return=-1) 38 * if errno set == expected errno 39 * Issue sys call fails with expected return value and errno. 40 * Otherwise, 41 * Issue sys call fails with unexpected errno. 42 * Otherwise, 43 * Issue sys call returns unexpected value. 44 * 45 * Cleanup: 46 * Print errno log and/or timing stats if options given 47 * 48 * Usage: <for command-line> 49 * setgroups04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 50 * where, -c n : Run n copies concurrently. 51 * -f : Turn off functionality Testing. 52 * -i n : Execute test n times. 53 * -I x : Execute test for x seconds. 54 * -P x : Pause for x seconds between iterations. 55 * -t : Turn on syscall timing. 56 * 57 * HISTORY 58 * 05/2002 Ported by Andr Merlier 59 * 60 * RESTRICTIONS: 61 * none. 62 * 63 */ 64 #include <sys/types.h> 65 #include <unistd.h> 66 #include <errno.h> 67 #include <pwd.h> 68 #include <grp.h> 69 70 #include "test.h" 71 72 #include "compat_16.h" 73 74 TCID_DEFINE(setgroups04); 75 int TST_TOTAL = 1; 76 77 GID_T groups_list[NGROUPS]; 78 79 void setup(); /* setup function for the test */ 80 void cleanup(); /* cleanup function for the test */ 81 82 #if !defined(UCLINUX) 83 84 int main(int ac, char **av) 85 { 86 int lc; 87 int gidsetsize; /* total no. of groups */ 88 char *test_desc; /* test specific error message */ 89 90 tst_parse_opts(ac, av, NULL, NULL); 91 92 /* Perform setup for test */ 93 setup(); 94 95 for (lc = 0; TEST_LOOPING(lc); lc++) { 96 97 tst_count = 0; 98 99 gidsetsize = NGROUPS; 100 test_desc = "EFAULT"; 101 102 /* 103 * Call setgroups() to test condition 104 * verify that it fails with -1 return value and 105 * sets appropriate errno. 106 */ 107 TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0))); 108 109 if (TEST_RETURN != -1) { 110 tst_resm(TFAIL, "setgroups() returned %ld, " 111 "expected -1, errno=%d", TEST_RETURN, 112 EFAULT); 113 } else { 114 115 if (TEST_ERRNO == EFAULT) { 116 tst_resm(TPASS, 117 "setgroups() fails with expected " 118 "error EFAULT errno:%d", TEST_ERRNO); 119 } else { 120 tst_resm(TFAIL, "setgroups() fails, %s, " 121 "errno=%d, expected errno=%d", 122 test_desc, TEST_ERRNO, EFAULT); 123 } 124 } 125 126 } 127 128 cleanup(); 129 tst_exit(); 130 131 } 132 133 #else 134 135 int main(void) 136 { 137 tst_resm(TINFO, "test is not available on uClinux"); 138 tst_exit(); 139 } 140 141 #endif /* if !defined(UCLINUX) */ 142 143 /* 144 * setup() 145 */ 146 void setup(void) 147 { 148 tst_require_root(); 149 150 tst_sig(NOFORK, DEF_HANDLER, cleanup); 151 152 TEST_PAUSE; 153 154 } 155 156 /* 157 * cleanup() 158 */ 159 void cleanup(void) 160 { 161 162 } 163