Skip to content

Commit

Permalink
Fix HostObject::connectionUid returning the wrong UID.
Browse files Browse the repository at this point in the history
Don't use 0 and an invalid ID as that's root, and work around a
timing issue that was causing the invalid ID to be returned.
  • Loading branch information
adenexter committed Jan 24, 2017
1 parent 5625d03 commit a2fab93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/nemo-devicelock/host/hostobject.cpp
Expand Up @@ -125,12 +125,12 @@ unsigned long HostObject::connectionPid(const QDBusConnection &connection)

unsigned long HostObject::connectionUid(const QDBusConnection &connection)
{
unsigned long uid = 0;
unsigned long uid = -1;
if (dbus_connection_get_unix_user(
static_cast<DBusConnection *>(connection.internalPointer()), &uid)) {
return uid;
} else {
return 0;
return -1;
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/nemo-devicelock/host/hostservice.cpp
Expand Up @@ -43,6 +43,7 @@
#include <QDBusConnection>
#include <QDBusMetaType>
#include <QDir>
#include <QThread>

#include <dbus/dbus.h>
#include <systemd/sd-daemon.h>
Expand Down Expand Up @@ -153,10 +154,20 @@ void HostService::connectionReady(const QDBusConnection &newConnection)
qCWarning(daemon, "Failed to connect to disconnect signal");
}

const auto connectionName = newConnection.name();
// The PID and UID of the connecting process can't be acquired until after the connection
// is authenticated which is done concurrently to the invokation of this slot. Block until
// the connection is authenticated or disconnected before trying to decide which services
// a process should have access to.
auto internalConnection = static_cast<DBusConnection *>(connection.internalPointer());
while (dbus_connection_get_is_connected(internalConnection)
&& !dbus_connection_get_is_authenticated(internalConnection)) {
QThread::usleep(100);
}

const auto connectionName = connection.name();

for (const auto object : m_objects) {
if (object->authorizeConnection(newConnection)) {
if (object->authorizeConnection(connection)) {
registerObject(connection, object->path(), object);
object->clientConnected(connectionName);
}
Expand Down

0 comments on commit a2fab93

Please sign in to comment.