~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/foundryMsg/foundryMsg.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-30 12:56:49 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730125649-97sfj5li8axiseoo
Tags: 2009.07.22-179896-2
* Temporarily building without dumbnet, the recently uploaded
  new dumbnet upstream version broke down (Closes: #539006).
* Using more common name to store local debian additions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
257
257
                           VIX_COMMAND_CATEGORY_ALWAYS_ALLOWED),
258
258
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_OPEN_TEAM,
259
259
                           VIX_COMMAND_CATEGORY_PRIVILEGED),
260
 
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_FIND_HOST_DEVICES,
261
 
                           VIX_COMMAND_CATEGORY_PRIVILEGED),
262
 
   
 
260
   VIX_DEFINE_UNUSED_COMMAND,
 
261
 
263
262
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_ANSWER_MESSAGE,
264
263
                           VIX_COMMAND_CATEGORY_PRIVILEGED),
265
264
 
422
421
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_LIST_FILESYSTEMS,
423
422
                           VIX_COMMAND_CATEGORY_ALWAYS_ALLOWED),
424
423
 
 
424
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_CHANGE_DISPLAY_TOPOLOGY,
 
425
                           VIX_COMMAND_CATEGORY_ALWAYS_ALLOWED),
 
426
 
 
427
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_SUSPEND_AND_RESUME,
 
428
                           VIX_COMMAND_CATEGORY_PRIVILEGED),
 
429
 
 
430
   VIX_DEFINE_COMMAND_INFO(VIX_COMMAND_REMOVE_BULK_SNAPSHOT,
 
431
                           VIX_COMMAND_CATEGORY_PRIVILEGED),
 
432
 
425
433
};
426
434
 
427
435
 
1315
1323
 *
1316
1324
 * VixAsyncOp_ValidateCommandInfoTable --
1317
1325
 *
1318
 
 *      Checkes that the command info table is generally well-formed.
 
1326
 *      Checks that the command info table is generally well-formed.
1319
1327
 *      Makes sure that the table is big enough to contain all the
1320
1328
 *      command op codes and that they are present in the right order.
1321
1329
 *
1461
1469
 
1462
1470
   return commandInfo;
1463
1471
} // VixGetCommandInfoForOpCode
 
1472
 
 
1473
 
 
1474
/*
 
1475
 *-----------------------------------------------------------------------------
 
1476
 *
 
1477
 * VixMsg_AllocGenericRequestMsg --
 
1478
 *
 
1479
 *      Allocate and initialize a generic request message.
 
1480
 *
 
1481
 *      Assumes the caller holds the lock to 'propertyList'.
 
1482
 *
 
1483
 * Results:
 
1484
 *      Returns VixError.
 
1485
 *      Upon retrun, *request will contain either the message with the
 
1486
 *      headers properly initialized or NULL.
 
1487
 *
 
1488
 * Side effects:
 
1489
 *      None.
 
1490
 *
 
1491
 *-----------------------------------------------------------------------------
 
1492
 */
 
1493
 
 
1494
VixError
 
1495
VixMsg_AllocGenericRequestMsg(int opCode,                         // IN
 
1496
                              uint64 cookie,                      // IN
 
1497
                              int credentialType,                 // IN
 
1498
                              const char *userNamePassword,       // IN
 
1499
                              int options,                        // IN
 
1500
                              VixPropertyListImpl *propertyList,  // IN
 
1501
                              VixCommandGenericRequest **request) // OUT
 
