aboutsummaryrefslogtreecommitdiff
path: root/src/protocol_ssh.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2018-05-14 13:38:24 +0200
committerToni Uhlig <matzeton@googlemail.com>2018-05-14 13:38:24 +0200
commitb02a48ca725ea99950d7af2f9c152c3bafacebe8 (patch)
tree3788c32508f9d04016594dc6f5c27e6c75b10b99 /src/protocol_ssh.c
parentee9f7bafbb2a8dd2ecd794b2d78e90022ef139fe (diff)
POTD skeleton #51.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/protocol_ssh.c')
-rw-r--r--src/protocol_ssh.c35
1 files changed, 15 insertions, 20 deletions
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;