Serenity Operating System
1/*
2 * Copyright (c) 2020, the SerenityOS developers.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <fcntl.h>
8#include <stdio.h>
9#include <sys/stat.h>
10#include <unistd.h>
11
12int main()
13{
14 rmdir("/tmp/foo/1");
15 rmdir("/tmp/foo");
16 unlink("/tmp/bar");
17
18 if (mkdir("/tmp/foo", 0755) < 0) {
19 perror("mkdir");
20 return 1;
21 }
22
23 if (mkdir("/tmp/foo/1", 0755) < 0) {
24 perror("mkdir");
25 return 1;
26 }
27
28 if (symlink("/tmp/foo", "/tmp/bar")) {
29 perror("symlink");
30 return 1;
31 }
32
33 if (unveil("/tmp/foo", "r") < 0) {
34 perror("unveil");
35 return 1;
36 }
37
38 if (unveil(nullptr, nullptr) < 0) {
39 perror("unveil");
40 return 1;
41 }
42
43 int fd = open("/tmp/foo/1", O_RDONLY);
44 if (fd < 0) {
45 perror("open");
46 return 1;
47 }
48 close(fd);
49
50 fd = open("/tmp/bar/1", O_RDONLY);
51 if (fd >= 0) {
52 fprintf(stderr, "FAIL, symlink was not unveiled\n");
53 return 1;
54 }
55
56 if (chdir("/tmp")) {
57 perror("chdir");
58 return 1;
59 }
60
61 fd = open("./foo/1", O_RDONLY);
62 if (fd < 0) {
63 perror("open");
64 return 1;
65 }
66 close(fd);
67
68 fd = open("./bar/1", O_RDONLY);
69 if (fd >= 0) {
70 fprintf(stderr, "FAIL, symlink was not unveiled\n");
71 return 1;
72 }
73
74 printf("PASS\n");
75 return 0;
76}