mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
tests: Use a common function to start sshd
In torture_reload_sshd_server(), instead of trying to use SIGHUP to
reload the configuration file, kill the original process and create a
new one with the new configuration. With this change, both
torture_setup_sshd_server() and torture_reload_sshd_server() need to
start sshd, with the only difference in the configuration setup. The
shared code to start the sshd server was moved to a new introduced
internal function torture_start_sshd_server().
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
(cherry picked from commit 35224092eb)
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Jakub Jelen
parent
761ba97145
commit
7f20bbca62
@@ -856,21 +856,16 @@ static int torture_wait_for_daemon(unsigned int seconds)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void torture_setup_sshd_server(void **state, bool pam)
|
static int torture_start_sshd_server(void **state)
|
||||||
{
|
{
|
||||||
struct torture_state *s;
|
struct torture_state *s = *state;
|
||||||
char sshd_start_cmd[1024];
|
char sshd_start_cmd[1024];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
torture_setup_socket_dir(state);
|
|
||||||
torture_setup_create_sshd_config(state, pam);
|
|
||||||
|
|
||||||
/* Set the default interface for the server */
|
/* Set the default interface for the server */
|
||||||
setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "10", 1);
|
setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "10", 1);
|
||||||
setenv("PAM_WRAPPER", "1", 1);
|
setenv("PAM_WRAPPER", "1", 1);
|
||||||
|
|
||||||
s = *state;
|
|
||||||
|
|
||||||
snprintf(sshd_start_cmd, sizeof(sshd_start_cmd),
|
snprintf(sshd_start_cmd, sizeof(sshd_start_cmd),
|
||||||
SSHD_EXECUTABLE " -r -f %s -E %s/sshd/daemon.log 2> %s/sshd/cwrap.log",
|
SSHD_EXECUTABLE " -r -f %s -E %s/sshd/daemon.log 2> %s/sshd/cwrap.log",
|
||||||
s->srv_config, s->socket_dir, s->socket_dir);
|
s->srv_config, s->socket_dir, s->socket_dir);
|
||||||
@@ -882,7 +877,20 @@ void torture_setup_sshd_server(void **state, bool pam)
|
|||||||
unsetenv("PAM_WRAPPER");
|
unsetenv("PAM_WRAPPER");
|
||||||
|
|
||||||
/* Wait until the sshd is ready to accept connections */
|
/* Wait until the sshd is ready to accept connections */
|
||||||
rc = torture_wait_for_daemon(5);
|
rc = torture_wait_for_daemon(15);
|
||||||
|
assert_int_equal(rc, 0);
|
||||||
|
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void torture_setup_sshd_server(void **state, bool pam)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
torture_setup_socket_dir(state);
|
||||||
|
torture_setup_create_sshd_config(state, pam);
|
||||||
|
|
||||||
|
rc = torture_start_sshd_server(state);
|
||||||
assert_int_equal(rc, 0);
|
assert_int_equal(rc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -922,29 +930,14 @@ static int
|
|||||||
torture_reload_sshd_server(void **state)
|
torture_reload_sshd_server(void **state)
|
||||||
{
|
{
|
||||||
struct torture_state *s = *state;
|
struct torture_state *s = *state;
|
||||||
pid_t pid;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* read the pidfile */
|
rc = torture_terminate_process(s->srv_pidfile);
|
||||||
pid = torture_read_pidfile(s->srv_pidfile);
|
|
||||||
assert_int_not_equal(pid, -1);
|
|
||||||
|
|
||||||
kill(pid, SIGHUP);
|
|
||||||
|
|
||||||
/* 10 ms */
|
|
||||||
usleep(10 * 1000);
|
|
||||||
|
|
||||||
rc = kill(pid, 0);
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "XXXXXX Failed to terminate sshd\n");
|
||||||
"ERROR: SSHD process %u died during reload!\n", pid);
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait until the sshd is ready to accept connections */
|
return torture_start_sshd_server(state);
|
||||||
rc = torture_wait_for_daemon(10);
|
|
||||||
assert_int_equal(rc, 0);
|
|
||||||
return SSH_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @brief: Updates SSHD server configuration with more options and
|
/* @brief: Updates SSHD server configuration with more options and
|
||||||
|
|||||||
Reference in New Issue
Block a user