1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-05-28 17:41:28 +03:00

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>
This commit is contained in:
Nikos Mavrogiannopoulos 2018-04-12 17:03:06 +02:00 committed by Andreas Schneider
parent e005fd310f
commit f3a19d8c96

View File

@ -1,5 +1,8 @@
#include "config.h" #include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#ifndef _WIN32 #ifndef _WIN32
@ -129,7 +132,14 @@ static void torture_path_expand_tilde_unix(void **state) {
if (user == NULL){ if (user == NULL){
user = getenv("LOGNAME"); 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"); home = getenv("HOME");
assert_non_null(home); assert_non_null(home);
snprintf(h, 256 - 1, "%s/.ssh", home); snprintf(h, 256 - 1, "%s/.ssh", home);