Blame SOURCES/openscap-1.3.6-PR-1753-getlogin.patch

f8d3e0
From b31cff1bc3a298cfa36a10476f2d633c290b6741 Mon Sep 17 00:00:00 2001
f8d3e0
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
f8d3e0
Date: Tue, 11 May 2021 13:20:18 +0200
f8d3e0
Subject: [PATCH] Replace getlogin by cuserid
f8d3e0
f8d3e0
The getlogin() is used here to fill in the xccdf:identity element which
f8d3e0
shall contain information about the system identity or user employed
f8d3e0
during application of the benchmark. But, the getlogin() can return NULL
f8d3e0
when there is no controlling terminal. This happened when testing oscap
f8d3e0
on a test system with no pty.  As an alternative, the system provides
f8d3e0
also cuserid() function which gets the effective user ID of the process.
f8d3e0
However, these 2 values differ when the program is executed under sudo.
f8d3e0
From the user experience point of view, it would be better to have
f8d3e0
displayed there the user logged in on the controlling terminal. As a
f8d3e0
compromise, we will first attempt to obtain the name using getlogin()
f8d3e0
and if that fails we will run cuserid().
f8d3e0
---
f8d3e0
 src/XCCDF/result.c | 5 ++++-
f8d3e0
 1 file changed, 4 insertions(+), 1 deletion(-)
f8d3e0
f8d3e0
diff --git a/src/XCCDF/result.c b/src/XCCDF/result.c
f8d3e0
index cd03e6bd8f..cbe016c44a 100644
f8d3e0
--- a/src/XCCDF/result.c
f8d3e0
+++ b/src/XCCDF/result.c
f8d3e0
@@ -217,7 +217,10 @@ static inline void _xccdf_result_fill_identity(struct xccdf_result *result)
f8d3e0
 	xccdf_identity_set_authenticated(id, 0);
f8d3e0
 	xccdf_identity_set_privileged(id, 0);
f8d3e0
 #ifdef OSCAP_UNIX
f8d3e0
-	xccdf_identity_set_name(id, getlogin());
f8d3e0
+	char *name = getlogin();
f8d3e0
+	if (name == NULL)
f8d3e0
+		name = cuserid(NULL);
f8d3e0
+	xccdf_identity_set_name(id, name);
f8d3e0
 #elif defined(OS_WINDOWS)
f8d3e0
 	GetUserName((TCHAR *) w32_username, &w32_usernamesize); /* XXX: Check the return value? */
f8d3e0
 	xccdf_identity_set_name(id, w32_username);