privilege: change the "peripheral_bus_check_privilege" function static to public. 60/160860/2
authorSegwon <segwon.han@samsung.com>
Mon, 20 Nov 2017 09:02:55 +0000 (18:02 +0900)
committerSegwon <segwon.han@samsung.com>
Mon, 20 Nov 2017 09:52:14 +0000 (18:52 +0900)
 - Use the peripheral_bus_check_privilege() directly in the gdbus function rather than in the peripheral_bus_get_client_info().
 - The ids generated by peripheral_bus_get_client_info() will not be used.

Change-Id: I8ec7536f04c1db069b31c8ac973d727e12ba7f0e
Signed-off-by: Segwon <segwon.han@samsung.com>
src/daemon/include/peripheral_bus_util.h
src/daemon/peripheral_bus_gdbus_gpio.c
src/daemon/peripheral_bus_gdbus_i2c.c
src/daemon/peripheral_bus_gdbus_pwm.c
src/daemon/peripheral_bus_gdbus_spi.c
src/daemon/peripheral_bus_gdbus_uart.c
src/daemon/peripheral_bus_util.c

index 45b8053..df2b6b1 100644 (file)
@@ -31,4 +31,8 @@ int peripheral_bus_handle_is_valid(
                pb_data_h handle,
                GList *list);
 
+int peripheral_bus_check_privilege(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data);
+
 #endif /* __PERIPHERAL_UTIL_H__ */
index 778f2c6..b45115b 100644 (file)
@@ -48,23 +48,23 @@ gboolean handle_gpio_open(
 
        GUnixFDList *gpio_fd_list = NULL;
 
-       if ((ret = peripheral_bus_gpio_open(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
                goto out;
+       }
 
-       if ((ret = peripheral_bus_get_client_info(invocation, pb_data, &gpio_handle->client_info)) < 0) {
-               peripheral_bus_gpio_close(gpio_handle);
-               gpio_handle = NULL;
+       if ((ret = peripheral_bus_gpio_open(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
                goto out;
-       }
 
-       gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       gpio_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+       gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                        NULL,
                        __gpio_on_name_vanished,
                        gpio_handle,
                        NULL);
-       _D("gpio : %d, id = %s", gpio_handle->dev.gpio.pin, gpio_handle->client_info.id);
 
 out:
        peripheral_io_gdbus_gpio_complete_open(gpio, invocation, gpio_fd_list, GPOINTER_TO_UINT(gpio_handle), ret);
index 8b21ac3..8a55bd5 100644 (file)
@@ -48,24 +48,23 @@ gboolean handle_i2c_open(
 
        GUnixFDList *i2c_fd_list = NULL;
 
-       if ((ret = peripheral_bus_i2c_open(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
                goto out;
+       }
 
-       if (peripheral_bus_get_client_info(invocation, pb_data, &i2c_handle->client_info) < 0) {
-               peripheral_bus_i2c_close(i2c_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               i2c_handle = NULL;
+       if ((ret = peripheral_bus_i2c_open(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
                goto out;
-       }
 
-       i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       i2c_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+       i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                        NULL,
                        __i2c_on_name_vanished,
                        i2c_handle,
                        NULL);
-       _D("bus : %d, address : 0x%x, id = %s", bus, address, i2c_handle->client_info.id);
 
 out:
        peripheral_io_gdbus_i2c_complete_open(i2c, invocation, i2c_fd_list, GPOINTER_TO_UINT(i2c_handle), ret);
index f4ad8e2..9560829 100644 (file)
@@ -48,24 +48,23 @@ gboolean handle_pwm_open(
 
        GUnixFDList *pwm_fd_list = NULL;
 
-       if ((ret = peripheral_bus_pwm_open(chip, pin, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
                goto out;
+       }
 
-       if (peripheral_bus_get_client_info(invocation, pb_data, &pwm_handle->client_info) < 0) {
-               peripheral_bus_pwm_close(pwm_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               pwm_handle = NULL;
+       if ((ret = peripheral_bus_pwm_open(chip, pin, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
                goto out;
-       }
 
-       pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       pwm_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+       pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                        NULL,
                        __pwm_on_name_vanished,
                        pwm_handle,
                        NULL);
-       _D("chip : %d, pin : %d, id = %s", chip, pin, pwm_handle->client_info.id);
 
 out:
        peripheral_io_gdbus_pwm_complete_open(pwm, invocation, pwm_fd_list, GPOINTER_TO_UINT(pwm_handle), ret);
index d85870e..11eb0e6 100644 (file)
@@ -48,24 +48,23 @@ gboolean handle_spi_open(
 
        GUnixFDList *spi_fd_list = NULL;
 
-       if ((ret = peripheral_bus_spi_open(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
                goto out;
+       }
 
-       if (peripheral_bus_get_client_info(invocation, pb_data, &spi_handle->client_info) < 0) {
-               peripheral_bus_spi_close(spi_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               spi_handle = NULL;
+       if ((ret = peripheral_bus_spi_open(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
                goto out;
-       }
 
-       spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       spi_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+       spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                        NULL,
                        __spi_on_name_vanished,
                        spi_handle,
                        NULL);
-       _D("bus : %d, cs : %d, id = %s", bus, cs, spi_handle->client_info.id);
 
 out:
        peripheral_io_gdbus_spi_complete_open(spi, invocation, spi_fd_list, GPOINTER_TO_UINT(spi_handle), ret);
index f05d02f..811d2eb 100644 (file)
@@ -47,24 +47,23 @@ gboolean handle_uart_open(
 
        GUnixFDList *uart_fd_list = NULL;
 
-       if ((ret = peripheral_bus_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       if (ret != 0) {
+               _E("Permission denied.");
+               ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
                goto out;
+       }
 
-       if (peripheral_bus_get_client_info(invocation, pb_data, &uart_handle->client_info) < 0) {
-               peripheral_bus_uart_close(uart_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               uart_handle = NULL;
+       if ((ret = peripheral_bus_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
                goto out;
-       }
 
-       uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       uart_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+       uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                       g_dbus_method_invocation_get_sender(invocation),
+                       G_BUS_NAME_WATCHER_FLAGS_NONE,
                        NULL,
                        __uart_on_name_vanished,
                        uart_handle,
                        NULL);
-       _D("port : %d, id = %s", port, uart_handle->client_info.id);
 
 out:
        peripheral_io_gdbus_uart_complete_open(uart, invocation, uart_fd_list, GPOINTER_TO_UINT(uart_handle), ret);
index 2c56614..859ebf9 100644 (file)
@@ -104,7 +104,7 @@ int peripheral_bus_data_free(pb_data_h handle)
        return 0;
 }
 
-static int peripheral_bus_check_privilege(
+int peripheral_bus_check_privilege(
                GDBusMethodInvocation *invocation,
                peripheral_bus_s *pb_data)
 {