Skip to content

Commit

Permalink
Merge branch 'jb42126' into 'master'
Browse files Browse the repository at this point in the history
Use P2P DBus for all signon flows

See merge request mer-core/libsignon!1
  • Loading branch information
chriadam committed Jun 22, 2018
2 parents b00ded9 + ddc271b commit 91ed876
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 7 deletions.
21 changes: 18 additions & 3 deletions libsignon/lib/SignOn/connection-manager.cpp
Expand Up @@ -40,7 +40,8 @@ static QPointer<ConnectionManager> connectionInstance = 0;
ConnectionManager::ConnectionManager(QObject *parent):
QObject(parent),
m_connection(QLatin1String("libsignon-qt-invalid")),
m_serviceStatus(ServiceStatusUnknown)
m_serviceStatus(ServiceStatusUnknown),
m_retryCount(0)
{
if (connectionInstance == 0) {
init();
Expand Down Expand Up @@ -128,6 +129,21 @@ void ConnectionManager::init()

SocketConnectionStatus status = setupSocketConnection();

if (status == SocketConnectionUnavailable) {
#ifdef ENABLE_P2P
if (m_retryCount >= 15) {
BLAME() << "Unable to activate p2p signond service!";
return;
}
TRACE() << "Unable to activate p2p signond service, trying again";
status = SocketConnectionNoService;
m_retryCount += 1;
#else
TRACE() << "Unable to activate p2p signond service, falling back to session bus";
m_connection = SIGNOND_BUS;
#endif
}

if (status == SocketConnectionNoService) {
TRACE() << "Peer connection unavailable, activating service";
QDBusConnectionInterface *interface =
Expand All @@ -142,11 +158,10 @@ void ConnectionManager::init()
SIGNAL(finished(QDBusPendingCallWatcher*)),
this,
SLOT(onActivationDone(QDBusPendingCallWatcher*)));
} else if (status == SocketConnectionUnavailable) {
m_connection = SIGNOND_BUS;
}

if (m_connection.isConnected()) {
m_retryCount = 0;
TRACE() << "Connected to" << m_connection.name();
Q_EMIT connected(m_connection);
}
Expand Down
1 change: 1 addition & 0 deletions libsignon/lib/SignOn/connection-manager.h
Expand Up @@ -74,6 +74,7 @@ private Q_SLOTS:
private:
QDBusConnection m_connection;
ServiceStatus m_serviceStatus;
int m_retryCount;
};

}
Expand Down
4 changes: 4 additions & 0 deletions libsignon/lib/SignOn/libsignon-qt.pri
Expand Up @@ -57,6 +57,10 @@ DEFINES += \
QT_NO_CAST_FROM_ASCII \
LIBSIGNON_TRACE

CONFIG(enable-p2p) {
DEFINES += ENABLE_P2P
}

include( $$TOP_SRC_DIR/common-installs-config.pri )

headers.files = $$public_headers \
Expand Down
26 changes: 24 additions & 2 deletions libsignon/src/signond/signonidentity.cpp
Expand Up @@ -26,6 +26,9 @@

#include <iostream>
#include <QVariantMap>
#ifdef ENABLE_P2P
#include <QStandardPaths>
#endif

