plars | 865695b | 2001-08-27 22:15:12 +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 | * setfsuid01.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Testcase to test the basic functionality of the setfsuid(2) system |
| 26 | * call. |
| 27 | * |
| 28 | * ALGORITHM |
| 29 | * Call setfsuid(2) and test the uid returned by setfsuid(2). |
| 30 | * If the returned value doesn't match the uid of the process, |
| 31 | * then the testcase fails. |
| 32 | * |
| 33 | * USAGE: <for command-line> |
| 34 | * setfsuid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] |
| 35 | * where, -c n : Run n copies concurrently. |
| 36 | * -f : Turn off functionality Testing. |
| 37 | * -i n : Execute test n times. |
| 38 | * -I x : Execute test for x seconds. |
| 39 | * -P x : Pause for x seconds between iterations. |
| 40 | * -t : Turn on syscall timing. |
| 41 | * |
| 42 | * HISTORY |
| 43 | * 07/2001 Ported by Wayne Boyer |
| 44 | * |
| 45 | * RESTRICTIONS |
| 46 | * None |
| 47 | */ |
robbiew | da0cc97 | 2003-03-28 17:18:51 +0000 | [diff] [blame^] | 48 | #include <sys/types.h> |
| 49 | #include <sys/fsuid.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | #include <stdio.h> |
| 51 | #include <unistd.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | #include <errno.h> |
| 53 | #include "test.h" |
| 54 | #include "usctest.h" |
| 55 | |
| 56 | void setup(void); |
| 57 | void cleanup(void); |
| 58 | |
| 59 | char *TCID = "setfsuid01"; |
| 60 | int TST_TOTAL = 1; |
| 61 | extern int Tst_count; |
| 62 | |
robbiew | da0cc97 | 2003-03-28 17:18:51 +0000 | [diff] [blame^] | 63 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | { |
| 65 | int lc; /* loop counter */ |
| 66 | char *msg; /* message returned from parse_opts */ |
| 67 | |
| 68 | uid_t uid; |
| 69 | |
| 70 | /* parse standard options */ |
| 71 | if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ |
| 72 | tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); |
| 73 | } |
| 74 | |
| 75 | setup(); |
| 76 | |
| 77 | uid = geteuid(); |
| 78 | |
| 79 | /* Check for looping state if -i option is given */ |
| 80 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 81 | |
| 82 | /* reset Tst_count in case we are looping */ |
| 83 | Tst_count = 0; |
| 84 | |
| 85 | TEST(setfsuid(uid)); |
| 86 | |
| 87 | if (TEST_RETURN == -1) { |
| 88 | tst_resm(TFAIL, "call failed unexpectedly - errno %d", |
| 89 | TEST_ERRNO); |
| 90 | continue; |
| 91 | } |
| 92 | |
| 93 | if (!STD_FUNCTIONAL_TEST) { |
| 94 | tst_resm(TPASS, "call succeeded"); |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | if (TEST_RETURN != uid) { |
| 99 | tst_resm(TFAIL, "setfsuid() returned %d, expected %d", |
| 100 | TEST_RETURN, uid); |
| 101 | } else { |
| 102 | tst_resm(TPASS, "setfsuid() returned expected value : " |
| 103 | "%d", uid); |
| 104 | } |
| 105 | } |
| 106 | cleanup(); |
| 107 | |
| 108 | /*NOTREACHED*/ |
robbiew | da0cc97 | 2003-03-28 17:18:51 +0000 | [diff] [blame^] | 109 | return(0); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * setup() - performs all ONE TIME setup for this test. |
| 114 | */ |
| 115 | void |
| 116 | setup() |
| 117 | { |
| 118 | /* capture signals */ |
| 119 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 120 | |
| 121 | /* Pause if that option was specified */ |
| 122 | TEST_PAUSE; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 127 | * completion or premature exit. |
| 128 | */ |
| 129 | void |
| 130 | cleanup() |
| 131 | { |
| 132 | /* |
| 133 | * print timing stats if that option was specified. |
| 134 | * print errno log if that option was specified. |
| 135 | */ |
| 136 | TEST_CLEANUP; |
| 137 | } |