More fixes for ssh

This commit is contained in:
Andrew Pamment 2016-12-11 23:17:43 +10:00
parent 48b478f9c3
commit 2c11107954

200
doors.c
View File

@ -194,86 +194,83 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
door_out = gSocket; door_out = gSocket;
} }
if (sshBBS && raw) {
ttySetRaw(STDIN_FILENO, &oldit);
ttySetRaw(STDOUT_FILENO, &oldot);
}
ws.ws_row = 24; ws.ws_row = 24;
ws.ws_col = 80; ws.ws_col = 80;
running_door = 1; running_door = 1;
if (openpty(&master, &slave, NULL, NULL, &ws) == 0) { if (!sshBBS) {
sa.sa_handler = doorchld_handler; if (openpty(&master, &slave, NULL, NULL, &ws) == 0) {
sigemptyset(&sa.sa_mask); sa.sa_handler = doorchld_handler;
sa.sa_flags = SA_RESTART | SA_SIGINFO; sigemptyset(&sa.sa_mask);
if (sigaction(SIGCHLD, &sa, NULL) == -1) { sa.sa_flags = SA_RESTART | SA_SIGINFO;
perror("sigaction"); if (sigaction(SIGCHLD, &sa, NULL) == -1) {
exit(1); perror("sigaction");
} exit(1);
if (raw) {
ttySetRaw(master, &oldit2);
ttySetRaw(slave, &oldit2);
}
pid = fork();
if (pid < 0) {
return;
} else if (pid == 0) {
if (cwd != NULL) {
chdir(cwd);
} }
close(master); if (raw) {
ttySetRaw(master, &oldit2);
dup2(slave, 0); ttySetRaw(slave, &oldit2);
dup2(slave, 1);
if (sshBBS) {
dup2(bbs_stderr, 2);
} }
pid = fork();
close(slave); if (pid < 0) {
return;
setsid(); } else if (pid == 0) {
if (cwd != NULL) {
ioctl(0, TIOCSCTTY, 1); chdir(cwd);
execvp(cmd, argv);
} else {
running_door_pid = pid;
gotiac = 0;
flush = 0;
while(running_door || !flush) {
FD_ZERO(&fdset);
FD_SET(master, &fdset);
FD_SET(door_in, &fdset);
if (master > door_in) {
t = master + 1;
} else {
t = door_in + 1;
} }
close(master);
thetimeout.tv_sec = 5; dup2(slave, 0);
thetimeout.tv_usec = 0; dup2(slave, 1);
ret = select(t, &fdset, NULL, NULL, &thetimeout); close(slave);
if (ret > 0) {
if (FD_ISSET(door_in, &fdset)) { setsid();
len = read(door_in, &c, 1);
if (len == 0) { ioctl(0, TIOCSCTTY, 1);
close(master);
disconnect("Socket Closed"); execvp(cmd, argv);
return; } else {
} running_door_pid = pid;
if (!raw) { gotiac = 0;
if (c == '\n' || c == '\0') { flush = 0;
close(slave);
while(running_door || !flush) {
FD_ZERO(&fdset);
FD_SET(master, &fdset);
FD_SET(door_in, &fdset);
if (master > door_in) {
t = master + 1;
} else {
t = door_in + 1;
}
thetimeout.tv_sec = 5;
thetimeout.tv_usec = 0;
ret = select(t, &fdset, NULL, NULL, &thetimeout);
if (ret > 0) {
if (FD_ISSET(door_in, &fdset)) {
len = read(door_in, &c, 1);
if (len == 0) {
close(master);
disconnect("Socket Closed");
return;
}
if (!raw) {
if (c == '\n' || c == '\0') {
continue;
}
}
if (!running_door) {
continue; continue;
} }
}
if (!running_door) {
continue;
}
if (!sshBBS) {
if (c == 255) { if (c == 255) {
if (gotiac == 1) { if (gotiac == 1) {
write(master, &c, 1); write(master, &c, 1);
@ -289,33 +286,62 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c
gotiac = 0; gotiac = 0;
} }
} }
} else { } else if (FD_ISSET(master, &fdset)) {
write(master, &c, 1); len = read(master, &c, 1);
} if (len == 0) {
} else if (FD_ISSET(master, &fdset)) { close(master);
len = read(master, &c, 1); break;
if (len == 0) { }
close(master); if (c == 255) {
break; write(door_out, &c, 1);
} }
if (c == 255 && !sshBBS) {
write(door_out, &c, 1); write(door_out, &c, 1);
} }
write(door_out, &c, 1); } else {
} if (!running_door) {
} else { flush = 1;
if (!running_door) { }
flush = 1;
} }
} }
close(master);
} }
} }
}
if (sshBBS && raw) {
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
}
} else {
if (raw) {
ttySetRaw(STDIN_FILENO, &oldit);
ttySetRaw(STDOUT_FILENO, &oldot);
}
sa.sa_handler = doorchld_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
perror("sigaction");
exit(1);
}
pid = fork();
if (pid < 0) {
return;
} else if (pid == 0) {
if (cwd != NULL) {
chdir(cwd);
}
dup2(bbs_stderr, 2);
execvp(cmd, argv);
} else {
while(running_door) {
sleep(1);
}
}
if (raw) {
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
}
}
} else { } else {
if (!sshBBS) { if (!sshBBS) {
snprintf(buffer, 1024, "%s", cmd); snprintf(buffer, 1024, "%s", cmd);