From fe7e5654fbb69baec6c8e6de5c367346580934bc Mon Sep 17 00:00:00 2001 From: Katy Feng Date: Thu, 5 Oct 2023 10:35:27 -0700 Subject: [PATCH] Linux guest identification: Correct the misidentification of Big Cloud Enterprise Linux. --- open-vm-tools/lib/misc/hostinfoPosix.c | 221 ++++++++++++++----------- 1 file changed, 126 insertions(+), 95 deletions(-) diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index dd3c16898..8b0fb629d 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -911,6 +911,101 @@ HostinfoArchString(void) } +/* + *----------------------------------------------------------------------------- + * + * HostinfoDefaultLinux -- + * + * Build and return generic data about the Linux disto. Only return what + * has been required - short description (i.e. guestOS string), long + * description (nice looking string). + * + * Return value: + * None + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static void +HostinfoDefaultLinux(char *distro, // OUT/OPT: + size_t distroSize, // IN: + char *distroShort, // OUT/OPT: + size_t distroShortSize) // IN: +{ + char generic[128]; + const char *distroOut = NULL; + const char *distroShortOut = NULL; + int majorVersion = Hostinfo_OSVersion(0); + int minorVersion = Hostinfo_OSVersion(1); + + switch (majorVersion) { + case 1: + distroOut = STR_OS_OTHER_FULL; + distroShortOut = STR_OS_OTHER; + break; + + case 2: + if (minorVersion < 4) { + distroOut = STR_OS_OTHER_FULL; + distroShortOut = STR_OS_OTHER; + } else if (minorVersion < 6) { + distroOut = STR_OS_OTHER_24_FULL; + distroShortOut = STR_OS_OTHER_24; + } else { + distroOut = STR_OS_OTHER_26_FULL; + distroShortOut = STR_OS_OTHER_26; + } + + break; + + case 3: + distroOut = STR_OS_OTHER_3X_FULL; + distroShortOut = STR_OS_OTHER_3X; + break; + + case 4: + distroOut = STR_OS_OTHER_4X_FULL; + distroShortOut = STR_OS_OTHER_4X; + break; + + case 5: + distroOut = STR_OS_OTHER_5X_FULL; + distroShortOut = STR_OS_OTHER_5X; + break; + + case 6: + distroOut = STR_OS_OTHER_6X_FULL; + distroShortOut = STR_OS_OTHER_6X; + break; + + default: + /* + * Anything newer than this code explicitly handles returns the + * "highest" known short description and a dynamically created, + * appropriate long description. + */ + + Str_Sprintf(generic, sizeof generic, "Other Linux %d.%d kernel", + majorVersion, minorVersion); + distroOut = generic; + distroShortOut = STR_OS_OTHER_5X; + } + + if (distro != NULL) { + ASSERT(distroOut != NULL); + Str_Strcpy(distro, distroOut, distroSize); + } + + if (distroShort != NULL) { + ASSERT(distroShortOut != NULL); + Str_Strcpy(distroShort, distroShortOut, distroShortSize); + } +} + + /* *----------------------------------------------------------------------------- * @@ -1013,6 +1108,35 @@ HostinfoSetAsianuxShortName(const ShortNameSet *entry, // IN: Unused } +/* + *----------------------------------------------------------------------------- + * + * HostinfoBCSetShortName -- + * + * Handle Big Cloud Enterprise Linux. + * + * Return value: + * TRUE success + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static Bool +HostinfoBCSetShortName(const ShortNameSet *entry, // IN: + int version, // IN: + const char *distroLower, // IN: + char *distroShort, // OUT: + int distroShortSize) // IN: +{ + HostinfoDefaultLinux(NULL, 0, distroShort, distroShortSize); + + return TRUE; +} + + /* *----------------------------------------------------------------------------- * @@ -1279,6 +1403,8 @@ static const ShortNameSet shortNameArray[] = { { "arklinux", STR_OS_ARKLINUX, HostinfoGenericSetShortName }, { "asianux", NULL, HostinfoSetAsianuxShortName }, { "aurox", STR_OS_AUROX, HostinfoGenericSetShortName }, +{ "bigcloud", NULL, HostinfoBCSetShortName }, +/* Big Cloud must come before Red Hat Entry */ { "black cat", STR_OS_BLACKCAT, HostinfoGenericSetShortName }, { "centos", NULL, HostinfoSetCentosShortName }, { "cobalt", STR_OS_COBALT, HostinfoGenericSetShortName }, @@ -1873,101 +1999,6 @@ HostinfoLsb(char ***args) // OUT: } -/* - *----------------------------------------------------------------------------- - * - * HostinfoDefaultLinux -- - * - * Build and return generic data about the Linux disto. Only return what - * has been required - short description (i.e. guestOS string), long - * description (nice looking string). - * - * Return value: - * None - * - * Side effects: - * None - * - *----------------------------------------------------------------------------- - */ - -static void -HostinfoDefaultLinux(char *distro, // OUT/OPT: - size_t distroSize, // IN: - char *distroShort, // OUT/OPT: - size_t distroShortSize) // IN: -{ - char generic[128]; - const char *distroOut = NULL; - const char *distroShortOut = NULL; - int majorVersion = Hostinfo_OSVersion(0); - int minorVersion = Hostinfo_OSVersion(1); - - switch (majorVersion) { - case 1: - distroOut = STR_OS_OTHER_FULL; - distroShortOut = STR_OS_OTHER; - break; - - case 2: - if (minorVersion < 4) { - distroOut = STR_OS_OTHER_FULL; - distroShortOut = STR_OS_OTHER; - } else if (minorVersion < 6) { - distroOut = STR_OS_OTHER_24_FULL; - distroShortOut = STR_OS_OTHER_24; - } else { - distroOut = STR_OS_OTHER_26_FULL; - distroShortOut = STR_OS_OTHER_26; - } - - break; - - case 3: - distroOut = STR_OS_OTHER_3X_FULL; - distroShortOut = STR_OS_OTHER_3X; - break; - - case 4: - distroOut = STR_OS_OTHER_4X_FULL; - distroShortOut = STR_OS_OTHER_4X; - break; - - case 5: - distroOut = STR_OS_OTHER_5X_FULL; - distroShortOut = STR_OS_OTHER_5X; - break; - - case 6: - distroOut = STR_OS_OTHER_6X_FULL; - distroShortOut = STR_OS_OTHER_6X; - break; - - default: - /* - * Anything newer than this code explicitly handles returns the - * "highest" known short description and a dynamically created, - * appropriate long description. - */ - - Str_Sprintf(generic, sizeof generic, "Other Linux %d.%d kernel", - majorVersion, minorVersion); - distroOut = generic; - distroShortOut = STR_OS_OTHER_5X; - } - - if (distro != NULL) { - ASSERT(distroOut != NULL); - Str_Strcpy(distro, distroOut, distroSize); - } - - if (distroShort != NULL) { - ASSERT(distroShortOut != NULL); - Str_Strcpy(distroShort, distroShortOut, distroShortSize); - } -} - - /* *----------------------------------------------------------------------------- * -- 2.47.3