Check ownership of socket file.
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 20 Apr 2009 09:31:09 +0000 (17:31 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 20 Apr 2009 09:31:09 +0000 (17:31 +0800)
src/ibusbus.c

index 53f07a3..8f02a32 100644 (file)
@@ -176,9 +176,23 @@ _connection_destroy_cb (IBusConnection  *connection,
 static void
 ibus_bus_connect (IBusBus *bus)
 {
+    const gchar *socket_path;
+    struct stat buf;
+
     IBusBusPrivate *priv;
     priv = IBUS_BUS_GET_PRIVATE (bus);
 
+    socket_path = ibus_get_socket_path ();
+
+    if (stat (socket_path, &buf) != 0) {
+        g_warning ("Can not get stat from %s!", socket_path);
+        return;
+    }
+    if (buf.st_uid != ibus_get_daemon_uid ()) {
+        g_warning ("The owner of %s is not %s!", socket_path, ibus_get_user_name ());
+        return;
+    }
+
     if (priv->connection != NULL) {
         ibus_object_destroy ((IBusObject *) priv->connection);
     }
@@ -237,7 +251,6 @@ ibus_bus_init (IBusBus *bus)
 
     if (stat (path, &buf) == 0) {
         if (buf.st_uid != ibus_get_daemon_uid ()) {
-            g_debug ("%ld %ld", buf.st_uid, ibus_get_daemon_uid ());
             g_warning ("The owner of %s is not %s!", path, ibus_get_user_name ());
             return;
         }