vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * setfsgid02.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Testcase to check the basic functionality of setfsgid(2) system |
| 26 | * call failures. |
| 27 | * |
| 28 | * ALGORITHM |
| 29 | * Call setfsgid() and test the return value when invalid gid used. |
| 30 | * |
| 31 | * USAGE: <for command-line> |
| 32 | * setfsgid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] |
| 33 | * where, -c n : Run n copies concurrently. |
| 34 | * -f : Turn off functionality Testing. |
| 35 | * -i n : Execute test n times. |
| 36 | * -I x : Execute test for x seconds. |
| 37 | * -P x : Pause for x seconds between iterations. |
| 38 | * -t : Turn on syscall timing. |
| 39 | * |
| 40 | * HISTORY |
| 41 | * 07/2001 Ported by Wayne Boyer |
| 42 | * 04/2003 Adapted by Dustin Kirkland (k1rkland@us.ibm.com) |
| 43 | * |
| 44 | * RESTRICTIONS |
| 45 | * None |
| 46 | */ |
| 47 | #include <stdio.h> |
| 48 | #include <unistd.h> |
| 49 | #include <grp.h> |
| 50 | #include <pwd.h> |
| 51 | #include <sys/types.h> |
| 52 | #include <errno.h> |
| 53 | #ifdef __GLIBC__ |
| 54 | #include <sys/fsuid.h> |
| 55 | #endif |
| 56 | #include "test.h" |
| 57 | #include "usctest.h" |
| 58 | |
| 59 | char *TCID = "setfsgid02"; |
| 60 | int TST_TOTAL = 1; |
| 61 | extern int Tst_count; |
| 62 | |
| 63 | void setup(void); |
| 64 | void cleanup(void); |
| 65 | |
| 66 | int main(int ac, char **av) |
| 67 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 68 | int lc; /* loop counter */ |
| 69 | char *msg; /* message returned from parse_opts */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 70 | |
| 71 | gid_t gid; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 72 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 73 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame^] | 74 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 75 | tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); |
| 76 | } |
| 77 | |
| 78 | setup(); |
| 79 | |
| 80 | /* Check for looping state if -i option is given */ |
| 81 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 82 | /* reset Tst_count in case we are looping */ |
| 83 | Tst_count = 0; |
| 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | gid = 1; |
| 86 | while (getgrgid(gid)) { |
| 87 | gid++; |
| 88 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 89 | |
| 90 | TEST(setfsgid(gid)); |
| 91 | |
| 92 | if (TEST_RETURN == -1) { |
| 93 | tst_resm(TFAIL, "call failed unexpectedly - errno %d", |
| 94 | TEST_ERRNO); |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | if (!STD_FUNCTIONAL_TEST) { |
| 99 | tst_resm(TPASS, "call succeeded"); |
| 100 | continue; |
| 101 | } |
| 102 | |
| 103 | if (TEST_RETURN == gid) { |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 104 | tst_resm(TFAIL, "setfsgid() returned %ld, expected %d", |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 105 | TEST_RETURN, gid); |
| 106 | } else { |
| 107 | tst_resm(TPASS, "setfsgid() returned expected value : " |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 108 | "%ld", TEST_RETURN); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | cleanup(); |
| 112 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | /*NOTREACHED*/ return EXIT_SUCCESS; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * setup() - performs all ONE TIME setup for this test. |
| 118 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | void setup() |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 120 | { |
| 121 | /* capture signals */ |
| 122 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 123 | |
| 124 | /* Pause if that option was specified */ |
| 125 | TEST_PAUSE; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 130 | * completion or premature exit. |
| 131 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | void cleanup() |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 133 | { |
| 134 | /* |
| 135 | * print timing stats if that option was specified. |
| 136 | * print errno log if that option was specified. |
| 137 | */ |
| 138 | TEST_CLEANUP; |
| 139 | |
| 140 | /* exit with return code appropriate for results */ |
| 141 | tst_exit(); |
| 142 | } |