92 #ifdef USE_DYNAMIC_MAPS
103 static HTABLE *dymap_info;
104 static int dymap_hooks_done = 0;
109 #define STREQ(x, y) (strcmp((x), (y)) == 0)
113 static DICT_OPEN_FN dymap_dict_lookup(
const char *dict_type)
123 if (saved_dict_open_hook != 0
124 && (dict_open_fn = saved_dict_open_hook(dict_type)) != 0)
125 return (dict_open_fn);
132 if ((dp = (DYMAP_INFO *)
htable_find(dymap_info, dict_type)) == 0)
134 if (
stat(dp->soname, &st) < 0) {
135 msg_warn(
"unsupported dictionary type: %s (%s: %m)",
136 dict_type, dp->soname);
139 if (st.st_uid != 0 || (st.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
140 msg_warn(
"unsupported dictionary type: %s "
141 "(%s: file is owned or writable by non-root users)",
142 dict_type, dp->soname);
145 fn[0].name = dp->dict_name;
153 static MKMAP_OPEN_FN dymap_mkmap_lookup(
const char *dict_type)
163 if (saved_mkmap_open_hook != 0
164 && (mkmap_open_fn = saved_mkmap_open_hook(dict_type)) != 0)
165 return (mkmap_open_fn);
172 if ((dp = (DYMAP_INFO *)
htable_find(dymap_info, dict_type)) == 0)
173 msg_fatal(
"unsupported dictionary type: %s. "
174 "Is the postfix-%s package installed?",
175 dict_type, dict_type);
177 msg_fatal(
"unsupported dictionary type: %s does not support "
178 "bulk-mode creation.", dict_type);
179 if (
stat(dp->soname, &st) < 0)
180 msg_fatal(
"unsupported dictionary type: %s (%s: %m). "
181 "Is the postfix-%s package installed?",
182 dict_type, dp->soname, dict_type);
183 if (st.st_uid != 0 || (st.st_mode & (S_IWGRP | S_IWOTH)) != 0)
184 msg_fatal(
"unsupported dictionary type: %s "
185 "(%s: file is owned or writable by non-root users)",
186 dict_type, dp->soname);
187 fn[0].name = dp->mkmap_name;
195 static void dymap_list(
ARGV *map_names)
202 if (saved_dict_mapnames_hook != 0)
203 saved_dict_mapnames_hook(map_names);
205 for (ht_list = ht =
htable_list(dymap_info); *ht != 0; ht++)
212 static DYMAP_INFO *dymap_entry_alloc(
char **argv)
216 dp = (DYMAP_INFO *)
mymalloc(
sizeof(*dp));
219 dp->mkmap_name = argv[2] ?
mystrdup(argv[2]) : 0;
225 static void dymap_entry_free(
void *ptr)
227 DYMAP_INFO *dp = (DYMAP_INFO *) ptr;
238 static void dymap_read_conf(
const char *path,
const char *path_base)
254 if (st.st_uid != 0 || (st.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
255 msg_warn(
"%s: file is owned or writable by non-root users"
256 " -- skipping this file", path);
262 if (*cp ==
'#' || *cp ==
'\0')
265 if (argv->
argc != 3 && argv->
argc != 4)
266 msg_fatal(
"%s, line %d: Expected \"dict-type .so-name dict"
267 "-function [mkmap-function]\"", path, linenum);
269 msg_fatal(
"%s, line %d: unsupported syntax \"%s\"",
270 path, linenum, argv->
argv[0]);
271 if (argv->
argv[1][0] !=
'/') {
277 msg_warn(
"%s: ignoring duplicate entry for \"%s\"",
278 path, argv->
argv[0]);
281 (
void *) dymap_entry_alloc(argv->
argv + 1));
290 if (dymap_hooks_done == 0) {
291 dymap_hooks_done = 1;
298 }
else if (errno != ENOENT) {
299 msg_fatal(
"%s: file open failed: %m", path);
305 void dymap_init(
const char *conf_path,
const char *plugin_dir)
307 static const char myname[] =
"dymap_init";
310 const char *conf_name;
323 dymap_read_conf(conf_path, plugin_dir);
328 conf_path_d =
concatenate(conf_path,
".d", (
char *) 0);
329 if (access(conf_path_d, R_OK | X_OK) == 0
334 dymap_read_conf(
vstring_str(sub_conf_path), plugin_dir);
338 msg_warn(
"%s: directory read error: %m", conf_path_d);
341 }
else if (errno != ENOENT) {
343 msg_warn(
"%s: directory open failed: %m", conf_path_d);
351 if (dymap_hooks_done != 0 && dymap_info == 0)
352 msg_panic(
"%s: post-condition botch", myname);
void htable_free(HTABLE *table, void(*free_fn)(void *))
HTABLE_INFO * htable_locate(HTABLE *table, const char *key)
char * mystrdup(const char *str)
int vstring_get_nonl(VSTRING *vp, VSTREAM *fp)
ARGV * argv_free(ARGV *argvp)
NORETURN msg_panic(const char *fmt,...)
void argv_replace_one(ARGV *argvp, ssize_t where, const char *arg)
void load_library_symbols(const char *, LIB_FN *, LIB_DP *)
void argv_add(ARGV *argvp,...)
DICT_OPEN_FN(* DICT_OPEN_EXTEND_FN)(const char *)
VSTREAM * vstream_fopen(const char *path, int flags, mode_t mode)
SCAN_DIR * scan_dir_open(const char *path)
HTABLE * htable_create(ssize_t size)
DICT_MAPNAMES_EXTEND_FN dict_mapnames_extend(DICT_MAPNAMES_EXTEND_FN)
HTABLE_INFO ** htable_list(HTABLE *table)
int vstream_fclose(VSTREAM *stream)
SCAN_DIR * scan_dir_close(SCAN_DIR *scan)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
DICT_OPEN_EXTEND_FN dict_open_extend(DICT_OPEN_EXTEND_FN)
void * htable_find(HTABLE *table, const char *key)
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
MKMAP_OPEN_FN(* MKMAP_OPEN_EXTEND_FN)(const char *)
NORETURN msg_fatal(const char *fmt,...)
void(* DICT_MAPNAMES_EXTEND_FN)(ARGV *)
char * concatenate(const char *arg0,...)
ARGV * argv_split(const char *, const char *)
DICT *(* DICT_OPEN_FN)(const char *, int, int)
VSTRING * vstring_free(VSTRING *vp)
#define vstream_fileno(vp)
MKMAP *(* MKMAP_OPEN_FN)(const char *)
MKMAP_OPEN_EXTEND_FN mkmap_open_extend(MKMAP_OPEN_EXTEND_FN)
char * scan_dir_next(SCAN_DIR *scan)
void * mymalloc(ssize_t len)
HTABLE_INFO * htable_enter(HTABLE *table, const char *key, void *value)