From 3778cdb66b7a7fc3e6dd43be0bb0da0c5f3f0d7a Mon Sep 17 00:00:00 2001 From: lns Date: Sun, 22 Apr 2018 13:00:31 +0200 Subject: POTD skeleton #23. Signed-off-by: lns --- src/server_ssh.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/server_ssh.c') diff --git a/src/server_ssh.c b/src/server_ssh.c index c84f718..474b5ab 100644 --- a/src/server_ssh.c +++ b/src/server_ssh.c @@ -12,6 +12,7 @@ #include #include "server_ssh.h" +#include "jail.h" #include "log.h" #if LIBSSH_VERSION_MAJOR != 0 || LIBSSH_VERSION_MINOR < 7 || \ @@ -412,6 +413,12 @@ static int main_loop(ssh_channel chan) pid_t childpid; ssh_event event; short events; + jail_ctx jail, *jail_ptr = &jail; + + jail_init(&jail_ptr, BUFSIZ); + if (jail_fork(jail_ptr)) { + E_STRERR("Jail fork"); + } childpid = forkpty(&fd, NULL, term, win); if (childpid == 0) { @@ -424,29 +431,27 @@ static int main_loop(ssh_channel chan) ssh_set_channel_callbacks(chan, &ssh_channel_cb); events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; - event = ssh_event_new(); + if (event == NULL) { - printf("Couldn't get a event\n"); - return -1; + W("%s", "Couldn't get a event"); + return 1; } if (ssh_event_add_fd(event, fd, events, copy_fd_to_chan, chan) != SSH_OK) { - printf("Couldn't add an fd to the event\n"); - return -1; + W("%s", "Couldn't add an fd to the event"); + return 1; } if (ssh_event_add_session(event, session) != SSH_OK) { - printf("Couldn't add the session to the event\n"); - return -1; + W("%s", "Couldn't add the session to the event"); + return 1; } do { ssh_event_dopoll(event, 1000); - } while(!ssh_channel_is_closed(chan)); + } while (!ssh_channel_is_closed(chan)); ssh_event_remove_fd(event, fd); - ssh_event_remove_session(event, session); - ssh_event_free(event); return 0; } -- cgit v1.2.3