Blob Blame History Raw
From 05a10950d635602fb3fcf4ed0021aa0b15dbd698 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Thu, 9 May 2019 15:49:09 +0900
Subject: [PATCH] src: Make ISO 639 language names with title

Danish translations are small in iso-codes-iso-639-2-da.po for the
genral usage but the users ask the title format on UI.
Now ibus_get_language_name() and ibus_get_untranslated_language_name()
return the dynamic allocation instead of the static characters
to make the capital character.

BUG=https://github.com/ibus/ibus/issues/2079
---
 src/ibusutil.c | 63 ++++++++++++++++++++++++++++++++++++++++++--------
 src/ibusutil.h |  8 +++----
 2 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/src/ibusutil.c b/src/ibusutil.c
index fd1da006..9d003e2e 100644
--- a/src/ibusutil.c
+++ b/src/ibusutil.c
@@ -2,7 +2,7 @@
 /* vim:set et sts=4: */
 /* bus - The Input Bus
  * Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (C) 2010-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
  * Copyright (C) 2008-2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -125,8 +125,8 @@ _load_lang()
     ibus_xml_free (node);
 }
 
-const gchar *
-ibus_get_untranslated_language_name (const gchar *_locale)
+const static gchar *
+ibus_get_untranslated_raw_language_name (const gchar *_locale)
 {
     const gchar *retval;
     gchar *p = NULL;
@@ -148,19 +148,64 @@ ibus_get_untranslated_language_name (const gchar *_locale)
         return "Other";
 }
 
-const gchar *
+static char *
+get_first_item_in_semicolon_list (const char *list)
+{
+        char **items;
+        char  *item;
+
+        items = g_strsplit (list, "; ", 2);
+
+        item = g_strdup (items[0]);
+        g_strfreev (items);
+
+        return item;
+}
+
+static char *
+capitalize_utf8_string (const char *str)
+{
+    char first[8] = { 0 };
+
+    if (!str)
+        return NULL;
+
+    g_unichar_to_utf8 (g_unichar_totitle (g_utf8_get_char (str)), first);
+
+    return g_strconcat (first, g_utf8_offset_to_pointer (str, 1), NULL);
+}
+
+gchar *
+ibus_get_untranslated_language_name (const gchar *_locale)
+{
+    const gchar *raw = ibus_get_untranslated_raw_language_name (_locale);
+    gchar *tmp = get_first_item_in_semicolon_list (raw);
+    gchar *retval = capitalize_utf8_string (tmp);
+    g_free (tmp);
+    return retval;
+}
+
+gchar *
 ibus_get_language_name (const gchar *_locale)
 {
-    const gchar *retval = ibus_get_untranslated_language_name (_locale);
+    const gchar *raw = ibus_get_untranslated_raw_language_name (_locale);
+    const gchar *translation = NULL;
+    gchar *tmp;
+    gchar *retval;
 
 #ifdef ENABLE_NLS
-    if (g_strcmp0 (retval, "Other") == 0)
-        return dgettext (GETTEXT_PACKAGE, N_("Other"));
+    if (g_strcmp0 (raw, "Other") == 0)
+        return g_strdup (dgettext (GETTEXT_PACKAGE, N_("Other")));
     else
-        return dgettext ("iso_639-3", retval);
+        translation = dgettext ("iso_639-3", raw);
 #else
-    return retval;
+    translation = raw;
 #endif
+
+    tmp = get_first_item_in_semicolon_list (translation);
+    retval = capitalize_utf8_string (tmp);
+    g_free (tmp);
+    return retval;
 }
 
 void
diff --git a/src/ibusutil.h b/src/ibusutil.h
index 226dd7a8..795365f6 100644
--- a/src/ibusutil.h
+++ b/src/ibusutil.h
@@ -2,8 +2,8 @@
 /* vim:set et sts=4: */
 /* bus - The Input Bus
  * Copyright (C) 2008-2015 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2010-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
- * Copyright (C) 2008-2016 Red Hat, Inc.
+ * Copyright (C) 2010-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (C) 2008-2018 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,7 +42,7 @@
  *
  * Returns: untranslated language name
  */
-const gchar *    ibus_get_untranslated_language_name
+gchar *          ibus_get_untranslated_language_name
                                                 (const gchar    *_locale);
 
 /**
@@ -51,6 +51,6 @@ const gchar *    ibus_get_untranslated_language_name
  *
  * Returns: translated language name
  */
-const gchar *    ibus_get_language_name         (const gchar    *_locale);
+gchar *          ibus_get_language_name         (const gchar    *_locale);
 
 #endif
