privilege: move peripheral_bus_check_privilege() to privilege_checker.h 94/160994/3
authorSegwon <segwon.han@samsung.com>
Tue, 21 Nov 2017 04:52:27 +0000 (13:52 +0900)
committerSegwon Han <segwon.han@samsung.com>
Tue, 21 Nov 2017 06:28:44 +0000 (06:28 +0000)
 - change name : peripheral_bus_check_privilege() -> peripheral_privilege_check()

Change-Id: I670e346d59ccd7fd8f51707c76268dc0a7c117fc
Signed-off-by: Segwon <segwon.han@samsung.com>
include/peripheral_bus.h
include/peripheral_bus_util.h
include/privilege_checker.h
src/gdbus/peripheral_gdbus_gpio.c
src/gdbus/peripheral_gdbus_i2c.c
src/gdbus/peripheral_gdbus_pwm.c
src/gdbus/peripheral_gdbus_spi.c
src/gdbus/peripheral_gdbus_uart.c
src/peripheral_bus_util.c
src/privilege_checker.c

index d4baf72..595ca2c 100644 (file)
@@ -22,8 +22,6 @@
 #include "peripheral_io_gdbus.h"
 #include "peripheral_bus_board.h"
 
-#define PERIPHERAL_PRIVILEGE "http://tizen.org/privilege/peripheralio"
-
 typedef enum {
        PERIPHERAL_BUS_TYPE_GPIO = 0,
        PERIPHERAL_BUS_TYPE_I2C,
index df2b6b1..45b8053 100644 (file)
@@ -31,8 +31,4 @@ 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 a39fb8d..e225bf7 100644 (file)
 #ifndef __PRIVILEGE_CHECKER_H__
 #define __PRIVILEGE_CHECKER_H__
 
-#include <stdbool.h>
+#include <gio/gio.h>
 
 void peripheral_privilege_init(void);
 void peripheral_privilege_deinit(void);
-bool peripheral_privilege_check(const char* client, const char* session, const char* user, const char* privilege);
+int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection);
 
 #endif /* __PRIVILEGE_CHECKER_H__ */
index 685c826..2401f8d 100644 (file)
@@ -23,6 +23,7 @@
 #include "peripheral_log.h"
 #include "peripheral_bus_util.h"
 #include "peripheral_gdbus_gpio.h"
+#include "privilege_checker.h"
 
 static void __gpio_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
