1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

userdel: Use pledge() and unveil()

This commit is contained in:
Brendan Coles 2021-01-12 06:39:08 +00:00 committed by Andreas Kling
parent eece9edd91
commit 959970e060

View file

@ -43,6 +43,23 @@
int main(int argc, char** argv)
{
if (pledge("stdio wpath rpath cpath fattr proc exec", nullptr) < 0) {
perror("pledge");
return 1;
}
if (unveil("/etc/", "rwc") < 0) {
perror("unveil");
return 1;
}
if (unveil("/bin/rm", "x") < 0) {
perror("unveil");
return 1;
}
unveil(nullptr, nullptr);
const char* username = nullptr;
bool remove_home = false;
@ -51,6 +68,13 @@ int main(int argc, char** argv)
args_parser.add_positional_argument(username, "Login user identity (username)", "login");
args_parser.parse(argc, argv);
if (!remove_home) {
if (pledge("stdio wpath rpath cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
}
char temp_filename[] = "/etc/passwd.XXXXXX";
auto fd = mkstemp(temp_filename);
if (fd == -1) {