mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
SystemServer: Detect spawning user for AcceptSocketConnections services
SystemServer now invokes services with the same uid as the process that made the request. This allows the superuser to have a normal GUI workflow. For example, read and write its own files in TextEditor.
This commit is contained in:
parent
5d5eccc91f
commit
f467ebc933
2 changed files with 17 additions and 0 deletions
|
@ -98,6 +98,8 @@ void Service::handle_socket_connection()
|
|||
}
|
||||
|
||||
int accepted_fd = maybe_accepted_fd.release_value();
|
||||
// FIXME: Propagate errors
|
||||
MUST(determine_account(accepted_fd));
|
||||
spawn(accepted_fd);
|
||||
close(accepted_fd);
|
||||
} else {
|
||||
|
@ -401,3 +403,16 @@ bool Service::is_enabled() const
|
|||
extern String g_system_mode;
|
||||
return m_system_modes.contains_slow(g_system_mode);
|
||||
}
|
||||
|
||||
ErrorOr<void> Service::determine_account(int fd)
|
||||
{
|
||||
struct ucred creds = {};
|
||||
socklen_t creds_size = sizeof(creds);
|
||||
TRY(Core::System::getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &creds_size));
|
||||
|
||||
auto const directory_name = String::formatted("/proc/{}/", creds.pid);
|
||||
auto const stat = TRY(Core::System::stat(directory_name.characters()));
|
||||
|
||||
m_account = TRY(Core::Account::from_uid(stat.st_uid));
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ private:
|
|||
|
||||
void spawn(int socket_fd = -1);
|
||||
|
||||
ErrorOr<void> determine_account(int fd);
|
||||
|
||||
/// SocketDescriptor describes the details of a single socket that was
|
||||
/// requested by a service.
|
||||
struct SocketDescriptor {
|
||||
|
|
Loading…
Add table
Reference in a new issue