X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=citadel%2Fmodules%2Fsmtp%2Fserv_smtp.c;h=8b03cfca65f9a637c061d064a282cd9f47d4a547;hp=b6fbc27d40696008a5ddd6a60d250ab6ba1ee971;hb=0387f48886a9395d89eaca01cd40ab751610426f;hpb=94d80bf1f806951eb236055bbb93dfccb806c016 diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index b6fbc27d4..8b03cfca6 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -20,7 +20,7 @@ * The VRFY and EXPN commands have been removed from this implementation * because nobody uses these commands anymore, except for spammers. * - * Copyright (c) 1998-2015 by the citadel.org team + * Copyright (c) 1998-2020 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. @@ -81,6 +81,7 @@ #include "ctdl_module.h" #include "smtp_util.h" + enum { /* Command states for login authentication */ smtp_command, smtp_user, @@ -103,16 +104,6 @@ typedef struct _smtp_handler_hook { int EnableSMTPLog = 0; -#define SMTPLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (EnableSMTPLog != 0)) - -#define SMTP_syslog(LEVEL, FORMAT, ...) \ - SMTPLOG(LEVEL) syslog(LEVEL, \ - "%s CC[%d]: " FORMAT, IOSTR, CCCID, __VA_ARGS__) - -#define SMTPM_syslog(LEVEL, FORMAT) \ - SMTPLOG(LEVEL) syslog(LEVEL, \ - "%s CC[%d]: " FORMAT, IOSTR, CCCID); - HashList *SMTPCmds = NULL; #define MaxSMTPCmdLen 10 @@ -125,7 +116,9 @@ void registerSmtpCMD(const char *First, long FLen, smtp_handler_hook *h; if (FLen >= MaxSMTPCmdLen) - cit_panic_backtrace (0); + { + abort(); + } h = (smtp_handler_hook*) malloc(sizeof(smtp_handler_hook)); memset(h, 0, sizeof(smtp_handler_hook)); @@ -135,6 +128,7 @@ void registerSmtpCMD(const char *First, long FLen, Put(SMTPCmds, First, FLen, h, NULL); } + void smtp_cleanup(void) { DeleteHash(&SMTPCmds); @@ -167,7 +161,7 @@ void smtp_greeting(int is_msa) * addresses immediately instead of after they execute a RCPT */ if ( (CtdlGetConfigInt("c_rbl_at_greeting")) && (sSMTP->is_msa == 0) ) { - if (rbl_check(message_to_spammer)) { + if (rbl_check(CC->cs_addr, message_to_spammer)) { if (server_shutting_down) cprintf("421 %s\r\n", message_to_spammer); else @@ -251,7 +245,7 @@ void lmtp_unfiltered_greeting(void) { void smtp_auth_greeting(long offset, long Flags) { struct CitContext *CCC = CC; cprintf("235 Hello, %s\r\n", CCC->user.fullname); - SMTP_syslog(LOG_NOTICE, "SMTP authenticated %s", CCC->user.fullname); + syslog(LOG_NOTICE, "SMTP authenticated %s", CCC->user.fullname); CCC->internal_pgm = 0; CCC->cs_flags &= ~CS_STEALTH; } @@ -332,7 +326,7 @@ void smtp_webcit_preferences_hack_backend(long msgnum, void *userdata) { return; // already got it } - msg = CtdlFetchMessage(msgnum, 1, 1); + msg = CtdlFetchMessage(msgnum, 1); if (msg == NULL) { return; } @@ -413,7 +407,7 @@ void smtp_get_user(long offset) StrBufDecodeBase64(sSMTP->Cmd); - if (CtdlLoginExistingUser(NULL, ChrPtr(sSMTP->Cmd)) == login_ok) { + if (CtdlLoginExistingUser(ChrPtr(sSMTP->Cmd)) == login_ok) { size_t len = CtdlEncodeBase64(buf, "Password:", 9, 0); if (buf[len - 1] == '\n') { @@ -434,13 +428,12 @@ void smtp_get_user(long offset) */ void smtp_get_pass(long offset, long Flags) { - struct CitContext *CCC = CC; citsmtp *sSMTP = SMTP; char password[SIZ]; memset(password, 0, sizeof(password)); StrBufDecodeBase64(sSMTP->Cmd); - SMTP_syslog(LOG_DEBUG, "Trying <%s>", password); + syslog(LOG_DEBUG, "Trying <%s>", password); if (CtdlTryPassword(SKEY(sSMTP->Cmd)) == pass_ok) { smtp_auth_greeting(offset, Flags); } @@ -499,10 +492,10 @@ void smtp_try_plain(long offset, long Flags) sSMTP->command_state = smtp_command; if (!IsEmptyStr(ident)) { - result = CtdlLoginExistingUser(user, ident); + result = CtdlLoginExistingUser(ident); } else { - result = CtdlLoginExistingUser(NULL, user); + result = CtdlLoginExistingUser(user); } if (result == login_ok) { @@ -693,13 +686,13 @@ void smtp_mail(long offset, long flags) { */ else if (CtdlGetConfigInt("c_allow_spoofing") == 0) { process_rfc822_addr(ChrPtr(sSMTP->from), user, node, name); - SMTP_syslog(LOG_DEBUG, "Claimed envelope sender is '%s' == '%s' @ '%s' ('%s')", + syslog(LOG_DEBUG, "Claimed envelope sender is '%s' == '%s' @ '%s' ('%s')", ChrPtr(sSMTP->from), user, node, name ); if (CtdlHostAlias(node) != hostalias_nomatch) { cprintf("550 You must log in to send mail from %s\r\n", node); FlushStrBuf(sSMTP->from); - SMTP_syslog(LOG_DEBUG, "Rejecting unauthenticated mail from %s", node); + syslog(LOG_DEBUG, "Rejecting unauthenticated mail from %s", node); return; } } @@ -748,7 +741,7 @@ void smtp_rcpt(long offset, long flags) if ( (!CCC->logged_in) /* Don't RBL authenticated users */ && (!sSMTP->is_lmtp) ) { /* Don't RBL LMTP clients */ if (CtdlGetConfigInt("c_rbl_at_greeting") == 0) { /* Don't RBL again if we already did it */ - if (rbl_check(message_to_spammer)) { + if (rbl_check(CC->cs_addr, message_to_spammer)) { if (server_shutting_down) cprintf("421 %s\r\n", message_to_spammer); else @@ -858,14 +851,14 @@ void smtp_data(long offset, long flags) nowstamp); } } - body = CtdlReadMessageBodyBuf(HKEY("."), CtdlGetConfigLong("c_maxmsglen"), defbody, 1, NULL); + body = CtdlReadMessageBodyBuf(HKEY("."), CtdlGetConfigLong("c_maxmsglen"), defbody, 1); FreeStrBuf(&defbody); if (body == NULL) { cprintf("550 Unable to save message: internal error.\r\n"); return; } - SMTPM_syslog(LOG_DEBUG, "Converting message..."); + syslog(LOG_DEBUG, "Converting message..."); msg = convert_internet_message_buf(&body); /* If the user is locally authenticated, FORCE the From: header to @@ -902,13 +895,11 @@ void smtp_data(long offset, long flags) } if (!validemail && (CtdlGetConfigInt("c_rfc822_strict_from") == CFG_SMTP_FROM_REJECT)) { - SMTP_syslog(LOG_ERR, "invalid sender '%s' - rejecting this message", msg->cm_fields[erFc822Addr]); + syslog(LOG_ERR, "invalid sender '%s' - rejecting this message", msg->cm_fields[erFc822Addr]); cprintf("550 Invalid sender '%s' - rejecting this message.\r\n", msg->cm_fields[erFc822Addr]); return; } - CM_SetField(msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename"))); - CM_SetField(msg, eHumanNode, CtdlGetConfigStr("c_humannode"), strlen(CtdlGetConfigStr("c_humannode"))); CM_SetField(msg, eOriginalRoom, HKEY(MAILROOM)); if (sSMTP->preferred_sender_name != NULL) CM_SetField(msg, eAuthor, SKEY(sSMTP->preferred_sender_name)); @@ -957,7 +948,7 @@ void smtp_data(long offset, long flags) } else { /* Ok, we'll accept this message. */ - msgnum = CtdlSubmitMsg(msg, valid, "", 0); + msgnum = CtdlSubmitMsg(msg, valid, ""); if (msgnum > 0L) { StrBufPrintf(sSMTP->OneRcpt, "250 Message accepted.\r\n"); } @@ -984,7 +975,7 @@ void smtp_data(long offset, long flags) /* Write something to the syslog(which may or may not be where the * rest of the Citadel logs are going; some sysadmins want LOG_MAIL). */ - SMTP_syslog((LOG_MAIL | LOG_INFO), + syslog((LOG_MAIL | LOG_INFO), "%ld: from=<%s>, nrcpts=%d, relay=%s [%s], stat=%s", msgnum, ChrPtr(sSMTP->from), @@ -1031,17 +1022,17 @@ void smtp_command_loop(void) char CMD[MaxSMTPCmdLen + 1]; if (sSMTP == NULL) { - SMTPM_syslog(LOG_EMERG, "Session SMTP data is null. WTF? We will crash now."); - return cit_panic_backtrace (0); + syslog(LOG_EMERG, "Session SMTP data is null. WTF? We will crash now."); + abort(); } time(&CCC->lastcmd); if (CtdlClientGetLine(sSMTP->Cmd) < 1) { - SMTPM_syslog(LOG_CRIT, "SMTP: client disconnected: ending session."); + syslog(LOG_CRIT, "SMTP: client disconnected: ending session."); CC->kill_me = KILLME_CLIENT_DISCONNECTED; return; } - SMTP_syslog(LOG_DEBUG, "SMTP server: %s", ChrPtr(sSMTP->Cmd)); + syslog(LOG_DEBUG, "SMTP server: %s", ChrPtr(sSMTP->Cmd)); if (sSMTP->command_state == smtp_user) { if (!strncmp(ChrPtr(sSMTP->Cmd), AuthPlainStr.Key, AuthPlainStr.len)) @@ -1120,7 +1111,7 @@ void smtp_cleanup_function(void) /* Don't do this stuff if this is not an SMTP session! */ if (CCC->h_command_function != smtp_command_loop) return; - SMTPM_syslog(LOG_DEBUG, "Performing SMTP cleanup hook"); + syslog(LOG_DEBUG, "Performing SMTP cleanup hook"); FreeStrBuf(&sSMTP->Cmd); FreeStrBuf(&sSMTP->helo_node); @@ -1139,17 +1130,11 @@ const char *CitadelServiceSMTP_MSA="SMTP-MSA"; const char *CitadelServiceSMTP_LMTP="LMTP"; const char *CitadelServiceSMTP_LMTP_UNF="LMTP-UnF"; -void DebugSMTPEnable(const int n) -{ - EnableSMTPLog = n; -} CTDL_MODULE_INIT(smtp) { if (!threading) { - CtdlRegisterDebugFlagHook(HKEY("SMTP"), DebugSMTPEnable, &EnableSMTPLog); - SMTPCmds = NewHash(1, NULL); RegisterSmtpCMD("AUTH", smtp_auth, 0);