]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Enhance the guest identification code for Linux
authorKaty Feng <fkaty@vmware.com>
Fri, 23 Dec 2022 00:25:49 +0000 (16:25 -0800)
committerKaty Feng <fkaty@vmware.com>
Fri, 23 Dec 2022 00:25:49 +0000 (16:25 -0800)
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.

open-vm-tools/lib/misc/hostinfoInt.h
open-vm-tools/lib/misc/hostinfoPosix.c

index a3bd79bc6adfa7ab56ef0152c8bd93c3953ec597..1ca389edf374e4c0346041aa6688bf06c1e2e1d4 100644 (file)
@@ -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,
index 72fdd18b4d8763b829c7d82fcb599d9d1d4e107b..3f105a4fcebbfb0b5974cc97a57e8687a4101bbf 100644 (file)
@@ -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);
       }