~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools-precise.sid-merge1

« back to all changes in this revision

Viewing changes to services/plugins/vix/foundryToolsDaemon.c

  • Committer: Evan Broder
  • Date: 2010-03-21 23:26:53 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: broder@mit.edu-20100321232653-5a57r7v7ch4o6byv
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
776
776
   return TRUE;
777
777
}
778
778
 
779
 
 
780
 
/*
781
 
 *-----------------------------------------------------------------------------
782
 
 *
783
 
 * ToolsDaemonTcloSetPrinter --
784
 
 *
785
 
 *    Set the printer on the guest.
786
 
 *
787
 
 * Return value:
788
 
 *    TRUE on success
789
 
 *    FALSE on failure
790
 
 *
791
 
 * Side effects:
792
 
 *    None
793
 
 *
794
 
 *-----------------------------------------------------------------------------
795
 
 */
796
 
 
797
 
RpcInRet
798
 
ToolsDaemonTcloSetPrinter(RpcInData *data) // IN
799
 
{
800
 
   static char resultBuffer[DEFAULT_RESULT_MSG_MAX_LENGTH];
801
 
#if defined(_WIN32)
802
 
   VixError err = VIX_OK;
803
 
   char *printerName = NULL;
804
 
   char *defaultString = NULL;
805
 
   int defaultInt;
806
 
   DWORD sysError = ERROR_SUCCESS;
807
 
   Debug(">ToolsDaemonTcloSetPrinter\n");
808
 
 
809
 
   /*
810
 
    * Parse the arguments
811
 
    */
812
 
   printerName = ToolsDaemonTcloGetQuotedString(data->args, &data->args);
813
 
   defaultString = ToolsDaemonTcloGetQuotedString(data->args, &data->args);
814
 
 
815
 
   /*
816
 
    * Validate the arguments.
817
 
    */
818
 
   if ((NULL == printerName) || (NULL == defaultString)) {
819
 
      err = VIX_E_INVALID_ARG;
820
 
      Debug("Failed to get string args\n");
821
 
      goto abort;
822
 
   }
823
 
 
824
 
   if (!StrUtil_StrToInt(&defaultInt, defaultString)) {
825
 
      err = VIX_E_INVALID_ARG;
826
 
      Debug("Failed to convert int arg\n");
827
 
      goto abort;
828
 
   }
829
 
 
830
 
   Debug("Setting printer to: \"%s\", %ssetting as default\n",
831
 
         printerName, (defaultInt != 0) ? "" : "not ");
832
 
 
833
 
   /* Actually set the printer. */
834
 
   if (!Printer_AddConnection(printerName, &sysError)) {
835
 
      err = VIX_E_FAIL;
836
 
      Debug("Failed to add printer %s : %d %s\n", printerName, sysError,
837
 
            Err_Errno2String(sysError));
838
 
      goto abort;
839
 
   }
840
 
 
841
 
   /* Set this printer as the default if requested. */
842
 
   if (defaultInt != 0) {
843
 
      if (!Win32U_SetDefaultPrinter(printerName)) {
844
 
         /*
845
 
          * We couldn't set this printer as default. Oh well. We'll
846
 
          * still report success or failure based purely on whether
847
 
          * the actual printer add succeeded or not.
848
 
          */
849
 
         Debug("Unable to set \"%s\" as the default printer\n",
850
 
               printerName);
851
 
      }
852
 
   }
853
 
 
854
 
abort:
855
 
   /*
856
 
    * All Foundry tools commands return results that start with a
857
 
    * foundry error and a guest-OS-specific error.
858
 
    */
859
 
   Str_Sprintf(resultBuffer, sizeof resultBuffer, "%"FMT64"d %d", err, sysError);
860
 
   RPCIN_SETRETVALS(data, resultBuffer, TRUE);
861
 
 
862
 
   /*
863
 
    * These were allocated by ToolsDaemonTcloGetQuotedString.
864
 
    */
865
 
   free(printerName);
866
 
   free(defaultString);
867
 
 
868
 
   Debug("<ToolsDaemonTcloSetPrinter\n");
869
 
   return TRUE;
870
 
 
871
 
#else
872
 
   Str_Sprintf(resultBuffer,
873
 
               sizeof resultBuffer,
874
 
               "%d %d 0",
875
 
               VIX_E_OP_NOT_SUPPORTED_ON_GUEST,
876
 
               Err_Errno());
877
 
   RPCIN_SETRETVALS(data, resultBuffer, TRUE);
878
 
   return TRUE;
879
 
#endif
880
 
}
881
779
#endif
882
780
 
883
781
 
1175
1073
    * the guest.
1176
1074
    */
1177
1075
   if (!FoundryToolsDaemon_RegisterOpenUrlCapability()) {
 
1076
      // Unregister Callback to avoid double registration down the line
 
1077
      RpcIn_UnregisterCallback(in, VIX_BACKDOORCOMMAND_OPEN_URL);
1178
1078
      return FALSE;
1179
1079
   }
1180
1080
 
1219
1119
   return TRUE;
1220
1120
}
1221
1121
 
1222
 
 
1223
 
