Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

lord-maild: mark the certificate event of an implicit-TLS SMTP server as smtp

Federico Pereiraab1cfba20c1e
diff --git a/server/src/mail/dav.c b/server/src/mail/dav.c
index 4de97a5..8cdd34f 100644
--- a/server/src/mail/dav.c
+++ b/server/src/mail/dav.c
@@ -18,7 +18,7 @@ static int dav_connect(Dav *d, const char *host, int port, int tls) {
if (!tls) { snprintf(d->err, sizeof d->err, "insecure"); return -1; }
TlsInfo ti;
char why[64];
- d->c = open_conn(d->a->id, host, port, 1, d->a->pin_dav, &ti, why, sizeof why);
+ d->c = open_conn(d->a->id, 0, host, port, 1, d->a->pin_dav, &ti, why, sizeof why);
if (!d->c) { snprintf(d->err, sizeof d->err, "%s", why); return -1; }
snprintf(d->host, sizeof d->host, "%s", host);
d->port = port;
diff --git a/server/src/mail/imap.c b/server/src/mail/imap.c
index 38d7d35..15822cc 100644
--- a/server/src/mail/imap.c
+++ b/server/src/mail/imap.c
@@ -148,7 +148,7 @@ static int imap_open(Imap *im, char *err, size_t ecap) {
if (!pw) { need_auth(a); snprintf(err, ecap, "no-password"); return -2; }
TlsInfo ti;
char why[64];
- im->c = open_conn(a->id, a->imap.host, a->imap.port, a->imap.sec == SEC_SSL, a->pin_imap, &ti, why, sizeof why);
+ im->c = open_conn(a->id, 0, a->imap.host, a->imap.port, a->imap.sec == SEC_SSL, a->pin_imap, &ti, why, sizeof why);
if (!im->c) { free(pw); snprintf(err, ecap, "%s", why); return !strcmp(why, "cert") ? -3 : -1; }
size_t len;
char *greet = read_raw(im, &len);
diff --git a/server/src/mail/maild.c b/server/src/mail/maild.c
index be394ec..89fb762 100644
--- a/server/src/mail/maild.c
+++ b/server/src/mail/maild.c
@@ -150,7 +150,7 @@ static void on_sock(DocMsg *m) {
pthread_mutex_unlock(&pend_mu);
}
-Conn *open_conn(const char *acct, const char *host, int port, int tls_now, const char *pin, TlsInfo *ti, char *why, size_t wcap) {
+Conn *open_conn(const char *acct, int smtp, const char *host, int port, int tls_now, const char *pin, TlsInfo *ti, char *why, size_t wcap) {
int fd = net_connect(host, port, why, wcap);
if (fd < 0) return NULL;
Conn *c = conn_new(fd, host, 60000);
@@ -163,7 +163,7 @@ Conn *open_conn(const char *acct, const char *host, int port, int tls_now, const
jb_init(&b);
jb_raw(&b, "{\"ev\":\"cert\",\"acct\":"); jb_str(&b, acct);
jb_raw(&b, ",\"host\":"); jb_str(&b, host);
- jb_printf(&b, ",\"port\":%d,\"reason\":", port); jb_str(&b, ti->reason);
+ jb_printf(&b, ",\"port\":%d,%s\"reason\":", port, smtp ? "\"smtp\":true," : ""); jb_str(&b, ti->reason);
jb_raw(&b, ",\"subject\":"); jb_str(&b, ti->subject);
jb_raw(&b, ",\"issuer\":"); jb_str(&b, ti->issuer);
jb_raw(&b, ",\"sha256\":"); jb_str(&b, ti->sha256);
diff --git a/server/src/mail/maild.h b/server/src/mail/maild.h
index 3a1e029..a44df86 100644
--- a/server/src/mail/maild.h
+++ b/server/src/mail/maild.h
@@ -40,7 +40,8 @@ void reply_image(uint32_t id, const uint32_t *argb, int w, int h);
int net_connect(const char *host, int port, char *why, size_t wcap);
/* Connects and starts TLS (implicit or STARTTLS is the caller's job when starttls=1).
* On a certificate problem emits a "cert" event for that account. */
-Conn *open_conn(const char *acct, const char *host, int port, int tls_now, const char *pin, TlsInfo *ti, char *why, size_t wcap);
+/* smtp: the connection is the account's SMTP server (its certificate event says so, so Mail pins it as "smtp") */
+Conn *open_conn(const char *acct, int smtp, const char *host, int port, int tls_now, const char *pin, TlsInfo *ti, char *why, size_t wcap);
void dbg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
/* ---- files under cache_fd ---- */
diff --git a/server/src/mail/smtp.c b/server/src/mail/smtp.c
index 1787601..e94bd27 100644
--- a/server/src/mail/smtp.c
+++ b/server/src/mail/smtp.c
@@ -212,7 +212,7 @@ int smtp_send(Account *a, const char *from, const char **rcpt, int nrcpt, const
if (s.sec == SEC_NONE || !s.host[0]) { free(pw); snprintf(err, ecap, s.host[0] ? "insecure" : "no SMTP server"); return -1; }
TlsInfo ti;
char why[64], text[512], caps[4096];
- Conn *c = open_conn(a->id, s.host, s.port, s.sec == SEC_SSL, pin, &ti, why, sizeof why);
+ Conn *c = open_conn(a->id, 1, s.host, s.port, s.sec == SEC_SSL, pin, &ti, why, sizeof why);
if (!c) { free(pw); snprintf(err, ecap, "%s", why); return -1; }
int r = -1;
if (smtp_reply(c, text, sizeof text, NULL, 0) != 220) { snprintf(err, ecap, "greeting: %s", text); goto out; }