X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=mts%2Fsmtp%2Fsmtp.c;h=7413639cece93a4bcfdf04f66753d85a96f67353;hb=a1e2c63df5871a156c2735b679b58716a0af2b29;hp=37a7b07c7c32d629a17fb16c98073e15d264e695;hpb=7b98850d3b8b2453b473fdfb6db52f4aa3fe39b6;p=mmh diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index 37a7b07..7413639 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -128,7 +128,8 @@ char *EHLOkeys[MAXEHLO + 1]; */ static int smtp_init (char *, char *, char *, int, int, int, int, int, int, char *, char *); -static int sendmail_init (char *, char *, int, int, int, int, int); +static int sendmail_init (char *, char *, int, int, int, int, int, int, + char *, char *); static int rclient (char *, char *); static int sm_ierror (char *fmt, ...); @@ -144,7 +145,6 @@ static char *EHLOset (char *); static int sm_fwrite(char *, int); static int sm_fputs(char *); static int sm_fputc(int); -static int sm_getc(void); static void sm_fflush(void); static int sm_fgets(char *, int, FILE *); @@ -166,13 +166,13 @@ sm_init (char *client, char *server, char *port, int watch, int verbose, debug, onex, queued, sasl, saslmech, user); else return sendmail_init (client, server, watch, verbose, - debug, onex, queued); + debug, onex, queued, sasl, saslmech, user); } static int smtp_init (char *client, char *server, char *port, int watch, int verbose, - int debug, int onex, int queued, int sasl, char *saslmech, - char *user) + int debug, int onex, int queued, + int sasl, char *saslmech, char *user) { #ifdef CYRUS_SASL char *server_mechs; @@ -300,8 +300,12 @@ send_options: ; int sendmail_init (char *client, char *server, int watch, int verbose, - int debug, int onex, int queued) + int debug, int onex, int queued, + int sasl, char *saslmech, char *user) { +#ifdef CYRUS_SASL + char *server_mechs; +#endif /* CYRUS_SASL */ int i, result, vecp; int pdi[2], pdo[2]; char *vec[15]; @@ -326,6 +330,13 @@ sendmail_init (char *client, char *server, int watch, int verbose, client = "localhost"; #endif +#ifdef CYRUS_SASL + sasl_inbuffer = malloc(SASL_MAXRECVBUF); + if (!sasl_inbuffer) + return sm_ierror("Unable to allocate %d bytes for read buffer", + SASL_MAXRECVBUF); +#endif /* CYRUS_SASL */ + if (pipe (pdi) == NOTOK) return sm_ierror ("no pipes"); if (pipe (pdo) == NOTOK) { @@ -420,6 +431,35 @@ sendmail_init (char *client, char *server, int watch, int verbose, } } +#ifdef CYRUS_SASL + /* + * If the user asked for SASL, then check to see if the SMTP server + * supports it. Otherwise, error out (because the SMTP server + * might have been spoofed; we don't want to just silently not + * do authentication + */ + + if (sasl) { + if (! (server_mechs = EHLOset("AUTH"))) { + sm_end(NOTOK); + return sm_ierror("SMTP server does not support SASL"); + } + + if (saslmech && stringdex(saslmech, server_mechs) == -1) { + sm_end(NOTOK); + return sm_ierror("Requested SASL mech \"%s\" is not in the " + "list of supported mechanisms:\n%s", + saslmech, server_mechs); + } + + if (sm_auth_sasl(user, saslmech ? saslmech : server_mechs, + server) != RP_OK) { + sm_end(NOTOK); + return NOTOK; + } + } +#endif /* CYRUS_SASL */ + #ifndef ZMAILER if (onex) smtalk (SM_HELO, "ONEX"); @@ -448,7 +488,7 @@ rclient (char *server, char *service) int sm_winit (int mode, char *from) { - char *smtpcom; + char *smtpcom = NULL; switch (mode) { case S_MAIL: @@ -466,6 +506,10 @@ sm_winit (int mode, char *from) case S_SAML: smtpcom = "SAML"; break; + + default: + /* Hopefully, we do not get here. */ + break; } switch (smtalk (SM_MAIL, "%s FROM:<%s>", smtpcom, from)) { @@ -897,20 +941,12 @@ sm_auth_sasl(char *user, char *mechlist, char *inhost) return NOTOK; } sasl_outbuflen = 0; - - sasl_inbuffer = malloc(SASL_MAXRECVBUF); - - if (sasl_inbuffer == NULL) { - sm_ierror("Unable to allocate %d bytes for SASL input " - "buffer", SASL_MAXRECVBUF); - free(sasl_outbuffer); - return NOTOK; - } sasl_inbuflen = 0; sasl_inptr = sasl_inbuffer; } else { sasl_outbuffer = NULL; - sasl_inbuffer = NULL; + /* Don't NULL out sasl_inbuffer because it could be used in + sm_fgetc (). */ } sasl_complete = 1; @@ -1172,10 +1208,10 @@ sm_werror (void) static int smhear (void) { - int i, code, cont, bc, rc, more; + int i, code, cont, bc = 0, rc, more; unsigned char *bp; char *rp; - char **ehlo, buffer[BUFSIZ]; + char **ehlo = NULL, buffer[BUFSIZ]; if (doingEHLO) { static int at_least_once = 0;