- 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>
pb_data_h handle,
GList *list);
+int peripheral_bus_check_privilege(
+ GDBusMethodInvocation *invocation,
+ peripheral_bus_s *pb_data);
+
#endif /* __PERIPHERAL_UTIL_H__ */
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);
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);
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);
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);
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);
return 0;
}
-static int peripheral_bus_check_privilege(
+int peripheral_bus_check_privilege(
GDBusMethodInvocation *invocation,
peripheral_bus_s *pb_data)
{