• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Copyright (c) International Business Machines Corp., 2001
3  */
4 
5 /*
6  * Verify that user cannot create a directory inside directory owned by another
7  * user with restrictive permissions and that the errno is set to EACCESS.
8  */
9 
10 #include <errno.h>
11 #include <sys/types.h>
12 #include <pwd.h>
13 #include "tst_test.h"
14 #include "tst_uid.h"
15 
16 #define TESTDIR	 "testdir"
17 #define TESTSUBDIR "testdir/testdir"
18 
verify_mkdir(void)19 static void verify_mkdir(void)
20 {
21 	if (mkdir(TESTSUBDIR, 0777) != -1) {
22 		tst_res(TFAIL, "mkdir(%s, %#o) succeeded unexpectedly",
23 			TESTSUBDIR, 0777);
24 		return;
25 	}
26 
27 	if (errno != EACCES) {
28 		tst_res(TFAIL | TERRNO, "Expected EACCES got");
29 		return;
30 	}
31 
32 	tst_res(TPASS | TERRNO, "mkdir() failed expectedly");
33 }
34 
setup(void)35 static void setup(void)
36 {
37 	uid_t test_users[2];
38 
39 	tst_get_uids(test_users, 0, 2);
40 
41 	SAFE_MKDIR(TESTDIR, 0700);
42 	SAFE_CHOWN(TESTDIR, test_users[0], getgid());
43 
44 	SAFE_SETREUID(test_users[1], test_users[1]);
45 }
46 
47 static struct tst_test test = {
48 	.test_all = verify_mkdir,
49 	.needs_tmpdir = 1,
50 	.needs_root = 1,
51 	.setup = setup,
52 };
53