From: Oliver Kurth Date: Wed, 16 Jan 2019 22:53:06 +0000 (-0800) Subject: Add WarningToHost() and WarningToGuest() functions X-Git-Tag: stable-11.0.0~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b9d0560bbeb50a395ffcfa7f1114d0c0246f207;p=thirdparty%2Fopen-vm-tools.git Add WarningToHost() and WarningToGuest() functions 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. --- diff --git a/open-vm-tools/lib/include/logToHost.h b/open-vm-tools/lib/include/logToHost.h new file mode 100644 index 000000000..2cf4b509c --- /dev/null +++ b/open-vm-tools/lib/include/logToHost.h @@ -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__ */ diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index 3ff98eb33..e492f9a96 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -80,6 +80,7 @@ #include "strutil.h" #include "codeset.h" #include "unicode.h" +#include "logToHost.h" #ifdef USERWORLD #include @@ -87,6 +88,7 @@ #include #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; } diff --git a/open-vm-tools/libvmtools/vmtoolsLog.c b/open-vm-tools/libvmtools/vmtoolsLog.c index 478f7d1ff..d5d3fab2c 100644 --- a/open-vm-tools/libvmtools/vmtoolsLog.c +++ b/open-vm-tools/libvmtools/vmtoolsLog.c @@ -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 -- */ /**