Пример #1
0
glong
ibus_get_daemon_uid (void)
{
    return getuid ();
#if 0
    struct passwd *pwd;
    uid_t uid;
    const gchar *username;

    uid = getuid ();

    if (uid != 0)
        return uid;

    username = ibus_get_user_name ();
    if (username == NULL)
        return 0;

    pwd = getpwnam (username);
    if (pwd == NULL)
        return 0;

    return pwd->pw_uid;
#endif
}
Пример #2
0
const gchar *
ibus_get_socket_folder (void)
{
    static gchar *folder = NULL;

    if (folder == NULL) {
        const gchar *session = ibus_get_session_id ();
        if (session && session[0] != '\0') {
            folder = g_strdup_printf ("/tmp/ibus-%s-%s",
                ibus_get_user_name (), session);
        }
        else {
            folder = g_strdup_printf ("/tmp/ibus-%s",
                ibus_get_user_name ());
        }
    }
    return folder;
}
Пример #3
0
static void
ibus_bus_init (IBusBus *bus)
{
    struct stat buf;
    gchar *path;
    GFile *file;

    IBusBusPrivate *priv;
    priv = IBUS_BUS_GET_PRIVATE (bus);

    priv->config = NULL;
    priv->connection = NULL;
    priv->watch_dbus_signal = FALSE;

    path = g_path_get_dirname (ibus_get_socket_path ());

    if (stat (path, &buf) == 0) {
        if (buf.st_uid != ibus_get_daemon_uid ()) {
            g_warning ("The owner of %s is not %s!", path, ibus_get_user_name ());
            return;
        }
    }
#if 0
    else {
        if (getuid () == ibus_get_daemon_uid ()) {
            mkdir (path, 0700);
            chmod (path, 0700);
        }
    }
#endif

    ibus_bus_connect (bus);


    file = g_file_new_for_path (ibus_get_socket_path ());
    priv->monitor = g_file_monitor_file (file, 0, NULL, NULL);

    g_signal_connect (priv->monitor, "changed", (GCallback) _changed_cb, bus);

    g_object_unref (file);
    g_free (path);
}
Пример #4
0
static void
ibus_bus_connect (IBusBus *bus)
{
    IBusBusPrivate *priv;
    priv = IBUS_BUS_GET_PRIVATE (bus);

#if 0
    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);
    }
