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 when called by a user other than root. 24 */ 25 26 #include <stdio.h> 27 #include <unistd.h> 28 #include <sys/types.h> 29 #include <errno.h> 30 #include <pwd.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(setfsuid03); 39 int TST_TOTAL = 1; 40 41 static char nobody_uid[] = "nobody"; 42 static struct passwd *ltpuser; 43 44 int main(int ac, char **av) 45 { 46 int lc; 47 48 uid_t uid; 49 50 tst_parse_opts(ac, av, NULL, NULL); 51 52 setup(); 53 54 uid = 1; 55 while (!getpwuid(uid)) 56 uid++; 57 58 UID16_CHECK(uid, setfsuid, cleanup); 59 60 for (lc = 0; TEST_LOOPING(lc); lc++) { 61 62 tst_count = 0; 63 64 TEST(SETFSUID(cleanup, uid)); 65 66 if (TEST_RETURN == -1) { 67 tst_resm(TFAIL | TTERRNO, 68 "setfsuid() failed unexpectedly"); 69 continue; 70 } 71 72 if (TEST_RETURN == uid) { 73 tst_resm(TFAIL, 74 "setfsuid() returned %ld, expected anything but %d", 75 TEST_RETURN, uid); 76 } else { 77 tst_resm(TPASS, "setfsuid() returned expected value : " 78 "%ld", TEST_RETURN); 79 } 80 } 81 82 cleanup(); 83 tst_exit(); 84 } 85 86 static void setup(void) 87 { 88 tst_require_root(); 89 90 ltpuser = getpwnam(nobody_uid); 91 if (ltpuser == NULL) 92 tst_brkm(TBROK, cleanup, "getpwnam failed for user id %s", 93 nobody_uid); 94 95 if (setuid(ltpuser->pw_uid) == -1) 96 tst_resm(TINFO | TERRNO, "setuid failed to " 97 "to set the effective uid to %d", ltpuser->pw_uid); 98 99 tst_sig(NOFORK, DEF_HANDLER, cleanup); 100 101 TEST_PAUSE; 102 } 103 104 static void cleanup(void) 105 { 106 } 107