Attempt to make doors, chat and files work with ssh

This commit is contained in:
Andrew Pamment 2016-08-07 13:45:52 +10:00
parent 23e3e30af7
commit 56a9505c6a
5 changed files with 51 additions and 22 deletions

View File

@ -110,6 +110,13 @@ void chat_system(struct user_record *user) {
char *message; char *message;
char *sep; char *sep;
char *target; char *target;
int chat_in;
if (sshBBS) {
chat_in = STDIN_FILENO;
} else {
chat_in = gSocket;
}
memset(inputbuffer, 0, 80); memset(inputbuffer, 0, 80);
if (conf.irc_server == NULL) { if (conf.irc_server == NULL) {
@ -152,20 +159,20 @@ void chat_system(struct user_record *user) {
while (1) { while (1) {
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(gSocket, &fds); FD_SET(chat_in, &fds);
FD_SET(chat_socket, &fds); FD_SET(chat_socket, &fds);
if (chat_socket > gSocket) { if (chat_socket > chat_in) {
t = chat_socket + 1; t = chat_socket + 1;
} else { } else {
t = gSocket + 1; t = chat_in + 1;
} }
ret = select(t, &fds, NULL, NULL, NULL); ret = select(t, &fds, NULL, NULL, NULL);
if (ret > 0) { if (ret > 0) {
if (FD_ISSET(gSocket, &fds)) { if (FD_ISSET(chat_in, &fds)) {
len = read(gSocket, &c, 1); len = read(chat_in, &c, 1);
if (len == 0) { if (len == 0) {
raw("QUIT\r\n"); raw("QUIT\r\n");
disconnect("Socket closed"); disconnect("Socket closed");

27
doors.c
View File

@ -140,6 +140,8 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
int t; int t;
struct winsize ws; struct winsize ws;
struct sigaction sa; struct sigaction sa;
int door_in;
int door_out;
timeoutpaused = 1; timeoutpaused = 1;
@ -148,11 +150,18 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
} }
if (stdio) { if (stdio) {
if (sshBBS) {
door_in = STDIN_FILENO;
door_out = STDOUT_FILENO;
} else {
door_in = gSocket;
door_out = gSocket;
}
arguments[0] = strdup(cmd); arguments[0] = strdup(cmd);
sprintf(buffer, "%d", mynode); sprintf(buffer, "%d", mynode);
arguments[1] = strdup(buffer); arguments[1] = strdup(buffer);
sprintf(buffer, "%d", gSocket); sprintf(buffer, "%d", door_out);
arguments[2] = strdup(buffer); arguments[2] = strdup(buffer);
arguments[3] = NULL; arguments[3] = NULL;
@ -192,16 +201,16 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
while(running_door != 0) { while(running_door != 0) {
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(master, &fdset); FD_SET(master, &fdset);
FD_SET(gSocket, &fdset); FD_SET(door_in, &fdset);
if (master > gSocket) { if (master > door_in) {
t = master + 1; t = master + 1;
} else { } else {
t = gSocket + 1; t = door_in + 1;
} }
ret = select(t, &fdset, NULL, NULL, NULL); ret = select(t, &fdset, NULL, NULL, NULL);
if (ret > 0) { if (ret > 0) {
if (FD_ISSET(gSocket, &fdset)) { if (FD_ISSET(door_in, &fdset)) {
len = read(gSocket, &c, 1); len = read(door_in, &c, 1);
if (len == 0) { if (len == 0) {
close(master); close(master);
disconnect("Socket Closed"); disconnect("Socket Closed");
@ -217,7 +226,7 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
close(master); close(master);
break; break;
} }
write(gSocket, &c, 1); write(door_out, &c, 1);
} }
} }
} }
@ -227,8 +236,12 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
free(arguments[1]); free(arguments[1]);
free(arguments[2]); free(arguments[2]);
} else { } else {
if (!sshBBS) {
sprintf(buffer, "%s %d %d", cmd, mynode, gSocket); sprintf(buffer, "%s %d %d", cmd, mynode, gSocket);
system(buffer); system(buffer);
} else {
s_printf("Non-STDIO door support on SSH is currently broken...\r\n");
}
} }
timeoutpaused = 0; timeoutpaused = 0;
} }

15
files.c
View File

@ -14,6 +14,7 @@
#include "lua/lauxlib.h" #include "lua/lauxlib.h"
extern struct bbs_config conf; extern struct bbs_config conf;
extern int gSocket; extern int gSocket;
extern int sshBBS;
struct file_entry { struct file_entry {
char *filename; char *filename;
@ -29,7 +30,7 @@ int ZXmitStr(u_char *str, int len, ZModem *info) {
int i; int i;
for (i=0;i<len;i++) { for (i=0;i<len;i++) {
if (str[i] == 255) { if (str[i] == 255 && !sshBBS) {
if (write(info->ofd, &str[i], 1) == 0) { if (write(info->ofd, &str[i], 1) == 0) {
return ZmErrSys; return ZmErrSys;
} }
@ -168,9 +169,13 @@ void upload_zmodem(struct user_record *user) {
zm.windowsize = 0; zm.windowsize = 0;
zm.bufsize = 0; zm.bufsize = 0;
if (!sshBBS) {
zm.ifd = gSocket; zm.ifd = gSocket;
zm.ofd = gSocket; zm.ofd = gSocket;
} else {
zm.ifd = STDIN_FILENO;
zm.ofd = STDOUT_FILENO;
}
zm.zrinitflags = 0; zm.zrinitflags = 0;
zm.zsinitflags = 0; zm.zsinitflags = 0;
@ -268,9 +273,13 @@ void download_zmodem(struct user_record *user, char *filename) {
zm.windowsize = 0; zm.windowsize = 0;
zm.bufsize = 0; zm.bufsize = 0;
if (!sshBBS) {
zm.ifd = gSocket; zm.ifd = gSocket;
zm.ofd = gSocket; zm.ofd = gSocket;
} else {
zm.ifd = STDIN_FILENO;
zm.ofd = STDOUT_FILENO;
}
zm.zrinitflags = 0; zm.zrinitflags = 0;
zm.zsinitflags = 0; zm.zsinitflags = 0;

View File

@ -7,7 +7,6 @@ extern int mynode;
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
extern int gSocket;
int l_bbsWString(lua_State *L) { int l_bbsWString(lua_State *L) {
char *str = (char *)lua_tostring(L, -1); char *str = (char *)lua_tostring(L, -1);

1
main.c
View File

@ -564,6 +564,7 @@ void serverssh(int port) {
if (bbs_pid == 0) { if (bbs_pid == 0) {
tcgetattr(STDIN_FILENO, &tios); tcgetattr(STDIN_FILENO, &tios);
tios.c_lflag &= ~(ICANON | ECHO | ECHONL); tios.c_lflag &= ~(ICANON | ECHO | ECHONL);
tios.c_iflag &= INLCR;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios); tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios);
runbbs_ssh(ip); runbbs_ssh(ip);
exit(0); exit(0);