7 /* create or rewrite database, generic interface
11 /* MKMAP *mkmap_open(type, path, open_flags, dict_flags)
17 /* void mkmap_append(mkmap, key, value, lineno)
23 /* void mkmap_close(mkmap)
26 /* This module implements support for creating Postfix databases.
27 /* It is a dict(3) wrapper that adds global locking to dict-level
28 /* routines where appropriate.
30 /* mkmap_open() creates or truncates the named database, after
31 /* appending the appropriate suffixes to the specified filename.
32 /* Before the database is updated, it is locked for exclusive
33 /* access, and signal delivery is suspended.
34 /* See dict(3) for a description of \fBopen_flags\fR and \fBdict_flags\fR.
35 /* All errors are fatal.
37 /* mkmap_append() appends the named (key, value) pair to the
38 /* database. Update errors are fatal; duplicate keys are ignored
39 /* (but a warning is issued).
40 /* \fBlineno\fR is used for diagnostics.
42 /* mkmap_close() closes the database, releases any locks,
43 /* and resumes signal delivery. All errors are fatal.
45 /* sigdelay(3) suspend/resume signal delivery
49 /* The Secure Mailer license must be distributed with this software.
52 /* IBM T.J. Watson Research
54 /* Yorktown Heights, NY 10598, USA
63 /* Utility library. */
70 #include <dict_sdbm.h>
71 #include <dict_proxy.h>
80 * Information about available database types. Here, we list only those map
81 * types that support "create" operations.
83 * We use a different table (in dict_open.c) when querying maps.
87 MKMAP
*(*before_open
) (const char *);
90 static const MKMAP_OPEN_INFO mkmap_types
[] = {
91 DICT_TYPE_PROXY
, mkmap_proxy_open
,
93 DICT_TYPE_CDB
, mkmap_cdb_open
,
96 DICT_TYPE_SDBM
, mkmap_sdbm_open
,
99 DICT_TYPE_DBM
, mkmap_dbm_open
,
102 DICT_TYPE_HASH
, mkmap_hash_open
,
103 DICT_TYPE_BTREE
, mkmap_btree_open
,
108 /* mkmap_append - append entry to map */
112 void mkmap_append(MKMAP
*mkmap
, const char *key
, const char *value
)
114 dict_put(mkmap
->dict
, key
, value
);
117 /* mkmap_close - close database */
119 void mkmap_close(MKMAP
*mkmap
)
123 * Close the database.
125 dict_close(mkmap
->dict
);
128 * Do whatever special processing is needed after closing the database,
129 * such as releasing a global exclusive lock on the database file.
130 * Individual Postfix dict modules implement locking only for individual
131 * record operations, because most Postfix applications don't need global
134 if (mkmap
->after_close
)
135 mkmap
->after_close(mkmap
);
138 * Resume signal delivery.
145 myfree((char *) mkmap
);
148 /* mkmap_open - create or truncate database */
150 MKMAP
*mkmap_open(const char *type
, const char *path
,
151 int open_flags
, int dict_flags
)
154 const MKMAP_OPEN_INFO
*mp
;
157 * Find out what map type to use.
159 for (mp
= mkmap_types
; /* void */ ; mp
++) {
161 msg_fatal("unsupported map type: %s", type
);
162 if (strcmp(type
, mp
->type
) == 0)
166 msg_info("open %s %s", type
, path
);
169 * Do whatever before-open initialization is needed, such as acquiring a
170 * global exclusive lock on an existing database file. Individual Postfix
171 * dict modules implement locking only for individual record operations,
172 * because most Postfix applications don't need global exclusive locks.
174 mkmap
= mp
->before_open(path
);
177 * Delay signal delivery, so that we won't leave the database in an
178 * inconsistent state if we can avoid it.
183 * Truncate the database upon open, and update it. Read-write mode is
184 * needed because the underlying routines read as well as write.
186 mkmap
->dict
= mkmap
->open(path
, open_flags
, dict_flags
);
187 mkmap
->dict
->lock_fd
= -1; /* XXX just in case */
188 mkmap
->dict
->stat_fd
= -1; /* XXX just in case */
189 mkmap
->dict
->flags
|= DICT_FLAG_DUP_WARN
;
192 * Do whatever post-open initialization is needed, such as acquiring a
193 * global exclusive lock on a database file that did not exist.
194 * Individual Postfix dict modules implement locking only for individual
195 * record operations, because most Postfix applications don't need global
198 if (mkmap
->after_open
)
199 mkmap
->after_open(mkmap
);