Make it so users must exist to address them in local mail

This commit is contained in:
Andrew Pamment 2018-10-23 16:32:17 +10:00
parent 60b7d0d874
commit 41b0e18ffc
5 changed files with 45 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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) {