summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2007-04-16 20:04:19 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-04-16 20:04:19 (GMT)
commit5150e0d85fd36298bf6095a7dc1b8df8fd25de92 (patch) (side-by-side diff)
treed520143c8fb8c26b5f8b7e43bbf802562ba2657b /src/main.c
parent3f7383369605d49c55c0ec6267bfd4a13c64749c (diff)
downloadmailfromd-5150e0d85fd36298bf6095a7dc1b8df8fd25de92.tar.gz
mailfromd-5150e0d85fd36298bf6095a7dc1b8df8fd25de92.tar.bz2
Fix Milter packet length calculation & redo Berkeley DB locking
git-svn-id: file:///svnroot/mailfromd/trunk@1355 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index c149240..d9be510 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 =

Return to:

Send suggestions and report system problems to the System administrator.