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