X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk-adaptor%2Fbridge.c;h=86bfc470323a902faf8c7aef31798cf11c719476;hb=7540b8404de04eca32735fec3482b9b42d1e432f;hp=0cb1f92a07ddc8f55cf9352f9c54a030fe0039e3;hpb=bf2e5788c56e02322e8e4b80a9be16301ffd1a49;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/atk-adaptor/bridge.c b/atk-adaptor/bridge.c index 0cb1f92..86bfc47 100644 --- a/atk-adaptor/bridge.c +++ b/atk-adaptor/bridge.c @@ -22,8 +22,8 @@ * Boston, MA 02111-1307, USA. */ +#define _GNU_SOURCE #include "config.h" -#include "dbus/dbus-glib-lowlevel.h" #include #include @@ -38,6 +38,7 @@ #include #include #include +#include #include "bridge.h" #include "event.h" @@ -100,77 +101,6 @@ spi_display_name (void) /*---------------------------------------------------------------------------*/ -/* - * 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) { @@ -507,13 +437,56 @@ install_plug_hooks () 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); @@ -541,7 +514,7 @@ setup_bus (void) 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; @@ -711,7 +684,7 @@ adaptor_init (gint * argc, gchar ** argv[]) /* 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); @@ -735,13 +708,9 @@ adaptor_init (gint * argc, gchar ** argv[]) } } -#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 ();