summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2012-08-25 23:35:10 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2012-08-25 23:35:10 +0000
commit04b0d16fcd5086e7220b1bcb4d14c77855a23238 (patch)
tree9b78accae290b06eb1abb504924b363bd0a6d4e3 /usr.sbin/smtpd
parentf306d139dbf080f0221fe7bae15fed27738ebd01 (diff)
Add compress_backend, allowing compression of messages and envelopes in the queue.
To use it, just add "queue compress" in smtpd.conf. For now, only zlib is used. lots of feedback from eric@ and gilles@ ok eric@ gilles@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/compress_backend.c71
-rw-r--r--usr.sbin/smtpd/compress_zlib.c130
-rw-r--r--usr.sbin/smtpd/encrypt.c56
-rw-r--r--usr.sbin/smtpd/parse.y27
-rw-r--r--usr.sbin/smtpd/queue_backend.c145
-rw-r--r--usr.sbin/smtpd/smtpctl/Makefile5
-rw-r--r--usr.sbin/smtpd/smtpd.c10
-rw-r--r--usr.sbin/smtpd/smtpd.h29
-rw-r--r--usr.sbin/smtpd/smtpd/Makefile13
-rw-r--r--usr.sbin/smtpd/util.c24
10 files changed, 491 insertions, 19 deletions
diff --git a/usr.sbin/smtpd/compress_backend.c b/usr.sbin/smtpd/compress_backend.c
new file mode 100644
index 00000000000..fe0563954a5
--- /dev/null
+++ b/usr.sbin/smtpd/compress_backend.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2012 Charles Longeau <chl@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <imsg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "smtpd.h"
+
+extern struct compress_backend compress_zlib;
+
+struct compress_backend *
+compress_backend_lookup(const char *name)
+{
+ if (!strcmp(name, "zlib"))
+ return &compress_zlib;
+
+ /* if (!strcmp(name, "bzip")) */
+ /* return &compress_bzip; */
+
+ /* if (!strcmp(name, "7zip")) */
+ /* return &compress_7zip; */
+
+ return (NULL);
+}
+
+int
+compress_file(int fdin, int fdout)
+{
+ return env->sc_compress->compress_file(fdin, fdout);
+}
+
+int
+uncompress_file(int fdin, int fdout)
+{
+ return env->sc_compress->uncompress_file(fdin, fdout);
+}
+
+size_t
+compress_buffer(const char *ib, size_t iblen, char *ob, size_t oblen)
+{
+ return env->sc_compress->compress_buffer(ib, iblen, ob, oblen);
+}
+
+size_t
+uncompress_buffer(const char *ib, size_t iblen, char *ob, size_t oblen)
+{
+ return env->sc_compress->uncompress_buffer(ib, iblen, ob, oblen);
+}
diff --git a/usr.sbin/smtpd/compress_zlib.c b/usr.sbin/smtpd/compress_zlib.c
new file mode 100644
index 00000000000..7026da20607
--- /dev/null
+++ b/usr.sbin/smtpd/compress_zlib.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2012 Charles Longeau <chl@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <fcntl.h>
+#include <imsg.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <zlib.h>
+
+#include "smtpd.h"
+#include "log.h"
+
+static int compress_file_zlib(int, int);
+static int uncompress_file_zlib(int, int);
+static size_t compress_buffer_zlib(const char *, size_t, char *, size_t);
+static size_t uncompress_buffer_zlib(const char *, size_t, char *, size_t);
+
+struct compress_backend compress_zlib = {
+ compress_file_zlib,
+ uncompress_file_zlib,
+ compress_buffer_zlib,
+ uncompress_buffer_zlib
+};
+
+
+static int
+compress_file_zlib(int fdin, int fdout)
+{
+ gzFile gzfd;
+ char buf[8192];
+ int r, w;
+
+ if (fdin == -1 || fdout == -1)
+ return (0);
+
+ gzfd = gzdopen(fdout, "wb");
+
+ while ((r = read(fdin, buf, sizeof(buf)))) {
+ if (r == -1)
+ return (0);
+
+ w = gzwrite(gzfd, buf, r);
+ if (w == 0 || w != r)
+ return (0);
+ }
+ gzclose(gzfd);
+
+ return (1);
+}
+
+static int
+uncompress_file_zlib(int fdin, int fdout)
+{
+ gzFile gzfd;
+ int outfd;
+ int r, w;
+ char buf[8192];
+
+ if (fdin == -1 || fdout == -1)
+ return (0);
+
+ gzfd = gzdopen(fdin, "r");
+ while ((r = gzread(gzfd, buf, sizeof(buf)))) {
+
+ if (r == -1)
+ return (0);
+
+ w = write(fdout, buf, r);
+
+ if (w == -1 || w != r)
+ return (0);
+ }
+ gzclose(gzfd);
+
+ return (1);
+}
+
+static size_t
+compress_buffer_zlib(const char *inbuf, size_t inbuflen, char *outbuf, size_t outbuflen)
+{
+ uLong compress_bound;
+ int ret;
+
+ compress_bound = compressBound((uLongf) inbuflen);
+
+ if (compress_bound > outbuflen)
+ return (0);
+
+ ret = compress((Bytef *) outbuf, (uLongf *) &outbuflen,
+ (const Bytef *) inbuf, (uLong) inbuflen);
+
+ return (ret == Z_OK ? outbuflen : 0);
+}
+
+static size_t
+uncompress_buffer_zlib(const char *inbuf, size_t inbuflen, char *outbuf, size_t outbuflen)
+{
+ int ret;
+
+ ret = uncompress((Bytef *) outbuf, (uLongf *) &outbuflen,
+ (const Bytef *) inbuf, (uLong) inbuflen);
+
+ return (ret == Z_OK ? outbuflen : 0);
+}
diff --git a/usr.sbin/smtpd/encrypt.c b/usr.sbin/smtpd/encrypt.c
new file mode 100644
index 00000000000..831d92ffce2
--- /dev/null
+++ b/usr.sbin/smtpd/encrypt.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012 Charles Longeau <chl@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <imsg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "smtpd.h"
+#include "log.h"
+
+
+int
+encrypt_file(int fdin, int fdout)
+{
+ return (1);
+}
+
+int
+decrypt_file(int fdin, int fdout)
+{
+ return (1);
+}
+
+size_t
+encrypt_buffer(const char *ib, size_t iblen, char *ob, size_t oblen)
+{
+ return (1);
+}
+
+size_t
+decrypt_buffer(const char *ib, size_t iblen, char *ob, size_t oblen)
+{
+ return (1);
+}
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index aee31596a91..1dcb6a2c31c 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.91 2012/08/21 20:19:46 eric Exp $ */
+/* $OpenBSD: parse.y,v 1.92 2012/08/25 23:35:09 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -121,7 +121,7 @@ typedef struct {
%}
-%token AS QUEUE INTERVAL SIZE LISTEN ON ALL PORT EXPIRE
+%token AS QUEUE COMPRESS INTERVAL SIZE LISTEN ON ALL PORT EXPIRE
%token MAP HASH LIST SINGLE SSL SMTPS CERTIFICATE
%token DB PLAIN DOMAIN SOURCE
%token RELAY BACKUP VIA DELIVER TO MAILDIR MBOX HOSTNAME
@@ -135,7 +135,7 @@ typedef struct {
%type <v.tv> interval
%type <v.object> mapref
%type <v.maddr> relay_as
-%type <v.string> certname user tag on alias credentials
+%type <v.string> certname user tag on alias credentials compress
%%
@@ -306,9 +306,29 @@ credentials : AUTH STRING {
| /* empty */ { $$ = 0; }
;
+compress : COMPRESS STRING {
+ $$ = $2;
+ }
+ | COMPRESS {
+ $$ = "zlib";
+ }
+ | /* empty */ { $$ = NULL; }
+ ;
+
main : QUEUE INTERVAL interval {
conf->sc_qintval = $3;
}
+ | QUEUE compress {
+ if ($2) {
+ conf->sc_queue_flags |= QUEUE_COMPRESS;
+ conf->sc_queue_compress_algo = strdup($2);
+ log_debug("queue compress using %s", conf->sc_queue_compress_algo);
+ }
+ if ($2 == NULL) {
+ yyerror("invalid queue compress <algo>");
+ YYERROR;
+ }
+ }
| EXPIRE STRING {
conf->sc_qexpire = delaytonum($2);
if (conf->sc_qexpire == -1) {
@@ -1103,6 +1123,7 @@ lookup(char *s)
{ "auth", AUTH },
{ "backup", BACKUP },
{ "certificate", CERTIFICATE },
+ { "compress", COMPRESS },
{ "db", DB },
{ "deliver", DELIVER },
{ "domain", DOMAIN },
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index 45c79e4a1b3..8a83dd684a1 100644
--- a/usr.sbin/smtpd/queue_backend.c
+++ b/usr.sbin/smtpd/queue_backend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_backend.c,v 1.32 2012/08/24 19:51:48 eric Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.33 2012/08/25 23:35:09 chl Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <ctype.h>
+#include <errno.h>
#include <event.h>
#include <fcntl.h>
#include <imsg.h>
@@ -99,7 +100,61 @@ queue_message_delete(uint32_t msgid)
int
queue_message_commit(uint32_t msgid)
{
+ char msgpath[MAXPATHLEN];
+ char tmppath[MAXPATHLEN];
+ int fdin = -1, fdout = -1;
+
+ queue_message_incoming_path(msgid, msgpath, sizeof msgpath);
+ strlcat(msgpath, PATH_MESSAGE, sizeof(msgpath));
+
+ if (env->sc_queue_flags & QUEUE_COMPRESS) {
+
+ bsnprintf(tmppath, sizeof tmppath, "%s.comp", msgpath);
+ fdin = open(msgpath, O_RDONLY);
+ fdout = open(tmppath, O_RDWR | O_CREAT | O_EXCL, 0600);
+ if (fdin == -1 || fdout == -1)
+ goto err;
+ if (! compress_file(fdin, fdout))
+ goto err;
+ close(fdin);
+ close(fdout);
+
+ if (rename(tmppath, msgpath) == -1) {
+ if (errno == ENOSPC)
+ return (0);
+ fatal("queue_message_commit: rename");
+ }
+ }
+
+#if 0
+ if (env->sc_queue_flags & QUEUE_ENCRYPT) {
+
+ bsnprintf(tmppath, sizeof tmppath, "%s.crypt", msgpath);
+ fdin = open(msgpath, O_RDONLY);
+ fdout = open(tmppath, O_RDWR | O_CREAT | O_EXCL, 0600);
+ if (fdin == -1 || fdout == -1)
+ goto err;
+ if (! encrypt_file(fdin, fdout))
+ goto err;
+ close(fdin);
+ close(fdout);
+
+ if (rename(tmppath, msgpath) == -1) {
+ if (errno == ENOSPC)
+ return (0);
+ fatal("queue_message_commit: rename");
+ }
+ }
+#endif
+
return env->sc_queue->message(QOP_COMMIT, &msgid);
+
+err:
+ if (fdin != -1)
+ close(fdin);
+ if (fdout != -1)
+ close(fdout);
+ return 0;
}
int
@@ -111,7 +166,36 @@ queue_message_corrupt(uint32_t msgid)
int
queue_message_fd_r(uint32_t msgid)
{
- return env->sc_queue->message(QOP_FD_R, &msgid);
+ int fdin, fdout;
+
+ fdin = env->sc_queue->message(QOP_FD_R, &msgid);
+
+#if 0
+ if (env->sc_queue_flags & QUEUE_ENCRYPT) {
+ fdout = mktmpfile();
+ if (! decrypt_file(fdin, fdout))
+ goto err;
+ close(fdin);
+ fdin = fdout;
+ }
+#endif
+
+ if (env->sc_queue_flags & QUEUE_COMPRESS) {
+ fdout = mktmpfile();
+ if (! uncompress_file(fdin, fdout))
+ goto err;
+ close(fdin);
+ fdin = fdout;
+ }
+
+ return (fdin);
+
+err:
+ if (fdin != -1)
+ close(fdin);
+ if (fdout != -1)
+ close(fdout);
+ return -1;
}
int
@@ -128,15 +212,66 @@ queue_message_fd_rw(uint32_t msgid)
static int
queue_envelope_dump_buffer(struct envelope *ep, char *evpbuf, size_t evpbufsize)
{
- return (envelope_dump_buffer(ep, evpbuf, evpbufsize));
+ char evpbufcom[sizeof(struct envelope)];
+ char evpbufenc[sizeof(struct envelope)];
+ char *evp;
+ size_t evplen;
+
+ evp = evpbuf;
+ evplen = envelope_dump_buffer(ep, evpbuf, evpbufsize);
+ if (evplen == 0)
+ return (0);
+
+ if (env->sc_queue_flags & QUEUE_COMPRESS) {
+ evplen = compress_buffer(evp, evplen, evpbufcom, sizeof evpbufcom);
+ if (evplen == 0)
+ return (0);
+ evp = evpbufcom;
+ }
+
+#if 0
+ if (env->sc_queue_flags & QUEUE_ENCRYPT) {
+ evplen = encrypt_buffer(evp, evplen, evpbufenc, sizeof evpbufenc);
+ if (evplen == 0)
+ return (0);
+ evp = evpbufenc;
+ }
+#endif
+
+ memmove(evpbuf, evp, evplen);
+
+ return (evplen);
}
static int
queue_envelope_load_buffer(struct envelope *ep, char *evpbuf, size_t evpbufsize)
{
- return (envelope_load_buffer(ep, evpbuf, evpbufsize));
-}
+ char evpbufcom[sizeof(struct envelope)];
+ char evpbufenc[sizeof(struct envelope)];
+ char *evp;
+ size_t evplen;
+
+ evp = evpbuf;
+ evplen = evpbufsize;
+
+#if 0
+ if (env->sc_queue_flags & QUEUE_ENCRYPT) {
+ evplen = decrypt_buffer(evp, evplen, evpbufenc, sizeof evpbufenc);
+ if (evplen == 0)
+ return (0);
+ evp = evpbufenc;
+ }
+#endif
+
+ if (env->sc_queue_flags & QUEUE_COMPRESS) {
+ evplen = uncompress_buffer(evp, evplen, evpbufcom, sizeof evpbufcom);
+ if (evplen == 0)
+ return (0);
+ evp = evpbufcom;
+ }
+ return (envelope_load_buffer(ep, evp, evplen));
+}
int
queue_envelope_create(struct envelope *ep)
diff --git a/usr.sbin/smtpd/smtpctl/Makefile b/usr.sbin/smtpd/smtpctl/Makefile
index c55c89d1380..3f93e4fed93 100644
--- a/usr.sbin/smtpd/smtpctl/Makefile
+++ b/usr.sbin/smtpd/smtpctl/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.23 2012/08/18 18:18:23 gilles Exp $
+# $OpenBSD: Makefile,v 1.24 2012/08/25 23:35:09 chl Exp $
.PATH: ${.CURDIR}/..
@@ -19,7 +19,8 @@ CFLAGS+= -Wsign-compare -Wbounded
SRCS= enqueue.c parser.c log.c envelope.c
SRCS+= queue_backend.c queue_fsqueue.c
SRCS+= smtpctl.c util.c
+SRCS+= compress_backend.c compress_zlib.c encrypt.c
-LDADD+= -lutil
+LDADD+= -lutil -lz
DPADD+= ${LIBUTIL} ${LIBEVENT}
.include <bsd.prog.mk>
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 6ff6dd273b5..ac2e94d4d9d 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.163 2012/08/25 15:39:11 gilles Exp $ */
+/* $OpenBSD: smtpd.c,v 1.164 2012/08/25 23:35:09 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -575,6 +575,14 @@ main(int argc, char *argv[])
if (env->sc_stat == NULL)
errx(1, "could not find stat backend \"%s\"", backend_stat);
+ if (env->sc_queue_compress_algo) {
+ env->sc_compress =
+ compress_backend_lookup(env->sc_queue_compress_algo);
+ if (env->sc_queue == NULL)
+ errx(1, "could not find queue compress backend \"%s\"",
+ env->sc_queue_compress_algo);
+ }
+
log_init(debug);
log_verbose(verbose);
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index c4495238e04..0a984b122a8 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.337 2012/08/25 22:03:26 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.338 2012/08/25 23:35:09 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -580,6 +580,12 @@ struct smtpd {
#define SMTPD_BOUNCE_BUSY 0x00000080
#define SMTPD_SMTP_DISABLED 0x00000100
uint32_t sc_flags;
+ uint32_t sc_queue_flags;
+#define QUEUE_COMPRESS 0x00000001
+#define QUEUE_ENCRYPT 0x00000002
+ char *sc_queue_compress_algo;
+ char *sc_queue_encrypt_cipher;
+ char *sc_queue_encrypt_key;
struct timeval sc_qintval;
int sc_qexpire;
struct event sc_ev;
@@ -592,6 +598,7 @@ struct smtpd {
struct passwd *sc_pw;
char sc_hostname[MAXHOSTNAMELEN];
struct queue_backend *sc_queue;
+ struct compress_backend *sc_compress;
struct scheduler_backend *sc_scheduler;
struct stat_backend *sc_stat;
@@ -808,6 +815,12 @@ struct queue_backend {
void (*qwalk_close)(void *);
};
+struct compress_backend {
+ int (*compress_file)(int, int);
+ int (*uncompress_file)(int, int);
+ size_t (*compress_buffer)(const char *, size_t, char *, size_t);
+ size_t (*uncompress_buffer)(const char *, size_t, char *, size_t);
+};
/* auth structures */
enum auth_type {
@@ -1073,6 +1086,19 @@ void *qwalk_new(uint32_t);
int qwalk(void *, uint64_t *);
void qwalk_close(void *);
+/* compress_backend.c */
+struct compress_backend *compress_backend_lookup(const char *);
+int compress_file(int, int);
+int uncompress_file(int, int);
+size_t compress_buffer(const char *, size_t, char *, size_t);
+size_t uncompress_buffer(const char *, size_t, char *, size_t);
+
+/* encrypt.c */
+int encrypt_file(int, int);
+int decrypt_file(int, int);
+size_t encrypt_buffer(const char *, size_t, char *, size_t);
+size_t decrypt_buffer(const char *, size_t, char *, size_t);
+
/* scheduler.c */
pid_t scheduler(void);
@@ -1192,6 +1218,7 @@ void log_imsg(int, int, struct imsg*);
int ckdir(const char *, mode_t, uid_t, gid_t, int);
int rmtree(char *, int);
int mvpurge(char *, char *);
+int mktmpfile(void);
const char *parse_smtp_response(char *, size_t, char **, int *);
int text_to_netaddr(struct netaddr *, char *);
int text_to_relayhost(struct relayhost *, char *);
diff --git a/usr.sbin/smtpd/smtpd/Makefile b/usr.sbin/smtpd/smtpd/Makefile
index 44fcb194fb5..407aabc48f4 100644
--- a/usr.sbin/smtpd/smtpd/Makefile
+++ b/usr.sbin/smtpd/smtpd/Makefile
@@ -1,13 +1,13 @@
-# $OpenBSD: Makefile,v 1.47 2012/08/18 18:18:23 gilles Exp $
+# $OpenBSD: Makefile,v 1.48 2012/08/25 23:35:09 chl Exp $
.PATH: ${.CURDIR}/.. ${.CURDIR}/../../../lib/libc/asr
PROG= smtpd
-SRCS= aliases.c auth.c bounce.c config.c control.c \
- delivery.c dns.c expand.c envelope.c forward.c \
- iobuf.c ioev.c lka.c lka_session.c log.c map.c mda.c \
- mfa.c mfa_session.c mta.c mta_session.c parse.y \
+SRCS= aliases.c auth.c bounce.c compress_backend.c config.c \
+ control.c delivery.c dns.c encrypt.c envelope.c expand.c\
+ forward.c iobuf.c ioev.c lka.c lka_session.c log.c map.c\
+ mda.c mfa.c mfa_session.c mta.c mta_session.c parse.y \
queue.c queue_backend.c ruleset.c \
scheduler.c scheduler_backend.c smtp.c smtp_session.c \
smtpd.c ssl.c ssl_privsep.c stat_backend.c tree.c \
@@ -16,6 +16,7 @@ SRCS= aliases.c auth.c bounce.c config.c control.c \
# backends
SRCS+= auth_bsd.c
SRCS+= auth_pwd.c
+SRCS+= compress_zlib.c
SRCS+= delivery_filename.c
SRCS+= delivery_maildir.c
SRCS+= delivery_mbox.c
@@ -37,7 +38,7 @@ SRCS+= asr.c asr_debug.c asr_utils.c gethostnamadr_async.c \
MAN= smtpd.8 smtpd.conf.5
BINDIR= /usr/sbin
-LDADD+= -levent -lutil -lssl -lcrypto -lm
+LDADD+= -levent -lutil -lssl -lcrypto -lm -lz
DPADD+= ${LIBEVENT} ${LIBUTIL} ${LIBSSL} ${LIBCRYPTO} ${LIBM}
CFLAGS+= -g3 -ggdb -I${.CURDIR}/.. -I${.CURDIR}/../../../lib/libc/asr
CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 0435c4c6f57..3469d75d390 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.72 2012/08/25 22:03:26 gilles Exp $ */
+/* $OpenBSD: util.c,v 1.73 2012/08/25 23:35:09 chl Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -330,6 +330,28 @@ mvpurge(char *from, char *to)
}
+int
+mktmpfile(void)
+{
+ char path[MAXPATHLEN];
+ int fd;
+
+#define PATH_TMP "/tmp"
+
+ if (ckdir(PATH_TMP, 0700, env->sc_pw->pw_uid, 0, 0) == 0)
+ errx(1, "error in /tmp directory setup");
+
+ if (! bsnprintf(path, sizeof(path), "%s/zlib.XXXXXXXXXX", PATH_TMP))
+ err(1, "snprintf");
+
+ if ((fd = mkstemp(path)) == -1)
+ err(1, "cannot create temporary file %s", path);
+
+ unlink(path);
+ return (fd);
+}
+
+
/* Close file, signifying temporary error condition (if any) to the caller. */
int
safe_fclose(FILE *fp)