refactor: wrap and move server session options in a new struct

Signed-off-by: Francesco Rollo <eferollo@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
Francesco Rollo
2024-06-10 21:06:22 +02:00
committed by Sahana Prasad
parent 6c59d975ba
commit b4ed60024b
5 changed files with 18 additions and 12 deletions

View File

@@ -248,8 +248,6 @@ struct ssh_session_struct {
char *wanted_methods[SSH_KEX_METHODS];
char *pubkey_accepted_types;
char *ProxyCommand;
char *custombanner;
char *moduli_file;
char *agent_socket;
unsigned long timeout; /* seconds */
unsigned long timeout_usec;
@@ -272,6 +270,13 @@ struct ssh_session_struct {
int control_master;
char *control_path;
} opts;
/* server options */
struct {
char *custombanner;
char *moduli_file;
} server_opts;
/* counters */
ssh_counter socket_counter;
ssh_counter raw_counter;

View File

@@ -480,16 +480,16 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd)
session->common.log_verbosity = sshbind->common.log_verbosity;
if (sshbind->banner != NULL) {
session->opts.custombanner = strdup(sshbind->banner);
if (session->opts.custombanner == NULL) {
session->server_opts.custombanner = strdup(sshbind->banner);
if (session->server_opts.custombanner == NULL) {
ssh_set_error_oom(sshbind);
return SSH_ERROR;
}
}
if (sshbind->moduli_file != NULL) {
session->opts.moduli_file = strdup(sshbind->moduli_file);
if (session->opts.moduli_file == NULL) {
session->server_opts.moduli_file = strdup(sshbind->moduli_file);
if (session->server_opts.moduli_file == NULL) {
ssh_set_error_oom(sshbind);
return SSH_ERROR;
}

View File

@@ -185,13 +185,13 @@ int ssh_send_banner(ssh_session session, int server)
int rc = SSH_ERROR;
if (server == 1) {
if (session->opts.custombanner == NULL){
if (session->server_opts.custombanner == NULL) {
session->serverbanner = strdup(banner);
if (session->serverbanner == NULL) {
goto end;
}
} else {
len = strlen(session->opts.custombanner);
len = strlen(session->server_opts.custombanner);
session->serverbanner = malloc(len + 8 + 1);
if(session->serverbanner == NULL) {
goto end;
@@ -199,7 +199,7 @@ int ssh_send_banner(ssh_session session, int server)
snprintf(session->serverbanner,
len + 8 + 1,
"SSH-2.0-%s",
session->opts.custombanner);
session->server_opts.custombanner);
}
snprintf(buffer,

View File

@@ -643,7 +643,7 @@ static SSH_PACKET_CALLBACK(ssh_packet_server_dhgex_request)
pn = pmin;
}
}
rc = ssh_retrieve_dhgroup(session->opts.moduli_file,
rc = ssh_retrieve_dhgroup(session->server_opts.moduli_file,
pmin,
pn,
pmax,

View File

@@ -339,8 +339,6 @@ void ssh_free(ssh_session session)
SAFE_FREE(session->opts.agent_socket);
SAFE_FREE(session->opts.bindaddr);
SAFE_FREE(session->opts.custombanner);
SAFE_FREE(session->opts.moduli_file);
SAFE_FREE(session->opts.username);
SAFE_FREE(session->opts.host);
SAFE_FREE(session->opts.sshdir);
@@ -358,6 +356,9 @@ void ssh_free(ssh_session session)
}
}
SAFE_FREE(session->server_opts.custombanner);
SAFE_FREE(session->server_opts.moduli_file);
_ssh_remove_legacy_log_cb();
/* burn connection, it could contain sensitive data */