/*
1224
 
 *-----------------------------------------------------------------------------
1225
 
 *
1226
 
 * FoundryToolsDaemon_RegisterSetPrinterCapability --
1227
 
 *
1228
 
 *      Register the Set Printer capability. Sometimes this needs to
1229
 
 *      be done separately from the TCLO callback registration, so we
1230
 
 *      provide it separately here.
1231
 
 *
1232
 
 * Results:
1233
 
 *      TRUE on success
1234
 
 *      FALSE on failure
1235
 
 *
1236
 
 * Side effects:
1237
 
 *      None
1238
 
 *
1239
 
 *-----------------------------------------------------------------------------
1240
 
 */
1241
 
 
1242
 
Bool
1243
 
FoundryToolsDaemon_RegisterSetPrinterCapability(void)
1244
 
{
1245
 
   if (!RpcOut_sendOne(NULL, NULL, "tools.capability.printer_set 1")) {
1246
 
      Debug("Unable to register printer set capability\n");
1247
 
      Debug("<FoundryToolsDaemon_RegisterSetPrinterCapability\n");
1248
 
      return FALSE;
1249
 
   }
1250
 
 
1251
 
   return TRUE;
1252
 
}
1253
 
 
1254
 
 
1255
 
/*
1256
 
 *-----------------------------------------------------------------------------
1257
 
 *
1258
 
 * FoundryToolsDaemon_RegisterSetPrinter --
1259
 
 *
1260
 
 *      Register the Set Printer capability and TCLO handler.
1261
 
 *
1262
 
 * Results:
1263
 
 *      TRUE on success
1264
 
 *      FALSE on failure
1265
 
 *
1266
 
 * Side effects:
1267
 
 *      None
1268
 
 *
1269
 
 *-----------------------------------------------------------------------------
1270
 
 */
1271
 
 
1272
 
Bool
1273
 
FoundryToolsDaemon_RegisterSetPrinter(RpcIn *in) // IN
1274
 
{
1275
 
   /* First, try to load the printer library. */
1276
 
   if (!Printer_Init()) {
1277
 
      Debug("<FoundryToolsDaemon_RegisterSetPrinter\n");
1278
 
      Debug("Unable to load printer library.\n");
1279
 
      return FALSE;
1280
 
   }
1281
 
 
1282
 
   /* Register the TCLO handler. */
1283
 
   RpcIn_RegisterCallbackEx(in,
1284
 
                            VIX_BACKDOORCOMMAND_SET_GUEST_PRINTER,
1285
 
                            ToolsDaemonTcloSetPrinter,
1286
 
                            NULL);
1287
 
   /*
1288
 
    * Inform the VMX that we support setting the guest printer; the UI
1289
 
    * and VMX need to know about this capability in advance (rather than
1290
 
    * simply trying and failing). I've put this here on the theory that
1291
 
    * it's better to have it close to the command that handles the
1292
 
    * actual request than it is to have it near the other capabilities
1293
 
    * registration code, which is in toolsDaemon.c.
1294
 
    *
1295
 
    * Eventually, Foundry might want to have a unified way of
1296
 
    * registering support for only a subset of the foundry commands in
1297
 
    * the guest.
1298
 
    */
1299
 
   if (!FoundryToolsDaemon_RegisterSetPrinterCapability()) {
1300
 
      Debug("<FoundryToolsDaemon_RegisterSetPrinter\n");
1301
 
      return FALSE;
1302
 
   }
1303
 
 
1304
 
   return TRUE;
1305
 
}
1306
 
 
1307
 
 
1308
 
/*
1309
 
 *-----------------------------------------------------------------------------
1310
 
 *
1311
 
 * FoundryToolsDaemon_UnregisterSetPrinter --
1312
 
 *
1313
 
 *      Unregister the "Set Printer" capability.
1314
 
 *
1315
 
 * Results:
1316
 
 *      TRUE on success
1317
 
 *      FALSE on failure
1318
 
 *
1319
 
 * Side effects:
1320
 
 *      None
1321
 
 *
1322
 
 *-----------------------------------------------------------------------------
1323
 
 */
1324
 
 
1325
 
Bool
1326
 
FoundryToolsDaemon_UnregisterSetPrinter(RpcIn *in) // IN
1327
 
{
1328
 
   /*
1329
 
    * RpcIn doesn't have an unregister facility, so all we need to do
1330
 
    * here is unregister the capability.
1331
 
    */
1332
 
 
1333
 
   /*
1334
 
    * Report no longer supporting setting the guest printer.
1335
 
    */
1336
 
   if (!RpcOut_sendOne(NULL, NULL, "tools.capability.printer_set 0")) {
1337
 
      Debug("<FoundryToolsDaemon_UnregisterSetPrinter\n");
1338
 
      Debug("Unable to unregister printer set capability\n");
1339
 
      return FALSE;
1340
 
   }
1341
 
 
1342
 
   /* Cleanup the printer library. */
1343
 
   if (!Printer_Cleanup()) {
1344
 
      /*
1345
 
       * Failed to cleanup, but we still unregistered the command so
1346
 
       * we'll just warn and pretend we succeeded.
1347
 
       */
1348
 
      Debug("Unable to cleanup printer library\n");
1349
 
   }
1350
 
 
1351
 
   return TRUE;
1352
 
}
1353
 
 
1354
1122
#endif
1355
1123
 
1356
 
 
1357
1124
/*
1358
1125
 *-----------------------------------------------------------------------------
1359
1126
 *