1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 20maps.dpatch by LaMont Jones <lamont@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: patches to build dynamic maps and shared libs
@DPATCH@
diff -urNad postfix~/conf/postfix-files postfix/conf/postfix-files
--- postfix~/conf/postfix-files 2006-07-24 23:42:11.000000000 -0600
+++ postfix/conf/postfix-files 2006-10-15 20:55:26.000000000 -0600
@@ -63,6 +63,12 @@
$queue_directory/trace:d:$mail_owner:-:700:ucr
$daemon_directory/anvil:f:root:-:755
$daemon_directory/bounce:f:root:-:755
+$daemon_directory/dict_cdb.so:f:root:-:755
+$daemon_directory/dict_ldap.so:f:root:-:755
+$daemon_directory/dict_pcre.so:f:root:-:755
+$daemon_directory/dict_mysql.so:f:root:-:755
+$daemon_directory/dict_tcp.so:f:root:-:755
+$daemon_directory/dict_sdbm.so:f:root:-:755
$daemon_directory/cleanup:f:root:-:755
$daemon_directory/discard:f:root:-:755
$daemon_directory/error:f:root:-:755
@@ -85,6 +91,11 @@
$daemon_directory/trivial-rewrite:f:root:-:755
$daemon_directory/verify:f:root:-:755
$daemon_directory/virtual:f:root:-:755
+/usr/lib/libpostfix-dns.so.1:f:root:-:755
+/usr/lib/libpostfix-global.so.1:f:root:-:755
+/usr/lib/libpostfix-tls.so.1:f:root:-:755
+/usr/lib/libpostfix-master.so.1:f:root:-:755
+/usr/lib/libpostfix-util.so.1:f:root:-:755
$daemon_directory/nqmgr:h:$daemon_directory/qmgr
$daemon_directory/lmtp:h:$daemon_directory/smtp
$command_directory/postalias:f:root:-:755
@@ -107,6 +118,7 @@
$config_directory/aliases:f:root:-:644:p
$config_directory/bounce.cf.default:f:root:-:644
$config_directory/canonical:f:root:-:644:p
+$config_directory/dynamicmaps.cf:f:root:-:644:p
$config_directory/cidr_table:f:root:-:644:o
$config_directory/generic:f:root:-:644:p
$config_directory/generics:f:root:-:644:o
diff -urNad postfix~/src/dns/Makefile.in postfix/src/dns/Makefile.in
--- postfix~/src/dns/Makefile.in 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/dns/Makefile.in 2006-10-15 20:55:26.000000000 -0600
@@ -14,7 +14,7 @@
LIB_DIR = ../../lib
INC_DIR = ../../include
-.c.o:; $(CC) $(CFLAGS) -c $*.c
+.c.o:; $(CC) -fPIC $(CFLAGS) -c $*.c
all: $(LIB)
@@ -31,12 +31,10 @@
root_tests:
$(LIB): $(OBJS)
- $(AR) $(ARFL) $(LIB) $?
- $(RANLIB) $(LIB)
+ gcc -shared -Wl,-soname,libpostfix-dns.so.1 -o $(LIB) $(OBJS) $(LIBS) $(SYSLIBS)
$(LIB_DIR)/$(LIB): $(LIB)
cp $(LIB) $(LIB_DIR)
- $(RANLIB) $(LIB_DIR)/$(LIB)
update: $(LIB_DIR)/$(LIB) $(HDRS)
-for i in $(HDRS); \
diff -urNad postfix~/src/global/Makefile.in postfix/src/global/Makefile.in
--- postfix~/src/global/Makefile.in 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/global/Makefile.in 2006-10-15 20:55:26.000000000 -0600
@@ -32,7 +32,7 @@
canon_addr.o cfg_parser.o cleanup_strerror.o cleanup_strflags.o \
clnt_stream.o conv_time.o db_common.o debug_peer.o debug_process.o \
defer.o deliver_completed.o deliver_flock.o deliver_pass.o \
- deliver_request.o dict_ldap.o dict_mysql.o dict_pgsql.o \
+ deliver_request.o \
dict_proxy.o domain_list.o dot_lockfile.o dot_lockfile_as.o \
dsb_scan.o dsn.o dsn_buf.o dsn_mask.o dsn_print.o dsn_util.o \
ehlo_mask.o ext_prop.o file_id.o flush_clnt.o header_opts.o \
@@ -45,7 +45,7 @@
mail_params.o mail_pathname.o mail_queue.o mail_run.o \
mail_scan_dir.o mail_stream.o mail_task.o mail_trigger.o maps.o \
mark_corrupt.o match_parent_style.o mbox_conf.o mbox_open.o \
- mime_state.o mkmap_cdb.o mkmap_db.o mkmap_dbm.o mkmap_open.o \
+ mime_state.o mkmap_db.o mkmap_dbm.o mkmap_open.o \
mkmap_sdbm.o msg_stats_print.o msg_stats_scan.o mynetworks.o \
mypwd.o namadr_list.o off_cvt.o opened.o own_inet_addr.o \
pipe_command.o post_mail.o quote_821_local.o quote_822_local.o \
@@ -97,10 +97,14 @@
LIB_DIR = ../../lib
INC_DIR = ../../include
MAKES =
+LDAPSO = dict_ldap.so
+MYSQLSO = dict_mysql.so
+PGSQLSO = dict_pgsql.so
+CDBSO = dict_cdb.so
-.c.o:; $(CC) $(CFLAGS) -c $*.c
+.c.o:; $(CC) -fPIC $(CFLAGS) -c $*.c
-all: $(LIB)
+all: $(LIB) $(CDBSO) $(LDAPSO) $(MYSQLSO) $(PGSQLSO)
$(OBJS): ../../conf/makedefs.out
@@ -110,14 +114,39 @@
test: $(TESTPROG)
$(LIB): $(OBJS)
- $(AR) $(ARFL) $(LIB) $?
- $(RANLIB) $(LIB)
+ gcc -shared -Wl,-soname,libpostfix-global.so.1 -o $(LIB) $(OBJS) $(LIBS) $(SYSLIBS)
+
+$(CDBSO): dict_cdb.o mkmap_cdb.o
+ gcc -shared -Wl,-soname,dict_cdb.so -o $@ $? -lcdb -L. -lutil
+
+dict_cdb.o: ../util/dict_cdb.c
+ $(CC) -fPIC $(CFLAGS) -c $?
+
+$(LDAPSO): dict_ldap.o
+ gcc -shared -Wl,-soname,dict_ldap.so -o $@ $? -lldap -llber -L../../lib -lutil -L. -lglobal
+
+$(MYSQLSO): dict_mysql.o
+ gcc -shared -Wl,-soname,dict_mysql.so -o $@ $? -lmysqlclient -L. -lutil -lglobal
+
+$(PGSQLSO): dict_pgsql.o
+ gcc -shared -Wl,-soname,dict_pgsql.so -o $@ $? -lpq -L. -lutil -lglobal
$(LIB_DIR)/$(LIB): $(LIB)
cp $(LIB) $(LIB_DIR)
- $(RANLIB) $(LIB_DIR)/$(LIB)
-update: $(LIB_DIR)/$(LIB) $(HDRS)
+$(LIB_DIR)/$(CDBSO): $(CDBSO)
+ cp $(CDBSO) $(LIB_DIR)
+
+$(LIB_DIR)/$(LDAPSO): $(LDAPSO)
+ cp $(LDAPSO) $(LIB_DIR)
+
+$(LIB_DIR)/$(MYSQLSO): $(MYSQLSO)
+ cp $(MYSQLSO) $(LIB_DIR)
+
+$(LIB_DIR)/$(PGSQLSO): $(PGSQLSO)
+ cp $(PGSQLSO) $(LIB_DIR)
+
+update: $(LIB_DIR)/$(LIB) $(LIB_DIR)/${CDBSO} $(LIB_DIR)/${LDAPSO} $(LIB_DIR)/${MYSQLSO} $(LIB_DIR)/${PGSQLSO} $(HDRS)
-for i in $(HDRS); \
do \
cmp -s $$i $(INC_DIR)/$$i 2>/dev/null || cp $$i $(INC_DIR); \
@@ -403,7 +432,7 @@
lint $(DEFS) $(SRCS) $(LINTFIX)
clean:
- rm -f *.o $(LIB) *core $(TESTPROG) junk
+ rm -f *.o $(LIB) $(CDBSO) $(LDAPSO) $(MYSQLSO) $(PGSQLSO) *core $(TESTPROG) junk
rm -rf printfck
tidy: clean
diff -urNad postfix~/src/global/mail_conf.c postfix/src/global/mail_conf.c
--- postfix~/src/global/mail_conf.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/global/mail_conf.c 2006-10-15 20:55:26.000000000 -0600
@@ -175,6 +175,13 @@
path = concatenate(var_config_dir, "/", "main.cf", (char *) 0);
dict_load_file(CONFIG_DICT, path);
myfree(path);
+
+#ifndef NO_DYNAMIC_MAPS
+ path = concatenate(var_config_dir, "/", "dynamicmaps.cf", (char *) 0);
+ dict_open_dlinfo(path);
+ myfree(path);
+#endif
+
}
/* mail_conf_eval - expand macros in string */
diff -urNad postfix~/src/global/mail_dict.c postfix/src/global/mail_dict.c
--- postfix~/src/global/mail_dict.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/global/mail_dict.c 2006-10-15 20:55:26.000000000 -0600
@@ -45,6 +45,7 @@
static DICT_OPEN_INFO dict_open_info[] = {
DICT_TYPE_PROXY, dict_proxy_open,
+#ifndef MAX_DYNAMIC_MAPS
#ifdef HAS_LDAP
DICT_TYPE_LDAP, dict_ldap_open,
#endif
@@ -54,6 +55,7 @@
#ifdef HAS_PGSQL
DICT_TYPE_PGSQL, dict_pgsql_open,
#endif
+#endif /* MAX_DYNAMIC_MAPS */
0,
};
diff -urNad postfix~/src/global/mail_params.c postfix/src/global/mail_params.c
--- postfix~/src/global/mail_params.c 2006-10-15 20:55:25.000000000 -0600
+++ postfix/src/global/mail_params.c 2006-10-15 20:55:26.000000000 -0600
@@ -77,6 +77,7 @@
/* char *var_export_environ;
/* char *var_debug_peer_list;
/* int var_debug_peer_level;
+/* int var_command_maxtime;
/* int var_in_flow_delay;
/* int var_fault_inj_code;
/* char *var_bounce_service;
@@ -249,6 +250,7 @@
char *var_export_environ;
char *var_debug_peer_list;
int var_debug_peer_level;
+int var_command_maxtime;
int var_fault_inj_code;
char *var_bounce_service;
char *var_cleanup_service;
@@ -260,6 +262,7 @@
char *var_error_service;
char *var_flush_service;
char *var_verify_service;
+char *var_scache_service;
char *var_trace_service;
int var_db_create_buf;
int var_db_read_buf;
diff -urNad postfix~/src/global/mkmap_open.c postfix/src/global/mkmap_open.c
--- postfix~/src/global/mkmap_open.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/global/mkmap_open.c 2006-10-15 20:57:13.000000000 -0600
@@ -78,14 +78,16 @@
* types that exist as files. Network-based maps are not of interest.
*/
typedef struct {
- char *type;
+ const char *type;
MKMAP *(*before_open) (const char *);
} MKMAP_OPEN_INFO;
MKMAP_OPEN_INFO mkmap_types[] = {
+#ifndef MAX_DYNAMIC_MAPS
#ifdef HAS_CDB
DICT_TYPE_CDB, mkmap_cdb_open,
#endif
+#endif
#ifdef HAS_SDBM
DICT_TYPE_SDBM, mkmap_sdbm_open,
#endif
@@ -152,7 +154,16 @@
*/
for (mp = mkmap_types; /* void */ ; mp++) {
if (mp->type == 0)
+#ifndef NO_DYNAMIC_MAPS
+ {
+ static MKMAP_OPEN_INFO oi;
+ oi.before_open=(MKMAP*(*)(const char*))dict_mkmap_func(type);
+ oi.type=type;
+ mp=&oi;
+ }
+#else
msg_fatal("unsupported map type: %s", type);
+#endif
if (strcmp(type, mp->type) == 0)
break;
}
diff -urNad postfix~/src/master/Makefile.in postfix/src/master/Makefile.in
--- postfix~/src/master/Makefile.in 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/master/Makefile.in 2006-10-15 20:55:26.000000000 -0600
@@ -20,7 +20,7 @@
INC_DIR = ../../include
BIN_DIR = ../../libexec
-.c.o:; $(CC) $(CFLAGS) -c $*.c
+.c.o:; $(CC) `for i in $(LIB_OBJ); do [ $$i = $@ ] && echo -fPIC; done` $(CFLAGS) -c $*.c
all: $(PROG) $(LIB)
@@ -39,12 +39,10 @@
root_tests:
$(LIB): $(LIB_OBJ)
- $(AR) $(ARFL) $(LIB) $?
- $(RANLIB) $(LIB)
+ gcc -shared -Wl,-soname,libpostfix-master.so.1 -o $(LIB) $(LIB_OBJ) $(LIBS) $(SYSLIBS)
$(LIB_DIR)/$(LIB): $(LIB)
cp $(LIB) $(LIB_DIR)/$(LIB)
- $(RANLIB) $(LIB_DIR)/$(LIB)
$(BIN_DIR)/$(PROG): $(PROG)
cp $(PROG) $(BIN_DIR)
diff -urNad postfix~/src/postconf/postconf.c postfix/src/postconf/postconf.c
--- postfix~/src/postconf/postconf.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/postconf/postconf.c 2006-10-15 20:55:26.000000000 -0600
@@ -898,6 +898,16 @@
{
ARGV *maps_argv;
int i;
+#ifndef NO_DYNAMIC_MAPS
+ char *path;
+ char *config_dir;
+
+ var_config_dir = mystrdup((config_dir = safe_getenv(CONF_ENV_PATH)) != 0 ?
+ config_dir : DEF_CONFIG_DIR); /* XXX */
+ path = concatenate(var_config_dir, "/", "dynamicmaps.cf", (char *) 0);
+ dict_open_dlinfo(path);
+ myfree(path);
+#endif
maps_argv = dict_mapnames();
for (i = 0; i < maps_argv->argc; i++)
diff -urNad postfix~/src/postmap/postmap.c postfix/src/postmap/postmap.c
--- postfix~/src/postmap/postmap.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/postmap/postmap.c 2006-10-15 20:55:26.000000000 -0600
@@ -5,7 +5,7 @@
/* Postfix lookup table management
/* SYNOPSIS
/* .fi
-/* \fBpostmap\fR [\fB-Nfinoprsvw\fR] [\fB-c \fIconfig_dir\fR]
+/* \fBpostmap\fR [\fB-Nfinoprsuvw\fR] [\fB-c \fIconfig_dir\fR]
/* [\fB-d \fIkey\fR] [\fB-q \fIkey\fR]
/* [\fIfile_type\fR:]\fIfile_name\fR ...
/* DESCRIPTION
@@ -109,6 +109,8 @@
/* as the original input order.
/* This feature is available in Postfix version 2.2 and later,
/* and is not available for all database types.
+/* .IP \fB-u\fR
+/* Upgrade the database to the current version.
/* .IP \fB-v\fR
/* Enable verbose logging for debugging purposes. Multiple \fB-v\fR
/* options make the software increasingly verbose.
@@ -531,6 +533,18 @@
dict_close(dict);
}
+/* postmap_upgrade - upgrade a map */
+
+static int postmap_upgrade(const char *map_type, const char *map_name)
+{
+ DICT *dict;
+
+ dict = dict_open3(map_type, map_name, O_RDWR,
+ DICT_FLAG_LOCK|DICT_FLAG_UPGRADE);
+ dict_close(dict);
+ return (dict != 0);
+}
+
/* usage - explain */
static NORETURN usage(char *myname)
@@ -549,6 +563,7 @@
int postmap_flags = POSTMAP_FLAG_AS_OWNER | POSTMAP_FLAG_SAVE_PERM;
int open_flags = O_RDWR | O_CREAT | O_TRUNC;
int dict_flags = DICT_FLAG_DUP_WARN | DICT_FLAG_FOLD_FIX;
+ int upgrade = 0;
char *query = 0;
char *delkey = 0;
int sequence = 0;
@@ -588,7 +603,7 @@
/*
* Parse JCL.
*/
- while ((ch = GETOPT(argc, argv, "Nc:d:finopq:rsvw")) > 0) {
+ while ((ch = GETOPT(argc, argv, "Nc:d:finopq:rsuvw")) > 0) {
switch (ch) {
default:
usage(argv[0]);
@@ -602,8 +617,8 @@
msg_fatal("out of memory");
break;
case 'd':
- if (sequence || query || delkey)
- msg_fatal("specify only one of -s -q or -d");
+ if (sequence || query || delkey || upgrade)
+ msg_fatal("specify only one of -s -q -u or -d");
delkey = optarg;
break;
case 'f':
@@ -623,8 +638,8 @@
postmap_flags &= ~POSTMAP_FLAG_SAVE_PERM;
break;
case 'q':
- if (sequence || query || delkey)
- msg_fatal("specify only one of -s -q or -d");
+ if (sequence || query || delkey || upgrade)
+ msg_fatal("specify only one of -s -q -u or -d");
query = optarg;
break;
case 'r':
@@ -632,10 +647,15 @@
dict_flags |= DICT_FLAG_DUP_REPLACE;
break;
case 's':
- if (query || delkey)
- msg_fatal("specify only one of -s or -q or -d");
+ if (query || delkey || upgrade)
+ msg_fatal("specify only one of -s or -q -u or -d");
sequence = 1;
break;
+ case 'u':
+ if (sequence || query || delkey || upgrade)
+ msg_fatal("specify only one of -s -q -u or -d");
+ upgrade=1;
+ break;
case 'v':
msg_verbose++;
break;
@@ -701,6 +721,21 @@
exit(0);
}
exit(1);
+ } else if (upgrade) { /* Upgrade the map(s) */
+ int success = 1;
+ if (optind + 1 > argc)
+ usage(argv[0]);
+ while (optind < argc) {
+ if ((path_name = split_at(argv[optind], ':')) != 0) {
+ success &= postmap_upgrade(argv[optind], path_name);
+ } else {
+ success &= postmap_upgrade(var_db_type, path_name);
+ }
+ if (!success)
+ exit(1);
+ optind++;
+ }
+ exit(0);
} else { /* create/update map(s) */
if (optind + 1 > argc)
usage(argv[0]);
diff -urNad postfix~/src/tls/Makefile.in postfix/src/tls/Makefile.in
--- postfix~/src/tls/Makefile.in 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/tls/Makefile.in 2006-10-15 20:55:26.000000000 -0600
@@ -22,7 +22,7 @@
INC_DIR = ../../include
MAKES =
-.c.o:; $(CC) $(CFLAGS) -c $*.c
+.c.o:; $(CC) -fPIC $(CFLAGS) -c $*.c
all: $(LIB)
@@ -38,12 +38,10 @@
root_tests:
$(LIB): $(OBJS)
- $(AR) $(ARFL) $(LIB) $?
- $(RANLIB) $(LIB)
+ gcc -shared -Wl,-soname,libpostfix-tls.so.1 -o $(LIB) $(OBJS) $(LIBS) $(SYSLIBS)
$(LIB_DIR)/$(LIB): $(LIB)
cp $(LIB) $(LIB_DIR)
- $(RANLIB) $(LIB_DIR)/$(LIB)
update: $(LIB_DIR)/$(LIB) $(HDRS)
-for i in $(HDRS); \
diff -urNad postfix~/src/util/Makefile.in postfix/src/util/Makefile.in
--- postfix~/src/util/Makefile.in 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/util/Makefile.in 2006-10-15 20:55:26.000000000 -0600
@@ -1,4 +1,4 @@
-SHELL = /bin/sh
+cdb = /bin/sh
SRCS = alldig.c allprint.c argv.c argv_split.c attr_clnt.c attr_print0.c \
attr_print64.c attr_print_plain.c attr_scan0.c attr_scan64.c \
attr_scan_plain.c auto_clnt.c base64_code.c basename.c binhash.c \
@@ -30,21 +30,21 @@
username.c valid_hostname.c vbuf.c vbuf_print.c vstream.c \
vstream_popen.c vstring.c vstring_vstream.c watchdog.c writable.c \
write_buf.c write_wait.c sane_basename.c format_tv.c allspace.c \
- allascii.c load_file.c
+ allascii.c load_file.c load_lib.c sdbm.c
OBJS = alldig.o allprint.o argv.o argv_split.o attr_clnt.o attr_print0.o \
attr_print64.o attr_print_plain.o attr_scan0.o attr_scan64.o \
attr_scan_plain.o auto_clnt.o base64_code.o basename.o binhash.o \
chroot_uid.o cidr_match.o clean_env.o close_on_exec.o concatenate.o \
- ctable.o dict.o dict_alloc.o dict_cdb.o dict_cidr.o dict_db.o \
+ ctable.o dict.o dict_alloc.o dict_cidr.o dict_db.o \
dict_dbm.o dict_debug.o dict_env.o dict_ht.o dict_ni.o dict_nis.o \
- dict_nisplus.o dict_open.o dict_pcre.o dict_regexp.o dict_sdbm.o \
- dict_static.o dict_tcp.o dict_unix.o dir_forest.o doze.o dummy_read.o \
+ dict_nisplus.o dict_open.o dict_regexp.o dict_sdbm.o \
+ dict_static.o dict_unix.o dir_forest.o doze.o dummy_read.o \
dummy_write.o duplex_pipe.o environ.o events.o exec_command.o \
fifo_listen.o fifo_trigger.o file_limit.o find_inet.o fsspace.o \
fullname.o get_domainname.o get_hostname.o hex_code.o hex_quote.o \
host_port.o htable.o inet_addr_host.o inet_addr_list.o \
inet_addr_local.o inet_connect.o inet_listen.o inet_proto.o \
- inet_trigger.o line_wrap.o lowercase.o lstat_as.o mac_expand.o \
+ inet_trigger.o line_wrap.o lowercase.o lstat_as.o mac_expand.o load_lib.o sdbm.o \
mac_parse.o make_dirs.o mask_addr.o match_list.o match_ops.o msg.o \
msg_output.o msg_syslog.o msg_vstream.o mvect.o myaddrinfo.o myflock.o \
mymalloc.o myrand.o mystrtok.o name_code.o name_mask.o netstring.o \
@@ -76,7 +76,7 @@
msg_output.h msg_syslog.h msg_vstream.h mvect.h myaddrinfo.h myflock.h \
mymalloc.h myrand.h name_code.h name_mask.h netstring.h nvtable.h \
open_as.h open_lock.h percentm.h posix_signals.h readlline.h ring.h \
- safe.h safe_open.h sane_accept.h sane_connect.h sane_fsops.h \
+ safe.h safe_open.h sane_accept.h sane_connect.h sane_fsops.h sdbm.h load_lib.h \
sane_socketpair.h sane_time.h scan_dir.h set_eugid.h set_ugid.h \
sigdelay.h sock_addr.h spawn_command.h split_at.h stat_as.h \
stringops.h sys_defs.h timed_connect.h timed_wait.h trigger.h \
@@ -88,6 +88,8 @@
CFLAGS = $(DEBUG) $(OPT) $(DEFS)
FILES = Makefile $(SRCS) $(HDRS)
INCL =
+PCRESO = dict_pcre.so
+TCPSO = dict_tcp.so
LIB = libutil.a
TESTPROG= dict_open dup2_pass_on_exec events exec_command fifo_open \
fifo_rdonly_bug fifo_rdwr_bug fifo_trigger fsspace fullname \
@@ -102,10 +104,11 @@
LIB_DIR = ../../lib
INC_DIR = ../../include
+LIBS = $(LIB_DIR)/$(LIB) $(LIB_DIR)/$(PCRESO) $(LIB_DIR)/$(TCPSO)
-.c.o:; $(CC) $(CFLAGS) -c $*.c
+.c.o:; $(CC) -fPIC $(CFLAGS) -c $*.c
-all: $(LIB)
+all: $(LIB) $(PCRESO) $(TCPSO)
$(OBJS): ../../conf/makedefs.out
@@ -114,15 +117,25 @@
test: $(TESTPROG)
+$(PCRESO): dict_pcre.o
+ gcc -shared -Wl,-soname,dict_pcre.so -o $@ $? -lpcre -L. -lutil
+
+$(TCPSO): dict_tcp.o
+ gcc -shared -Wl,-soname,dict_tcp.so -o $@ $? -L. -lutil
+
$(LIB): $(OBJS)
- $(AR) $(ARFL) $(LIB) $?
- $(RANLIB) $(LIB)
+ gcc -shared -Wl,-soname,libpostfix-util.so.1 -o $(LIB) $(OBJS) -ldl $(SYSLIBS)
$(LIB_DIR)/$(LIB): $(LIB)
cp $(LIB) $(LIB_DIR)
- $(RANLIB) $(LIB_DIR)/$(LIB)
-update: $(LIB_DIR)/$(LIB) $(HDRS)
+$(LIB_DIR)/$(PCRESO): $(PCRESO)
+ cp $(PCRESO) $(LIB_DIR)
+
+$(LIB_DIR)/$(TCPSO): $(TCPSO)
+ cp $(TCPSO) $(LIB_DIR)
+
+update: $(LIBS) $(HDRS)
-for i in $(HDRS); \
do \
cmp -s $$i $(INC_DIR)/$$i 2>/dev/null || cp $$i $(INC_DIR); \
@@ -144,7 +157,8 @@
lint $(SRCS)
clean:
- rm -f *.o $(LIB) *core $(TESTPROG) junk $(MAKES) *.tmp
+ rm -f *.o $(LIB) $(PCRESO) $(TCPSO) *core $(TESTPROG) \
+ junk $(MAKES) *.tmp
rm -rf printfck
tidy: clean
diff -urNad postfix~/src/util/dict.h postfix/src/util/dict.h
--- postfix~/src/util/dict.h 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/util/dict.h 2006-10-15 20:55:26.000000000 -0600
@@ -65,6 +65,7 @@
#define DICT_FLAG_NO_UNAUTH (1<<13) /* disallow unauthenticated data */
#define DICT_FLAG_FOLD_FIX (1<<14) /* case-fold key with fixed-case map */
#define DICT_FLAG_FOLD_MUL (1<<15) /* case-fold key with multi-case map */
+#define DICT_FLAG_UPGRADE (1<<30) /* Upgrade the db */
#define DICT_FLAG_FOLD_ANY (DICT_FLAG_FOLD_FIX | DICT_FLAG_FOLD_MUL)
/* IMPORTANT: Update the dict_mask[] table when the above changes */
@@ -109,6 +110,11 @@
extern DICT *dict_open(const char *, int, int);
extern DICT *dict_open3(const char *, const char *, int, int);
extern void dict_open_register(const char *, DICT *(*) (const char *, int, int));
+#ifndef NO_DYNAMIC_MAPS
+extern void dict_open_dlinfo(const char *path);
+typedef void* (*dict_mkmap_func_t)(const char *);
+dict_mkmap_func_t dict_mkmap_func(const char *dict_type);
+#endif
#define dict_get(dp, key) (dp)->lookup((dp), (key))
#define dict_put(dp, key, val) (dp)->update((dp), (key), (val))
diff -urNad postfix~/src/util/dict_db.c postfix/src/util/dict_db.c
--- postfix~/src/util/dict_db.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/util/dict_db.c 2006-10-15 20:55:26.000000000 -0600
@@ -658,6 +658,12 @@
msg_fatal("set DB cache size %d: %m", dict_db_cache_size);
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);
+ if (dict_flags & DICT_FLAG_UPGRADE) {
+ if (msg_verbose)
+ msg_info("upgrading database %s",db_path);
+ if ((errno = db->upgrade(db,db_path,0)) != 0)
+ msg_fatal("upgrade of database %s: %m",db_path);
+ }
#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 0)
if ((errno = db->open(db, 0, db_path, 0, type, db_flags, 0644)) != 0)
msg_fatal("open database %s: %m", db_path);
diff -urNad postfix~/src/util/dict_dbm.c postfix/src/util/dict_dbm.c
--- postfix~/src/util/dict_dbm.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/util/dict_dbm.c 2006-10-15 20:55:26.000000000 -0600
@@ -401,6 +401,10 @@
char *dbm_path;
int lock_fd;
+#ifdef HAVE_GDBM
+ msg_fatal("%s: gdbm maps use locking that is incompatible with postfix. Use a hash map instead.",
+ path);
+#endif
/*
* Note: DICT_FLAG_LOCK is used only by programs that do fine-grained (in
* the time domain) locking while accessing individual database records.
diff -urNad postfix~/src/util/dict_open.c postfix/src/util/dict_open.c
--- postfix~/src/util/dict_open.c 2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/util/dict_open.c 2006-10-15 20:55:26.000000000 -0600
@@ -44,6 +44,8 @@
/* DICT *(*open) (const char *, int, int);
/*
/* ARGV *dict_mapnames()
+/*
+/* void (*)() dict_mkmap_func(const char *dict_type)
/* DESCRIPTION
/* This module implements a low-level interface to multiple
/* physical dictionary types.
@@ -156,6 +158,9 @@
/*
/* dict_mapnames() returns a sorted list with the names of all available
/* dictionary types.
+/*
+/* dict_mkmap_func() returns a pointer to the mkmap setup function
+/* for the given map type, as given in /etc/dynamicmaps.cf
/* DIAGNOSTICS
/* Fatal error: open error, unsupported dictionary type, attempt to
/* update non-writable dictionary.
@@ -180,6 +185,9 @@
#include <strings.h>
#endif
+#include <sys/stat.h>
+#include <unistd.h>
+
/* Utility library. */
#include <argv.h>
@@ -204,6 +212,27 @@
#include <split_at.h>
#include <htable.h>
+#ifndef NO_DYNAMIC_MAPS
+#include <load_lib.h>
+#include <vstring.h>
+#include <vstream.h>
+#include <vstring_vstream.h>
+#include <mvect.h>
+
+ /*
+ * Interface for dynamic map loading.
+ */
+typedef struct {
+ const char *pattern;
+ const char *soname;
+ const char *openfunc;
+ const char *mkmapfunc;
+} DLINFO;
+
+static DLINFO *dict_dlinfo;
+static DLINFO *dict_open_dlfind(const char *type);
+#endif
+
/*
* lookup table for available map types.
*/
@@ -213,14 +242,18 @@
} DICT_OPEN_INFO;
static DICT_OPEN_INFO dict_open_info[] = {
+#ifndef MAX_DYNAMIC_MAPS
#ifdef HAS_CDB
DICT_TYPE_CDB, dict_cdb_open,
#endif
+#endif /* MAX_DYNAMIC_MAPS */
DICT_TYPE_ENVIRON, dict_env_open,
DICT_TYPE_UNIX, dict_unix_open,
+#ifndef MAX_DYNAMIC_MAPS
#ifdef SNAPSHOT
DICT_TYPE_TCP, dict_tcp_open,
#endif
+#endif
#ifdef HAS_SDBM
DICT_TYPE_SDBM, dict_sdbm_open,
#endif
@@ -240,9 +273,11 @@
#ifdef HAS_NETINFO
DICT_TYPE_NETINFO, dict_ni_open,
#endif
+#ifndef MAX_DYNAMIC_MAPS
#ifdef HAS_PCRE
DICT_TYPE_PCRE, dict_pcre_open,
#endif
+#endif /* MAX_DYNAMIC_MAPS */
#ifdef HAS_POSIX_REGEXP
DICT_TYPE_REGEXP, dict_regexp_open,
#endif
@@ -300,8 +335,31 @@
dict_type, dict_name);
if (dict_open_hash == 0)
dict_open_init();
- if ((dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type)) == 0)
- msg_fatal("unsupported dictionary type: %s", dict_type);
+ if ((dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type)) == 0) {
+#ifdef NO_DYNAMIC_MAPS
+ msg_fatal("%s: unsupported dictionary type: %s", myname, dict_type);
+#else
+ struct stat st;
+ LIB_FN fn[2];
+ DICT *(*open) (const char *, int, int);
+ DLINFO *dl=dict_open_dlfind(dict_type);
+ if (!dl)
+ msg_fatal("%s: unsupported dictionary type: %s: Is the postfix-%s package installed?", myname, dict_type, dict_type);
+ if (stat(dl->soname,&st) < 0) {
+ msg_fatal("%s: unsupported dictionary type: %s (%s not found. Is the postfix-%s package installed?)",
+ myname, dict_type, dl->soname, dict_type);
+ }
+ fn[0].name = dl->openfunc;
+ fn[0].ptr = (void**)&open;
+ fn[1].name = NULL;
+ load_library_symbols(dl->soname, fn, NULL);
+ dict_open_register(dict_type, open);
+ dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type);
+#endif
+ }
+ if (msg_verbose>1) {
+ msg_info("%s: calling %s open routine",myname,dict_type);
+ }
if ((dict = dp->open(dict_name, open_flags, dict_flags)) == 0)
msg_fatal("opening %s:%s %m", dict_type, dict_name);
if (msg_verbose)
@@ -309,6 +367,36 @@
return (dict);
}
+dict_mkmap_func_t dict_mkmap_func(const char *dict_type)
+{
+ char *myname="dict_mkmap_func";
+ struct stat st;
+ LIB_FN fn[2];
+ dict_mkmap_func_t mkmap;
+ DLINFO *dl;
+#ifndef NO_DYNAMIC_MAPS
+ if (!dict_dlinfo)
+ msg_fatal("dlinfo==NULL");
+ dl=dict_open_dlfind(dict_type);
+ if (!dl)
+ msg_fatal("%s: unsupported dictionary type: %s: Is the postfix-%s package installed?", myname, dict_type, dict_type);
+ if (stat(dl->soname,&st) < 0) {
+ msg_fatal("%s: unsupported dictionary type: %s (%s not found. Is the postfix-%s package installed?)",
+ myname, dict_type, dl->soname, dict_type);
+ }
+ if (!dl->mkmapfunc)
+ msg_fatal("%s: unsupported dictionary type: %s does not allow map creation.", myname, dict_type);
+
+ fn[0].name = dl->mkmapfunc;
+ fn[0].ptr = (void**)&mkmap;
+ fn[1].name = NULL;
+ load_library_symbols(dl->soname, fn, NULL);
+ return mkmap;
+#else
+ return (void(*)())NULL;
+#endif
+}
+
/* dict_open_register - register dictionary type */
void dict_open_register(const char *type,
@@ -342,6 +430,9 @@
HTABLE_INFO **ht;
DICT_OPEN_INFO *dp;
ARGV *mapnames;
+#ifndef NO_DYNAMIC_MAPS
+ DLINFO *dlp;
+#endif
if (dict_open_hash == 0)
dict_open_init();
@@ -350,6 +441,13 @@
dp = (DICT_OPEN_INFO *) ht[0]->value;
argv_add(mapnames, dp->type, ARGV_END);
}
+#ifndef NO_DYNAMIC_MAPS
+ if (!dict_dlinfo)
+ msg_fatal("dlinfo==NULL");
+ for (dlp=dict_dlinfo; dlp->pattern; dlp++) {
+ argv_add(mapnames, dlp->pattern, ARGV_END);
+ }
+#endif
qsort((void *) mapnames->argv, mapnames->argc, sizeof(mapnames->argv[0]),
dict_sort_alpha_cpp);
myfree((char *) ht_info);
@@ -357,6 +455,87 @@
return mapnames;
}
+#ifndef NO_DYNAMIC_MAPS
+#define STREQ(x,y) (x == y || (x[0] == y[0] && strcmp(x,y) == 0))
+
+void dict_open_dlinfo(const char *path)
+{
+ char *myname="dict_open_dlinfo";
+ VSTREAM *conf_fp=vstream_fopen(path,O_RDONLY,0);
+ VSTRING *buf = vstring_alloc(100);
+ char *cp;
+ ARGV *argv;
+ MVECT vector;
+ int nelm=0;
+ int linenum=0;
+
+ dict_dlinfo=(DLINFO*)mvect_alloc(&vector,sizeof(DLINFO),3,NULL,NULL);
+
+ if (!conf_fp) {
+ msg_warn("%s: cannot open %s. No dynamic maps will be allowed.",
+ myname, path);
+ } else {
+ while (vstring_get_nonl(buf,conf_fp) != VSTREAM_EOF) {
+ cp = vstring_str(buf);
+ linenum++;
+ if (*cp == '#' || *cp == '\0')
+ continue;
+ argv = argv_split(cp, " \t");
+ if (argv->argc != 3 && argv->argc != 4) {
+ msg_fatal("%s: Expected \"pattern .so-name open-function [mkmap-function]\" at line %d",
+ myname, linenum);
+ }
+ if (STREQ(argv->argv[0],"*")) {
+ msg_warn("%s: wildcard dynamic map entry no longer supported.",
+ myname);
+ continue;
+ }
+ if (argv->argv[1][0] != '/') {
+ msg_fatal("%s: .so name must begin with a \"/\" at line %d",
+ myname, linenum);
+ }
+ if (nelm >= vector.nelm) {
+ dict_dlinfo=(DLINFO*)mvect_realloc(&vector,vector.nelm+3);
+ }
+ dict_dlinfo[nelm].pattern = mystrdup(argv->argv[0]);
+ dict_dlinfo[nelm].soname = mystrdup(argv->argv[1]);
+ dict_dlinfo[nelm].openfunc = mystrdup(argv->argv[2]);
+ if (argv->argc==4)
+ dict_dlinfo[nelm].mkmapfunc = mystrdup(argv->argv[3]);
+ else
+ dict_dlinfo[nelm].mkmapfunc = NULL;
+ nelm++;
+ argv_free(argv);
+ }
+ }
+ if (nelm >= vector.nelm) {
+ dict_dlinfo=(DLINFO*)mvect_realloc(&vector,vector.nelm+1);
+ }
+ dict_dlinfo[nelm].pattern = NULL;
+ dict_dlinfo[nelm].soname = NULL;
+ dict_dlinfo[nelm].openfunc = NULL;
+ dict_dlinfo[nelm].mkmapfunc = NULL;
+ if (conf_fp)
+ vstream_fclose(conf_fp);
+ vstring_free(buf);
+}
+
+static DLINFO *dict_open_dlfind(const char *type)
+{
+ DLINFO *dp;
+
+ if (!dict_dlinfo)
+ return NULL;
+
+ for (dp=dict_dlinfo; dp->pattern; dp++) {
+ if (STREQ(dp->pattern,type))
+ return dp;
+ }
+ return NULL;
+}
+
+#endif /* !NO_DYNAMIC_MAPS */
+
#ifdef TEST
/*
diff -urNad postfix~/src/util/load_lib.c postfix/src/util/load_lib.c
--- postfix~/src/util/load_lib.c 1969-12-31 17:00:00.000000000 -0700
+++ postfix/src/util/load_lib.c 2006-10-15 20:55:26.000000000 -0600
@@ -0,0 +1,135 @@
+/*++
+/* NAME
+/* load_lib 3
+/* SUMMARY
+/* library loading wrappers
+/* SYNOPSIS
+/* #include <load_lib.h>
+/*
+/* extern int load_library_symbols(const char *, LIB_FN *, LIB_FN *);
+/* const char *libname;
+/* LIB_FN *libfuncs;
+/* LIB_FN *libdata;
+/*
+/* DESCRIPTION
+/* This module loads functions from libraries, returnine pointers
+/* to the named functions.
+/*
+/* load_library_symbols() loads all of the desired functions, and
+/* returns zero for success, or exits via msg_fatal().
+/*
+/* SEE ALSO
+/* msg(3) diagnostics interface
+/* DIAGNOSTICS
+/* Problems are reported via the msg(3) diagnostics routines:
+/* library not found, symbols not found, other fatal errors.
+/* LICENSE
+/* .ad
+/* .fi
+/* The Secure Mailer license must be distributed with this software.
+/* AUTHOR(S)
+/* LaMont Jones
+/* Hewlett-Packard Company
+/* 3404 Harmony Road
+/* Fort Collins, CO 80528, USA
+/*
+/* Wietse Venema
+/* IBM T.J. Watson Research
+/* P.O. Box 704
+/* Yorktown Heights, NY 10598, USA
+/*--*/
+
+/* System libraries. */
+
+#include "sys_defs.h"
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#if defined(HAS_DLOPEN)
+#include <dlfcn.h>
+#elif defined(HAS_SHL_LOAD)
+#include <dl.h>
+#endif
+
+/* Application-specific. */
+
+#include "msg.h"
+#include "load_lib.h"
+
+extern int load_library_symbols(const char * libname, LIB_FN * libfuncs, LIB_FN * libdata)
+{
+ char *myname = "load_library_symbols";
+ LIB_FN *fn;
+
+#if defined(HAS_DLOPEN)
+ void *handle;
+ char *emsg;
+
+ handle=dlopen(libname,RTLD_NOW);
+ emsg=dlerror();
+ if (emsg) {
+ msg_fatal("%s: dlopen failure loading %s: %s", myname, libname, emsg);
+ }
+
+ if (libfuncs) {
+ for (fn=libfuncs; fn->name; fn++) {
+ *(fn->ptr) = dlsym(handle,fn->name);
+ emsg=dlerror();
+ if (emsg) {
+ msg_fatal("%s: dlsym failure looking up %s in %s: %s", myname,
+ fn->name, libname, emsg);
+ }
+ if (msg_verbose>1) {
+ msg_info("loaded %s = %lx",fn->name, *((long*)(fn->ptr)));
+ }
+ }
+ }
+
+ if (libdata) {
+ for (fn=libdata; fn->name; fn++) {
+ *(fn->ptr) = dlsym(handle,fn->name);
+ emsg=dlerror();
+ if (emsg) {
+ msg_fatal("%s: dlsym failure looking up %s in %s: %s", myname,
+ fn->name, libname, emsg);
+ }
+ if (msg_verbose>1) {
+ msg_info("loaded %s = %lx",fn->name, *((long*)(fn->ptr)));
+ }
+ }
+ }
+#elif defined(HAS_SHL_LOAD)
+ shl_t handle;
+
+ handle = shl_load(libname,BIND_IMMEDIATE,0);
+
+ if (libfuncs) {
+ for (fn=libfuncs; fn->name; fn++) {
+ if (shl_findsym(&handle,fn->name,TYPE_PROCEDURE,fn->ptr) != 0) {
+ msg_fatal("%s: shl_findsym failure looking up %s in %s: %m",
+ myname, fn->name, libname);
+ }
+ if (msg_verbose>1) {
+ msg_info("loaded %s = %x",fn->name, *((long*)(fn->ptr)));
+ }
+ }
+ }
+
+ if (libdata) {
+ for (fn=libdata; fn->name; fn++) {
+ if (shl_findsym(&handle,fn->name,TYPE_DATA,fn->ptr) != 0) {
+ msg_fatal("%s: shl_findsym failure looking up %s in %s: %m",
+ myname, fn->name, libname);
+ }
+ if (msg_verbose>1) {
+ msg_info("loaded %s = %x",fn->name, *((long*)(fn->ptr)));
+ }
+ }
+ }
+
+#else
+ msg_fatal("%s: need dlopen or shl_load support for dynamic libraries",
+ myname);
+#endif
+ return 0;
+}
diff -urNad postfix~/src/util/load_lib.h postfix/src/util/load_lib.h
--- postfix~/src/util/load_lib.h 1969-12-31 17:00:00.000000000 -0700
+++ postfix/src/util/load_lib.h 2006-10-15 20:55:26.000000000 -0600
@@ -0,0 +1,41 @@
+#ifndef _LOAD_LIB_H_INCLUDED_
+#define _LOAD_LIB_H_INCLUDED_
+
+/*++
+/* NAME
+/* load_lib 3h
+/* SUMMARY
+/* library loading wrappers
+/* SYNOPSIS
+/* #include "load_lib.h"
+/* DESCRIPTION
+/* .nf
+
+ /*
+ * External interface.
+ */
+/* NULL name terminates list */
+typedef struct LIB_FN {
+ const char *name;
+ void **ptr;
+} LIB_FN;
+
+extern int load_library_symbols(const char *, LIB_FN *, LIB_FN *);
+
+/* LICENSE
+/* .ad
+/* .fi
+/* The Secure Mailer license must be distributed with this software.
+/* AUTHOR(S)
+/* LaMont Jones
+/* Hewlett-Packard Company
+/* 3404 Harmony Road
+/* Fort Collins, CO 80528, USA
+/*
+/* Wietse Venema
+/* IBM T.J. Watson Research
+/* P.O. Box 704
+/* Yorktown Heights, NY 10598, USA
+/*--*/
+
+#endif
diff -urNad postfix~/src/util/sdbm.c postfix/src/util/sdbm.c
--- postfix~/src/util/sdbm.c 1969-12-31 17:00:00.000000000 -0700
+++ postfix/src/util/sdbm.c 2006-10-15 20:55:26.000000000 -0600
@@ -0,0 +1,972 @@
+/*++
+/* NAME
+/* sdbm 3h
+/* SUMMARY
+/* SDBM Simple DBM: ndbm work-alike hashed database library
+/* SYNOPSIS
+/* include "sdbm.h"
+/* DESCRIPTION
+/* This file includes the public domain SDBM (ndbm work-alike hashed
+/* database library), based on Per-Aake Larson's Dynamic Hashing
+/* algorithms. BIT 18 (1978).
+/* author: oz@nexus.yorku.ca
+/* status: public domain
+/* The file has been patched following the advice of Uwe Ohse
+/* <uwe@ohse.de>:
+/* --------------------------------------------------------------
+/* this patch fixes a problem with sdbms .dir file, which arrises when
+/* a second .dir block is needed for the first time. read() returns 0
+/* in that case, and the library forgot to initialize that new block.
+/*
+/* A related problem is that the calculation of db->maxbno is wrong.
+/* It just appends 4096*BYTESIZ bits, which is not enough except for
+/* small databases (.dir basically doubles everytime it's too small).
+/* --------------------------------------------------------------
+/* According to Uwe Ohse, the patch has also been submitted to the
+/* author of SDBM. (The 4096*BYTESIZ bits comment may apply with a
+/* different size for Postfix/TLS, as the patch was sent against the
+/* original SDBM distributiona and for Postfix/TLS I have changed the
+/* default sizes.
+/* .nf
+/*--*/
+
+/*
+ * sdbm - ndbm work-alike hashed database library
+ * based on Per-Aake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
+ * author: oz@nexus.yorku.ca
+ * status: public domain.
+ *
+ * core routines
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef WIN32
+#include <io.h>
+#include <errno.h>
+#else
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#ifdef __STDC__
+#include <stddef.h>
+#endif
+#include <mymalloc.h>
+
+#include <sdbm.h>
+
+/*
+ * useful macros
+ */
+#define bad(x) ((x).dptr == NULL || (x).dsize <= 0)
+#define exhash(item) sdbm_hash((item).dptr, (item).dsize)
+#define ioerr(db) ((db)->flags |= DBM_IOERR)
+
+#define OFF_PAG(off) (long) (off) * PBLKSIZ
+#define OFF_DIR(off) (long) (off) * DBLKSIZ
+
+static long masks[] =
+{
+ 000000000000, 000000000001, 000000000003, 000000000007,
+ 000000000017, 000000000037, 000000000077, 000000000177,
+ 000000000377, 000000000777, 000000001777, 000000003777,
+ 000000007777, 000000017777, 000000037777, 000000077777,
+ 000000177777, 000000377777, 000000777777, 000001777777,
+ 000003777777, 000007777777, 000017777777, 000037777777,
+ 000077777777, 000177777777, 000377777777, 000777777777,
+ 001777777777, 003777777777, 007777777777, 017777777777
+};
+
+datum nullitem =
+{NULL, 0};
+
+typedef struct
+{
+ int dirf; /* directory file descriptor */
+ int pagf; /* page file descriptor */
+ int flags; /* status/error flags, see below */
+ long maxbno; /* size of dirfile in bits */
+ long curbit; /* current bit number */
+ long hmask; /* current hash mask */
+ long blkptr; /* current block for nextkey */
+ int keyptr; /* current key for nextkey */
+ long blkno; /* current page to read/write */
+ long pagbno; /* current page in pagbuf */
+ char *pagbuf; /* page file block buffer */
+ long dirbno; /* current block in dirbuf */
+ char *dirbuf; /* directory file block buffer */
+} DBM;
+
+
+/* ************************* */
+
+/*
+ * sdbm - ndbm work-alike hashed database library
+ * based on Per-Aake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
+ * author: oz@nexus.yorku.ca
+ * status: public domain. keep it that way.
+ *
+ * hashing routine
+ */
+
+/*
+ * polynomial conversion ignoring overflows
+ * [this seems to work remarkably well, in fact better
+ * then the ndbm hash function. Replace at your own risk]
+ * use: 65599 nice.
+ * 65587 even better.
+ */
+static long sdbm_hash (char *str, int len)
+{
+ unsigned long n = 0;
+
+#ifdef DUFF
+#define HASHC n = *str++ + 65599 * n
+ if (len > 0)
+ {
+ int loop = (len + 8 - 1) >> 3;
+
+ switch (len & (8 - 1))
+ {
+ case 0:
+ do
+ {
+ HASHC;
+ case 7:
+ HASHC;
+ case 6:
+ HASHC;
+ case 5:
+ HASHC;
+ case 4:
+ HASHC;
+ case 3:
+ HASHC;
+ case 2:
+ HASHC;
+ case 1:
+ HASHC;
+ }
+ while (--loop);
+ }
+
+ }
+#else
+ while (len--)
+ n = *str++ + 65599 * n;
+#endif
+ return n;
+}
+
+/*
+ * check page sanity:
+ * number of entries should be something
+ * reasonable, and all offsets in the index should be in order.
+ * this could be made more rigorous.
+ */
+static int chkpage (char *pag)
+{
+ int n;
+ int off;
+ short *ino = (short *) pag;
+
+ if ((n = ino[0]) < 0 || n > PBLKSIZ / sizeof (short))
+ return 0;
+
+ if (n > 0)
+ {
+ off = PBLKSIZ;
+ for (ino++; n > 0; ino += 2)
+ {
+ if (ino[0] > off || ino[1] > off ||
+ ino[1] > ino[0])
+ return 0;
+ off = ino[1];
+ n -= 2;
+ }
+ }
+ return 1;
+}
+
+/*
+ * search for the key in the page.
+ * return offset index in the range 0 < i < n.
+ * return 0 if not found.
+ */
+static int seepair (char *pag, int n, char *key, int siz)
+{
+ int i;
+ int off = PBLKSIZ;
+ short *ino = (short *) pag;
+
+ for (i = 1; i < n; i += 2)
+ {
+ if (siz == off - ino[i] &&
+ memcmp (key, pag + ino[i], siz) == 0)
+ return i;
+ off = ino[i + 1];
+ }
+ return 0;
+}
+
+#ifdef SEEDUPS
+static int duppair (char *pag, datum key)
+{
+ short *ino = (short *) pag;
+
+ return ino[0] > 0 && seepair (pag, ino[0], key.dptr, key.dsize) > 0;
+}
+
+#endif
+
+/* ************************* */
+
+/*
+ * sdbm - ndbm work-alike hashed database library
+ * based on Per-Aake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
+ * author: oz@nexus.yorku.ca
+ * status: public domain.
+ *
+ * page-level routines
+ */
+
+/*
+ * page format:
+ * +------------------------------+
+ * ino | n | keyoff | datoff | keyoff |
+ * +------------+--------+--------+
+ * | datoff | - - - ----> |
+ * +--------+---------------------+
+ * | F R E E A R E A |
+ * +--------------+---------------+
+ * | <---- - - - | data |
+ * +--------+-----+----+----------+
+ * | key | data | key |
+ * +--------+----------+----------+
+ *
+ * calculating the offsets for free area: if the number
+ * of entries (ino[0]) is zero, the offset to the END of
+ * the free area is the block size. Otherwise, it is the
+ * nth (ino[ino[0]]) entry's offset.
+ */
+
+static int fitpair (char *pag, int need)
+{
+ int n;
+ int off;
+ int avail;
+ short *ino = (short *) pag;
+
+ off = ((n = ino[0]) > 0) ? ino[n] : PBLKSIZ;
+ avail = off - (n + 1) * sizeof (short);
+ need += 2 * sizeof (short);
+
+ return need <= avail;
+}
+
+static void putpair (char *pag, datum key, datum val)
+{
+ int n;
+ int off;
+ short *ino = (short *) pag;
+
+ off = ((n = ino[0]) > 0) ? ino[n] : PBLKSIZ;
+/*
+ * enter the key first
+ */
+ off -= key.dsize;
+ (void) memcpy (pag + off, key.dptr, key.dsize);
+ ino[n + 1] = off;
+/*
+ * now the data
+ */
+ off -= val.dsize;
+ (void) memcpy (pag + off, val.dptr, val.dsize);
+ ino[n + 2] = off;
+/*
+ * adjust item count
+ */
+ ino[0] += 2;
+}
+
+static datum getpair (char *pag, datum key)
+{
+ int i;
+ int n;
+ datum val;
+ short *ino = (short *) pag;
+
+ if ((n = ino[0]) == 0)
+ return nullitem;
+
+ if ((i = seepair (pag, n, key.dptr, key.dsize)) == 0)
+ return nullitem;
+
+ val.dptr = pag + ino[i + 1];
+ val.dsize = ino[i] - ino[i + 1];
+ return val;
+}
+
+static datum getnkey (char *pag, int num)
+{
+ datum key;
+ int off;
+ short *ino = (short *) pag;
+
+ num = num * 2 - 1;
+ if (ino[0] == 0 || num > ino[0])
+ return nullitem;
+
+ off = (num > 1) ? ino[num - 1] : PBLKSIZ;
+
+ key.dptr = pag + ino[num];
+ key.dsize = off - ino[num];
+
+ return key;
+}
+
+static int delpair (char *pag, datum key)
+{
+ int n;
+ int i;
+ short *ino = (short *) pag;
+
+ if ((n = ino[0]) == 0)
+ return 0;
+
+ if ((i = seepair (pag, n, key.dptr, key.dsize)) == 0)
+ return 0;
+/*
+ * found the key. if it is the last entry
+ * [i.e. i == n - 1] we just adjust the entry count.
+ * hard case: move all data down onto the deleted pair,
+ * shift offsets onto deleted offsets, and adjust them.
+ * [note: 0 < i < n]
+ */
+ if (i < n - 1)
+ {
+ int m;
+ char *dst = pag + (i == 1 ? PBLKSIZ : ino[i - 1]);
+ char *src = pag + ino[i + 1];
+ int zoo = dst - src;
+
+/*
+ * shift data/keys down
+ */
+ m = ino[i + 1] - ino[n];
+#ifdef DUFF
+#define MOVB *--dst = *--src
+ if (m > 0)
+ {
+ int loop = (m + 8 - 1) >> 3;
+
+ switch (m & (8 - 1))
+ {
+ case 0:
+ do
+ {
+ MOVB;
+ case 7:
+ MOVB;
+ case 6:
+ MOVB;
+ case 5:
+ MOVB;
+ case 4:
+ MOVB;
+ case 3:
+ MOVB;
+ case 2:
+ MOVB;
+ case 1:
+ MOVB;
+ }
+ while (--loop);
+ }
+ }
+#else
+ dst -= m;
+ src -= m;
+ memmove (dst, src, m);
+#endif
+/*
+ * adjust offset index up
+ */
+ while (i < n - 1)
+ {
+ ino[i] = ino[i + 2] + zoo;
+ i++;
+ }
+ }
+ ino[0] -= 2;
+ return 1;
+}
+
+static void splpage (char *pag, char *new, long sbit)
+{
+ datum key;
+ datum val;
+
+ int n;
+ int off = PBLKSIZ;
+ char cur[PBLKSIZ];
+ short *ino = (short *) cur;
+
+ (void) memcpy (cur, pag, PBLKSIZ);
+ (void) memset (pag, 0, PBLKSIZ);
+ (void) memset (new, 0, PBLKSIZ);
+
+ n = ino[0];
+ for (ino++; n > 0; ino += 2)
+ {
+ key.dptr = cur + ino[0];
+ key.dsize = off - ino[0];
+ val.dptr = cur + ino[1];
+ val.dsize = ino[0] - ino[1];
+/*
+ * select the page pointer (by looking at sbit) and insert
+ */
+ (void) putpair ((exhash (key) & sbit) ? new : pag, key, val);
+
+ off = ino[1];
+ n -= 2;
+ }
+}
+
+static int getdbit (DBM * db, long dbit)
+{
+ long c;
+ long dirb;
+
+ c = dbit / BYTESIZ;
+ dirb = c / DBLKSIZ;
+
+ if (dirb != db->dirbno)
+ {
+ int got;
+ if (lseek (db->dirf, OFF_DIR (dirb), SEEK_SET) < 0
+ || (got = read(db->dirf, db->dirbuf, DBLKSIZ)) < 0)
+ return 0;
+ if (got==0)
+ memset(db->dirbuf,0,DBLKSIZ);
+ db->dirbno = dirb;
+ }
+
+ return db->dirbuf[c % DBLKSIZ] & (1 << dbit % BYTESIZ);
+}
+
+static int setdbit (DBM * db, long dbit)
+{
+ long c;
+ long dirb;
+
+ c = dbit / BYTESIZ;
+ dirb = c / DBLKSIZ;
+
+ if (dirb != db->dirbno)
+ {
+ int got;
+ if (lseek (db->dirf, OFF_DIR (dirb), SEEK_SET) < 0
+ || (got = read(db->dirf, db->dirbuf, DBLKSIZ)) < 0)
+ return 0;
+ if (got==0)
+ memset(db->dirbuf,0,DBLKSIZ);
+ db->dirbno = dirb;
+ }
+
+ db->dirbuf[c % DBLKSIZ] |= (1 << dbit % BYTESIZ);
+
+#if 0
+ if (dbit >= db->maxbno)
+ db->maxbno += DBLKSIZ * BYTESIZ;
+#else
+ if (OFF_DIR((dirb+1))*BYTESIZ > db->maxbno)
+ db->maxbno=OFF_DIR((dirb+1))*BYTESIZ;
+#endif
+
+ if (lseek (db->dirf, OFF_DIR (dirb), SEEK_SET) < 0
+ || write (db->dirf, db->dirbuf, DBLKSIZ) < 0)
+ return 0;
+
+ return 1;
+}
+
+/*
+ * getnext - get the next key in the page, and if done with
+ * the page, try the next page in sequence
+ */
+static datum getnext (DBM * db)
+{
+ datum key;
+
+ for (;;)
+ {
+ db->keyptr++;
+ key = getnkey (db->pagbuf, db->keyptr);
+ if (key.dptr != NULL)
+ return key;
+/*
+ * we either run out, or there is nothing on this page..
+ * try the next one... If we lost our position on the
+ * file, we will have to seek.
+ */
+ db->keyptr = 0;
+ if (db->pagbno != db->blkptr++)
+ if (lseek (db->pagf, OFF_PAG (db->blkptr), SEEK_SET) < 0)
+ break;
+ db->pagbno = db->blkptr;
+ if (read (db->pagf, db->pagbuf, PBLKSIZ) <= 0)
+ break;
+ if (!chkpage (db->pagbuf))
+ break;
+ }
+
+ return ioerr (db), nullitem;
+}
+
+/*
+ * all important binary trie traversal
+ */
+static int getpage (DBM * db, long hash)
+{
+ int hbit;
+ long dbit;
+ long pagb;
+
+ dbit = 0;
+ hbit = 0;
+ while (dbit < db->maxbno && getdbit (db, dbit))
+ dbit = 2 * dbit + ((hash & (1 << hbit++)) ? 2 : 1);
+
+ db->curbit = dbit;
+ db->hmask = masks[hbit];
+
+ pagb = hash & db->hmask;
+/*
+ * see if the block we need is already in memory.
+ * note: this lookaside cache has about 10% hit rate.
+ */
+ if (pagb != db->pagbno)
+ {
+/*
+ * note: here, we assume a "hole" is read as 0s.
+ * if not, must zero pagbuf first.
+ */
+ if (lseek (db->pagf, OFF_PAG (pagb), SEEK_SET) < 0
+ || read (db->pagf, db->pagbuf, PBLKSIZ) < 0)
+ return 0;
+ if (!chkpage (db->pagbuf))
+ return 0;
+ db->pagbno = pagb;
+ }
+ return 1;
+}
+
+/*
+ * makroom - make room by splitting the overfull page
+ * this routine will attempt to make room for SPLTMAX times before
+ * giving up.
+ */
+static int makroom (DBM * db, long hash, int need)
+{
+ long newp;
+ char twin[PBLKSIZ];
+ char *pag = db->pagbuf;
+ char *new = twin;
+ int smax = SPLTMAX;
+
+ do
+ {
+/*
+ * split the current page
+ */
+ (void) splpage (pag, new, db->hmask + 1);
+/*
+ * address of the new page
+ */
+ newp = (hash & db->hmask) | (db->hmask + 1);
+
+/*
+ * write delay, read avoidence/cache shuffle:
+ * select the page for incoming pair: if key is to go to the new page,
+ * write out the previous one, and copy the new one over, thus making
+ * it the current page. If not, simply write the new page, and we are
+ * still looking at the page of interest. current page is not updated
+ * here, as sdbm_store will do so, after it inserts the incoming pair.
+ */
+ if (hash & (db->hmask + 1))
+ {
+ if (lseek (db->pagf, OFF_PAG (db->pagbno), SEEK_SET) < 0
+ || write (db->pagf, db->pagbuf, PBLKSIZ) < 0)
+ return 0;
+ db->pagbno = newp;
+ (void) memcpy (pag, new, PBLKSIZ);
+ }
+ else if (lseek (db->pagf, OFF_PAG (newp), SEEK_SET) < 0
+ || write (db->pagf, new, PBLKSIZ) < 0)
+ return 0;
+
+ if (!setdbit (db, db->curbit))
+ return 0;
+/*
+ * see if we have enough room now
+ */
+ if (fitpair (pag, need))
+ return 1;
+/*
+ * try again... update curbit and hmask as getpage would have
+ * done. because of our update of the current page, we do not
+ * need to read in anything. BUT we have to write the current
+ * [deferred] page out, as the window of failure is too great.
+ */
+ db->curbit = 2 * db->curbit +
+ ((hash & (db->hmask + 1)) ? 2 : 1);
+ db->hmask |= db->hmask + 1;
+
+ if (lseek (db->pagf, OFF_PAG (db->pagbno), SEEK_SET) < 0
+ || write (db->pagf, db->pagbuf, PBLKSIZ) < 0)
+ return 0;
+
+ }
+ while (--smax);
+/*
+ * if we are here, this is real bad news. After SPLTMAX splits,
+ * we still cannot fit the key. say goodnight.
+ */
+#ifdef BADMESS
+ (void) write (2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44);
+#endif
+ return 0;
+
+}
+
+static SDBM *sdbm_prep (char *dirname, char *pagname, int flags, int mode)
+{
+ SDBM *db;
+ struct stat dstat;
+
+ if ((db = (SDBM *) mymalloc (sizeof (SDBM))) == NULL)
+ return errno = ENOMEM, (SDBM *) NULL;
+
+ db->flags = 0;
+ db->blkptr = 0;
+ db->keyptr = 0;
+/*
+ * adjust user flags so that WRONLY becomes RDWR,
+ * as required by this package. Also set our internal
+ * flag for RDONLY if needed.
+ */
+ if (flags & O_WRONLY)
+ flags = (flags & ~O_WRONLY) | O_RDWR;
+ else if ((flags & 03) == O_RDONLY)
+ db->flags = DBM_RDONLY;
+#if defined(OS2) || defined(MSDOS) || defined(WIN32)
+ flags |= O_BINARY;
+#endif
+
+/*
+ * Make sure to ignore the O_EXCL option, as the file might exist due
+ * to the locking.
+ */
+ flags &= ~O_EXCL;
+
+/*
+ * open the files in sequence, and stat the dirfile.
+ * If we fail anywhere, undo everything, return NULL.
+ */
+
+ if ((db->pagf = open (pagname, flags, mode)) > -1)
+ {
+ if ((db->dirf = open (dirname, flags, mode)) > -1)
+ {
+/*
+ * need the dirfile size to establish max bit number.
+ */
+ if (fstat (db->dirf, &dstat) == 0)
+ {
+ /*
+ * success
+ */
+ return db;
+ }
+ msg_info ("closing dirf");
+ (void) close (db->dirf);
+ }
+ msg_info ("closing pagf");
+ (void) close (db->pagf);
+ }
+ myfree ((char *) db);
+ return (SDBM *) NULL;
+}
+
+static DBM *sdbm_internal_open (SDBM * sdbm)
+{
+ DBM *db;
+ struct stat dstat;
+
+ if ((db = (DBM *) mymalloc (sizeof (DBM))) == NULL)
+ return errno = ENOMEM, (DBM *) NULL;
+
+ db->flags = sdbm->flags;
+ db->hmask = 0;
+ db->blkptr = sdbm->blkptr;
+ db->keyptr = sdbm->keyptr;
+ db->pagf = sdbm->pagf;
+ db->dirf = sdbm->dirf;
+ db->pagbuf = sdbm->pagbuf;
+ db->dirbuf = sdbm->dirbuf;
+
+/*
+ * need the dirfile size to establish max bit number.
+ */
+ if (fstat (db->dirf, &dstat) == 0)
+ {
+/*
+ * zero size: either a fresh database, or one with a single,
+ * unsplit data page: dirpage is all zeros.
+ */
+ db->dirbno = (!dstat.st_size) ? 0 : -1;
+ db->pagbno = -1;
+ db->maxbno = dstat.st_size * BYTESIZ;
+
+ (void) memset (db->pagbuf, 0, PBLKSIZ);
+ (void) memset (db->dirbuf, 0, DBLKSIZ);
+ return db;
+ }
+ myfree ((char *) db);
+ return (DBM *) NULL;
+}
+
+static void sdbm_internal_close (DBM * db)
+{
+ if (db == NULL)
+ errno = EINVAL;
+ else
+ {
+ myfree ((char *) db);
+ }
+}
+
+datum sdbm_fetch (SDBM * sdb, datum key)
+{
+ datum retval;
+ DBM *db;
+
+ if (sdb == NULL || bad (key))
+ return errno = EINVAL, nullitem;
+
+ if (!(db = sdbm_internal_open (sdb)))
+ return errno = EINVAL, nullitem;
+
+ if (getpage (db, exhash (key)))
+ {
+ retval = getpair (db->pagbuf, key);
+ sdbm_internal_close (db);
+ return retval;
+ }
+
+ sdbm_internal_close (db);
+
+ return ioerr (sdb), nullitem;
+}
+
+int sdbm_delete (SDBM * sdb, datum key)
+{
+ int retval;
+ DBM *db;
+
+ if (sdb == NULL || bad (key))
+ return errno = EINVAL, -1;
+ if (sdbm_rdonly (sdb))
+ return errno = EPERM, -1;
+
+ if (!(db = sdbm_internal_open (sdb)))
+ return errno = EINVAL, -1;
+
+ if (getpage (db, exhash (key)))
+ {
+ if (!delpair (db->pagbuf, key))
+ retval = -1;
+/*
+ * update the page file
+ */
+ else if (lseek (db->pagf, OFF_PAG (db->pagbno), SEEK_SET) < 0
+ || write (db->pagf, db->pagbuf, PBLKSIZ) < 0)
+ retval = ioerr (sdb), -1;
+ else
+ retval = 0;
+ }
+ else
+ retval = ioerr (sdb), -1;
+
+ sdbm_internal_close (db);
+
+ return retval;
+}
+
+int sdbm_store (SDBM * sdb, datum key, datum val, int flags)
+{
+ int need;
+ int retval;
+ long hash;
+ DBM *db;
+
+ if (sdb == NULL || bad (key))
+ return errno = EINVAL, -1;
+ if (sdbm_rdonly (sdb))
+ return errno = EPERM, -1;
+
+ need = key.dsize + val.dsize;
+/*
+ * is the pair too big (or too small) for this database ??
+ */
+ if (need < 0 || need > PAIRMAX)
+ return errno = EINVAL, -1;
+
+ if (!(db = sdbm_internal_open (sdb)))
+ return errno = EINVAL, -1;
+
+ if (getpage (db, (hash = exhash (key))))
+ {
+/*
+ * if we need to replace, delete the key/data pair
+ * first. If it is not there, ignore.
+ */
+ if (flags == DBM_REPLACE)
+ (void) delpair (db->pagbuf, key);
+#ifdef SEEDUPS
+ else if (duppair (db->pagbuf, key))
+ {
+ sdbm_internal_close (db);
+ return 1;
+ }
+#endif
+/*
+ * if we do not have enough room, we have to split.
+ */
+ if (!fitpair (db->pagbuf, need))
+ if (!makroom (db, hash, need))
+ {
+ sdbm_internal_close (db);
+ return ioerr (db), -1;
+ }
+/*
+ * we have enough room or split is successful. insert the key,
+ * and update the page file.
+ */
+ (void) putpair (db->pagbuf, key, val);
+
+ if (lseek (db->pagf, OFF_PAG (db->pagbno), SEEK_SET) < 0
+ || write (db->pagf, db->pagbuf, PBLKSIZ) < 0)
+ {
+ sdbm_internal_close (db);
+ return ioerr (db), -1;
+ }
+ /*
+ * success
+ */
+ sdbm_internal_close (db);
+ return 0;
+ }
+
+ sdbm_internal_close (db);
+ return ioerr (sdb), -1;
+}
+
+/*
+ * the following two routines will break if
+ * deletions aren't taken into account. (ndbm bug)
+ */
+datum sdbm_firstkey (SDBM * sdb)
+{
+ datum retval;
+ DBM *db;
+
+ if (sdb == NULL)
+ return errno = EINVAL, nullitem;
+
+ if (!(db = sdbm_internal_open (sdb)))
+ return errno = EINVAL, nullitem;
+
+/*
+ * start at page 0
+ */
+ if (lseek (db->pagf, OFF_PAG (0), SEEK_SET) < 0
+ || read (db->pagf, db->pagbuf, PBLKSIZ) < 0)
+ {
+ sdbm_internal_close (db);
+ return ioerr (sdb), nullitem;
+ }
+ db->pagbno = 0;
+ db->blkptr = 0;
+ db->keyptr = 0;
+
+ retval = getnext (db);
+ sdb->blkptr = db->blkptr;
+ sdb->keyptr = db->keyptr;
+ sdbm_internal_close (db);
+ return retval;
+}
+
+datum sdbm_nextkey (SDBM * sdb)
+{
+ datum retval;
+ DBM *db;
+
+ if (sdb == NULL)
+ return errno = EINVAL, nullitem;
+
+ if (!(db = sdbm_internal_open (sdb)))
+ return errno = EINVAL, nullitem;
+
+ retval = getnext (db);
+ sdb->blkptr = db->blkptr;
+ sdb->keyptr = db->keyptr;
+ sdbm_internal_close (db);
+ return retval;
+}
+
+void sdbm_close (SDBM * db)
+{
+ if (db == NULL)
+ errno = EINVAL;
+ else
+ {
+ (void) close (db->dirf);
+ (void) close (db->pagf);
+ myfree ((char *) db);
+ }
+}
+
+SDBM *sdbm_open (char *file, int flags, int mode)
+{
+ SDBM *db;
+ char *dirname;
+ char *pagname;
+ int n;
+
+ if (file == NULL || !*file)
+ return errno = EINVAL, (SDBM *) NULL;
+/*
+ * need space for two seperate filenames
+ */
+ n = strlen (file) * 2 + strlen (DIRFEXT) + strlen (PAGFEXT) + 2;
+
+ if ((dirname = (char *) mymalloc ((unsigned) n)) == NULL)
+ return errno = ENOMEM, (SDBM *) NULL;
+/*
+ * build the file names
+ */
+ dirname = strcat (strcpy (dirname, file), DIRFEXT);
+ pagname = strcpy (dirname + strlen (dirname) + 1, file);
+ pagname = strcat (pagname, PAGFEXT);
+
+ db = sdbm_prep (dirname, pagname, flags, mode);
+ myfree ((char *) dirname);
+ return db;
+}
+
diff -urNad postfix~/src/util/sdbm.h postfix/src/util/sdbm.h
--- postfix~/src/util/sdbm.h 1969-12-31 17:00:00.000000000 -0700
+++ postfix/src/util/sdbm.h 2006-10-15 20:55:26.000000000 -0600
@@ -0,0 +1,97 @@
+/*++
+/* NAME
+/* sdbm 3h
+/* SUMMARY
+/* SDBM Simple DBM: ndbm work-alike hashed database library
+/* SYNOPSIS
+/* include "sdbm.h"
+/* DESCRIPTION
+/* .nf
+/*--*/
+
+#ifndef UTIL_SDBM_H
+#define UTIL_SDBM_H
+
+/*
+ * sdbm - ndbm work-alike hashed database library
+ * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
+ * author: oz@nexus.yorku.ca
+ * status: public domain.
+ */
+
+#define DUFF /* go ahead and use the loop-unrolled version */
+
+#include <stdio.h>
+
+#define DBLKSIZ 16384 /* SSL cert chains require more */
+#define PBLKSIZ 8192 /* SSL cert chains require more */
+#define PAIRMAX 8008 /* arbitrary on PBLKSIZ-N */
+#define SPLTMAX 10 /* maximum allowed splits */
+ /* for a single insertion */
+#define DIRFEXT ".dir"
+#define PAGFEXT ".pag"
+
+typedef struct {
+ int dirf; /* directory file descriptor */
+ int pagf; /* page file descriptor */
+ int flags; /* status/error flags, see below */
+ long blkptr; /* current block for nextkey */
+ int keyptr; /* current key for nextkey */
+ char pagbuf[PBLKSIZ]; /* page file block buffer */
+ char dirbuf[DBLKSIZ]; /* directory file block buffer */
+} SDBM;
+
+#define DBM_RDONLY 0x1 /* data base open read-only */
+#define DBM_IOERR 0x2 /* data base I/O error */
+
+/*
+ * utility macros
+ */
+#define sdbm_rdonly(db) ((db)->flags & DBM_RDONLY)
+#define sdbm_error(db) ((db)->flags & DBM_IOERR)
+
+#define sdbm_clearerr(db) ((db)->flags &= ~DBM_IOERR) /* ouch */
+
+#define sdbm_dirfno(db) ((db)->dirf)
+#define sdbm_pagfno(db) ((db)->pagf)
+
+typedef struct {
+ char *dptr;
+ int dsize;
+} datum;
+
+extern datum nullitem;
+
+/*
+ * flags to sdbm_store
+ */
+#define DBM_INSERT 0
+#define DBM_REPLACE 1
+
+/*
+ * ndbm interface
+ */
+extern SDBM *sdbm_open(char *, int, int);
+extern void sdbm_close(SDBM *);
+extern datum sdbm_fetch(SDBM *, datum);
+extern int sdbm_delete(SDBM *, datum);
+extern int sdbm_store(SDBM *, datum, datum, int);
+extern datum sdbm_firstkey(SDBM *);
+extern datum sdbm_nextkey(SDBM *);
+
+/*
+ * sdbm - ndbm work-alike hashed database library
+ * tuning and portability constructs [not nearly enough]
+ * author: oz@nexus.yorku.ca
+ */
+
+#define BYTESIZ 8
+
+/*
+ * important tuning parms (hah)
+ */
+
+#define SEEDUPS /* always detect duplicates */
+#define BADMESS /* generate a message for worst case:
+ cannot make room after SPLTMAX splits */
+#endif /* UTIL_SDBM_H */
diff -urNad postfix~/src/util/sys_defs.h postfix/src/util/sys_defs.h
--- postfix~/src/util/sys_defs.h 2006-08-29 08:17:05.000000000 -0600
+++ postfix/src/util/sys_defs.h 2006-10-15 20:55:26.000000000 -0600
@@ -655,6 +655,7 @@
#define INTERNAL_LOCK MYFLOCK_STYLE_FLOCK
#define DEF_MAILBOX_LOCK "fcntl, dotlock" /* RedHat >= 4.x */
#define HAS_FSYNC
+#define HAS_SDBM
#define HAS_DB
#define DEF_DB_TYPE "hash"
#define ALIAS_DB_MAP "hash:/etc/aliases"
@@ -667,11 +668,25 @@
#define UNIX_DOMAIN_CONNECT_BLOCKS_FOR_ACCEPT
#define PREPEND_PLUS_TO_OPTSTRING
#define HAS_POSIX_REGEXP
+#define HAS_DLOPEN
#define NATIVE_SENDMAIL_PATH "/usr/sbin/sendmail"
#define NATIVE_MAILQ_PATH "/usr/bin/mailq"
#define NATIVE_NEWALIAS_PATH "/usr/bin/newaliases"
#define NATIVE_COMMAND_DIR "/usr/sbin"
+#ifdef DEBIAN
+#define NATIVE_DAEMON_DIR "/usr/lib/postfix"
+#ifndef DEF_MANPAGE_DIR
+#define DEF_MANPAGE_DIR "/usr/share/man"
+#endif
+#ifndef DEF_SAMPLE_DIR
+#define DEF_SAMPLE_DIR "/usr/share/doc/postfix/examples"
+#endif
+#ifndef DEF_README_DIR
+#define DEF_README_DIR "/usr/share/doc/postfix"
+#endif
+#else
#define NATIVE_DAEMON_DIR "/usr/libexec/postfix"
+#endif
#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
#define SOCKADDR_SIZE socklen_t
#define SOCKOPT_SIZE socklen_t
@@ -757,6 +772,7 @@
#define USE_STATFS
#define STATFS_IN_SYS_VFS_H
#define HAS_POSIX_REGEXP
+#define HAS_DLOPEN
#define NATIVE_SENDMAIL_PATH "/usr/sbin/sendmail"
#define NATIVE_MAILQ_PATH "/usr/bin/mailq"
#define NATIVE_NEWALIAS_PATH "/usr/bin/newaliases"
@@ -794,6 +810,7 @@
#define USE_STATFS
#define STATFS_IN_SYS_VFS_H
#define HAS_POSIX_REGEXP
+#define HAS_SHL_LOAD
#define NATIVE_SENDMAIL_PATH "/usr/sbin/sendmail"
#define NATIVE_MAILQ_PATH "/usr/bin/mailq"
#define NATIVE_NEWALIAS_PATH "/usr/bin/newaliases"
@@ -833,6 +850,7 @@
#define USE_STATFS
#define STATFS_IN_SYS_VFS_H
#define HAS_POSIX_REGEXP
+#define HAS_SHL_LOAD
#define NATIVE_SENDMAIL_PATH "/usr/bin/sendmail"
#define NATIVE_MAILQ_PATH "/usr/bin/mailq"
#define NATIVE_NEWALIAS_PATH "/usr/bin/newaliases"
|