* complete copyright information.
*/
-#include <h/mh.h>
+#include "h/mh.h"
+#include "sbr/r1bindex.h"
+#include "sbr/client.h"
+#include "sbr/error.h"
#include "smtp.h"
-#include <h/mts.h>
-#include <h/signals.h>
-#include <h/utils.h>
-#include <h/netsec.h>
+#include "h/mts.h"
+#include "h/signals.h"
+#include "h/utils.h"
+#include "h/netsec.h"
#include <sys/socket.h>
#include "sbr/base64.h"
static char *EHLOset (char *) PURE;
static int sm_sasl_callback(enum sasl_message_type, unsigned const char *,
unsigned int, unsigned char **, unsigned int *,
- char **);
+ void *, char **);
int
sm_init (char *client, char *server, char *port, int watch, int verbose,
if (sasl) {
if (netsec_set_sasl_params(nsc, "smtp", saslmech, sm_sasl_callback,
- &errstr) != OK)
+ NULL, &errstr) != OK)
return sm_nerror(errstr);
}
if (sasl) {
if (netsec_set_sasl_params(nsc, "smtp", saslmech, sm_sasl_callback,
- &errstr) != OK)
+ NULL, &errstr) != OK)
return sm_nerror(errstr);
}
execvp (sendmail, vec);
fprintf (stderr, "unable to exec ");
perror (sendmail);
- _exit (-1); /* NOTREACHED */
+ _exit(1); /* NOTREACHED */
default:
SIGNAL (SIGPIPE, SIG_IGN);
int
sm_wtxt (char *buffer, int len)
{
- int result;
+ int result, snoopstate;
+
+ if ((snoopstate = netsec_get_snoop(nsc)))
+ netsec_set_snoop(nsc, 0);
result = sm_wstream (buffer, len);
+ netsec_set_snoop(nsc, snoopstate);
return result == NOTOK ? RP_BHST : RP_OK;
}
int
sm_wtend (void)
{
+ int snoopstate;
+
+ if ((snoopstate = netsec_get_snoop(nsc)))
+ netsec_set_snoop(nsc, 0);
+
if (sm_wstream(NULL, 0) == NOTOK)
return RP_BHST;
+ /*
+ * Because snoop output now happens at flush time, if we are using snoop
+ * we force an extra flush here. While this introduces some extra network
+ * traffic, we're only doing it when snoop is in effect so I think it's
+ * reasonable.
+ */
+
+ if (snoopstate) {
+ char *errstr;
+ if (netsec_flush(nsc, &errstr) != OK) {
+ sm_nerror(errstr);
+ return RP_BHST;
+ }
+ netsec_set_snoop(nsc, snoopstate);
+ }
+
switch (smtalk (SM_DOT + 3 * sm_addrs, ".")) {
case 250:
case 251:
char **ehlo = EHLOkeys, *buffer;
if (doingEHLO) {
- static int at_least_once = 0;
+ static bool at_least_once;
if (at_least_once) {
char *ep;
free (ep);
}
} else {
- at_least_once = 1;
+ at_least_once = true;
}
ehlo = EHLOkeys;
}
}
- return 0;
+ return NULL;
}
/*
static int
sm_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata,
unsigned int indatalen, unsigned char **outdata,
- unsigned int *outdatalen, char **errstr)
+ unsigned int *outdatalen, void *context, char **errstr)
{
int rc, snoopoffset;
char *mech, *line;
size_t len;
+ NMH_UNUSED(context);
switch (mtype) {
case NETSEC_SASL_START:
snoopoffset = 6 + strlen(mech);
rc = netsec_printf(nsc, errstr, "AUTH %s %s\r\n", mech, b64data);
free(b64data);
- netsec_set_snoop_callback(nsc, NULL, NULL);
} else {
rc = netsec_printf(nsc, errstr, "AUTH %s\r\n", mech);
}
- if (rc != OK)
+ if (rc != OK) {
+ netsec_set_snoop_callback(nsc, NULL, NULL);
return NOTOK;
+ }
+
+ rc = netsec_flush(nsc, errstr);
+ netsec_set_snoop_callback(nsc, NULL, NULL);
- if (netsec_flush(nsc, errstr) != OK)
+ if (rc != OK)
return NOTOK;
break;
writeBase64raw(indata, indatalen, b64data);
netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL);
rc = netsec_printf(nsc, errstr, "%s\r\n", b64data);
- netsec_set_snoop_callback(nsc, NULL, NULL);
free(b64data);
}
if (rc != OK)
return NOTOK;
- if (netsec_flush(nsc, errstr) != OK)
+ rc = netsec_flush(nsc, errstr);
+ netsec_set_snoop_callback(nsc, NULL, NULL);
+
+ if (rc != OK)
return NOTOK;
break;