File optional-override-os-name.patch of Package open-vm-tools.9224

commit 87593b29e5c337141be65e4430fb95a4f1741afb
Author: Oliver Kurth <okurth@vmware.com>
Date:   Fri Oct 5 13:55:27 2018 -0700

    Optional override for short and long OS names sent from Tools
    
    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

diff --git a/open-vm-tools/lib/include/conf.h b/open-vm-tools/lib/include/conf.h
index af685348..f9698c18 100644
--- a/open-vm-tools/lib/include/conf.h
+++ b/open-vm-tools/lib/include/conf.h
@@ -169,6 +169,32 @@
  */
 
 
+/*
+ ******************************************************************************
+ * 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.
diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
index 2cdad508..f31eddf0 100644
--- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
+++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
@@ -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 =
openSUSE Build Service is sponsored by