aboutsummaryrefslogtreecommitdiff
path: root/src/pty.c
diff options
context:
space:
mode:
authorJulien Dessaux2018-06-20 13:23:48 +0200
committerJulien Dessaux2018-06-20 13:23:48 +0200
commit8c04f0d56d88ebea808d5505dcee07e8d197e360 (patch)
tree81f8e3f59c17ab234eb95c7812adb0054779a117 /src/pty.c
parentInitial import with working simple server based on libssh examples (diff)
downloadbastion-8c04f0d56d88ebea808d5505dcee07e8d197e360.tar.gz
bastion-8c04f0d56d88ebea808d5505dcee07e8d197e360.tar.bz2
bastion-8c04f0d56d88ebea808d5505dcee07e8d197e360.zip
Made a working ssh proxy server
Diffstat (limited to '')
-rw-r--r--src/pty.c128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/pty.c b/src/pty.c
deleted file mode 100644
index c888df3..0000000
--- a/src/pty.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include <pty.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <utmp.h>
-
-#include "pty.h"
-
-// callback function for SSH channel PTY request from a client
-int pty_request(ssh_session session, ssh_channel channel,
- const char *term, int cols, int rows, int py, int px,
- void *userdata) {
- struct channel_data_struct *cdata = (struct channel_data_struct *)userdata;
-
- (void) session;
- (void) channel;
- (void) term;
-
- cdata->winsize->ws_row = rows;
- cdata->winsize->ws_col = cols;
- cdata->winsize->ws_xpixel = px;
- cdata->winsize->ws_ypixel = py;
-
- if (openpty(&cdata->pty_master, &cdata->pty_slave, NULL, NULL,
- cdata->winsize) != 0) {
- fprintf(stderr, "Failed to open pty\n");
- return SSH_ERROR;
- }
- return SSH_OK;
-}
-
-// callback function for SSH channel PTY resize from a client
-int pty_resize(ssh_session session, ssh_channel channel, int cols,
- int rows, int py, int px, void *userdata) {
- struct channel_data_struct *cdata = (struct channel_data_struct *)userdata;
-
- (void) session;
- (void) channel;
-
- cdata->winsize->ws_row = rows;
- cdata->winsize->ws_col = cols;
- cdata->winsize->ws_xpixel = px;
- cdata->winsize->ws_ypixel = py;
-
- if (cdata->pty_master != -1) {
- return ioctl(cdata->pty_master, TIOCSWINSZ, cdata->winsize);
- }
-
- return SSH_ERROR;
-}
-
-int exec_pty(const char *mode, const char *command,
- struct channel_data_struct *cdata) {
- switch(cdata->pid = fork()) {
- case -1:
- close(cdata->pty_master);
- close(cdata->pty_slave);
- fprintf(stderr, "Failed to fork\n");
- return SSH_ERROR;
- case 0:
- close(cdata->pty_master);
- if (login_tty(cdata->pty_slave) != 0) {
- exit(1);
- }
- execl("/bin/sh", "sh", mode, command, NULL);
- exit(0);
- default:
- close(cdata->pty_slave);
- /* pty fd is bi-directional */
- cdata->child_stdout = cdata->child_stdin = cdata->pty_master;
- }
- return SSH_OK;
-}
-
-int exec_nopty(const char *command, struct channel_data_struct *cdata) {
- int in[2], out[2], err[2];
-
- /* Do the plumbing to be able to talk with the child process. */
- if (pipe(in) != 0) {
- goto stdin_failed;
- }
- if (pipe(out) != 0) {
- goto stdout_failed;
- }
- if (pipe(err) != 0) {
- goto stderr_failed;
- }
-
- switch(cdata->pid = fork()) {
- case -1:
- goto fork_failed;
- case 0:
- /* Finish the plumbing in the child process. */
- close(in[1]);
- close(out[0]);
- close(err[0]);
- dup2(in[0], STDIN_FILENO);
- dup2(out[1], STDOUT_FILENO);
- dup2(err[1], STDERR_FILENO);
- close(in[0]);
- close(out[1]);
- close(err[1]);
- /* exec the requested command. */
- execl("/bin/sh", "sh", "-c", command, NULL);
- exit(0);
- }
-
- close(in[0]);
- close(out[1]);
- close(err[1]);
-
- cdata->child_stdin = in[1];
- cdata->child_stdout = out[0];
- cdata->child_stderr = err[0];
-
- return SSH_OK;
-
-fork_failed:
- close(err[0]);
- close(err[1]);
-stderr_failed:
- close(out[0]);
- close(out[1]);
-stdout_failed:
- close(in[0]);
- close(in[1]);
-stdin_failed:
- return SSH_ERROR;
-}