269
269
HgfsParseRequest(HgfsPacket *packet, // IN: request packet
270
HgfsSessionInfo *session, // IN: current session
270
HgfsTransportSessionInfo *transportSession, // IN: current session
271
271
HgfsInputParam **input, // OUT: request parameters
272
272
HgfsInternalStatus *status) // OUT: error code
275
275
size_t packetSize;
276
276
HgfsInternalStatus result = HGFS_ERROR_SUCCESS;
277
277
HgfsInputParam *localInput;
278
HgfsSessionInfo *session = NULL;
279
request = (HgfsRequest *) HSPU_GetMetaPacket(packet, &packetSize, session);
280
request = (HgfsRequest *) HSPU_GetMetaPacket(packet, &packetSize, transportSession);
280
281
ASSERT_DEVEL(request);
283
LOG(4, ("%s: Recieved a request with opcode %d.\n", __FUNCTION__, (int) request->op));
284
287
* How can I return error back to the client, clearly the client is either broken or
293
296
memset(localInput, 0, sizeof *localInput);
294
297
localInput->metaPacket = (char *)request;
295
298
localInput->metaPacketSize = packetSize;
296
localInput->session = session;
299
localInput->transportSession = transportSession;
297
300
localInput->packet = packet;
301
localInput->session = NULL;
300
304
* Error out if less than HgfsRequest size.
327
331
HgfsHeader *header = (HgfsHeader *)request;
328
332
localInput->v4header = TRUE;
329
333
localInput->id = header->requestId;
334
localInput->op = header->op;
331
336
if (packetSize >= offsetof(HgfsHeader, sessionId) + sizeof header->sessionId) {
332
if (header->sessionId != session->sessionId &&
333
header->op != HGFS_OP_CREATE_SESSION_V4) {
337
if (packetSize < header->packetSize ||
338
header->packetSize < header->headerSize) {
339
LOG(4, ("%s: Malformed HGFS packet received - inconsistent header"
340
" and packet sizes!\n", __FUNCTION__));
341
result = HGFS_ERROR_PROTOCOL;
344
if ((HGFS_ERROR_SUCCESS == result) &&
345
(header->op != HGFS_OP_CREATE_SESSION_V4)) {
346
session = HgfsServerTransportGetSessionInfo(transportSession,
348
if (!session || session->state != HGFS_SESSION_STATE_OPEN) {
334
349
LOG(4, ("%s: HGFS packet with invalid session id!\n", __FUNCTION__));
335
350
result = HGFS_ERROR_STALE_SESSION;
336
} else if (packetSize < header->packetSize ||
337
header->packetSize < header->headerSize) {
338
LOG(4, ("%s: Malformed HGFS packet received - inconsistent header"
339
" and packet sizes!\n", __FUNCTION__));
340
result = HGFS_ERROR_PROTOCOL;
343
354
LOG(4, ("%s: Malformed HGFS packet received - header is too small!\n",
348
359
if (HGFS_ERROR_SUCCESS == result) { // Passed all tests
349
localInput->op = header->op;
350
360
localInput->payload = (char *)request + header->headerSize;
351
361
localInput->payloadSize = header->packetSize - header->headerSize;
356
366
result = HGFS_ERROR_PROTOCOL;
358
369
if (HGFS_ERROR_SUCCESS != result) {
359
370
LOG(4, ("%s: Malformed HGFS packet received!\n", __FUNCTION__));
371
} else if ((NULL == session) && (!localInput->v4header)) {
372
session = HgfsServerTransportGetSessionInfo(transportSession,
373
transportSession->defaultSessionId);
374
if (NULL == session) {
376
* Create a new session if the default session doesn't exist.
378
if (!HgfsServerAllocateSession(transportSession,
379
transportSession->channelCapabilities,
381
result = HGFS_ERROR_NOT_ENOUGH_MEMORY;
383
result = HgfsServerTransportAddSessionToList(transportSession,
385
if (HGFS_ERROR_SUCCESS != result) {
386
LOG(4, ("%s: Could not add session to the list.\n", __FUNCTION__));
388
transportSession->defaultSessionId = session->sessionId;
389
HgfsServerSessionGet(session);
396
session->isInactive = FALSE;
398
localInput->session = session;
362
399
localInput->payloadOffset = (char *)localInput->payload -
363
400
(char *)localInput->metaPacket;
364
401
*status = result;
4322
4359
*data = HSPU_GetDataPacketBuf(input->packet,
4361
input->transportSession);
4325
4362
if (NULL == *data) {
4326
4363
LOG(4, ("%s: Failed to get data in guest memory\n", __FUNCTION__));
4327
4364
result = FALSE;