robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | /* |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 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" |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 71 | |
subrata_modak | 34a572a | 2008-08-27 12:02:42 +0000 | [diff] [blame] | 72 | #include "compat_16.h" |
| 73 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 74 | TCID_DEFINE(setgroups04); |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 75 | int TST_TOTAL = 1; |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 76 | |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 77 | GID_T groups_list[NGROUPS]; |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 78 | |
| 79 | void setup(); /* setup function for the test */ |
| 80 | void cleanup(); /* cleanup function for the test */ |
| 81 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 82 | #if !defined(UCLINUX) |
| 83 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 84 | int main(int ac, char **av) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 85 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 86 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 87 | const char *msg; |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 88 | int gidsetsize; /* total no. of groups */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | char *test_desc; /* test specific error message */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 90 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 91 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 92 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 93 | |
| 94 | /* Perform setup for test */ |
| 95 | setup(); |
| 96 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 97 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 98 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 99 | tst_count = 0; |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 100 | |
| 101 | gidsetsize = NGROUPS; |
| 102 | test_desc = "EFAULT"; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 103 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 104 | /* |
| 105 | * Call setgroups() to test condition |
| 106 | * verify that it fails with -1 return value and |
| 107 | * sets appropriate errno. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 108 | */ |
Stanislav Kholmanskikh | ce0dffe | 2013-09-05 11:01:48 +0400 | [diff] [blame] | 109 | TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0))); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 110 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 111 | if (TEST_RETURN != -1) { |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 112 | tst_resm(TFAIL, "setgroups() returned %ld, " |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 113 | "expected -1, errno=%d", TEST_RETURN, |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 114 | EFAULT); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | } else { |
| 116 | |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 117 | if (TEST_ERRNO == EFAULT) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | tst_resm(TPASS, |
| 119 | "setgroups() fails with expected " |
| 120 | "error EFAULT errno:%d", TEST_ERRNO); |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 121 | } else { |
| 122 | tst_resm(TFAIL, "setgroups() fails, %s, " |
| 123 | "errno=%d, expected errno=%d", |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 124 | test_desc, TEST_ERRNO, EFAULT); |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 128 | } |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 129 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 130 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 131 | tst_exit(); |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 132 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 133 | } |
| 134 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 135 | #else |
| 136 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 137 | int main(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 138 | { |
vapier | 81a6307 | 2006-02-27 04:29:21 +0000 | [diff] [blame] | 139 | tst_resm(TINFO, "test is not available on uClinux"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 140 | tst_exit(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 141 | } |
| 142 | |
robbiew | 61f8e60 | 2005-08-02 17:51:41 +0000 | [diff] [blame] | 143 | #endif /* if !defined(UCLINUX) */ |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 144 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 145 | /* |
| 146 | * setup() |
| 147 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 148 | void setup(void) |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 149 | { |
Nicolas Joly | d4ceb37 | 2014-06-22 17:03:57 +0200 | [diff] [blame] | 150 | tst_require_root(NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 152 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 153 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 154 | TEST_PAUSE; |
| 155 | |
| 156 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 157 | |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 158 | /* |
| 159 | * cleanup() |
| 160 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 161 | void cleanup(void) |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 162 | { |
robbiew | 8da5497 | 2002-05-30 18:50:35 +0000 | [diff] [blame] | 163 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 164 | } |