From: Katy Feng Date: Fri, 23 Dec 2022 00:25:49 +0000 (-0800) Subject: Enhance the guest identification code for Linux X-Git-Tag: stable-12.2.0~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e85f51de2849566e8dd08f035474bfc626a17d8d;p=thirdparty%2Fopen-vm-tools.git Enhance the guest identification code for Linux The Linux guest identification code is enhanced to return two additional fields (when a distro makes them available): 1) The VERSION field This field sometimes contains additional information not found in other fields. For instance, on SLES, this provides the patch level information. 2) The CPE_NAME field This is the NIST Common Platform Enumeration Specification string. If present, this may provide information in a standardized form. --- diff --git a/open-vm-tools/lib/misc/hostinfoInt.h b/open-vm-tools/lib/misc/hostinfoInt.h index a3bd79bc6..1ca389edf 100644 --- a/open-vm-tools/lib/misc/hostinfoInt.h +++ b/open-vm-tools/lib/misc/hostinfoInt.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2009-2021 VMware, Inc. All rights reserved. + * Copyright (C) 2009-2022 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 @@ -43,6 +43,8 @@ typedef enum { ARCH, BITNESS, BUILD_NUMBER, + CPE_STRING, + DISTRO_ADDL_VERSION, DISTRO_NAME, DISTRO_VERSION, FAMILY_NAME, diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index 72fdd18b4..3f105a4fc 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -178,6 +178,8 @@ static const DistroNameScan osReleaseFields[] = { { "NAME=", "NAME=%s" }, { "VERSION_ID=", "VERSION_ID=%s" }, { "BUILD_ID=", "BUILD_ID=%s" }, + { "VERSION=", "VERSION=%s" }, + { "CPE_NAME=", "CPE_NAME=%s" }, // NIST CPE specification { NULL, NULL }, }; @@ -247,21 +249,34 @@ static const DistroInfo distroArray[] = { }; #endif -/* Must be sorted. Keep in the same ordering as DetailedDataFieldType */ +/* + * Any data obtained about the distro is obtained - UNMODIFIED - from the + * standardized (i.e. LSB, os-release) disto description files. Under no + * circumstances is code specific to a distro allowed or used. If the data + * specified by a distro isn't useful, talk to the disto, not VMware. + * + * The fields from the standardized distro description files used may be + * found above (i.e. lsbFields, osReleaseFields). + * + * Must be sorted. Keep in the same ordering as DetailedDataFieldType + */ + DetailedDataField detailedDataFields[] = { #if defined(VM_ARM_ANY) - { "architecture", "Arm" }, // Arm + { "architecture", "Arm" }, // Arm #else - { "architecture", "X86" }, // Intel/X86 + { "architecture", "X86" }, // Intel/X86 #endif - { "bitness", "" }, // "32" or "64" - { "buildNumber", "" }, // Present for MacOS and some Linux distros. - { "distroName", "" }, // Defaults to uname -s - { "distroVersion", "" }, // Present for MacOS. - { "familyName", "" }, // Defaults to uname -s - { "kernelVersion", "" }, // Defaults to uname -r - { "prettyName", "" }, // Present for MacOS. - { NULL, "" }, // MUST BE LAST + { "bitness", "" }, // "32" or "64" + { "buildNumber", "" }, // When available + { "cpeString", "" }, // When available + { "distroAddlVersion", "" }, // When available + { "distroName", "" }, // Defaults to uname -s + { "distroVersion", "" }, // When available + { "familyName", "" }, // Defaults to uname -s + { "kernelVersion", "" }, // Defaults to uname -r + { "prettyName", "" }, // When available + { NULL, "" }, // MUST BE LAST }; #if defined __ANDROID__ || defined __aarch64__ @@ -1990,6 +2005,17 @@ HostinfoBestScore(char *distro, // OUT: sizeof detailedDataFields[BUILD_NUMBER].value); } + if (osReleaseData[4] != NULL) { + Str_Strcpy(detailedDataFields[DISTRO_ADDL_VERSION].value, + osReleaseData[4], + sizeof detailedDataFields[DISTRO_ADDL_VERSION].value); + } + + if (osReleaseData[5] != NULL) { + Str_Strcpy(detailedDataFields[CPE_STRING].value, osReleaseData[5], + sizeof detailedDataFields[CPE_STRING].value); + } + if (osReleaseData[fields] != NULL) { Str_Strcpy(distro, osReleaseData[fields], distroSize); }