1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of gsignond
6 * Copyright (C) 2012-2013 Intel Corporation.
8 * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include "gsignond/gsignond-log.h"
28 #include "gsignond/gsignond-utils.h"
29 #include "gsignond-dbus-identity-adapter.h"
30 #include "gsignond-dbus-auth-session-adapter.h"
31 #include "gsignond-dbus.h"
43 static GParamSpec *properties[N_PROPERTIES];
46 GSignondDbusIdentityAdapter *adapter;
47 GDBusMethodInvocation *invocation;
51 static _IdentityDbusInfo*
52 _identity_dbus_info_new (GSignondDbusIdentityAdapter *self, GDBusMethodInvocation *invocation, gpointer userdata)
54 _IdentityDbusInfo *info = g_new0(_IdentityDbusInfo, 1);
56 info->adapter = g_object_ref (self);
57 info->invocation = g_object_ref (invocation);
58 info->user_data = userdata;
64 _identity_dbus_info_free (_IdentityDbusInfo *info)
68 if (info->adapter) g_object_unref (info->adapter);
69 if (info->invocation) g_object_unref (info->invocation);
74 struct _GSignondDbusIdentityAdapterPrivate
76 GDBusConnection *connection;
77 GSignondDbusIdentity *dbus_identity;
78 GSignondIdentity *identity;
80 GSignondSecurityContext *sec_context;
82 /* signal handler ids */
83 gulong info_updated_handler_id;
84 gulong verify_user_handler_id;
85 gulong verify_secret_handler_id;
86 gulong credentials_update_handler_id;
89 G_DEFINE_TYPE (GSignondDbusIdentityAdapter, gsignond_dbus_identity_adapter, GSIGNOND_TYPE_DISPOSABLE)
91 #define GSIGNOND_DBUS_IDENTITY_ADAPTER_GET_PRIV(obj) \
92 G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSIGNOND_TYPE_DBUS_IDENTITY_ADAPTER, GSignondDbusIdentityAdapterPrivate)
94 #define PREPARE_SECURITY_CONTEXT(dbus_object, invocation) \
96 GSignondDbusIdentityAdapterPrivate *priv = dbus_object->priv;\
97 GSignondAccessControlManager *acm = gsignond_identity_get_acm (priv->identity);\
99 const gchar *sender = NULL; \
101 sender = g_dbus_method_invocation_get_sender (invocation);\
103 GDBusConnection *connection = g_dbus_method_invocation_get_connection (invocation);\
104 fd = g_socket_get_fd (g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream(connection))));\
106 gsignond_access_control_manager_security_context_of_peer( \
111 priv->app_context); \
115 static gboolean _handle_request_credentials_update (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar*, gpointer);
116 static gboolean _handle_get_info (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, gpointer);
117 static gboolean _handle_get_auth_session (GSignondDbusIdentityAdapter *self, GDBusMethodInvocation *invocation, const gchar *method, gpointer user_data);
118 static gboolean _handle_verify_user (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, GVariant *, gpointer);
119 static gboolean _handle_verify_secret (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar *, gpointer);
120 static gboolean _handle_remove (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, gpointer);
121 static gboolean _handle_sign_out (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, gpointer);
122 static gboolean _handle_store (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const GVariant *, gpointer);
123 static gboolean _handle_add_reference (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar *, gpointer);
124 static gboolean _handle_remove_reference (GSignondDbusIdentityAdapter *, GDBusMethodInvocation *, const gchar *, gpointer);
125 static void _emit_info_updated (GSignondIdentity *identity, GSignondIdentityChangeType change, gpointer userdata);
126 static void _on_session_disposed (gpointer data, GObject *session);
129 gsignond_dbus_identity_adapter_set_property (GObject *object,
131 const GValue *value, GParamSpec *pspec)
133 GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
135 switch (property_id) {
136 case PROP_CONNECTION: {
137 self->priv->connection = g_value_get_object (value);
140 case PROP_IDENTITY: {
141 gpointer identity = g_value_get_object (value);
143 if (self->priv->identity) {
144 if (self->priv->info_updated_handler_id) {
145 g_signal_handler_disconnect (self->priv->identity, self->priv->info_updated_handler_id);
146 self->priv->info_updated_handler_id = 0;
148 if (self->priv->verify_user_handler_id) {
149 g_signal_handler_disconnect (self->priv->identity, self->priv->verify_user_handler_id);
150 self->priv->verify_user_handler_id = 0;
152 if (self->priv->verify_secret_handler_id) {
153 g_signal_handler_disconnect (self->priv->identity, self->priv->verify_secret_handler_id);
154 self->priv->verify_secret_handler_id = 0;
156 if (self->priv->credentials_update_handler_id) {
157 g_signal_handler_disconnect (self->priv->identity, self->priv->credentials_update_handler_id);
158 self->priv->credentials_update_handler_id = 0;
160 g_object_unref (self->priv->identity);
161 self->priv->identity = NULL;
163 self->priv->identity = GSIGNOND_IDENTITY(identity);
164 self->priv->info_updated_handler_id = g_signal_connect (
165 self->priv->identity, "info-updated", G_CALLBACK (_emit_info_updated), self);
169 case PROP_APP_CONTEXT: {
170 if (self->priv->app_context) g_free (self->priv->app_context);
171 self->priv->app_context = g_strdup (g_value_get_string (value));
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
180 gsignond_dbus_identity_adapter_get_property (GObject *object,
185 GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
187 switch (property_id) {
189 g_value_set_object (value, self->priv->identity);
192 case PROP_CONNECTION: {
193 g_value_set_object (value, self->priv->connection);
196 case PROP_APP_CONTEXT:{
197 g_value_set_string (value, self->priv->app_context);
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
206 _destroy_session (gpointer data, gpointer user_data)
208 if (data && GSIGNOND_IS_DBUS_AUTH_SESSION_ADAPTER (data)) {
209 GObject *dbus_session = G_OBJECT (data);
210 g_object_weak_unref (dbus_session, _on_session_disposed, user_data);
211 gsignond_dbus_auth_session_adapter_abort_process (
212 GSIGNOND_DBUS_AUTH_SESSION_ADAPTER (dbus_session));
213 g_object_unref (dbus_session);
218 gsignond_dbus_identity_adapter_dispose (GObject *object)
220 GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
222 if (self->priv->sessions) {
223 g_list_foreach (self->priv->sessions, _destroy_session, self);
226 if (self->priv->identity) {
227 if (self->priv->info_updated_handler_id) {
228 g_signal_handler_disconnect (self->priv->identity, self->priv->info_updated_handler_id);
229 self->priv->info_updated_handler_id = 0;
231 if (self->priv->verify_user_handler_id) {
232 g_signal_handler_disconnect (self->priv->identity, self->priv->verify_user_handler_id);
233 self->priv->verify_user_handler_id = 0;
235 if (self->priv->verify_secret_handler_id) {
236 g_signal_handler_disconnect (self->priv->identity, self->priv->verify_secret_handler_id);
237 self->priv->verify_secret_handler_id = 0;
240 if (self->priv->credentials_update_handler_id) {
241 g_signal_handler_disconnect (self->priv->identity, self->priv->credentials_update_handler_id);
242 self->priv->credentials_update_handler_id = 0;
245 g_object_unref (self->priv->identity);
246 self->priv->identity = NULL;
249 if (self->priv->dbus_identity) {
250 GDBusInterfaceSkeleton *iface = G_DBUS_INTERFACE_SKELETON(self->priv->dbus_identity);
251 gsignond_dbus_identity_emit_unregistered (self->priv->dbus_identity);
252 DBG("(-)'%s' object unexported", g_dbus_interface_skeleton_get_object_path (iface));
253 g_dbus_interface_skeleton_unexport (iface);
254 g_object_unref (self->priv->dbus_identity);
255 self->priv->dbus_identity = NULL;
258 if (self->priv->connection) {
259 g_object_unref (self->priv->connection);
260 self->priv->connection = NULL;
263 G_OBJECT_CLASS (gsignond_dbus_identity_adapter_parent_class)->dispose (object);
267 gsignond_dbus_identity_adapter_finalize (GObject *object)
269 GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (object);
271 if (self->priv->sec_context) {
272 gsignond_security_context_free (self->priv->sec_context);
273 self->priv->sec_context = NULL;
276 if (self->priv->sessions) {
277 g_list_free (self->priv->sessions);
278 self->priv->sessions = NULL;
281 if (self->priv->app_context) {
282 g_free (self->priv->app_context);
283 self->priv->app_context = NULL;
286 G_OBJECT_CLASS (gsignond_dbus_identity_adapter_parent_class)->finalize (object);
290 gsignond_dbus_identity_adapter_class_init (GSignondDbusIdentityAdapterClass *klass)
292 GObjectClass* object_class = G_OBJECT_CLASS (klass);
294 g_type_class_add_private (object_class, sizeof (GSignondDbusIdentityAdapterPrivate));
296 object_class->get_property = gsignond_dbus_identity_adapter_get_property;
297 object_class->set_property = gsignond_dbus_identity_adapter_set_property;
298 object_class->dispose = gsignond_dbus_identity_adapter_dispose;
299 object_class->finalize = gsignond_dbus_identity_adapter_finalize;
301 properties[PROP_IDENTITY] = g_param_spec_object ("identity",
302 "Core identity object",
303 "Core Identity Object",
304 GSIGNOND_TYPE_IDENTITY,
306 G_PARAM_CONSTRUCT_ONLY |
307 G_PARAM_STATIC_STRINGS);
308 properties[PROP_CONNECTION] = g_param_spec_object ("connection",
309 "bus connection used",
311 G_TYPE_DBUS_CONNECTION,
313 G_PARAM_CONSTRUCT_ONLY |
314 G_PARAM_STATIC_STRINGS);
315 properties[PROP_APP_CONTEXT] = g_param_spec_string (
317 "application security context",
318 "Application security context of the identity object creater",
320 G_PARAM_READWRITE |G_PARAM_STATIC_STRINGS);
322 g_object_class_install_properties (object_class, N_PROPERTIES, properties);
326 gsignond_dbus_identity_adapter_init (GSignondDbusIdentityAdapter *self)
328 self->priv = GSIGNOND_DBUS_IDENTITY_ADAPTER_GET_PRIV(self);
330 self->priv->connection = 0;
331 self->priv->identity = 0;
332 self->priv->app_context = 0;
333 self->priv->dbus_identity = gsignond_dbus_identity_skeleton_new();
334 self->priv->sec_context = gsignond_security_context_new ();
336 g_signal_connect_swapped (self->priv->dbus_identity,
337 "handle-request-credentials-update", G_CALLBACK (_handle_request_credentials_update), self);
338 g_signal_connect_swapped (self->priv->dbus_identity,
339 "handle-get-info", G_CALLBACK(_handle_get_info), self);
340 g_signal_connect_swapped (self->priv->dbus_identity,
341 "handle-get-auth-session", G_CALLBACK(_handle_get_auth_session), self);
342 g_signal_connect_swapped (self->priv->dbus_identity,
343 "handle-verify-user", G_CALLBACK(_handle_verify_user), self);
344 g_signal_connect_swapped (self->priv->dbus_identity,
345 "handle-verify-secret", G_CALLBACK(_handle_verify_secret), self);
346 g_signal_connect_swapped (self->priv->dbus_identity,
347 "handle-remove", G_CALLBACK(_handle_remove), self);
348 g_signal_connect_swapped (self->priv->dbus_identity,
349 "handle-sign-out", G_CALLBACK(_handle_sign_out), self);
350 g_signal_connect_swapped (self->priv->dbus_identity,
351 "handle-store", G_CALLBACK(_handle_store), self);
352 g_signal_connect_swapped (self->priv->dbus_identity,
353 "handle-add-reference", G_CALLBACK(_handle_add_reference), self);
354 g_signal_connect_swapped (self->priv->dbus_identity,
355 "handle-remove-reference", G_CALLBACK(_handle_remove_reference), self);
359 _on_credentials_updated (_IdentityDbusInfo *info, guint32 updated_id, GError *error, gpointer userdata)
363 GSignondDbusIdentityAdapter *self = info->adapter;
364 GDBusMethodInvocation *invocation = info->invocation;
366 g_signal_handler_disconnect (userdata, self->priv->credentials_update_handler_id);
367 self->priv->credentials_update_handler_id = 0;
369 g_dbus_method_invocation_return_gerror (invocation, error);
370 g_error_free (error);
374 gsignond_dbus_identity_complete_request_credentials_update (
375 self->priv->dbus_identity, invocation, updated_id);
378 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
380 _identity_dbus_info_free (info);
384 _handle_request_credentials_update (GSignondDbusIdentityAdapter *self,
385 GDBusMethodInvocation *invocation,
386 const gchar *message,
389 GError *error = NULL;
391 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
393 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
395 PREPARE_SECURITY_CONTEXT (self, invocation);
397 gsignond_identity_request_credentials_update (self->priv->identity, message, self->priv->sec_context, &error);
399 g_dbus_method_invocation_return_gerror (invocation, error);
400 g_error_free (error);
402 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
405 self->priv->credentials_update_handler_id = g_signal_connect_swapped (self->priv->identity,
406 "credentials-updated", G_CALLBACK (_on_credentials_updated), self);
413 _handle_get_info (GSignondDbusIdentityAdapter *self,
414 GDBusMethodInvocation *invocation,
417 GVariant *identity_data = 0;
418 GError *error = NULL;
420 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
422 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
424 PREPARE_SECURITY_CONTEXT (self, invocation);
426 identity_data = gsignond_identity_get_info (self->priv->identity,
427 self->priv->sec_context, &error);
430 gsignond_dbus_identity_complete_get_info (
431 self->priv->dbus_identity, invocation, identity_data);
434 g_dbus_method_invocation_return_gerror (invocation, error);
435 g_error_free (error);
438 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
444 _on_session_disposed (gpointer data, GObject *session)
446 GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (data);
450 self->priv->sessions = g_list_remove (self->priv->sessions, session);
452 if (g_list_length (self->priv->sessions) == 0){
453 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), TRUE);
458 _handle_get_auth_session (GSignondDbusIdentityAdapter *self,
459 GDBusMethodInvocation *invocation,
463 GSignondAuthSession *session = NULL;
464 GError *error = NULL;
466 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
468 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
470 PREPARE_SECURITY_CONTEXT (self, invocation);
472 session = gsignond_identity_get_auth_session (self->priv->identity, method, self->priv->sec_context, &error);
475 guint timeout =gsignond_identity_get_auth_session_timeout (self->priv->identity);
476 GSignondDbusAuthSessionAdapter *dbus_session = gsignond_dbus_auth_session_adapter_new_with_connection (
477 g_object_ref (self->priv->connection), session, self->priv->app_context, timeout);
479 if (g_list_length (self->priv->sessions) == 0)
480 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
482 self->priv->sessions = g_list_append (self->priv->sessions, dbus_session);
484 g_object_weak_ref (G_OBJECT (dbus_session), _on_session_disposed, self);
486 gsignond_dbus_identity_complete_get_auth_session (
487 self->priv->dbus_identity, invocation,
488 gsignond_dbus_auth_session_adapter_get_object_path (dbus_session));
491 g_dbus_method_invocation_return_gerror (invocation, error);
492 g_error_free (error);
495 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), TRUE);
501 _on_user_verfied (_IdentityDbusInfo *info, gboolean res, const GError *error, gpointer user_data)
504 WARN ("assertion G_UNLIKELY (info) failed");
508 GSignondDbusIdentityAdapter *self = info->adapter;
509 GDBusMethodInvocation *invocation = info->invocation;
511 g_signal_handler_disconnect (user_data, self->priv->verify_user_handler_id);
512 self->priv->verify_user_handler_id = 0;
515 g_dbus_method_invocation_return_gerror (invocation, error);
518 gsignond_dbus_identity_complete_verify_user (
519 self->priv->dbus_identity, invocation, res);
522 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
524 _identity_dbus_info_free (info);
528 _handle_verify_user (GSignondDbusIdentityAdapter *self,
529 GDBusMethodInvocation *invocation,
533 GError *error = NULL;
535 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
537 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
539 PREPARE_SECURITY_CONTEXT (self, invocation);
541 gsignond_identity_verify_user (self->priv->identity, params, self->priv->sec_context, &error);
544 g_dbus_method_invocation_return_gerror (invocation, error);
545 g_error_free (error);
547 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
550 _IdentityDbusInfo *info = _identity_dbus_info_new (self, invocation, NULL);
552 /* FIXME: Do we allow multiple calls at a given point of time */
553 self->priv->verify_user_handler_id = g_signal_connect_swapped (self->priv->identity,
554 "user-verified", G_CALLBACK (_on_user_verfied), (gpointer)info);
561 _on_secret_verfied (_IdentityDbusInfo *info, gboolean res, const GError *error, gpointer user_data)
565 GSignondDbusIdentityAdapter *self = info->adapter;
566 GDBusMethodInvocation *invocation = info->invocation;
568 g_signal_handler_disconnect (user_data, self->priv->verify_secret_handler_id);
569 self->priv->verify_secret_handler_id = 0;
572 g_dbus_method_invocation_return_gerror (info->invocation, error);
575 gsignond_dbus_identity_complete_verify_secret (
576 self->priv->dbus_identity, invocation, res);
579 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE(self), TRUE);
581 _identity_dbus_info_free (info);
585 _handle_verify_secret (GSignondDbusIdentityAdapter *self,
586 GDBusMethodInvocation *invocation,
590 GError *error = NULL;
592 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
594 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
596 PREPARE_SECURITY_CONTEXT (self, invocation);
598 gsignond_identity_verify_secret (self->priv->identity, secret, self->priv->sec_context, &error);
601 g_dbus_method_invocation_return_gerror (invocation, error);
602 g_error_free (error);
603 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
606 _IdentityDbusInfo *info = _identity_dbus_info_new (self, invocation, NULL);
608 self->priv->verify_secret_handler_id = g_signal_connect_swapped (self->priv->identity,
609 "secret-verified", G_CALLBACK (_on_secret_verfied), (gpointer)info);
616 _handle_remove (GSignondDbusIdentityAdapter *self,
617 GDBusMethodInvocation *invocation,
620 GError *error = NULL;
622 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
624 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
626 PREPARE_SECURITY_CONTEXT (self, invocation);
628 if (!gsignond_identity_remove (self->priv->identity, self->priv->sec_context, &error)) {
629 g_dbus_method_invocation_return_gerror (invocation, error);
630 g_error_free (error);
633 gsignond_dbus_identity_complete_remove (self->priv->dbus_identity, invocation);
636 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
642 _handle_sign_out (GSignondDbusIdentityAdapter *self,
643 GDBusMethodInvocation *invocation,
646 GError *error = NULL;
649 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
651 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
653 PREPARE_SECURITY_CONTEXT (self, invocation);
655 res = gsignond_identity_sign_out (self->priv->identity, self->priv->sec_context, &error);
658 gsignond_dbus_identity_complete_sign_out (self->priv->dbus_identity, invocation, res);
661 g_dbus_method_invocation_return_gerror (invocation, error);
662 g_error_free (error);
665 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
671 _handle_store (GSignondDbusIdentityAdapter *self,
672 GDBusMethodInvocation *invocation,
673 const GVariant *info,
677 GError *error = NULL;
679 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
681 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
683 PREPARE_SECURITY_CONTEXT (self, invocation);
685 id = gsignond_identity_store (self->priv->identity, info, self->priv->sec_context, &error);
688 gsignond_dbus_identity_complete_store (self->priv->dbus_identity, invocation, id);
690 g_dbus_method_invocation_return_gerror (invocation, error);
691 g_error_free (error);
694 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
700 _handle_add_reference (GSignondDbusIdentityAdapter *self,
701 GDBusMethodInvocation *invocation,
702 const gchar *reference,
706 GError *error = NULL;
708 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
710 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
712 PREPARE_SECURITY_CONTEXT (self, invocation);
714 id = gsignond_identity_add_reference (self->priv->identity, reference, self->priv->sec_context, &error);
717 gsignond_dbus_identity_complete_add_reference (self->priv->dbus_identity, invocation, id);
720 g_dbus_method_invocation_return_gerror (invocation, error);
721 g_error_free (error);
724 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
730 _handle_remove_reference (GSignondDbusIdentityAdapter *self,
731 GDBusMethodInvocation *invocation,
732 const gchar *reference,
736 GError *error = NULL;
738 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), FALSE);
740 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), FALSE);
742 PREPARE_SECURITY_CONTEXT (self, invocation);
744 id = gsignond_identity_remove_reference (self->priv->identity, reference, self->priv->sec_context, &error);
747 gsignond_dbus_identity_complete_remove_reference (self->priv->dbus_identity, invocation, id);
749 g_dbus_method_invocation_return_gerror (invocation, error);
750 g_error_free (error);
753 gsignond_disposable_set_auto_dispose (GSIGNOND_DISPOSABLE (self), TRUE);
759 _emit_info_updated (GSignondIdentity *identity,
760 GSignondIdentityChangeType change,
763 GSignondDbusIdentityAdapter *self = GSIGNOND_DBUS_IDENTITY_ADAPTER (userdata);
765 gsignond_dbus_identity_emit_info_updated (self->priv->dbus_identity, change);
767 if (change == GSIGNOND_IDENTITY_REMOVED)
768 gsignond_disposable_delete_later (GSIGNOND_DISPOSABLE (self));
769 else if (change == GSIGNOND_IDENTITY_SIGNED_OUT && self->priv->sessions) {
770 /* destroy all sessions on this identity as it's signed out */
771 g_list_foreach (self->priv->sessions, _destroy_session, NULL);
772 g_list_free (self->priv->sessions);
773 self->priv->sessions = NULL;
778 gsignond_dbus_identity_adapter_get_object_path(GSignondDbusIdentityAdapter *self)
780 g_return_val_if_fail (self && GSIGNOND_IS_DBUS_IDENTITY_ADAPTER (self), NULL);
782 return g_dbus_interface_skeleton_get_object_path (
783 G_DBUS_INTERFACE_SKELETON (self->priv->dbus_identity));
786 GSignondDbusIdentityAdapter *
787 gsignond_dbus_identity_adapter_new_with_connection (GDBusConnection *connection,
788 GSignondIdentity *identity,
789 const gchar *app_context,
792 static guint32 object_counter = 0;
794 gchar *object_path = NULL;
796 GSignondDbusIdentityAdapter *adapter = GSIGNOND_DBUS_IDENTITY_ADAPTER (
797 g_object_new (GSIGNOND_TYPE_DBUS_IDENTITY_ADAPTER,
798 "identity", identity, "connection", connection, "app-context", app_context, NULL));
800 if (!adapter) return NULL;
802 nonce = gsignond_generate_nonce ();
803 object_path = g_strdup_printf ("%s/Identity_%s_%d",
804 GSIGNOND_DAEMON_OBJECTPATH,
809 if (!g_dbus_interface_skeleton_export (
810 G_DBUS_INTERFACE_SKELETON (adapter->priv->dbus_identity),
811 adapter->priv->connection, object_path, &err)) {
812 ERR ("failed to register object: %s", err->message);
814 g_free (object_path);
815 g_object_unref (adapter);
819 DBG("(+)'%s' object exported(%p)", object_path, adapter);
820 g_free (object_path);
822 gsignond_disposable_set_timeout (GSIGNOND_DISPOSABLE (adapter), timeout);
829 * gsignond_dbus_identity_adapter_new:
830 * @impl: Instance of #GSignondDbusIdentityAdapter
832 * Creates new instance of #GSignondDbusIdentityAdapter
834 * Retrurns: (transfer full) new instance of #GSignondDbusIdentityAdapter
836 GSignondDbusIdentityAdapter *
837 gsignond_dbus_identity_adapter_new (GSignondIdentity *identity, const gchar *app_context, guint timeout)
839 GError *error = NULL;
840 GDBusConnection *connection = g_bus_get_sync (GSIGNOND_BUS_TYPE, NULL, &error);
843 ERR("failed to connect to session bus : %s", error->message);
844 g_error_free (error);
848 return gsignond_dbus_identity_adapter_new_with_connection (connection, identity, app_context, timeout);
852 #undef PREPARE_SECURITY_CONTEXT