]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtp.c
For the SSL-only ports, if crypto negotiation fails,
[citadel.git] / citadel / modules / smtp / serv_smtp.c
index c2329ba9168cf958524ed78e8a568efdd842bc16..960e105d0816164602b6a3182c861439a5179105 100644 (file)
 #include "locate_host.h"
 #include "citadel_dirs.h"
 
-#ifdef HAVE_OPENSSL
-#include "serv_crypto.h"
-#endif
-
 
 
 #ifndef HAVE_SNPRINTF
@@ -168,12 +164,11 @@ void smtp_greeting(int is_msa)
 /*
  * SMTPS is just like SMTP, except it goes crypto right away.
  */
-#ifdef HAVE_OPENSSL
 void smtps_greeting(void) {
-       CtdlStartTLS(NULL, NULL, NULL);
+       CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
+       if (!CC->redirect_ssl) CC->kill_me = 1;         /* kill session if no crypto */
        smtp_greeting(0);
 }
-#endif
 
 
 /*
@@ -365,7 +360,7 @@ void smtp_try_plain(char *encoded_authstring) {
 
        SMTP->command_state = smtp_command;
 
-       if (strlen(ident) > 0) {
+       if (!IsEmptyStr(ident)) {
                result = CtdlLoginExistingUser(user, ident);
        }
        else {
@@ -496,7 +491,7 @@ void smtp_mail(char *argbuf) {
        char node[SIZ];
        char name[SIZ];
 
-       if (strlen(SMTP->from) != 0) {
+       if (!IsEmptyStr(SMTP->from)) {
                cprintf("503 5.1.0 Only one sender permitted\r\n");
                return;
        }
@@ -518,7 +513,7 @@ void smtp_mail(char *argbuf) {
         * address so we don't have to contend with the empty string causing
         * other code to fail when it's expecting something there.
         */
