1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci
3f08c3bdfSopenharmony_ci/*
4f08c3bdfSopenharmony_ci *   Copyright (C) Bull S.A. 2001
5f08c3bdfSopenharmony_ci *   Copyright (c) International Business Machines  Corp., 2001
6f08c3bdfSopenharmony_ci *		05/2002 Ported by Jacky Malcles
7f08c3bdfSopenharmony_ci *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
8f08c3bdfSopenharmony_ci */
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_ci/*\
11f08c3bdfSopenharmony_ci * [Description]
12f08c3bdfSopenharmony_ci *
13f08c3bdfSopenharmony_ci * Verify that statfs(2) fails with errno EACCES when search permission
14f08c3bdfSopenharmony_ci * is denied for a component of the path prefix of path.
15f08c3bdfSopenharmony_ci */
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ci#include <pwd.h>
18f08c3bdfSopenharmony_ci#include "tst_test.h"
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci#define TEMP_DIR "testdir"
21f08c3bdfSopenharmony_ci#define TEMP_DIR2 TEMP_DIR"/subdir"
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_cistatic void setup(void)
24f08c3bdfSopenharmony_ci{
25f08c3bdfSopenharmony_ci	struct passwd *ltpuser;
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_ci	SAFE_MKDIR(TEMP_DIR, 0444);
28f08c3bdfSopenharmony_ci	SAFE_MKDIR(TEMP_DIR2, 0444);
29f08c3bdfSopenharmony_ci
30f08c3bdfSopenharmony_ci	ltpuser = SAFE_GETPWNAM("nobody");
31f08c3bdfSopenharmony_ci	SAFE_SETEUID(ltpuser->pw_uid);
32f08c3bdfSopenharmony_ci}
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_cistatic void run(void)
35f08c3bdfSopenharmony_ci{
36f08c3bdfSopenharmony_ci	struct statfs buf;
37f08c3bdfSopenharmony_ci
38f08c3bdfSopenharmony_ci	TST_EXP_FAIL(statfs(TEMP_DIR2, &buf), EACCES);
39f08c3bdfSopenharmony_ci}
40f08c3bdfSopenharmony_ci
41f08c3bdfSopenharmony_cistatic struct tst_test test = {
42f08c3bdfSopenharmony_ci	.setup = setup,
43f08c3bdfSopenharmony_ci	.test_all = run,
44f08c3bdfSopenharmony_ci	.needs_tmpdir = 1,
45f08c3bdfSopenharmony_ci	.needs_root = 1
46f08c3bdfSopenharmony_ci};
47