-- 
2.20.1

From 1cb5032e85d85f496e349236d1b74f17fb8db966 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Tue, 23 Apr 2019 15:40:45 +0900
Subject: [PATCH] configure: Move ibus-setup from configure.ac to Makefile.am

@localedir@ can be extracted to ${datarootdir}/locale and
it needs datarootdir=/usr/share in case configure.ac is used
and deleting the datarootdir line caused a regression.
All variables can be extracted in Makefile.am with sed.
---
 configure.ac      |  1 -
 setup/Makefile.am | 13 +++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9518e808..7503f3e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -724,7 +724,6 @@ ibus/interface/Makefile
 ui/Makefile
 ui/gtk3/Makefile
 setup/Makefile
-setup/ibus-setup
 bindings/Makefile
 bindings/pygobject/Makefile
 bindings/vala/Makefile
diff --git a/setup/Makefile.am b/setup/Makefile.am
index cb4dd8d1..34c8f136 100644
--- a/setup/Makefile.am
+++ b/setup/Makefile.am
@@ -3,8 +3,8 @@
 # ibus - The Input Bus
 #
 # Copyright (c) 2007-2014 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
-# Copyright (c) 2007-2018 Red Hat, Inc.
+# Copyright (c) 2015-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2007-2019 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -40,6 +40,15 @@ ibussetup_DATA = \
 bin_SCRIPTS = ibus-setup
 ibussetupdir = $(pkgdatadir)/setup
 
+ibus-setup: ibus-setup.in
+	$(AM_V_GEN) sed -e "s|\@datarootdir\@|$(datarootdir)|g" \
+	                -e "s|\@localedir\@|$(localedir)|g" \
+	                -e "s|\@libexecdir\@|$(libexecdir)|g" \
+	                -e "s|\@prefix\@|$(prefix)|g" \
+	                -e "s|\@PYTHON\@|$(PYTHON)|g" \
+	$< > $@.tmp && \
+	mv $@.tmp $@
+
 desktop_notrans_files = ibus-setup.desktop
 desktop_DATA = org.freedesktop.IBus.Setup.desktop
 desktopdir = $(datadir)/applications
-- 
2.20.1

From 1c54fea645b2ec3a385d492e4ca30a70dbb87c3a Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Tue, 23 Apr 2019 18:44:45 +0900
Subject: [PATCH] data/its: Add ibus.its for IME's component files

IBusEngineDesc has translatable strings in longname and
description tags and they needs to be extracted by xgettext.

After you install the ibus.[its|loc] to /usr/share/gettext/its,
each engine's component file needs to renamed with
'.inputMethod.xml' in the source directory suffix. E.g.
Rename 'anthy.xml' to 'anthy.inputMethod.xml' and write the file
path to the engine's POTFILES.in
---
 configure.ac         |  1 +
 data/Makefile.am     |  3 ++-
 data/its/Makefile.am | 29 +++++++++++++++++++++++++++++
 data/its/ibus.its    | 14 ++++++++++++++
 data/its/ibus.loc    |  7 +++++++
 5 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 data/its/Makefile.am
 create mode 100644 data/its/ibus.its
 create mode 100644 data/its/ibus.loc

diff --git a/configure.ac b/configure.ac
index 7503f3e8..b5a87b56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -711,6 +711,7 @@ util/IMdkit/Makefile
 data/Makefile
 data/annotations/Makefile
 data/icons/Makefile
+data/its/Makefile
 data/keymaps/Makefile
 data/dconf/Makefile
 docs/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 2533f444..aa3ee466 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,7 +3,7 @@
 # ibus - The Input Bus
 #
 # Copyright (c) 2007-2016 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2007-2018 Red Hat, Inc.
+# Copyright (c) 2007-2019 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,7 @@
 SUBDIRS = \
 	annotations \
 	icons \
+	its \
 	keymaps \
 	$(NULL)
 
