Skip to content

Commit f362840

Browse files
committed
LoginServer: Create well known home dirs when missing on first login
1 parent ad23718 commit f362840

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Userland/Services/LoginServer/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <sys/wait.h>
1919
#include <unistd.h>
2020

21+
static constexpr Array WELL_KNOWN_HOME_DIRS = { "Desktop"sv, "Documents"sv, "Downloads"sv, "Music"sv, "Pictures"sv, "Videos"sv };
22+
2123
static void child_process(Core::Account const& account)
2224
{
2325
pid_t rc = setsid();
@@ -31,6 +33,15 @@ static void child_process(Core::Account const& account)
3133
exit(1);
3234
}
3335

36+
// Create well-known home subdirectories when not existing
37+
for (auto dir : WELL_KNOWN_HOME_DIRS) {
38+
auto path = MUST(String::formatted("{}/{}", account.home_directory(), dir));
39+
if (FileSystem::exists(path))
40+
continue;
41+
MUST(Core::System::mkdir(path, 0755));
42+
MUST(Core::System::chown(path, account.uid(), account.gid()));
43+
}
44+
3445
if (auto const result = account.login(); result.is_error()) {
3546
dbgln("failed to switch users: {}", result.error());
3647
exit(1);
@@ -65,7 +76,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
6576
auto app = TRY(GUI::Application::create(arguments));
6677

6778
TRY(Core::System::pledge("stdio recvfd sendfd cpath chown rpath exec proc id"));
68-
TRY(Core::System::unveil("/home", "r"));
79+
TRY(Core::System::unveil("/home", "rwc"));
6980
TRY(Core::System::unveil("/tmp", "c"));
7081
TRY(Core::System::unveil("/etc/passwd", "r"));
7182
TRY(Core::System::unveil("/etc/shadow", "r"));

0 commit comments

Comments
 (0)