diff options
-rw-r--r-- | smtpd/crypto.c | 20 | ||||
-rw-r--r-- | smtpd/lka.c | 4 | ||||
-rw-r--r-- | smtpd/mproc.c | 149 | ||||
-rw-r--r-- | smtpd/smtpctl.c | 42 | ||||
-rw-r--r-- | smtpd/smtpctl/CVS/Entries | 2 | ||||
-rw-r--r-- | smtpd/smtpd-api.h | 10 | ||||
-rw-r--r-- | smtpd/smtpd.h | 4 | ||||
-rw-r--r-- | smtpd/smtpd/CVS/Entries | 2 |
8 files changed, 92 insertions, 141 deletions
diff --git a/smtpd/crypto.c b/smtpd/crypto.c index 2648dbe6..1cc1af7c 100644 --- a/smtpd/crypto.c +++ b/smtpd/crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crypto.c,v 1.5 2015/12/28 22:08:30 jung Exp $ */ +/* $OpenBSD: crypto.c,v 1.6 2016/09/03 14:42:08 gilles Exp $ */ /* * Copyright (c) 2013 Gilles Chehade <gilles@openbsd.org> @@ -42,7 +42,6 @@ size_t crypto_encrypt_buffer(const char *, size_t, char *, size_t); size_t crypto_decrypt_buffer(const char *, size_t, char *, size_t); static struct crypto_ctx { - const EVP_CIPHER *cipher; unsigned char key[KEY_SIZE]; } cp; @@ -53,7 +52,6 @@ crypto_setup(const char *key, size_t len) return 0; memset(&cp, 0, sizeof cp); - cp.cipher = EVP_aes_256_gcm(); /* openssl rand -hex 16 */ memcpy(cp.key, key, sizeof cp.key); @@ -92,7 +90,7 @@ crypto_encrypt_file(FILE * in, FILE * out) return 0; EVP_CIPHER_CTX_init(&ctx); - EVP_EncryptInit(&ctx, cp.cipher, cp.key, iv); + EVP_EncryptInit_ex(&ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); /* encrypt until end of file */ while ((r = fread(ibuf, 1, CRYPTO_BUFFER_SIZE, in)) != 0) { @@ -105,7 +103,7 @@ crypto_encrypt_file(FILE * in, FILE * out) goto end; /* finalize and write last chunk if any */ - if (!EVP_EncryptFinal(&ctx, obuf, &len)) + if (!EVP_EncryptFinal_ex(&ctx, obuf, &len)) goto end; if (len && (w = fwrite(obuf, len, 1, out)) != 1) goto end; @@ -172,7 +170,7 @@ crypto_decrypt_file(FILE * in, FILE * out) EVP_CIPHER_CTX_init(&ctx); - EVP_DecryptInit(&ctx, cp.cipher, cp.key, iv); + EVP_DecryptInit_ex(&ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); /* set expected tag */ EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, sizeof tag, tag); @@ -195,7 +193,7 @@ crypto_decrypt_file(FILE * in, FILE * out) goto end; /* finalize, write last chunk if any and perform authentication check */ - if (!EVP_DecryptFinal(&ctx, obuf, &len)) + if (!EVP_DecryptFinal_ex(&ctx, obuf, &len)) goto end; if (len && (w = fwrite(obuf, len, 1, out)) != 1) goto end; @@ -240,7 +238,7 @@ crypto_encrypt_buffer(const char *in, size_t inlen, char *out, size_t outlen) len += sizeof iv; EVP_CIPHER_CTX_init(&ctx); - EVP_EncryptInit(&ctx, cp.cipher, cp.key, iv); + EVP_EncryptInit_ex(&ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); /* encrypt buffer */ if (!EVP_EncryptUpdate(&ctx, out + len, &olen, in, inlen)) @@ -248,7 +246,7 @@ crypto_encrypt_buffer(const char *in, size_t inlen, char *out, size_t outlen) len += olen; /* finalize and write last chunk if any */ - if (!EVP_EncryptFinal(&ctx, out + len, &olen)) + if (!EVP_EncryptFinal_ex(&ctx, out + len, &olen)) goto end; len += olen; @@ -293,7 +291,7 @@ crypto_decrypt_buffer(const char *in, size_t inlen, char *out, size_t outlen) in += sizeof iv; EVP_CIPHER_CTX_init(&ctx); - EVP_DecryptInit(&ctx, cp.cipher, cp.key, iv); + EVP_DecryptInit_ex(&ctx, EVP_aes_256_gcm(), NULL, cp.key, iv); /* set expected tag */ EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, sizeof tag, tag); @@ -304,7 +302,7 @@ crypto_decrypt_buffer(const char *in, size_t inlen, char *out, size_t outlen) len += olen; /* finalize, write last chunk if any and perform authentication check */ - if (!EVP_DecryptFinal(&ctx, out + len, &olen)) + if (!EVP_DecryptFinal_ex(&ctx, out + len, &olen)) goto end; ret = len + olen; diff --git a/smtpd/lka.c b/smtpd/lka.c index 703a97a8..7ca46e90 100644 --- a/smtpd/lka.c +++ b/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.194 2016/09/01 10:54:25 eric Exp $ */ +/* $OpenBSD: lka.c,v 1.195 2016/09/03 15:54:14 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -419,7 +419,7 @@ lka(void) config_process(PROC_LKA); - if (setgroups(1, &pw->pw_gid) || + if (initgroups(pw->pw_name, pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("lka: cannot drop privileges"); diff --git a/smtpd/mproc.c b/smtpd/mproc.c index d5008cea..cd98243d 100644 --- a/smtpd/mproc.c +++ b/smtpd/mproc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mproc.c,v 1.24 2016/09/01 15:12:45 eric Exp $ */ +/* $OpenBSD: mproc.c,v 1.26 2016/09/03 16:06:26 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@faurot.net> @@ -226,16 +226,13 @@ imsg_read_nofd(struct imsgbuf *ibuf) buf = ibuf->r.buf + ibuf->r.wpos; len = sizeof(ibuf->r.buf) - ibuf->r.wpos; - again: - if ((n = recv(ibuf->fd, buf, len, 0)) == -1) { - if (errno != EINTR && errno != EAGAIN) - goto fail; - goto again; + while ((n = recv(ibuf->fd, buf, len, 0)) == -1) { + if (errno != EINTR) + return (n); } - ibuf->r.wpos += n; -fail: - return (n); + ibuf->r.wpos += n; + return (n); } void @@ -422,132 +419,80 @@ m_is_eom(struct msg *m) static inline void m_get(struct msg *m, void *dst, size_t sz) { - if (m->pos + sz > m->end) - m_error("msg too short"); + if (sz > MAX_IMSGSIZE || + m->end - m->pos < (ssize_t)sz) + fatalx("msg too short"); + memmove(dst, m->pos, sz); m->pos += sz; } -static inline void -m_get_typed(struct msg *m, uint8_t type, void *dst, size_t sz) -{ - if (m->pos + 1 + sz > m->end) - m_error("msg too short"); - if (*m->pos != type) - m_error("msg bad type"); - memmove(dst, m->pos + 1, sz); - m->pos += sz + 1; -} - -static inline void -m_get_typed_sized(struct msg *m, uint8_t type, const void **dst, size_t *sz) -{ - if (m->pos + 1 + sizeof(*sz) > m->end) - m_error("msg too short"); - if (*m->pos != type) - m_error("msg bad type"); - memmove(sz, m->pos + 1, sizeof(*sz)); - m->pos += sizeof(sz) + 1; - if (m->pos + *sz > m->end) - m_error("msg too short"); - *dst = m->pos; - m->pos += *sz; -} - -static void -m_add_typed(struct mproc *p, uint8_t type, const void *data, size_t len) -{ - m_add(p, &type, 1); - m_add(p, data, len); -} - -static void -m_add_typed_sized(struct mproc *p, uint8_t type, const void *data, size_t len) -{ - m_add(p, &type, 1); - m_add(p, &len, sizeof(len)); - m_add(p, data, len); -} - -enum { - M_INT, - M_UINT32, - M_SIZET, - M_TIME, - M_STRING, - M_DATA, - M_ID, - M_EVPID, - M_MSGID, - M_SOCKADDR, - M_MAILADDR, - M_ENVELOPE, -}; - void m_add_int(struct mproc *m, int v) { - m_add_typed(m, M_INT, &v, sizeof v); + m_add(m, &v, sizeof(v)); }; void m_add_u32(struct mproc *m, uint32_t u32) { - m_add_typed(m, M_UINT32, &u32, sizeof u32); + m_add(m, &u32, sizeof(u32)); }; void m_add_size(struct mproc *m, size_t sz) { - m_add_typed(m, M_SIZET, &sz, sizeof sz); + m_add(m, &sz, sizeof(sz)); }; void m_add_time(struct mproc *m, time_t v) { - m_add_typed(m, M_TIME, &v, sizeof v); + m_add(m, &v, sizeof(v)); }; void m_add_string(struct mproc *m, const char *v) { - m_add_typed(m, M_STRING, v, strlen(v) + 1); + m_add(m, v, strlen(v) + 1); }; void m_add_data(struct mproc *m, const void *v, size_t len) { - m_add_typed_sized(m, M_DATA, v, len); + m_add_size(m, len); + m_add(m, v, len); }; void m_add_id(struct mproc *m, uint64_t v) { - m_add_typed(m, M_ID, &v, sizeof(v)); + m_add(m, &v, sizeof(v)); } void m_add_evpid(struct mproc *m, uint64_t v) { - m_add_typed(m, M_EVPID, &v, sizeof(v)); + m_add(m, &v, sizeof(v)); } void m_add_msgid(struct mproc *m, uint32_t v) { - m_add_typed(m, M_MSGID, &v, sizeof(v)); + m_add(m, &v, sizeof(v)); } void m_add_sockaddr(struct mproc *m, const struct sockaddr *sa) { - m_add_typed_sized(m, M_SOCKADDR, sa, sa->sa_len); + m_add_size(m, sa->sa_len); + m_add(m, sa, sa->sa_len); } void m_add_mailaddr(struct mproc *m, const struct mailaddr *maddr) { - m_add_typed(m, M_MAILADDR, maddr, sizeof(*maddr)); + m_add(m, maddr, sizeof(*maddr)); } #ifndef BUILD_FILTER @@ -558,7 +503,7 @@ m_add_envelope(struct mproc *m, const struct envelope *evp) envelope_dump_buffer(evp, buf, sizeof(buf)); m_add_evpid(m, evp->id); - m_add_typed_sized(m, M_ENVELOPE, buf, strlen(buf) + 1); + m_add_string(m, buf); } #endif @@ -584,25 +529,25 @@ m_add_params(struct mproc *m, struct dict *d) void m_get_int(struct msg *m, int *i) { - m_get_typed(m, M_INT, i, sizeof(*i)); + m_get(m, i, sizeof(*i)); } void m_get_u32(struct msg *m, uint32_t *u32) { - m_get_typed(m, M_UINT32, u32, sizeof(*u32)); + m_get(m, u32, sizeof(*u32)); } void m_get_size(struct msg *m, size_t *sz) { - m_get_typed(m, M_SIZET, sz, sizeof(*sz)); + m_get(m, sz, sizeof(*sz)); } void m_get_time(struct msg *m, time_t *t) { - m_get_typed(m, M_TIME, t, sizeof(*t)); + m_get(m, t, sizeof(*t)); } void @@ -610,57 +555,60 @@ m_get_string(struct msg *m, const char **s) { uint8_t *end; - if (m->pos + 2 > m->end) + if (m->pos >= m->end) m_error("msg too short"); - if (*m->pos != M_STRING) - m_error("bad msg type"); - end = memchr(m->pos + 1, 0, m->end - (m->pos + 1)); + end = memchr(m->pos, 0, m->end - m->pos); if (end == NULL) m_error("unterminated string"); - *s = m->pos + 1; + *s = m->pos; m->pos = end + 1; } void m_get_data(struct msg *m, const void **data, size_t *sz) { - m_get_typed_sized(m, M_DATA, data, sz); + m_get_size(m, sz); + + if (m->pos + *sz > m->end) + m_error("msg too short"); + + *data = m->pos; + m->pos += *sz; } void m_get_evpid(struct msg *m, uint64_t *evpid) { - m_get_typed(m, M_EVPID, evpid, sizeof(*evpid)); + m_get(m, evpid, sizeof(*evpid)); } void m_get_msgid(struct msg *m, uint32_t *msgid) { - m_get_typed(m, M_MSGID, msgid, sizeof(*msgid)); + m_get(m, msgid, sizeof(*msgid)); } void m_get_id(struct msg *m, uint64_t *id) { - m_get_typed(m, M_ID, id, sizeof(*id)); + m_get(m, id, sizeof(*id)); } void m_get_sockaddr(struct msg *m, struct sockaddr *sa) { - size_t s; - const void *d; + size_t len; - m_get_typed_sized(m, M_SOCKADDR, &d, &s); - memmove(sa, d, s); + m_get_size(m, &len); + m_get(m, sa, len); } void m_get_mailaddr(struct msg *m, struct mailaddr *maddr) { - m_get_typed(m, M_MAILADDR, maddr, sizeof(*maddr)); + m_get(m, maddr, sizeof(*maddr)); } #ifndef BUILD_FILTER @@ -668,13 +616,12 @@ void m_get_envelope(struct msg *m, struct envelope *evp) { uint64_t evpid; - size_t s; - const void *d; + const char *buf; m_get_evpid(m, &evpid); - m_get_typed_sized(m, M_ENVELOPE, &d, &s); + m_get_string(m, &buf); - if (!envelope_load_buffer(evp, d, s - 1)) + if (!envelope_load_buffer(evp, buf, strlen(buf))) fatalx("failed to retrieve envelope"); evp->id = evpid; } diff --git a/smtpd/smtpctl.c b/smtpd/smtpctl.c index 9cc68c07..5febe339 100644 --- a/smtpd/smtpctl.c +++ b/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.149 2016/04/29 08:55:08 eric Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.150 2016/09/03 16:06:26 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot <eric@openbsd.org> @@ -220,45 +220,51 @@ srv_read(void *dst, size_t sz) static void srv_get_int(int *i) { - uint8_t type; - - srv_read(&type, 1); srv_read(i, sizeof(*i)); } static void srv_get_time(time_t *t) { - uint8_t type; - - srv_read(&type, 1); srv_read(t, sizeof(*t)); } static void srv_get_evpid(uint64_t *evpid) { - uint8_t type; - - srv_read(&type, 1); srv_read(evpid, sizeof(*evpid)); } static void +srv_get_string(const char **s) +{ + const char *end; + size_t len; + + if (rlen == 0) + errx(1, "message too short"); + + end = memchr(rdata, 0, rlen); + if (end == NULL) + errx(1, "unterminated string"); + + len = end + 1 - rdata; + + *s = rdata; + rlen -= len; + rdata += len; +} + +static void srv_get_envelope(struct envelope *evp) { uint64_t evpid; - uint8_t type; - size_t s; - const void *d; + const char *str; srv_get_evpid(&evpid); - srv_read(&type, sizeof(type)); - srv_read(&s, sizeof(s)); - d = rdata; - srv_read(NULL, s); + srv_get_string(&str); - envelope_load_buffer(evp, d, s - 1); + envelope_load_buffer(evp, str, strlen(str)); evp->id = evpid; } diff --git a/smtpd/smtpctl/CVS/Entries b/smtpd/smtpctl/CVS/Entries index 8214dd8b..376303a5 100644 --- a/smtpd/smtpctl/CVS/Entries +++ b/smtpd/smtpctl/CVS/Entries @@ -1,2 +1,2 @@ -/Makefile/1.44/Wed Mar 30 06:38:46 2016// +/Makefile/1.44/Sat Sep 3 16:12:42 2016// D diff --git a/smtpd/smtpd-api.h b/smtpd/smtpd-api.h index 9a7b3308..ce18063f 100644 --- a/smtpd/smtpd-api.h +++ b/smtpd/smtpd-api.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd-api.h,v 1.30 2016/06/29 06:46:06 eric Exp $ */ +/* $OpenBSD: smtpd-api.h,v 1.31 2016/09/03 16:06:26 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot <eric@openbsd.org> @@ -20,7 +20,7 @@ #ifndef _SMTPD_API_H_ #define _SMTPD_API_H_ -#define FILTER_API_VERSION 51 +#define FILTER_API_VERSION 52 struct mailaddr { char user[SMTPD_MAXLOCALPARTSIZE]; @@ -96,7 +96,7 @@ struct filter_connect { const char *hostname; }; -#define PROC_QUEUE_API_VERSION 1 +#define PROC_QUEUE_API_VERSION 2 enum { PROC_QUEUE_OK, @@ -116,7 +116,7 @@ enum { PROC_QUEUE_ENVELOPE_WALK, }; -#define PROC_SCHEDULER_API_VERSION 1 +#define PROC_SCHEDULER_API_VERSION 2 struct scheduler_info; @@ -184,7 +184,7 @@ struct scheduler_info { #define SCHED_MDA 0x10 #define SCHED_MTA 0x20 -#define PROC_TABLE_API_VERSION 1 +#define PROC_TABLE_API_VERSION 2 struct table_open_params { uint32_t version; diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h index 30dbc6ac..0b6d3c5f 100644 --- a/smtpd/smtpd.h +++ b/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.521 2016/09/01 10:54:25 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.522 2016/09/03 16:06:26 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -161,7 +161,7 @@ union lookup { * Bump IMSG_VERSION whenever a change is made to enum imsg_type. * This will ensure that we can never use a wrong version of smtpctl with smtpd. */ -#define IMSG_VERSION 14 +#define IMSG_VERSION 15 enum imsg_type { IMSG_NONE, diff --git a/smtpd/smtpd/CVS/Entries b/smtpd/smtpd/CVS/Entries index bd198cee..b2a8a563 100644 --- a/smtpd/smtpd/CVS/Entries +++ b/smtpd/smtpd/CVS/Entries @@ -1,2 +1,2 @@ -/Makefile/1.85/Sat Jan 9 09:48:03 2016// +/Makefile/1.85/Sat Sep 3 16:12:42 2016// D |