1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LibIPC: Support sending file descriptors :^)

It is now possible to use the special IPC::File type in message arguments. In
C++, the type is nothing more than a wrapper over a file descriptor. But when
serializing/deserializing IPC::File arguments, LibIPC will use the sendfd/recvfd
kernel APIs instead of sending the integer inline.

This makes it quite convenient to pass files over IPC, and will allow us to
significantly tighten sandboxes in the future :^)

Closes https://github.com/SerenityOS/serenity/issues/3643
This commit is contained in:
Sergey Bugaev 2020-11-21 21:59:12 +03:00 committed by Andreas Kling
parent fa2e3e2be4
commit 23dc3ff0c2
9 changed files with 148 additions and 50 deletions

View file

@ -217,6 +217,7 @@ int main(int argc, char** argv)
#include <LibIPC/Dictionary.h>
#include <LibIPC/Encoder.h>
#include <LibIPC/Endpoint.h>
#include <LibIPC/File.h>
#include <LibIPC/Message.h>
)~~~");
@ -318,9 +319,9 @@ public:
static i32 static_message_id() { return (int)MessageID::@message.name@; }
virtual const char* message_name() const override { return "@endpoint.name@::@message.name@"; }
static OwnPtr<@message.name@> decode(InputMemoryStream& stream)
static OwnPtr<@message.name@> decode(InputMemoryStream& stream, int sockfd)
{
IPC::Decoder decoder { stream };
IPC::Decoder decoder { stream, sockfd };
)~~~");
for (auto& parameter : parameters) {
@ -436,7 +437,7 @@ public:
static String static_name() { return "@endpoint.name@"; }
virtual String name() const override { return "@endpoint.name@"; }
static OwnPtr<IPC::Message> decode_message(const ByteBuffer& buffer)
static OwnPtr<IPC::Message> decode_message(const ByteBuffer& buffer, int sockfd)
{
InputMemoryStream stream { buffer };
i32 message_endpoint_magic = 0;
@ -488,7 +489,7 @@ public:
message_generator.append(R"~~~(
case (int)Messages::@endpoint.name@::MessageID::@message.name@:
message = Messages::@endpoint.name@::@message.name@::decode(stream);
message = Messages::@endpoint.name@::@message.name@::decode(stream, sockfd);
break;
)~~~");
};