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

tests: Support logging into separate file for exec-ed libssh test server

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2024-04-04 17:43:16 +02:00
committed by Andreas Schneider
parent 9170320298
commit 8577f588c3
4 changed files with 39 additions and 2 deletions

View File

@ -59,6 +59,7 @@ struct arguments_st {
char *password; char *password;
char *config_file; char *config_file;
char *log_file;
bool with_global_config; bool with_global_config;
char *pid_file; char *pid_file;
}; };
@ -84,6 +85,7 @@ static void free_arguments(struct arguments_st *arguments)
SAFE_FREE(arguments->username); SAFE_FREE(arguments->username);
SAFE_FREE(arguments->password); SAFE_FREE(arguments->password);
SAFE_FREE(arguments->config_file); SAFE_FREE(arguments->config_file);
SAFE_FREE(arguments->log_file);
SAFE_FREE(arguments->pid_file); SAFE_FREE(arguments->pid_file);
end: end:
@ -174,6 +176,7 @@ static void print_server_state(struct server_state_st *state)
state->parse_global_config? "TRUE": "FALSE"); state->parse_global_config? "TRUE": "FALSE");
printf("config_file = %s\n", printf("config_file = %s\n",
state->config_file? state->config_file: "NULL"); state->config_file? state->config_file: "NULL");
printf("log_file = %s\n", state->log_file ? state->log_file : "NULL");
printf("=================================================\n"); printf("=================================================\n");
} }
} }
@ -297,6 +300,11 @@ static int init_server_state(struct server_state_st *state,
arguments->config_file = NULL; arguments->config_file = NULL;
} }
if (arguments->log_file) {
state->log_file = arguments->log_file;
arguments->log_file = NULL;
}
/* TODO make configurable */ /* TODO make configurable */
state->max_tries = 3; state->max_tries = 3;
state->error = 0; state->error = 0;
@ -440,6 +448,14 @@ static struct argp_option options[] = {
.doc = "Use this server configuration file.", .doc = "Use this server configuration file.",
.group = 0 .group = 0
}, },
{
.name = "log_file",
.key = 'l',
.arg = "LOG_FILE",
.flags = 0,
.doc = "Output log to this file.",
.group = 0
},
{ .name = NULL } { .name = NULL }
}; };
@ -553,6 +569,14 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
goto end; goto end;
} }
break; break;
case 'l':
arguments->log_file = strdup(arg);
if (arguments->log_file == NULL) {
fprintf(stderr, "Out of memory\n");
rc = ENOMEM;
goto end;
}
break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
if (state->arg_num >= 1) { if (state->arg_num >= 1) {
/* Too many arguments. */ /* Too many arguments. */

View File

@ -54,6 +54,8 @@ static int libssh_server_setup(void **state)
struct test_server_st *tss = NULL; struct test_server_st *tss = NULL;
struct torture_state *s = NULL; struct torture_state *s = NULL;
char log_file[1024];
assert_non_null(state); assert_non_null(state);
tss = (struct test_server_st*)calloc(1, sizeof(struct test_server_st)); tss = (struct test_server_st*)calloc(1, sizeof(struct test_server_st));
@ -62,6 +64,13 @@ static int libssh_server_setup(void **state)
torture_setup_socket_dir((void **)&s); torture_setup_socket_dir((void **)&s);
torture_setup_create_libssh_config((void **)&s); torture_setup_create_libssh_config((void **)&s);
snprintf(log_file,
sizeof(log_file),
"%s/sshd/log",
s->socket_dir);
s->log_file = strdup(log_file);
/* The second argument is the relative path to the "server" directory binary /* The second argument is the relative path to the "server" directory binary
*/ */
torture_setup_libssh_server((void **)&s, "./test_server/test_server"); torture_setup_libssh_server((void **)&s, "./test_server/test_server");

View File

@ -1020,10 +1020,12 @@ void torture_setup_libssh_server(void **state, const char *server_path)
/* Write the start command */ /* Write the start command */
printed = snprintf(start_cmd, sizeof(start_cmd), printed = snprintf(start_cmd, sizeof(start_cmd),
"%s" "%s"
"%s -f%s -v4 -p22 -i%s -C%s%s%s", "%s -f%s -v4 -p22 -i%s -C%s%s%s%s%s",
timeout_cmd, timeout_cmd,
server_path, s->pcap_file, s->srv_pidfile, server_path, s->pcap_file, s->srv_pidfile,
s->srv_config, extra_options, TORTURE_SSH_SERVER); s->srv_config,
s->log_file ? " -l " : "", s->log_file ? s->log_file : "",
extra_options, TORTURE_SSH_SERVER);
if (printed < 0) { if (printed < 0) {
fail_msg("Failed to print start command!"); fail_msg("Failed to print start command!");
/* Unreachable */ /* Unreachable */
@ -1116,6 +1118,7 @@ void torture_free_state(struct torture_state *s)
free(s->srv_config); free(s->srv_config);
free(s->socket_dir); free(s->socket_dir);
free(s->pcap_file); free(s->pcap_file);
free(s->log_file);
free(s->srv_pidfile); free(s->srv_pidfile);
free(s->srv_additional_config); free(s->srv_additional_config);
free(s); free(s);

View File

@ -68,6 +68,7 @@ struct torture_sftp {
struct torture_state { struct torture_state {
char *socket_dir; char *socket_dir;
char *pcap_file; char *pcap_file;
char *log_file;
char *srv_pidfile; char *srv_pidfile;
char *srv_config; char *srv_config;
bool srv_pam; bool srv_pam;