1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-17 06:18:58 +03:00

reformat: bind.c

reformat: remove unneeded free

Signed-off-by: Gauravsingh Sisodia <xaerru@gmail.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
Gauravsingh Sisodia
2024-03-08 17:41:55 +00:00
committed by Sahana Prasad
parent fcd63abb6a
commit b9d4e11456

View File

@@ -225,11 +225,29 @@ static int ssh_bind_import_keys(ssh_bind sshbind) {
return SSH_OK;
}
int ssh_bind_listen(ssh_bind sshbind) {
const char *host;
int ssh_bind_listen(ssh_bind sshbind)
{
const char *host = NULL;
socket_t fd;
int rc;
/* Apply global bind configurations, if it hasn't been applied before */
rc = ssh_bind_options_parse_config(sshbind, NULL);
if (rc != 0) {
ssh_set_error(sshbind, SSH_FATAL, "Could not parse global config");
return SSH_ERROR;
}
/* Set default hostkey paths if no hostkey was found before */
if (sshbind->ecdsakey == NULL &&
sshbind->rsakey == NULL &&
sshbind->ed25519key == NULL) {
sshbind->ecdsakey = strdup("/etc/ssh/ssh_host_ecdsa_key");
sshbind->rsakey = strdup("/etc/ssh/ssh_host_rsa_key");
sshbind->ed25519key = strdup("/etc/ssh/ssh_host_ed25519_key");
}
if (sshbind->rsa == NULL &&
sshbind->ecdsa == NULL &&
sshbind->ed25519 == NULL) {
@@ -247,22 +265,18 @@ int ssh_bind_listen(ssh_bind sshbind) {
fd = bind_socket(sshbind, host, sshbind->bindport);
if (fd == SSH_INVALID_SOCKET) {
ssh_key_free(sshbind->rsa);
sshbind->rsa = NULL;
/* XXX should this clear also other structures that were allocated */
return -1;
return SSH_ERROR;
}
if (listen(fd, 10) < 0) {
char err_msg[SSH_ERRNO_MSG_MAX] = {0};
ssh_set_error(sshbind, SSH_FATAL,
ssh_set_error(sshbind,
SSH_FATAL,
"Listening to socket %d: %s",
fd, ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
fd,
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
CLOSE_SOCKET(fd);
ssh_key_free(sshbind->rsa);
sshbind->rsa = NULL;
/* XXX should this clear also other structures that were allocated */
return -1;
return SSH_ERROR;
}
sshbind->bindfd = fd;
@@ -272,8 +286,8 @@ int ssh_bind_listen(ssh_bind sshbind) {
return 0;
}
int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
void *userdata){
int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks, void *userdata)
{
if (sshbind == NULL) {
return SSH_ERROR;
}
@@ -282,7 +296,8 @@ int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
return SSH_ERROR;
}
if (callbacks->size <= 0 || callbacks->size > 1024 * sizeof(void *)) {
ssh_set_error(sshbind,SSH_FATAL,
ssh_set_error(sshbind,
SSH_FATAL,
"Invalid callback passed in (badly initialized)");
return SSH_ERROR;
}
@@ -295,8 +310,8 @@ int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
* @brief callback being called by poll when an event happens
*
*/
static int ssh_bind_poll_callback(ssh_poll_handle sshpoll,
socket_t fd, int revents, void *user){
static int ssh_bind_poll_callback(ssh_poll_handle sshpoll, socket_t fd, int revents, void *user)
{
ssh_bind sshbind = (ssh_bind)user;
(void)sshpoll;
(void)fd;
@@ -336,19 +351,23 @@ ssh_poll_handle ssh_bind_get_poll(ssh_bind sshbind)
return sshbind->poll;
}
void ssh_bind_set_blocking(ssh_bind sshbind, int blocking) {
void ssh_bind_set_blocking(ssh_bind sshbind, int blocking)
{
sshbind->blocking = blocking ? 1 : 0;
}
socket_t ssh_bind_get_fd(ssh_bind sshbind) {
socket_t ssh_bind_get_fd(ssh_bind sshbind)
{
return sshbind->bindfd;
}
void ssh_bind_set_fd(ssh_bind sshbind, socket_t fd) {
void ssh_bind_set_fd(ssh_bind sshbind, socket_t fd)
{
sshbind->bindfd = fd;
}
void ssh_bind_fd_toaccept(ssh_bind sshbind) {
void ssh_bind_fd_toaccept(ssh_bind sshbind)
{
sshbind->toaccept = 1;
}