From 8e6667ed4ff5f9fb407ab0222abfb0f4d9238614 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 7 Aug 2016 15:43:29 +1000 Subject: [PATCH] fixes for disconnecting ssh without logging out --- bbs.c | 6 +++--- main.c | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bbs.c b/bbs.c index 7960810..e0a660b 100644 --- a/bbs.c +++ b/bbs.c @@ -15,7 +15,7 @@ #include "lua/lualib.h" #include "lua/lauxlib.h" -int mynode; +int mynode = 0; struct bbs_config conf; struct user_record *gUser; @@ -508,8 +508,7 @@ void runbbs_real(int socket, char *ip, int ssh) { s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR); // find out which node we are - mynode = 0; - for (i=1;i<=conf.nodes;i++) { + for (i=1;i<=conf.nodes;i++) { sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, i); if (stat(buffer, &s) != 0) { mynode = i; @@ -710,6 +709,7 @@ void runbbs(int socket, char *ip) { } void runbbs_ssh(char *ip) { + setbuf(stdin, NULL); setbuf(stdout, NULL); runbbs_real(-1, ip, 1); } diff --git a/main.c b/main.c index e115efc..562b855 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,7 @@ extern struct bbs_config conf; extern struct user_record *gUser; +extern int mynode; int ssh_pid = -1; @@ -446,10 +447,14 @@ static int ssh_copy_chan_to_fd(ssh_session session, } static void ssh_chan_close(ssh_session session, ssh_channel channel, void *userdata) { - int fd = *(int*)userdata; + int fd = *(int*)userdata; (void)session; (void)channel; + if (mynode != 0) { + disconnect("Channel Closed"); + } + close(fd); }