From 5150e0d85fd36298bf6095a7dc1b8df8fd25de92 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Mon, 16 Apr 2007 20:04:19 +0000 Subject: Fix Milter packet length calculation & redo Berkeley DB locking git-svn-id: file:///svnroot/mailfromd/trunk@1355 7a8a7f39-df28-0410-adc6-e0d955640f24 --- src/main.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index c1492408..d9be5103 100644 --- a/src/main.c +++ b/src/main.c @@ -67,6 +67,7 @@ int single_process_option; /* Run in single process mode. */ unsigned long source_address = INADDR_ANY; /* Source address for TCP connections */ char *syslog_tag; /* Tag to mark syslog entries with. */ +char *mailfromd_state_dir; char *pidfile = DEFAULT_PIDFILE; char *user = DEFAULT_USER; /* Switch to this user privileges after startup */ @@ -742,8 +743,7 @@ option_pidfile(char *opt, void **pval, char *newval) mu_error("Invalid pidfile name: must be absolute"); return 1; } - *pval = newval; - return 0; + return option_string(opt, pval, newval); } static int @@ -805,6 +805,35 @@ option_group(char *opt, void **pval, char *newval) return 0; } +void +set_state_directory(void *value) +{ + /* nothing */ +} + +int +option_state_directory(char *opt, void **pval, char *newval) +{ + struct stat st; + if (stat(newval, &st)) { + mu_error("cannot stat file `%s': %s", + newval, + mu_strerror(errno)); + return 1; + } + if (!S_ISDIR(st.st_mode)) { + mu_error("`%s' is not a directory", newval); + return 1; + } + if (newval[0] != '/') { + mu_error("state directory `%s' is not an absolute file name", + newval); + return 1; + } + mailfromd_state_dir = xstrdup(newval); + return 0; +} + struct option_cache { char *name; void *value; @@ -837,6 +866,7 @@ struct option_cache { { "source", NULL, option_source, set_source }, { "lock-retry-count", NULL, option_number, set_lock_retry_count }, { "lock-retry-timeout", NULL, option_time, set_lock_retry_timeout }, + { "state-directory", NULL, option_state_directory, set_state_directory }, { NULL } }; @@ -1551,12 +1581,43 @@ get_db_name() void db_format_setup() { + mailfromd_state_dir = xstrdup(DEFAULT_STATE_DIR); dns_cache_format = db_format_install(dns_cache_format); cache_format = db_format_install(cache_format); rate_format = db_format_install(rate_format); greylist_format = db_format_install(greylist_format); } +static int +db_fixup_name_enumerator(void *sym, void *data) +{ + struct db_format *fmt = sym; + static size_t slen; + + if (slen == 0) + slen = strlen(mailfromd_state_dir); + + if (fmt->dbname[0] != '/') { + size_t olen = strlen(fmt->dbname); + size_t flen = slen + 1 + olen + 1; + char *p = xrealloc(fmt->dbname, flen); + memmove(p + slen + 1, p, olen + 1); + memcpy(p, mailfromd_state_dir, slen); + p[slen] = '/'; + fmt->dbname = p; + } + return 0; +} + +static void +db_fixup_names() +{ + size_t slen = strlen(mailfromd_state_dir); + if (mailfromd_state_dir[slen-1] == '/') + mailfromd_state_dir[slen-1] = 0; + db_format_enumerate(db_fixup_name_enumerator, NULL); +} + void mailfromd_delete(int argc, char **argv) { @@ -1724,7 +1785,8 @@ main(int argc, char **argv) exit(EX_CONFIG); } process_options(); - + db_fixup_names(); + /* Process some special options */ if (expire_interval) cache_format->expire_interval = negative_expire_interval = -- cgit v1.2.1