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

ProtocolServer: Turn this into a multi-instance service

Everyone who connects to ProtocolServer now gets his own instance.
This means that different users can no longer talk to the same exact
ProtocolServer process, enhanching security and stability.
This commit is contained in:
Andreas Kling 2020-07-06 13:27:25 +02:00
parent a122a544da
commit 6f059ee830
3 changed files with 8 additions and 15 deletions

View file

@ -2,10 +2,10 @@
Socket=/tmp/portal/protocol Socket=/tmp/portal/protocol
SocketPermissions=660 SocketPermissions=660
Lazy=1 Lazy=1
Priority=low
KeepAlive=1
User=protocol User=protocol
BootModes=text,graphical BootModes=text,graphical
MultiInstance=1
AcceptSocketConnections=1
[WebContent] [WebContent]
Socket=/tmp/portal/webcontent Socket=/tmp/portal/webcontent

View file

@ -48,6 +48,8 @@ ClientConnection::~ClientConnection()
void ClientConnection::die() void ClientConnection::die()
{ {
s_connections.remove(client_id()); s_connections.remove(client_id());
if (s_connections.is_empty())
Core::EventLoop::current().quit(0);
} }
OwnPtr<Messages::ProtocolServer::IsSupportedProtocolResponse> ClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message) OwnPtr<Messages::ProtocolServer::IsSupportedProtocolResponse> ClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message)

View file

@ -56,18 +56,9 @@ int main(int, char**)
(void)*new ProtocolServer::GeminiProtocol; (void)*new ProtocolServer::GeminiProtocol;
(void)*new ProtocolServer::HttpProtocol; (void)*new ProtocolServer::HttpProtocol;
(void)*new ProtocolServer::HttpsProtocol; (void)*new ProtocolServer::HttpsProtocol;
auto server = Core::LocalServer::construct();
bool ok = server->take_over_from_system_server(); auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
ASSERT(ok); ASSERT(socket);
server->on_ready_to_accept = [&] { IPC::new_client_connection<ProtocolServer::ClientConnection>(socket.release_nonnull(), 1);
auto client_socket = server->accept();
if (!client_socket) {
dbg() << "ProtocolServer: accept failed.";
return;
}
static int s_next_client_id = 0;
int client_id = ++s_next_client_id;
IPC::new_client_connection<ProtocolServer::ClientConnection>(*client_socket, client_id);
};
return event_loop.exec(); return event_loop.exec();
} }