From 41b0e18ffc5f4e49403afa4152f082cb98dfcaa6 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Tue, 23 Oct 2018 16:32:17 +1000 Subject: [PATCH] Make it so users must exist to address them in local mail --- dist/magicka.strings | 2 +- src/bbs.h | 2 ++ src/mail_menu.c | 15 +++++++++++++++ src/users.c | 25 +++++++++++++++++++++++-- src/www_msgs.c | 4 ++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dist/magicka.strings b/dist/magicka.strings index c0683a1..55a94c3 100644 --- a/dist/magicka.strings +++ b/dist/magicka.strings @@ -61,7 +61,7 @@ Non-STDIO door support on SSH is currently broken...\r\n \e[1;30m-------------------------------------------------------------------------------\e[0m\r\n \e[1;37mPress \e[1;36mR\e[1;37m to reply, \e[1;36mD\e[1;37m to delete \e[1;36mEnter\e[1;37m to quit...\e[0m\r\n \r\nYou have no email\r\n -\e[2J\e[1;1H\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m +\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m \e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n \e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n \e[1;37mEnter \e[1;36m# \e[1;37mto read, \e[1;36mQ \e[1;37mto quit or \e[1;36mEnter\e[1;37m to continue\e[0m\r\n diff --git a/src/bbs.h b/src/bbs.h index 57a42e6..8c5af51 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -314,6 +314,8 @@ extern void gen_salt(char **s); extern char *hash_sha256(char *pass, char *salt); extern int save_user(struct user_record *user); extern int check_user(char *loginname); +extern int check_fullname_j(char *firstandlastname); +extern int check_fullname(char *firstname, char *lastname); extern struct user_record *new_user(); extern struct user_record *check_user_pass(char *loginname, char *password); extern void list_users(struct user_record *user); diff --git a/src/mail_menu.c b/src/mail_menu.c index b114759..ead0702 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -1594,6 +1594,16 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno s_printf(get_string(114)); s_readstring_inject(buffer, 32, msghs->msgs[mailno]->from); to = strdup(buffer); + if (ma->type == TYPE_LOCAL_AREA && (strcasecmp(to, "all") != 0 && check_user(to) && check_fullname_j(to))) { + s_printf(get_string(55)); + free(body); + free(subject); + free(to); + free(from); + ptr_vector_apply(&msg_lines, free); + destroy_ptr_vector(&msg_lines); + return 0; + } s_printf(get_string(115)); s_readstring_inject(buffer, 64, subject); free(subject); @@ -2026,6 +2036,11 @@ void post_message(struct user_record *user) { strlcpy(buffer, "ALL", sizeof(buffer)); } + if (ma->type == TYPE_LOCAL_AREA && (strcasecmp(buffer, "all") != 0 && check_user(buffer) && check_fullname_j(buffer))) { + s_printf(get_string(55)); + return; + } + if (ma->type == TYPE_NETMAIL_AREA) { s_printf(get_string(121)); s_readstring(buffer2, 32); diff --git a/src/users.c b/src/users.c index 689fa89..5a2cd96 100644 --- a/src/users.c +++ b/src/users.c @@ -540,6 +540,27 @@ void list_users(struct user_record *user) { s_getc(); } +int check_fullname_j(char *firstandlastname) { + char *firstname = strdup(firstandlastname); + + if (!firstname) { + return 0; + } + + char *lastname = strchr(firstname, ' '); + int ret; + + if (lastname == NULL) { + return 0; + } + *lastname = '\0'; + lastname++; + ret = check_fullname(firstname, lastname); + + free(firstname); + return ret; +} + int check_fullname(char *firstname, char *lastname) { sqlite3 *db = NULL; sqlite3_stmt *res = NULL; @@ -561,7 +582,7 @@ int check_fullname(char *firstname, char *lastname) { sqlite3_finalize(res); sqlite3_close(db); - return (!(step == SQLITE_ROW)); + return (step != SQLITE_ROW); } int check_user(char *loginname) { @@ -576,7 +597,7 @@ int check_user(char *loginname) { if (rc != SQLITE_OK) { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_close(db); - return 1; + return 0; } sqlite3_bind_text(res, 1, loginname, -1, 0); int step = sqlite3_step(res); diff --git a/src/www_msgs.c b/src/www_msgs.c index 7f145cd..2f91bc1 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -964,6 +964,10 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, return 0; struct mail_area *ma = get_area(conference, area); + if (ma->type == TYPE_LOCAL_AREA && (strcasecmp(to, "all") != 0 && check_user(to) && check_fullname_j(to))) { + return 0; + } + if (ma->write_sec_level <= user->sec_level && ma->type != TYPE_NETMAIL_AREA) { jb = open_jam_base(ma->path); if (!jb) {