- change name : peripheral_bus_check_privilege() -> peripheral_privilege_check()
Change-Id: I670e346d59ccd7fd8f51707c76268dc0a7c117fc
Signed-off-by: Segwon <segwon.han@samsung.com>
#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,
pb_data_h handle,
GList *list);
-int peripheral_bus_check_privilege(
- GDBusMethodInvocation *invocation,
- peripheral_bus_s *pb_data);
-
#endif /* __PERIPHERAL_UTIL_H__ */
#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__ */
#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,
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;
#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,
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;
#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,
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;
#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,
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;
#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,
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;
#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;
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,
GError *error = NULL;
GVariant *_ret;
const gchar *id;
- int err;
id = g_dbus_method_invocation_get_sender(invocation);
if (id == NULL) {
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);
* 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;
_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;
}