From 1b36348d8b9676546e81eb86c2336dcdf8ff4e2f Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Tue, 19 Jul 2022 21:01:04 +0200 Subject: [PATCH] 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. --- Base/home/anon/.config/SystemServer.ini | 2 +- .../HackStudio/LanguageClients/ConnectionsToServer.h | 6 +++--- Userland/DevTools/Inspector/InspectorServerClient.h | 2 +- Userland/Libraries/LibAudio/ConnectionToServer.h | 2 +- Userland/Libraries/LibConfig/Client.h | 2 +- Userland/Libraries/LibCore/Account.cpp | 9 +++++++++ Userland/Libraries/LibCore/Account.h | 1 + Userland/Libraries/LibDesktop/Launcher.cpp | 2 +- Userland/Libraries/LibFileSystemAccessClient/Client.h | 2 +- Userland/Libraries/LibGUI/Clipboard.cpp | 2 +- .../Libraries/LibGUI/ConnectionToWindowManagerServer.h | 2 +- Userland/Libraries/LibGUI/ConnectionToWindowServer.h | 2 +- Userland/Libraries/LibGUI/Notification.cpp | 2 +- Userland/Libraries/LibIPC/ConnectionToServer.h | 4 +++- Userland/Libraries/LibImageDecoderClient/Client.h | 2 +- Userland/Libraries/LibProtocol/RequestClient.h | 2 +- Userland/Libraries/LibProtocol/WebSocketClient.h | 2 +- Userland/Libraries/LibSQL/SQLClient.h | 2 +- Userland/Libraries/LibWebView/WebContentClient.h | 2 +- .../Services/SpiceAgent/ConnectionToClipboardServer.h | 2 +- Userland/Services/SystemServer/Service.cpp | 2 +- 21 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Base/home/anon/.config/SystemServer.ini b/Base/home/anon/.config/SystemServer.ini index ac9f6f7166..1cb28c95ce 100644 --- a/Base/home/anon/.config/SystemServer.ini +++ b/Base/home/anon/.config/SystemServer.ini @@ -1,5 +1,5 @@ [LaunchServer] -Socket=/tmp/user/100/portal/launch +Socket=/tmp/user/%uid/portal/launch SocketPermissions=600 Lazy=true SystemModes=text,graphical diff --git a/Userland/DevTools/HackStudio/LanguageClients/ConnectionsToServer.h b/Userland/DevTools/HackStudio/LanguageClients/ConnectionsToServer.h index 97a642410e..3022290ce6 100644 --- a/Userland/DevTools/HackStudio/LanguageClients/ConnectionsToServer.h +++ b/Userland/DevTools/HackStudio/LanguageClients/ConnectionsToServer.h @@ -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) } diff --git a/Userland/DevTools/Inspector/InspectorServerClient.h b/Userland/DevTools/Inspector/InspectorServerClient.h index 8ce73d7c0a..caff6df1e2 100644 --- a/Userland/DevTools/Inspector/InspectorServerClient.h +++ b/Userland/DevTools/Inspector/InspectorServerClient.h @@ -15,7 +15,7 @@ namespace Inspector { class InspectorServerClient final : public IPC::ConnectionToServer , public InspectorClientEndpoint { - IPC_CLIENT_CONNECTION(InspectorServerClient, "/tmp/portal/inspector") + IPC_CLIENT_CONNECTION(InspectorServerClient, "/tmp/portal/inspector"sv) public: virtual ~InspectorServerClient() override = default; diff --git a/Userland/Libraries/LibAudio/ConnectionToServer.h b/Userland/Libraries/LibAudio/ConnectionToServer.h index e14deab6c3..687eae652e 100644 --- a/Userland/Libraries/LibAudio/ConnectionToServer.h +++ b/Userland/Libraries/LibAudio/ConnectionToServer.h @@ -26,7 +26,7 @@ namespace Audio { class ConnectionToServer final : public IPC::ConnectionToServer , public AudioClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/audio") + IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/audio"sv) public: virtual ~ConnectionToServer() override; diff --git a/Userland/Libraries/LibConfig/Client.h b/Userland/Libraries/LibConfig/Client.h index 99d45a2fc6..48a93e3491 100644 --- a/Userland/Libraries/LibConfig/Client.h +++ b/Userland/Libraries/LibConfig/Client.h @@ -18,7 +18,7 @@ namespace Config { class Client final : public IPC::ConnectionToServer , public ConfigClientEndpoint { - IPC_CLIENT_CONNECTION(Client, "/tmp/portal/config") + IPC_CLIENT_CONNECTION(Client, "/tmp/portal/config"sv) public: void pledge_domains(Vector const&); diff --git a/Userland/Libraries/LibCore/Account.cpp b/Userland/Libraries/LibCore/Account.cpp index 715721570a..dc2e64a1d3 100644 --- a/Userland/Libraries/LibCore/Account.cpp +++ b/Userland/Libraries/LibCore/Account.cpp @@ -68,6 +68,15 @@ ErrorOr Account::from_passwd(passwd const& pwd, spwd const& spwd) return account; } +String Account::parse_path_with_uid(StringView general_path, Optional 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::self([[maybe_unused]] Read options) { Vector extra_gids = TRY(Core::System::getgroups()); diff --git a/Userland/Libraries/LibCore/Account.h b/Userland/Libraries/LibCore/Account.h index 36eef9dbd5..8e545aaad1 100644 --- a/Userland/Libraries/LibCore/Account.h +++ b/Userland/Libraries/LibCore/Account.h @@ -34,6 +34,7 @@ public: // FIXME: Convert the methods below to take StringViews instead. + static String parse_path_with_uid(StringView general_path, Optional force_uid = {}); static ErrorOr self(Read options = Read::All); static ErrorOr from_name(char const* username, Read options = Read::All); static ErrorOr from_uid(uid_t uid, Read options = Read::All); diff --git a/Userland/Libraries/LibDesktop/Launcher.cpp b/Userland/Libraries/LibDesktop/Launcher.cpp index 6dc00d0a05..724e118e92 100644 --- a/Userland/Libraries/LibDesktop/Launcher.cpp +++ b/Userland/Libraries/LibDesktop/Launcher.cpp @@ -36,7 +36,7 @@ auto Launcher::Details::from_details_str(String const& details_str) -> NonnullRe class ConnectionToLaunchServer final : public IPC::ConnectionToServer , public LaunchClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/100/portal/launch") + IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/%uid/portal/launch"sv) private: ConnectionToLaunchServer(NonnullOwnPtr socket) : IPC::ConnectionToServer(*this, move(socket)) diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.h b/Userland/Libraries/LibFileSystemAccessClient/Client.h index 94aa01b9cc..c086ded70e 100644 --- a/Userland/Libraries/LibFileSystemAccessClient/Client.h +++ b/Userland/Libraries/LibFileSystemAccessClient/Client.h @@ -23,7 +23,7 @@ using Result = ErrorOr>; class Client final : public IPC::ConnectionToServer , 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); diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index c7dbb2075a..a0b8598d2a 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -16,7 +16,7 @@ namespace GUI { class ConnectionToClipboardServer final : public IPC::ConnectionToServer , public ClipboardClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard") + IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard"sv) private: ConnectionToClipboardServer(NonnullOwnPtr socket) diff --git a/Userland/Libraries/LibGUI/ConnectionToWindowManagerServer.h b/Userland/Libraries/LibGUI/ConnectionToWindowManagerServer.h index 2761070aef..015d520222 100644 --- a/Userland/Libraries/LibGUI/ConnectionToWindowManagerServer.h +++ b/Userland/Libraries/LibGUI/ConnectionToWindowManagerServer.h @@ -16,7 +16,7 @@ namespace GUI { class ConnectionToWindowManagerServer final : public IPC::ConnectionToServer , public WindowManagerClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToWindowManagerServer, "/tmp/portal/wm") + IPC_CLIENT_CONNECTION(ConnectionToWindowManagerServer, "/tmp/portal/wm"sv) public: static ConnectionToWindowManagerServer& the(); diff --git a/Userland/Libraries/LibGUI/ConnectionToWindowServer.h b/Userland/Libraries/LibGUI/ConnectionToWindowServer.h index 94f8de89f4..e4f25cff2f 100644 --- a/Userland/Libraries/LibGUI/ConnectionToWindowServer.h +++ b/Userland/Libraries/LibGUI/ConnectionToWindowServer.h @@ -16,7 +16,7 @@ namespace GUI { class ConnectionToWindowServer final : public IPC::ConnectionToServer , 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; } diff --git a/Userland/Libraries/LibGUI/Notification.cpp b/Userland/Libraries/LibGUI/Notification.cpp index 04e4a5aed0..a44c0de46e 100644 --- a/Userland/Libraries/LibGUI/Notification.cpp +++ b/Userland/Libraries/LibGUI/Notification.cpp @@ -15,7 +15,7 @@ namespace GUI { class ConnectionToNotificationServer final : public IPC::ConnectionToServer , public NotificationClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/portal/notify") + IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/portal/notify"sv) friend class Notification; diff --git a/Userland/Libraries/LibIPC/ConnectionToServer.h b/Userland/Libraries/LibIPC/ConnectionToServer.h index 38994155dd..0b7ec8d54c 100644 --- a/Userland/Libraries/LibIPC/ConnectionToServer.h +++ b/Userland/Libraries/LibIPC/ConnectionToServer.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -17,7 +18,8 @@ public: template \ static ErrorOr> 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)); \ \ diff --git a/Userland/Libraries/LibImageDecoderClient/Client.h b/Userland/Libraries/LibImageDecoderClient/Client.h index 0fc4572643..be96a58fe8 100644 --- a/Userland/Libraries/LibImageDecoderClient/Client.h +++ b/Userland/Libraries/LibImageDecoderClient/Client.h @@ -27,7 +27,7 @@ struct DecodedImage { class Client final : public IPC::ConnectionToServer , public ImageDecoderClientEndpoint { - IPC_CLIENT_CONNECTION(Client, "/tmp/portal/image"); + IPC_CLIENT_CONNECTION(Client, "/tmp/portal/image"sv); public: Optional decode_image(ReadonlyBytes); diff --git a/Userland/Libraries/LibProtocol/RequestClient.h b/Userland/Libraries/LibProtocol/RequestClient.h index d44d3a9f4b..5787228ae6 100644 --- a/Userland/Libraries/LibProtocol/RequestClient.h +++ b/Userland/Libraries/LibProtocol/RequestClient.h @@ -20,7 +20,7 @@ class Request; class RequestClient final : public IPC::ConnectionToServer , public RequestClientEndpoint { - IPC_CLIENT_CONNECTION(RequestClient, "/tmp/portal/request") + IPC_CLIENT_CONNECTION(RequestClient, "/tmp/portal/request"sv) public: template> diff --git a/Userland/Libraries/LibProtocol/WebSocketClient.h b/Userland/Libraries/LibProtocol/WebSocketClient.h index f802c73597..6d6d479f13 100644 --- a/Userland/Libraries/LibProtocol/WebSocketClient.h +++ b/Userland/Libraries/LibProtocol/WebSocketClient.h @@ -18,7 +18,7 @@ class WebSocket; class WebSocketClient final : public IPC::ConnectionToServer , public WebSocketClientEndpoint { - IPC_CLIENT_CONNECTION(WebSocketClient, "/tmp/portal/websocket") + IPC_CLIENT_CONNECTION(WebSocketClient, "/tmp/portal/websocket"sv) public: RefPtr connect(const URL&, String const& origin = {}, Vector const& protocols = {}, Vector const& extensions = {}, HashMap const& request_headers = {}); diff --git a/Userland/Libraries/LibSQL/SQLClient.h b/Userland/Libraries/LibSQL/SQLClient.h index 83eaf1fd9c..8ede4127e5 100644 --- a/Userland/Libraries/LibSQL/SQLClient.h +++ b/Userland/Libraries/LibSQL/SQLClient.h @@ -16,7 +16,7 @@ namespace SQL { class SQLClient : public IPC::ConnectionToServer , public SQLClientEndpoint { - IPC_CLIENT_CONNECTION(SQLClient, "/tmp/portal/sql") + IPC_CLIENT_CONNECTION(SQLClient, "/tmp/portal/sql"sv) virtual ~SQLClient() = default; Function on_connected; diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 3dd0619cf4..ecb722f3cd 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -19,7 +19,7 @@ class OutOfProcessWebView; class WebContentClient final : public IPC::ConnectionToServer , public WebContentClientEndpoint { - IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/portal/webcontent"); + IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/portal/webcontent"sv); public: Function on_web_content_process_crash; diff --git a/Userland/Services/SpiceAgent/ConnectionToClipboardServer.h b/Userland/Services/SpiceAgent/ConnectionToClipboardServer.h index fc2e0c8ab9..c76e0d5ae0 100644 --- a/Userland/Services/SpiceAgent/ConnectionToClipboardServer.h +++ b/Userland/Services/SpiceAgent/ConnectionToClipboardServer.h @@ -15,7 +15,7 @@ class ConnectionToClipboardServer final : public IPC::ConnectionToServer , public ClipboardClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard") + IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard"sv) public: Function on_data_changed; diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp index 2f8d6f57be..c8a4da259b 100644 --- a/Userland/Services/SystemServer/Service.cpp +++ b/Userland/Services/SystemServer/Service.cpp @@ -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 {}); // Socket path (plus NUL) must fit into the structs sent to the Kernel. VERIFY(path.length() < UNIX_PATH_MAX);