summaryrefslogtreecommitdiff
path: root/gdbus/gdbusconnection.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdbus/gdbusconnection.c')
-rw-r--r--gdbus/gdbusconnection.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/gdbus/gdbusconnection.c b/gdbus/gdbusconnection.c
index b4a272e..bfa859f 100644
--- a/gdbus/gdbusconnection.c
+++ b/gdbus/gdbusconnection.c
@@ -114,6 +114,7 @@
#include "gdbusintrospection.h"
#include "gdbusmethodinvocation.h"
#include "gdbusprivate.h"
+#include "gdbusauthobserver.h"
#include "gdbus-marshal.h"
/**
@@ -258,6 +259,9 @@ struct _GDBusConnectionPrivate
/* Capabilities negotiated during authentication */
GDBusCapabilityFlags capabilities;
+
+ GDBusAuthObserver *authentication_observer;
+ GCredentials *crendentials;
};
typedef struct ExportedObject ExportedObject;
@@ -283,6 +287,7 @@ enum
PROP_CLOSED,
PROP_EXIT_ON_CLOSE,
PROP_CAPABILITY_FLAGS,
+ PROP_AUTHENTICATION_OBSERVER,
};
static void distribute_signals (GDBusConnection *connection,
@@ -347,6 +352,9 @@ g_dbus_connection_finalize (GObject *object)
{
GDBusConnection *connection = G_DBUS_CONNECTION (object);
+ if (connection->priv->authentication_observer != NULL)
+ g_object_unref (connection->priv->authentication_observer);
+
if (connection->priv->auth != NULL)
g_object_unref (connection->priv->auth);
@@ -468,6 +476,10 @@ g_dbus_connection_set_property (GObject *object,
g_dbus_connection_set_exit_on_close (connection, g_value_get_boolean (value));
break;
+ case PROP_AUTHENTICATION_OBSERVER:
+ connection->priv->authentication_observer = g_value_dup_object (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -657,6 +669,23 @@ g_dbus_connection_class_init (GDBusConnectionClass *klass)
G_PARAM_STATIC_NICK));
/**
+ * GDBusConnection:authentication-observer:
+ *
+ * A #GDBusAuthObserver object to assist in the authentication process or %NULL.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_AUTHENTICATION_OBSERVER,
+ g_param_spec_object ("authentication-observer",
+ _("Authentication Observer"),
+ _("Object used to assist in the authentication process"),
+ G_TYPE_DBUS_AUTH_OBSERVER,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NICK));
+
+ /**
* GDBusConnection::closed:
* @connection: The #GDBusConnection emitting the signal.
* @remote_peer_vanished: %TRUE if @connection is closed because the
@@ -1575,10 +1604,12 @@ initable_init (GInitable *initable,
g_assert (connection->priv->guid != NULL);
connection->priv->auth = _g_dbus_auth_new (connection->priv->stream);
if (!_g_dbus_auth_run_server (connection->priv->auth,
+ connection->priv->authentication_observer,
connection->priv->guid,
(connection->priv->flags & G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS),
get_offered_capabilities_max (connection),
&connection->priv->capabilities,
+ &connection->priv->crendentials,
cancellable,
&connection->priv->initialization_error))
goto out;
@@ -1597,6 +1628,14 @@ initable_init (GInitable *initable,
goto out;
}
+ if (connection->priv->authentication_observer != NULL)
+ {
+ g_object_unref (connection->priv->authentication_observer);
+ connection->priv->authentication_observer = NULL;
+ }
+
+ //g_output_stream_flush (G_SOCKET_CONNECTION (connection->priv->stream)
+
//g_debug ("haz unix fd passing powers: %d", connection->priv->capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
/* Hack used until
@@ -1721,6 +1760,7 @@ async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
* @stream: A #GIOStream.
* @guid: The GUID to use if a authenticating as a server or %NULL.
* @flags: Flags describing how to make the connection.
+ * @authentication_observer: A #GDBusAuthObserver or %NULL.
* @cancellable: A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied.
* @user_data: The data to pass to @callback.
@@ -1728,6 +1768,10 @@ async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
* Asynchronously sets up a D-Bus connection for exchanging D-Bus messages
* with the end represented by @stream.
*
+ * If %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER is set in @flags,
+ * @auth_observer (if not %NULL) is used to assist in the client
+ * authentication process.
+ *
* When the operation is finished, @callback will be invoked. You can
* then call g_dbus_connection_new_finish() to get the result of the
* operation.
@@ -1740,6 +1784,7 @@ void
g_dbus_connection_new (GIOStream *stream,
const gchar *guid,
GDBusConnectionFlags flags,
+ GDBusAuthObserver *authentication_observer,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -1753,6 +1798,7 @@ g_dbus_connection_new (GIOStream *stream,
"stream", stream,
"guid", guid,
"flags", flags,
+ "authentication-observer", authentication_observer,
NULL);
}
@@ -1792,12 +1838,17 @@ g_dbus_connection_new_finish (GAsyncResult *res,
* @stream: A #GIOStream.
* @guid: The GUID to use if a authenticating as a server or %NULL.
* @flags: Flags describing how to make the connection.
+ * @authentication_observer: A #GDBusAuthObserver or %NULL.
* @cancellable: A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously sets up a D-Bus connection for exchanging D-Bus messages
* with the end represented by @stream.
*
+ * If %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER is set in @flags,
+ * @auth_observer (if not %NULL) is used to assist in the client
+ * authentication process.
+ *
* This is a synchronous failable constructor. See
* g_dbus_connection_new() for the asynchronous version.
*
@@ -1807,6 +1858,7 @@ GDBusConnection *
g_dbus_connection_new_sync (GIOStream *stream,
const gchar *guid,
GDBusConnectionFlags flags,
+ GDBusAuthObserver *authentication_observer,
GCancellable *cancellable,
GError **error)
{
@@ -1818,6 +1870,7 @@ g_dbus_connection_new_sync (GIOStream *stream,
"stream", stream,
"guid", guid,
"flags", flags,
+ "authentication-observer", authentication_observer,
NULL);
}
@@ -2010,6 +2063,30 @@ g_dbus_connection_get_unique_name (GDBusConnection *connection)
return connection->priv->bus_unique_name;
}
+/**
+ * g_dbus_connection_get_peer_credentials:
+ * @connection: A #GDBusConnection.
+ *
+ * Gets the credentials of the authenticated peer. This will always
+ * return %NULL unless @connection acted as a server
+ * (e.g. %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER was passed)
+ * when set up and the client passed credentials as part of the
+ * authentication process.
+ *
+ * In a message bus setup, the message bus is always the server and
+ * each application is a client. So this method will always return
+ * %NULL for message bus clients.
+ *
+ * Returns: A #GCredentials or %NULL if not available. Do not free
+ * this object, it is owned by @connection.
+ */
+GCredentials *
+g_dbus_connection_get_peer_credentials (GDBusConnection *connection)
+{
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+ return connection->priv->crendentials;
+}
+
/* ---------------------------------------------------------------------------------------------------- */
static guint _global_filter_id = 1;