mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -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]
|
[LaunchServer]
|
||||||
Socket=/tmp/user/100/portal/launch
|
Socket=/tmp/user/%uid/portal/launch
|
||||||
SocketPermissions=600
|
SocketPermissions=600
|
||||||
Lazy=true
|
Lazy=true
|
||||||
SystemModes=text,graphical
|
SystemModes=text,graphical
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#define LANGUAGE_CLIENT(language_name_, socket_name) \
|
#define LANGUAGE_CLIENT(language_name_, socket_name) \
|
||||||
namespace language_name_ { \
|
namespace language_name_ { \
|
||||||
class ConnectionToServer final : public HackStudio::ConnectionToServer { \
|
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: \
|
public: \
|
||||||
static char const* language_name() { return #language_name_; } \
|
static char const* language_name() { return #language_name_; } \
|
||||||
\
|
\
|
||||||
|
@ -29,8 +29,8 @@
|
||||||
|
|
||||||
namespace LanguageClients {
|
namespace LanguageClients {
|
||||||
|
|
||||||
LANGUAGE_CLIENT(Cpp, cpp)
|
LANGUAGE_CLIENT(Cpp, "cpp"sv)
|
||||||
LANGUAGE_CLIENT(Shell, shell)
|
LANGUAGE_CLIENT(Shell, "shell"sv)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Inspector {
|
||||||
class InspectorServerClient final
|
class InspectorServerClient final
|
||||||
: public IPC::ConnectionToServer<InspectorClientEndpoint, InspectorServerEndpoint>
|
: public IPC::ConnectionToServer<InspectorClientEndpoint, InspectorServerEndpoint>
|
||||||
, public InspectorClientEndpoint {
|
, public InspectorClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(InspectorServerClient, "/tmp/portal/inspector")
|
IPC_CLIENT_CONNECTION(InspectorServerClient, "/tmp/portal/inspector"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~InspectorServerClient() override = default;
|
virtual ~InspectorServerClient() override = default;
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Audio {
|
||||||
class ConnectionToServer final
|
class ConnectionToServer final
|
||||||
: public IPC::ConnectionToServer<AudioClientEndpoint, AudioServerEndpoint>
|
: public IPC::ConnectionToServer<AudioClientEndpoint, AudioServerEndpoint>
|
||||||
, public AudioClientEndpoint {
|
, public AudioClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/audio")
|
IPC_CLIENT_CONNECTION(ConnectionToServer, "/tmp/portal/audio"sv)
|
||||||
public:
|
public:
|
||||||
virtual ~ConnectionToServer() override;
|
virtual ~ConnectionToServer() override;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Config {
|
||||||
class Client final
|
class Client final
|
||||||
: public IPC::ConnectionToServer<ConfigClientEndpoint, ConfigServerEndpoint>
|
: public IPC::ConnectionToServer<ConfigClientEndpoint, ConfigServerEndpoint>
|
||||||
, public ConfigClientEndpoint {
|
, public ConfigClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/config")
|
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/config"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void pledge_domains(Vector<String> const&);
|
void pledge_domains(Vector<String> const&);
|
||||||
|
|
|
@ -68,6 +68,15 @@ ErrorOr<Account> Account::from_passwd(passwd const& pwd, spwd const& spwd)
|
||||||
return account;
|
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)
|
ErrorOr<Account> Account::self([[maybe_unused]] Read options)
|
||||||
{
|
{
|
||||||
Vector<gid_t> extra_gids = TRY(Core::System::getgroups());
|
Vector<gid_t> extra_gids = TRY(Core::System::getgroups());
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
|
|
||||||
// FIXME: Convert the methods below to take StringViews instead.
|
// 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> self(Read options = Read::All);
|
||||||
static ErrorOr<Account> from_name(char const* username, 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);
|
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
|
class ConnectionToLaunchServer final
|
||||||
: public IPC::ConnectionToServer<LaunchClientEndpoint, LaunchServerEndpoint>
|
: public IPC::ConnectionToServer<LaunchClientEndpoint, LaunchServerEndpoint>
|
||||||
, public LaunchClientEndpoint {
|
, public LaunchClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/100/portal/launch")
|
IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/%uid/portal/launch"sv)
|
||||||
private:
|
private:
|
||||||
ConnectionToLaunchServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
ConnectionToLaunchServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||||
: IPC::ConnectionToServer<LaunchClientEndpoint, LaunchServerEndpoint>(*this, move(socket))
|
: IPC::ConnectionToServer<LaunchClientEndpoint, LaunchServerEndpoint>(*this, move(socket))
|
||||||
|
|
|
@ -23,7 +23,7 @@ using Result = ErrorOr<NonnullRefPtr<Core::File>>;
|
||||||
class Client final
|
class Client final
|
||||||
: public IPC::ConnectionToServer<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
: public IPC::ConnectionToServer<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
||||||
, public FileSystemAccessClientEndpoint {
|
, public FileSystemAccessClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess")
|
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Result try_request_file_read_only_approved(GUI::Window* parent_window, String const& path);
|
Result try_request_file_read_only_approved(GUI::Window* parent_window, String const& path);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
||||||
class ConnectionToClipboardServer final
|
class ConnectionToClipboardServer final
|
||||||
: public IPC::ConnectionToServer<ClipboardClientEndpoint, ClipboardServerEndpoint>
|
: public IPC::ConnectionToServer<ClipboardClientEndpoint, ClipboardServerEndpoint>
|
||||||
, public ClipboardClientEndpoint {
|
, public ClipboardClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard")
|
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard"sv)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConnectionToClipboardServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
ConnectionToClipboardServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
||||||
class ConnectionToWindowManagerServer final
|
class ConnectionToWindowManagerServer final
|
||||||
: public IPC::ConnectionToServer<WindowManagerClientEndpoint, WindowManagerServerEndpoint>
|
: public IPC::ConnectionToServer<WindowManagerClientEndpoint, WindowManagerServerEndpoint>
|
||||||
, public WindowManagerClientEndpoint {
|
, public WindowManagerClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToWindowManagerServer, "/tmp/portal/wm")
|
IPC_CLIENT_CONNECTION(ConnectionToWindowManagerServer, "/tmp/portal/wm"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ConnectionToWindowManagerServer& the();
|
static ConnectionToWindowManagerServer& the();
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
||||||
class ConnectionToWindowServer final
|
class ConnectionToWindowServer final
|
||||||
: public IPC::ConnectionToServer<WindowClientEndpoint, WindowServerEndpoint>
|
: public IPC::ConnectionToServer<WindowClientEndpoint, WindowServerEndpoint>
|
||||||
, public WindowClientEndpoint {
|
, public WindowClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToWindowServer, "/tmp/portal/window")
|
IPC_CLIENT_CONNECTION(ConnectionToWindowServer, "/tmp/portal/window"sv)
|
||||||
public:
|
public:
|
||||||
static ConnectionToWindowServer& the();
|
static ConnectionToWindowServer& the();
|
||||||
i32 expose_client_id() { return m_client_id; }
|
i32 expose_client_id() { return m_client_id; }
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace GUI {
|
||||||
class ConnectionToNotificationServer final
|
class ConnectionToNotificationServer final
|
||||||
: public IPC::ConnectionToServer<NotificationClientEndpoint, NotificationServerEndpoint>
|
: public IPC::ConnectionToServer<NotificationClientEndpoint, NotificationServerEndpoint>
|
||||||
, public NotificationClientEndpoint {
|
, public NotificationClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/portal/notify")
|
IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/portal/notify"sv)
|
||||||
|
|
||||||
friend class Notification;
|
friend class Notification;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibCore/Account.h>
|
||||||
#include <LibCore/Stream.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibIPC/Connection.h>
|
#include <LibIPC/Connection.h>
|
||||||
|
|
||||||
|
@ -17,7 +18,8 @@ public:
|
||||||
template<typename Klass = klass, class... Args> \
|
template<typename Klass = klass, class... Args> \
|
||||||
static ErrorOr<NonnullRefPtr<klass>> try_create(Args&&... 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 */ \
|
/* We want to rate-limit our clients */ \
|
||||||
TRY(socket->set_blocking(true)); \
|
TRY(socket->set_blocking(true)); \
|
||||||
\
|
\
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct DecodedImage {
|
||||||
class Client final
|
class Client final
|
||||||
: public IPC::ConnectionToServer<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>
|
: public IPC::ConnectionToServer<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>
|
||||||
, public ImageDecoderClientEndpoint {
|
, public ImageDecoderClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/image");
|
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/image"sv);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Optional<DecodedImage> decode_image(ReadonlyBytes);
|
Optional<DecodedImage> decode_image(ReadonlyBytes);
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Request;
|
||||||
class RequestClient final
|
class RequestClient final
|
||||||
: public IPC::ConnectionToServer<RequestClientEndpoint, RequestServerEndpoint>
|
: public IPC::ConnectionToServer<RequestClientEndpoint, RequestServerEndpoint>
|
||||||
, public RequestClientEndpoint {
|
, public RequestClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(RequestClient, "/tmp/portal/request")
|
IPC_CLIENT_CONNECTION(RequestClient, "/tmp/portal/request"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template<typename RequestHashMapTraits = Traits<String>>
|
template<typename RequestHashMapTraits = Traits<String>>
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WebSocket;
|
||||||
class WebSocketClient final
|
class WebSocketClient final
|
||||||
: public IPC::ConnectionToServer<WebSocketClientEndpoint, WebSocketServerEndpoint>
|
: public IPC::ConnectionToServer<WebSocketClientEndpoint, WebSocketServerEndpoint>
|
||||||
, public WebSocketClientEndpoint {
|
, public WebSocketClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(WebSocketClient, "/tmp/portal/websocket")
|
IPC_CLIENT_CONNECTION(WebSocketClient, "/tmp/portal/websocket"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RefPtr<WebSocket> connect(const URL&, String const& origin = {}, Vector<String> const& protocols = {}, Vector<String> const& extensions = {}, HashMap<String, String> const& request_headers = {});
|
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
|
class SQLClient
|
||||||
: public IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>
|
: public IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>
|
||||||
, public SQLClientEndpoint {
|
, public SQLClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(SQLClient, "/tmp/portal/sql")
|
IPC_CLIENT_CONNECTION(SQLClient, "/tmp/portal/sql"sv)
|
||||||
virtual ~SQLClient() = default;
|
virtual ~SQLClient() = default;
|
||||||
|
|
||||||
Function<void(int, String const&)> on_connected;
|
Function<void(int, String const&)> on_connected;
|
||||||
|
|
|
@ -19,7 +19,7 @@ class OutOfProcessWebView;
|
||||||
class WebContentClient final
|
class WebContentClient final
|
||||||
: public IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>
|
: public IPC::ConnectionToServer<WebContentClientEndpoint, WebContentServerEndpoint>
|
||||||
, public WebContentClientEndpoint {
|
, public WebContentClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/portal/webcontent");
|
IPC_CLIENT_CONNECTION(WebContentClient, "/tmp/portal/webcontent"sv);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Function<void()> on_web_content_process_crash;
|
Function<void()> on_web_content_process_crash;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
class ConnectionToClipboardServer final
|
class ConnectionToClipboardServer final
|
||||||
: public IPC::ConnectionToServer<ClipboardClientEndpoint, ClipboardServerEndpoint>
|
: public IPC::ConnectionToServer<ClipboardClientEndpoint, ClipboardServerEndpoint>
|
||||||
, public ClipboardClientEndpoint {
|
, public ClipboardClientEndpoint {
|
||||||
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard")
|
IPC_CLIENT_CONNECTION(ConnectionToClipboardServer, "/tmp/portal/clipboard"sv)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Function<void()> on_data_changed;
|
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.
|
// Need i here to iterate along with all other vectors.
|
||||||
for (unsigned i = 0; i < socket_paths.size(); i++) {
|
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.
|
// Socket path (plus NUL) must fit into the structs sent to the Kernel.
|
||||||
VERIFY(path.length() < UNIX_PATH_MAX);
|
VERIFY(path.length() < UNIX_PATH_MAX);
|
||||||
|
|
Loading…
Add table
Reference in a new issue