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:
committed by
Sahana Prasad
parent
fcd63abb6a
commit
b9d4e11456
71
src/bind.c
71
src/bind.c
@@ -225,11 +225,29 @@ static int ssh_bind_import_keys(ssh_bind sshbind) {
|
|||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_bind_listen(ssh_bind sshbind) {
|
int ssh_bind_listen(ssh_bind sshbind)
|
||||||
const char *host;
|
{
|
||||||
|
const char *host = NULL;
|
||||||
socket_t fd;
|
socket_t fd;
|
||||||
int rc;
|
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 &&
|
if (sshbind->rsa == NULL &&
|
||||||
sshbind->ecdsa == NULL &&
|
sshbind->ecdsa == NULL &&
|
||||||
sshbind->ed25519 == NULL) {
|
sshbind->ed25519 == NULL) {
|
||||||
@@ -247,22 +265,18 @@ int ssh_bind_listen(ssh_bind sshbind) {
|
|||||||
|
|
||||||
fd = bind_socket(sshbind, host, sshbind->bindport);
|
fd = bind_socket(sshbind, host, sshbind->bindport);
|
||||||
if (fd == SSH_INVALID_SOCKET) {
|
if (fd == SSH_INVALID_SOCKET) {
|
||||||
ssh_key_free(sshbind->rsa);
|
return SSH_ERROR;
|
||||||
sshbind->rsa = NULL;
|
|
||||||
/* XXX should this clear also other structures that were allocated */
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(fd, 10) < 0) {
|
if (listen(fd, 10) < 0) {
|
||||||
char err_msg[SSH_ERRNO_MSG_MAX] = {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",
|
"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);
|
CLOSE_SOCKET(fd);
|
||||||
ssh_key_free(sshbind->rsa);
|
return SSH_ERROR;
|
||||||
sshbind->rsa = NULL;
|
|
||||||
/* XXX should this clear also other structures that were allocated */
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sshbind->bindfd = fd;
|
sshbind->bindfd = fd;
|
||||||
@@ -272,8 +286,8 @@ int ssh_bind_listen(ssh_bind sshbind) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
|
int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks, void *userdata)
|
||||||
void *userdata){
|
{
|
||||||
if (sshbind == NULL) {
|
if (sshbind == NULL) {
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
@@ -281,13 +295,14 @@ int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
|
|||||||
ssh_set_error_invalid(sshbind);
|
ssh_set_error_invalid(sshbind);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
if(callbacks->size <= 0 || callbacks->size > 1024 * sizeof(void *)){
|
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)");
|
"Invalid callback passed in (badly initialized)");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
sshbind->bind_callbacks = callbacks;
|
sshbind->bind_callbacks = callbacks;
|
||||||
sshbind->bind_callbacks_userdata=userdata;
|
sshbind->bind_callbacks_userdata = userdata;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,15 +310,15 @@ int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
|
|||||||
* @brief callback being called by poll when an event happens
|
* @brief callback being called by poll when an event happens
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int ssh_bind_poll_callback(ssh_poll_handle sshpoll,
|
static int ssh_bind_poll_callback(ssh_poll_handle sshpoll, socket_t fd, int revents, void *user)
|
||||||
socket_t fd, int revents, void *user){
|
{
|
||||||
ssh_bind sshbind=(ssh_bind)user;
|
ssh_bind sshbind = (ssh_bind)user;
|
||||||
(void)sshpoll;
|
(void)sshpoll;
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
|
||||||
if(revents & POLLIN){
|
if (revents & POLLIN) {
|
||||||
/* new incoming connection */
|
/* new incoming connection */
|
||||||
if(ssh_callbacks_exists(sshbind->bind_callbacks,incoming_connection)){
|
if (ssh_callbacks_exists(sshbind->bind_callbacks, incoming_connection)) {
|
||||||
sshbind->bind_callbacks->incoming_connection(sshbind,
|
sshbind->bind_callbacks->incoming_connection(sshbind,
|
||||||
sshbind->bind_callbacks_userdata);
|
sshbind->bind_callbacks_userdata);
|
||||||
}
|
}
|
||||||
@@ -336,19 +351,23 @@ ssh_poll_handle ssh_bind_get_poll(ssh_bind sshbind)
|
|||||||
return sshbind->poll;
|
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;
|
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;
|
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;
|
sshbind->bindfd = fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_bind_fd_toaccept(ssh_bind sshbind) {
|
void ssh_bind_fd_toaccept(ssh_bind sshbind)
|
||||||
|
{
|
||||||
sshbind->toaccept = 1;
|
sshbind->toaccept = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user