]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Optional override for short and long OS names sent from Tools
authorOliver Kurth <okurth@vmware.com>
Fri, 5 Oct 2018 20:55:27 +0000 (13:55 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 5 Oct 2018 20:55:27 +0000 (13:55 -0700)
Added support for customers to override the returned long and short OS
names through the tools config file. If the setting is present, then names
gathered by hostinfo will be ignored. The user is responsible for setting
the appropriate names.

The override will be ignored if the short-name setting is not present in
tools.conf.

An empty string will be sent for the long OS name if only the short-name
setting is present.

Appropriate warning msg will be generated in both cases.

Example of the conf setting:

[guestosinfo]
short-name = centos6-64
long-name = some long name

open-vm-tools/lib/include/conf.h
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c

index af685348750d58a15709424dfabfaaf92933c1ad..f9698c18991aa5cfd466d5823d9171ec43d793b7 100644 (file)
  */
 
 
+/*
+ ******************************************************************************
+ * BEGIN GuestOSInfo goodies.
+ */
+
+/**
+ * Defines the string used for the GuestOSInfo config file group.
+ */
+#define CONFGROUPNAME_GUESTOSINFO "guestosinfo"
+
+/**
+ * Lets users override the short OS name sent by Tools.
+ */
+#define CONFNAME_GUESTOSINFO_SHORTNAME "short-name"
+
+/**
+ * Lets users override the long OS name sent by Tools.
+ */
+#define CONFNAME_GUESTOSINFO_LONGNAME "long-name"
+
+/*
+ * END GuestOSInfo goodies.
+ ******************************************************************************
+ */
+
+
 /*
  ******************************************************************************
  * BEGIN Unity goodies.
index 2cdad508c434f611db29adb8265cd7ebe333e595..f31eddf0d0f63177dfd1749c1dccd3d6499ce794 100644 (file)
@@ -483,6 +483,8 @@ GuestInfoGather(gpointer data)
    Bool lowPriorityChanged;
    int maxIPv4RoutesToGather;
    int maxIPv6RoutesToGather;
+   gchar *osNameOverride;
+   gchar *osNameFullOverride;
 
    g_debug("Entered guest info gather.\n");
 
@@ -498,26 +500,67 @@ GuestInfoGather(gpointer data)
       g_warning("Failed to update VMDB with tools version.\n");
    }
 
-   /* Gather all the relevant guest information. */
-   osString = Hostinfo_GetOSName();
-   if (osString == NULL) {
-      g_warning("Failed to get OS info.\n");
+   /* Check for manual override of guest information in the config file */
+   osNameOverride = VMTools_ConfigGetString(ctx->config,
+                                            CONFGROUPNAME_GUESTOSINFO,
+                                            CONFNAME_GUESTOSINFO_SHORTNAME,
+                                            NULL);
+   osNameFullOverride = VMTools_ConfigGetString(ctx->config,
+                                                CONFGROUPNAME_GUESTOSINFO,
+                                                CONFNAME_GUESTOSINFO_LONGNAME,
+                                                NULL);
+   /* If only the OS Full Name is provided, continue as normal, but emit
+    * warning. */
+   if (osNameOverride == NULL && osNameFullOverride != NULL) {
+      g_warning("Ignoring " CONFNAME_GUESTOSINFO_LONGNAME " override.\n");
+      g_warning("To use the GOS name override, "
+                CONFNAME_GUESTOSINFO_SHORTNAME " must be present in the "
+                "tools.conf file.\n");
+      g_free(osNameFullOverride);
+   }
+
+   /* Only use override if at least the short OS name is provided */
+   if (osNameOverride == NULL) {
+      /* Gather all the relevant guest information. */
+      osString = Hostinfo_GetOSName();
+      if (osString == NULL) {
+         g_warning("Failed to get OS info.\n");
+      } else {
+         if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME_FULL, osString, 0)) {
+            g_warning("Failed to update VMDB\n");
+         }
+      }
+      free(osString);
+
+      osString = Hostinfo_GetOSGuestString();
+      if (osString == NULL) {
+         g_warning("Failed to get OS info.\n");
+      } else {
+         if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME, osString, 0)) {
+            g_warning("Failed to update VMDB\n");
+         }
+      }
+      free(osString);
    } else {
-      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME_FULL, osString, 0)) {
+      /* Use osName and osNameFull provided in config file */
+      if (osNameFullOverride == NULL) {
+         g_warning(CONFNAME_GUESTOSINFO_LONGNAME " was not set in "
+                   "tools.conf, using empty string.\n");
+      }
+      if (!GuestInfoUpdateVmdb(ctx,
+                               INFO_OS_NAME_FULL,
+                               (osNameFullOverride == NULL) ? "" : osNameFullOverride,
+                               0)) {
          g_warning("Failed to update VMDB\n");
       }
-   }
-   free(osString);
+      g_free(osNameFullOverride);
 
-   osString = Hostinfo_GetOSGuestString();
-   if (osString == NULL) {
-      g_warning("Failed to get OS info.\n");
-   } else {
-      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME, osString, 0)) {
+      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME, osNameOverride, 0)) {
          g_warning("Failed to update VMDB\n");
       }
+      g_free(osNameOverride);
+      g_debug("Using values in tools.conf to override OS Name.\n");
    }
-   free(osString);
 
 #if !defined(USERWORLD)
    disableQueryDiskInfo =