Correct authentication behavior
authorMartin Zielinski <martin.zielinski@nokia.com>
Mon, 4 Jul 2011 07:54:42 +0000 (09:54 +0200)
committerMartin Zielinski <martin.zielinski@nokia.com>
Wed, 6 Jul 2011 09:27:23 +0000 (11:27 +0200)
The authentication of clients via windowmanager-token is now
more robust. This is needed to get the app-booster usecase working
correctly.

src/qt-compositor/wayland_wrapper/wlcompositor.cpp
src/qt-compositor/wayland_wrapper/wlcompositor.h
src/qt-compositor/wayland_wrapper/wlsurface.cpp
src/qt-compositor/wayland_wrapper/wlsurface.h
src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp
src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h

index 9522001..65c074f 100644 (file)
@@ -268,14 +268,7 @@ void Compositor::createSurface(struct wl_client *client, int id)
     addClientResource(client, &surface->base()->resource, id, &wl_surface_interface,
             &surface_interface, destroy_surface);
 
-    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_windowManagerWaylandProtocol->updateOrientation(client);
-    }
-
     m_qt_compositor->surfaceCreated(surface->handle());
 
     QList<struct wl_client *> prevClientList = clients();
@@ -332,6 +325,7 @@ void Compositor::processWaylandEvents()
         fprintf(stderr, "wl_event_loop_dispatch error: %d\n", ret);
 }
 
+
 void Compositor::surfaceDestroyed(Surface *surface)
 {
     m_surfaces.removeOne(surface);
@@ -456,3 +450,16 @@ wl_input_device * Wayland::Compositor::defaultInputDevice()
 {
     return &m_input;
 }
+
+QList<Wayland::Surface *> Wayland::Compositor::surfacesForClient(wl_client *client)
+{
+    QList<Wayland::Surface *> ret;
+
+    for (int i=0; i < m_surfaces.count(); ++i) {
+        if (m_surfaces.at(i)->clientHandle() == client) {
+            ret.append(m_surfaces.at(i));
+        }
+    }
+    return ret;
+}
+
index 21a4109..be63a94 100644 (file)
@@ -96,6 +96,8 @@ public:
     bool setDirectRenderSurface(Surface *surface);
     Surface *directRenderSurface() const {return m_directRenderSurface;}
 
+    QList<Surface*> surfacesForClient(wl_client* client);
+
     wl_input_device *defaultInputDevice();
     WaylandCompositor *qtCompositor() const { return m_qt_compositor; }
 
index 52d793e..d653a82 100644 (file)
@@ -270,13 +270,7 @@ void Surface::setProcessId(qint64 processId)
 QByteArray Surface::authenticationToken() const
 {
     Q_D(const Surface);
-    return d->authenticationToken;
-}
-
-void Surface::setAuthenticationToken(const QByteArray &authenticationToken)
-{
-    Q_D(Surface);
-    d->authenticationToken = authenticationToken;
+    return WindowManagerServerIntegration::instance()->managedClient(d->client)->authenticationToken();
 }
 
 uint32_t toWaylandButton(Qt::MouseButton button)
index 2a699a9..ed6e0aa 100644 (file)
@@ -105,7 +105,6 @@ public:
     qint64 processId() const;
     void setProcessId(qint64 processId);
     QByteArray authenticationToken() const;
-    void setAuthenticationToken(const QByteArray &authenticationToken);
 
     void setSurfaceCreationFinished(bool isCreated);
 
index de3ca8c..5fb9ea0 100644 (file)
@@ -61,11 +61,13 @@ public:
 
     void mapClientToProcess(wl_client *client, uint32_t processId)
     {
+        //qDebug() << "COMPOSITOR:" << Q_FUNC_INFO << client << processId;
         WindowManagerServerIntegration::instance()->mapClientToProcess(client, processId);
     }
 
     void authenticateWithToken(wl_client *client, const char *authenticationToken)
     {
+        //qDebug() << "COMPOSITOR:" << Q_FUNC_INFO << client << authenticationToken;
         WindowManagerServerIntegration::instance()->authenticateWithToken(client, authenticationToken);
     }
 
@@ -122,9 +124,13 @@ void WindowManagerServerIntegration::mapClientToProcess(wl_client *client, uint3
 
 void WindowManagerServerIntegration::authenticateWithToken(wl_client *client, const char *token)
 {
+    Q_ASSERT(token != 0 && *token != 0);
+
     WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient);
     managedClient->m_authenticationToken = QByteArray(token);
     m_managedClients.insert(client, managedClient);
+
+    emit clientAuthenticated(client);
 }
 
 void WindowManagerServerIntegration::changeScreenVisibility(wl_client *client, int visible)
index 199c96b..be7c609 100644 (file)
@@ -44,7 +44,6 @@
 
 #include <qwindowdefs.h>
 #include <stdint.h>
-#include "wayland_wrapper/wldisplay.h"
 
 #include <QObject>
 #include <QMap>
 
 struct wl_client;
 
+namespace Wayland {
+    class Display;
+}
+
 class WindowManagerObject;
 class WaylandManagedClient;
 
@@ -70,6 +73,10 @@ public:
     void setScreenOrientation(wl_client *client, qint32 orientationInDegrees);
     void updateOrientation(wl_client *client);
 
+
+signals:
+    void clientAuthenticated(wl_client *client);
+
 private:
     void mapClientToProcess(wl_client *client, uint32_t processId);
     void authenticateWithToken(wl_client *client, const char *token);