1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

Userland: userdel: Resolve home directory realpath before removal

This commit is contained in:
Brendan Coles 2020-12-21 10:41:08 +00:00 committed by Andreas Kling
parent 58c52b155a
commit a3fdf5148b

View file

@ -27,6 +27,7 @@
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
@ -116,12 +117,16 @@ int main(int argc, char** argv)
}
if (remove_home) {
if (home_directory == "/") {
if (access(home_directory.characters(), F_OK) == -1)
return 0;
String real_path = Core::File::real_path_for(home_directory);
if (real_path == "/") {
fprintf(stderr, "home directory is /, not deleted!\n");
return 12;
}
if (access(home_directory.characters(), F_OK) != -1) {
pid_t child;
const char* argv[] = { "rm", "-r", home_directory.characters(), nullptr };
if ((errno = posix_spawn(&child, "/bin/rm", nullptr, nullptr, const_cast<char**>(argv), environ))) {
@ -138,7 +143,6 @@ int main(int argc, char** argv)
return 12;
}
}
}
return 0;
}