mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +03:00
tests: Allow setting configuration file for test server
This allows testing the server with a configuration file. This also adds an option for the stand-alone test server to skip parsing the system-wide configuration file. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Andreas Schneider
parent
79f0c38fbd
commit
e7ef40c8f0
@ -58,6 +58,9 @@ struct arguments_st {
|
||||
|
||||
char *username;
|
||||
char *password;
|
||||
|
||||
char *config_file;
|
||||
bool with_global_config;
|
||||
};
|
||||
|
||||
static void free_arguments(struct arguments_st *arguments)
|
||||
@ -81,6 +84,7 @@ static void free_arguments(struct arguments_st *arguments)
|
||||
|
||||
SAFE_FREE(arguments->username);
|
||||
SAFE_FREE(arguments->password);
|
||||
SAFE_FREE(arguments->config_file);
|
||||
|
||||
end:
|
||||
return;
|
||||
@ -168,6 +172,11 @@ static void print_server_state(struct server_state_st *state)
|
||||
printf("password = %s\n",
|
||||
state->expected_password? state->expected_password: "NULL");
|
||||
printf("=================================================\n");
|
||||
printf("with_global_config = %s\n",
|
||||
state->parse_global_config? "TRUE": "FALSE");
|
||||
printf("config_file = %s\n",
|
||||
state->config_file? state->config_file: "NULL");
|
||||
printf("=================================================\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,10 +299,18 @@ static int init_server_state(struct server_state_st *state,
|
||||
}
|
||||
}
|
||||
|
||||
state->parse_global_config = arguments->with_global_config;
|
||||
|
||||
if (arguments->config_file) {
|
||||
state->config_file = arguments->config_file;
|
||||
arguments->config_file = NULL;
|
||||
}
|
||||
|
||||
/* TODO make configurable */
|
||||
state->max_tries = 3;
|
||||
state->error = 0;
|
||||
|
||||
|
||||
if (state) {
|
||||
print_server_state(state);
|
||||
}
|
||||
@ -416,6 +433,22 @@ static struct argp_option options[] = {
|
||||
.doc = "Use PCAP.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "without-global-config",
|
||||
.key = 'g',
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Do not use system-wide configuration file.",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "config",
|
||||
.key = 'C',
|
||||
.arg = "CONFIG_FILE",
|
||||
.flags = 0,
|
||||
.doc = "Use this server configuration file.",
|
||||
.group = 0
|
||||
},
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
@ -518,6 +551,17 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
|
||||
case 'w':
|
||||
arguments->with_pcap = true;
|
||||
break;
|
||||
case 'g':
|
||||
arguments->with_global_config = false;
|
||||
break;
|
||||
case 'C':
|
||||
arguments->config_file = strdup(arg);
|
||||
if (arguments->config_file == NULL) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
rc = ENOMEM;
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
if (state->arg_num >= 1) {
|
||||
/* Too many arguments. */
|
||||
@ -557,6 +601,7 @@ int main(UNUSED_PARAM(int argc), UNUSED_PARAM(char **argv))
|
||||
|
||||
struct arguments_st arguments = {
|
||||
.address = NULL,
|
||||
.with_global_config = true,
|
||||
};
|
||||
struct server_state_st state = {
|
||||
.address = NULL,
|
||||
|
@ -55,6 +55,7 @@ void free_server_state(struct server_state_st *state)
|
||||
|
||||
SAFE_FREE(state->expected_username);
|
||||
SAFE_FREE(state->expected_password);
|
||||
SAFE_FREE(state->config_file);
|
||||
|
||||
end:
|
||||
return;
|
||||
@ -120,6 +121,22 @@ int run_server(struct server_state_st *state)
|
||||
}
|
||||
}
|
||||
|
||||
if (!state->parse_global_config) {
|
||||
rc = ssh_bind_options_set(sshbind,
|
||||
SSH_BIND_OPTIONS_PROCESS_CONFIG,
|
||||
&(state->parse_global_config));
|
||||
if (rc != 0) {
|
||||
goto free_sshbind;
|
||||
}
|
||||
}
|
||||
|
||||
if (state->config_file) {
|
||||
rc = ssh_bind_options_parse_config(sshbind, state->config_file);
|
||||
if (rc != 0) {
|
||||
goto free_sshbind;
|
||||
}
|
||||
}
|
||||
|
||||
rc = ssh_bind_options_set(sshbind,
|
||||
SSH_BIND_OPTIONS_BINDADDR,
|
||||
state->address);
|
||||
|
@ -50,6 +50,9 @@ struct server_state_st {
|
||||
char *expected_username;
|
||||
char *expected_password;
|
||||
|
||||
char *config_file;
|
||||
bool parse_global_config;
|
||||
|
||||
/* State */
|
||||
int max_tries;
|
||||
int error;
|
||||
|
@ -191,6 +191,9 @@ static int setup_default_server(void **state)
|
||||
ss->handle_session = default_handle_session_cb;
|
||||
assert_non_null(ss->handle_session);
|
||||
|
||||
/* Do not use global configuration */
|
||||
ss->parse_global_config = false;
|
||||
|
||||
/* Start the server using the default values */
|
||||
pid = fork_run_server(ss);
|
||||
if (pid < 0) {
|
||||
|
Reference in New Issue
Block a user