telepathy-qt: dbus-tubes: Implement proper handling of SCM_CREDENTIALS
Dario Freddi
drf at kemper.freedesktop.org
Tue Jul 3 15:08:42 PDT 2012
Module: telepathy-qt
Branch: master
Commit: 3ad1c46263cd4a0e11dbfcaf33c78c96bfe9e883
URL: http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=3ad1c46263cd4a0e11dbfcaf33c78c96bfe9e883
Author: Dario Freddi <dario.freddi at collabora.com>
Date: Tue Nov 1 23:12:25 2011 +0100
dbus-tubes: Implement proper handling of SCM_CREDENTIALS
---
TelepathyQt/incoming-dbus-tube-channel.cpp | 23 +++++++++++++++-
TelepathyQt/outgoing-dbus-tube-channel.cpp | 3 +-
TelepathyQt/pending-dbus-tube.cpp | 39 +++++++++++++++++++++++++++-
TelepathyQt/pending-dbus-tube.h | 11 +++++--
4 files changed, 69 insertions(+), 7 deletions(-)
diff --git a/TelepathyQt/incoming-dbus-tube-channel.cpp b/TelepathyQt/incoming-dbus-tube-channel.cpp
index d84bf90..cad3a5f 100644
--- a/TelepathyQt/incoming-dbus-tube-channel.cpp
+++ b/TelepathyQt/incoming-dbus-tube-channel.cpp
@@ -41,10 +41,13 @@ public:
// Public object
IncomingDBusTubeChannel *parent;
+ static bool initRandom;
};
+bool IncomingDBusTubeChannel::Private::initRandom = true;
+
IncomingDBusTubeChannel::Private::Private(IncomingDBusTubeChannel *parent)
- : parent(parent)
+ : parent(parent)
{
}
@@ -223,12 +226,28 @@ PendingDBusTube *IncomingDBusTubeChannel::acceptTube(bool requireCredentials)
IncomingDBusTubeChannelPtr(this));
}
+ QDBusVariant accessControlParam;
+ uchar credentialByte = 0;
+ if (accessControl == SocketAccessControlLocalhost) {
+ accessControlParam.setVariant(qVariantFromValue(static_cast<uint>(0)));
+ } else if (accessControl == SocketAccessControlCredentials) {
+ if (mPriv->initRandom) {
+ qsrand(QTime::currentTime().msec());
+ mPriv->initRandom = false;
+ }
+ credentialByte = static_cast<uchar>(qrand());
+ accessControlParam.setVariant(qVariantFromValue(credentialByte));
+ } else {
+ Q_ASSERT(false);
+ }
+
PendingString *ps = new PendingString(
interface<Client::ChannelTypeDBusTubeInterface>()->Accept(
accessControl),
IncomingDBusTubeChannelPtr(this));
- PendingDBusTube *op = new PendingDBusTube(ps, IncomingDBusTubeChannelPtr(this));
+ PendingDBusTube *op = new PendingDBusTube(ps, requireCredentials,
+ credentialByte, IncomingDBusTubeChannelPtr(this));
return op;
}
diff --git a/TelepathyQt/outgoing-dbus-tube-channel.cpp b/TelepathyQt/outgoing-dbus-tube-channel.cpp
index 3504919..a2e036b 100644
--- a/TelepathyQt/outgoing-dbus-tube-channel.cpp
+++ b/TelepathyQt/outgoing-dbus-tube-channel.cpp
@@ -199,7 +199,8 @@ PendingDBusTube *OutgoingDBusTubeChannel::offerTube(const QVariantMap ¶meter
accessControl),
OutgoingDBusTubeChannelPtr(this));
- PendingDBusTube *op = new PendingDBusTube(ps, OutgoingDBusTubeChannelPtr(this));
+ PendingDBusTube *op = new PendingDBusTube(ps, requireCredentials,
+ 0, OutgoingDBusTubeChannelPtr(this));
return op;
}
diff --git a/TelepathyQt/pending-dbus-tube.cpp b/TelepathyQt/pending-dbus-tube.cpp
index c4da9db..e3c85be 100644
--- a/TelepathyQt/pending-dbus-tube.cpp
+++ b/TelepathyQt/pending-dbus-tube.cpp
@@ -41,10 +41,15 @@ struct TP_QT_NO_EXPORT PendingDBusTube::Private
PendingDBusTube *parent;
DBusTubeChannelPtr tube;
+
+ bool requiresCredentials;
+ uchar credentialByte;
};
PendingDBusTube::Private::Private(PendingDBusTube *parent)
- : parent(parent)
+ : parent(parent),
+ requiresCredentials(false),
+ credentialByte(0)
{
}
@@ -64,12 +69,17 @@ PendingDBusTube::Private::~Private()
PendingDBusTube::PendingDBusTube(
PendingString *string,
+ bool requiresCredentials,
+ uchar credentialByte,
const DBusTubeChannelPtr &object)
: PendingOperation(object)
, mPriv(new Private(this))
{
mPriv->tube = object;
+ mPriv->requiresCredentials = requiresCredentials;
+ mPriv->credentialByte = credentialByte;
+
connect(mPriv->tube.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
this, SLOT(onChannelInvalidated(Tp::DBusProxy*,QString,QString)));
@@ -114,6 +124,33 @@ QString PendingDBusTube::address() const
return mPriv->tube->address();
}
+/**
+ * Return whether sending a credential byte once connecting to the socket is required.
+ *
+ * Note that if this method returns \c true, one should send a SCM_CREDS or SCM_CREDENTIALS
+ * and the credentialByte() once connected. If SCM_CREDS or SCM_CREDENTIALS cannot be sent,
+ * the credentialByte() should still be sent.
+ *
+ * \return \c true if sending credentials is required, \c false otherwise.
+ * \sa credentialByte()
+ */
+bool PendingDBusTube::requiresCredentials() const
+{
+ return mPriv->requiresCredentials;
+}
+
+/**
+ * Return the credential byte to send once connecting to the socket if requiresCredentials() is \c
+ * true.
+ *
+ * \return The credential byte.
+ * \sa requiresCredentials()
+ */
+uchar PendingDBusTube::credentialByte() const
+{
+ return mPriv->credentialByte;
+}
+
void PendingDBusTube::onConnectionFinished(PendingOperation *op)
{
if (isFinished()) {
diff --git a/TelepathyQt/pending-dbus-tube.h b/TelepathyQt/pending-dbus-tube.h
index 45948ac..bebb2ef 100644
--- a/TelepathyQt/pending-dbus-tube.h
+++ b/TelepathyQt/pending-dbus-tube.h
@@ -42,6 +42,9 @@ public:
QString address() const;
+ bool requiresCredentials() const;
+ uchar credentialByte() const;
+
private Q_SLOTS:
TP_QT_NO_EXPORT void onConnectionFinished(Tp::PendingOperation *op);
TP_QT_NO_EXPORT void onStateChanged(Tp::TubeChannelState state);
@@ -50,9 +53,11 @@ private Q_SLOTS:
const QString &errorMessage);
private:
- PendingDBusTube(PendingString *string, const DBusTubeChannelPtr &object);
- PendingDBusTube(const QString &errorName, const QString &errorMessage,
- const DBusTubeChannelPtr &object);
+ TP_QT_NO_EXPORT PendingDBusTube(PendingString *string,
+ bool requiresCredentials, uchar credentialByte,
+ const DBusTubeChannelPtr &object);
+ TP_QT_NO_EXPORT PendingDBusTube(const QString &errorName, const QString &errorMessage,
+ const DBusTubeChannelPtr &object);
struct Private;
friend class OutgoingDBusTubeChannel;
More information about the telepathy-commits
mailing list