diff --git a/data/its/Makefile.am b/data/its/Makefile.am
new file mode 100644
index 00000000..07c8a96d
--- /dev/null
+++ b/data/its/Makefile.am
@@ -0,0 +1,29 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+itsdir = $(datadir)/gettext/its
+its_DATA = \
+    ibus.its \
+    ibus.loc \
+    $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/data/its/ibus.its b/data/its/ibus.its
new file mode 100644
index 00000000..30d8d4e2
--- /dev/null
+++ b/data/its/ibus.its
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<its:rules xmlns:its="http://www.w3.org/2005/11/its"
+           version="2.0">
+  <its:translateRule selector="/component" translate="no"/>
+  <its:translateRule selector="/engines" translate="no"/>
+  <its:translateRule selector="//engine" translate="no"/>
+  <its:translateRule selector="//longname |
+                               //description"
+                     translate="yes"/>
+  <its:translateRule selector="//longname[@translatable = 'no']"
+                     translate="no"/>
+  <its:translateRule selector="//description[@translatable = 'no']"
+                     translate="no"/>
+</its:rules>
diff --git a/data/its/ibus.loc b/data/its/ibus.loc
new file mode 100644
index 00000000..5a73798b
--- /dev/null
+++ b/data/its/ibus.loc
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<locatingRules>
+  <locatingRule name="IBusEngineDesc" pattern="*.inputMethod.xml">
+    <documentRule localName="engines" target="ibus.its"/>
+    <documentRule localName="component" target="ibus.its"/>
+  </locatingRule>
+</locatingRules>
-- 
2.20.1

From cebe7a9553de69943b955ec99285f74961c9ee4e Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Thu, 9 May 2019 15:49:21 +0900
Subject: [PATCH] client/gtk2: Keep preedit cursor_pos and visible in clearing
 preedit text

Clear the preedit_string but keep the preedit_cursor_pos and
preedit_visible because a time lag could happen, firefox commit
the preedit text before the preedit text is cleared and it cause
a double commits of the Hangul preedit in firefox if the preedit
would be located on the URL bar and click on anywhere of firefox
out of the URL bar.
---
 client/gtk2/ibusimcontext.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index 264a747a..5e3457ba 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -881,10 +881,18 @@ ibus_im_context_clear_preedit_text (IBusIMContext *ibusimcontext)
         ibusimcontext->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
         preedit_string = g_strdup (ibusimcontext->preedit_string);
     }
