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

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