]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/smtp/serv_smtp.c
validate_recipients() - completed removal of unused param
[citadel.git] / citadel / server / modules / smtp / serv_smtp.c
index 8707406bfab899b46195560b84cd685910cde182..b153207567cbf0aebb36357624d57e7cb2fe5b0d 100644 (file)
@@ -19,7 +19,7 @@
 // The VRFY and EXPN commands have been removed from this implementation
 // because nobody uses these commands anymore, except for spammers.
 //
-// Copyright (c) 1998-2022 by the citadel.org team
+// Copyright (c) 1998-2023 by the citadel.org team
 //
 // This program is open source software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 3.
@@ -48,8 +48,9 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <assert.h>
 #include <libcitadel.h>
-#include "../../citadel.h"
+#include "../../citadel_defs.h"
 #include "../../server.h"
 #include "../../citserver.h"
 #include "../../support.h"
@@ -110,7 +111,7 @@ void smtp_greeting(int is_msa) {
                        else
                                cprintf("550 %s\r\n", message_to_spammer);
                        CC->kill_me = KILLME_SPAMMER;
-                       /* no need to free_recipients(valid), it's not allocated yet */
+                       // no need to free_recipients(valid), it's not allocated yet
                        return;
                }
        }
@@ -205,11 +206,7 @@ void smtp_hello(int which_command) {
        }
        else {
                if (which_command == EHLO) {
-                       cprintf("250-Hello %s (%s [%s])\r\n",
-                               ChrPtr(SMTP->helo_node),
-                               CC->cs_host,
-                               CC->cs_addr
-                       );
+                       cprintf("250-Hello %s (%s [%s])\r\n", ChrPtr(SMTP->helo_node), CC->cs_host, CC->cs_addr);
                }
                else {
                        cprintf("250-Greetings and joyous salutations.\r\n");
@@ -218,11 +215,12 @@ void smtp_hello(int which_command) {
                cprintf("250-SIZE %ld\r\n", CtdlGetConfigLong("c_maxmsglen"));
 
 #ifdef HAVE_OPENSSL
-               // Offer TLS, but only if TLS is not already active.
-               // Furthermore, only offer TLS when running on
-               // the SMTP-MSA port, not on the SMTP-MTA port, due to
-               // questionable reliability of TLS in certain sending MTA's.
-               if ( (!CC->redirect_ssl) && (SMTP->is_msa) ) {
+               // Offer the STARTTLS option...
+               if (    (!CC->redirect_ssl)                                                     // not if we're already TLS
+                       && (    (SMTP->is_msa)                                                  // Always on port 587
+                               || (CtdlGetConfigInt("smtp_advertise_starttls") != 0)           // On port 25 only if enabled
+                       )
+               ) {
                        cprintf("250-STARTTLS\r\n");
                }
 #endif
@@ -252,8 +250,8 @@ void smtp_webcit_preferences_hack_backend(long msgnum, void *userdata) {
 
        if ( !CM_IsEmpty(msg, eMsgSubject) && (!strcasecmp(msg->cm_fields[eMsgSubject], "__ WebCit Preferences __"))) {
                // This is it!  Change ownership of the message text so it doesn't get freed.
-               *webcit_conf = (char *)msg->cm_fields[eMesageText];
-               msg->cm_fields[eMesageText] = NULL;
+               *webcit_conf = (char *)msg->cm_fields[eMessageText];
+               msg->cm_fields[eMessageText] = NULL;
        }
        CM_Free(msg);
 }
@@ -312,7 +310,7 @@ void smtp_get_user(int offset) {
        StrBufDecodeBase64(UserName);
 
        if (CtdlLoginExistingUser(ChrPtr(UserName)) == login_ok) {
-               size_t len = CtdlEncodeBase64(buf, "Password:", 9, 0);
+               size_t len = CtdlEncodeBase64(buf, "Password:", 9, BASE64_NO_LINEBREAKS);
 
                if (buf[len - 1] == '\n') {
                        buf[len - 1] = '\0';
@@ -426,7 +424,7 @@ void smtp_auth(void) {
                        smtp_get_user(11);
                }
                else {
-                       size_t len = CtdlEncodeBase64(username_prompt, "Username:", 9, 0);
+                       size_t len = CtdlEncodeBase64(username_prompt, "Username:", 9, BASE64_NO_LINEBREAKS);
                        if (username_prompt[len - 1] == '\n') {
                                username_prompt[len - 1] = '\0';
                        }
@@ -444,10 +442,7 @@ void smtp_auth(void) {
                        return;
                }
 
-               len = extract_token(encoded_authstring, 
-                                   ChrPtr(SMTP->Cmd) + 5,
-                                   1, ' ',
-                                   sizeof encoded_authstring);
+               len = extract_token(encoded_authstring, ChrPtr(SMTP->Cmd) + 5, 1, ' ', sizeof encoded_authstring);
                StrBufPlain(SMTP->Cmd, encoded_authstring, len);
                smtp_try_plain();
                return;
@@ -614,7 +609,6 @@ void smtp_rcpt(void) {
        // This is a *preliminary* call to validate_recipients() to evaluate one recipient.
        valid = validate_recipients(
                (char *)ChrPtr(SMTP->OneRcpt), 
-               smtp_get_Recipients(),
                (SMTP->is_lmtp)? POST_LMTP: (CC->logged_in)? POST_LOGGED_IN: POST_EXTERNAL
        );
 
@@ -743,11 +737,10 @@ void smtp_data(void) {
                    ((CtdlGetConfigInt("c_rfc822_strict_from") == CFG_SMTP_FROM_CORRECT) || 
                     (CtdlGetConfigInt("c_rfc822_strict_from") == CFG_SMTP_FROM_REJECT)    )  )
                {
-                       if (!IsEmptyStr(CC->cs_inet_email))
+                       if (!IsEmptyStr(CC->cs_inet_email)) {
                                validemail = strcmp(CC->cs_inet_email, msg->cm_fields[erFc822Addr]) == 0;
-                       if ((!validemail) && 
-                           (!IsEmptyStr(CC->cs_inet_other_emails)))
-                       {
+                       }
+                       if ((!validemail) && (!IsEmptyStr(CC->cs_inet_other_emails))) {
                                int num_secondary_emails = 0;
                                int i;
                                num_secondary_emails = num_tokens(CC->cs_inet_other_emails, '|');
@@ -765,32 +758,31 @@ void smtp_data(void) {
                        return;
                }
 
-               CM_SetField(msg, eOriginalRoom, HKEY(MAILROOM));
+               CM_SetField(msg, eOriginalRoom, MAILROOM);
                if (SMTP->preferred_sender_name != NULL)
-                       CM_SetField(msg, eAuthor, SKEY(SMTP->preferred_sender_name));
+                       CM_SetField(msg, eAuthor, ChrPtr(SMTP->preferred_sender_name));
                else 
-                       CM_SetField(msg, eAuthor, CC->user.fullname, strlen(CC->user.fullname));
+                       CM_SetField(msg, eAuthor, CC->user.fullname);
 
                if (!validemail) {
                        if (SMTP->preferred_sender_email != NULL) {
-                               CM_SetField(msg, erFc822Addr, SKEY(SMTP->preferred_sender_email));
+                               CM_SetField(msg, erFc822Addr, ChrPtr(SMTP->preferred_sender_email));
                        }
                        else {
-                               CM_SetField(msg, erFc822Addr, CC->cs_inet_email, strlen(CC->cs_inet_email));
+                               CM_SetField(msg, erFc822Addr, CC->cs_inet_email);
                        }
                }
        }
 
        // Set the "envelope from" address
-       CM_SetField(msg, eMessagePath, SKEY(SMTP->from));
+       CM_SetField(msg, eMessagePath, ChrPtr(SMTP->from));
 
        // Set the "envelope to" address
-       CM_SetField(msg, eenVelopeTo, SKEY(SMTP->recipients));
+       CM_SetField(msg, eenVelopeTo, ChrPtr(SMTP->recipients));
 
        // Submit the message into the Citadel system.
        valid = validate_recipients(
                (char *)ChrPtr(SMTP->recipients),
-               smtp_get_Recipients(),
                (SMTP->is_lmtp)? POST_LMTP: (CC->logged_in)? POST_LOGGED_IN: POST_EXTERNAL
        );
 
@@ -807,7 +799,7 @@ void smtp_data(void) {
        if (scan_errors > 0) {  // We don't want this message!
 
                if (CM_IsEmpty(msg, eErrorMsg)) {
-                       CM_SetField(msg, eErrorMsg, HKEY("Message rejected by filter"));
+                       CM_SetField(msg, eErrorMsg, "Message rejected by filter");
                }
 
                StrBufPrintf(SMTP->OneRcpt, "550 %s\r\n", msg->cm_fields[eErrorMsg]);
@@ -887,10 +879,7 @@ void smtp_quit(void) {
 void smtp_command_loop(void) {
        static const ConstStr AuthPlainStr = {HKEY("AUTH PLAIN")};
 
-       if (SMTP == NULL) {
-               syslog(LOG_ERR, "serv_smtp: Session SMTP data is null.  WTF?  We will crash now.");
-               abort();
-       }
+       assert(SMTP != NULL);
 
        time(&CC->lastcmd);
        if (CtdlClientGetLine(SMTP->Cmd) < 1) {
@@ -986,16 +975,14 @@ void smtp_command_loop(void) {
 }
 
 
-/*****************************************************************************/
-/*                      MODULE INITIALIZATION STUFF                          */
-/*****************************************************************************/
-/*
- * This cleanup function blows away the temporary memory used by
- * the SMTP server.
- */
-void smtp_cleanup_function(void)
-{
-       /* Don't do this stuff if this is not an SMTP session! */
+// *****************************************************************************
+// *                      MODULE INITIALIZATION STUFF                          *
+// *****************************************************************************
+
+// This cleanup function blows away the temporary memory used by
+// the SMTP server.
+void smtp_cleanup_function(void) {
+       // Don't do this stuff if this is not an SMTP session!
        if (CC->h_command_function != smtp_command_loop) return;
 
        syslog(LOG_DEBUG, "Performing SMTP cleanup hook");
@@ -1021,7 +1008,7 @@ const char *CitadelServiceSMTP_LMTP_UNF="LMTP-UnF";
 // Initialization function, called from modules_init.c
 char *ctdl_module_init_smtp(void) {
        if (!threading) {
-               CtdlRegisterServiceHook(CtdlGetConfigInt("c_smtp_port"),        /* SMTP MTA */
+               CtdlRegisterServiceHook(CtdlGetConfigInt("c_smtp_port"),        // SMTP MTA
                                        NULL,
                                        smtp_mta_greeting,
                                        smtp_command_loop,
@@ -1029,7 +1016,7 @@ char *ctdl_module_init_smtp(void) {
                                        CitadelServiceSMTP_MTA);
 
 #ifdef HAVE_OPENSSL
-               CtdlRegisterServiceHook(CtdlGetConfigInt("c_smtps_port"),       /* SMTPS MTA */
+               CtdlRegisterServiceHook(CtdlGetConfigInt("c_smtps_port"),       // SMTPS MTA
                                        NULL,
                                        smtps_greeting,
                                        smtp_command_loop,
@@ -1037,21 +1024,21 @@ char *ctdl_module_init_smtp(void) {
                                        CitadelServiceSMTPS_MTA);
 #endif
 
-               CtdlRegisterServiceHook(CtdlGetConfigInt("c_msa_port"),         /* SMTP MSA */
+               CtdlRegisterServiceHook(CtdlGetConfigInt("c_msa_port"),         // SMTP MSA
                                        NULL,
                                        smtp_msa_greeting,
                                        smtp_command_loop,
                                        NULL,
                                        CitadelServiceSMTP_MSA);
 
-               CtdlRegisterServiceHook(0,                      /* local LMTP */
+               CtdlRegisterServiceHook(0,                                      // local LMTP
                                        file_lmtp_socket,
                                        lmtp_greeting,
                                        smtp_command_loop,
                                        NULL,
                                        CitadelServiceSMTP_LMTP);
 
-               CtdlRegisterServiceHook(0,                      /* local LMTP */
+               CtdlRegisterServiceHook(0,                                      // local LMTP
                                        file_lmtp_unfiltered_socket,
                                        lmtp_unfiltered_greeting,
                                        smtp_command_loop,
@@ -1061,6 +1048,6 @@ char *ctdl_module_init_smtp(void) {
                CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP, PRIO_STOP + 250);
        }
        
-       /* return our module name for the log */
+       // return our module name for the log
        return "smtp";
 }