1 /* 2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it would be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * You should have received a copy of the GNU General Public License along 13 * with this program; if not, write the Free Software Foundation, Inc., 14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15 * 16 * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi (at) wipro.com> 17 * 18 * DESCRIPTION 19 * Verify that umount(2) returns -1 and sets errno to EPERM if the user 20 * is not the super-user. 21 */ 22 23 #include <errno.h> 24 #include <pwd.h> 25 #include <sys/mount.h> 26 #include <sys/types.h> 27 #include <unistd.h> 28 #include "tst_test.h" 29 30 #define MNTPOINT "mntpoint" 31 32 static int mount_flag; 33 34 static void verify_umount(void) 35 { 36 TEST(umount(MNTPOINT)); 37 38 if (TEST_RETURN != -1) { 39 tst_res(TFAIL, "umount() succeeds unexpectedly"); 40 return; 41 } 42 43 if (TEST_ERRNO != EPERM) { 44 tst_res(TFAIL | TTERRNO, "umount() should fail with EPERM"); 45 return; 46 } 47 48 tst_res(TPASS | TTERRNO, "umount() fails as expected"); 49 } 50 51 static void setup(void) 52 { 53 struct passwd *pw; 54 55 SAFE_MKDIR(MNTPOINT, 0775); 56 SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL); 57 mount_flag = 1; 58 59 pw = SAFE_GETPWNAM("nobody"); 60 SAFE_SETEUID(pw->pw_uid); 61 } 62 63 static void cleanup(void) 64 { 65 if (seteuid(0)) 66 tst_res(TWARN | TERRNO, "seteuid(0) Failed"); 67 68 if (mount_flag) 69 tst_umount(MNTPOINT); 70 } 71 72 static struct tst_test test = { 73 .needs_root = 1, 74 .needs_tmpdir = 1, 75 .format_device = 1, 76 .setup = setup, 77 .cleanup = cleanup, 78 .test_all = verify_umount, 79 }; 80