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