#include "html.h"
#include "genstamp.h"
#include "internet_addressing.h"
-#include "vcard.h"
#include "euidindex.h"
#include "journaling.h"
#include "citadel_dirs.h"
#include "clientsocket.h"
-
+#include "serv_network.h"
+#include "threads.h"
long config_msgnum;
struct addresses_to_be_filed *atbf = NULL;
msg->cm_fields['N'] = strdup(NODENAME);
if (to != NULL) {
msg->cm_fields['R'] = strdup(to);
- recp = validate_recipients(to);
+ recp = validate_recipients(to, NULL, 0);
}
if (subject != NULL) {
msg->cm_fields['U'] = strdup(subject);
* 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 CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf,
+ size_t n,
+ const char* RemoteIdentifier,
+ int PostPublic) {
int ra;
- if (!(CC->logged_in)) {
+ if (!(CC->logged_in) &&
+ (PostPublic == POST_LOGGED_IN)) {
snprintf(errmsgbuf, n, "Not logged in.");
return (ERROR + NOT_LOGGED_IN);
}
+ else if (PostPublic == CHECK_EXISTANCE) {
+ return (0); // We're Evaling whether a recipient exists
+ }
+ else if (!(CC->logged_in)) {
+ if ((CC->room.QRflags & QR_READONLY)) {
+ snprintf(errmsgbuf, n, "Not logged in.");
+ return (ERROR + NOT_LOGGED_IN);
+ }
+ if (CC->room.QRflags2 & QR2_MODERATED) {
+ snprintf(errmsgbuf, n, "Not logged in Moderation feature not yet implemented!");
+ return (ERROR + NOT_LOGGED_IN);
+ }
+ if (CC->room.QRflags2 & QR2_SMTP_PUBLIC == 0){
+ SpoolControl *sc;
+ char filename[SIZ];
+ int found;
+
+ if (RemoteIdentifier == NULL)
+ {
+ snprintf(errmsgbuf, n, "Need sender to permit access.");
+ return (ERROR + USERNAME_REQUIRED);
+ }
+
+ assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
+ begin_critical_section(S_NETCONFIGS);
+ if (!read_spoolcontrol_file(&sc, filename))
+ {
+ end_critical_section(S_NETCONFIGS);
+ snprintf(errmsgbuf, n, "No Subscribers found.");
+ return (ERROR + NO_SUCH_USER);
+ }
+ end_critical_section(S_NETCONFIGS);
+ found = is_recipient (sc, RemoteIdentifier);
+ free_spoolcontrol_struct(&sc);
+ if (found)
+ return (0);
+ else
+ return (ERROR + NO_SUCH_USER);
+ }
+ return (0);
+
+ }
if ((CC->user.axlevel < 2)
&& ((CC->room.QRflags & QR_MAILBOX) == 0)) {
*
* Caller needs to free the result using free_recipients()
*/
-struct recptypes *validate_recipients(char *supplied_recipients) {
+struct recptypes *validate_recipients(char *supplied_recipients,
+ const char *RemoteIdentifier,
+ int Flags) {
struct recptypes *ret;
char *recipients = NULL;
char this_recp[256];
int invalid;
struct ctdluser tempUS;
struct ctdlroom tempQR;
+ struct ctdlroom tempQR2;
+ int err = 0;
+ char errmsg[SIZ];
int in_quotes = 0;
/* Initialize */
}
else if ( (!strncasecmp(this_recp, "room_", 5))
&& (!getroom(&tempQR, &this_recp_cooked[5])) ) {
- ++ret->num_room;
- if (!IsEmptyStr(ret->recp_room)) {
- strcat(ret->recp_room, "|");
+
+ /* Save room so we can restore it later */
+ tempQR2 = CC->room;
+ CC->room = tempQR;
+
+ /* Check permissions to send mail to this room */
+ err = CtdlDoIHavePermissionToPostInThisRoom(errmsg,
+ sizeof errmsg,
+ RemoteIdentifier,
+ Flags);
+ if (err)
+ {
+ cprintf("%d %s\n", err, errmsg);
+ ++ret->num_error;
+ invalid = 1;
+ }
+ else {
+ ++ret->num_room;
+ if (!IsEmptyStr(ret->recp_room)) {
+ strcat(ret->recp_room, "|");
+ }
+ strcat(ret->recp_room, &this_recp_cooked[5]);
}
- strcat(ret->recp_room, &this_recp_cooked[5]);
+
+ /* Restore room in case something needs it */
+ CC->room = tempQR2;
+
}
else {
++ret->num_error;
/* first check to make sure the request is valid. */
- err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, sizeof errmsg);
+ err = CtdlDoIHavePermissionToPostInThisRoom(errmsg, sizeof errmsg, NULL, POST_LOGGED_IN);
if (err)
{
cprintf("%d %s\n", err, errmsg);
strcpy(bcc, "");
}
- valid_to = validate_recipients(recp);
+ 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);
+ 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);
return;
}
- valid_bcc = validate_recipients(bcc);
+ 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);
strcat(all_recps, bcc);
}
if (!IsEmptyStr(all_recps)) {
- valid = validate_recipients(all_recps);
+ valid = validate_recipients(all_recps, NULL, 0);
}
else {
valid = NULL;
struct recptypes *recp;
int i;
- recp = validate_recipients(addr);
+ recp = validate_recipients(addr, NULL, 0);
if (recp == NULL) return(0);
if (recp->num_local == 0) {