1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

tests: Fix running ssh-agent

ssh-agent needs to be executed as the local user and not a fake user or
we will not be able to add identies.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2016-02-02 11:28:07 +01:00
parent 063430744d
commit f128ffd88b
3 changed files with 32 additions and 5 deletions

View File

@ -25,6 +25,8 @@
#include "libssh/libssh.h"
#include "libssh/priv.h"
#include "libssh/session.h"
#include <errno.h>
#include <sys/types.h>
#include <pwd.h>
@ -80,7 +82,9 @@ static int pubkey_setup(void **state)
pwd = getpwnam("bob");
assert_non_null(pwd);
setuid(pwd->pw_uid);
rc = setuid(pwd->pw_uid);
assert_return_code(rc, errno);
/* Make sure we do not interfere with another ssh-agent */
unsetenv("SSH_AUTH_SOCK");
@ -95,6 +99,8 @@ static int agent_setup(void **state)
char ssh_agent_cmd[4096];
char ssh_agent_sock[1024];
char ssh_agent_pidfile[1024];
char bob_ssh_key[1024];
struct passwd *pwd;
int rc;
rc = pubkey_setup(state);
@ -102,6 +108,9 @@ static int agent_setup(void **state)
return rc;
}
pwd = getpwnam("bob");
assert_non_null(pwd);
snprintf(ssh_agent_sock,
sizeof(ssh_agent_cmd),
"%s/agent.sock",
@ -118,13 +127,21 @@ static int agent_setup(void **state)
"eval `ssh-agent -a %s`; echo $SSH_AGENT_PID > %s",
ssh_agent_sock, ssh_agent_pidfile);
/* run ssh-agent and ssh-add as the normal user */
unsetenv("UID_WRAPPER_ROOT");
rc = system(ssh_agent_cmd);
assert_return_code(rc, errno);
setenv("SSH_AUTH_SOCK", ssh_agent_sock, 1);
setenv("TORTURE_SSH_AGENT_PIDFILE", ssh_agent_pidfile, 1);
rc = system("ssh-add");
snprintf(bob_ssh_key,
sizeof(bob_ssh_key),
"ssh-add %s/.ssh/id_rsa",
pwd->pw_dir);
rc = system(bob_ssh_key);
assert_return_code(rc, errno);
return 0;