aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/forward.c4
-rw-r--r--src/protocol_ssh.c35
2 files changed, 17 insertions, 22 deletions
diff --git a/src/forward.c b/src/forward.c
index b2a36d4..590892b 100644
--- a/src/forward.c
+++ b/src/forward.c
@@ -126,13 +126,13 @@ int fwd_connect_sock(forward_ctx *ctx, psocket *fwd_client)
}
if (ctx->ai) {
- s = socket_connectaddr_in(&ctx->sock, &ctx->ai,
+ s = socket_connectaddr_in(dst, &ctx->ai,
ctx->host_buf,
ctx->service_buf);
switch (s) {
case -1:
E_STRERR("Connection to forward socket with fd %d",
- ctx->sock.fd);
+ dst->fd);
break;
case 0:
if (ctx->ai)
diff --git a/src/protocol_ssh.c b/src/protocol_ssh.c
index 1479ca1..94149d4 100644
--- a/src/protocol_ssh.c
+++ b/src/protocol_ssh.c
@@ -6,8 +6,6 @@
#include <signal.h>
#include <pthread.h>
#include <poll.h>
-#include <pty.h>
-#include <utmp.h>
#include <libssh/callbacks.h>
#include <libssh/server.h>
@@ -23,6 +21,7 @@
typedef struct ssh_data {
pthread_t self;
ssh_bind sshbind;
+ protocol_ctx *ctx;
} ssh_data;
struct protocol_cbs potd_ssh_callbacks = {
@@ -39,7 +38,7 @@ static void *
ssh_thread_mainloop(void *arg);
static int authenticate(ssh_session session);
static int auth_password(const char *user, const char *password);
-static int client_mainloop(ssh_channel chan);
+static int client_mainloop(ssh_channel chan, ssh_data *data);
static int copy_fd_to_chan(socket_t fd, int revents, void *userdata);
static int copy_chan_to_fd(ssh_session session, ssh_channel channel, void *data,
uint32_t len, int is_stderr, void *userdata);
@@ -83,6 +82,7 @@ int ssh_init_cb(protocol_ctx *ctx)
ssh_data *d = (ssh_data *) calloc(1, sizeof(*d));
assert(d);
d->sshbind = ssh_bind_new();
+ d->ctx = ctx;
ctx->src.data = d;
ssh_set_log_callback(ssh_log_cb);
@@ -333,7 +333,7 @@ ssh_thread_mainloop(void *arg)
}
N("%s", "Dropping user into shell");
- client_mainloop(chan);
+ client_mainloop(chan, d);
failed:
ssh_disconnect(ses);
@@ -410,23 +410,18 @@ static int auth_password(const char *user, const char *password)
return 1; /* authenticated */
}
-static int client_mainloop(ssh_channel chan)
+static int client_mainloop(ssh_channel chan, ssh_data *data)
{
ssh_session session = ssh_channel_get_session(chan);
- socket_t fd;
- struct termios *term = NULL;
- struct winsize *win = NULL;
- pid_t childpid;
ssh_event event;
short events;
+ protocol_ctx *ctx = data->ctx;
+ psocket fwd;
- childpid = forkpty(&fd, NULL, term, win);
- if (childpid == 0) {
- execl("/bin/bash", "/bin/bash", (char *)NULL);
- abort();
- }
+ if (fwd_connect_sock(&ctx->dst, &fwd))
+ return 1;
- ssh_channel_cb.userdata = &fd;
+ ssh_channel_cb.userdata = &fwd.fd;
ssh_callbacks_init(&ssh_channel_cb);
ssh_set_channel_callbacks(chan, &ssh_channel_cb);
@@ -434,15 +429,15 @@ static int client_mainloop(ssh_channel chan)
event = ssh_event_new();
if (event == NULL) {
- W("%s", "Couldn't get a event");
+ E2("%s", "Couldn't get a event");
return 1;
}
- if (ssh_event_add_fd(event, fd, events, copy_fd_to_chan, chan) != SSH_OK) {
- W("%s", "Couldn't add an fd to the event");
+ if (ssh_event_add_fd(event, fwd.fd, events, copy_fd_to_chan, chan) != SSH_OK) {
+ E2("Couldn't add fd %d to the event queue", fwd.fd);
return 1;
}
if (ssh_event_add_session(event, session) != SSH_OK) {
- W("%s", "Couldn't add the session to the event");
+ E2("%s", "Couldn't add the session to the event");
return 1;
}
@@ -450,7 +445,7 @@ static int client_mainloop(ssh_channel chan)
ssh_event_dopoll(event, 1000);
} while (!ssh_channel_is_closed(chan));
- ssh_event_remove_fd(event, fd);
+ ssh_event_remove_fd(event, fwd.fd);
ssh_event_remove_session(event, session);
ssh_event_free(event);
return 0;