1 /* 2 * Copyright (C) International Business Machines Corp., 2001 3 * Ported by Wayne Boyer 4 * Adapted by Dustin Kirkland (k1rkland (at) us.ibm.com) 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14 * the GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 /* 22 * Testcase to test the basic functionality of the setfsuid(2) system 23 * call to fail on invalid uid. 24 */ 25 26 #include <stdio.h> 27 #include <unistd.h> 28 #include <pwd.h> 29 #include <sys/types.h> 30 #include <errno.h> 31 32 #include "test.h" 33 #include "compat_16.h" 34 35 static void setup(void); 36 static void cleanup(void); 37 38 TCID_DEFINE(setfsuid02); 39 int TST_TOTAL = 1; 40 41 int main(int ac, char **av) 42 { 43 int lc; 44 45 uid_t uid; 46 47 tst_parse_opts(ac, av, NULL, NULL); 48 49 setup(); 50 51 uid = 1; 52 while (getpwuid(uid)) 53 uid++; 54 55 UID16_CHECK(uid, setfsuid, cleanup); 56 57 for (lc = 0; TEST_LOOPING(lc); lc++) { 58 59 tst_count = 0; 60 61 TEST(SETFSUID(cleanup, uid)); 62 63 if (TEST_RETURN == -1) { 64 tst_resm(TFAIL | TTERRNO, 65 "setfsuid() failed unexpectedly"); 66 continue; 67 } 68 69 if (TEST_RETURN == uid) { 70 tst_resm(TFAIL, "setfsuid() returned %ld, expected %d", 71 TEST_RETURN, uid); 72 } else { 73 tst_resm(TPASS, "setfsuid() returned expected value : " 74 "%ld", TEST_RETURN); 75 } 76 } 77 78 cleanup(); 79 tst_exit(); 80 } 81 82 static void setup(void) 83 { 84 tst_sig(NOFORK, DEF_HANDLER, cleanup); 85 86 TEST_PAUSE; 87 } 88 89 static void cleanup(void) 90 { 91 } 92