Add method to QDBusServer to allow anonymous client connections.
This change adds a new method to QDBusServer to allow anonymous connections. This is part of the DBus API and was not yet possible to use with QDBusServer. It is set in the newConnection callback when a new client tries to connect. Anonymous connections are enabled by default in DBus but not allowed by default. [ChangeLog][QtDBus][QDBusServer] Added method to QDBusServer to allow anonymous client connections, even if the connecting client is not authenticated as a user. Change-Id: I984c9e634101ecd2e67bb25c8d12bb1071836fd3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
40133df06f
commit
419a1f53d5
@ -183,6 +183,9 @@ DEFINEFUNC(unsigned int , dbus_watch_get_flags, (DBusWatch *watch),
|
||||
DEFINEFUNC(dbus_bool_t , dbus_watch_handle, (DBusWatch *watch,
|
||||
unsigned int flags),
|
||||
(watch, flags), return)
|
||||
DEFINEFUNC(void , dbus_connection_set_allow_anonymous, (DBusConnection *connection,
|
||||
dbus_bool_t value),
|
||||
(connection, value), return)
|
||||
|
||||
/* dbus-errors.h */
|
||||
DEFINEFUNC(void , dbus_error_free, (DBusError *error),
|
||||
|
@ -322,6 +322,8 @@ public:
|
||||
QMutex callDeliveryMutex;
|
||||
QDBusCallDeliveryEvent *callDeliveryState; // protected by the callDeliveryMutex mutex
|
||||
|
||||
bool anonymousAuthenticationAllowed;
|
||||
|
||||
public:
|
||||
// static methods
|
||||
static int findSlot(QObject *obj, const QByteArray &normalizedName, QVector<int> ¶ms);
|
||||
|
@ -391,6 +391,10 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v
|
||||
q_dbus_connection_ref(connection);
|
||||
QDBusConnectionPrivate *serverConnection = static_cast<QDBusConnectionPrivate *>(data);
|
||||
|
||||
// allow anonymous authentication
|
||||
if (serverConnection->anonymousAuthenticationAllowed)
|
||||
q_dbus_connection_set_allow_anonymous(connection, true);
|
||||
|
||||
QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate(serverConnection->parent());
|
||||
QMutexLocker locker(&QDBusConnectionManager::instance()->mutex);
|
||||
QDBusConnectionManager::instance()->setConnection(QLatin1String("QDBusServer-") + QString::number(reinterpret_cast<qulonglong>(newConnection)), newConnection);
|
||||
@ -1014,7 +1018,8 @@ extern bool qDBusInitThreads();
|
||||
QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
|
||||
: QObject(p), ref(1), capabilities(0), mode(InvalidMode), connection(0), server(0), busService(0),
|
||||
watchAndTimeoutLock(QMutex::Recursive),
|
||||
rootNode(QString(QLatin1Char('/')))
|
||||
rootNode(QString(QLatin1Char('/'))),
|
||||
anonymousAuthenticationAllowed(false)
|
||||
{
|
||||
static const bool threads = q_dbus_threads_init_default();
|
||||
static const int debugging = qgetenv("QDBUS_DEBUG").toInt();
|
||||
|
@ -149,6 +149,33 @@ QString QDBusServer::address() const
|
||||
return addr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.3
|
||||
|
||||
If \a value is set to true, an incoming connection can proceed even if the
|
||||
connecting client is not authenticated as a user.
|
||||
|
||||
By default, this value is false.
|
||||
|
||||
\sa isAnonymousAuthenticationAllowed()
|
||||
*/
|
||||
void QDBusServer::setAnonymousAuthenticationAllowed(bool value)
|
||||
{
|
||||
d->anonymousAuthenticationAllowed = value;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.3
|
||||
|
||||
Returns true if anonymous authentication is allowed.
|
||||
|
||||
\sa setAnonymousAuthenticationAllowed()
|
||||
*/
|
||||
bool QDBusServer::isAnonymousAuthenticationAllowed() const
|
||||
{
|
||||
return d->anonymousAuthenticationAllowed;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void QDBusServer::newConnection(const QDBusConnection &connection)
|
||||
|
||||
|
@ -66,6 +66,9 @@ public:
|
||||
QDBusError lastError() const;
|
||||
QString address() const;
|
||||
|
||||
void setAnonymousAuthenticationAllowed(bool value);
|
||||
bool isAnonymousAuthenticationAllowed() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void newConnection(const QDBusConnection &connection);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user