summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/makemap/Makefile4
-rw-r--r--usr.sbin/smtpd/map.c184
-rw-r--r--usr.sbin/smtpd/map_backend.c191
-rw-r--r--usr.sbin/smtpd/map_parser.c60
-rw-r--r--usr.sbin/smtpd/smtpd.h16
-rw-r--r--usr.sbin/smtpd/smtpd/Makefile9
6 files changed, 274 insertions, 190 deletions
diff --git a/usr.sbin/smtpd/makemap/Makefile b/usr.sbin/smtpd/makemap/Makefile
index 7b68c2fa840..ed147393622 100644
--- a/usr.sbin/smtpd/makemap/Makefile
+++ b/usr.sbin/smtpd/makemap/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.8 2009/11/08 23:15:03 gilles Exp $
+# $OpenBSD: Makefile,v 1.9 2010/04/21 21:04:29 gilles Exp $
.PATH: ${.CURDIR}/..
@@ -16,7 +16,7 @@ CFLAGS+= -Wmissing-declarations
CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
CFLAGS+= -Wsign-compare -Wbounded
-SRCS= parse.y makemap.c aliases.c expand.c map.c log.c util.c
+SRCS= parse.y makemap.c aliases.c expand.c map.c map_backend.c map_parser.c log.c util.c
DPADD+= ${LIBUTIL}
LDADD+= -lutil
.include <bsd.prog.mk>
diff --git a/usr.sbin/smtpd/map.c b/usr.sbin/smtpd/map.c
index 2c1927709e2..63b9c684a4b 100644
--- a/usr.sbin/smtpd/map.c
+++ b/usr.sbin/smtpd/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.13 2010/04/21 20:10:24 gilles Exp $ */
+/* $OpenBSD: map.c,v 1.14 2010/04/21 21:04:29 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -37,42 +37,6 @@
struct map_backend *map_backend_lookup(enum map_src);
struct map_parser *map_parser_lookup(enum map_kind);
-/* db(3) backend */
-void *map_db_open(char *);
-void map_db_close(void *);
-char *map_db_get(void *, char *, size_t *);
-int map_db_put(void *, char *, char *);
-
-/* stdio(3) backend */
-void *map_stdio_open(char *);
-void map_stdio_close(void *);
-char *map_stdio_get(void *, char *, size_t *);
-int map_stdio_put(void *, char *, char *);
-
-
-struct map_backend {
- enum map_src source;
- void *(*open)(char *);
- void (*close)(void *);
- char *(*get)(void *, char *, size_t *);
- int (*put)(void *, char *, char *);
-} map_backends[] = {
- { S_DB,
- map_db_open, map_db_close, map_db_get, map_db_put },
- { S_FILE,
- map_stdio_open, map_stdio_close, map_stdio_get, map_stdio_put },
-};
-
-struct map_parser {
- enum map_kind kind;
- void *(*extract)(char *, size_t len);
-} map_parsers[] = {
- { K_NONE, NULL },
- { K_ALIASES, NULL },
- { K_VIRTUAL, NULL },
- { K_SECRETS, NULL }
-};
-
struct map *
map_findbyname(struct smtpd *env, const char *name)
{
@@ -134,149 +98,3 @@ end:
backend->close(hdl);
return ret;
}
-
-struct map_backend *
-map_backend_lookup(enum map_src source)
-{
- u_int8_t i;
-
- for (i = 0; i < nitems(map_backends); ++i)
- if (map_backends[i].source == source)
- break;
-
- if (i == nitems(map_backends))
- fatalx("invalid map type");
-
- return &map_backends[i];
-}
-
-struct map_parser *
-map_parser_lookup(enum map_kind kind)
-{
- u_int8_t i;
-
- for (i = 0; i < nitems(map_parsers); ++i)
- if (map_parsers[i].kind == kind)
- break;
-
- if (i == nitems(map_parsers))
- fatalx("invalid map kind");
-
- return &map_parsers[i];
-}
-
-/* db(3) backend */
-void *
-map_db_open(char *src)
-{
- return dbopen(src, O_RDONLY, 0600, DB_HASH, NULL);
-}
-
-void
-map_db_close(void *hdl)
-{
- DB *db = hdl;
-
- db->close(db);
-}
-
-char *
-map_db_get(void *hdl, char *key, size_t *len)
-{
- int ret;
- DBT dbk;
- DBT dbv;
- DB *db = hdl;
- char *result = NULL;
-
- dbk.data = key;
- dbk.size = strlen(dbk.data) + 1;
-
- if ((ret = db->get(db, &dbk, &dbv, 0)) != 0)
- return NULL;
-
- result = calloc(dbv.size, 1);
- if (result == NULL)
- fatal("calloc");
- (void)strlcpy(result, dbv.data, dbv.size);
-
- *len = dbv.size;
-
- return result;
-}
-
-int
-map_db_put(void *hdl, char *key, char *val)
-{
- return 0;
-}
-
-
-/* stdio(3) backend */
-void *
-map_stdio_open(char *src)
-{
- return fopen(src, "r");
-}
-
-void
-map_stdio_close(void *hdl)
-{
- FILE *fp = hdl;
-
- fclose(fp);
-}
-
-char *
-map_stdio_get(void *hdl, char *key, size_t *len)
-{
- char *buf, *lbuf;
- size_t flen;
- char *keyp;
- char *valp;
- FILE *fp = hdl;
- char *result = NULL;
-
- lbuf = NULL;
- while ((buf = fgetln(fp, &flen))) {
- if (buf[flen - 1] == '\n')
- buf[flen - 1] = '\0';
- else {
- if ((lbuf = malloc(flen + 1)) == NULL)
- err(1, NULL);
- memcpy(lbuf, buf, flen);
- lbuf[flen] = '\0';
- buf = lbuf;
- }
-
- keyp = buf;
- while (isspace((int)*keyp))
- ++keyp;
- if (*keyp == '\0' || *keyp == '#')
- continue;
-
- valp = keyp;
- strsep(&valp, " \t:");
- if (valp == NULL || valp == keyp)
- continue;
-
- if (strcmp(keyp, key) != 0)
- continue;
-
- result = strdup(valp);
- if (result == NULL)
- err(1, NULL);
- *len = strlen(result);
-
- break;
- }
- free(lbuf);
-
- return result;
-}
-
-int
-map_stdio_put(void *hdl, char *key, char *val)
-{
- return 0;
-}
diff --git a/usr.sbin/smtpd/map_backend.c b/usr.sbin/smtpd/map_backend.c
new file mode 100644
index 00000000000..f0122f532c0
--- /dev/null
+++ b/usr.sbin/smtpd/map_backend.c
@@ -0,0 +1,191 @@
+/* $OpenBSD: map_backend.c,v 1.1 2010/04/21 21:04:29 gilles Exp $ */
+
+/*
+ * Copyright (c) 2010 Gilles Chehade <gilles@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 <ctype.h>
+#include <db.h>
+#include <err.h>
+#include <errno.h>
+#include <event.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "smtpd.h"
+
+
+struct map_backend *map_backend_lookup(enum map_src);
+
+/* db(3) backend */
+void *map_db_open(char *);
+void map_db_close(void *);
+char *map_db_get(void *, char *, size_t *);
+int map_db_put(void *, char *, char *);
+
+/* stdio(3) backend */
+void *map_stdio_open(char *);
+void map_stdio_close(void *);
+char *map_stdio_get(void *, char *, size_t *);
+int map_stdio_put(void *, char *, char *);
+
+
+struct map_backend map_backends[] = {
+ { S_DB,
+ map_db_open, map_db_close, map_db_get, map_db_put },
+ { S_FILE,
+ map_stdio_open, map_stdio_close, map_stdio_get, map_stdio_put },
+};
+
+
+struct map_backend *
+map_backend_lookup(enum map_src source)
+{
+ u_int8_t i;
+
+ for (i = 0; i < nitems(map_backends); ++i)
+ if (map_backends[i].source == source)
+ break;
+
+ if (i == nitems(map_backends))
+ fatalx("invalid map type");
+
+ return &map_backends[i];
+}
+
+
+/* db(3) backend */
+void *
+map_db_open(char *src)
+{
+ return dbopen(src, O_RDONLY, 0600, DB_HASH, NULL);
+}
+
+void
+map_db_close(void *hdl)
+{
+ DB *db = hdl;
+
+ db->close(db);
+}
+
+char *
+map_db_get(void *hdl, char *key, size_t *len)
+{
+ int ret;
+ DBT dbk;
+ DBT dbv;
+ DB *db = hdl;
+ char *result = NULL;
+
+ dbk.data = key;
+ dbk.size = strlen(dbk.data) + 1;
+
+ if ((ret = db->get(db, &dbk, &dbv, 0)) != 0)
+ return NULL;
+
+ result = calloc(dbv.size, 1);
+ if (result == NULL)
+ fatal("calloc");
+ (void)strlcpy(result, dbv.data, dbv.size);
+
+ *len = dbv.size;
+
+ return result;
+}
+
+int
+map_db_put(void *hdl, char *key, char *val)
+{
+ return 0;
+}
+
+
+/* stdio(3) backend */
+void *
+map_stdio_open(char *src)
+{
+ return fopen(src, "r");
+}
+
+void
+map_stdio_close(void *hdl)
+{
+ FILE *fp = hdl;
+
+ fclose(fp);
+}
+
+char *
+map_stdio_get(void *hdl, char *key, size_t *len)
+{
+ char *buf, *lbuf;
+ size_t flen;
+ char *keyp;
+ char *valp;
+ FILE *fp = hdl;
+ char *result = NULL;
+
+ lbuf = NULL;
+ while ((buf = fgetln(fp, &flen))) {
+ if (buf[flen - 1] == '\n')
+ buf[flen - 1] = '\0';
+ else {
+ if ((lbuf = malloc(flen + 1)) == NULL)
+ err(1, NULL);
+ memcpy(lbuf, buf, flen);
+ lbuf[flen] = '\0';
+ buf = lbuf;
+ }
+
+ keyp = buf;
+ while (isspace((int)*keyp))
+ ++keyp;
+ if (*keyp == '\0' || *keyp == '#')
+ continue;
+
+ valp = keyp;
+ strsep(&valp, " \t:");
+ if (valp == NULL || valp == keyp)
+ continue;
+
+ if (strcmp(keyp, key) != 0)
+ continue;
+
+ result = strdup(valp);
+ if (result == NULL)
+ err(1, NULL);
+ *len = strlen(result);
+
+ break;
+ }
+ free(lbuf);
+
+ return result;
+}
+
+int
+map_stdio_put(void *hdl, char *key, char *val)
+{
+ return 0;
+}
diff --git a/usr.sbin/smtpd/map_parser.c b/usr.sbin/smtpd/map_parser.c
new file mode 100644
index 00000000000..daa21094bc9
--- /dev/null
+++ b/usr.sbin/smtpd/map_parser.c
@@ -0,0 +1,60 @@
+/* $OpenBSD: map_parser.c,v 1.1 2010/04/21 21:04:29 gilles Exp $ */
+
+/*
+ * Copyright (c) 2010 Gilles Chehade <gilles@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 <ctype.h>
+#include <db.h>
+#include <err.h>
+#include <errno.h>
+#include <event.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "smtpd.h"
+
+struct map_parser *map_parser_lookup(enum map_kind);
+
+
+struct map_parser map_parsers[] = {
+ { K_NONE, NULL },
+ { K_ALIASES, NULL },
+ { K_VIRTUAL, NULL },
+ { K_SECRETS, NULL }
+};
+
+struct map_parser *
+map_parser_lookup(enum map_kind kind)
+{
+ u_int8_t i;
+
+ for (i = 0; i < nitems(map_parsers); ++i)
+ if (map_parsers[i].kind == kind)
+ break;
+
+ if (i == nitems(map_parsers))
+ fatalx("invalid map kind");
+
+ return &map_parsers[i];
+}
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index c4ba75f3846..d49c7234a99 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.177 2010/04/21 19:53:16 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.178 2010/04/21 21:04:29 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -285,6 +285,19 @@ struct map {
TAILQ_HEAD(mapel_list, mapel) m_contents;
};
+struct map_backend {
+ enum map_src source;
+ void *(*open)(char *);
+ void (*close)(void *);
+ char *(*get)(void *, char *, size_t *);
+ int (*put)(void *, char *, char *);
+};
+
+struct map_parser {
+ enum map_kind kind;
+ void *(*extract)(char *, size_t);
+};
+
enum cond_type {
C_ALL,
C_NET,
@@ -821,6 +834,7 @@ struct mta_session {
void *pcb;
};
+
extern void (*imsg_callback)(struct smtpd *, struct imsgev *, struct imsg *);
/* aliases.c */
diff --git a/usr.sbin/smtpd/smtpd/Makefile b/usr.sbin/smtpd/smtpd/Makefile
index 6cf4056bc28..19a271cac55 100644
--- a/usr.sbin/smtpd/smtpd/Makefile
+++ b/usr.sbin/smtpd/smtpd/Makefile
@@ -1,11 +1,12 @@
-# $OpenBSD: Makefile,v 1.14 2009/11/08 23:15:03 gilles Exp $
+# $OpenBSD: Makefile,v 1.15 2010/04/21 21:04:29 gilles Exp $
PROG= smtpd
SRCS= aliases.c authenticate.c bounce.c buffer.c client.c \
config.c control.c dns.c expand.c forward.c imsg.c \
- lka.c log.c map.c mda.c mfa.c mta.c parse.y queue.c \
- queue_shared.c ruleset.c runner.c smtp.c smtp_session.c \
- smtpd.c ssl.c ssl_privsep.c util.c
+ lka.c log.c map.c map_backend.c map_parser.c mda.c \
+ mfa.c mta.c parse.y queue.c queue_shared.c ruleset.c \
+ runner.c smtp.c smtp_session.c smtpd.c ssl.c \
+ ssl_privsep.c util.c
MAN= smtpd.8 smtpd.conf.5
BINDIR= /usr/sbin