+
+    /* Clear the preedit_string but keep the preedit_cursor_pos and
+     * preedit_visible because a time lag could happen, firefox commit
+     * the preedit text before the preedit text is cleared and it cause
+     * a double commits of the Hangul preedit in firefox if the preedit
+     * would be located on the URL bar and click on anywhere of firefox
+     * out of the URL bar.
+     */
     _ibus_context_update_preedit_text_cb (ibusimcontext->ibuscontext,
                                           ibus_text_new_from_string (""),
-                                          0,
-                                          FALSE,
+                                          ibusimcontext->preedit_cursor_pos,
+                                          ibusimcontext->preedit_visible,
                                           IBUS_ENGINE_PREEDIT_CLEAR,
                                           ibusimcontext);
     if (preedit_string) {
-- 
2.20.1

From 3d442dbf936d197aa11ca0a71663c2bc61696151 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Fri, 13 Sep 2019 15:59:03 +0900
Subject: [PATCH] bus: Implement GDBusAuthObserver callback

ibus uses a GDBusServer with G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS,
and doesn't set a GDBusAuthObserver, which allows anyone who can connect
to its AF_UNIX socket to authenticate and be authorized to send method calls.
It also seems to use an abstract AF_UNIX socket, which does not have
filesystem permissions, so the practical effect might be that a local
attacker can connect to another user's ibus service and make arbitrary
method calls.

BUGS=rhbz#1717958
---
 bus/server.c | 89 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 73 insertions(+), 16 deletions(-)

diff --git a/bus/server.c b/bus/server.c
index 3a626230..2439de14 100644
--- a/bus/server.c
+++ b/bus/server.c
@@ -2,7 +2,8 @@
 /* vim:set et sts=4: */
 /* bus - The Input Bus
  * Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2008-2010 Red Hat, Inc.
+ * Copyright (C) 2011-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (C) 2008-2019 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -69,17 +70,64 @@ _restart_server (void)
     exit (-1);
 }
 
+/**
+ * bus_allow_mechanism_cb:
+ * @observer: A #GDBusAuthObserver.
+ * @mechanism: The name of the mechanism.
+ * @user_data: always %NULL.
+ *
+ * Check if @mechanism can be used to authenticate the other peer.
+ * Returns: %TRUE if the peer's mechanism is allowed.
+ */
+static gboolean
+bus_allow_mechanism_cb (GDBusAuthObserver     *observer,
+                        const gchar           *mechanism,
+                        G_GNUC_UNUSED gpointer user_data)
+{
+    if (g_strcmp0 (mechanism, "EXTERNAL") == 0)
+        return TRUE;
+    return FALSE;
+}
+
+/**
+ * bus_authorize_authenticated_peer_cb:
+ * @observer: A #GDBusAuthObserver.
+ * @stream: A #GIOStream.
+ * @credentials: A #GCredentials.
+ * @user_data: always %NULL.
+ *
+ * Check if a peer who has already authenticated should be authorized.
+ * Returns: %TRUE if the peer's credential is authorized.
+ */
+static gboolean
+bus_authorize_authenticated_peer_cb (GDBusAuthObserver     *observer,
+                                     GIOStream             *stream,
+                                     GCredentials          *credentials,
+                                     G_GNUC_UNUSED gpointer user_data)
+{
+    gboolean authorized = FALSE;
+    if (credentials) {
+        GCredentials *own_credentials = g_credentials_new ();
+        if (g_credentials_is_same_user (credentials, own_credentials, NULL))
+            authorized = TRUE;
+        g_object_unref (own_credentials);
+    }
+    return authorized;
+}
+
 /**
  * bus_new_connection_cb:
- * @user_data: always NULL.
- * @returns: TRUE when the function can handle the connection.
+ * @observer: A #GDBusAuthObserver.
+ * @dbus_connection: A #GDBusconnection.
+ * @user_data: always %NULL.
  *
  * Handle incoming connections.
+ * Returns: %TRUE when the function can handle the connection.
  */
 static gboolean
-bus_new_connection_cb (GDBusServer     *server,
-                       GDBusConnection *dbus_connection,
-                       gpointer         user_data)
+bus_new_connection_cb (GDBusServer           *server,
+                       GDBusConnection       *dbus_connection,
+                       G_GNUC_UNUSED gpointer user_data)
 {
     BusConnection *connection = bus_connection_new (dbus_connection);
     bus_dbus_impl_new_connection (dbus, connection);
@@ -94,9 +142,9 @@ bus_new_connection_cb (GDBusServer     *server,
 }
 
 static void
-_server_connect_start_portal_cb (GObject      *source_object,
-                                 GAsyncResult *res,
-                                 gpointer      user_data)
+_server_connect_start_portal_cb (GObject               *source_object,
+                                 GAsyncResult          *res,
+                                 G_GNUC_UNUSED gpointer user_data)
 {
     GVariant *result;
     GError *error = NULL;
@@ -113,9 +161,9 @@ _server_connect_start_portal_cb (GObject      *source_object,
 }
 
 static void
-bus_acquired_handler (GDBusConnection *connection,
-                      const gchar     *name,
-                      gpointer         user_data)
+bus_acquired_handler (GDBusConnection       *connection,
+                      const gchar           *name,
+                      G_GNUC_UNUSED gpointer user_data)
 {
     g_dbus_connection_call (connection,
                             IBUS_SERVICE_PORTAL,
@@ -136,14 +184,17 @@ void
 bus_server_init (void)
 {
     GError *error = NULL;
+    GDBusServerFlags flags = G_DBUS_SERVER_FLAGS_NONE;
+    gchar *guid;
+    GDBusAuthObserver *observer;
 
     dbus = bus_dbus_impl_get_default ();
     ibus = bus_ibus_impl_get_default ();
     bus_dbus_impl_register_object (dbus, (IBusService *)ibus);
 
     /* init server */
-    GDBusServerFlags flags = G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
-    gchar *guid = g_dbus_generate_guid ();
+    guid = g_dbus_generate_guid ();
+    observer = g_dbus_auth_observer_new ();
     if (!g_str_has_prefix (g_address, "unix:tmpdir=") &&
         !g_str_has_prefix (g_address, "unix:path=")) {
         g_error ("Your socket address does not have the format unix:tmpdir=$DIR "
@@ -152,7 +203,7 @@ bus_server_init (void)
     server =  g_dbus_server_new_sync (
                     g_address, /* the place where the socket file lives, e.g. /tmp, abstract namespace, etc. */
                     flags, guid,
-                    NULL /* observer */,
+                    observer,
                     NULL /* cancellable */,
                     &error);
     if (server == NULL) {
@@ -162,7 +213,13 @@ bus_server_init (void)
     }
     g_free (guid);
 
-    g_signal_connect (server, "new-connection", G_CALLBACK (bus_new_connection_cb), NULL);
+    g_signal_connect (observer, "allow-mechanism",
+                      G_CALLBACK (bus_allow_mechanism_cb), NULL);
+    g_signal_connect (observer, "authorize-authenticated-peer",
+                      G_CALLBACK (bus_authorize_authenticated_peer_cb), NULL);
+    g_object_unref (observer);
+    g_signal_connect (server, "new-connection",
+                      G_CALLBACK (bus_new_connection_cb), NULL);
 
     g_dbus_server_start (server);
 
-- 
2.21.0