Fix a crash reported by Ross L Richardson.
ok gilles@
-/* $OpenBSD: smtp.h,v 1.2 2018/09/20 11:42:28 eric Exp $ */
+/* $OpenBSD: smtp.h,v 1.3 2019/09/02 20:05:21 eric Exp $ */
/*
* Copyright (c) 2018 Eric Faurot <eric@openbsd.org>
/* TLS options */
int tls_req; /* requested TLS mode */
- void *tls_ctx; /* TLS ctx to use */
int tls_verify; /* need valid server certificate */
/* SMTP options */
/* smtp_client.c */
struct smtp_client *smtp_connect(const struct smtp_params *, void *);
void smtp_cert_verified(struct smtp_client *, int);
+void smtp_set_tls(struct smtp_client *, void *);
void smtp_quit(struct smtp_client *);
void smtp_sendmail(struct smtp_client *, struct smtp_mail *);
/* callbacks */
void smtp_verify_server_cert(void *, struct smtp_client *, void *);
+void smtp_require_tls(void *, struct smtp_client *);
void smtp_ready(void *, struct smtp_client *);
void smtp_failed(void *, struct smtp_client *, int, const char *);
void smtp_closed(void *, struct smtp_client *);
-/* $OpenBSD: smtp_client.c,v 1.10 2019/06/12 17:42:53 eric Exp $ */
+/* $OpenBSD: smtp_client.c,v 1.11 2019/09/02 20:05:21 eric Exp $ */
/*
* Copyright (c) 2018 Eric Faurot <eric@openbsd.org>
}
}
+void
+smtp_set_tls(struct smtp_client *proto, void *ctx)
+{
+ io_start_tls(proto->io, ctx);
+}
+
void
smtp_quit(struct smtp_client *proto)
{
smtp_client_state(proto, STATE_AUTH);
}
else
- io_start_tls(proto->io, proto->params.tls_ctx);
+ smtp_require_tls(proto->tag, proto);
break;
case STATE_AUTH_PLAIN:
case IO_CONNECTED:
if (proto->params.tls_req == TLS_SMTPS) {
io_set_write(io);
- io_start_tls(proto->io, proto->params.tls_ctx);
+ smtp_require_tls(proto->tag, proto);
}
else
smtp_client_state(proto, STATE_BANNER);
-/* $OpenBSD: smtpc.c,v 1.7 2019/09/02 19:17:43 gilles Exp $ */
+/* $OpenBSD: smtpc.c,v 1.8 2019/09/02 20:05:21 eric Exp $ */
/*
* Copyright (c) 2018 Eric Faurot <eric@openbsd.org>
if (port == NULL)
port = "smtp";
- if (params.tls_req != TLS_NO) {
- params.tls_ctx = ssl_mta_init(NULL, NULL, 0, NULL);
- if (params.tls_ctx == NULL)
- fatal("ssl_mta_init");
- }
-
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
smtp_cert_verified(proto, CERT_UNKNOWN);
}
+void
+smtp_require_tls(void *tag, struct smtp_client *proto)
+{
+ void *ctx;
+
+ ctx = ssl_mta_init(NULL, NULL, 0, NULL);
+
+ smtp_set_tls(proto, ctx);
+}
+
void
smtp_ready(void *tag, struct smtp_client *proto)
{