daemon/dbus: peer-2-peer dbus now using file system socket.
authorAmarnath Valluri <amarnath.valluri@linux.intel.com>
Tue, 28 May 2013 13:20:56 +0000 (16:20 +0300)
committerAmarnath Valluri <amarnath.valluri@linux.intel.com>
Tue, 28 May 2013 13:20:56 +0000 (16:20 +0300)
supported change should go in client library.

src/daemon/dbus/gsignond-dbus-server.c
src/daemon/dbus/gsignond-dbus.h
test/daemon/daemon-test.c

index ddaddff..b5d2b1d 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
+#include <errno.h>
+#include <string.h>
+#include <glib/gstdio.h>
+
+#include "config.h"
 
-#include <config.h>
 #include "gsignond-dbus-server.h"
 #include "gsignond-dbus-auth-service-adapter.h"
 #include "gsignond-dbus.h"
@@ -158,7 +162,11 @@ _finalize (GObject *object)
 {
 #ifdef USE_P2P
     GSignondDbusServer *self = GSIGNOND_DBUS_SERVER (object);
-    if (self->priv->address) {
+    if (self->priv->address && g_str_has_prefix (self->priv->address, "unix:path=")) {
+        const gchar *path = g_strstr_len(self->priv->address, -1, "unix:path=") + 10;
+        if (path) { 
+            g_unlink (path);
+        }
         g_free (self->priv->address);
         self->priv->address = NULL;
     }
@@ -300,11 +308,27 @@ GSignondDbusServer * gsignond_dbus_server_new_with_address (const gchar *address
 {
     GError *err = NULL;
     gchar *guid = 0;
+    const gchar *file_path = NULL;
     GSignondDbusServer *server = GSIGNOND_DBUS_SERVER (
         g_object_new (GSIGNOND_TYPE_DBUS_SERVER, "address", address, NULL));
 
     if (!server) return NULL;
 
+    if (g_str_has_prefix(address, "unix:path=")) {
+        file_path = g_strstr_len (address, -1, "unix:path=") + 10;
+
+        if (g_file_test(file_path, G_FILE_TEST_EXISTS)) {
+            g_unlink (file_path);
+        }
+        else {
+            gchar *base_path = g_path_get_dirname (file_path);
+            if (g_mkdir_with_parents (base_path, S_IRUSR | S_IWUSR | S_IXUSR) == -1) {
+                WARN ("Could not create '%s', error: %s", base_path, strerror(errno));
+            }
+            g_free (base_path);
+        }
+    }
+
     guid = g_dbus_generate_guid ();
 
     server->priv->bus_server = g_dbus_server_new_sync (server->priv->address,
@@ -326,11 +350,20 @@ GSignondDbusServer * gsignond_dbus_server_new_with_address (const gchar *address
 
     g_dbus_server_start (server->priv->bus_server);
 
+    if (file_path)
+        g_chmod (file_path, S_IRUSR | S_IWUSR);
+
     return server;
 }
 
 GSignondDbusServer * gsignond_dbus_server_new () {
-    return gsignond_dbus_server_new_with_address (GSIGNOND_DBUS_ADDRESS);
+       GSignondDbusServer *server = NULL;
+       gchar *address = g_strdup_printf (GSIGNOND_DBUS_ADDRESS, g_get_user_runtime_dir());
+
+    server = gsignond_dbus_server_new_with_address (address);
+    g_free (address);
+
+    return server ;
 }
 #else
 
index 0d74902..82fb529 100644 (file)
@@ -29,7 +29,7 @@
 /*
  * Common DBUS definitions
  */
-#define GSIGNOND_DBUS_ADDRESS            "unix:abstract=gsignond"
+#define GSIGNOND_DBUS_ADDRESS            "unix:path=%s/gsignond/bus-sock"
 #define GSIGNOND_SERVICE_PREFIX          "com.google.code.AccountsSSO.gSingleSignOn"
 #define GSIGNOND_SERVICE                 GSIGNOND_SERVICE_PREFIX
 #define GSIGNOND_DAEMON_OBJECTPATH       "/com/google/code/AccountsSSO/gSingleSignOn"
index 99ad6b5..c4f7557 100644 (file)
@@ -231,8 +231,11 @@ GVariant * _create_identity_info_with_data (const gchar *username,
 GDBusConnection * _get_bus_connection (GError **error)
 {
 #if USE_P2P
+    gchar address[128];
+
+    g_snprintf (address, 127, GSIGNOND_DBUS_ADDRESS, g_get_user_runtime_dir());
     return g_dbus_connection_new_for_address_sync (
-        GSIGNOND_DBUS_ADDRESS,
+        address,
         G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
         NULL,
         NULL,