From 610b9f8d3dcba0c272a3814b6816e67dcd93dc5b Mon Sep 17 00:00:00 2001 From: Wietse Venema Date: Sat, 11 Dec 2004 00:00:00 -0500 Subject: [PATCH] postfix-2.2-20041211 --- postfix/src/global/Makefile.in | 21 ++++-- postfix/src/global/mail_version.h | 2 +- postfix/src/global/mkmap_open.c | 3 + postfix/src/global/mkmap_sdbm.c | 113 ++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 postfix/src/global/mkmap_sdbm.c diff --git a/postfix/src/global/Makefile.in b/postfix/src/global/Makefile.in index 3d5dd511e..4adf152e8 100644 --- a/postfix/src/global/Makefile.in +++ b/postfix/src/global/Makefile.in @@ -14,7 +14,7 @@ SRCS = abounce.c anvil_clnt.c been_here.c bounce.c bounce_log.c \ mail_open_ok.c mail_params.c mail_pathname.c mail_queue.c \ mail_run.c mail_scan_dir.c mail_stream.c mail_task.c mail_trigger.c \ maps.c mark_corrupt.c match_parent_style.c mbox_conf.c \ - mbox_open.c mime_state.c mkmap_db.c mkmap_cdb.c mkmap_dbm.c mkmap_open.c \ + mbox_open.c mime_state.c mkmap_db.c mkmap_dbm.c mkmap_open.c \ mynetworks.c mypwd.c namadr_list.c off_cvt.c opened.c \ own_inet_addr.c pipe_command.c post_mail.c quote_821_local.c \ quote_822_local.c rec_streamlf.c rec_type.c recipient_list.c \ @@ -23,7 +23,7 @@ SRCS = abounce.c anvil_clnt.c been_here.c bounce.c bounce_log.c \ sys_exits.c timed_ipc.c tok822_find.c tok822_node.c tok822_parse.c \ tok822_resolve.c tok822_rewrite.c tok822_tree.c trace.c verify.c \ verify_clnt.c verp_sender.c virtual8_maps.c xtext.c scache_single.c \ - scache_clnt.c scache_multi.c user_acl.c + scache_clnt.c scache_multi.c user_acl.c mkmap_cdb.c mkmap_sdbm.c OBJS = abounce.o anvil_clnt.o been_here.o bounce.o bounce_log.o \ canon_addr.o cfg_parser.o cleanup_strerror.o cleanup_strflags.o \ clnt_stream.o debug_peer.o debug_process.o defer.o \ @@ -39,7 +39,7 @@ OBJS = abounce.o anvil_clnt.o been_here.o bounce.o bounce_log.o \ mail_open_ok.o mail_params.o mail_pathname.o mail_queue.o \ mail_run.o mail_scan_dir.o mail_stream.o mail_task.o mail_trigger.o \ maps.o mark_corrupt.o match_parent_style.o mbox_conf.o \ - mbox_open.o mime_state.o mkmap_db.o mkmap_cdb.o mkmap_dbm.o mkmap_open.o \ + mbox_open.o mime_state.o mkmap_db.o mkmap_dbm.o mkmap_open.o \ mynetworks.o mypwd.o namadr_list.o off_cvt.o opened.o \ own_inet_addr.o pipe_command.o post_mail.o quote_821_local.o \ quote_822_local.o rec_streamlf.o rec_type.o recipient_list.o \ @@ -48,7 +48,7 @@ OBJS = abounce.o anvil_clnt.o been_here.o bounce.o bounce_log.o \ sys_exits.o timed_ipc.o tok822_find.o tok822_node.o tok822_parse.o \ tok822_resolve.o tok822_rewrite.o tok822_tree.o trace.o verify.o \ verify_clnt.o verp_sender.o virtual8_maps.o xtext.o scache_single.o \ - scache_clnt.o scache_multi.o user_acl.o + scache_clnt.o scache_multi.o user_acl.o mkmap_cdb.o mkmap_sdbm.o HDRS = abounce.h anvil_clnt.h been_here.h bounce.h bounce_log.h \ canon_addr.h cfg_parser.h cleanup_user.h clnt_stream.h config.h \ debug_peer.h debug_process.h defer.h deliver_completed.h \ @@ -1073,6 +1073,19 @@ mkmap_open.o: ../../include/dict_dbm.h mkmap_open.o: ../../include/sigdelay.h mkmap_open.o: ../../include/mymalloc.h mkmap_open.o: mkmap.h +mkmap_sdbm.o: mkmap_sdbm.c +mkmap_sdbm.o: ../../include/sys_defs.h +mkmap_sdbm.o: ../../include/msg.h +mkmap_sdbm.o: ../../include/mymalloc.h +mkmap_sdbm.o: ../../include/stringops.h +mkmap_sdbm.o: ../../include/vstring.h +mkmap_sdbm.o: ../../include/vbuf.h +mkmap_sdbm.o: ../../include/dict.h +mkmap_sdbm.o: ../../include/vstream.h +mkmap_sdbm.o: ../../include/argv.h +mkmap_sdbm.o: ../../include/dict_sdbm.h +mkmap_sdbm.o: ../../include/myflock.h +mkmap_sdbm.o: mkmap.h mynetworks.o: mynetworks.c mynetworks.o: ../../include/sys_defs.h mynetworks.o: ../../include/msg.h diff --git a/postfix/src/global/mail_version.h b/postfix/src/global/mail_version.h index 1c5eac077..2361aaba1 100644 --- a/postfix/src/global/mail_version.h +++ b/postfix/src/global/mail_version.h @@ -20,7 +20,7 @@ * Patches change the patchlevel and the release date. Snapshots change the * release date only. */ -#define MAIL_RELEASE_DATE "20041210" +#define MAIL_RELEASE_DATE "20041211" #define MAIL_VERSION_NUMBER "2.2" #define VAR_MAIL_VERSION "mail_version" diff --git a/postfix/src/global/mkmap_open.c b/postfix/src/global/mkmap_open.c index a972f06b0..92ed0f96c 100644 --- a/postfix/src/global/mkmap_open.c +++ b/postfix/src/global/mkmap_open.c @@ -85,6 +85,9 @@ MKMAP_OPEN_INFO mkmap_types[] = { #ifdef HAS_CDB DICT_TYPE_CDB, mkmap_cdb_open, #endif +#ifdef HAS_SDBM + DICT_TYPE_SDBM, mkmap_sdbm_open, +#endif #ifdef HAS_DBM DICT_TYPE_DBM, mkmap_dbm_open, #endif diff --git a/postfix/src/global/mkmap_sdbm.c b/postfix/src/global/mkmap_sdbm.c new file mode 100644 index 000000000..7e87e4e82 --- /dev/null +++ b/postfix/src/global/mkmap_sdbm.c @@ -0,0 +1,113 @@ +/*++ +/* NAME +/* mkmap_sdbm 3 +/* SUMMARY +/* create or open database, SDBM style +/* SYNOPSIS +/* #include +/* +/* MKMAP *mkmap_sdbm_open(path) +/* const char *path; +/* DESCRIPTION +/* This module implements support for creating SDBM databases. +/* +/* mkmap_sdbm_open() takes a file name, appends the ".dir" and ".pag" +/* suffixes, and creates or opens the named SDBM database. +/* This routine is a SDBM-specific helper for the more general +/* mkmap_open() routine. +/* +/* All errors are fatal. +/* SEE ALSO +/* dict_sdbm(3), SDBM dictionary interface. +/* LICENSE +/* .ad +/* .fi +/* The Secure Mailer license must be distributed with this software. +/* AUTHOR(S) +/* Wietse Venema +/* IBM T.J. Watson Research +/* P.O. Box 704 +/* Yorktown Heights, NY 10598, USA +/*--*/ + +/* System library. */ + +#include +#include + +/* Utility library. */ + +#include +#include +#include +#include +#include +#include + +/* Application-specific. */ + +#include "mkmap.h" + +#ifdef HAS_SDBM + +#include + +typedef struct MKMAP_SDBM { + MKMAP mkmap; /* parent class */ + char *lock_file; /* path name */ + int lock_fd; /* -1 or open locked file */ +} MKMAP_SDBM; + +/* mkmap_sdbm_after_close - clean up after closing database */ + +static void mkmap_sdbm_after_close(MKMAP *mp) +{ + MKMAP_SDBM *mkmap = (MKMAP_SDBM *) mp; + + if (mkmap->lock_fd >= 0 && close(mkmap->lock_fd) < 0) + msg_warn("close %s: %m", mkmap->lock_file); + myfree(mkmap->lock_file); +} + +/* mkmap_sdbm_open - create or open database */ + +MKMAP *mkmap_sdbm_open(const char *path) +{ + MKMAP_SDBM *mkmap = (MKMAP_SDBM *) mymalloc(sizeof(*mkmap)); + char *pag_file; + int pag_fd; + + /* + * Fill in the generic members. + */ + mkmap->lock_file = concatenate(path, ".dir", (char *) 0); + mkmap->mkmap.open = dict_sdbm_open; + mkmap->mkmap.after_open = 0; + mkmap->mkmap.after_close = mkmap_sdbm_after_close; + + /* + * Unfortunately, not all systems support locking on open(), so we open + * the .dir and .pag files before truncating them. Keep one file open for + * locking. + */ + if ((mkmap->lock_fd = open(mkmap->lock_file, O_CREAT | O_RDWR, 0644)) < 0) + msg_fatal("open %s: %m", mkmap->lock_file); + + pag_file = concatenate(path, ".pag", (char *) 0); + if ((pag_fd = open(pag_file, O_CREAT | O_RDWR, 0644)) < 0) + msg_fatal("open %s: %m", pag_file); + if (close(pag_fd)) + msg_warn("close %s: %m", pag_file); + myfree(pag_file); + + /* + * Get an exclusive lock - we're going to change the database so we can't + * have any spectators. + */ + if (myflock(mkmap->lock_fd, INTERNAL_LOCK, MYFLOCK_OP_EXCLUSIVE) < 0) + msg_fatal("lock %s: %m", mkmap->lock_file); + + return (&mkmap->mkmap); +} + +#endif