예제 #1
0
int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out)
{
	uint32 error = 0;

	DEBUG_SVC("length %d", stream_get_length(data_out));

	error = plugin->channel_entry_points.pVirtualChannelWrite(plugin->priv->open_handle,
		stream_get_data(data_out), stream_get_length(data_out), data_out);
	if (error != CHANNEL_RC_OK)
		printf("svc_plugin_send: VirtualChannelWrite failed %d\n", error);

	return error;
}
예제 #2
0
파일: svc_plugin.c 프로젝트: akboom/FreeRDP
int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out)
{
	UINT32 status = 0;

	DEBUG_SVC("length %d", (int) stream_get_length(data_out));

	if (!plugin)
		status = CHANNEL_RC_BAD_INIT_HANDLE;
	else
		status = plugin->channel_entry_points.pVirtualChannelWrite(plugin->open_handle,
			stream_get_data(data_out), stream_get_length(data_out), data_out);

	if (status != CHANNEL_RC_OK)
	{
		stream_free(data_out);
		fprintf(stderr, "svc_plugin_send: VirtualChannelWrite failed %d\n", status);
	}

	return status;
}
예제 #3
0
int dvcman_receive_channel_data(IWTSVirtualChannelManager* pChannelMgr, uint32 ChannelId, uint8* data, uint32 data_size)
{
	int error = 0;
	DVCMAN_CHANNEL* channel;

	channel = dvcman_find_channel_by_id(pChannelMgr, ChannelId);

	if (channel == NULL)
	{
		DEBUG_WARN("ChannelId %d not found!", ChannelId);
		return 1;
	}

	if (channel->dvc_data)
	{
		/* Fragmented data */
		if (stream_get_length(channel->dvc_data) + data_size > (uint32) stream_get_size(channel->dvc_data))
		{
			DEBUG_WARN("data exceeding declared length!");
			stream_free(channel->dvc_data);
			channel->dvc_data = NULL;
			return 1;
		}

		stream_write(channel->dvc_data, data, data_size);

		if (stream_get_length(channel->dvc_data) >= stream_get_size(channel->dvc_data))
		{
			error = channel->channel_callback->OnDataReceived(channel->channel_callback,
				stream_get_size(channel->dvc_data), stream_get_data(channel->dvc_data));
			stream_free(channel->dvc_data);
			channel->dvc_data = NULL;
		}
	}
	else
	{
		error = channel->channel_callback->OnDataReceived(channel->channel_callback, data_size, data);
	}

	return error;
}
예제 #4
0
void scard_device_control(SCARD_DEVICE* scard, IRP* irp)
{
	uint32 output_len, input_len, ioctl_code;
	uint32 stream_len, result;
	uint32 pos, pad_len;
	uint32 irp_len;
	uint32 irp_result_pos, output_len_pos, result_pos;

	stream_read_uint32(irp->input, output_len);
	stream_read_uint32(irp->input, input_len);
	stream_read_uint32(irp->input, ioctl_code);

	stream_seek(irp->input, 20);	/* padding */

	// stream_seek(irp->input, 4);	/* TODO: parse len, le, v1 */
	// stream_seek(irp->input, 4);	/* 0xcccccccc */
	// stream_seek(irp->input, 4);	/* rpce len */

	/* [MS-RDPESC] 3.2.5.1 Sending Outgoing Messages */
	stream_extend(irp->output, 2048);

	irp_result_pos = stream_get_pos(irp->output);

	stream_write_uint32(irp->output, 0x00081001); /* len 8, LE, v1 */

	/* [MS-RPCE] 2.2.6.1 */
	stream_write_uint32(irp->output, 0x00081001); /* len 8, LE, v1 */
	stream_write_uint32(irp->output, 0xcccccccc); /* filler */

	output_len_pos = stream_get_pos(irp->output);
	stream_seek(irp->output, 4);		/* size */

	stream_write_uint32(irp->output, 0x0);	/* filler */

	result_pos = stream_get_pos(irp->output);
	stream_seek(irp->output, 4);		/* result */

	/* body */
	switch (ioctl_code)
	{
		case SCARD_IOCTL_ESTABLISH_CONTEXT:
			result = handle_EstablishContext(irp);
			break;

		case SCARD_IOCTL_IS_VALID_CONTEXT:
			result = handle_IsValidContext(irp);
			break;

		case SCARD_IOCTL_RELEASE_CONTEXT:
			result = handle_ReleaseContext(irp);
			break;

		case SCARD_IOCTL_LIST_READERS:
			result = handle_ListReaders(irp, 0);
			break;
		case SCARD_IOCTL_LIST_READERS + 4:
			result = handle_ListReaders(irp, 1);
			break;

		case SCARD_IOCTL_LIST_READER_GROUPS:
		case SCARD_IOCTL_LIST_READER_GROUPS + 4:
			/* typically not used unless list_readers fail */
			result = SCARD_F_INTERNAL_ERROR;
			break;

		case SCARD_IOCTL_GET_STATUS_CHANGE:
			result = handle_GetStatusChange(irp, 0);
			break;
		case SCARD_IOCTL_GET_STATUS_CHANGE + 4:
			result = handle_GetStatusChange(irp, 1);
			break;

		case SCARD_IOCTL_CANCEL:
			result = handle_Cancel(irp);
			break;

		case SCARD_IOCTL_CONNECT:
			result = handle_Connect(irp, 0);
			break;
		case SCARD_IOCTL_CONNECT + 4:
			result = handle_Connect(irp, 1);
			break;

		case SCARD_IOCTL_RECONNECT:
			result = handle_Reconnect(irp);
			break;

		case SCARD_IOCTL_DISCONNECT:
			result = handle_Disconnect(irp);
			break;

		case SCARD_IOCTL_BEGIN_TRANSACTION:
			result = handle_BeginTransaction(irp);
			break;

		case SCARD_IOCTL_END_TRANSACTION:
			result = handle_EndTransaction(irp);
			break;

		case SCARD_IOCTL_STATE:
			result = handle_State(irp);
			break;

		case SCARD_IOCTL_STATUS:
			result = handle_Status(irp, 0);
			break;
		case SCARD_IOCTL_STATUS + 4:
			result = handle_Status(irp, 1);
			break;

		case SCARD_IOCTL_TRANSMIT:
			result = handle_Transmit(irp);
			break;

		case SCARD_IOCTL_CONTROL:
			result = handle_Control(irp);
			break;

		case SCARD_IOCTL_GETATTRIB:
			result = handle_GetAttrib(irp);
			break;

		case SCARD_IOCTL_ACCESS_STARTED_EVENT:
			result = handle_AccessStartedEvent(irp);
			break;

		case SCARD_IOCTL_LOCATE_CARDS_BY_ATR:
			result = handle_LocateCardsByATR(irp, 0);
			break;
		case SCARD_IOCTL_LOCATE_CARDS_BY_ATR + 4:
			result = handle_LocateCardsByATR(irp, 1);
			break;

		default:
			result = 0xc0000001;
			printf("scard unknown ioctl 0x%x\n", ioctl_code);
			break;
	}

	/* look for NTSTATUS errors */
	if ((result & 0xc0000000) == 0xc0000000)
		return scard_error(scard, irp, result);

	/* per Ludovic Rousseau, map different usage of this particular
  	 * error code between pcsc-lite & windows */
	if (result == 0x8010001F)
		result = 0x80100022;

	/* handle response packet */
	pos = stream_get_pos(irp->output);
	stream_len = pos - irp_result_pos - 4;

	stream_set_pos(irp->output, output_len_pos);
	stream_write_uint32(irp->output, stream_len - 24);

	stream_set_pos(irp->output, result_pos);
	stream_write_uint32(irp->output, result);

	stream_set_pos(irp->output, pos);

	/* pad stream to 16 byte align */
	pad_len = stream_len % 16;
	stream_write_zero(irp->output, pad_len);
	pos = stream_get_pos(irp->output);
	irp_len = stream_len + pad_len;

	stream_set_pos(irp->output, irp_result_pos);
	stream_write_uint32(irp->output, irp_len);
	stream_set_pos(irp->output, pos);

#ifdef WITH_DEBUG_SCARD
	freerdp_hexdump(stream_get_data(irp->output), stream_get_length(irp->output));
#endif
	irp->IoStatus = 0;

	irp->Complete(irp);

}
예제 #5
0
파일: rdpdr_main.c 프로젝트: 4hosi/FreeRDP
static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL user_loggedon)
{
	int i;
	int pos;
	BYTE c;
	UINT32 count;
	int data_len;
	int count_pos;
	STREAM* data_out;
	DEVICE* device;
	LIST_ITEM* item;

	data_out = stream_new(256);

	stream_write_UINT16(data_out, RDPDR_CTYP_CORE);
	stream_write_UINT16(data_out, PAKID_CORE_DEVICELIST_ANNOUNCE);

	count_pos = stream_get_pos(data_out);
	count = 0;
	stream_seek_UINT32(data_out); /* deviceCount */

	for (item = rdpdr->devman->devices->head; item; item = item->next)
	{
		device = (DEVICE*) item->data;

		/**
		 * 1. versionMinor 0x0005 doesn't send PAKID_CORE_USER_LOGGEDON
		 *    so all devices should be sent regardless of user_loggedon
		 * 2. smartcard devices should be always sent
		 * 3. other devices are sent only after user_loggedon
		 */

		if ((rdpdr->versionMinor == 0x0005) ||
			(device->type == RDPDR_DTYP_SMARTCARD) || user_loggedon)
		{
			data_len = (device->data == NULL ? 0 : stream_get_length(device->data));
			stream_check_size(data_out, 20 + data_len);

			stream_write_UINT32(data_out, device->type); /* deviceType */
			stream_write_UINT32(data_out, device->id); /* deviceID */
			strncpy((char*) stream_get_tail(data_out), device->name, 8);

			for (i = 0; i < 8; i++)
			{
				stream_peek_BYTE(data_out, c);

				if (c > 0x7F)
					stream_write_BYTE(data_out, '_');
				else
					stream_seek_BYTE(data_out);
			}

			stream_write_UINT32(data_out, data_len);

			if (data_len > 0)
				stream_write(data_out, stream_get_data(device->data), data_len);

			count++;

			printf("registered device #%d: %s (type=%d id=%d)\n",
				count, device->name, device->type, device->id);
		}
	}

	pos = stream_get_pos(data_out);
	stream_set_pos(data_out, count_pos);
	stream_write_UINT32(data_out, count);
	stream_set_pos(data_out, pos);
	stream_seal(data_out);

	svc_plugin_send((rdpSvcPlugin*) rdpdr, data_out);
}