#endif
    if (ibus_get_address () != NULL) {
        priv->connection = ibus_connection_open (ibus_get_address ());
    }

    if (priv->connection) {
        ibus_bus_hello (bus);
        g_signal_connect (priv->connection,
                          "destroy",
                          (GCallback) _connection_destroy_cb,
                          bus);
        g_signal_emit (bus, bus_signals[CONNECTED], 0);

        if (priv->watch_dbus_signal) {
            ibus_bus_watch_dbus_signal (bus);
        }
    }
}
Пример #5
0
gboolean
bus_server_listen (BusServer *server)
{
    g_assert (BUS_IS_SERVER (server));

    // const gchar *address = "unix:abstract=/tmp/ibus-c"
    const gchar *address;
    gchar *path;
    gboolean retval;

    path = g_strdup_printf("/tmp/ibus-%s", ibus_get_user_name ());
    mkdir (path, 0775);
    address = ibus_get_address ();

    retval = ibus_server_listen (IBUS_SERVER (server), address);

    if (!retval) {
        g_printerr ("Can not listen on %s! Please try remove directory %s and run again.", address, path);
        exit (-1);
    }

    g_free(path);
    return retval;
}
Пример #6
0
Файл: main.c Проект: nzinfo/ibus
gint
main (gint argc, gchar **argv)
{
    setlocale (LC_ALL, "");

    GOptionContext *context = g_option_context_new ("- ibus daemon");
    g_option_context_add_main_entries (context, entries, "ibus-daemon");

    g_argv = g_strdupv (argv);
    GError *error = NULL;
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("Option parsing failed: %s\n", error->message);
        g_error_free (error);
        exit (-1);
    }
    if (g_gdbus_timeout < -1) {
        g_printerr ("Bad timeout (must be >= -1): %d\n", g_gdbus_timeout);
        exit (-1);
    }

    if (g_mempro) {
        g_mem_set_vtable (glib_mem_profiler_table);
        signal (SIGUSR2, _sig_usr2_handler);
    }

    /* check uid */
    {
        const gchar *username = ibus_get_user_name ();
        uid_t uid = getuid ();
        struct passwd *pwd = getpwuid (uid);

        if (pwd == NULL || g_strcmp0 (pwd->pw_name, username) != 0) {
            g_printerr ("Please run ibus-daemon with login user! Do not run ibus-daemon with sudo or su.\n");
            exit (-1);
        }
    }

    /* daemonize process */
    if (daemonize) {
        if (daemon (1, 0) != 0) {
            g_printerr ("Can not daemonize ibus.\n");
            exit (-1);
        }
    }

    /* create a new process group. this is important to kill all of its children by SIGTERM at a time in bus_ibus_impl_destroy. */
    setpgid (0, 0);

    ibus_init ();

    ibus_set_log_handler (g_verbose);

    /* check if ibus-daemon is running in this session */
    if (ibus_get_address () != NULL) {
        IBusBus *bus = ibus_bus_new ();

        if (ibus_bus_is_connected (bus)) {
            if (!replace) {
                g_printerr ("current session already has an ibus-daemon.\n");
                exit (-1);
            }
            ibus_bus_exit (bus, FALSE);
            while (ibus_bus_is_connected (bus)) {
                g_main_context_iteration (NULL, TRUE);
            }
        }
        g_object_unref (bus);
    }

    bus_server_init ();
    if (!single) {
        /* execute config component */
        if (g_strcmp0 (config, "default") == 0) {
            BusComponent *component;
            component = bus_ibus_impl_lookup_component_by_name (
                            BUS_DEFAULT_IBUS, IBUS_SERVICE_CONFIG);
            if (component) {
                bus_component_set_restart (component, restart);
            }
            if (component == NULL || !bus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default config program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (config, "disable") != 0 && g_strcmp0 (config, "") != 0) {
            if (!execute_cmdline (config))
                exit (-1);
        }

        /* execute panel component */
        if (g_strcmp0 (panel, "default") == 0) {
            BusComponent *component;
            component = bus_ibus_impl_lookup_component_by_name (
                            BUS_DEFAULT_IBUS, IBUS_SERVICE_PANEL);
            if (component) {
                bus_component_set_restart (component, restart);
            }
            if (component == NULL || !bus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default panel program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (panel, "disable") != 0 && g_strcmp0 (panel, "") != 0) {
            if (!execute_cmdline (panel))
                exit (-1);
        }
    }

    /* execute ibus xim server */
    if (xim) {
        if (!execute_cmdline (LIBEXECDIR "/ibus-x11 --kill-daemon"))
            exit (-1);
    }

    bus_server_run ();
    return 0;
}
Пример #7
0
Файл: main.c Проект: juhp/ibus
gint
main (gint argc, gchar **argv)
{
    GOptionContext *context;
    BusServer *server;
    IBusBus *bus;

    GError *error = NULL;

    setlocale (LC_ALL, "");

    context = g_option_context_new ("- ibus daemon");

    g_option_context_add_main_entries (context, entries, "ibus-daemon");

    g_argv = g_strdupv (argv);
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("Option parsing failed: %s\n", error->message);
        exit (-1);
    }

    if (g_mempro) {
        g_mem_set_vtable (glib_mem_profiler_table);
        signal (SIGUSR2, _sig_usr2_handler);
    }

    /* check uid */
    {
        const gchar *username = ibus_get_user_name ();
        uid_t uid = getuid ();
        struct passwd *pwd = getpwuid (uid);

        if (pwd == NULL || g_strcmp0 (pwd->pw_name, username) != 0) {
            g_printerr ("Please run ibus-daemon with login user! Do not run ibus-daemon with sudo or su.\n");
            exit (-1);
        }
    }

    /* daemonize process */
    if (daemonize) {
        if (daemon (1, 0) != 0) {
            g_printerr ("Can not daemonize ibus.\n");
            exit (-1);
        }
    }

    /* create a new process group */
    setpgrp ();

    g_type_init ();

    g_log_set_handler (G_LOG_DOMAIN,
        G_LOG_LEVEL_WARNING | G_LOG_LEVEL_DEBUG | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
        _my_log_handler,
        NULL);

    /* check if ibus-daemon is running in this session */
    if (ibus_get_address () != NULL) {
        bus = ibus_bus_new ();

        if (ibus_bus_is_connected (bus)) {
            if (!replace) {
                g_printerr ("current session already has an ibus-daemon.\n");
                exit (-1);
            }
            ibus_bus_exit (bus, FALSE);
            while (ibus_bus_is_connected (bus)) {
                g_main_context_iteration (NULL, TRUE);
            }
        }
        g_object_unref (bus);
        bus = NULL;
    }

    /* create ibus server */
    server = bus_server_get_default ();
    bus_server_listen (server);

    if (!single) {
        /* execute config component */
        if (g_strcmp0 (config, "default") == 0) {
            IBusComponent *component;
            component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_CONFIG);
            if (component == NULL || !ibus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default config program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (config, "disable") != 0 && g_strcmp0 (config, "") != 0) {
            if (!execute_cmdline (config))
                exit (-1);
        }

        /* execut panel component */
        if (g_strcmp0 (panel, "default") == 0) {
            IBusComponent *component;
            component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_PANEL);
            if (component == NULL || !ibus_component_start (component, g_verbose)) {
                g_printerr ("Can not execute default panel program\n");
                exit (-1);
            }
        } else if (g_strcmp0 (panel, "disable") != 0 && g_strcmp0 (panel, "") != 0) {
            if (!execute_cmdline (panel))
                exit (-1);
        }
    }

    /* execute ibus xim server */
    if (xim) {
        if (!execute_cmdline (LIBEXECDIR"/ibus-x11 --kill-daemon"))
            exit (-1);
    }

    bus_server_run (server);

    return 0;
}