1502
{
 
1503
   VixError err;
 
1504
   VixCommandGenericRequest *requestLocal = NULL;
 
1505
   size_t msgHeaderAndBodyLength;
 
1506
   char *serializedBufferBody = NULL;
 
1507
   size_t serializedBufferLength = 0;
 
1508
 
 
1509
   if (NULL == request) {
 
1510
      ASSERT(0);
 
1511
      err = VIX_E_FAIL;
 
1512
      goto abort;
 
1513
   }
 
1514
 
 
1515
   *request = NULL;
 
1516
 
 
1517
   if (NULL != propertyList) {
 
1518
      err = VixPropertyList_Serialize(propertyList,
 
1519
                                      FALSE,
 
1520
                                      &serializedBufferLength,
 
1521
                                      &serializedBufferBody);
 
1522
      if (VIX_OK != err) {
 
1523
         goto abort;
 
1524
      }
 
1525
   }
 
1526
 
 
1527
   msgHeaderAndBodyLength = sizeof(*requestLocal) + serializedBufferLength;
 
1528
   requestLocal = (VixCommandGenericRequest *)
 
1529
      VixMsg_AllocRequestMsg(msgHeaderAndBodyLength,
 
1530
                             opCode,
 
1531
                             cookie,
 
1532
                             credentialType,
 
1533
                             userNamePassword);
 
1534
   if (NULL == requestLocal) {
 
1535
      err = VIX_E_FAIL;
 
1536
      goto abort;
 
1537
   }
 
1538
 
 
1539
   requestLocal->options = options;
 
1540
   requestLocal->propertyListSize = serializedBufferLength;
 
1541
 
 
1542
   if (NULL != serializedBufferBody) {
 
1543
      char *dst = (char *)request + sizeof(*request);
 
1544
      memcpy(dst, serializedBufferBody, serializedBufferLength);
 
1545
   }
 
1546
 
 
1547
   *request = requestLocal;
 
1548
   err = VIX_OK;
 
1549
 
 
1550
 abort:
 
1551
   free(serializedBufferBody);
 
1552
 
 
1553
   return err;
 
1554
}  // VixMsg_AllocGenericRequestMsg
 
1555
 
 
1556
 
 
1557
/*
 
1558
 *-----------------------------------------------------------------------------
 
1559
 *
 
1560
 * VixMsg_ParseGenericRequestMsg --
 
1561
 *
 
1562
 *      Extract the options and property list from the request
 
1563
 *      message, while validating message.
 
1564
 *
 
1565
 * Results:
 
1566
 *      VixError
 
1567
 *
 
1568
 * Side effects:
 
1569
 *      None.
 
1570
 *
 
1571
 *-----------------------------------------------------------------------------
 
1572
 */
 
1573
 
 
1574
VixError
 
1575
VixMsg_ParseGenericRequestMsg(const VixCommandGenericRequest *request,  // IN
 
1576
                              int *options,                             // OUT
 
1577
                              VixPropertyListImpl *propertyList)        // OUT
 
1578
{
 
1579
   VixError err;
 
1580
   uint64 headerAndBodyLength;
 
1581
 
 
1582
   if ((NULL == request) || (NULL == options) || (NULL == propertyList)) {
 
1583
      ASSERT(0);
 
1584
      err = VIX_E_FAIL;
 
1585
      goto abort;
 
1586
   }
 
1587
 
 
1588
   *options = 0;
 
1589
   VixPropertyList_Initialize(propertyList);
 
1590
 
 
1591
   /*
 
1592
    * In most cases we will have already called VixMsg_ValidateResponseMsg()
 
1593
    * on this request before, but call it here so that this function will
 
1594
    * always be sufficient to validate the request.
 
1595
    */
 
1596
   err = VixMsg_ValidateRequestMsg(request,
 
1597
                                   request->header.commonHeader.totalMessageLength);
 
1598
   if (VIX_OK != err) {
 
1599
      goto abort;
 
1600
   }
 
1601
 
 
1602
   if (request->header.commonHeader.totalMessageLength < sizeof *request) {
 
1603
      err = VIX_E_INVALID_MESSAGE_BODY;
 
1604
      goto abort;
 
1605
   }
 
1606
 
 
1607
   headerAndBodyLength = (uint64) request->header.commonHeader.headerLength
 
1608
      + request->header.commonHeader.bodyLength;
 
1609
 
 
1610
   if (headerAndBodyLength < ((uint64) sizeof *request
 
1611
                              + request->propertyListSize)) {
 
1612
      err = VIX_E_INVALID_MESSAGE_BODY;
 
1613
      goto abort;
 
1614
   }
 
1615
 
 
1616
   if (request->propertyListSize > 0) {
 
1617
      const char *serializedBuffer = (const char *) request + sizeof(*request);
 
1618
 
 
1619
      err = VixPropertyList_Deserialize(propertyList,
 
1620
                                        serializedBuffer,
 
1621
                                        request->propertyListSize);
 
1622
      if (VIX_OK != err) {
 
1623
         goto abort;
 
1624
      }
 
1625
   }
 
1626
 
 
1627
   *options = request->options;
 
1628
   err = VIX_OK;
 
1629
 
 
1630
 abort:
 
1631
 
 
1632
   return err;
 
1633
} // VixMsg_ParseGenericRequestMsg