* Boston, MA 02111-1307, USA.
*/
+#define _GNU_SOURCE
#include "config.h"
-#include "dbus/dbus-glib-lowlevel.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <droute/droute.h>
#include <gmodule.h>
#include <glib/gi18n.h>
+#include <atspi/atspi.h>
#include "bridge.h"
#include "event.h"
#include "adaptors.h"
#include "object.h"
+#include "common/spi-stateset.h"
#include "accessible-register.h"
#include "accessible-leasing.h"
SpiBridge *spi_global_app_data = NULL;
-static const AtkMisc *atk_misc = NULL;
-
/*static Display *bridge_display = NULL;*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
-/*
- * Gets the IOR from the XDisplay.
- * Not currently used in D-Bus version, but something similar
- * may be employed in the future for accessing the registry daemon
- * bus name.
- */
-
-static DBusConnection *
-spi_atk_bridge_get_bus (void)
-{
- Atom AT_SPI_BUS;
- Atom actual_type;
- Display *bridge_display;
- int actual_format;
- unsigned char *data = NULL;
- unsigned long nitems;
- unsigned long leftover;
-
- DBusConnection *bus = NULL;
- DBusError error;
-
- bridge_display = XOpenDisplay (spi_display_name ());
- if (!bridge_display)
- {
- g_warning ("AT_SPI: Could not get the display\n");
- return NULL;
- }
-
- AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
- XGetWindowProperty (bridge_display,
- XDefaultRootWindow (bridge_display),
- AT_SPI_BUS, 0L,
- (long) BUFSIZ, False,
- (Atom) 31, &actual_type, &actual_format,
- &nitems, &leftover, &data);
-
- dbus_error_init (&error);
-
- if (data == NULL)
- {
- g_warning
- ("AT-SPI: Accessibility bus not found - Using session bus.\n");
- bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus)
- {
- g_warning ("AT-SPI: Couldn't connect to bus: %s\n", error.message);
- return NULL;
- }
- }
- else
- {
- bus = dbus_connection_open (data, &error);
- XFree (data);
- if (!bus)
- {
- g_warning ("AT-SPI: Couldn't connect to bus: %s\n", error.message);
- return NULL;
- }
- else
- {
- if (!dbus_bus_register (bus, &error))
- {
- g_warning ("AT-SPI: Couldn't register with bus: %s\n", error.message);
- return NULL;
- }
- }
- }
-
- return bus;
-}
-
static void
set_reply (DBusPendingCall *pending, void *user_data)
{
socket_class->embed = socket_embed_hook;
}
+static uint
+get_ancestral_uid (uint pid)
+{
+ FILE *fp;
+ char buf [80];
+ int ppid = 0;
+ int uid = 0;
+ gboolean got_ppid = 0;
+ gboolean got_uid = 0;
+
+ sprintf (buf, "/proc/%d/status", pid);
+ fp = fopen (buf, "r");
+ if (!fp)
+ return 0;
+ while ((!got_ppid || !got_uid) && fgets (buf, sizeof (buf), fp))
+ {
+ if (sscanf (buf, "PPid:\t%d", &ppid) == 1)
+ got_ppid = TRUE;
+ else if (sscanf (buf, "Uid:\t%d", &uid) == 1)
+ got_uid = TRUE;
+ }
+ fclose (fp);
+
+ if (!got_ppid || !got_uid)
+ return 0;
+ if (uid != 0)
+ return uid;
+ if (ppid == 0 || ppid == 1)
+ return 0;
+ return get_ancestral_uid (ppid);
+}
+
+static dbus_bool_t
+user_check (DBusConnection *bus, unsigned long uid)
+{
+ if (uid == getuid () || uid == geteuid ())
+ return TRUE;
+ if (getuid () == 0)
+ return get_ancestral_uid (getpid ()) == uid;
+ return FALSE;
+}
+
static void
new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
{
GList *new_list;
+ dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
dbus_connection_ref(con);
- dbus_connection_setup_with_g_main(con, NULL);
+ atspi_dbus_connection_setup_with_g_main(con, NULL);
droute_intercept_dbus (con);
droute_context_register (spi_global_app_data->droute, con);
return -1;
}
- dbus_server_setup_with_g_main(server, NULL);
+ atspi_dbus_server_setup_with_g_main(server, NULL);
dbus_server_set_new_connection_function(server, new_connection_cb, NULL, NULL);
spi_global_app_data->server = server;
/* Allocate global data and do ATK initializations */
spi_global_app_data = g_new0 (SpiBridge, 1);
- atk_misc = atk_misc_get_instance ();
spi_global_app_data->root = g_object_ref (root);
/* Set up D-Bus connection and register bus name */
dbus_error_init (&error);
- spi_global_app_data->bus = spi_atk_bridge_get_bus ();
+ spi_global_app_data->bus = atspi_get_a11y_bus ();
if (!spi_global_app_data->bus)
{
g_free (spi_global_app_data);
}
}
-#ifndef DISABLE_P2P
spi_global_app_data->main_context = g_main_context_new ();
-#else
- spi_global_app_data->main_context = NULL;
-#endif
- dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
+ atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
/* Hook our plug-and socket functions */
install_plug_hooks ();