mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
LibCore+LibIPC: Recognise %uid in path
This patch allows to insert "%uid" in `IPC_CLIENT_CONNECTION` declaration and in SystemServer's ini files. This pattern is replaced then replaced by the UID of the owner of the service. It opens a path for seamlessly managed, per-user portal.
This commit is contained in:
parent
c5b7c9f479
commit
1b36348d8b
21 changed files with 33 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
[LaunchServer]
|
||||
Socket=/tmp/user/100/portal/launch
|
||||
Socket=/tmp/user/%uid/portal/launch
|
||||
SocketPermissions=600
|
||||
Lazy=true
|
||||
SystemModes=text,graphical
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#define LANGUAGE_CLIENT(language_name_, socket_name) \
|
||||
namespace language_name_ { \
|
||||
class ConnectionToServer final : public HackStudio::ConnectionToServer { \
|
||||
IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/language/" #socket_name) \
|
||||
IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/language/" socket_name) \
|
||||
public: \
|
||||
static char const* language_name() { return #language_name_; } \
|
||||
\
|
||||
|
@ -29,8 +29,8 @@
|
|||
|
||||
namespace LanguageClients {
|
||||
|
||||
LANGUAGE_CLIENT(Cpp, cpp)
|
||||
LANGUAGE_CLIENT(Shell, shell)
|
||||
LANGUAGE_CLIENT(Cpp, "cpp"sv)
|
||||
LANGUAGE_CLIENT(Shell, "shell"sv)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Inspector {
|
|||
class InspectorServerClient final
|
||||
: public IPC::ConnectionToServer<InspectorClientEndpoint, InspectorServerEndpoint>
|
||||
, public InspectorClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(InspectorServerClient, "/tmp/portal/inspector")
|
||||
IPC_CLIENT_CONNECTION(InspectorServerClient, "/tmp/portal/inspector"sv)
|
||||
|
||||
public:
|
||||
virtual ~InspectorServerClient() override = default;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Audio {
|
|||
class ConnectionToServer final
|
||||
: public IPC::ConnectionToServer<AudioClientEndpoint, AudioServerEndpoint>
|
||||
, public AudioClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/audio")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/audio"sv)
|
||||
public:
|
||||
virtual ~ConnectionToServer() override;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Config {
|
|||
class Client final
|
||||
: public IPC::ConnectionToServer<ConfigClientEndpoint, ConfigServerEndpoint>
|
||||
, public ConfigClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/config")
|
||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/config"sv)
|
||||
|
||||
public:
|
||||
void pledge_domains(Vector<String> const&);
|
||||
|
|
|
@ -68,6 +68,15 @@ ErrorOr<Account> Account::from_passwd(passwd const& pwd, spwd const& spwd)
|
|||
return account;
|
||||
}
|
||||
|
||||
String Account::parse_path_with_uid(StringView general_path, Optional<uid_t> uid)
|
||||
{
|
||||
if (general_path.contains("%uid"sv)) {
|
||||
auto const final_uid = uid.has_value() ? uid.value() : getuid();
|
||||
return general_path.replace("%uid"sv, String::number(final_uid), ReplaceMode::All);
|
||||
}
|
||||
return general_path;
|
||||
}
|
||||
|
||||
ErrorOr<Account> Account::self([[maybe_unused]] Read options)
|
||||
{
|
||||
Vector<gid_t> extra_gids = TRY(Core::System::getgroups());
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
|
||||
// FIXME: Convert the methods below to take StringViews instead.
|
||||
|
||||
static String parse_path_with_uid(StringView general_path, Optional<uid_t> force_uid = {});
|
||||
static ErrorOr<Account> self(Read options = Read::All);
|
||||
static ErrorOr<Account> from_name(char const* username, Read options = Read::All);
|
||||
static ErrorOr<Account> from_uid(uid_t uid, Read options = Read::All);
|
||||
|
|
|
@ -36,7 +36,7 @@ auto Launcher::Details::from_details_str(String const& details_str) -> NonnullRe
|
|||
class ConnectionToLaunchServer final
|
||||
: public IPC::ConnectionToServer<LaunchClientEndpoint, LaunchServerEndpoint>
|
||||
, public LaunchClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/100/portal/launch")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/%uid/portal/launch"sv)
|
||||
private:
|
||||
ConnectionToLaunchServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||
: IPC::ConnectionToServer<LaunchClientEndpoint, LaunchServerEndpoint>(*this, move(socket))
|
||||
|
|
|
@ -23,7 +23,7 @@ using Result = ErrorOr<NonnullRefPtr<Core::File>>;
|
|||
class Client final
|
||||
: public IPC::ConnectionToServer<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
||||
, public FileSystemAccessClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess")
|
||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess"sv)
|
||||
|
||||
public:
|
||||
Result try_request_file_read_only_approved(GUI::Window* parent_window, String const& path);
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
|||
class ConnectionToClipboardServer final
|
||||
: public IPC::ConnectionToServer<ClipboardClientEndpoint, ClipboardServerEndpoint>
|
||||
, public ClipboardClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard"sv)
|
||||
|
||||
private:
|
||||
ConnectionToClipboardServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
|||
class ConnectionToWindowManagerServer final
|
||||
: public IPC::ConnectionToServer<WindowManagerClientEndpoint, WindowManagerServerEndpoint>
|
||||
, public WindowManagerClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToWindowManagerServer, "/tmp/portal/wm")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToWindowManagerServer, "/tmp/portal/wm"sv)
|
||||
|
||||
public:
|
||||
static ConnectionToWindowManagerServer& the();
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
|||
class ConnectionToWindowServer final
|
||||
: public IPC::ConnectionToServer<WindowClientEndpoint, WindowServerEndpoint>
|
||||
, public WindowClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToWindowServer, "/tmp/portal/window")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToWindowServer, "/tmp/portal/window"sv)
|
||||
public:
|
||||
static ConnectionToWindowServer& the();
|
||||
i32 expose_client_id() { return m_client_id; }
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace GUI {
|
|||
class ConnectionToNotificationServer final
|
||||
: public IPC::ConnectionToServer<NotificationClientEndpoint, NotificationServerEndpoint>
|
||||
, public NotificationClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/portal/notify")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/portal/notify"sv)
|
||||
|
||||
friend class Notification;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibCore/Account.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibIPC/Connection.h>
|
||||
|
||||
|
@ -17,7 +18,8 @@ public:
|
|||
template<typename Klass = klass, class... Args> \
|
||||
static ErrorOr<NonnullRefPtr<klass>> try_create(Args&&... args) \
|
||||
{ \
|
||||
auto socket = TRY(Core::Stream::LocalSocket::connect(socket_path)); \
|
||||
auto parsed_socket_path { Core::Account::parse_path_with_uid(socket_path) }; \
|
||||
auto socket = TRY(Core::Stream::LocalSocket::connect(move(parsed_socket_path))); \
|
||||
/* We want to rate-limit our clients */ \
|
||||
TRY(socket->set_blocking(true)); \
|
||||
\
|
||||
|
|
|
@ -27,7 +27,7 @@ struct DecodedImage {
|
|||
class Client final
|
||||
: public IPC::ConnectionToServer<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>
|
||||
, public ImageDecoderClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/image");
|
||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/image"sv);
|
||||
|
||||
public:
|
||||
Optional<DecodedImage> decode_image(ReadonlyBytes);
|
||||
|
|
|
@ -20,7 +20,7 @@ class Request;
|
|||
class RequestClient final
|
||||
: public IPC::ConnectionToServer<RequestClientEndpoint, RequestServerEndpoint>
|
||||
, public RequestClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(RequestClient, "/tmp/portal/request")
|
||||
IPC_CLIENT_CONNECTION(RequestClient, "/tmp/portal/request"sv)
|
||||
|
||||
public:
|
||||
template<typename RequestHashMapTraits = Traits<String>>
|
||||
|
|
|
@ -18,7 +18,7 @@ class WebSocket;
|
|||
class WebSocketClient final
|
||||
: public IPC::ConnectionToServer<WebSocketClientEndpoint, WebSocketServerEndpoint>
|
||||
, public WebSocketClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(WebSocketClient, "/tmp/portal/websocket")
|
||||
IPC_CLIENT_CONNECTION(WebSocketClient, "/tmp/portal/websocket"sv)
|
||||
|
||||
public:
|
||||
RefPtr<WebSocket> connect(const URL&, String const& origin = {}, Vector<String> const& protocols = {}, Vector<String> const& extensions = {}, HashMap<String, String> const& request_headers = {});
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace SQL {
|
|||
class SQLClient
|
||||
: public IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>
|
||||
, public SQLClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(SQLClient, "/tmp/portal/sql")
|
||||
IPC_CLIENT_CONNECTION(SQLClient, "/tmp/portal/sql"sv)
|
||||
virtual ~SQLClient() = default;
|
||||
|
||||
Function<void(int, String const&)> on_connected;
|
||||
|
|
|
@ -19,7 +19,7 @@ class OutOfProcessWebView;
|
|||
class WebContentClient final
|
||||
: public IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>
|
||||
, public WebContentClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/portal/webcontent");
|
||||
IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/portal/webcontent"sv);
|
||||
|
||||
public:
|
||||
Function<void()> on_web_content_process_crash;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
class ConnectionToClipboardServer final
|
||||
: public IPC::ConnectionToServer<ClipboardClientEndpoint, ClipboardServerEndpoint>
|
||||
, public ClipboardClientEndpoint {
|
||||
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard")
|
||||
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard"sv)
|
||||
|
||||
public:
|
||||
Function<void()> on_data_changed;
|
||||
|
|
|
@ -322,7 +322,7 @@ Service::Service(Core::ConfigFile const& config, StringView name)
|
|||
|
||||
// Need i here to iterate along with all other vectors.
|
||||
for (unsigned i = 0; i < socket_paths.size(); i++) {
|
||||
String& path = socket_paths.at(i);
|
||||
auto const path = Core::Account::parse_path_with_uid(socket_paths.at(i), m_account.has_value() ? m_account.value().uid() : Optional<uid_t> {});
|
||||
|
||||
// Socket path (plus NUL) must fit into the structs sent to the Kernel.
|
||||
VERIFY(path.length() < UNIX_PATH_MAX);
|
||||
|
|
Loading…
Add table
Reference in a new issue