* give the flag to the CtdlDoIHavePermissionToPostInThisRoom in through the parameter...
[citadel.git] / citadel / modules / smtp / serv_smtp.c
index 960e105d0816164602b6a3182c861439a5179105..d2c7b1e95f6ca4896187885c199dca25e28485ae 100644 (file)
@@ -55,6 +55,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -66,7 +67,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "genstamp.h"
 #include "domain.h"
@@ -105,7 +105,7 @@ enum {                              /* Command states for login authentication */
        smtp_plain
 };
 
-#define SMTP           CC->SMTP
+#define SMTP           ((struct citsmtp *)CC->session_specific_data)
 
 
 int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */
@@ -127,7 +127,7 @@ void smtp_greeting(int is_msa)
        strcpy(CC->cs_clientname, "SMTP session");
        CC->internal_pgm = 1;
        CC->cs_flags |= CS_STEALTH;
-       SMTP = malloc(sizeof(struct citsmtp));
+       CC->session_specific_data = malloc(sizeof(struct citsmtp));
        memset(SMTP, 0, sizeof(struct citsmtp));
        SMTP->is_msa = is_msa;
 
@@ -166,7 +166,9 @@ void smtp_greeting(int is_msa)
  */
 void smtps_greeting(void) {
        CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
+#ifdef HAVE_OPENSSL
        if (!CC->redirect_ssl) CC->kill_me = 1;         /* kill session if no crypto */
+#endif
        smtp_greeting(0);
 }
 
@@ -314,7 +316,7 @@ void smtp_get_user(char *argbuf) {
        CtdlDecodeBase64(username, argbuf, SIZ);
        /* lprintf(CTDL_DEBUG, "Trying <%s>\n", username); */
        if (CtdlLoginExistingUser(NULL, username) == login_ok) {
-               CtdlEncodeBase64(buf, "Password:", 9);
+               CtdlEncodeBase64(buf, "Password:", 9, 0);
                cprintf("334 %s\r\n", buf);
                SMTP->command_state = smtp_password;
        }
@@ -397,7 +399,7 @@ void smtp_auth(char *argbuf) {
                        smtp_get_user(&argbuf[6]);
                }
                else {
-                       CtdlEncodeBase64(username_prompt, "Username:", 9);
+                       CtdlEncodeBase64(username_prompt, "Username:", 9, 0);
                        cprintf("334 %s\r\n", username_prompt);
                        SMTP->command_state = smtp_user;
                }
@@ -596,7 +598,8 @@ void smtp_rcpt(char *argbuf) {
                }
        }
 
-       valid = validate_recipients(recp);
+       valid = validate_recipients(recp, 
+                                   (CC->logged_in)? POST_LOGGED_IN:POST_EXTERNAL);
        if (valid->num_error != 0) {
                cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg);
                free_recipients(valid);
@@ -673,7 +676,7 @@ void smtp_data(void) {
                        config.c_fqdn,
                        nowstamp);
        
