diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-10-14 11:58:24 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-10-14 11:58:24 +0000 |
commit | 9c4a800e568b41a715338f7828b289638231c1d3 (patch) | |
tree | 569f6977d85151c57cd0dfc2da7a5eda8f4f70b4 /usr.sbin/smtpd | |
parent | 48f944375b479b7ec9d8d8ac55afc4889d18f95f (diff) |
introduce map_file.c which will deprecate map_stdio.c
The idea is to have a file-backed map but to have smtpd(8) cache the maps
so that it cannot be partially read if edited while mail is received. The
file is read and converted to a static map (map_static.c), changes aren't
visible to smtpd until an explicit: smtpctl update map which reads file,
builds a new static map and invalidates the former.
partial-read issue discussed with beck@ and halex@
idea to convert internally to a static map by eric@
diff ok eric@ and chl@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/control.c | 18 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka.c | 27 | ||||
-rw-r--r-- | usr.sbin/smtpd/makemap/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/map.c | 84 | ||||
-rw-r--r-- | usr.sbin/smtpd/map_db.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/map_file.c | 178 | ||||
-rw-r--r-- | usr.sbin/smtpd/map_static.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/parse.y | 13 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.c | 23 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.h | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.8 | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 13 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 17 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd/Makefile | 4 |
15 files changed, 362 insertions, 38 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index de3392ba425..4171bea4949 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.75 2012/09/28 12:00:09 eric Exp $ */ +/* $OpenBSD: control.c,v 1.76 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org> @@ -336,7 +336,7 @@ control_dispatch_ext(int fd, short event, void *arg) struct stat_kv *kvp; char *key; struct stat_value val; - + size_t len; if (getpeereid(fd, &euid, &egid) == -1) fatal("getpeereid"); @@ -549,6 +549,19 @@ control_dispatch_ext(int fd, short event, void *arg) NULL, 0); break; + case IMSG_LKA_UPDATE_MAP: + if (euid) + goto badcred; + + /* map name too long */ + len = strlen(imsg.data); + if (len >= MAX_LINE_SIZE) + goto invalid; + + imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_LKA_UPDATE_MAP, + 0, 0, -1, imsg.data, len + 1); + break; + default: log_debug("control_dispatch_ext: " "error handling %s imsg", @@ -559,6 +572,7 @@ control_dispatch_ext(int fd, short event, void *arg) continue; badcred: +invalid: imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); } diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 247619daaf4..0b260b8ef20 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.144 2012/10/13 08:01:47 eric Exp $ */ +/* $OpenBSD: lka.c,v 1.145 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -57,6 +57,7 @@ lka_imsg(struct imsgev *iev, struct imsg *imsg) struct mapel *mapel; struct rule *rule; struct map *map; + struct map *mp; void *tmp; if (imsg->hdr.type == IMSG_DNS_HOST || imsg->hdr.type == IMSG_DNS_MX || @@ -152,6 +153,16 @@ lka_imsg(struct imsgev *iev, struct imsg *imsg) map = xmemdup(imsg->data, sizeof *map, "lka:map"); TAILQ_INIT(&map->m_contents); TAILQ_INSERT_TAIL(env->sc_maps_reload, map, m_entry); + + tmp = env->sc_maps; + env->sc_maps = env->sc_maps_reload; + + mp = map_open(map); + if (mp == NULL) + errx(1, "lka: could not open map \"%s\"", map->m_name); + map_close(map, mp); + + env->sc_maps = tmp; return; case IMSG_CONF_RULE_SOURCE: @@ -195,6 +206,20 @@ lka_imsg(struct imsgev *iev, struct imsg *imsg) } } + if (iev->proc == PROC_CONTROL) { + switch (imsg->hdr.type) { + case IMSG_LKA_UPDATE_MAP: + map = map_findbyname(imsg->data); + if (map == NULL) { + log_warnx("lka: no such map \"%s\"", + (char *)imsg->data); + return; + } + map_update(map); + return; + } + } + errx(1, "lka_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type)); } diff --git a/usr.sbin/smtpd/makemap/Makefile b/usr.sbin/smtpd/makemap/Makefile index 9bbdefa84f8..5fe4e87efde 100644 --- a/usr.sbin/smtpd/makemap/Makefile +++ b/usr.sbin/smtpd/makemap/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2012/10/07 15:46:38 chl Exp $ +# $OpenBSD: Makefile,v 1.16 2012/10/14 11:58:23 gilles Exp $ .PATH: ${.CURDIR}/.. @@ -18,7 +18,7 @@ CFLAGS+= -Wsign-compare -Wbounded CFLAGS+= -DNO_IO SRCS= parse.y makemap.c aliases.c expand.c log.c util.c map.c \ - map_static.c map_db.c map_stdio.c + map_static.c map_db.c map_file.c tree.c DPADD+= ${LIBUTIL} ${LIBCRYPTO} LDADD+= -lutil -lcrypto diff --git a/usr.sbin/smtpd/map.c b/usr.sbin/smtpd/map.c index 71e082c2225..5eb39173e16 100644 --- a/usr.sbin/smtpd/map.c +++ b/usr.sbin/smtpd/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.33 2012/10/13 08:01:47 eric Exp $ */ +/* $OpenBSD: map.c,v 1.34 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -38,8 +38,7 @@ struct map_backend *map_backend_lookup(enum map_src); extern struct map_backend map_backend_static; extern struct map_backend map_backend_db; -extern struct map_backend map_backend_stdio; -/* extern struct map_backend map_backend_ldap; */ +extern struct map_backend map_backend_file; static objid_t last_map_id = 0; @@ -53,12 +52,9 @@ map_backend_lookup(enum map_src source) case S_DB: return &map_backend_db; - case S_PLAIN: - return &map_backend_stdio; -/* - case S_LDAP: - return &map_backend_ldap; -*/ + case S_FILE: + return &map_backend_file; + default: fatalx("invalid map type"); } @@ -150,7 +146,7 @@ map_compare(objid_t mapid, const char *key, enum map_kind kind, return ret; } -struct map* +struct map * map_create(enum map_src src, const char *name) { struct map *m; @@ -181,6 +177,23 @@ map_create(enum map_src src, const char *name) } void +map_destroy(struct map *m) +{ + struct mapel *me; + + if (m->m_src != S_NONE) + errx(1, "map_add: cannot delete all from map"); + + while ((me = TAILQ_FIRST(&m->m_contents))) { + TAILQ_REMOVE(&m->m_contents, me, me_entry); + free(me); + } + + TAILQ_REMOVE(env->sc_maps, m, m_entry); + free(m); +} + +void map_add(struct map *m, const char *key, const char * val) { struct mapel *me; @@ -195,11 +208,58 @@ map_add(struct map *m, const char *key, const char * val) errx(1, "map_add: key too long"); if (val) { - n = strlcpy(me->me_val.med_string, key, + n = strlcpy(me->me_val.med_string, val, sizeof(me->me_val.med_string)); if (n >= sizeof(me->me_val.med_string)) errx(1, "map_add: value too long"); } - + TAILQ_INSERT_TAIL(&m->m_contents, me, me_entry); } + +void +map_delete(struct map *m, const char *key) +{ + struct mapel *me; + + if (m->m_src != S_NONE) + errx(1, "map_add: cannot delete from map"); + + TAILQ_FOREACH(me, &m->m_contents, me_entry) { + if (strcmp(me->me_key.med_string, key) == 0) + break; + } + if (me == NULL) + return; + TAILQ_REMOVE(&m->m_contents, me, me_entry); + free(me); +} + +void * +map_open(struct map *m) +{ + struct map_backend *backend = NULL; + + backend = map_backend_lookup(m->m_src); + return backend->open(m); +} + +void +map_close(struct map *m, void *hdl) +{ + struct map_backend *backend = NULL; + + backend = map_backend_lookup(m->m_src); + backend->close(hdl); +} + + +void +map_update(struct map *m) +{ + struct map_backend *backend = NULL; + + backend = map_backend_lookup(m->m_src); + if (backend->update) + backend->update(m); +} diff --git a/usr.sbin/smtpd/map_db.c b/usr.sbin/smtpd/map_db.c index 43a2dd573d9..4e33ac6c149 100644 --- a/usr.sbin/smtpd/map_db.c +++ b/usr.sbin/smtpd/map_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map_db.c,v 1.10 2012/09/27 17:58:56 chl Exp $ */ +/* $OpenBSD: map_db.c,v 1.11 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -52,6 +52,7 @@ static void *map_db_netaddr(const char *, char *, size_t); struct map_backend map_backend_db = { map_db_open, + NULL, map_db_close, map_db_lookup, map_db_compare diff --git a/usr.sbin/smtpd/map_file.c b/usr.sbin/smtpd/map_file.c new file mode 100644 index 00000000000..8d9e612fcad --- /dev/null +++ b/usr.sbin/smtpd/map_file.c @@ -0,0 +1,178 @@ +/* $OpenBSD: map_file.c,v 1.1 2012/10/14 11:58:23 gilles Exp $ */ + +/* + * Copyright (c) 2012 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 <sys/stat.h> + +#include <ctype.h> +#include <err.h> +#include <errno.h> +#include <event.h> +#include <fcntl.h> +#include <imsg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "smtpd.h" +#include "log.h" + +/* file backend */ +static void *map_file_open(struct map *); +static void map_file_update(struct map *); +static void *map_file_lookup(void *, const char *, enum map_kind); +static int map_file_compare(void *, const char *, enum map_kind, + int (*)(const char *, const char *)); +static void map_file_close(void *); + +struct map_backend *map_backend_lookup(enum map_src); + +struct map_backend map_backend_file = { + map_file_open, + map_file_update, + map_file_close, + map_file_lookup, + map_file_compare +}; + +static void +file_load(struct map *m, FILE *fp) +{ + char *buf, *lbuf; + size_t flen; + char *keyp; + char *valp; + + lbuf = NULL; + while ((buf = fgetln(fp, &flen))) { + if (buf[flen - 1] == '\n') + buf[flen - 1] = '\0'; + else { + lbuf = xmalloc(flen + 1, "map_stdio_get_entry"); + 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) { + while (*valp && isspace(*valp)) + ++valp; + if (*valp == '\0') + valp = NULL; + } + map_add(m, keyp, valp == keyp ? NULL : valp); + } + free(lbuf); +} + + +static void * +map_file_open(struct map *map) +{ + FILE *fp = NULL; + struct map *mp = NULL; + + if (map->m_handle) + return map->m_handle; + + mp = map_create(S_NONE, NULL); + + fp = fopen(map->m_config, "r"); + if (fp == NULL) + goto err; + file_load(mp, fp); + fclose(fp); + + map->m_handle = mp; + + log_info("map_file_open: initialized map \"%s\" from %s", + map->m_name, map->m_config); + + return mp; + +err: + if (mp) + map_destroy(mp); + + if (fp) + fclose(fp); + + return NULL; +} + +static void +map_file_update(struct map *map) +{ + FILE *fp = NULL; + struct map *mp = NULL; + + fp = fopen(map->m_config, "r"); + if (fp == NULL) { + log_info("map_file_update: could not update map \"%s\" from %s: %s", + map->m_name, map->m_config, strerror(errno)); + return; + } + + mp = map_create(S_NONE, NULL); + file_load(mp, fp); + fclose(fp); + + if (map->m_handle != NULL) { + map_destroy(map->m_handle); + map->m_handle = NULL; + } + + map->m_handle = mp; + log_info("map_file_update: updated map \"%s\" from %s", + map->m_name, map->m_config); +} + +static void +map_file_close(void *hdl) +{ + /* ignore */ +} + +static void * +map_file_lookup(void *hdl, const char *key, enum map_kind kind) +{ + struct map *mp = hdl; + + return map_lookup(mp->m_id, key, kind); +} + +static int +map_file_compare(void *hdl, const char *key, enum map_kind kind, + int (*func)(const char *, const char *)) +{ + struct map *mp = hdl; + + return map_compare(mp->m_id, key, kind, func); +} diff --git a/usr.sbin/smtpd/map_static.c b/usr.sbin/smtpd/map_static.c index 8aac67119ab..c66da1025b1 100644 --- a/usr.sbin/smtpd/map_static.c +++ b/usr.sbin/smtpd/map_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map_static.c,v 1.7 2012/09/27 17:47:49 chl Exp $ */ +/* $OpenBSD: map_static.c,v 1.8 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org> @@ -49,6 +49,7 @@ static void *map_static_netaddr(const char *, char *, size_t); struct map_backend map_backend_static = { map_static_open, + NULL, map_static_close, map_static_lookup, map_static_compare diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index c71f3f392e0..8f8a194b233 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.108 2012/10/11 21:14:32 gilles Exp $ */ +/* $OpenBSD: parse.y,v 1.109 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -121,7 +121,7 @@ typedef struct { %token AS QUEUE COMPRESSION CIPHER INTERVAL SIZE LISTEN ON ANY PORT EXPIRE %token MAP HASH LIST SINGLE SSL SMTPS CERTIFICATE ENCRYPTION -%token DB LDAP PLAIN DOMAIN SOURCE +%token DB LDAP FILE DOMAIN SOURCE %token RELAY BACKUP VIA DELIVER TO MAILDIR MBOX HOSTNAME %token ACCEPT REJECT INCLUDE ERROR MDA FROM FOR %token ARROW AUTH TLS LOCAL VIRTUAL TAG ALIAS FILTER KEY DIGEST @@ -440,14 +440,14 @@ main : QUEUE INTERVAL interval { */ ; -mapsource : SOURCE PLAIN STRING { - map->m_src = S_PLAIN; +mapsource : SOURCE FILE STRING { + map->m_src = S_FILE; if (strlcpy(map->m_config, $3, sizeof(map->m_config)) >= sizeof(map->m_config)) err(1, "pathname too long"); } | STRING { - map->m_src = S_PLAIN; + map->m_src = S_FILE; if (strlcpy(map->m_config, $1, sizeof(map->m_config)) >= sizeof(map->m_config)) err(1, "pathname too long"); @@ -951,6 +951,7 @@ lookup(char *s) { "domain", DOMAIN }, { "encryption", ENCRYPTION }, { "expire", EXPIRE }, + { "file", FILE }, { "filter", FILTER }, { "for", FOR }, { "from", FROM }, @@ -968,7 +969,7 @@ lookup(char *s) { "mbox", MBOX }, { "mda", MDA }, { "on", ON }, - { "plain", PLAIN }, + { "plain", FILE }, { "port", PORT }, { "queue", QUEUE }, { "reject", REJECT }, diff --git a/usr.sbin/smtpd/parser.c b/usr.sbin/smtpd/parser.c index 6c61abfdd20..c93386de32f 100644 --- a/usr.sbin/smtpd/parser.c +++ b/usr.sbin/smtpd/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.28 2012/10/10 19:39:11 gilles Exp $ */ +/* $OpenBSD: parser.c,v 1.29 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -47,15 +47,17 @@ struct token { const struct token *next; }; +static const struct token t_log[]; static const struct token t_main[]; -static const struct token t_schedule_id[]; -static const struct token t_show[]; static const struct token t_pause[]; static const struct token t_remove[]; static const struct token t_resume[]; -static const struct token t_log[]; +static const struct token t_schedule_id[]; +static const struct token t_show[]; static const struct token t_show_envelope[]; static const struct token t_show_message[]; +static const struct token t_update[]; +static const struct token t_update_map[]; static const struct token t_main[] = { {KEYWORD, "schedule-id", NONE, t_schedule_id}, @@ -67,6 +69,7 @@ static const struct token t_main[] = { {KEYWORD, "resume", NONE, t_resume}, {KEYWORD, "stop", SHUTDOWN, NULL}, {KEYWORD, "log", NONE, t_log}, + {KEYWORD, "update", NONE, t_update}, {ENDTOKEN, "", NONE, NULL} }; @@ -118,6 +121,18 @@ static const struct token t_log[] = { {ENDTOKEN, "", NONE, NULL} }; +static const struct token t_update[] = { + {KEYWORD, "map", NONE, t_update_map}, + {ENDTOKEN, "", NONE, NULL} +}; + +static const struct token t_update_map[] = { + {VARIABLE, "name", UPDATE_MAP, NULL}, + {ENDTOKEN, "", NONE, NULL} +}; + + + static const struct token *match_token(const char *, const struct token [], struct parse_result *); static void show_valid_args(const struct token []); diff --git a/usr.sbin/smtpd/parser.h b/usr.sbin/smtpd/parser.h index c6fb452a8dc..01227026b5d 100644 --- a/usr.sbin/smtpd/parser.h +++ b/usr.sbin/smtpd/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.22 2012/10/10 19:39:11 gilles Exp $ */ +/* $OpenBSD: parser.h,v 1.23 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -36,6 +36,7 @@ enum actions { RESUME_MDA, RESUME_MTA, RESUME_SMTP, + UPDATE_MAP, }; struct parse_result { diff --git a/usr.sbin/smtpd/smtpctl.8 b/usr.sbin/smtpd/smtpctl.8 index ee253e1d1e1..2bfafb9479e 100644 --- a/usr.sbin/smtpd/smtpctl.8 +++ b/usr.sbin/smtpd/smtpctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpctl.8,v 1.29 2012/10/14 11:47:09 gilles Exp $ +.\" $OpenBSD: smtpctl.8,v 1.30 2012/10/14 11:58:23 gilles Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> .\" @@ -69,7 +69,10 @@ Displays information concerning envelopes that are currently in a queue. .It Cm show stats Displays runtime statistics concerning -.Xr smtpd 8 . +.It Cm update map Ar name +For map backends that provide caching, causes +.Xr smtpd 8 +to update the cache. .El .Pp When diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index 4cca0dc058c..56c0ccb9146 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.92 2012/10/10 19:39:11 gilles Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.93 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -217,6 +217,16 @@ connected: case SHOW_STATS: imsg_compose(ibuf, IMSG_STATS, 0, 0, -1, NULL, 0); break; + case UPDATE_MAP: { + char name[MAX_LINE_SIZE]; + + if (strlcpy(name, res->data, sizeof name) >= sizeof name) + errx(1, "map name too long."); + imsg_compose(ibuf, IMSG_LKA_UPDATE_MAP, 0, 0, -1, + name, strlen(name) + 1); + done = 1; + break; + } case MONITOR: /* XXX */ break; @@ -269,6 +279,7 @@ connected: break; case NONE: break; + case UPDATE_MAP: case MONITOR: break; default: diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 4d312e90f15..ae52a333efa 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.175 2012/10/11 21:55:16 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.176 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1260,6 +1260,7 @@ imsg_to_str(int type) CASE(IMSG_CONF_FILTER); CASE(IMSG_CONF_END); + CASE(IMSG_LKA_UPDATE_MAP); CASE(IMSG_LKA_MAIL); CASE(IMSG_LKA_RCPT); CASE(IMSG_LKA_SECRET); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 0d13040caed..5e21f593d12 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.388 2012/10/12 08:51:02 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.389 2012/10/14 11:58:23 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -126,10 +126,14 @@ enum imsg_type { IMSG_CONF_RULE_SOURCE, IMSG_CONF_FILTER, IMSG_CONF_END, + + IMSG_LKA_UPDATE_MAP, + IMSG_LKA_MAIL, IMSG_LKA_RCPT, IMSG_LKA_SECRET, IMSG_LKA_RULEMATCH, + IMSG_MDA_SESS_NEW, IMSG_MDA_DONE, @@ -230,7 +234,7 @@ struct peer { enum map_src { S_NONE, - S_PLAIN, + S_FILE, S_DB /*, S_LDAP*/ }; @@ -265,11 +269,13 @@ struct map { enum map_src m_src; char m_config[MAXPATHLEN]; TAILQ_HEAD(mapel_list, mapel) m_contents; + void *m_handle; }; struct map_backend { void *(*open)(struct map *); + void (*update)(struct map *); void (*close)(void *); void *(*lookup)(void *, const char *, enum map_kind); int (*compare)(void *, const char *, enum map_kind, @@ -972,13 +978,20 @@ void lka_session(struct submit_status *); void lka_session_forward_reply(struct forward_req *, int); /* map.c */ +void *map_open(struct map *); +void map_update(struct map *); +void map_close(struct map *, void *); + void *map_lookup(objid_t, const char *, enum map_kind); int map_compare(objid_t, const char *, enum map_kind, int (*)(const char *, const char *)); struct map *map_find(objid_t); struct map *map_findbyname(const char *); struct map *map_create(enum map_src, const char *); +void map_destroy(struct map *); void map_add(struct map *, const char *, const char *); +void map_delete(struct map *, const char *); +void map_delete_all(struct map *); /* mda.c */ diff --git a/usr.sbin/smtpd/smtpd/Makefile b/usr.sbin/smtpd/smtpd/Makefile index f504da11bf3..305d6fce77a 100644 --- a/usr.sbin/smtpd/smtpd/Makefile +++ b/usr.sbin/smtpd/smtpd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.56 2012/09/17 06:27:34 jmc Exp $ +# $OpenBSD: Makefile,v 1.57 2012/10/14 11:58:23 gilles Exp $ .PATH: ${.CURDIR}/.. ${.CURDIR}/../../../lib/libc/asr @@ -22,8 +22,8 @@ SRCS+= delivery_maildir.c SRCS+= delivery_mbox.c SRCS+= delivery_mda.c SRCS+= map_db.c +SRCS+= map_file.c SRCS+= map_static.c -SRCS+= map_stdio.c SRCS+= queue_fsqueue.c SRCS+= scheduler_ramqueue.c SRCS+= stat_ramstat.c |