Merge pull request #14 from MagickaBBS/dualstack

Dualstack
This commit is contained in:
Andrew Pamment 2018-01-19 11:15:47 +10:00 committed by GitHub
commit 6dbd32b7bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 192 additions and 70 deletions

11
.gitignore vendored
View File

@ -64,3 +64,14 @@ utils/magimail/bin/magimail
utils/magimail/bin/magimaint utils/magimail/bin/magimaint
utils/magimail/bin/magistats utils/magimail/bin/magistats
utils/magimail/bin/magiwrite utils/magimail/bin/magiwrite
keys/ssh_host_dsa_key
magicka.strings
www
keys/ssh_host_dsa_key.pub
keys/ssh_host_rsa_key
keys/ssh_host_rsa_key.pub
menus/doors.mnu
menus/file.mnu
menus/logoff.mnu
menus/mail.mnu
menus/main.mnu

Binary file not shown.

1
dist/config/bbs.ini vendored
View File

@ -31,6 +31,7 @@ IP Guard Timeout = 120
IP Guard Tries = 4 IP Guard Tries = 4
Root Menu = main Root Menu = main
Date Style = EU Date Style = EU
Enable IPv6 = true
[paths] [paths]
Config Path = /home/andrew/MagickaBBS/config Config Path = /home/andrew/MagickaBBS/config

View File

@ -61,15 +61,23 @@ printstuff "Please enter the name of your BBS:"
read -e bbsname read -e bbsname
sed -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/bbs.ini PLATFORM=`uname`
sed -i "s/BBS Name = Magicka BBS/BBS Name = ${bbsname}/g" config/bbs.ini
sed -i "s/Sysop Name = sysop/Sysop Name = ${handle}/g" config/bbs.ini if [[ "$PLATFORM" == 'FreeBSD' ]] || [[ "$PLATFORM" == 'Darwin' ]] || [[ "$PLATFORM" == 'DragonFly' ]]; then
sed -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/localmail.ini SED=gsed
sed -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/filesgen.ini else
sed -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/illusionnet.ini SED=sed
sed -i "s@/home/andrew/MagickaBBS@${PWD}@g" utils/magiedit/magiedit.sh fi
sed -i "s@/home/andrew/MagickaBBS@${PWD}@g" scripts/login_stanza.lua
sed -i "s/MagiChat Server = localhost/; MagiChat Server = localhost/g" config/bbs.ini $SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/bbs.ini
sed -i "s/Default Tagline = Brought to you by Another Magicka BBS!/Default Tagline = ${bbsname}/g" config/bbs.ini $SED -i "s/BBS Name = Magicka BBS/BBS Name = ${bbsname}/g" config/bbs.ini
sed -i "s/echomail.out/mail.out/g" config/bbs.ini $SED -i "s/Sysop Name = sysop/Sysop Name = ${handle}/g" config/bbs.ini
sed -i "s/netmail.out/mail.out/g" config/bbs.ini $SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/localmail.ini
$SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/filesgen.ini
$SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/illusionnet.ini
$SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" utils/magiedit/magiedit.sh
$SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" scripts/login_stanza.lua
$SED -i "s/MagiChat Server = localhost/; MagiChat Server = localhost/g" config/bbs.ini
$SED -i "s/Default Tagline = Brought to you by Another Magicka BBS!/Default Tagline = ${bbsname}/g" config/bbs.ini
$SED -i "s/echomail.out/mail.out/g" config/bbs.ini
$SED -i "s/netmail.out/mail.out/g" config/bbs.ini

View File

