1 /*
2 * Copyright (c) 2016-2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #include "tests.h"
9 #include "scno.h"
10
11 #ifdef __NR_access
12
13 # include <fcntl.h>
14 # include <stdio.h>
15 # include <unistd.h>
16
17 # include "secontext.h"
18
19 int
20 main(void)
21 {
22 /*
23 * Make sure the current workdir of the tracee
24 * is different from the current workdir of the tracer.
25 */
26 create_and_enter_subdir("access_subdir");
27
28 char *my_secontext = SECONTEXT_PID_MY();
29
30 static const char sample[] = "access_sample";
31 (void) unlink(sample);
32 if (open(sample, O_CREAT|O_RDONLY, 0400) == -1)
33 perror_msg_and_fail("open: %s", sample);
34
35 long rc = syscall(__NR_access, sample, F_OK);
36 printf("%s%s(\"%s\"%s, F_OK) = %s\n",
37 my_secontext, "access",
38 sample, SECONTEXT_FILE(sample),
39 sprintrc(rc));
40
41 if (unlink(sample))
42 perror_msg_and_fail("unlink: %s", sample);
43
44 rc = syscall(__NR_access, sample, R_OK|W_OK|X_OK);
45 printf("%s%s(\"%s\", R_OK|W_OK|X_OK) = %s\n",
46 my_secontext, "access",
47 sample,
48 sprintrc(rc));
49
50 leave_and_remove_subdir();
51
52 puts("+++ exited with 0 +++");
53 return 0;
54 }
55
56 #else
57
58 SKIP_MAIN_UNDEFINED("__NR_access")
59
60 #endif