#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "citserver.h"
#include "policy.h"
#include "database.h"
#include "msgbase.h"
-#include "tools.h"
#include "internet_addressing.h"
#include "genstamp.h"
#include "domain.h"
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 */
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;
*/
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);
}
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;
}
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;
}
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");
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));
-
+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)
{
- CtdlRegisterServiceHook(config.c_smtp_port, /* SMTP MTA */
- NULL,
- smtp_mta_greeting,
- smtp_command_loop,
- NULL);
+ 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);
+ 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);
-
- CtdlRegisterServiceHook(0, /* local LMTP */
- file_lmtp_socket,
- lmtp_greeting,
- smtp_command_loop,
- NULL);
-
- CtdlRegisterServiceHook(0, /* local LMTP */
- file_lmtp_unfiltered_socket,
- lmtp_unfiltered_greeting,
- smtp_command_loop,
- NULL);
-
- 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$";
}