aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2018-04-12 17:03:06 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-04-17 17:59:14 +0200
commitf3a19d8c963a0510ca67a5292436ac5c40c8e788 (patch)
tree83d0bf889660548ed6a63942ed2b1acac1b81b04
parente005fd310f614fdedc1f5ac69843d5d41acf0b42 (diff)
downloadlibssh-f3a19d8c963a0510ca67a5292436ac5c40c8e788.tar.gz
libssh-f3a19d8c963a0510ca67a5292436ac5c40c8e788.tar.xz
libssh-f3a19d8c963a0510ca67a5292436ac5c40c8e788.zip
torture_path_expand_tilde_unix: use getpwuid() if no env variables
This allows operating under environments where the username variables are not present. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/unittests/torture_misc.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c
index de84c4a3..37fa4aed 100644
--- a/tests/unittests/torture_misc.c
+++ b/tests/unittests/torture_misc.c
@@ -1,5 +1,8 @@
#include "config.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include <sys/types.h>
#ifndef _WIN32
@@ -129,7 +132,14 @@ static void torture_path_expand_tilde_unix(void **state) {
if (user == NULL){
user = getenv("LOGNAME");
}
- assert_non_null(user);
+ /* in certain CIs there no such variables */
+ if (!user){
+ struct passwd *pw = getpwuid(getuid());
+ if (pw){
+ user = pw->pw_name;
+ }
+ }
+
home = getenv("HOME");
assert_non_null(home);
snprintf(h, 256 - 1, "%s/.ssh", home);