1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4 * Author: Nirmala Devi Dhanasekar <nirmala.devi@wipro.com> 5 * 6 * Verify that umount(2) returns -1 and sets errno to EPERM if the user 7 * is not the super-user. 8 */ 9 10#include <errno.h> 11#include <pwd.h> 12#include <sys/mount.h> 13#include <sys/types.h> 14#include <unistd.h> 15#include "tst_test.h" 16 17#define MNTPOINT "mntpoint" 18 19static int mount_flag; 20 21static void verify_umount(void) 22{ 23 TEST(umount(MNTPOINT)); 24 25 if (TST_RET != -1) { 26 tst_res(TFAIL, "umount() succeeds unexpectedly"); 27 return; 28 } 29 30 if (TST_ERR != EPERM) { 31 tst_res(TFAIL | TTERRNO, "umount() should fail with EPERM"); 32 return; 33 } 34 35 tst_res(TPASS | TTERRNO, "umount() fails as expected"); 36} 37 38static void setup(void) 39{ 40 struct passwd *pw; 41 42 SAFE_MKDIR(MNTPOINT, 0775); 43 SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL); 44 mount_flag = 1; 45 46 pw = SAFE_GETPWNAM("nobody"); 47 SAFE_SETEUID(pw->pw_uid); 48} 49 50static void cleanup(void) 51{ 52 if (seteuid(0)) 53 tst_res(TWARN | TERRNO, "seteuid(0) Failed"); 54 55 if (mount_flag) 56 tst_umount(MNTPOINT); 57} 58 59static struct tst_test test = { 60 .needs_root = 1, 61 .format_device = 1, 62 .setup = setup, 63 .cleanup = cleanup, 64 .test_all = verify_umount, 65}; 66