From 939ba3f9a9da345cc3bf48e646ef5787074ac05d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 10 Dec 2007 23:22:03 +0000 Subject: [PATCH] * give message sender in while evaluating the recipient... * evaluate sender against the subscriber list. * in all other cases, hand over a NULL --- citadel/journaling.c | 2 +- citadel/modules/calendar/serv_calendar.c | 12 ++--- citadel/modules/imap/imap_acl.c | 2 +- citadel/modules/imap/imap_misc.c | 2 +- citadel/modules/network/serv_network.c | 12 ++--- citadel/modules/sieve/serv_sieve.c | 2 +- citadel/modules/smtp/serv_smtp.c | 10 +++- citadel/modules/vcard/serv_vcard.c | 2 +- citadel/msgbase.c | 59 +++++++++++++++++++----- citadel/msgbase.h | 10 +++- citadel/serv_network.h | 2 +- citadel/user_ops.c | 2 +- 12 files changed, 84 insertions(+), 33 deletions(-) diff --git a/citadel/journaling.c b/citadel/journaling.c index c78292b6b..f008e7680 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -133,7 +133,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { static int seq = 0; int i; - journal_recps = validate_recipients(config.c_journal_dest, 0); + journal_recps = validate_recipients(config.c_journal_dest, NULL, 0); if (journal_recps != NULL) { if ( (journal_recps->num_local > 0) diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index 526d737c5..01f336ca1 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -264,7 +264,7 @@ void ical_send_a_reply(icalcomponent *request, char *action) { if (!strncasecmp(attendee_string, "MAILTO:", 7)) { strcpy(attendee_string, &attendee_string[7]); striplt(attendee_string); - recp = validate_recipients(attendee_string, 0); + recp = validate_recipients(attendee_string, NULL, 0); if (recp != NULL) { if (!strcasecmp(recp->recp_local, CC->user.fullname)) { if (me_attend) icalproperty_free(me_attend); @@ -350,7 +350,7 @@ void ical_send_a_reply(icalcomponent *request, char *action) { reply_message_text); if (msg != NULL) { - valid = validate_recipients(organizer_string, 0); + valid = validate_recipients(organizer_string, NULL, 0); CtdlSubmitMsg(msg, valid, ""); CtdlFreeMessage(msg); free_recipients(valid); @@ -1214,7 +1214,7 @@ void ical_freebusy(char *who) { /* If not found, try it as an unqualified email address. */ if (found_user != 0) { strcpy(buf, who); - recp = validate_recipients(buf, 0); + recp = validate_recipients(buf, NULL, 0); lprintf(CTDL_DEBUG, "Trying <%s>\n", buf); if (recp != NULL) { if (recp->num_local == 1) { @@ -1230,7 +1230,7 @@ void ical_freebusy(char *who) { if (found_user != 0) { snprintf(buf, sizeof buf, "%s@%s", who, config.c_fqdn); lprintf(CTDL_DEBUG, "Trying <%s>\n", buf); - recp = validate_recipients(buf, 0); + recp = validate_recipients(buf, NULL, 0); if (recp != NULL) { if (recp->num_local == 1) { found_user = getuser(&usbuf, recp->recp_local); @@ -1253,7 +1253,7 @@ void ical_freebusy(char *who) { || (!strcasecmp(type, "directory")) ) { snprintf(buf, sizeof buf, "%s@%s", who, host); lprintf(CTDL_DEBUG, "Trying <%s>\n", buf); - recp = validate_recipients(buf, 0); + recp = validate_recipients(buf, NULL, 0); if (recp != NULL) { if (recp->num_local == 1) { found_user = getuser(&usbuf, recp->recp_local); @@ -1794,7 +1794,7 @@ void ical_send_out_invitations(icalcomponent *cal) { request_message_text); if (msg != NULL) { - valid = validate_recipients(attendees_string, 0); + valid = validate_recipients(attendees_string, NULL, 0); CtdlSubmitMsg(msg, valid, ""); CtdlFreeMessage(msg); free_recipients(valid); diff --git a/citadel/modules/imap/imap_acl.c b/citadel/modules/imap/imap_acl.c index 3b5d44c88..c54340a49 100644 --- a/citadel/modules/imap/imap_acl.c +++ b/citadel/modules/imap/imap_acl.c @@ -230,7 +230,7 @@ void imap_listrights(int num_parms, char *parms[]) { * Search for the specified user */ ret = (-1); - valid = validate_recipients(parms[3], 0); + valid = validate_recipients(parms[3], NULL, 0); if (valid != NULL) { if (valid->num_local == 1) { ret = getuser(&temp, valid->recp_local); diff --git a/citadel/modules/imap/imap_misc.c b/citadel/modules/imap/imap_misc.c index f0f93627e..eacb44e6f 100644 --- a/citadel/modules/imap/imap_misc.c +++ b/citadel/modules/imap/imap_misc.c @@ -467,7 +467,7 @@ void imap_append(int num_parms, char *parms[]) { /* * Can we post here? */ - ret = CtdlDoIHavePermissionToPostInThisRoom(buf, sizeof buf, POST_LOGGED_IN); + ret = CtdlDoIHavePermissionToPostInThisRoom(buf, sizeof buf, NULL, POST_LOGGED_IN); if (ret) { /* Nope ... print an error message */ diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 13d4a73e1..cf9c9800b 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -518,7 +518,7 @@ void network_deliver_digest(SpoolControl *sc) { } /* Now submit the message */ - valid = validate_recipients(recps, 0); + valid = validate_recipients(recps, NULL, 0); free(recps); CtdlSubmitMsg(msg, valid, NULL); CtdlFreeMessage(msg); @@ -565,7 +565,7 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc) { } /* Now submit the message */ - valid = validate_recipients(recps, 0); + valid = validate_recipients(recps, NULL, 0); free(recps); CtdlSubmitMsg(msg, valid, NULL); free_recipients(valid); @@ -734,7 +734,7 @@ void network_spool_msg(long msgnum, void *userdata) { } msg->cm_fields['R'] = strdup(nptr->name); - valid = validate_recipients(nptr->name, 0); + valid = validate_recipients(nptr->name, NULL, 0); CtdlSubmitMsg(msg, valid, ""); free_recipients(valid); } @@ -1060,7 +1060,7 @@ int writenfree_spoolcontrol_file(SpoolControl **scc, char *filename) } return 1; } -int is_recipient(SpoolControl *sc, char *Name) +int is_recipient(SpoolControl *sc, const char *Name) { namelist *nptr; @@ -1403,7 +1403,7 @@ void network_bounce(struct CtdlMessage *msg, char *reason) { free(oldpath); /* Now submit the message */ - valid = validate_recipients(recipient, 0); + valid = validate_recipients(recipient, NULL, 0); if (valid != NULL) if (valid->num_error != 0) { free_recipients(valid); valid = NULL; @@ -1561,7 +1561,7 @@ void network_process_buffer(char *buffer, long size) { /* Otherwise, does it have a recipient? If so, validate it... */ else if (msg->cm_fields['R'] != NULL) { - recp = validate_recipients(msg->cm_fields['R'], 0); + recp = validate_recipients(msg->cm_fields['R'], NULL, 0); if (recp != NULL) if (recp->num_error != 0) { network_bounce(msg, "A message you sent could not be delivered due to an invalid address.\n" diff --git a/citadel/modules/sieve/serv_sieve.c b/citadel/modules/sieve/serv_sieve.c index 39827f365..e8baaec8a 100644 --- a/citadel/modules/sieve/serv_sieve.c +++ b/citadel/modules/sieve/serv_sieve.c @@ -104,7 +104,7 @@ int ctdl_redirect(sieve2_context_t *s, void *my) lprintf(CTDL_DEBUG, "Action is REDIRECT, recipient <%s>\n", recp); - valid = validate_recipients(recp, 0); + valid = validate_recipients(recp, NULL, 0); if (valid == NULL) { lprintf(CTDL_WARNING, "REDIRECT failed: bad recipient <%s>\n", recp); return SIEVE2_ERROR_BADARGS; diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index d2c7b1e95..507d44d6d 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -483,7 +483,13 @@ void smtp_data_clear(void) { SMTP->message_originated_locally = 0; } +const char *smtp_get_Recipients(void) +{ + if (SMTP == NULL) + return NULL; + else return SMTP->from; +} /* * Implements the "MAIL From:" command @@ -599,6 +605,7 @@ void smtp_rcpt(char *argbuf) { } valid = validate_recipients(recp, + smtp_get_Recipients (), (CC->logged_in)? POST_LOGGED_IN:POST_EXTERNAL); if (valid->num_error != 0) { cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg); @@ -723,6 +730,7 @@ void smtp_data(void) { /* Submit the message into the Citadel system. */ valid = validate_recipients(SMTP->recipients, + smtp_get_Recipients (), (CC->logged_in)? POST_LOGGED_IN:POST_EXTERNAL); /* If there are modules that want to scan this message before final @@ -1439,7 +1447,7 @@ void smtp_do_bounce(char *instr) { } /* Can we deliver the bounce to the original sender? */ - valid = validate_recipients(bounceto, 0); + valid = validate_recipients(bounceto, smtp_get_Recipients (), 0); if (valid != NULL) { if (valid->num_error == 0) { CtdlSubmitMsg(bmsg, valid, ""); diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index fc610c79c..8458670ad 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -1271,7 +1271,7 @@ void check_get(void) { char *argbuf = &cmdbuf[4]; extract_token(internet_addr, argbuf, 0, '|', sizeof internet_addr); - rcpt = validate_recipients(internet_addr, CHECK_EXISTANCE); + rcpt = validate_recipients(internet_addr, NULL, CHECK_EXISTANCE); if ((rcpt != NULL)&& ( (*rcpt->recp_local != '\0')|| diff --git a/citadel/msgbase.c b/citadel/msgbase.c index a34c418ce..e9e545da8 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -52,6 +52,7 @@ #include "journaling.h" #include "citadel_dirs.h" #include "clientsocket.h" +#include "serv_network.h" long config_msgnum; @@ -2841,7 +2842,7 @@ void quickie_message(char *from, char *fromaddr, char *to, char *room, char *tex msg->cm_fields['N'] = strdup(NODENAME); if (to != NULL) { msg->cm_fields['R'] = strdup(to); - recp = validate_recipients(to, 0); + recp = validate_recipients(to, NULL, 0); } if (subject != NULL) { msg->cm_fields['U'] = strdup(subject); @@ -3090,7 +3091,10 @@ struct CtdlMessage *CtdlMakeMessage( * room. Returns a *CITADEL ERROR CODE* and puts a message in errmsgbuf, or * returns 0 on success. */ -int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n, int PostPublic) { +int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, + size_t n, + const char* RemoteIdentifier, + int PostPublic) { int ra; if (!(CC->logged_in) && @@ -3099,7 +3103,35 @@ int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n, int PostPub return (ERROR + NOT_LOGGED_IN); } else if (PostPublic == CHECK_EXISTANCE) { - return (0); + SpoolControl *sc; + char filename[SIZ]; + char room_to_spool[SIZ]; + int found; + + if (RemoteIdentifier == NULL) + { + snprintf(errmsgbuf, n, "Need sender to permit access."); + return (0); + } + if (getroom(&CC->room, room_to_spool) != 0) { + lprintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", room_to_spool); + return (0); + } + + assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir); + + lprintf(CTDL_INFO, "Networking started for <%s>\n", CC->room.QRname); + begin_critical_section(S_NETCONFIGS); + if (!read_spoolcontrol_file(&sc, filename)) + { + end_critical_section(S_NETCONFIGS); + snprintf(errmsgbuf, n, "No Subscribers found."); + return (0); + } + end_critical_section(S_NETCONFIGS); + found = is_recipient (sc, RemoteIdentifier); + free_spoolcontrol_struct(&sc); + return (found); } else if (!(CC->logged_in)) { if ((CC->room.QRflags & QR_READONLY)) { @@ -3166,7 +3198,9 @@ int CtdlCheckInternetMailPermission(struct ctdluser *who) { * * Caller needs to free the result using free_recipients() */ -struct recptypes *validate_recipients(char *supplied_recipients, int Flags) { +struct recptypes *validate_recipients(char *supplied_recipients, + const char *RemoteIdentifier, + int Flags) { struct recptypes *ret; char *recipients = NULL; char this_recp[256]; @@ -3295,7 +3329,10 @@ struct recptypes *validate_recipients(char *supplied_recipients, int Flags) { CC->room = tempQR; /* Check permissions to send mail to this room */ - err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, sizeof errmsg, Flags); + err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, + sizeof errmsg, + RemoteIdentifier, + Flags); if (err) { cprintf("%d %s\n", err, errmsg); @@ -3473,7 +3510,7 @@ void cmd_ent0(char *entargs) /* first check to make sure the request is valid. */ - err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, sizeof errmsg, POST_LOGGED_IN); + err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, sizeof errmsg, NULL, POST_LOGGED_IN); if (err) { cprintf("%d %s\n", err, errmsg); @@ -3541,14 +3578,14 @@ void cmd_ent0(char *entargs) strcpy(bcc, ""); } - valid_to = validate_recipients(recp, 0); + valid_to = validate_recipients(recp, NULL, 0); if (valid_to->num_error > 0) { cprintf("%d Invalid recipient (To)\n", ERROR + NO_SUCH_USER); free_recipients(valid_to); return; } - valid_cc = validate_recipients(cc, 0); + valid_cc = validate_recipients(cc, NULL, 0); if (valid_cc->num_error > 0) { cprintf("%d Invalid recipient (CC)\n", ERROR + NO_SUCH_USER); free_recipients(valid_to); @@ -3556,7 +3593,7 @@ void cmd_ent0(char *entargs) return; } - valid_bcc = validate_recipients(bcc, 0); + valid_bcc = validate_recipients(bcc, NULL, 0); if (valid_bcc->num_error > 0) { cprintf("%d Invalid recipient (BCC)\n", ERROR + NO_SUCH_USER); free_recipients(valid_to); @@ -3683,7 +3720,7 @@ void cmd_ent0(char *entargs) strcat(all_recps, bcc); } if (!IsEmptyStr(all_recps)) { - valid = validate_recipients(all_recps, 0); + valid = validate_recipients(all_recps, NULL, 0); } else { valid = NULL; @@ -4401,7 +4438,7 @@ int CtdlIsMe(char *addr, int addr_buf_len) struct recptypes *recp; int i; - recp = validate_recipients(addr, 0); + recp = validate_recipients(addr, NULL, 0); if (recp == NULL) return(0); if (recp->num_local == 0) { diff --git a/citadel/msgbase.h b/citadel/msgbase.h index e4f3854cc..685f8bb11 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -154,7 +154,10 @@ enum { POST_EXTERNAL, CHECK_EXISTANCE }; -int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n, int PostPublic); +int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, + size_t n, + const char* RemoteIdentifier, + int PostPublic); /* values for which_set */ @@ -167,7 +170,10 @@ void CtdlSetSeen(long *target_msgnums, int num_target_msgnums, struct ctdluser *which_user, struct ctdlroom *which_room); void CtdlGetSeen(char *buf, int which_set); -struct recptypes *validate_recipients(char *recipients, int Flags); +struct recptypes *validate_recipients(char *recipients, + const char *RemoteIdentifier, + int Flags); + void free_recipients(struct recptypes *); struct CtdlMessage *CtdlMakeMessage( diff --git a/citadel/serv_network.h b/citadel/serv_network.h index c21973c0a..6f05431e8 100644 --- a/citadel/serv_network.h +++ b/citadel/serv_network.h @@ -51,7 +51,7 @@ void free_spoolcontrol_struct(SpoolControl **scc); int writenfree_spoolcontrol_file(SpoolControl **scc, char *filename); int read_spoolcontrol_file(SpoolControl **scc, char *filename); -int is_recipient(SpoolControl *sc, char *Name); +int is_recipient(SpoolControl *sc, const char *Name); void network_queue_room(struct ctdlroom *, void *); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 2c1228b87..fc54495cd 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -422,7 +422,7 @@ int CtdlLoginExistingUser(char *authname, char *trythisname) * is an e-mail address */ if (found_user != 0) { - valid = validate_recipients(username, 0); + valid = validate_recipients(username, NULL, 0); if (valid != NULL) { if (valid->num_local == 1) { found_user = getuser(&CC->user, valid->recp_local); -- 2.30.2