KWin
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
securitycontext_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 David Edmundson <davidedmundson@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
7#include "display.h"
9#include "wayland/display_p.h"
10
11#include <qwayland-server-security-context-v1.h>
12
13#include <QDebug>
14
15class QSocketNotifier;
16
17namespace KWin
18{
19static const quint32 s_version = 1;
20
21class SecurityContextManagerV1InterfacePrivate : public QtWaylandServer::wp_security_context_manager_v1
22{
23public:
25
26protected:
27 void wp_security_context_manager_v1_destroy(Resource *resource) override;
28 void wp_security_context_manager_v1_create_listener(Resource *resource, uint32_t id, int32_t listen_fd, int32_t close_fd) override;
29
30private:
31 Display *m_display;
32};
33
34class SecurityContextV1Interface : public QtWaylandServer::wp_security_context_v1
35{
36public:
37 SecurityContextV1Interface(Display *display, int listenFd, int closeFd, wl_resource *resource);
38
39protected:
40 void wp_security_context_v1_set_sandbox_engine(Resource *resource, const QString &name) override;
41 void wp_security_context_v1_set_app_id(Resource *resource, const QString &app_id) override;
42 void wp_security_context_v1_set_instance_id(Resource *resource, const QString &instance_id) override;
43 void wp_security_context_v1_commit(Resource *resource) override;
44 void wp_security_context_v1_destroy_resource(Resource *resource) override;
45 void wp_security_context_v1_destroy(Resource *resource) override;
46
47private:
48 Display *m_display;
49 FileDescriptor m_listenFd;
50 FileDescriptor m_closeFd;
51 bool m_committed = false;
52 QString m_sandboxEngine;
53 QString m_appId;
54 QString m_instanceId;
55};
56
58 : QObject(parent)
60{
61}
62
66
68 : QtWaylandServer::wp_security_context_manager_v1(*display, s_version)
69 , m_display(display)
70{
71}
72
74{
75 wl_resource_destroy(resource->handle);
76}
77
78void SecurityContextManagerV1InterfacePrivate::wp_security_context_manager_v1_create_listener(Resource *resource, uint32_t id, int32_t listen_fd, int32_t close_fd)
79{
80 auto *securityContextResource = wl_resource_create(resource->client(), &wp_security_context_v1_interface, resource->version(), id);
81 if (!securityContextResource) {
82 wl_resource_post_no_memory(resource->handle);
83 return;
84 }
85 new SecurityContextV1Interface(m_display, listen_fd, close_fd, securityContextResource);
86}
87
88SecurityContextV1Interface::SecurityContextV1Interface(Display *display, int listenFd, int closeFd, wl_resource *resource)
89 : QtWaylandServer::wp_security_context_v1(resource)
90 , m_display(display)
91 , m_listenFd(listenFd)
92 , m_closeFd(closeFd)
93{
94}
95
97{
98 if (m_committed) {
99 wl_resource_post_error(resource->handle, error_already_used, "Already committed");
100 return;
101 }
102 m_sandboxEngine = name;
103}
104
105void SecurityContextV1Interface::wp_security_context_v1_set_app_id(Resource *resource, const QString &app_id)
106{
107 if (m_committed) {
108 wl_resource_post_error(resource->handle, error_already_used, "Already committed");
109 return;
110 }
111 if (app_id.isEmpty()) {
112 wl_resource_post_error(resource->handle, error_invalid_metadata, "App ID cannot be empty");
113 return;
114 }
115 m_appId = app_id;
116}
117
118void SecurityContextV1Interface::wp_security_context_v1_set_instance_id(Resource *resource, const QString &instance_id)
119{
120 if (m_committed) {
121 wl_resource_post_error(resource->handle, error_already_used, "Already committed");
122 return;
123 }
124 m_instanceId = instance_id;
125}
126
128{
129 if (m_committed) {
130 wl_resource_post_error(resource->handle, error_already_used, "Already committed");
131 return;
132 }
133 if (m_appId.isEmpty()) {
134 wl_resource_post_error(resource->handle, error_invalid_metadata, "App ID cannot be empty");
135 return;
136 }
137 if (m_sandboxEngine.isEmpty()) {
138 wl_resource_post_error(resource->handle, error_invalid_metadata, "Sandbox engine cannot be empty");
139 return;
140 }
141
142 m_committed = true;
143
144 // lifespan is managed by the closeFD's state
145 new SecurityContext(m_display, std::move(m_listenFd), std::move(m_closeFd), m_appId);
146}
147
149{
150 delete this;
151}
152
154{
155 wl_resource_destroy(resource->handle);
156}
157
158}
Class holding the Wayland server display loop.
Definition display.h:34
The SecurityContext is a helper for the SecurityContextProtocol It stays alive whilst closeFd remains...
Definition display_p.h:54
SecurityContextManagerV1Interface(Display *display, QObject *parent=nullptr)
void wp_security_context_manager_v1_destroy(Resource *resource) override
void wp_security_context_manager_v1_create_listener(Resource *resource, uint32_t id, int32_t listen_fd, int32_t close_fd) override
void wp_security_context_v1_commit(Resource *resource) override
void wp_security_context_v1_destroy(Resource *resource) override
void wp_security_context_v1_destroy_resource(Resource *resource) override
SecurityContextV1Interface(Display *display, int listenFd, int closeFd, wl_resource *resource)
void wp_security_context_v1_set_app_id(Resource *resource, const QString &app_id) override
void wp_security_context_v1_set_instance_id(Resource *resource, const QString &instance_id) override
void wp_security_context_v1_set_sandbox_engine(Resource *resource, const QString &name) override