1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-01 11:26:52 +03:00

Use helper variable in connect_host()

According to libssh coding conventions, function
return values must not be directly passed to if-
or while- conditions. This rule was not being followed
in connect_host(). A helper variable has been introduced
which stores the return code of the functions which
is then passed to the if- conditions.

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Eshan Kelkar
2023-06-07 13:19:54 +05:30
committed by Sahana Prasad
parent d8790d06c4
commit 4e239484fe

View File

@ -278,26 +278,43 @@ static void arguments_init(struct argument_s *arguments)
static ssh_session connect_host(const char *host, int verbose, char *cipher)
{
ssh_session session = ssh_new();
ssh_session session = NULL;
int rc;
session = ssh_new();
if (session == NULL)
goto error;
if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0)
rc = ssh_options_set(session, SSH_OPTIONS_HOST, host);
if (rc < 0)
goto error;
rc = ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbose);
if (rc < 0)
goto error;
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbose);
if (cipher != NULL) {
if (ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, cipher) ||
ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, cipher)) {
rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, cipher);
if (rc < 0)
goto error;
rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, cipher);
if (rc < 0)
goto error;
}
}
ssh_options_parse_config(session, NULL);
if (ssh_connect(session) == SSH_ERROR)
rc = ssh_options_parse_config(session, NULL);
if (rc < 0)
goto error;
if (ssh_userauth_autopubkey(session, NULL) != SSH_AUTH_SUCCESS)
rc = ssh_connect(session);
if (rc == SSH_ERROR)
goto error;
rc = ssh_userauth_autopubkey(session, NULL);
if (rc != SSH_AUTH_SUCCESS)
goto error;
return session;
error: