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