-       if (strlen(SMTP->from) == 0) {
+       if (IsEmptyStr(SMTP->from)) {
                strcpy(SMTP->from, "someone@somewhere.org");
        }
 
@@ -563,7 +558,7 @@ void smtp_rcpt(char *argbuf) {
        char message_to_spammer[SIZ];
        struct recptypes *valid = NULL;
 
-       if (strlen(SMTP->from) == 0) {
+       if (IsEmptyStr(SMTP->from)) {
                cprintf("503 5.5.1 Need MAIL before RCPT\r\n");
                return;
        }
@@ -628,7 +623,7 @@ void smtp_rcpt(char *argbuf) {
        }
 
        cprintf("250 2.1.5 RCPT ok <%s>\r\n", recp);
-       if (strlen(SMTP->recipients) > 0) {
+       if (!IsEmptyStr(SMTP->recipients)) {
                strcat(SMTP->recipients, ",");
        }
        strcat(SMTP->recipients, recp);
@@ -654,7 +649,7 @@ void smtp_data(void) {
        int i;
        char result[SIZ];
 
-       if (strlen(SMTP->from) == 0) {
+       if (IsEmptyStr(SMTP->from)) {
                cprintf("503 5.5.1 Need MAIL command first.\r\n");
                return;
        }
@@ -797,7 +792,6 @@ void smtp_data(void) {
 /*
  * implements the STARTTLS command (Citadel API version)
  */
-#ifdef HAVE_OPENSSL
 void smtp_starttls(void)
 {
        char ok_response[SIZ];
@@ -805,15 +799,14 @@ void smtp_starttls(void)
        char error_response[SIZ];
 
        sprintf(ok_response,
-               "200 2.0.0 Begin TLS negotiation now\r\n");
+               "220 2.0.0 Begin TLS negotiation now\r\n");
        sprintf(nosup_response,
                "554 5.7.3 TLS not supported here\r\n");
        sprintf(error_response,
                "554 5.7.3 Internal error\r\n");
-       CtdlStartTLS(ok_response, nosup_response, error_response);
+       CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response);
        smtp_rset(0);
 }
-#endif
 
 
 
@@ -966,7 +959,7 @@ void smtp_try(const char *key, const char *addr, int *status,
                if (!strncasecmp(buf, "From:", 5)) {
                        safestrncpy(mailfrom, &buf[5], sizeof mailfrom);
                        striplt(mailfrom);
-                       for (i=0; i<strlen(mailfrom); ++i) {
+                       for (i=0; mailfrom[i]; ++i) {
                                if (!isprint(mailfrom[i])) {
                                        strcpy(&mailfrom[i], &mailfrom[i+1]);
                                        i=0;
@@ -976,7 +969,7 @@ void smtp_try(const char *key, const char *addr, int *status,
                        /* Strip out parenthesized names */
                        lp = (-1);
                        rp = (-1);
-                       for (i=0; i<strlen(mailfrom); ++i) {
+                       for (i=0; mailfrom[i]; ++i) {
                                if (mailfrom[i] == '(') lp = i;
                                if (mailfrom[i] == ')') rp = i;
                        }
@@ -987,7 +980,7 @@ void smtp_try(const char *key, const char *addr, int *status,
                        /* Prefer brokketized names */
                        lp = (-1);
                        rp = (-1);
-                       for (i=0; i<strlen(mailfrom); ++i) {
+                       for (i=0; mailfrom[i]; ++i) {
                                if (mailfrom[i] == '<') lp = i;
                                if (mailfrom[i] == '>') rp = i;
                        }
@@ -999,7 +992,7 @@ void smtp_try(const char *key, const char *addr, int *status,
                        scan_done = 1;
                }
        } while (scan_done == 0);
-       if (strlen(mailfrom)==0) strcpy(mailfrom, "someone@somewhere.org");
+       if (IsEmptyStr(mailfrom)) strcpy(mailfrom, "someone@somewhere.org");
        stripallbut(mailfrom, '<', '>');
 
        /* Figure out what mail exchanger host we have to connect to */
@@ -1113,7 +1106,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        }
 
        /* Do an AUTH command if necessary */
-       if (strlen(mx_user) > 0) {
+       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);
@@ -1436,7 +1429,7 @@ void smtp_do_bounce(char *instr) {
 
                /* First try the user who sent the message */
                lprintf(CTDL_DEBUG, "bounce to user? <%s>\n", bounceto);
-               if (strlen(bounceto) == 0) {
+               if (IsEmptyStr(bounceto)) {
                        lprintf(CTDL_ERR, "No bounce address specified\n");
                        bounce_msgid = (-1L);
                }
@@ -1811,7 +1804,11 @@ void smtp_cleanup_function(void) {
 
 
 
-
+const char *CitadelServiceSMTP_MTA="SMTP-MTA";
+const char *CitadelServiceSMTPS_MTA="SMTPs-MTA";
+const char *CitadelServiceSMTP_MSA="SMTP-MSA";
+const char *CitadelServiceSMTP_LMTP="LMTP";
+const char *CitadelServiceSMTP_LMTP_UNF="LMTP-UnF";
 
 CTDL_MODULE_INIT(smtp)
 {
@@ -1819,33 +1816,38 @@ CTDL_MODULE_INIT(smtp)
                                NULL,
                                smtp_mta_greeting,
                                smtp_command_loop,
-                               NULL);
+                               NULL, 
+                               CitadelServiceSMTP_MTA);
 
 #ifdef HAVE_OPENSSL
        CtdlRegisterServiceHook(config.c_smtps_port,
                                NULL,
                                smtps_greeting,
                                smtp_command_loop,
-                               NULL);
+                               NULL,
+                               CitadelServiceSMTPS_MTA);
 #endif
 
        CtdlRegisterServiceHook(config.c_msa_port,      /* SMTP MSA */
                                NULL,
                                smtp_msa_greeting,
                                smtp_command_loop,
-                               NULL);
+                               NULL,
+                               CitadelServiceSMTP_MSA);
 
        CtdlRegisterServiceHook(0,                      /* local LMTP */
                                file_lmtp_socket,
                                lmtp_greeting,
                                smtp_command_loop,
-                               NULL);
+                               NULL,
+                               CitadelServiceSMTP_LMTP);
 
        CtdlRegisterServiceHook(0,                      /* local LMTP */
                                file_lmtp_unfiltered_socket,
                                lmtp_unfiltered_greeting,
                                smtp_command_loop,
-                               NULL);
+                               NULL,
+                               CitadelServiceSMTP_LMTP_UNF);
 
        smtp_init_spoolout();
        CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);