From: Oliver Kurth Date: Tue, 21 Apr 2020 21:43:45 +0000 (-0700) Subject: Common source file changes not applicable to open-vm-tools. X-Git-Tag: stable-11.2.0~248 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f9bc344328dd144c5539dd44fe1508d0f7b8b6f;p=thirdparty%2Fopen-vm-tools.git Common source file changes not applicable to open-vm-tools. Tools Windows: test plugin DLLs are the correct version --- diff --git a/open-vm-tools/services/vmtoolsd/mainLoop.c b/open-vm-tools/services/vmtoolsd/mainLoop.c index 941452acb..f864742cb 100644 --- a/open-vm-tools/services/vmtoolsd/mainLoop.c +++ b/open-vm-tools/services/vmtoolsd/mainLoop.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -45,6 +45,7 @@ #include "vmware/tools/utils.h" #include "vmware/tools/vmbackup.h" #if defined(_WIN32) +# include "codeset.h" # include "windowsu.h" #else # include "posix.h" @@ -676,6 +677,98 @@ ToolCoreGetLastErrorMsg(DWORD error) return msg; } + +/** + * Check the version for a file using GetFileVersionInfo method + * + * @param[in] pluginPath plugin path name. + * @param[in] checkBuildNumber inlcude check for build number. + * + * @return TRUE if plugin version matches the tools version, + * FALSE in case of a mismatch. + */ + +gboolean +ToolsCore_CheckModuleVersion(const gchar *pluginPath, + gboolean checkBuildNumber) +{ + WCHAR *pluginPathW = NULL; + void *buffer = NULL; + DWORD bufferLen = 0; + DWORD dummy = 0; + VS_FIXEDFILEINFO *fixedFileInfo = NULL; + UINT fixedFileInfoLen = 0; + ToolsVersionComponents toolsVer = {0}; + uint32 pluginVersion[4] = {0}; + gboolean result = FALSE; + static const uint32 toolsBuildNumber = PRODUCT_BUILD_NUMBER_NUMERIC; + + if (!CodeSet_Utf8ToUtf16le(pluginPath, + strlen(pluginPath), + (char **)&pluginPathW, + NULL)) { + g_debug("%s: Could not convert file %s to UTF-16\n", + __FUNCTION__, pluginPath); + goto exit; + } + + bufferLen = GetFileVersionInfoSizeW(pluginPathW, &dummy); + if (bufferLen == 0) { + g_debug("%s: Failed to get info size from %s %u", + __FUNCTION__, pluginPath, GetLastError()); + goto exit; + } + + buffer = g_malloc(bufferLen); + if (!buffer) { + g_debug("%s: malloc failed for %s", __FUNCTION__, pluginPath); + goto exit; + } + + if (!GetFileVersionInfoW(pluginPathW, 0, bufferLen, buffer)) { + g_debug("%s: Failed to get info size from %s %u", + __FUNCTION__, pluginPath, GetLastError()); + goto exit; + } + + if (!VerQueryValueW(buffer, L"\\", (void **)&fixedFileInfo, &fixedFileInfoLen)) { + g_debug("%s: Failed to get fixed file info from %s %u", + __FUNCTION__, pluginPath, GetLastError()); + goto exit; + } + + if (fixedFileInfoLen < sizeof *fixedFileInfo) { + g_debug("%s: Fixed file info from %s is too short: %d", + __FUNCTION__, pluginPath, fixedFileInfoLen); + goto exit; + } + + /* Using Product version. File version is also available. */ + pluginVersion[0] = (uint16)(fixedFileInfo->dwProductVersionMS >> 16); + pluginVersion[1] = (uint16)(fixedFileInfo->dwProductVersionMS >> 0); + pluginVersion[2] = (uint16)(fixedFileInfo->dwProductVersionLS >> 16); + pluginVersion[3] = (uint16)(fixedFileInfo->dwProductVersionLS >> 0); + + TOOLS_VERSION_UINT_TO_COMPONENTS(TOOLS_VERSION_CURRENT, &toolsVer); + + result = (pluginVersion[0] == toolsVer.major && + pluginVersion[1] == toolsVer.minor && + pluginVersion[2] == toolsVer.base); + + if (result && checkBuildNumber) { + result = pluginVersion[3] == toolsBuildNumber; + } + +exit: + if (!result) { + g_warning("%s: Failed or no version check %s : %u.%u.%u.%u", + __FUNCTION__, pluginPath, pluginVersion[0], pluginVersion[1], + pluginVersion[2], pluginVersion[3]); + } + g_free(buffer); + free(pluginPathW); + return result; +} #endif diff --git a/open-vm-tools/services/vmtoolsd/pluginMgr.c b/open-vm-tools/services/vmtoolsd/pluginMgr.c index a7338db90..53b91f7aa 100644 --- a/open-vm-tools/services/vmtoolsd/pluginMgr.c +++ b/open-vm-tools/services/vmtoolsd/pluginMgr.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -554,6 +554,21 @@ ToolsCoreLoadDirectory(ToolsAppCtx *ctx, } #endif +#ifdef _WIN32 + /* + * Only load compatible versions of a plugin which requires that a plugin + * and tools product versions match. + * Using FALSE compares the major.minor.base components of the version. + * Version format is: "major.minor.base.buildnumber" e.g. "11.2.0.19761" + * Use TRUE for a more strict check to verify all four version components. + */ + if (!ToolsCore_CheckModuleVersion(path, FALSE)) { + g_warning("%s: Version check of plugin '%s' failed: not loaded.\n", + __FUNCTION__, path); + goto next; + } +#endif + module = g_module_open(path, G_MODULE_BIND_LOCAL); #ifdef USE_APPLOADER if (module == NULL) { diff --git a/open-vm-tools/services/vmtoolsd/toolsCoreInt.h b/open-vm-tools/services/vmtoolsd/toolsCoreInt.h index b26a0d0cd..06c990202 100644 --- a/open-vm-tools/services/vmtoolsd/toolsCoreInt.h +++ b/open-vm-tools/services/vmtoolsd/toolsCoreInt.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2008-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2008-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -150,6 +150,11 @@ void ToolsCore_SetCapabilities(RpcChannel *chan, GArray *caps, gboolean set); +#if defined(_WIN32) +gboolean +ToolsCore_CheckModuleVersion(const gchar *pluginPath, + gboolean checkBuildNumber); +#endif void ToolsCore_UnloadPlugins(ToolsServiceState *state);