diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-04-16 20:04:19 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-04-16 20:04:19 +0000 |
commit | 5150e0d85fd36298bf6095a7dc1b8df8fd25de92 (patch) | |
tree | d520143c8fb8c26b5f8b7e43bbf802562ba2657b /src/main.c | |
parent | 3f7383369605d49c55c0ec6267bfd4a13c64749c (diff) | |
download | mailfromd-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')
-rw-r--r-- | src/main.c | 68 |
1 files changed, 65 insertions, 3 deletions
@@ -67,6 +67,7 @@ int single_process_option; /* Run in single process mode. */ | |||
67 | unsigned long source_address = INADDR_ANY; /* Source address for TCP | 67 | unsigned long source_address = INADDR_ANY; /* Source address for TCP |
68 | connections */ | 68 | connections */ |
69 | char *syslog_tag; /* Tag to mark syslog entries with. */ | 69 | char *syslog_tag; /* Tag to mark syslog entries with. */ |
70 | char *mailfromd_state_dir; | ||
70 | char *pidfile = DEFAULT_PIDFILE; | 71 | char *pidfile = DEFAULT_PIDFILE; |
71 | char *user = DEFAULT_USER; /* Switch to this user privileges after | 72 | char *user = DEFAULT_USER; /* Switch to this user privileges after |
72 | startup */ | 73 | startup */ |
@@ -742,8 +743,7 @@ option_pidfile(char *opt, void **pval, char *newval) | |||
742 | mu_error("Invalid pidfile name: must be absolute"); | 743 | mu_error("Invalid pidfile name: must be absolute"); |
743 | return 1; | 744 | return 1; |
744 | } | 745 | } |
745 | *pval = newval; | 746 | return option_string(opt, pval, newval); |
746 | return 0; | ||
747 | } | 747 | } |
748 | 748 | ||
749 | static int | 749 | static int |
@@ -805,6 +805,35 @@ option_group(char *opt, void **pval, char *newval) | |||
805 | return 0; | 805 | return 0; |
806 | } | 806 | } |
807 | 807 | ||
808 | void | ||
809 | set_state_directory(void *value) | ||
810 | { | ||
811 | /* nothing */ | ||
812 | } | ||
813 | |||
814 | int | ||
815 | option_state_directory(char *opt, void **pval, char *newval) | ||
816 | { | ||
817 | struct stat st; | ||
818 | if (stat(newval, &st)) { | ||
819 | mu_error("cannot stat file `%s': %s", | ||
820 | newval, | ||
821 | mu_strerror(errno)); | ||
822 | return 1; | ||
823 | } | ||
824 | if (!S_ISDIR(st.st_mode)) { | ||
825 | mu_error("`%s' is not a directory", newval); | ||
826 | return 1; | ||
827 | } | ||
828 | if (newval[0] != '/') { | ||
829 | mu_error("state directory `%s' is not an absolute file name", | ||
830 | newval); | ||
831 | return 1; | ||
832 | } | ||
833 | mailfromd_state_dir = xstrdup(newval); | ||
834 | return 0; | ||
835 | } | ||
836 | |||
808 | struct option_cache { | 837 | struct option_cache { |
809 | char *name; | 838 | char *name; |
810 | void *value; | 839 | void *value; |
@@ -837,6 +866,7 @@ struct option_cache { | |||
837 | { "source", NULL, option_source, set_source }, | 866 | { "source", NULL, option_source, set_source }, |
838 | { "lock-retry-count", NULL, option_number, set_lock_retry_count }, | 867 | { "lock-retry-count", NULL, option_number, set_lock_retry_count }, |
839 | { "lock-retry-timeout", NULL, option_time, set_lock_retry_timeout }, | 868 | { "lock-retry-timeout", NULL, option_time, set_lock_retry_timeout }, |
869 | { "state-directory", NULL, option_state_directory, set_state_directory }, | ||
840 | { NULL } | 870 | { NULL } |
841 | }; | 871 | }; |
842 | 872 | ||
@@ -1551,12 +1581,43 @@ get_db_name() | |||
1551 | void | 1581 | void |
1552 | db_format_setup() | 1582 | db_format_setup() |
1553 | { | 1583 | { |
1584 | mailfromd_state_dir = xstrdup(DEFAULT_STATE_DIR); | ||
1554 | dns_cache_format = db_format_install(dns_cache_format); | 1585 | dns_cache_format = db_format_install(dns_cache_format); |
1555 | cache_format = db_format_install(cache_format); | 1586 | cache_format = db_format_install(cache_format); |
1556 | rate_format = db_format_install(rate_format); | 1587 | rate_format = db_format_install(rate_format); |
1557 | greylist_format = db_format_install(greylist_format); | 1588 | greylist_format = db_format_install(greylist_format); |
1558 | } | 1589 | } |
1559 | 1590 | ||
1591 | static int | ||
1592 | db_fixup_name_enumerator(void *sym, void *data) | ||
1593 | { | ||
1594 | struct db_format *fmt = sym; | ||
1595 | static size_t slen; | ||
1596 | |||
1597 | if (slen == 0) | ||
1598 | slen = strlen(mailfromd_state_dir); | ||
1599 | |||
1600 | if (fmt->dbname[0] != '/') { | ||
1601 | size_t olen = strlen(fmt->dbname); | ||
1602 | size_t flen = slen + 1 + olen + 1; | ||
1603 | char *p = xrealloc(fmt->dbname, flen); | ||
1604 | memmove(p + slen + 1, p, olen + 1); | ||
1605 | memcpy(p, mailfromd_state_dir, slen); | ||
1606 | p[slen] = '/'; | ||
1607 | fmt->dbname = p; | ||
1608 | } | ||
1609 | return 0; | ||
1610 | } | ||
1611 | |||
1612 | static void | ||
1613 | db_fixup_names() | ||
1614 | { | ||
1615 | size_t slen = strlen(mailfromd_state_dir); | ||
1616 | if (mailfromd_state_dir[slen-1] == '/') | ||
1617 | mailfromd_state_dir[slen-1] = 0; | ||
1618 | db_format_enumerate(db_fixup_name_enumerator, NULL); | ||
1619 | } | ||
1620 | |||
1560 | void | 1621 | void |
1561 | mailfromd_delete(int argc, char **argv) | 1622 | mailfromd_delete(int argc, char **argv) |
1562 | { | 1623 | { |
@@ -1724,7 +1785,8 @@ main(int argc, char **argv) | |||
1724 | exit(EX_CONFIG); | 1785 | exit(EX_CONFIG); |
1725 | } | 1786 | } |
1726 | process_options(); | 1787 | process_options(); |
1727 | 1788 | db_fixup_names(); | |
1789 | |||
1728 | /* Process some special options */ | 1790 | /* Process some special options */ |
1729 | if (expire_interval) | 1791 | if (expire_interval) |
1730 | cache_format->expire_interval = negative_expire_interval = | 1792 | cache_format->expire_interval = negative_expire_interval = |