From 2348f48f319a9a6ff19451deece8deb923e30059 Mon Sep 17 00:00:00 2001 From: Lasse Holmstedt Date: Wed, 25 May 2011 12:55:26 +0200 Subject: [PATCH] Add authentication token support for wayland windos MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For compositors that support it, the wayland clients can associate themselves with an auth token which is transmitted by the windowmanager protocol extension. Reviewed-by: Samuel Rødal --- src/qt-compositor/wayland_wrapper/wlcompositor.cpp | 10 +++-- src/qt-compositor/wayland_wrapper/wlsurface.cpp | 13 ++++++ src/qt-compositor/wayland_wrapper/wlsurface.h | 3 ++ .../wayland-windowmanager-protocol.c | 4 +- .../wayland-windowmanager-server-protocol.h | 5 ++- .../waylandwindowmanagerintegration.cpp | 51 +++++++++++++++++++--- .../waylandwindowmanagerintegration.h | 23 +++++++--- 7 files changed, 93 insertions(+), 16 deletions(-) diff --git a/src/qt-compositor/wayland_wrapper/wlcompositor.cpp b/src/qt-compositor/wayland_wrapper/wlcompositor.cpp index 8ddcbee..b95eea8 100644 --- a/src/qt-compositor/wayland_wrapper/wlcompositor.cpp +++ b/src/qt-compositor/wayland_wrapper/wlcompositor.cpp @@ -241,9 +241,13 @@ void Compositor::createSurface(struct wl_client *client, int id) addClientResource(client, &surface->base()->resource, id, &wl_surface_interface, &surface_interface, destroy_surface); - quint32 processId = m_windowManagerWaylandProtocol->pidForClient(client); - // if there is no PID, the client does not support the protocol. - surface->setProcessId(processId); + WaylandManagedClient *managedClient = m_windowManagerWaylandProtocol->managedClient(client); + if (managedClient) { + // if there is no PID, the client does not support the protocol. + surface->setProcessId(managedClient->processId()); + surface->setAuthenticationToken(managedClient->authenticationToken()); + } + m_qt_compositor->surfaceCreated(surface->handle()); QList prevClientList = clients(); diff --git a/src/qt-compositor/wayland_wrapper/wlsurface.cpp b/src/qt-compositor/wayland_wrapper/wlsurface.cpp index 0fb93fc..76346a0 100644 --- a/src/qt-compositor/wayland_wrapper/wlsurface.cpp +++ b/src/qt-compositor/wayland_wrapper/wlsurface.cpp @@ -110,6 +110,7 @@ public: bool textureCreatedForBuffer; wl_buffer *directRenderBuffer; qint64 processId; + QByteArray authenticationToken; private: struct wl_buffer *surfaceBuffer; @@ -313,6 +314,18 @@ void Surface::setProcessId(qint64 processId) d->processId = processId; } +QByteArray Surface::authenticationToken() const +{ + Q_D(const Surface); + return d->authenticationToken; +} + +void Surface::setAuthenticationToken(const QByteArray &authenticationToken) +{ + Q_D(Surface); + d->authenticationToken = authenticationToken; +} + uint32_t toWaylandButton(Qt::MouseButton button) { switch (button) { diff --git a/src/qt-compositor/wayland_wrapper/wlsurface.h b/src/qt-compositor/wayland_wrapper/wlsurface.h index ff345d1..73f19fd 100644 --- a/src/qt-compositor/wayland_wrapper/wlsurface.h +++ b/src/qt-compositor/wayland_wrapper/wlsurface.h @@ -100,6 +100,9 @@ public: wl_client *clientHandle() const; qint64 processId() const; void setProcessId(qint64 processId); + QByteArray authenticationToken() const; + void setAuthenticationToken(const QByteArray &authenticationToken); + void setSurfaceCreationFinished(bool isCreated); protected: diff --git a/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-protocol.c b/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-protocol.c index 48049d8..b753b16 100644 --- a/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-protocol.c +++ b/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-protocol.c @@ -26,7 +26,8 @@ #include "wayland-util.h" static const struct wl_message wl_windowmanager_requests[] = { - { "map_client_to_process", "u", NULL }, + { "map_client_to_process", "u" }, + { "authenticate_with_token", "s" }, }; WL_EXPORT const struct wl_interface wl_windowmanager_interface = { @@ -34,3 +35,4 @@ WL_EXPORT const struct wl_interface wl_windowmanager_interface = { ARRAY_LENGTH(wl_windowmanager_requests), wl_windowmanager_requests, 0, NULL, }; + diff --git a/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-server-protocol.h b/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-server-protocol.h index bde9d97..8738146 100644 --- a/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-server-protocol.h +++ b/src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-server-protocol.h @@ -40,8 +40,11 @@ extern const struct wl_interface wl_windowmanager_interface; struct wl_windowmanager_interface { void (*map_client_to_process)(struct wl_client *client, - struct wl_windowmanager *wl_windowmanager, + struct wl_windowmanager *windowmanager, uint32_t processid); + void (*authenticate_with_token)(struct wl_client *client, + struct wl_windowmanager *windowmanager, + const char *wl_authentication_token); }; #ifdef __cplusplus diff --git a/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp b/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp index 3f19b3d..5783959 100644 --- a/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp +++ b/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp @@ -66,6 +66,11 @@ public: WindowManagerServerIntegration::instance()->mapClientToProcess(client, processId); } + void authenticateWithToken(wl_client *client, const char *authenticationToken) + { + WindowManagerServerIntegration::instance()->authenticateWithToken(client, authenticationToken); + } + }; void map_client_to_process(wl_client *client, struct wl_windowmanager *windowMgr, uint32_t processId) @@ -73,8 +78,14 @@ void map_client_to_process(wl_client *client, struct wl_windowmanager *windowMgr reinterpret_cast(windowMgr)->mapClientToProcess(client, processId); } +void authenticate_with_token(wl_client *client, struct wl_windowmanager *windowMgr, const char *wl_authentication_token) +{ + reinterpret_cast(windowMgr)->authenticateWithToken(client, wl_authentication_token); +} + const static struct wl_windowmanager_interface windowmanager_interface = { - map_client_to_process + map_client_to_process, + authenticate_with_token }; WindowManagerServerIntegration *WindowManagerServerIntegration::m_instance = 0; @@ -94,22 +105,50 @@ void WindowManagerServerIntegration::initialize(Wayland::Display *waylandDisplay void WindowManagerServerIntegration::removeClient(wl_client *client) { - m_clientToProcessId.remove(client); + WaylandManagedClient *managedClient = m_managedClients.take(client); + delete managedClient; } void WindowManagerServerIntegration::mapClientToProcess(wl_client *client, uint32_t processId) { - m_clientToProcessId.insert(client, processId); - emit clientMappedToProcess(client, processId); + WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient); + managedClient->m_processId = processId; + m_managedClients.insert(client, managedClient); } +void WindowManagerServerIntegration::authenticateWithToken(wl_client *client, const char *token) +{ + WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient); + managedClient->m_authenticationToken = QByteArray(token); + m_managedClients.insert(client, managedClient); +} -qint64 WindowManagerServerIntegration::pidForClient(wl_client *client) const +WaylandManagedClient *WindowManagerServerIntegration::managedClient(wl_client *client) const { - return m_clientToProcessId.value(client, 0); + return m_managedClients.value(client, 0); } WindowManagerServerIntegration *WindowManagerServerIntegration::instance() { return m_instance; } + +/// /// +/// / WaylandManagedClient +/// /// + +WaylandManagedClient::WaylandManagedClient() + : m_processId(0) +{ + +} + +qint64 WaylandManagedClient::processId() const +{ + return m_processId; +} + +QByteArray WaylandManagedClient::authenticationToken() const +{ + return m_authenticationToken; +} diff --git a/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h b/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h index e198c44..b3e90af 100644 --- a/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h +++ b/src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h @@ -53,6 +53,7 @@ struct wl_client; class WindowManagerObject; +class WaylandManagedClient; class WindowManagerServerIntegration : public QObject { @@ -63,16 +64,14 @@ public: void initialize(Wayland::Display *waylandDisplay); void removeClient(wl_client *client); - qint64 pidForClient(wl_client *client) const; - -signals: - void clientMappedToProcess(wl_client *client, quint32 processId); + WaylandManagedClient *managedClient(wl_client *client) const; private: void mapClientToProcess(wl_client *client, uint32_t processId); + void authenticateWithToken(wl_client *client, const char *token); private: - QMap m_clientToProcessId; + QMap m_managedClients; static WindowManagerServerIntegration *m_instance; WindowManagerObject *m_windowManagerObject; @@ -80,4 +79,18 @@ private: friend class WindowManagerObject; }; +class WaylandManagedClient +{ +public: + WaylandManagedClient(); + qint64 processId() const; + QByteArray authenticationToken() const; + +private: + qint64 m_processId; + QByteArray m_authenticationToken; + + friend class WindowManagerServerIntegration; +}; + #endif // WAYLANDWINDOWMANAGERINTEGRATION_H -- 2.7.4