From: Mateusz Moscicki Date: Mon, 17 Jul 2023 13:16:39 +0000 (+0200) Subject: Use private dbus connection for synchronous calls. X-Git-Tag: accepted/tizen/6.0/unified/20230807.011505^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F296208%2F1;p=platform%2Fcore%2Fsystem%2Flibstorage.git Use private dbus connection for synchronous calls. This change is related to dotnet-launcher which in the process preparation, caused the connection to be established, which had a privileged label and was later used by an unprivileged application From now the connection is established before the dbus method is called and closed immediately after that. Change-Id: If672046f68b9e5aa37053fdb772ef17873df2340 --- diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 731296a..1fe6f8b 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -123,6 +123,55 @@ static GDBusConnection *get_dbus_connection(void) return conn; } +static GDBusConnection *get_dbus_private_connection(void) +{ + GError *err = NULL; + GDBusConnection *conn = NULL; + const char * address; + + address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (!address || err) { + _E("failed to get bus address\n"); + g_error_free(err); + return NULL; + } + + conn = g_dbus_connection_new_for_address_sync(address, + (GDBusConnectionFlags) (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), + NULL, /* GDBusAuthObserver */ + NULL, + &err); + if (!conn || err) { + _E("failed to get private bus\n"); + g_error_free(err); + return NULL; + } + + return conn; + +} + +static void free_dbus_connection(GDBusConnection *conn) +{ + assert(conn); + + GError *err = NULL; + if (!g_dbus_connection_flush_sync(conn, NULL, &err)) { + _E("failed to flush %s\n", err->message); + g_error_free(err); + err = NULL; + } + + if (!g_dbus_connection_close_sync(conn, NULL, &err)) { + _E("Error closing connection %s\n", err->message); + g_error_free(err); + err = NULL; + } + + g_object_unref(conn); +} + static void _cb_pending(GDBusConnection *conn, GAsyncResult *res, gpointer user_data) @@ -206,7 +255,7 @@ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, if (!dest || !path || !iface || !method) return NULL; - conn = get_dbus_connection(); + conn = get_dbus_private_connection(); if (!conn) { _E("fail to get dbus connection"); //LCOV_EXCL_LINE return NULL; @@ -227,6 +276,8 @@ GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, //LCOV_EXCL_STOP } + free_dbus_connection(conn); + return ret; }