@ -12,7 +12,7 @@
#include "jamlib/jam.h" #include "jamlib/jam.h"
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 7 #define VERSION_MINOR 8
#define VERSION_STR "alpha" #define VERSION_STR "alpha"
#define NETWORK_FIDO 1 #define NETWORK_FIDO 1
@ -115,6 +115,7 @@ struct ip_address_guard {
struct bbs_config { struct bbs_config {
int codepage; int codepage;
int ipv6;
char *bbs_name; char *bbs_name;
char *bwave_name; char *bwave_name;
char *sysop_name; char *sysop_name;

View File

@ -410,6 +410,12 @@ static int handler(void* user, const char* section, const char* name,
conf->ssh_server = 1; conf->ssh_server = 1;
} else { } else {
conf->ssh_server = 0; conf->ssh_server = 0;
}
} else if (strcasecmp(name, "enable ipv6") == 0) {
if (strcasecmp(value, "true") == 0) {
conf->ipv6 = 1;
} else {
conf->ipv6 = 0;
} }
} else if (strcasecmp(name, "enable www") == 0) { } else if (strcasecmp(name, "enable www") == 0) {
if (strcasecmp(value, "true") == 0) { if (strcasecmp(value, "true") == 0) {
@ -680,7 +686,7 @@ struct ssh_channel_callbacks_struct ssh_cb = {
.userdata = NULL .userdata = NULL
}; };
void serverssh(int port) { void serverssh(int port, int ipv6) {
ssh_session p_ssh_session; ssh_session p_ssh_session;
ssh_bind p_ssh_bind; ssh_bind p_ssh_bind;
int err; int err;
@ -698,6 +704,8 @@ void serverssh(int port) {
char buffer[1024]; char buffer[1024];
FILE *fptr; FILE *fptr;
struct sockaddr_in6 server, client; struct sockaddr_in6 server, client;
struct sockaddr_in server4, client4;
void *server_p, *client_p;
int ssh_sock, csock, c; int ssh_sock, csock, c;
int on = 1; int on = 1;
char str[INET6_ADDRSTRLEN]; char str[INET6_ADDRSTRLEN];
@ -722,8 +730,11 @@ void serverssh(int port) {
ssh_bind_options_set(p_ssh_bind, SSH_BIND_OPTIONS_RSAKEY, conf.ssh_rsa_key); ssh_bind_options_set(p_ssh_bind, SSH_BIND_OPTIONS_RSAKEY, conf.ssh_rsa_key);
//ssh_bind_listen(p_ssh_bind); //ssh_bind_listen(p_ssh_bind);
if (ipv6) {
ssh_sock = socket(AF_INET6, SOCK_STREAM, 0); ssh_sock = socket(AF_INET6, SOCK_STREAM, 0);
} else {
ssh_sock = socket(AF_INET, SOCK_STREAM, 0);
}
if (ssh_sock == -1) { if (ssh_sock == -1) {
fprintf(stderr, "Error starting SSH server.\n"); fprintf(stderr, "Error starting SSH server.\n");
exit(-1); exit(-1);
@ -735,20 +746,43 @@ void serverssh(int port) {
exit(-1); exit(-1);
} }
memset(&server, 0, sizeof(server)); if (ipv6) {
if (setsockopt(ssh_sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
}
memset(&server, 0, sizeof(server));
server.sin6_family = AF_INET6;
server.sin6_addr = in6addr_any;
server.sin6_port = htons(port);
server.sin6_family = AF_INET6; server_p = &server;
server.sin6_addr = in6addr_any; client_p = &client;
server.sin6_port = htons(port);
if (bind(ssh_sock, (struct sockaddr *)&server, sizeof(server)) < 0) { if (bind(ssh_sock, (struct sockaddr *)server_p, sizeof(struct sockaddr_in6)) < 0) {
perror("Bind Failed, Error\n"); perror("Bind Failed, Error\n");
exit(1); exit(1);
}
c = sizeof(struct sockaddr_in6);
} else {
memset(&server4, 0, sizeof(server4));
server4.sin_family = AF_INET;
server4.sin_addr.s_addr = INADDR_ANY;
server4.sin_port = htons(port);
server_p = &server4;
client_p = &client4;
if (bind(ssh_sock, (struct sockaddr *)server_p, sizeof(struct sockaddr_in)) < 0) {
perror("Bind Failed, Error\n");
exit(1);
}
c = sizeof(struct sockaddr_in);
} }
listen(ssh_sock, 3); listen(ssh_sock, 3);
c = sizeof(struct sockaddr_in6);
while ((csock = accept(ssh_sock, (struct sockaddr *)&client, (socklen_t *)&c))) { while ((csock = accept(ssh_sock, (struct sockaddr *)client_p, (socklen_t *)&c))) {
p_ssh_session = ssh_new(); p_ssh_session = ssh_new();
if (p_ssh_session == NULL) { if (p_ssh_session == NULL) {
fprintf(stderr, "Error starting SSH session.\n"); fprintf(stderr, "Error starting SSH session.\n");
@ -756,8 +790,11 @@ void serverssh(int port) {
continue; continue;
} }
if (ssh_bind_accept_fd(p_ssh_bind, p_ssh_session, csock) == SSH_OK) { if (ssh_bind_accept_fd(p_ssh_bind, p_ssh_session, csock) == SSH_OK) {
ip = strdup(inet_ntop(AF_INET6, &client.sin6_addr, str, sizeof(str))); if (ipv6) {
ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str)));
} else {
ip = strdup(inet_ntop(AF_INET, &((struct sockaddr_in *)client_p)->sin_addr, str, sizeof(str)));
}
if (conf.ipguard_enable) { if (conf.ipguard_enable) {
i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard)); i = hashmap_get(ip_guard_map, ip, (void **)(&ip_guard));
@ -778,7 +815,7 @@ void serverssh(int port) {
ip_guard->connection_count++; ip_guard->connection_count++;
if (ip_guard->connection_count == conf.ipguard_tries) { if (ip_guard->connection_count == conf.ipguard_tries) {
ip_guard->status = IP_STATUS_BLACKLISTED; ip_guard->status = IP_STATUS_BLACKLISTED;
snprintf(buffer, 1024, "%s/blacklist.ip", conf.bbs_path); snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
fptr = fopen(buffer, "a"); fptr = fopen(buffer, "a");
fprintf(fptr, "%s\n", ip); fprintf(fptr, "%s\n", ip);
fclose(fptr); fclose(fptr);
@ -910,7 +947,7 @@ void serverssh(int port) {
} }
} }
void server(int port) { void server(int port, int ipv6) {
struct sigaction sa; struct sigaction sa;
struct sigaction st; struct sigaction st;
struct sigaction sq; struct sigaction sq;
@ -918,6 +955,8 @@ void server(int port) {
int pid; int pid;
char *ip; char *ip;
struct sockaddr_in6 server, client; struct sockaddr_in6 server, client;
struct sockaddr_in server4, client4;
void *client_p, *server_p;
FILE *fptr; FILE *fptr;
char buffer[1024]; char buffer[1024];
struct ip_address_guard *ip_guard; struct ip_address_guard *ip_guard;
@ -929,25 +968,11 @@ void server(int port) {
www_daemon = NULL; www_daemon = NULL;
#endif #endif
if (!conf.fork) {
printf("Magicka BBS Server Starting....\n");
}
for (i=1;i<=conf.nodes;i++) {
snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) {
if (!conf.fork) {
printf(" - Removing stale file: nodeinuse.%d\n", i);
}
unlink(buffer);
}
}
if (conf.ipguard_enable) { if (conf.ipguard_enable) {
ip_guard_map = hashmap_new(); ip_guard_map = hashmap_new();
snprintf(buffer, 1024, "%s/whitelist.ip", conf.bbs_path); snprintf(buffer, 1024, "%s/whitelist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
fptr = fopen(buffer, "r"); fptr = fopen(buffer, "r");
if (fptr) { if (fptr) {
@ -970,7 +995,7 @@ void server(int port) {
} }
fclose(fptr); fclose(fptr);
} }
snprintf(buffer, 1024, "%s/blacklist.ip", conf.bbs_path); snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
fptr = fopen(buffer, "r"); fptr = fopen(buffer, "r");
if (fptr) { if (fptr) {
@ -1023,7 +1048,7 @@ void server(int port) {
if (conf.ssh_server) { if (conf.ssh_server) {
if (!conf.fork) { if (!conf.fork) {
printf(" - SSH Starting on Port %d\n", conf.ssh_port); printf(" - SSH Starting on Port %d (IPv%d)\n", conf.ssh_port, (ipv6 ? 6 : 4));
} }
// fork ssh server // fork ssh server
@ -1031,7 +1056,7 @@ void server(int port) {
if (ssh_pid == 0) { if (ssh_pid == 0) {
ssh_pid = -1; ssh_pid = -1;
serverssh(conf.ssh_port); serverssh(conf.ssh_port, ipv6);
exit(0); exit(0);
} }
if (ssh_pid < 0) { if (ssh_pid < 0) {
@ -1042,20 +1067,29 @@ void server(int port) {
#if defined(ENABLE_WWW) #if defined(ENABLE_WWW)
if (conf.www_server && conf.www_path != NULL) { if (conf.www_server && conf.www_path != NULL) {
if (!conf.fork) { if (!conf.fork) {
printf(" - HTTP Starting on Port %d\n", conf.www_port); printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4));
} }
www_init(); www_init();
www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION|MHD_USE_DUAL_STACK, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); if (ipv6) {
www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION|MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END);
} else {
www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END);
}
} }
#endif #endif
server_socket = socket(AF_INET6, SOCK_STREAM, 0); if (ipv6) {
server_socket = socket(AF_INET6, SOCK_STREAM, 0);
} else {
server_socket = socket(AF_INET, SOCK_STREAM, 0);
}
if (server_socket == -1) { if (server_socket == -1) {
remove(conf.pid_file); remove(conf.pid_file);
fprintf(stderr, "Couldn't create socket..\n"); fprintf(stderr, "Couldn't create socket..\n");
exit(1); exit(1);
} }
if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
remove(conf.pid_file); remove(conf.pid_file);
@ -1063,28 +1097,55 @@ void server(int port) {
exit(1); exit(1);
} }
memset(&server, 0, sizeof(server));
server.sin6_family = AF_INET6;
server.sin6_addr = in6addr_any;
server.sin6_port = htons(port);
if (!conf.fork) { if (!conf.fork) {
printf(" - Telnet Starting on Port %d\n", port); printf(" - Telnet Starting on Port %d (IPv%d)\n", port, (ipv6 ? 6 : 4));
} }
if (bind(server_socket, (struct sockaddr *)&server, sizeof(server)) < 0) {
perror("Bind Failed, Error\n"); if (ipv6) {
remove(conf.pid_file); if (setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) < 0) {
exit(1); fprintf(stderr, "setsockopt(IPV6_V6ONLY) failed");
}
memset(&server, 0, sizeof(server));
server.sin6_family = AF_INET6;
server.sin6_addr = in6addr_any;
server.sin6_port = htons(port);
if (bind(server_socket, (struct sockaddr *)&server, sizeof(server)) < 0) {
perror("Bind Failed, Error\n");
remove(conf.pid_file);
exit(1);
}
c = sizeof(struct sockaddr_in6);
server_p = &server;
client_p = &client;
} else {
memset(&server4, 0, sizeof(server4));
server4.sin_family = AF_INET;
server4.sin_addr.s_addr = INADDR_ANY;
server4.sin_port = htons(port);
if (bind(server_socket, (struct sockaddr *)&server4, sizeof(server4)) < 0) {
perror("Bind Failed, Error\n");
remove(conf.pid_file);
exit(1);
}
c = sizeof(struct sockaddr_in);
server_p = &server4;
client_p = &client4;
} }
listen(server_socket, 3); listen(server_socket, 3);
c = sizeof(struct sockaddr_in6);
while ((client_sock = accept(server_socket, (struct sockaddr *)&client, (socklen_t *)&c))) { while ((client_sock = accept(server_socket, (struct sockaddr *)client_p, (socklen_t *)&c))) {
ip = strdup(inet_ntop(AF_INET6, &client.sin6_addr, str, sizeof(str))); if (ipv6) {
ip = strdup(inet_ntop(AF_INET6, &((struct sockaddr_in6 *)client_p)->sin6_addr, str, sizeof(str)));
} else {
ip = strdup(inet_ntop(AF_INET, &((struct sockaddr_in *)client_p)->sin_addr, str, sizeof(str)));
}
if (client_sock == -1) { if (client_sock == -1) {
if (errno == EINTR) { if (errno == EINTR) {
continue; continue;
@ -1114,7 +1175,7 @@ void server(int port) {
ip_guard->connection_count++; ip_guard->connection_count++;
if (ip_guard->connection_count == conf.ipguard_tries) { if (ip_guard->connection_count == conf.ipguard_tries) {
ip_guard->status = IP_STATUS_BLACKLISTED; ip_guard->status = IP_STATUS_BLACKLISTED;
snprintf(buffer, 1024, "%s/blacklist.ip", conf.bbs_path); snprintf(buffer, 1024, "%s/blacklist.ip%d", conf.bbs_path, (ipv6 ? 6 : 4));
fptr = fopen(buffer, "a"); fptr = fopen(buffer, "a");
fprintf(fptr, "%s\n", ip); fprintf(fptr, "%s\n", ip);
fclose(fptr); fclose(fptr);
@ -1153,7 +1214,7 @@ void server(int port) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i; int i;
int main_pid; int main_pid, ipv6_pid;
FILE *fptr; FILE *fptr;
struct stat s; struct stat s;
char buffer[1024]; char buffer[1024];
@ -1191,7 +1252,8 @@ int main(int argc, char **argv) {
conf.protocol_count = 0; conf.protocol_count = 0;
conf.codepage = 0; conf.codepage = 0;
conf.date_style = 0; conf.date_style = 0;
conf.ipv6 = 0;
// Load BBS data // Load BBS data
if (ini_parse(argv[1], handler, &conf) <0) { if (ini_parse(argv[1], handler, &conf) <0) {
fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
@ -1266,9 +1328,48 @@ int main(int argc, char **argv) {
fclose(fptr); fclose(fptr);
} }
} else { } else {
server(conf.telnet_port); for (i=1;i<=conf.nodes;i++) {
snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) {
unlink(buffer);
}
}
if (conf.ipv6) {
ipv6_pid = fork();
if (ipv6_pid < 0) {
fprintf(stderr, "Error forking.\n");
exit(-1);
} else if (ipv6_pid > 0) {
server(conf.telnet_port, 0);
} else {
server(conf.telnet_port, 1);
}
} else {
server(conf.telnet_port, 0);
}
} }
} else { } else {
server(conf.telnet_port); printf("Magicka BBS Server Starting....\n");
for (i=1;i<=conf.nodes;i++) {
snprintf(buffer, 1024, "%s/nodeinuse.%d", conf.bbs_path, i);
if (stat(buffer, &s) == 0) {
printf(" - Removing stale file: nodeinuse.%d\n", i);
unlink(buffer);
}
}
if (conf.ipv6) {
ipv6_pid = fork();
if (ipv6_pid < 0) {
fprintf(stderr, "Error forking.\n");
exit(-1);
} else if (ipv6_pid > 0) {
server(conf.telnet_port, 0);
} else {
server(conf.telnet_port, 1);
}
} else {
server(conf.telnet_port, 0);
}
} }
} }