Skip to content

Commit 098bad0

Browse files
committed
Add support for security-context-v1
Based on Sway's usage of wlr_security_context_v1
1 parent c5c9040 commit 098bad0

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

src/server.cpp

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <wlr/types/wlr_presentation_time.h>
2121
#include <wlr/types/wlr_primary_selection_v1.h>
2222
#include <wlr/types/wlr_screencopy_v1.h>
23+
#include <wlr/types/wlr_security_context_v1.h>
2324
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
2425
#include <wlr/types/wlr_viewporter.h>
2526
#include <wlr/types/wlr_xcursor_manager.h>
@@ -29,6 +30,7 @@
2930
#include <wlr/types/wlr_xdg_output_v1.h>
3031
#include <wlr/util/box.h>
3132
#include <wlr/util/log.h>
33+
#include <wlr/xwayland/shell.h>
3234
#include "wlr-wrap-end.hpp"
3335

3436
void Server::focus_view(std::shared_ptr<View>&& view, wlr_surface* surface) {
@@ -361,6 +363,23 @@ void output_manager_apply_notify(wl_listener* listener, void* data) {
361363
server.seat->cursor.reload_image();
362364
}
363365

366+
bool filter_globals(const struct wl_client* client, const struct wl_global* global, void* data) {
367+
const auto& server = *static_cast<Server*>(data);
368+
const auto* wlr_xwayland = server.xwayland->wlr;
369+
370+
if (global == wlr_xwayland->shell_v1->global) {
371+
return wlr_xwayland->server != nullptr && client == wlr_xwayland->server->client;
372+
}
373+
374+
const auto* security_context =
375+
wlr_security_context_manager_v1_lookup_client(server.security_context_manager, (wl_client*) client);
376+
if (server.is_restricted(global)) {
377+
return security_context == nullptr;
378+
}
379+
380+
return true;
381+
}
382+
364383
void early_exit(wl_display* display, const std::string& err) {
365384
wlr_log(WLR_ERROR, "%s", err.c_str());
366385
wl_display_destroy_clients(display);
@@ -417,6 +436,9 @@ Server::Server() : listeners(*this) {
417436
wlr_subcompositor_create(display);
418437
wlr_data_device_manager_create(display);
419438

439+
security_context_manager = wlr_security_context_manager_v1_create(display);
440+
wl_display_set_global_filter(display, filter_globals, nullptr);
441+
420442
// https://wayfire.org/2020/08/04/Wayfire-0-5.html
421443
wlr_primary_selection_v1_device_manager_create(display);
422444

@@ -479,16 +501,16 @@ Server::Server() : listeners(*this) {
479501
listeners.activation_request_activation.notify = request_activation_notify;
480502
wl_signal_add(&xdg_activation->events.request_activate, &listeners.activation_request_activation);
481503

482-
wlr_data_control_manager_v1_create(display);
504+
data_control_manager = wlr_data_control_manager_v1_create(display);
483505
foreign_toplevel_manager = wlr_foreign_toplevel_manager_v1_create(display);
484506

485507
xwayland = std::make_shared<XWayland>(*this);
486508

487509
wlr_viewporter_create(display);
488510
wlr_single_pixel_buffer_manager_v1_create(display);
489-
wlr_screencopy_manager_v1_create(display);
490-
wlr_export_dmabuf_manager_v1_create(display);
491-
wlr_gamma_control_manager_v1_create(display);
511+
screencopy_manager = wlr_screencopy_manager_v1_create(display);
512+
export_dmabuf_manager = wlr_export_dmabuf_manager_v1_create(display);
513+
gamma_control_manager = wlr_gamma_control_manager_v1_create(display);
492514

493515
wlr_xdg_foreign_registry* foreign_registry = wlr_xdg_foreign_registry_create(display);
494516
wlr_xdg_foreign_v1_create(display, foreign_registry);
@@ -505,3 +527,29 @@ Server::Server() : listeners(*this) {
505527

506528
content_type_manager = wlr_content_type_manager_v1_create(display, 1);
507529
}
530+
531+
bool Server::is_restricted(const wl_global* global) const {
532+
if (drm_manager != nullptr) {
533+
wlr_drm_lease_device_v1* drm_lease_dev;
534+
wl_list_for_each(drm_lease_dev, &drm_manager->devices, link) {
535+
if (global == drm_lease_dev->global) {
536+
return true;
537+
}
538+
}
539+
}
540+
541+
// clang-format off
542+
return
543+
global == data_control_manager->global ||
544+
global == foreign_toplevel_manager->global ||
545+
global == export_dmabuf_manager->global ||
546+
global == gamma_control_manager->global ||
547+
global == layer_shell->global ||
548+
global == output_manager->global ||
549+
global == output_power_manager->global ||
550+
global == seat->virtual_keyboard_mgr->global ||
551+
global == seat->virtual_pointer_mgr->global ||
552+
global == screencopy_manager->global ||
553+
global == security_context_manager->global;
554+
// clang-format on
555+
}

src/server.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
#include <wlr/backend/session.h>
1313
#include <wlr/render/allocator.h>
1414
#include <wlr/types/wlr_content_type_v1.h>
15+
#include <wlr/types/wlr_data_control_v1.h>
1516
#include <wlr/types/wlr_drm_lease_v1.h>
17+
#include <wlr/types/wlr_export_dmabuf_v1.h>
18+
#include <wlr/types/wlr_gamma_control_v1.h>
1619
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
1720
#include <wlr/types/wlr_idle_inhibit_v1.h>
1821
#include <wlr/types/wlr_idle_notify_v1.h>
1922
#include <wlr/types/wlr_layer_shell_v1.h>
2023
#include <wlr/types/wlr_output_management_v1.h>
2124
#include <wlr/types/wlr_output_power_management_v1.h>
2225
#include <wlr/types/wlr_scene.h>
26+
#include <wlr/types/wlr_screencopy_v1.h>
27+
#include <wlr/types/wlr_security_context_v1.h>
2328
#include <wlr/types/wlr_xdg_activation_v1.h>
2429
#include <wlr/types/wlr_xdg_shell.h>
2530
#include "wlr-wrap-end.hpp"
@@ -93,11 +98,17 @@ class Server final : public std::enable_shared_from_this<Server> {
9398

9499
wlr_drm_lease_v1_manager* drm_manager;
95100
wlr_content_type_manager_v1* content_type_manager;
101+
wlr_data_control_manager_v1* data_control_manager;
102+
wlr_security_context_manager_v1* security_context_manager;
103+
wlr_export_dmabuf_manager_v1* export_dmabuf_manager;
104+
wlr_gamma_control_manager_v1* gamma_control_manager;
105+
wlr_screencopy_manager_v1* screencopy_manager;
96106

97107
Server();
98108

99109
std::weak_ptr<Surface> surface_at(double lx, double ly, wlr_surface** wlr, double* sx, double* sy) const;
100110
void focus_view(std::shared_ptr<View>&& view, wlr_surface* surface = nullptr);
111+
bool is_restricted(const wl_global* global) const;
101112
};
102113

103114
#endif

0 commit comments

Comments
 (0)