mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
Userland: userdel: Resolve home directory realpath before removal
This commit is contained in:
parent
58c52b155a
commit
a3fdf5148b
1 changed files with 21 additions and 17 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibCore/File.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -116,12 +117,16 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove_home) {
|
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");
|
fprintf(stderr, "home directory is /, not deleted!\n");
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(home_directory.characters(), F_OK) != -1) {
|
|
||||||
pid_t child;
|
pid_t child;
|
||||||
const char* argv[] = { "rm", "-r", home_directory.characters(), nullptr };
|
const char* argv[] = { "rm", "-r", home_directory.characters(), nullptr };
|
||||||
if ((errno = posix_spawn(&child, "/bin/rm", nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
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 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue