*
*/
+#include <cynara-client.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdint.h>
#include "resourced.h"
#include "util.h"
#include "fd-handler.h"
+#include "procfs.h"
#define D_BUS_INIT_RETRY_COUNT 5
static const GDBusInterfaceVTable vtable = { d_bus_method_handler, NULL, NULL };
+static gboolean d_bus_is_privileged(const gchar *name)
+{
+ int ret;
+ pid_t pid;
+ uid_t uid;
+ GVariant *reply;
+ cynara *p_cynara;
+ char *session = "";
+ char label[PROC_NAME_MAX];
+ char uid_str[8];
+
+ /* 1. Check SMACK label */
+ reply = g_dbus_connection_call_sync(d_bus_get_connection(),
+ DBUS_BUS_NAME, DBUS_OBJECT_PATH,
+ DBUS_INTERFACE_NAME, METHOD_DBUS_GET_PID,
+ g_variant_new("(s)", name), NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, NULL);
+
+ if (!reply) {
+ _E("Failed to get the PID of sender %s", name);
+ return FALSE;
+ }
+
+ g_variant_get(reply, "(u)", &pid);
+ g_variant_unref(reply);
+
+ ret = proc_get_label(pid, label);
+ if (ret < 0) {
+ _E("Failed to get SMACK label for PID %u (%d)", pid, ret);
+ return FALSE;
+ }
+
+ if (!strncmp(label, "System", 7) || !strncmp(label, "System::Privileged", 19))
+ return TRUE;
+
+ /* 2. Check privilege */
+ reply = g_dbus_connection_call_sync(d_bus_get_connection(),
+ DBUS_BUS_NAME, DBUS_OBJECT_PATH,
+ DBUS_INTERFACE_NAME, METHOD_DBUS_GET_UID,
+ g_variant_new("(s)", name), NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, NULL);
+
+ if (!reply) {
+ _E("Failed to get the UID of sender %s", name);
+ return FALSE;
+ }
+
+ g_variant_get(reply, "(u)", &uid);
+ g_variant_unref(reply);
+
+ snprintf(uid_str, 8, "%u", uid);
+
+ ret = cynara_initialize(&p_cynara, NULL);
+ if (ret != CYNARA_API_SUCCESS) {
+ _E("Failed to initialize cynara (%d)", ret);
+ return FALSE;
+ }
+
+ ret = cynara_check(p_cynara, label, session, uid_str, "http://tizen.org/privilege/systemsettings.admin");
+
+ cynara_finish(p_cynara);
+
+ if (ret != CYNARA_API_ACCESS_ALLOWED) {
+ _E("PID %u doesn't have a privilege", pid);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void d_bus_signal_handler(GDBusConnection *connection,
const gchar *sender, const gchar *object_path,
const gchar *interface_name, const gchar *signal_name,
if (!signal || !signal->callback)
return;
+ if (!d_bus_is_privileged(sender)) {
+ _E("This sender doesn't have privilege to run %s", signal_name);
+ return;
+ }
+
signal->callback(parameters);
}