Transferring uid will be a hole.
Someone will use the hole to use the paired/connected BT devices.
Therefore, uid is get from dbus.
Change-Id: I633772df0317284d60fe4635f5bd219c2f2bac56
Signed-off-by: Wu Zheng <wu.zheng@intel.com>
#include <dirent.h>
#include <dbus/dbus.h>
#include <gio/gunixfdlist.h>
+#include <string.h>
#include "bluetooth.h"
#include "obex.h"
static int bt_device_get_privileges(const char *remote_address)
{
int user_privilieges;
- int uid;
- uid = getuid();
- DBG("uid = %d, address = %s", uid, remote_address);
+ DBG("address = %s", remote_address);
user_privilieges = comms_bluetooth_get_user_privileges_sync(
- uid, remote_address);
+ remote_address);
return user_privilieges;
}
static int bt_device_get_privileges(const char *remote_address)
{
int user_privilieges;
- int uid;
- uid = getuid();
- DBG("uid = %d, address = %s", uid, remote_address);
+ DBG("address = %s", remote_address);
user_privilieges = comms_bluetooth_get_user_privileges_sync(
- uid, remote_address);
+ remote_address);
return user_privilieges;
}
static void handle_generic_device_removed(bluez_device_t *device, void *user_data)
{
adapter_device_discovery_info_t *device_info;
- int userid;
DBG("");
bluez_unpaired_device_removed(device, unpaired_device_removed_node);
else {
if (device_info->remote_address) {
- userid = getuid();
- comms_bluetooth_remove_user_privileges_sync(userid,
+ comms_bluetooth_remove_user_privileges_sync(
device_info->remote_address);
}
bluez_paired_device_removed(device, paired_device_removed_node);
memset(pairing_address, 0, ADDRESS_LEN);
return BT_SUCCESS;
} else if (user_privilieges == 2) {
- int uid;
- uid = getuid();
- DBG("pairing uid = %d", uid);
- comms_bluetooth_device_pair(remote_address, uid,
+ comms_bluetooth_device_pair(remote_address,
bt_device_paired_cb, strdup(remote_address));
return BT_SUCCESS;
Possible errors: org.bluez.Error.DoesNotExist
org.bluez.Error.Failed
- int GetUserPrivileges(int userid, string address)
+ int GetUserPrivileges(string address)
This method can be used to get user privileges
operation by the GetUserPrivileges method.
Possible errors: org.bluez.Error.DoesNotExist
- void RemoveUserPrivileges(int userid, string address)
+ void RemoveUserPrivileges(string address)
This method can be used to remove user privileges
operation by the RemoveUserPrivileges method.
void comms_bluetooth_device_pair(
const char *address,
- const unsigned int uid,
bluetooth_simple_callback cb,
void *user_data);
void *user_data);
int comms_bluetooth_get_user_privileges_sync(
- const unsigned int uid,
const char *address);
int comms_bluetooth_remove_user_privileges_sync(
- const unsigned int uid,
const char *address);
#endif
}
void comms_bluetooth_device_pair(const char *address,
- const unsigned int uid,
bluetooth_simple_callback cb,
void *user_data)
{
async_result_node->user_data = user_data;
g_dbus_proxy_call(this_bluetooth->pairing.proxy, "Pair",
- g_variant_new("(is)", uid, address),
+ g_variant_new("(s)", address),
0, -1, NULL,
bluetooth_simple_async_cb,
async_result_node);
return BT_SUCCESS;
}
-int comms_bluetooth_get_user_privileges_sync(const unsigned int uid,
- const char *address)
+int comms_bluetooth_get_user_privileges_sync(const char *address)
{
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_sync(this_bluetooth->pairing.proxy,
"GetUserPrivileges",
- g_variant_new("(is)", uid, address),
+ g_variant_new("(s)", address),
0, -1, NULL, &error);
if (error) {
return privileges;
}
-int comms_bluetooth_remove_user_privileges_sync(const unsigned int uid,
- const char *address)
+int comms_bluetooth_remove_user_privileges_sync(const char *address)
{
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_sync(this_bluetooth->pairing.proxy,
"RemoveUserPrivileges",
- g_variant_new("(is)", uid, address),
+ g_variant_new("(s)", address),
0, -1, NULL, &error);
if (error) {
GDBUS_ARGS(_ARG("agent", "o")), NULL),
GDBUS_METHOD("UnregisterPairingAgent",
GDBUS_ARGS(_ARG("agent", "o")), NULL),
- GDBUS_METHOD("Pair", GDBUS_ARGS(_ARG("userid", "i"),
- _ARG("address", "s")), NULL),
+ GDBUS_METHOD("Pair", GDBUS_ARGS(_ARG("address", "s")), NULL),
GDBUS_METHOD("CancelPairing", NULL, NULL),
GDBUS_METHOD("GetUserPrivileges",
- GDBUS_ARGS(_ARG("userid", "i"),
- _ARG("address", "s")),
+ GDBUS_ARGS(_ARG("address", "s")),
GDBUS_ARGS(_ARG("privilege_id", "i"))),
GDBUS_METHOD("RemoveUserPrivileges",
- GDBUS_ARGS(_ARG("userid", "i"),
- _ARG("address", "s")), NULL),
+ GDBUS_ARGS(_ARG("address", "s")), NULL),
NULL
};
NULL
};
+static guint32 get_connection_user_id(GDBusConnection *connection,
+ GDBusMethodInvocation *invocation)
+{
+ GError *error = NULL;
+ GVariant *uidvalue;
+ const gchar *sender;
+ guint32 uid;
+
+ DBG("");
+
+ sender = g_dbus_method_invocation_get_sender(invocation);
+ uidvalue = g_dbus_connection_call_sync(connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "GetConnectionUnixUser",
+ g_variant_new("(s)", sender),
+ NULL, 0, -1, NULL, &error);
+
+ if (uidvalue == NULL) {
+ DBG("GetConnectionUnixUser: %s", error->message);
+ g_error_free(error);
+ return -1;
+ }
+
+ g_variant_get(uidvalue, "(u)", &uid);
+ g_variant_unref(uidvalue);
+
+ DBG("uid = %d", uid);
+
+ return uid;
+}
+
static gboolean create_pairing_agent(GDBusConnection *connection)
{
DBG("");
{
bluez_device_t *device;
gchar *address;
- guint uid;
+ guint32 uid;
DBG("");
isbonding = TRUE;
- g_variant_get(parameters, "(is)", &uid, &address);
+ uid = get_connection_user_id(connection, invocation);
+ if (uid == -1) {
+ comms_error_does_not_exist(invocation);
+ isbonding = FALSE;
+ return;
+ }
+
+ g_variant_get(parameters, "(s)", &address);
if (pairing_device_address)
g_free(pairing_device_address);
gpointer user_data)
{
gchar *address;
- guint uid;
+ guint32 uid;
GVariant *value;
guint retvalue;
bluez_device_t *device;
DBG("+");
- g_variant_get(parameters, "(is)", &uid, &address);
+ uid = get_connection_user_id(connection, invocation);
+ if (uid == -1) {
+ comms_error_does_not_exist(invocation);
+ return;
+ }
+
+ g_variant_get(parameters, "(s)", &address);
device = bluez_adapter_get_device_by_address(default_adapter,
address);
gpointer user_data)
{
gchar *address;
- guint uid;
+ guint32 uid;
DBG("");
- g_variant_get(parameters, "(is)", &uid, &address);
+ uid = get_connection_user_id(connection, invocation);
+ if (uid == -1) {
+ comms_error_does_not_exist(invocation);
+ return;
+ }
+
+ g_variant_get(parameters, "(s)", &address);
remove_userprivileges(uid, address);
static int bt_pair(void *p1, void *p2)
{
- int uid;
-
- uid = getuid();
-
- DBG("uid = %d", uid);
+ DBG("");
- comms_bluetooth_device_pair(p1, uid, bt_simple_result_cb, NULL);
+ comms_bluetooth_device_pair(p1, bt_simple_result_cb, NULL);
return 0;
}