From d9dcbbcc7ca937af643b4c29d833ad6fe181863e Mon Sep 17 00:00:00 2001 From: Wietse Venema Date: Sat, 5 Feb 2022 00:00:00 -0500 Subject: [PATCH] postfix-3.7.0 --- postfix/HISTORY | 13 +++ postfix/RELEASE_NOTES | 2 +- postfix/WISHLIST | 6 ++ postfix/html/tlsproxy.8.html | 18 ++-- postfix/man/man8/tlsproxy.8 | 14 ++-- postfix/proto/stop.double-cc | 2 +- postfix/proto/stop.spell-cc | 1 + postfix/src/global/mail_version.h | 4 +- postfix/src/postconf/postconf_lookup.c | 1 - postfix/src/postconf/test2.ref | 2 +- postfix/src/postconf/test28.ref | 2 +- postfix/src/postconf/test29.ref | 16 ++-- postfix/src/postconf/test34.ref | 2 +- postfix/src/postconf/test35.ref | 2 +- postfix/src/postconf/test41.ref | 6 +- postfix/src/postconf/test42.ref | 4 +- postfix/src/postconf/test57.ref | 2 +- postfix/src/postconf/test59.ref | 2 +- postfix/src/postconf/test67.ref | 2 +- postfix/src/tlsproxy/tlsproxy.c | 14 ++-- postfix/src/util/Makefile.in | 15 +++- postfix/src/util/binhash.c | 110 +++++++++++++++++++++++++ postfix/src/util/binhash.h | 7 ++ postfix/src/util/dict_db.c | 2 +- postfix/src/util/hash_fnv.c | 7 +- postfix/src/util/hash_fnv.h | 6 +- postfix/src/util/htable.c | 5 +- postfix/src/util/ldseed.c | 1 + 28 files changed, 212 insertions(+), 56 deletions(-) diff --git a/postfix/HISTORY b/postfix/HISTORY index 55d4d4109..0d900728b 100644 --- a/postfix/HISTORY +++ b/postfix/HISTORY @@ -26267,3 +26267,16 @@ Apologies for any names omitted. Cleanup: factored out the non-cryptographic seeder. Files: ldseed.[hc]. + +20220130 + + Cleanup: added a binhash unit test, and updated the htable + unit test. Files: util/Makefile.in, util/binhash.[hc], + util/htable.c. + + Cleanup: names of hash_fnv(3) build options. File: hash:fnv.c. + +20220202 + + Bitrot: Berkeley DB 18 is like Berkeley DB 6. Yasuhiro + Kimura. File: util/dict_db.c. diff --git a/postfix/RELEASE_NOTES b/postfix/RELEASE_NOTES index a15bf4ed9..05ce65ac2 100644 --- a/postfix/RELEASE_NOTES +++ b/postfix/RELEASE_NOTES @@ -66,7 +66,7 @@ to do $name expansion as it evaluates the parameter value. Major changes - lmdb support ---------------------------- -[Feature 20210605] Overhauled the LMDB client implementation, and +[Feature 20210605] Overhauled the LMDB client's error handling, and added integration tests for future-proofing. There are no visible changes in documented behavior. diff --git a/postfix/WISHLIST b/postfix/WISHLIST index ef4cf78c9..d0a0db45c 100644 --- a/postfix/WISHLIST +++ b/postfix/WISHLIST @@ -6,6 +6,12 @@ Wish list: Disable -DSNAPSHOT and -DNONPROD in makedefs. + Alias htable(3) calls to equivalent binhash(3) calls, + and obsolete the htable(3) module. + + FILTER_README needs some text on multi-instance implementations, + and existing multi-instance references need to be updated. + Fix code that still uses "long" for data_size and data_offset, and that uses "%ld" in sscanf(). diff --git a/postfix/html/tlsproxy.8.html b/postfix/html/tlsproxy.8.html index d0b8b0ea1..c15322bf3 100644 --- a/postfix/html/tlsproxy.8.html +++ b/postfix/html/tlsproxy.8.html @@ -323,14 +323,6 @@ TLSPROXY(8) TLSPROXY(8) tlsproxy_client_scert_verifydepth ($smtp_tls_scert_verifydepth) The verification depth for remote TLS server certificates. - tlsproxy_client_level ($smtp_tls_security_level) - The default TLS security level for the Postfix tlsproxy(8) - client. - - tlsproxy_client_policy ($smtp_tls_policy_maps) - Optional lookup tables with the Postfix tlsproxy(8) client TLS - security policy by next-hop destination. - tlsproxy_client_use_tls ($smtp_use_tls) Opportunistic mode: use TLS when a remote server announces TLS support. @@ -343,6 +335,16 @@ TLSPROXY(8) TLSPROXY(8) usage policy by next-hop destination and by remote TLS server hostname. + Available in Postfix version 3.4-3.6: + + tlsproxy_client_level ($smtp_tls_security_level) + The default TLS security level for the Postfix tlsproxy(8) + client. + + tlsproxy_client_policy ($smtp_tls_policy_maps) + Optional lookup tables with the Postfix tlsproxy(8) client TLS + security policy by next-hop destination. + Available in Postfix version 3.7 and later: tlsproxy_client_security_level ($smtp_tls_security_level) diff --git a/postfix/man/man8/tlsproxy.8 b/postfix/man/man8/tlsproxy.8 index 10b447606..5b6167089 100644 --- a/postfix/man/man8/tlsproxy.8 +++ b/postfix/man/man8/tlsproxy.8 @@ -292,12 +292,6 @@ The name of the parameter that provides the tlsproxy_client_loglevel value. .IP "\fBtlsproxy_client_scert_verifydepth ($smtp_tls_scert_verifydepth)\fR" The verification depth for remote TLS server certificates. -.IP "\fBtlsproxy_client_level ($smtp_tls_security_level)\fR" -The default TLS security level for the Postfix \fBtlsproxy\fR(8) -client. -.IP "\fBtlsproxy_client_policy ($smtp_tls_policy_maps)\fR" -Optional lookup tables with the Postfix \fBtlsproxy\fR(8) client TLS -security policy by next\-hop destination. .IP "\fBtlsproxy_client_use_tls ($smtp_use_tls)\fR" Opportunistic mode: use TLS when a remote server announces TLS support. @@ -308,6 +302,14 @@ Optional lookup tables with the Postfix \fBtlsproxy\fR(8) client TLS usage policy by next\-hop destination and by remote TLS server hostname. .PP +Available in Postfix version 3.4\-3.6: +.IP "\fBtlsproxy_client_level ($smtp_tls_security_level)\fR" +The default TLS security level for the Postfix \fBtlsproxy\fR(8) +client. +.IP "\fBtlsproxy_client_policy ($smtp_tls_policy_maps)\fR" +Optional lookup tables with the Postfix \fBtlsproxy\fR(8) client TLS +security policy by next\-hop destination. +.PP Available in Postfix version 3.7 and later: .IP "\fBtlsproxy_client_security_level ($smtp_tls_security_level)\fR" The default TLS security level for the Postfix \fBtlsproxy\fR(8) diff --git a/postfix/proto/stop.double-cc b/postfix/proto/stop.double-cc index 9a4cc5aec..1e9b3de22 100644 --- a/postfix/proto/stop.double-cc +++ b/postfix/proto/stop.double-cc @@ -327,4 +327,4 @@ more more useful and more consistent Fatal error error opening existing file XXX XXX int compar DNS_RR DNS_RR -NO_64_BITS NO_64_BITS +USE_FNV_32BIT USE_FNV_32BIT diff --git a/postfix/proto/stop.spell-cc b/postfix/proto/stop.spell-cc index 3f49e1421..916629853 100644 --- a/postfix/proto/stop.spell-cc +++ b/postfix/proto/stop.spell-cc @@ -1781,3 +1781,4 @@ ldseed softwareengineering stackexchange stdint +Noll diff --git a/postfix/src/global/mail_version.h b/postfix/src/global/mail_version.h index 591be9b6c..d882ae875 100644 --- a/postfix/src/global/mail_version.h +++ b/postfix/src/global/mail_version.h @@ -20,8 +20,8 @@ * Patches change both the patchlevel and the release date. Snapshots have no * patchlevel; they change the release date only. */ -#define MAIL_RELEASE_DATE "20220129" -#define MAIL_VERSION_NUMBER "3.7.0-RC2" +#define MAIL_RELEASE_DATE "20220205" +#define MAIL_VERSION_NUMBER "3.7.0" #ifdef SNAPSHOT #define MAIL_VERSION_DATE "-" MAIL_RELEASE_DATE diff --git a/postfix/src/postconf/postconf_lookup.c b/postfix/src/postconf/postconf_lookup.c index 2237d9d89..5185681e7 100644 --- a/postfix/src/postconf/postconf_lookup.c +++ b/postfix/src/postconf/postconf_lookup.c @@ -158,7 +158,6 @@ char *pcf_expand_parameter_value(VSTRING *buf, int mode, const char *value, PCF_MASTER_ENT *local_scope) { const char *myname = "pcf_expand_parameter_value"; - static VSTRING *local_buf; int status; PCF_EVAL_CTX eval_ctx; diff --git a/postfix/src/postconf/test2.ref b/postfix/src/postconf/test2.ref index ff25b0bd8..49af249a3 100644 --- a/postfix/src/postconf/test2.ref +++ b/postfix/src/postconf/test2.ref @@ -1,3 +1,3 @@ config_directory = . -./postconf: warning: ./main.cf: unused parameter: foo=yes ./postconf: warning: ./main.cf: unused parameter: restriction_classes=foo bar +./postconf: warning: ./main.cf: unused parameter: foo=yes diff --git a/postfix/src/postconf/test28.ref b/postfix/src/postconf/test28.ref index cb117b009..4e9373463 100644 --- a/postfix/src/postconf/test28.ref +++ b/postfix/src/postconf/test28.ref @@ -6,5 +6,5 @@ hh_domain = whatever yy = aap zz = $yy ./postconf: warning: ./main.cf: unused parameter: foo_domain=bar -./postconf: warning: ./main.cf: unused parameter: aa_domain=whatever ./postconf: warning: ./main.cf: unused parameter: xx=proxy:ldap:foo +./postconf: warning: ./main.cf: unused parameter: aa_domain=whatever diff --git a/postfix/src/postconf/test29.ref b/postfix/src/postconf/test29.ref index ce872f553..646890aaa 100644 --- a/postfix/src/postconf/test29.ref +++ b/postfix/src/postconf/test29.ref @@ -1,16 +1,16 @@ config_directory = . +./postconf: warning: ./main.cf: unused parameter: pgsqlfoo_domain=bar ./postconf: warning: ./main.cf: unused parameter: sqlitefoo_domain=bar -./postconf: warning: ./main.cf: unused parameter: mysqlfoo_domain=bar +./postconf: warning: ./main.cf: unused parameter: ldapxx=proxy:ldap:ldapfoo ./postconf: warning: ./main.cf: unused parameter: sqlitexx=proxy:sqlite:sqlitefoo -./postconf: warning: ./main.cf: unused parameter: pgsqlxx=proxy:pgsql:pgsqlfoo +./postconf: warning: ./main.cf: unused parameter: mysqlfoo_domain=bar +./postconf: warning: ./main.cf: unused parameter: sqlitefoo_domainx=bar +./postconf: warning: ./main.cf: unused parameter: memcachefoo_domain=bar ./postconf: warning: ./main.cf: unused parameter: pgsqlfoo_domainx=bar -./postconf: warning: ./main.cf: unused parameter: memcachexx=proxy:memcache:memcachefoo ./postconf: warning: ./main.cf: unused parameter: ldapfoo_domainx=bar ./postconf: warning: ./main.cf: unused parameter: ldapfoo_domain=bar +./postconf: warning: ./main.cf: unused parameter: memcachexx=proxy:memcache:memcachefoo ./postconf: warning: ./main.cf: unused parameter: memcachefoo_domainx=bar -./postconf: warning: ./main.cf: unused parameter: sqlitefoo_domainx=bar -./postconf: warning: ./main.cf: unused parameter: ldapxx=proxy:ldap:ldapfoo -./postconf: warning: ./main.cf: unused parameter: memcachefoo_domain=bar -./postconf: warning: ./main.cf: unused parameter: mysqlxx=proxy:mysql:mysqlfoo ./postconf: warning: ./main.cf: unused parameter: mysqlfoo_domainx=bar -./postconf: warning: ./main.cf: unused parameter: pgsqlfoo_domain=bar +./postconf: warning: ./main.cf: unused parameter: mysqlxx=proxy:mysql:mysqlfoo +./postconf: warning: ./main.cf: unused parameter: pgsqlxx=proxy:pgsql:pgsqlfoo diff --git a/postfix/src/postconf/test34.ref b/postfix/src/postconf/test34.ref index e7712932f..2c9d6bd55 100644 --- a/postfix/src/postconf/test34.ref +++ b/postfix/src/postconf/test34.ref @@ -1,4 +1,4 @@ -./postconf: warning: ./main.cf: read-only parameter assignment: process_id=yyy ./postconf: warning: ./main.cf: read-only parameter assignment: process_name=xxx +./postconf: warning: ./main.cf: read-only parameter assignment: process_id=yyy mydestination = whatever process_name = postconf diff --git a/postfix/src/postconf/test35.ref b/postfix/src/postconf/test35.ref index dc27f397b..601648f7b 100644 --- a/postfix/src/postconf/test35.ref +++ b/postfix/src/postconf/test35.ref @@ -1,3 +1,3 @@ -./postconf: warning: ./master.cf: read-only parameter assignment: process_id=bbb ./postconf: warning: ./master.cf: read-only parameter assignment: process_name=aaa +./postconf: warning: ./master.cf: read-only parameter assignment: process_id=bbb process_name = postconf diff --git a/postfix/src/postconf/test41.ref b/postfix/src/postconf/test41.ref index 852d309ee..f8200d401 100644 --- a/postfix/src/postconf/test41.ref +++ b/postfix/src/postconf/test41.ref @@ -3,16 +3,16 @@ bar unix - n n - 0 other -o xxx=yyy -o aaa=bbb baz unix - n n - 0 other -./postconf: warning: ./master.cf: unused parameter: xxx=yyy ./postconf: warning: ./master.cf: unused parameter: aaa=bbb +./postconf: warning: ./master.cf: unused parameter: xxx=yyy foo unix - n n - 0 other bar unix - n n - 0 other -o xxx=YYY -o aaa=BBB baz unix - n n - 0 other -./postconf: warning: ./master.cf: unused parameter: xxx=YYY ./postconf: warning: ./master.cf: unused parameter: aaa=BBB +./postconf: warning: ./master.cf: unused parameter: xxx=YYY bar/unix/aaa = BBB bar/unix/xxx = YYY -./postconf: warning: ./master.cf: unused parameter: xxx=YYY ./postconf: warning: ./master.cf: unused parameter: aaa=BBB +./postconf: warning: ./master.cf: unused parameter: xxx=YYY diff --git a/postfix/src/postconf/test42.ref b/postfix/src/postconf/test42.ref index 98981183a..80676f350 100644 --- a/postfix/src/postconf/test42.ref +++ b/postfix/src/postconf/test42.ref @@ -3,12 +3,12 @@ bar unix - n n - 0 other -o xxx=yyy -o aaa=bbb baz unix - n n - 0 other -./postconf: warning: ./master.cf: unused parameter: xxx=yyy ./postconf: warning: ./master.cf: unused parameter: aaa=bbb +./postconf: warning: ./master.cf: unused parameter: xxx=yyy bar/unix/aaa = bbb bar/unix/xxx = yyy -./postconf: warning: ./master.cf: unused parameter: xxx=yyy ./postconf: warning: ./master.cf: unused parameter: aaa=bbb +./postconf: warning: ./master.cf: unused parameter: xxx=yyy foo unix - n n - 0 other bar unix - n n - 0 other baz unix - n n - 0 other diff --git a/postfix/src/postconf/test57.ref b/postfix/src/postconf/test57.ref index 9bb13926e..362fd167a 100644 --- a/postfix/src/postconf/test57.ref +++ b/postfix/src/postconf/test57.ref @@ -6,5 +6,5 @@ config_directory = . t1 = Postfix 2.11 compatible x = x-value y = y-value -./postconf: warning: ./main.cf: unused parameter: foo=$bar$baz ./postconf: warning: ./main.cf: unused parameter: t2=$t1 +./postconf: warning: ./main.cf: unused parameter: foo=$bar$baz diff --git a/postfix/src/postconf/test59.ref b/postfix/src/postconf/test59.ref index 3a7e57f6a..c5cb3f6a0 100644 --- a/postfix/src/postconf/test59.ref +++ b/postfix/src/postconf/test59.ref @@ -6,5 +6,5 @@ bar inet - n n 0 0 other -o {name2=value2a value2b} arg1a arg1b {arg2a arg2b} {arg3a arg3b} baz unix - n n 0 0 other -./postconf: warning: ./master.cf: unused parameter: name1=value1 ./postconf: warning: ./master.cf: unused parameter: name2=value2a value2b +./postconf: warning: ./master.cf: unused parameter: name1=value1 diff --git a/postfix/src/postconf/test67.ref b/postfix/src/postconf/test67.ref index 1fd053856..2014e9925 100644 --- a/postfix/src/postconf/test67.ref +++ b/postfix/src/postconf/test67.ref @@ -6,5 +6,5 @@ smtp unix n - n - - smtp -o test2_service_name=smtp ./postconf: warning: ./master.cf: unused parameter: test1_service_name=$service_name ./postconf: warning: ./master.cf: unused parameter: test1_process_name=$process_name -./postconf: warning: ./master.cf: unused parameter: test2_process_name=$process_name ./postconf: warning: ./master.cf: unused parameter: test2_service_name=$service_name +./postconf: warning: ./master.cf: unused parameter: test2_process_name=$process_name diff --git a/postfix/src/tlsproxy/tlsproxy.c b/postfix/src/tlsproxy/tlsproxy.c index 42b7a75e7..b8242df77 100644 --- a/postfix/src/tlsproxy/tlsproxy.c +++ b/postfix/src/tlsproxy/tlsproxy.c @@ -272,12 +272,6 @@ /* value. /* .IP "\fBtlsproxy_client_scert_verifydepth ($smtp_tls_scert_verifydepth)\fR" /* The verification depth for remote TLS server certificates. -/* .IP "\fBtlsproxy_client_level ($smtp_tls_security_level)\fR" -/* The default TLS security level for the Postfix \fBtlsproxy\fR(8) -/* client. -/* .IP "\fBtlsproxy_client_policy ($smtp_tls_policy_maps)\fR" -/* Optional lookup tables with the Postfix \fBtlsproxy\fR(8) client TLS -/* security policy by next-hop destination. /* .IP "\fBtlsproxy_client_use_tls ($smtp_use_tls)\fR" /* Opportunistic mode: use TLS when a remote server announces TLS /* support. @@ -288,6 +282,14 @@ /* usage policy by next-hop destination and by remote TLS server /* hostname. /* .PP +/* Available in Postfix version 3.4-3.6: +/* .IP "\fBtlsproxy_client_level ($smtp_tls_security_level)\fR" +/* The default TLS security level for the Postfix \fBtlsproxy\fR(8) +/* client. +/* .IP "\fBtlsproxy_client_policy ($smtp_tls_policy_maps)\fR" +/* Optional lookup tables with the Postfix \fBtlsproxy\fR(8) client TLS +/* security policy by next-hop destination. +/* .PP /* Available in Postfix version 3.7 and later: /* .IP "\fBtlsproxy_client_security_level ($smtp_tls_security_level)\fR" /* The default TLS security level for the Postfix \fBtlsproxy\fR(8) diff --git a/postfix/src/util/Makefile.in b/postfix/src/util/Makefile.in index b0bfc2fa0..c59cdf986 100644 --- a/postfix/src/util/Makefile.in +++ b/postfix/src/util/Makefile.in @@ -140,7 +140,7 @@ TESTPROG= dict_open dup2_pass_on_exec events exec_command fifo_open \ valid_utf8_string ip_match base32_code msg_rate_delay netstring \ vstream timecmp dict_cache midna_domain casefold strcasecmp_utf8 \ vbuf_print split_qnameval vstream msg_logger byte_mask \ - known_tcp_ports dict_stream find_inet + known_tcp_ports dict_stream find_inet binhash PLUGIN_MAP_SO = $(LIB_PREFIX)pcre$(LIB_SUFFIX) HTABLE_FIX = NORANDOMIZE=1 LIB_DIR = ../../lib @@ -427,6 +427,11 @@ htable: $(LIB) $(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(SYSLIBS) mv junk $@.o +binhash: $(LIB) + mv $@.o junk + $(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(SYSLIBS) + mv junk $@.o + unix_recv_fd: $(LIB) mv $@.o junk $(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(SYSLIBS) @@ -580,7 +585,7 @@ tests: all valid_hostname_test mac_expand_test dict_test unescape_test \ dict_static_file_test dict_random_test dict_random_file_test \ dict_inline_file_test byte_mask_tests mystrtok_test \ known_tcp_ports_test dict_stream_test dict_inline_regexp_test \ - dict_inline_cidr_test + dict_inline_cidr_test binhash_test dict_pcre_tests: dict_pcre_test miss_endif_pcre_test dict_pcre_file_test \ dict_inline_pcre_test @@ -731,6 +736,9 @@ attr_scan_plain_test: attr_print_plain attr_scan_plain attr_scan_plain.ref htable_test: htable /usr/share/dict/words $(SHLIB_ENV) ${VALGRIND} ./htable < /usr/share/dict/words +binhash_test: binhash /usr/share/dict/words + $(SHLIB_ENV) ${VALGRIND} ./binhash < /usr/share/dict/words + hex_code_test: hex_code $(SHLIB_ENV) ${VALGRIND} ./hex_code @@ -1251,6 +1259,7 @@ basename.o: vbuf.h basename.o: vstring.h binhash.o: binhash.c binhash.o: binhash.h +binhash.o: hash_fnv.h binhash.o: msg.h binhash.o: mymalloc.h binhash.o: sys_defs.h @@ -2041,6 +2050,7 @@ known_tcp_ports.o: vbuf.h known_tcp_ports.o: vstring.h ldseed.o: iostuff.h ldseed.o: ldseed.c +ldseed.o: ldseed.h ldseed.o: msg.h ldseed.o: sys_defs.h line_number.o: check_arg.h @@ -2546,7 +2556,6 @@ stream_trigger.o: mymalloc.h stream_trigger.o: stream_trigger.c stream_trigger.o: sys_defs.h stream_trigger.o: trigger.h -sys_compat.o: iostuff.h sys_compat.o: sys_compat.c sys_compat.o: sys_defs.h timecmp.o: timecmp.c diff --git a/postfix/src/util/binhash.c b/postfix/src/util/binhash.c index ef8900dcc..fd9bc8779 100644 --- a/postfix/src/util/binhash.c +++ b/postfix/src/util/binhash.c @@ -51,6 +51,10 @@ /* /* BINHASH_INFO **binhash_list(table) /* BINHASH *table; +/* +/* BINHASH_INFO *binhash_sequence(table, how) +/* BINHASH *table; +/* int how; /* DESCRIPTION /* This module maintains one or more hash tables. Each table entry /* consists of a unique binary-valued lookup key and a generic @@ -91,6 +95,13 @@ /* binhash_list() returns a null-terminated list of pointers to /* all elements in the named table. The list should be passed to /* myfree(). +/* +/* binhash_sequence() returns the first or next element +/* depending on the value of the "how" argument. Specify +/* BINHASH_SEQ_FIRST to start a new sequence, BINHASH_SEQ_NEXT +/* to continue, and BINHASH_SEQ_STOP to terminate a sequence +/* early. The caller must not delete an element before it is +/* visited. /* RESTRICTIONS /* A callback function should not modify the hash table that is /* specified to its caller. @@ -100,6 +111,7 @@ /* to delete a non-existent entry. /* SEE ALSO /* mymalloc(3) memory management wrapper +/* hash_fnv(3) Fowler/Noll/Vo hash function /* LICENSE /* .ad /* .fi @@ -109,6 +121,11 @@ /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA +/* +/* Wietse Venema +/* Google, Inc. +/* 111 8th Avenue +/* New York, NY 10011, USA /*--*/ /* C library */ @@ -124,6 +141,13 @@ /* binhash_hash - hash a string */ +#ifndef NO_HASH_FNV +#include "hash_fnv.h" + +#define binhash_hash(key, len, size) (hash_fnv((key), (len)) % (size)) + +#else + static size_t binhash_hash(const void *key, ssize_t len, size_t size) { size_t h = 0; @@ -143,6 +167,8 @@ static size_t binhash_hash(const void *key, ssize_t len, size_t size) return (h % size); } +#endif + /* binhash_link - insert element into table */ #define binhash_link(table, elm) { \ @@ -178,6 +204,7 @@ BINHASH *binhash_create(ssize_t size) table = (BINHASH *) mymalloc(sizeof(BINHASH)); binhash_size(table, size < 13 ? 13 : size); + table->seq_bucket = table->seq_element = 0; return (table); } @@ -295,6 +322,9 @@ void binhash_free(BINHASH *table, void (*free_fn) (void *)) } myfree((void *) table->data); table->data = 0; + if (table->seq_bucket) + myfree((void *) table->seq_bucket); + table->seq_bucket = 0; myfree((void *) table); } } @@ -335,3 +365,83 @@ BINHASH *table; list[count] = 0; return (list); } + +/* binhash_sequence - dict(3) compatibility iterator */ + +BINHASH_INFO *binhash_sequence(BINHASH *table, int how) +{ + if (table == 0) + return (0); + + switch (how) { + case BINHASH_SEQ_FIRST: /* start new sequence */ + if (table->seq_bucket) + myfree((void *) table->seq_bucket); + table->seq_bucket = binhash_list(table); + table->seq_element = table->seq_bucket; + return (*(table->seq_element)++); + case BINHASH_SEQ_NEXT: /* next element */ + if (table->seq_element && *table->seq_element) + return (*(table->seq_element)++); + /* FALLTHROUGH */ + default: /* terminate sequence */ + if (table->seq_bucket) { + myfree((void *) table->seq_bucket); + table->seq_bucket = table->seq_element = 0; + } + return (0); + } +} + +#ifdef TEST +#include +#include + +int main(int unused_argc, char **unused_argv) +{ + VSTRING *buf = vstring_alloc(10); + ssize_t count = 0; + BINHASH *hash; + BINHASH_INFO **ht_info; + BINHASH_INFO **ht; + BINHASH_INFO *info; + ssize_t i; + ssize_t r; + int op; + + /* + * Load a large number of strings including terminator, and delete them + * in a random order. + */ + hash = binhash_create(10); + while (vstring_get(buf, VSTREAM_IN) != VSTREAM_EOF) + binhash_enter(hash, vstring_str(buf), VSTRING_LEN(buf) + 1, + CAST_INT_TO_VOID_PTR(count++)); + if (count != hash->used) + msg_panic("%ld entries stored, but %lu entries exist", + (long) count, (unsigned long) hash->used); + for (i = 0, op = BINHASH_SEQ_FIRST; (info = binhash_sequence(hash, op)) != 0; + i++, op = BINHASH_SEQ_NEXT) + if (memchr(info->key, 0, info->key_len) == 0) + msg_panic("no null byte in lookup key"); + if (i != hash->used) + msg_panic("%ld entries found, but %lu entries exist", + (long) i, (unsigned long) hash->used); + ht_info = binhash_list(hash); + for (i = 0; i < hash->used; i++) { + r = myrand() % hash->used; + info = ht_info[i]; + ht_info[i] = ht_info[r]; + ht_info[r] = info; + } + for (ht = ht_info; *ht; ht++) + binhash_delete(hash, ht[0]->key, ht[0]->key_len, (void (*) (void *)) 0); + if (hash->used > 0) + msg_panic("%ld entries not deleted", (long) hash->used); + myfree((void *) ht_info); + binhash_free(hash, (void (*) (void *)) 0); + vstring_free(buf); + return (0); +} + +#endif diff --git a/postfix/src/util/binhash.h b/postfix/src/util/binhash.h index d9ff83f43..3b4e1a479 100644 --- a/postfix/src/util/binhash.h +++ b/postfix/src/util/binhash.h @@ -27,6 +27,8 @@ typedef struct BINHASH { ssize_t size; /* length of entries array */ ssize_t used; /* number of entries in table */ BINHASH_INFO **data; /* entries array, auto-resized */ + BINHASH_INFO **seq_bucket; /* current sequence hash bucket */ + BINHASH_INFO **seq_element; /* current sequence element */ } BINHASH; extern BINHASH *binhash_create(ssize_t); @@ -37,6 +39,11 @@ extern void binhash_delete(BINHASH *, const void *, ssize_t, void (*) (void *)); extern void binhash_free(BINHASH *, void (*) (void *)); extern void binhash_walk(BINHASH *, void (*) (BINHASH_INFO *, void *), void *); extern BINHASH_INFO **binhash_list(BINHASH *); +extern BINHASH_INFO *binhash_sequence(BINHASH *, int); + +#define BINHASH_SEQ_FIRST 0 +#define BINHASH_SEQ_NEXT 1 +#define BINHASH_SEQ_STOP (-1) /* LICENSE /* .ad diff --git a/postfix/src/util/dict_db.c b/postfix/src/util/dict_db.c index 9cd1128ee..b2d0c336f 100644 --- a/postfix/src/util/dict_db.c +++ b/postfix/src/util/dict_db.c @@ -754,7 +754,7 @@ static DICT *dict_db_open(const char *class, const char *path, int open_flags, if (type == DB_HASH && db->set_h_nelem(db, DICT_DB_NELM) != 0) msg_fatal("set DB hash element count %d: %m", DICT_DB_NELM); db_base_buf = vstring_alloc(100); -#if DB_VERSION_MAJOR == 6 || DB_VERSION_MAJOR == 5 || \ +#if DB_VERSION_MAJOR == 18 || DB_VERSION_MAJOR == 6 || DB_VERSION_MAJOR == 5 || \ (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 0) if ((errno = db->open(db, 0, sane_basename(db_base_buf, db_path), 0, type, db_flags, 0644)) != 0) diff --git a/postfix/src/util/hash_fnv.c b/postfix/src/util/hash_fnv.c index d8baac549..10e97f056 100644 --- a/postfix/src/util/hash_fnv.c +++ b/postfix/src/util/hash_fnv.c @@ -28,9 +28,10 @@ /* get the standard behavior. /* /* The default HASH_FNV_T result type is uint64_t. When compiled -/* with -DNO_64_BITS, the result type is uint32_t. On ancient +/* with -DUSE_FNV_32BIT, the result type is uint32_t. On ancient /* systems without , define HASH_FNV_T on the compiler -/* command line as an unsigned 32-bit or 64-bit integer type. +/* command line as an unsigned 32-bit or 64-bit integer type, +/* and specify -DUSE_FNV_32BIT when HASH_FNV_T is a 32-bit type. /* SEE ALSO /* http://www.isthe.com/chongo/tech/comp/fnv/index.html /* https://softwareengineering.stackexchange.com/questions/49550/ @@ -62,7 +63,7 @@ /* * Application-specific. */ -#ifdef NO_64_BITS +#ifdef USE_FNV_32BIT #define FNV_prime 0x01000193UL #define FNV_offset_basis 0x811c9dc5UL #else diff --git a/postfix/src/util/hash_fnv.h b/postfix/src/util/hash_fnv.h index 19122aeef..dbbb383c5 100644 --- a/postfix/src/util/hash_fnv.h +++ b/postfix/src/util/hash_fnv.h @@ -16,11 +16,11 @@ */ #ifndef HASH_FNV_T #include -#ifdef NO_64_BITS +#ifdef USE_FNV_32BIT #define HASH_FNV_T uint32_t -#else /* NO_64_BITS */ +#else /* USE_FNV_32BIT */ #define HASH_FNV_T uint64_t -#endif /* NO_64_BITS */ +#endif /* USE_FNV_32BIT */ #endif /* HASH_FNV_T */ extern HASH_FNV_T hash_fnv(const void *, size_t); diff --git a/postfix/src/util/htable.c b/postfix/src/util/htable.c index 940d68699..1c08e9797 100644 --- a/postfix/src/util/htable.c +++ b/postfix/src/util/htable.c @@ -103,8 +103,8 @@ /* terminate immediately: memory allocation failure; an attempt /* to delete a non-existent entry. /* SEE ALSO -/* hash_fnv() Fowler/Noll/Vo hash function /* mymalloc(3) memory management wrapper +/* hash_fnv(3) Fowler/Noll/Vo hash function /* LICENSE /* .ad /* .fi @@ -410,6 +410,9 @@ int main(int unused_argc, char **unused_argv) hash = htable_create(10); while (vstring_get(buf, VSTREAM_IN) != VSTREAM_EOF) htable_enter(hash, vstring_str(buf), CAST_INT_TO_VOID_PTR(count++)); + if (count != hash->used) + msg_panic("%ld entries stored, but %lu entries exist", + (long) count, (unsigned long) hash->used); for (i = 0, op = HTABLE_SEQ_FIRST; htable_sequence(hash, op) != 0; i++, op = HTABLE_SEQ_NEXT) /* void */ ; diff --git a/postfix/src/util/ldseed.c b/postfix/src/util/ldseed.c index 7bce66831..c23115272 100644 --- a/postfix/src/util/ldseed.c +++ b/postfix/src/util/ldseed.c @@ -51,6 +51,7 @@ */ #include #include +#include /* * Different systems have different names for non-wallclock time.