*/
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, ...);
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 *);
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;
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];
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) {
}
}
+#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");
int
sm_winit (int mode, char *from)
{
- char *smtpcom;
+ char *smtpcom = NULL;
switch (mode) {
case S_MAIL:
case S_SAML:
smtpcom = "SAML";
break;
+
+ default:
+ /* Hopefully, we do not get here. */
+ break;
}
switch (smtalk (SM_MAIL, "%s FROM:<%s>", smtpcom, from)) {
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;
int i, code, cont, bc, rc, more;
unsigned char *bp;
char *rp;
- char **ehlo, buffer[BUFSIZ];
+ char **ehlo = NULL, buffer[BUFSIZ];
if (doingEHLO) {
static int at_least_once = 0;