diff --git a/bluewave.c b/bluewave.c index c48d800..35dbd6a 100644 --- a/bluewave.c +++ b/bluewave.c @@ -13,6 +13,9 @@ extern struct user_record *gUser; extern int mynode; extern char upload_filename[1024]; extern int sshBBS; +extern int bbs_stdin; +extern int bbs_stdout; +extern int bbs_stderr; tLONG convertl(tLONG l) { #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -103,15 +106,30 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file break; } - if (strcasecmp(msghs->msgs[k]->to, gUser->loginname) == 0) { - personal_msgs++; + if (msghs->msgs[k]->to != NULL) { + if (strcasecmp(msghs->msgs[k]->to, gUser->loginname) == 0) { + personal_msgs++; + } } memset(&fti, 0, sizeof(FTI_REC)); - strncpy(fti.from, msghs->msgs[k]->from, 35); - strncpy(fti.to, msghs->msgs[k]->to, 35); - strncpy(fti.subject, msghs->msgs[k]->subject, 71); + if (msghs->msgs[k]->from != NULL) { + strncpy(fti.from, msghs->msgs[k]->from, 35); + } else { + sprintf(fti.from, "(Missing From)"); + } + if (msghs->msgs[k]->to != NULL) { + strncpy(fti.to, msghs->msgs[k]->to, 35); + } else { + sprintf(fti.to, "(Missing To)"); + } + + if (msghs->msgs[k]->subject != NULL) { + strncpy(fti.subject, msghs->msgs[k]->subject, 71); + } else { + sprintf(fti.subject, "(Missing Subject)"); + } localtime_r((time_t *)&msghs->msgs[k]->msg_h->DateWritten, &timeStruct); @@ -187,6 +205,9 @@ void bwave_create_packet() { int lasttot; int bpos; int last_ptr = 0; + int stout; + int stin; + int sterr; struct termios oldit; struct termios oldot; @@ -251,7 +272,9 @@ void bwave_create_packet() { for (j=0;jmail_area_count;j++) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level <= gUser->sec_level && conf.mail_conferences[i]->mail_areas[j]->qwkname != NULL) { lasttot = totmsgs; + printf("Scan Started\n"); totmsgs = bwave_scan_area(i, j, area_count+1, totmsgs, fti_file, mix_file, dat_file, &last_ptr); + printf("Scan complete\n"); s_printf(get_string(195), conf.mail_conferences[i]->name, conf.mail_conferences[i]->mail_areas[j]->name, totmsgs - lasttot); if (lasttot == totmsgs) { continue; @@ -354,7 +377,27 @@ void bwave_create_packet() { buffer[bpos] = '\0'; } } + if (sshBBS) { + stout = dup(STDOUT_FILENO); + stin = dup(STDIN_FILENO); + sterr = dup(STDERR_FILENO); + + dup2(bbs_stdout, STDOUT_FILENO); + dup2(bbs_stderr, STDERR_FILENO); + dup2(bbs_stdin, STDIN_FILENO); + } system(buffer); + + if (sshBBS) { + + dup2(stout, STDOUT_FILENO); + dup2(sterr, STDERR_FILENO); + dup2(stin, STDIN_FILENO); + + close(stin); + close(stout); + close(sterr); + } do_download(gUser, archive); @@ -563,6 +606,9 @@ void bwave_upload_reply() { FILE *msg_file; int sem_fd; int msg_count; + int stout; + int stin; + int sterr; msg_count = 0; @@ -604,8 +650,28 @@ void bwave_upload_reply() { buffer[bpos] = '\0'; } } + if (sshBBS) { + stout = dup(STDOUT_FILENO); + stin = dup(STDIN_FILENO); + sterr = dup(STDERR_FILENO); + + dup2(bbs_stdout, STDOUT_FILENO); + dup2(bbs_stderr, STDERR_FILENO); + dup2(bbs_stdin, STDIN_FILENO); + } system(buffer); + if (sshBBS) { + + dup2(stout, STDOUT_FILENO); + dup2(sterr, STDERR_FILENO); + dup2(stin, STDIN_FILENO); + + close(stin); + close(stout); + close(sterr); + } + unlink(upload_filename); snprintf(buffer, 1024, "%s/node%d/bwave/%s.UPL", conf.bbs_path, mynode, conf.bwave_name); diff --git a/doors.c b/doors.c index 348dc3a..77f7978 100644 --- a/doors.c +++ b/doors.c @@ -8,6 +8,7 @@ #include #include #include +#include #if defined(linux) # include #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) @@ -24,7 +25,7 @@ extern struct bbs_config conf; extern int mynode; extern int gSocket; extern int sshBBS; - +extern int bbs_stderr; int running_door_pid = 0; int running_door = 0; @@ -172,8 +173,12 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c int i; int gotiac; int flush; + struct timeval thetimeout; struct termios oldit; + struct termios oldot; + struct termios oldit2; + timeoutpaused = 1; if (write_door32sys(user) != 0) { @@ -189,6 +194,11 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c door_out = gSocket; } + if (sshBBS && raw) { + ttySetRaw(STDIN_FILENO, &oldit); + ttySetRaw(STDOUT_FILENO, &oldot); + } + ws.ws_row = 24; ws.ws_col = 80; @@ -203,8 +213,8 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c exit(1); } if (raw) { - ttySetRaw(master, &oldit); - ttySetRaw(slave, &oldit); + ttySetRaw(master, &oldit2); + ttySetRaw(slave, &oldit2); } pid = fork(); if (pid < 0) { @@ -214,9 +224,13 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c chdir(cwd); } close(master); - dup2(slave, 0); - dup2(slave, 1); + dup2(slave, 0); + dup2(slave, 1); + if (sshBBS) { + dup2(bbs_stderr, 2); + } + close(slave); setsid(); @@ -241,6 +255,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c thetimeout.tv_sec = 5; thetimeout.tv_usec = 0; + ret = select(t, &fdset, NULL, NULL, &thetimeout); if (ret > 0) { if (FD_ISSET(door_in, &fdset)) { @@ -258,20 +273,24 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c if (!running_door) { continue; } - if (c == 255) { - if (gotiac == 1) { - write(master, &c, 1); - gotiac = 0; + if (!sshBBS) { + if (c == 255) { + if (gotiac == 1) { + write(master, &c, 1); + gotiac = 0; + } else { + gotiac = 1; + } } else { - gotiac = 1; + if (gotiac < 2 && gotiac != 0) { + gotiac++; + } else { + write(master, &c, 1); + gotiac = 0; + } } } else { - if (gotiac < 2 && gotiac != 0) { - gotiac++; - } else { - write(master, &c, 1); - gotiac = 0; - } + write(master, &c, 1); } } else if (FD_ISSET(master, &fdset)) { len = read(master, &c, 1); @@ -279,7 +298,7 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c close(master); break; } - if (c == 255) { + if (c == 255 && !sshBBS) { write(door_out, &c, 1); } write(door_out, &c, 1); @@ -292,6 +311,10 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c } } } + if (sshBBS && raw) { + tcsetattr(STDIN_FILENO, TCSANOW, &oldit); + tcsetattr(STDOUT_FILENO, TCSANOW, &oldot); + } } else { if (!sshBBS) { diff --git a/files.c b/files.c index 6cba91e..f4298a9 100644 --- a/files.c +++ b/files.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "Xmodem/zmodem.h" #include "bbs.h" #include "lua/lua.h" @@ -18,6 +19,9 @@ extern struct bbs_config conf; extern int gSocket; extern int sshBBS; extern int mynode; +extern int bbs_stdin; +extern int bbs_stdout; +extern int bbs_stderr; struct file_entry { char *filename; @@ -229,7 +233,10 @@ char *get_file_id_diz(char *filename) { int len; int ext; int arch; - + int stout; + int stin; + int sterr; + ext = 0; arch = -1; @@ -289,8 +296,29 @@ char *get_file_id_diz(char *filename) { buffer[bpos] = '\0'; } } + + if (sshBBS) { + stout = dup(STDOUT_FILENO); + stin = dup(STDIN_FILENO); + sterr = dup(STDERR_FILENO); + + dup2(bbs_stdout, STDOUT_FILENO); + dup2(bbs_stderr, STDERR_FILENO); + dup2(bbs_stdin, STDIN_FILENO); + } system(buffer); + if (sshBBS) { + + dup2(stout, STDOUT_FILENO); + dup2(sterr, STDERR_FILENO); + dup2(stin, STDIN_FILENO); + + close(stin); + close(stout); + close(sterr); + } + snprintf(buffer, 1024, "%s/node%d/temp/FILE_ID.DIZ", conf.bbs_path, mynode); if (stat(buffer, &s) != 0) { snprintf(buffer, 1024, "%s/node%d/temp/file_id.diz", conf.bbs_path, mynode); @@ -502,10 +530,6 @@ int do_upload(struct user_record *user, char *final_path) { } arguments[bpos] = NULL; - for (i=0;istatus = IP_STATUS_UNKNOWN; + ip_guard->last_connection = time(NULL); + ip_guard->connection_count = 1; + hashmap_put(ip_guard_map, strdup(ip), ip_guard); + } else if (i == MAP_OK) { + + if (ip_guard->status == IP_STATUS_BLACKLISTED) { + free(ip); + ssh_disconnect(p_ssh_session); + continue; + } else if (ip_guard->status == IP_STATUS_UNKNOWN) { + if (ip_guard->last_connection + conf.ipguard_timeout > time(NULL)) { + ip_guard->connection_count++; + if (ip_guard->connection_count == conf.ipguard_tries) { + ip_guard->status = IP_STATUS_BLACKLISTED; + snprintf(buffer, 1024, "%s/blacklist.ip", conf.bbs_path); + fptr = fopen(buffer, "a"); + fprintf(fptr, "%s\n", ip); + fclose(fptr); + free(ip); + ssh_disconnect(p_ssh_session); + continue; + + } + } else { + ip_guard->connection_count = 0; + ip_guard->last_connection = time(NULL); + } + } + } + } + pid = fork(); if (pid == 0) { if (ssh_handle_key_exchange(p_ssh_session)) { @@ -753,7 +803,7 @@ void serverssh(int port) { exit(-1); } - ip = ssh_getip(p_ssh_session); +