@@ -48,7 +49,7 @@ gboolean handle_gpio_open(
 
        GUnixFDList *gpio_fd_list = NULL;
 
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       ret = peripheral_privilege_check(invocation, pb_data->connection);
        if (ret != 0) {
                _E("Permission denied.");
                ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
index 5272fc7..f4dea91 100644 (file)
@@ -22,6 +22,7 @@
 #include "peripheral_log.h"
 #include "peripheral_bus_util.h"
 #include "peripheral_gdbus_i2c.h"
+#include "privilege_checker.h"
 
 static void __i2c_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
@@ -48,7 +49,7 @@ gboolean handle_i2c_open(
 
        GUnixFDList *i2c_fd_list = NULL;
 
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       ret = peripheral_privilege_check(invocation, pb_data->connection);
        if (ret != 0) {
                _E("Permission denied.");
                ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
index 7c40024..4de63b7 100644 (file)
@@ -22,6 +22,7 @@
 #include "peripheral_log.h"
 #include "peripheral_bus_util.h"
 #include "peripheral_gdbus_pwm.h"
+#include "privilege_checker.h"
 
 static void __pwm_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
@@ -48,7 +49,7 @@ gboolean handle_pwm_open(
 
        GUnixFDList *pwm_fd_list = NULL;
 
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       ret = peripheral_privilege_check(invocation, pb_data->connection);
        if (ret != 0) {
                _E("Permission denied.");
                ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
index d8b590d..3427329 100644 (file)
@@ -22,6 +22,7 @@
 #include "peripheral_log.h"
 #include "peripheral_bus_util.h"
 #include "peripheral_gdbus_spi.h"
+#include "privilege_checker.h"
 
 static void __spi_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
@@ -48,7 +49,7 @@ gboolean handle_spi_open(
 
        GUnixFDList *spi_fd_list = NULL;
 
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       ret = peripheral_privilege_check(invocation, pb_data->connection);
        if (ret != 0) {
                _E("Permission denied.");
                ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
index 06d028b..bbb09a6 100644 (file)
@@ -22,6 +22,7 @@
 #include "peripheral_log.h"
 #include "peripheral_bus_util.h"
 #include "peripheral_gdbus_uart.h"
+#include "privilege_checker.h"
 
 static void __uart_on_name_vanished(GDBusConnection *connection,
                const gchar     *name,
@@ -47,7 +48,7 @@ gboolean handle_uart_open(
 
        GUnixFDList *uart_fd_list = NULL;
 
-       ret = peripheral_bus_check_privilege(invocation, pb_data);
+       ret = peripheral_privilege_check(invocation, pb_data->connection);
        if (ret != 0) {
                _E("Permission denied.");
                ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
index eb27024..075d9ae 100644 (file)
 #include <string.h>
 #include <gio/gio.h>
 
-#include <cynara-creds-gdbus.h>
-#include <cynara-client.h>
-#include <cynara-session.h>
-
 #include "peripheral_bus.h"
 #include "peripheral_log.h"
 
-#include "privilege_checker.h"
-
 GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length)
 {
        GVariantBuilder *builder;
@@ -85,43 +79,7 @@ int peripheral_bus_data_free(pb_data_h handle)
        return 0;
 }
 
-int peripheral_bus_check_privilege(
-               GDBusMethodInvocation *invocation,
-               peripheral_bus_s *pb_data)
-{
-       int pid;
-       const char *sender;
-       char *session;
-       char *client;
-       char *user;
-
-       sender = g_dbus_method_invocation_get_sender(invocation);
-
-       cynara_creds_gdbus_get_pid(pb_data->connection, sender, &pid);
-       session = cynara_session_from_pid(pid);
-
-       cynara_creds_gdbus_get_client(pb_data->connection, sender, CLIENT_METHOD_DEFAULT, &client);
-       cynara_creds_gdbus_get_user(pb_data->connection, sender, USER_METHOD_DEFAULT, &user);
-
-       if (!session || !client || !user) {
-               _E("Failed to get client info");
-               return -1;
-       }
-
-       if (!peripheral_privilege_check(client, session, user, PERIPHERAL_PRIVILEGE)) {
-               g_free(session);
-               g_free(client);
-               g_free(user);
-               return -EACCES;
-       }
-
-       g_free(session);
-       g_free(client);
-       g_free(user);
-
-       return 0;
-}
-
+// TODO : This function will be removed (unused)
 int peripheral_bus_get_client_info(
                GDBusMethodInvocation *invocation,
                peripheral_bus_s *pb_data,
@@ -131,7 +89,6 @@ int peripheral_bus_get_client_info(
        GError *error = NULL;
        GVariant *_ret;
        const gchar *id;
-       int err;
 
        id = g_dbus_method_invocation_get_sender(invocation);
        if (id == NULL) {
@@ -161,11 +118,6 @@ int peripheral_bus_get_client_info(
        g_variant_get(_ret, "(u)", &pid);
        g_variant_unref(_ret);
 
-       if ((err = peripheral_bus_check_privilege(invocation, pb_data)) < 0) {
-               _E("Permission denied(%d)", pid);
-               return err;
-       }
-
        client_info->pid = (pid_t)pid;
        client_info->pgid = getpgid(pid);
        client_info->id = strdup(id);
index e35298d..37f9dd5 100644 (file)
  * limitations under the License.
  */
 
-#include <sys/types.h>
-#include <unistd.h>
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <peripheral_io.h>
-
 #include <cynara-creds-gdbus.h>
 #include <cynara-client.h>
 #include <cynara-session.h>
 
-#include "peripheral_bus.h"
+#include "privilege_checker.h"
 #include "peripheral_log.h"
 
+#define PERIPHERAL_PRIVILEGE "http://tizen.org/privilege/peripheralio"
+
 #define CACHE_SIZE  100
 
 static cynara *__cynara;
@@ -67,11 +61,39 @@ void peripheral_privilege_deinit(void)
        _D("Cynara deinitialized");
 }
 
-bool peripheral_privilege_check(const char* client, const char* session, const char* user, const char* privilege)
+int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection)
 {
-       RETVM_IF(!privilege, true, "Invalid parameter");
-       RETVM_IF(!__cynara, false, "Cynara does not initialized");
+       int ret;
+       int pid;
+       const char *sender;
+       char *session;
+       char *client;
+       char *user;
+
+       sender = g_dbus_method_invocation_get_sender(invocation);
+
+       cynara_creds_gdbus_get_pid(connection, sender, &pid);
+       session = cynara_session_from_pid(pid);
+
+       cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client);
+       cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user);
+
+       if (!session || !client || !user) {
+               _E("Failed to get client info");
+               return -1;
+       }
+
+       ret = cynara_check(__cynara, client, session, user, PERIPHERAL_PRIVILEGE);
+       if (ret != 0) {
+               g_free(session);
+               g_free(client);
+               g_free(user);
+               return -EACCES;
+       }
+
+       g_free(session);
+       g_free(client);
+       g_free(user);
 
-       int ret = cynara_check(__cynara, client, session, user, privilege);
-       return (ret == CYNARA_API_ACCESS_ALLOWED);
+       return 0;
 }