Apply send_destination_prefix policy#3 78/198178/1 submit/tizen_5.0/20190118.024626
authorWootak Jung <wootak.jung@samsung.com>
Tue, 22 Jan 2019 05:29:20 +0000 (14:29 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 22 Jan 2019 05:29:20 +0000 (14:29 +0900)
Change rfcomm connection from private to shared

Change-Id: I59924564c134a7d4f7ea13a4c25ffd41345792d8

bt-api/bt-common.c
bt-api/include/bt-common.h
bt-oal/bluez_hal/bluetooth-frwk-gap-agent.conf

index ca76fa0..ed4ddba 100644 (file)
@@ -951,11 +951,28 @@ void _bt_unregister_gdbus(int object_id)
 {
        GDBusConnection *gconn;
 
-       gconn = __get_gdbus_connection();
+       gconn = _bt_init_system_gdbus_conn();
        if (gconn == NULL)
                return;
 
        g_dbus_connection_unregister_object(gconn, object_id);
+
+       /* TODO: bus_id needs to be un-owned if all of path is unregistered */
+}
+
+static GDBusNodeInfo *_bt_get_gdbus_node(GDBusConnection *gconn, const gchar *xml_data, const char *bus_name)
+{
+       if (bus_id == 0) {
+               char *name = g_strdup(bus_name);
+               BT_DBG("well-known name: %s", name);
+               bus_id = g_bus_own_name_on_connection(gconn,
+                               name, G_BUS_NAME_OWNER_FLAGS_NONE,
+                               NULL, NULL, NULL, NULL);
+               BT_DBG("Got bus id %d", bus_id);
+               g_free(name);
+       }
+
+       return g_dbus_node_info_new_for_xml(xml_data, NULL);
 }
 
 int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
@@ -964,14 +981,20 @@ int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
        GDBusNodeInfo *node_info;
        int id;
        GError *error = NULL;
+       char *bus_name;
 
-       gconn = __get_gdbus_connection();
+       gconn = _bt_init_system_gdbus_conn();
        if (gconn == NULL)
                return -1;
 
-       node_info = _bt_get_gdbus_node(rfcomm_agent_xml);
-       if (node_info == NULL)
+       bus_name = g_strdup_printf("org.bt.frwk.p%d", getpid());
+
+       node_info = _bt_get_gdbus_node(gconn, rfcomm_agent_xml, bus_name);
+       if (node_info == NULL) {
+               g_free(bus_name);
                return -1;
+       }
+       g_free(bus_name);
 
        id = g_dbus_connection_register_object(gconn, path,
                                                node_info->interfaces[0],
@@ -1065,12 +1088,11 @@ int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_conn
        int id;
        GError *error = NULL;
 
-       gconn = __get_gdbus_connection();
+       gconn = _bt_init_system_gdbus_conn();
        if (gconn == NULL)
                return -1;
 
-       node_info = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name);
-
+       node_info = _bt_get_gdbus_node(gconn, rfcomm_agent_xml, bus_name);
        if (node_info == NULL)
                return -1;
 
@@ -1322,45 +1344,6 @@ void _bt_unregister_profile(char *path)
        return;
 }
 
-GDBusNodeInfo * _bt_get_gdbus_node(const gchar *xml_data)
-{
-       if (bus_id == 0) {
-               char *name = g_strdup_printf("org.bt.frwk.p%d", getpid());
-
-               bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                                               name,
-                                               G_BUS_NAME_OWNER_FLAGS_NONE,
-                                               NULL,
-                                               NULL,
-                                               NULL,
-                                               NULL,
-                                               NULL);
-               BT_DBG("Got bus id %d", bus_id);
-               g_free(name);
-       }
-
-       return g_dbus_node_info_new_for_xml(xml_data, NULL);
-}
-
-GDBusNodeInfo * _bt_get_gdbus_node_ex(const gchar *xml_data, const char *bus_name)
-{
-       if (bus_id == 0) {
-               char *name = g_strdup(bus_name);
-               bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                                               name,
-                                               G_BUS_NAME_OWNER_FLAGS_NONE,
-                                               NULL,
-                                               NULL,
-                                               NULL,
-                                               NULL,
-                                               NULL);
-               BT_DBG("Got bus id %d", bus_id);
-               g_free(name);
-       }
-
-       return g_dbus_node_info_new_for_xml(xml_data, NULL);
-}
-
 int _bt_connect_profile(char *address, char *uuid, void *cb,
                                                        gpointer func_data)
 {
index aaee16c..e7d3765 100644 (file)
@@ -363,8 +363,6 @@ int _bt_register_profile_platform(bt_register_profile_info_t *info, gboolean use
 int _bt_register_profile_ex(bt_register_profile_info_t *info, gboolean use_default_rfcomm, const char *name, const char *path);
 
 void _bt_unregister_profile(char *path);
-GDBusNodeInfo * _bt_get_gdbus_node(const gchar *xml_data);
-GDBusNodeInfo * _bt_get_gdbus_node_ex(const gchar *xml_data, const char *bus_name);
 int __rfcomm_assign_id(void);
 void __rfcomm_delete_id(int id);
 void _bt_unregister_gdbus(int object_id);
index 29f6a17..afe7243 100644 (file)
@@ -2,31 +2,20 @@
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
     <policy user="root">
-        <!-- service name(org.bt.frwk.p<pid>) is changeable by pid -->
         <allow own_prefix="org.bt.frwk"/>
-        <allow send_interface="org.bluez.Profile1" send_member="NewConnection"/>
-        <allow send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
+        <allow send_destination_prefix="org.bt.frwk"/>
         <allow own_prefix="org.frwk.gatt_service"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.Properties"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.ObjectManager"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattCharacteristic1"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattDescriptor1"/>
+        <allow send_destination_prefix="org.frwk.gatt_service"/>
     </policy>
     <policy group="network_fw">
-        <!-- service name(org.bt.frwk.p<pid>) is changeable by pid -->
         <allow own_prefix="org.bt.frwk"/>
-        <allow send_interface="org.bluez.Profile1" send_member="NewConnection"/>
-        <allow send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
+        <allow send_destination_prefix="org.bt.frwk"/>
         <allow own_prefix="org.frwk.gatt_service"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.Properties"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.ObjectManager"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattCharacteristic1"/>
-        <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattDescriptor1"/>
+        <allow send_destination_prefix="org.frwk.gatt_service"/>
     </policy>
     <policy context="default">
         <deny own_prefix="org.bt.frwk"/>
-        <deny send_interface="org.bluez.Profile1" send_member="NewConnection"/>
-        <deny send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
+        <deny send_destination_prefix="org.bt.frwk"/>
         <deny own_prefix="org.frwk.gatt_service"/>
         <deny send_destination_prefix="org.frwk.gatt_service"/>
     </policy>