#include "signond-common.h"
#include "signonidentity.h"
Expand Down Expand Up @@ -85,10 +88,11 @@ class PendingCallWatcherWithContext: public QDBusPendingCallWatcher
SignonIdentity::SignonIdentity(quint32 id, int timeout,
SignonDaemon *parent):
SignonDisposable(timeout, parent),
m_id(id),
m_p2pc(QStringLiteral("identity.dbus.connection")),
m_signonui(NULL),
m_pInfo(NULL)
{
m_id = id;

(void)new SignonIdentityAdaptor(this);

/*
Expand All @@ -99,10 +103,28 @@ SignonIdentity::SignonIdentity(quint32 id, int timeout,
+ QString::number(incr++, 16);
setObjectName(objectName);

#ifdef ENABLE_P2P
m_p2pc = QDBusConnection::connectToPeer(
QStringLiteral("unix:path=%1/signonui-socket")
.arg(QStandardPaths::writableLocation(
QStandardPaths::RuntimeLocation)),
objectName);
if (!m_p2pc.isConnected()) {
BLAME() << "Identity unable to connect to signonui socket:"
<< m_p2pc.lastError()
<< m_p2pc.lastError().type()
<< m_p2pc.lastError().name();
}
m_signonui = new SignonUiAdaptor(SIGNON_UI_SERVICE,
SIGNON_UI_DAEMON_OBJECTPATH,
m_p2pc,
this);
#else
m_signonui = new SignonUiAdaptor(SIGNON_UI_SERVICE,
SIGNON_UI_DAEMON_OBJECTPATH,
QDBusConnection::sessionBus(),
this);
#endif

/* Watch for credential updates happening outside of this object (this can
* happen on request of authentication plugins) */
Expand Down
1 change: 1 addition & 0 deletions libsignon/src/signond/signonidentity.h
Expand Up @@ -95,6 +95,7 @@ private Q_SLOTS:

private:
quint32 m_id;
QDBusConnection m_p2pc;
SignonUiAdaptor *m_signonui;
SignonIdentityInfo *m_pInfo;
}; //class SignonDaemon
Expand Down
36 changes: 34 additions & 2 deletions libsignon/src/signond/signonsessioncore.cpp
Expand Up @@ -33,6 +33,10 @@
#include "SignOn/authpluginif.h"
#include "SignOn/signonerror.h"

#ifdef ENABLE_P2P
#include <QStandardPaths>
#endif

#define MAX_IDLE_TIME SIGNOND_MAX_IDLE_TIME
/*
* the watchdog searches for idle sessions with period of half of idle timeout
Expand Down Expand Up @@ -76,6 +80,7 @@ SignonSessionCore::SignonSessionCore(quint32 id,
int timeout,
QObject *parent):
SignonDisposable(timeout, parent),
m_p2pc(QStringLiteral("session.dbus.connection")),
m_signonui(0),
m_watcher(0),
m_requestIsActive(false),
Expand All @@ -84,10 +89,26 @@ SignonSessionCore::SignonSessionCore(quint32 id,
m_method(method),
m_queryCredsUiDisplayed(false)
{
#ifdef ENABLE_P2P
m_p2pc = QDBusConnection::connectToPeer(
QStringLiteral("unix:path=%1/signonui-socket")
.arg(QStandardPaths::writableLocation(
QStandardPaths::RuntimeLocation)),
QStringLiteral("signon-session-core-%1").arg(id));
if (!m_p2pc.isConnected()) {
BLAME() << "Session unable to connect to signonui socket:"
<< m_p2pc.lastError()
<< m_p2pc.lastError().type()
<< m_p2pc.lastError().name();
}
m_signonui = new SignonUiAdaptor(SIGNON_UI_SERVICE,
SIGNON_UI_DAEMON_OBJECTPATH,
m_p2pc);
#else
m_signonui = new SignonUiAdaptor(SIGNON_UI_SERVICE,
SIGNON_UI_DAEMON_OBJECTPATH,
QDBusConnection::sessionBus());

#endif

connect(CredentialsAccessManager::instance(),
SIGNAL(credentialsSystemReady()),
Expand Down Expand Up @@ -326,13 +347,24 @@ void SignonSessionCore::setId(quint32 id)

void SignonSessionCore::startProcess()
{

TRACE() << "the number of requests is" << m_listOfRequests.length();

m_requestIsActive = true;
RequestData data = m_listOfRequests.head();
QVariantMap parameters = data.m_params;

#ifdef ENABLE_P2P
/* inject the in-process signon ui bus address */
pid_t clientPid = AccessControlManagerHelper::pidOfPeer(
data.m_conn, data.m_msg);
parameters.insert(
QStringLiteral("InProcessBusAddress"),
QStringLiteral("unix:path=%1/signonui-%2-socket")
.arg(QStandardPaths::writableLocation(
QStandardPaths::RuntimeLocation))
.arg(clientPid));
#endif

/* save the client data; this should not be modified during the processing
* of this request */
m_clientData = parameters;
Expand Down
1 change: 1 addition & 0 deletions libsignon/src/signond/signonsessioncore.h
Expand Up @@ -126,6 +126,7 @@ private Q_SLOTS:
private:
PluginProxy *m_plugin;
QQueue<RequestData> m_listOfRequests;
QDBusConnection m_p2pc;
SignonUiAdaptor *m_signonui;

QDBusPendingCallWatcher *m_watcher;
Expand Down

0 comments on commit 91ed876

Please sign in to comment.