]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Don't crash tools if backdoor is disabled.
authorVMware, Inc <>
Mon, 20 Sep 2010 18:03:04 +0000 (11:03 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 20 Sep 2010 18:03:04 +0000 (11:03 -0700)
Four fixes:

. the provider list is empty when we don't detect the backdoor, so need
to check for NULL when cleaning it up.

. check if backdoor is available before trying to execute a command when
invoking "vmtoolsd --cmd".

. unity plugin shouldn't initialize itself if rpc channel is not available.

. ditto for dnd.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/services/plugins/dndcp/dndcp.cpp
open-vm-tools/services/plugins/unity/unityPluginEntry.cpp
open-vm-tools/services/vmtoolsd/cmdLine.c
open-vm-tools/services/vmtoolsd/pluginMgr.c

index 346de25e6a90b27d5ebb4ff2038c9239ae7b1c75..b72191154da1bfa758bae927abce06815b906707 100644 (file)
@@ -173,29 +173,33 @@ ToolsOnLoad(ToolsAppCtx *ctx)
       NULL
    };
 
-   ToolsPluginSignalCb sigs[] = {
-      { TOOLS_CORE_SIG_CAPABILITIES, (void *) DnDCPCapabilities, NULL },
-      { TOOLS_CORE_SIG_RESET, (void *) DnDCPReset, NULL },
-      { TOOLS_CORE_SIG_SET_OPTION, (void *) DnDCPSetOption, NULL },
-      { TOOLS_CORE_SIG_SHUTDOWN, (void *) DnDCPShutdown, NULL }
-   };
-
-   ToolsAppReg regs[] = {
-      { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) }
-   };
-
-   /*
-    * DnD/CP Initialization here.
-    */
-
-   CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
-   if (p) {
-      p->Init(ctx);
-      p->PointerInit();
+   if (ctx->rpc != NULL) {
+      ToolsPluginSignalCb sigs[] = {
+         { TOOLS_CORE_SIG_CAPABILITIES, (void *) DnDCPCapabilities, NULL },
+         { TOOLS_CORE_SIG_RESET, (void *) DnDCPReset, NULL },
+         { TOOLS_CORE_SIG_SET_OPTION, (void *) DnDCPSetOption, NULL },
+         { TOOLS_CORE_SIG_SHUTDOWN, (void *) DnDCPShutdown, NULL }
+      };
+
+      ToolsAppReg regs[] = {
+         { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) }
+      };
+
+      /*
+       * DnD/CP Initialization here.
+       */
+
+      CopyPasteDnDWrapper *p = CopyPasteDnDWrapper::GetInstance();
+      if (p) {
+         p->Init(ctx);
+         p->PointerInit();
+      }
+
+      regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs));
+      return &regData;
    }
 
-   regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs));
-   return &regData;
+   return NULL;
 }
 
 }
index 0c7d3cd4adb11bc94d2b224d34e04bd05d767bc9..5806fd015aa870fee893b2fc8ad16c416f1191ca 100644 (file)
@@ -175,36 +175,40 @@ ToolsOnLoad(ToolsAppCtx *ctx)
       NULL
    };
 