-       body = CtdlReadMessageBody(".", config.c_maxmsglen, body, 1);
+       body = CtdlReadMessageBody(".", config.c_maxmsglen, body, 1, 0);
        if (body == NULL) {
                cprintf("550 5.6.5 "
                        "Unable to save message: internal error.\r\n");
@@ -719,7 +722,8 @@ void smtp_data(void) {
        msg->cm_fields['V'] = strdup(SMTP->recipients);
 
        /* Submit the message into the Citadel system. */
-       valid = validate_recipients(SMTP->recipients);
+       valid = validate_recipients(SMTP->recipients, 
+                                   (CC->logged_in)? POST_LOGGED_IN:POST_EXTERNAL);
 
        /* If there are modules that want to scan this message before final
         * submission (such as virus checkers or spam filters), call them now
@@ -1109,7 +1113,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        if (!IsEmptyStr(mx_user)) {
                char encoded[1024];
                sprintf(buf, "%s%c%s%c%s", mx_user, '\0', mx_user, '\0', mx_pass);
-               CtdlEncodeBase64(encoded, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 2);
+               CtdlEncodeBase64(encoded, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 2, 0);
                snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", encoded);
                lprintf(CTDL_DEBUG, ">%s", buf);
                sock_write(sock, buf, strlen(buf));
@@ -1435,7 +1439,7 @@ void smtp_do_bounce(char *instr) {
                }
 
                /* Can we deliver the bounce to the original sender? */
-               valid = validate_recipients(bounceto);
+               valid = validate_recipients(bounceto, 0);
                if (valid != NULL) {
                        if (valid->num_error == 0) {
                                CtdlSubmitMsg(bmsg, valid, "");
@@ -1812,48 +1816,51 @@ const char *CitadelServiceSMTP_LMTP_UNF="LMTP-UnF";
 
 CTDL_MODULE_INIT(smtp)
 {
-       CtdlRegisterServiceHook(config.c_smtp_port,     /* SMTP MTA */
-                               NULL,
-                               smtp_mta_greeting,
-                               smtp_command_loop,
-                               NULL, 
-                               CitadelServiceSMTP_MTA);
+       if (!threading)
+       {
+               CtdlRegisterServiceHook(config.c_smtp_port,     /* SMTP MTA */
+                                       NULL,
+                                       smtp_mta_greeting,
+                                       smtp_command_loop,
+                                       NULL, 
+                                       CitadelServiceSMTP_MTA);
 
 #ifdef HAVE_OPENSSL
-       CtdlRegisterServiceHook(config.c_smtps_port,
-                               NULL,
-                               smtps_greeting,
-                               smtp_command_loop,
-                               NULL,
-                               CitadelServiceSMTPS_MTA);
+               CtdlRegisterServiceHook(config.c_smtps_port,
+                                       NULL,
+                                       smtps_greeting,
+                                       smtp_command_loop,
+                                       NULL,
+                                       CitadelServiceSMTPS_MTA);
 #endif
 
-       CtdlRegisterServiceHook(config.c_msa_port,      /* SMTP MSA */
-                               NULL,
-                               smtp_msa_greeting,
-                               smtp_command_loop,
-                               NULL,
-                               CitadelServiceSMTP_MSA);
-
-       CtdlRegisterServiceHook(0,                      /* local LMTP */
-                               file_lmtp_socket,
-                               lmtp_greeting,
-                               smtp_command_loop,
-                               NULL,
-                               CitadelServiceSMTP_LMTP);
-
-       CtdlRegisterServiceHook(0,                      /* local LMTP */
-                               file_lmtp_unfiltered_socket,
-                               lmtp_unfiltered_greeting,
-                               smtp_command_loop,
-                               NULL,
-                               CitadelServiceSMTP_LMTP_UNF);
-
-       smtp_init_spoolout();
-       CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
-       CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP);
-       CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
-
+               CtdlRegisterServiceHook(config.c_msa_port,      /* SMTP MSA */
+                                       NULL,
+                                       smtp_msa_greeting,
+                                       smtp_command_loop,
+                                       NULL,
+                                       CitadelServiceSMTP_MSA);
+
+               CtdlRegisterServiceHook(0,                      /* local LMTP */
+                                       file_lmtp_socket,
+                                       lmtp_greeting,
+                                       smtp_command_loop,
+                                       NULL,
+                                       CitadelServiceSMTP_LMTP);
+
+               CtdlRegisterServiceHook(0,                      /* local LMTP */
+                                       file_lmtp_unfiltered_socket,
+                                       lmtp_unfiltered_greeting,
+                                       smtp_command_loop,
+                                       NULL,
+                                       CitadelServiceSMTP_LMTP_UNF);
+
+               smtp_init_spoolout();
+               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
+               CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP);
+               CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
+       }
+       
        /* return our Subversion id for the Log */
        return "$Id$";
 }