1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-13 23:47:36 +00:00
serenity/Userland/Tests/Kernel/unveil-symlinks.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

76 lines
1.3 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
rmdir("/tmp/foo/1");
rmdir("/tmp/foo");
unlink("/tmp/bar");
if (mkdir("/tmp/foo", 0755) < 0) {
perror("mkdir");
return 1;
}
if (mkdir("/tmp/foo/1", 0755) < 0) {
perror("mkdir");
return 1;
}
if (symlink("/tmp/foo", "/tmp/bar")) {
perror("symlink");
return 1;
}
if (unveil("/tmp/foo", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
int fd = open("/tmp/foo/1", O_RDONLY);
if (fd < 0) {
perror("open");
return 1;
}
close(fd);
fd = open("/tmp/bar/1", O_RDONLY);
if (fd >= 0) {
fprintf(stderr, "FAIL, symlink was not unveiled\n");
return 1;
}
if (chdir("/tmp")) {
perror("chdir");
return 1;
}
fd = open("./foo/1", O_RDONLY);
if (fd < 0) {
perror("open");
return 1;
}
close(fd);
fd = open("./bar/1", O_RDONLY);
if (fd >= 0) {
fprintf(stderr, "FAIL, symlink was not unveiled\n");
return 1;
}
printf("PASS\n");
return 0;
}