static DBusMessage *cancel_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; struct service_adapter *serv_adapter = data; struct pending_auth *auth; const gchar *sender; sender = dbus_message_get_sender(msg); auth = find_pending_by_sender(serv_adapter, sender); if (auth == NULL) return btd_error_does_not_exist(msg); btd_cancel_authorization(auth->id); reply = btd_error_not_authorized(auth->msg); dbus_message_unref(auth->msg); g_dbus_send_message(btd_get_dbus_connection(), reply); serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list, auth); g_free(auth); auth = next_pending(serv_adapter); if (auth == NULL) goto done; auth->id = btd_request_authorization(get_address(serv_adapter), &auth->dst, auth->uuid, auth_cb, serv_adapter); done: return dbus_message_new_method_return(msg); }
static void auth_cb(DBusError *derr, void *user_data) { struct service_adapter *serv_adapter = user_data; DBusMessage *reply; struct pending_auth *auth; bdaddr_t src; auth = next_pending(serv_adapter); if (auth == NULL) { info("Authorization cancelled: Client exited"); return; } if (derr) { error("Access denied: %s", derr->message); reply = btd_error_not_authorized(auth->msg); dbus_message_unref(auth->msg); g_dbus_send_message(auth->conn, reply); goto done; } g_dbus_send_reply(auth->conn, auth->msg, DBUS_TYPE_INVALID); done: dbus_connection_unref(auth->conn); serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list, auth); g_free(auth); auth = next_pending(serv_adapter); if (auth == NULL) return; if (serv_adapter->adapter) adapter_get_address(serv_adapter->adapter, &src); else bacpy(&src, BDADDR_ANY); btd_request_authorization(&src, &auth->dst, auth->uuid, auth_cb, serv_adapter); }
static void build_list(struct pending_list *list, w_string_t *parent_name, size_t depth, size_t num_files, size_t num_dirs) { size_t i; for (i = 0; i < num_files; i++) { struct watchman_pending_fs *item = next_pending(list); item->path = w_string_make_printf("%.*s/file%d", parent_name->len, parent_name->buf, i); item->flags = W_PENDING_VIA_NOTIFY; } for (i = 0; i < num_dirs; i++) { struct watchman_pending_fs *item = next_pending(list); item->path = w_string_make_printf("%.*s/dir%d", parent_name->len, parent_name->buf, i); item->flags = W_PENDING_RECURSIVE; if (depth > 0) { build_list(list, item->path, depth - 1, num_files, num_dirs); } } }
static DBusMessage *cancel_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; struct service_adapter *serv_adapter = data; struct pending_auth *auth; const gchar *sender; bdaddr_t src; sender = dbus_message_get_sender(msg); auth = find_pending_by_sender(serv_adapter, sender); if (auth == NULL) return does_not_exist(msg); if (serv_adapter->adapter) adapter_get_address(serv_adapter->adapter, &src); else bacpy(&src, BDADDR_ANY); btd_cancel_authorization(&src, &auth->dst); reply = not_authorized(auth->msg); dbus_message_unref(auth->msg); g_dbus_send_message(auth->conn, reply); dbus_connection_unref(auth->conn); serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list, auth); g_free(auth); auth = next_pending(serv_adapter); if (auth == NULL) goto done; if (serv_adapter->adapter) adapter_get_address(serv_adapter->adapter, &src); else bacpy(&src, BDADDR_ANY); btd_request_authorization(&src, &auth->dst, auth->uuid, auth_cb, serv_adapter); done: return dbus_message_new_method_return(msg); }
static DBusMessage *request_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { struct record_data *user_record; struct service_adapter *serv_adapter = data; sdp_record_t *record; sdp_list_t *services; const char *sender; dbus_uint32_t handle; const char *address; struct pending_auth *auth; char uuid_str[MAX_LEN_UUID_STR]; uuid_t *uuid, *uuid128; bdaddr_t src; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) return NULL; sender = dbus_message_get_sender(msg); if (find_pending_by_sender(serv_adapter, sender)) return btd_error_does_not_exist(msg); user_record = find_record(serv_adapter, handle, sender); if (!user_record) { user_record = find_record(serv_adapter_any, handle, sender); if (!user_record) return btd_error_not_authorized(msg); } record = sdp_record_find(user_record->handle); if (record == NULL) return btd_error_not_authorized(msg); if (sdp_get_service_classes(record, &services) < 0) { sdp_record_free(record); return btd_error_not_authorized(msg); } if (services == NULL) return btd_error_not_authorized(msg); uuid = services->data; uuid128 = sdp_uuid_to_uuid128(uuid); sdp_list_free(services, bt_free); if (sdp_uuid2strn(uuid128, uuid_str, MAX_LEN_UUID_STR) < 0) { bt_free(uuid128); return btd_error_not_authorized(msg); } bt_free(uuid128); auth = g_new0(struct pending_auth, 1); auth->msg = dbus_message_ref(msg); auth->conn = dbus_connection_ref(connection); auth->sender = user_record->sender; memcpy(auth->uuid, uuid_str, MAX_LEN_UUID_STR); str2ba(address, &auth->dst); serv_adapter->pending_list = g_slist_append(serv_adapter->pending_list, auth); auth = next_pending(serv_adapter); if (auth == NULL) return btd_error_does_not_exist(msg); if (serv_adapter->adapter) adapter_get_address(serv_adapter->adapter, &src); else bacpy(&src, BDADDR_ANY); if (btd_request_authorization(&src, &auth->dst, auth->uuid, auth_cb, serv_adapter) < 0) { serv_adapter->pending_list = g_slist_remove(serv_adapter->pending_list, auth); g_free(auth); return btd_error_not_authorized(msg); } return NULL; }