1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) Bull S.A. 2001 4 * Copyright (c) International Business Machines Corp., 2001 5 * 6 * 04/2002 Ported by Jacky Malcles 7 */ 8 9 /*\ 10 * [Description] 11 * 12 * Testcase to check that chroot sets errno to EACCES. 13 * 14 * As a non-root user attempt to perform chroot() to a directory that the user 15 * does not have a search permission for. The chroot() call should fail with 16 * EACESS. 17 */ 18 19 #include <stdio.h> 20 #include <pwd.h> 21 #include "tst_test.h" 22 23 #define TEST_TMPDIR "chroot04_tmpdir" 24 verify_chroot(void)25static void verify_chroot(void) 26 { 27 TST_EXP_FAIL(chroot(TEST_TMPDIR), EACCES, "no search permission chroot()"); 28 } 29 setup(void)30static void setup(void) 31 { 32 struct passwd *ltpuser; 33 34 SAFE_MKDIR(TEST_TMPDIR, 0222); 35 36 ltpuser = SAFE_GETPWNAM("nobody"); 37 SAFE_SETEUID(ltpuser->pw_uid); 38 } 39 40 static struct tst_test test = { 41 .setup = setup, 42 .test_all = verify_chroot, 43 .needs_root = 1, 44 .needs_tmpdir = 1, 45 }; 46