1d13d74bbf207c2d01598c6fef092a75b93b07c71vapier/* 20e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * Copyright (C) International Business Machines Corp., 2001 30e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * Ported by Wayne Boyer 40e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * Adapted by Dustin Kirkland (k1rkland@us.ibm.com) 5d13d74bbf207c2d01598c6fef092a75b93b07c71vapier * 60e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * This program is free software; you can redistribute it and/or modify 70e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * it under the terms of the GNU General Public License as published by 80e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * the Free Software Foundation; either version 2 of the License, or 90e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * (at your option) any later version. 10d13d74bbf207c2d01598c6fef092a75b93b07c71vapier * 110e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * This program is distributed in the hope that it will be useful, 120e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * but WITHOUT ANY WARRANTY; without even the implied warranty of 130e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 140e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * the GNU General Public License for more details. 15d13d74bbf207c2d01598c6fef092a75b93b07c71vapier * 160e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * You should have received a copy of the GNU General Public License 170e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * along with this program; if not, write to the Free Software 180e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19d13d74bbf207c2d01598c6fef092a75b93b07c71vapier */ 20d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 21d13d74bbf207c2d01598c6fef092a75b93b07c71vapier/* 220e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * Testcase to test the basic functionality of the setfsuid(2) system 230e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh * call to fail on invalid uid. 24d13d74bbf207c2d01598c6fef092a75b93b07c71vapier */ 250e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh 26d13d74bbf207c2d01598c6fef092a75b93b07c71vapier#include <stdio.h> 27d13d74bbf207c2d01598c6fef092a75b93b07c71vapier#include <unistd.h> 28d13d74bbf207c2d01598c6fef092a75b93b07c71vapier#include <pwd.h> 29d13d74bbf207c2d01598c6fef092a75b93b07c71vapier#include <sys/types.h> 30d13d74bbf207c2d01598c6fef092a75b93b07c71vapier#include <errno.h> 310e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh 32d13d74bbf207c2d01598c6fef092a75b93b07c71vapier#include "test.h" 330e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh#include "compat_16.h" 34d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 350e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikhstatic void setup(void); 360e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikhstatic void cleanup(void); 37d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 380e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav KholmanskikhTCID_DEFINE(setfsuid02); 39d13d74bbf207c2d01598c6fef092a75b93b07c71vapierint TST_TOTAL = 1; 40d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 41d13d74bbf207c2d01598c6fef092a75b93b07c71vapierint main(int ac, char **av) 42d13d74bbf207c2d01598c6fef092a75b93b07c71vapier{ 4389af32a63ce8a780ea39337339e14caae244b5a4Cyril Hrubis int lc; 44d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 45d13d74bbf207c2d01598c6fef092a75b93b07c71vapier uid_t uid; 46bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 47d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(ac, av, NULL, NULL); 48d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 49d13d74bbf207c2d01598c6fef092a75b93b07c71vapier setup(); 50d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 5156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak uid = 1; 520e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh while (getpwuid(uid)) 5356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak uid++; 54d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 550e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh UID16_CHECK(uid, setfsuid, cleanup); 560e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh 57d13d74bbf207c2d01598c6fef092a75b93b07c71vapier for (lc = 0; TEST_LOOPING(lc); lc++) { 58d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 59d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 60d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 610e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh TEST(SETFSUID(cleanup, uid)); 62d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 63d13d74bbf207c2d01598c6fef092a75b93b07c71vapier if (TEST_RETURN == -1) { 640e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh tst_resm(TFAIL | TTERRNO, 650e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh "setfsuid() failed unexpectedly"); 66d13d74bbf207c2d01598c6fef092a75b93b07c71vapier continue; 67d13d74bbf207c2d01598c6fef092a75b93b07c71vapier } 68d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 69d13d74bbf207c2d01598c6fef092a75b93b07c71vapier if (TEST_RETURN == uid) { 70923b23ff1fd1b77bd895949f9a6b4508c6485f33subrata_modak tst_resm(TFAIL, "setfsuid() returned %ld, expected %d", 71d13d74bbf207c2d01598c6fef092a75b93b07c71vapier TEST_RETURN, uid); 72d13d74bbf207c2d01598c6fef092a75b93b07c71vapier } else { 73d13d74bbf207c2d01598c6fef092a75b93b07c71vapier tst_resm(TPASS, "setfsuid() returned expected value : " 74923b23ff1fd1b77bd895949f9a6b4508c6485f33subrata_modak "%ld", TEST_RETURN); 75d13d74bbf207c2d01598c6fef092a75b93b07c71vapier } 76d13d74bbf207c2d01598c6fef092a75b93b07c71vapier } 770e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikh 78d13d74bbf207c2d01598c6fef092a75b93b07c71vapier cleanup(); 791e6f5a673655551de5734ff31ef48cd63b604e6dGarrett Cooper tst_exit(); 80354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao} 81d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 820e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikhstatic void setup(void) 83d13d74bbf207c2d01598c6fef092a75b93b07c71vapier{ 84d13d74bbf207c2d01598c6fef092a75b93b07c71vapier tst_sig(NOFORK, DEF_HANDLER, cleanup); 85d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 86d13d74bbf207c2d01598c6fef092a75b93b07c71vapier TEST_PAUSE; 87d13d74bbf207c2d01598c6fef092a75b93b07c71vapier} 88d13d74bbf207c2d01598c6fef092a75b93b07c71vapier 890e7a99b5316fdefc8fb8df77e7d0e2abff7511acStanislav Kholmanskikhstatic void cleanup(void) 90d13d74bbf207c2d01598c6fef092a75b93b07c71vapier{ 91ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 92