]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add WarningToHost() and WarningToGuest() functions
authorOliver Kurth <okurth@vmware.com>
Wed, 16 Jan 2019 22:53:06 +0000 (14:53 -0800)
committerOliver Kurth <okurth@vmware.com>
Wed, 16 Jan 2019 22:53:06 +0000 (14:53 -0800)
This change is needed to address the privacy and security changes that
are required so that vmware library warnings can be forwarded to the
host side selectively.

For instance, if a warning message is sent to VMX, the user name must be
stripped from the message.

open-vm-tools/lib/include/logToHost.h [new file with mode: 0644]
open-vm-tools/lib/procMgr/procMgrPosix.c
open-vm-tools/libvmtools/vmtoolsLog.c

diff --git a/open-vm-tools/lib/include/logToHost.h b/open-vm-tools/lib/include/logToHost.h
new file mode 100644 (file)
index 0000000..2cf4b50
--- /dev/null
@@ -0,0 +1,32 @@
+/*********************************************************
+ * Copyright (C) 2018 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
+ * by the Free Software Foundation version 2.1 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
+ *
+ *********************************************************/
+
+/*
+ * logToHost.h --
+ *
+ *    Log function prototypes to discretionarily direct log to the host or the
+ *    guest.
+ */
+
+#ifndef __LOG_TO_HOST_H__
+#define __LOG_TO_HOST_H__
+
+void WarningToGuest(const char *fmt, ...);
+void WarningToHost(const char *fmt, ...);
+
+#endif /* __LOG_TO_HOST_H__ */
index 3ff98eb33a1eacbde5bd64c366358c4686ac575e..e492f9a9626afb2f863e4b9b4e404d4ffa047b4e 100644 (file)
@@ -80,6 +80,7 @@
 #include "strutil.h"
 #include "codeset.h"
 #include "unicode.h"
+#include "logToHost.h"
 
 #ifdef USERWORLD
 #include <vm_basic_types.h>
@@ -87,6 +88,7 @@
 #include <vmkusercompat.h>
 #endif
 
+
 /*
  * All signals that:
  * . Can terminate the process
@@ -2238,13 +2240,15 @@ ProcMgr_ImpersonateUserStart(const char *user,  // IN: UTF-8 encoded user name
    ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid);
 #endif
    if (ret < 0) {
-      Warning("Failed to set gid for user %s\n", user);
+      WarningToGuest("Failed to set gid for user %s\n", user);
+      WarningToHost("Failed to set gid\n");
       return FALSE;
    }
 #ifndef USERWORLD
    ret = initgroups(ppw->pw_name, ppw->pw_gid);
    if (ret < 0) {
-      Warning("Failed to initgroups() for user %s\n", user);
+      WarningToGuest("Failed to initgroups() for user %s\n", user);
+      WarningToHost("Failed to initgroups()\n");
       goto failure;
    }
 #endif
@@ -2257,7 +2261,8 @@ ProcMgr_ImpersonateUserStart(const char *user,  // IN: UTF-8 encoded user name
    ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
 #endif
    if (ret < 0) {
-      Warning("Failed to set uid for user %s\n", user);
+      WarningToGuest("Failed to set uid for user %s\n", user);
+      WarningToHost("Failed to set uid\n");
       goto failure;
    }
 
index 478f7d1ffc2e48eb1b2ab0e330ec51b40e7c4b34..d5d3fab2cf5dd14d08232e75a7779653de56c1b7 100644 (file)
@@ -57,6 +57,7 @@
 #include "vmware/tools/guestrpc.h"
 #include "vmware/guestrpc/tclodefs.h"
 #include "err.h"
+#include "logToHost.h"
 
 #define LOGGING_GROUP         "logging"
 
@@ -203,6 +204,11 @@ static void VmxGuestLog(const gchar *domain,
                         GLogLevelFlags level,
                         const gchar *message);
 void Debug(const char *fmt, ...);
+static void LogWhereLevelV(LogWhere where,
+                           GLogLevelFlags level,
+                           const gchar *domain,
+                           const gchar *fmt,
+                           va_list args);
 
 /* Internal functions. */
 
@@ -2260,6 +2266,96 @@ Warning(const char *fmt, ...)
 }
 
 
+/*
+ *******************************************************************************
+ * VmwareLogWrapper --                                                    */ /**
+ *
+ * Generic wrapper for VMware log functions to directly log to either guest
+ * or host.
+ *
+ * @param[in]  where    Log to host or guest.
+ * @param[in]  level    Log level.
+ * @param[in]  fmt      Message format.
+ * @param[in]  args     Message arguments.
+ *
+ *******************************************************************************
+ */
+
+static void
+VmwareLogWrapper(LogWhere where,
+                 GLogLevelFlags level,
+                 const char *fmt,
+                 va_list args)
+{
+   if (!gLogInitialized && !IS_FATAL(level)) {
+      /*
+       * Avoid logging without initialization because
+       * it leads to spamming of the console output.
+       * Fatal messages are exception.
+       */
+      return;
+   }
+
+   VMTools_AcquireLogStateLock();
+
+   LogWhereLevelV(where, level, gLogDomain, fmt, args);
+
+   VMTools_ReleaseLogStateLock();
+}
+
+
+/*
+ *******************************************************************************
+ * WarningToHost --                                                       */ /**
+ *
+ * Logs a message at the host side using the G_LOG_LEVEL_WARNING level
+ *
+ * @param[in] fmt Log message format.
+ *
+ *******************************************************************************
+ */
+
+void
+WarningToHost(const char *fmt, ...)
+{
+   va_list args;
+   va_start(args, fmt);
+   if (gGuestSDKMode) {
+      GuestSDK_Warning(fmt, args);
+   } else {
+      WITH_ERRNO(err,
+         VmwareLogWrapper(TO_HOST, G_LOG_LEVEL_WARNING, fmt, args));
+   }
+   va_end(args);
+}
+
+
+/*
+ *******************************************************************************
+ * WarningToGuest --                                                      */ /**
+ *
+ * Logs a message at the guest side using the G_LOG_LEVEL_WARNING level
+ *
+ * @param[in] fmt Log message format.
+ *
+ *******************************************************************************
+ */
+
+void
+WarningToGuest(const char *fmt, ...)
+{
+   va_list args;
+   va_start(args, fmt);
+   if (gGuestSDKMode) {
+      GuestSDK_Warning(fmt, args);
+   } else {
+      WITH_ERRNO(err,
+         VmwareLogWrapper(IN_GUEST, G_LOG_LEVEL_WARNING, fmt, args));
+   }
+   va_end(args);
+}
+
+
 /*
  *******************************************************************************
  * VMTools_ChangeLogFilePath --                                           */ /**