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 d4baf729046349e197b81ad534d3b5d3d235ab41..595ca2c5dca78f4d4874768363ce7061d17cc1dc 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 df2b6b11183f7e7db440e434a93564a6bce513c0..45b8053ec2c08984e6a5fe09336033dfbf4c7641 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 a39fb8de7b717f493f98807d4023386c3590c53e..e225bf7cb25cafe3ac56b0fb9deddd7b1edf28f7 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 685c826516524c3e4a0ca1df26b7a44abed366eb..2401f8dc09067841c6ee39ea17b79e2489466953 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 5272fc70d6525987e5cbeab00054b10f6fe400c4..f4dea911978ae94ed7edb06d463f215e2e065de9 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 7c40024594e1651c8c67a8f467cda2e5bea83a84..4de63b7a0821503889cf4d8fbbed077dc65dd69d 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 d8b590d38aa2a201282bc1e5fa806c693bff611b..3427329080d4748b75b7e8d801a0d7e3ff63dc02 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 06d028bd599e3cf5a0abee3e4b281c33a64e4df8..bbb09a62bc1f3848308f9c75ada8076478debd1f 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 eb270241759b79d6dc72e779100e1b92705b9dd9..075d9ae5f8ea22b0053b6ea275bf16ea07873657 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 e35298d0ad5224f3d0d2d884951e65685c59c520..37f9dd525bd661eee645c4530377b312ca38f2a1 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;
 }