Blame SOURCES/ovt-End-VGAuth-impersonation-in-the-case-of-error.patch

378f6c
From b80da5a181c50c3aae682166f8f39b2cf3fdec80 Mon Sep 17 00:00:00 2001
8d58a8
From: Cathy Avery <cavery@redhat.com>
378f6c
Date: Fri, 25 Oct 2019 15:34:04 +0200
378f6c
Subject: [PATCH 2/3] End VGAuth impersonation in the case of error.
8d58a8
8d58a8
RH-Author: Cathy Avery <cavery@redhat.com>
378f6c
Message-id: <20191025153405.10241-3-cavery@redhat.com>
378f6c
Patchwork-id: 91966
378f6c
O-Subject: [RHEL7.8 open-vm-tools PATCH v2 2/3] End VGAuth impersonation in the case of error.
378f6c
Bugzilla: 1760625
8d58a8
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
378f6c
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
8d58a8
8d58a8
commit 7b874f37f970aab2adddb063a8363594f47abf70
8d58a8
Author: Oliver Kurth <okurth@vmware.com>
8d58a8
Date:   Tue Sep 4 15:40:58 2018 -0700
8d58a8
8d58a8
    End VGAuth impersonation in the case of error.
8d58a8
8d58a8
    * In GuestAuthPasswordAuthenticateImpersonate():
8d58a8
    When VGAuth_UserHandleAccessToken fails, unimpersonation is not
8d58a8
    being done. This can cause issues. Fixed it.
8d58a8
8d58a8
    * In GuestAuthSAMLAuthenticateAndImpersonate(), fixed the following issues:
8d58a8
    The 'newHandle' is not being freed which causes a memory leak.
8d58a8
    When VGAuth_UserHandleAccessToken fails, unimpersonation is not
8d58a8
    being done.
8d58a8
8d58a8
Signed-off-by: Cathy Avery <cavery@redhat.com>
8d58a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8d58a8
---
8d58a8
 services/plugins/vix/vixTools.c | 25 +++++++++++++++++++++++--
8d58a8
 1 file changed, 23 insertions(+), 2 deletions(-)
8d58a8
8d58a8
diff --git a/services/plugins/vix/vixTools.c b/services/plugins/vix/vixTools.c
378f6c
index 4436944..00b40b1 100644
8d58a8
--- a/services/plugins/vix/vixTools.c
8d58a8
+++ b/services/plugins/vix/vixTools.c
378f6c
@@ -11550,6 +11550,7 @@ GuestAuthPasswordAuthenticateImpersonate(
8d58a8
    VGAuthError vgErr;
8d58a8
    VGAuthUserHandle *newHandle = NULL;
8d58a8
    VGAuthExtraParams extraParams[1];
8d58a8
+   Bool impersonated = FALSE;
8d58a8
 
8d58a8
    extraParams[0].name = VGAUTH_PARAM_LOAD_USER_PROFILE;
8d58a8
    extraParams[0].value = VGAUTH_PARAM_VALUE_TRUE;
378f6c
@@ -11585,6 +11586,8 @@ GuestAuthPasswordAuthenticateImpersonate(
8d58a8
       goto done;
8d58a8
    }
8d58a8
 
8d58a8
+   impersonated = TRUE;
8d58a8
+
8d58a8
 #ifdef _WIN32
8d58a8
    // this is making a copy of the token, be sure to close it
8d58a8
    vgErr = VGAuth_UserHandleAccessToken(ctx, newHandle, userToken);
378f6c
@@ -11604,6 +11607,10 @@ done:
8d58a8
    Util_ZeroFreeString(password);
8d58a8
 
8d58a8
    if (VIX_OK != err) {
8d58a8
+      if (impersonated) {
8d58a8
+         vgErr = VGAuth_EndImpersonation(ctx);
8d58a8
+         ASSERT(vgErr == VGAUTH_E_OK);
8d58a8
+      }
8d58a8
       VGAuth_UserHandleFree(newHandle);
8d58a8
       newHandle = NULL;
8d58a8
    }
378f6c
@@ -11638,12 +11645,13 @@ GuestAuthSAMLAuthenticateAndImpersonate(
8d58a8
 {
8d58a8
 #if SUPPORT_VGAUTH
8d58a8
    VixError err;
8d58a8
-   char *token;
8d58a8
-   char *username;
8d58a8
+   char *token = NULL;
8d58a8
+   char *username = NULL;
8d58a8
    VGAuthContext *ctx = NULL;
8d58a8
    VGAuthError vgErr;
8d58a8
    VGAuthUserHandle *newHandle = NULL;
8d58a8
    VGAuthExtraParams extraParams[1];
8d58a8
+   Bool impersonated = FALSE;
8d58a8
 
8d58a8
    extraParams[0].name = VGAUTH_PARAM_LOAD_USER_PROFILE;
8d58a8
    extraParams[0].value = VGAUTH_PARAM_VALUE_TRUE;
378f6c
@@ -11735,6 +11743,8 @@ impersonate:
8d58a8
       goto done;
8d58a8
    }
8d58a8
 
8d58a8
+   impersonated = TRUE;
8d58a8
+
8d58a8
 #ifdef _WIN32
8d58a8
    // this is making a copy of the token, be sure to close it
8d58a8
    vgErr = VGAuth_UserHandleAccessToken(ctx, newHandle, userToken);
378f6c
@@ -11750,6 +11760,17 @@ impersonate:
8d58a8
    err = VIX_OK;
8d58a8
 
8d58a8
 done:
8d58a8
+   Util_ZeroFreeString(token);
8d58a8
+   Util_ZeroFreeString(username);
8d58a8
+
8d58a8
+   if (VIX_OK != err) {
8d58a8
+      if (impersonated) {
8d58a8
+         vgErr = VGAuth_EndImpersonation(ctx);
8d58a8
+         ASSERT(vgErr == VGAUTH_E_OK);
8d58a8
+      }
8d58a8
+      VGAuth_UserHandleFree(newHandle);
8d58a8
+      newHandle = NULL;
8d58a8
+   }
8d58a8
 
8d58a8
    return err;
8d58a8
 #else
8d58a8
-- 
8d58a8
1.8.3.1
8d58a8