-   ToolsPluginSignalCb sigs[] = {
-      { TOOLS_CORE_SIG_RESET, (void *) UnityPluginReset, &regData },
-      { TOOLS_CORE_SIG_SHUTDOWN, (void *) UnityPluginShutdown, &regData },
-      { TOOLS_CORE_SIG_CAPABILITIES, (void *) UnityPluginCapabilities, &regData },
-      { TOOLS_CORE_SIG_SET_OPTION, (void *) UnityPluginSetOption, &regData },
-   };
+   if (ctx->rpc != NULL) {
+      ToolsPluginSignalCb sigs[] = {
+         { TOOLS_CORE_SIG_RESET, (void *) UnityPluginReset, &regData },
+         { TOOLS_CORE_SIG_SHUTDOWN, (void *) UnityPluginShutdown, &regData },
+         { TOOLS_CORE_SIG_CAPABILITIES, (void *) UnityPluginCapabilities, &regData },
+         { TOOLS_CORE_SIG_SET_OPTION, (void *) UnityPluginSetOption, &regData },
+      };
 
-   ToolsPlugin *pluginInstance = NULL;
+      ToolsPlugin *pluginInstance = NULL;
 
 #if WIN32
-   pluginInstance = new UnityPluginWin32(ctx);
+      pluginInstance = new UnityPluginWin32(ctx);
 #else // Linux
-   pluginInstance = new UnityPlugin(ctx);
+      pluginInstance = new UnityPlugin(ctx);
 #endif
 
-   if (!pluginInstance) {
-      // There's nothing we can do if we can't construct the plugin instance
-      return NULL;
-   }
-   regData._private = pluginInstance;
+      if (!pluginInstance) {
+         // There's nothing we can do if we can't construct the plugin instance
+         return NULL;
+      }
+      regData._private = pluginInstance;
 
-   std::vector<RpcChannelCallback> rpcs = pluginInstance->GetRpcCallbackList();
+      std::vector<RpcChannelCallback> rpcs = pluginInstance->GetRpcCallbackList();
 
-   ToolsAppReg regs[] = {
-      { TOOLS_APP_GUESTRPC, VMTools_WrapArray(&rpcs[0], sizeof rpcs[0], rpcs.size()) },
-      { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) }
-   };
+      ToolsAppReg regs[] = {
+         { TOOLS_APP_GUESTRPC, VMTools_WrapArray(&rpcs[0], sizeof rpcs[0], rpcs.size()) },
+         { TOOLS_APP_SIGNALS, VMTools_WrapArray(sigs, sizeof *sigs, ARRAYSIZE(sigs)) }
+      };
 
-   regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs));
+      regData.regs = VMTools_WrapArray(regs, sizeof *regs, ARRAYSIZE(regs));
+
+      return &regData;
+   }
 
-   return &regData;
+   return NULL;
 }
 
index 655579c5e77c05e11ca0a22ee03be6d10a33278a..ee24e3aab3f8f1161b16708c2103450a563f72d3 100644 (file)
@@ -37,6 +37,7 @@
 #include "conf.h"
 #include "rpcout.h"
 #include "str.h"
+#include "vmcheck.h"
 #include "vmtoolsd_version.h"
 #include "vmware/tools/utils.h"
 #include "vmware/tools/i18n.h"
@@ -60,19 +61,26 @@ ToolsCoreRunCommand(const gchar *option,
                     gpointer data,
                     GError **error)
 {
-   char *result = NULL;
-   Bool status = FALSE;
+#if defined(_WIN32)
+   VMTools_AttachConsole();
+#endif
+   if (VmCheck_IsVirtualWorld()) {
+      char *result = NULL;
+      Bool status = FALSE;
 
-   status = RpcOut_sendOne(&result, NULL, "%s", value);
+      status = RpcOut_sendOne(&result, NULL, "%s", value);
 
-   if (!status) {
-      g_printerr("%s\n", result ? result : "NULL");
-   } else {
-      g_print("%s\n", result);
-   }
+      if (!status) {
+         g_printerr("%s\n", result ? result : "NULL");
+      } else {
+         g_print("%s\n", result);
+      }
 
-   vm_free(result);
-   exit(status ? 0 : 1);
+      vm_free(result);
+      exit(status ? 0 : 1);
+   }
+   g_printerr(SU_(cmdline.rpcerror, "Unable to send command to VMware hypervisor.\n"));
+   exit(1);
 }
 
 
index 7b2a0aecadd10b99f3ac0a5888d9bf7cc764f1d2..68c68ca8edbcb56f12a03c75af726d9cc9438094 100644 (file)
@@ -736,7 +736,7 @@ ToolsCore_UnloadPlugins(ToolsServiceState *state)
     * Stop all app providers, and free the memory we allocated for the two
     * internal app providers.
     */
-   for (i = 0; i < state->providers->len; i++) {
+   for (i = 0; state->providers != NULL && i < state->providers->len; i++) {
        ToolsAppProviderReg *preg = &g_array_index(state->providers,
                                                   ToolsAppProviderReg,
                                                   i);
@@ -774,8 +774,10 @@ ToolsCore_UnloadPlugins(ToolsServiceState *state)
       g_free(plugin);
    }
 
-   g_array_free(state->providers, TRUE);
-   state->providers = NULL;
+   if (state->providers != NULL) {
+      g_array_free(state->providers, TRUE);
+      state->providers = NULL;
+   }
 
    g_ptr_array_free(state->plugins, TRUE);
    state->plugins = NULL;